Motr  M0
sd_post_record.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2017-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_FDMI
24 #include "lib/trace.h"
25 
26 #include "lib/memory.h"
27 #include "ut/ut.h"
28 #include "fdmi/fdmi.h"
29 #include "fdmi/service.h" /* m0_reqh_fdmi_service */
31 
32 #include "fdmi/ut/sd_common.h"
33 
34 static struct m0_semaphore g_sem;
35 static struct m0_semaphore g_sem2;
36 static struct m0_fdmi_src_rec g_src_rec;
37 static int g_refcount;
38 
39 static int test_fs_node_eval(
40  struct m0_fdmi_src_rec *src_rec,
41  struct m0_fdmi_flt_var_node *value_desc,
42  struct m0_fdmi_flt_operand *value)
43 {
44  M0_UT_ASSERT(false);
45  return 0;
46 }
47 
48 static int test_fs_encode(struct m0_fdmi_src_rec *src_rec,
49  struct m0_buf *buf)
50 {
51  M0_UT_ASSERT(false);
52  return 0;
53 }
54 
55 static int test_fs_decode(struct m0_buf *buf, void **handle)
56 {
57  M0_UT_ASSERT(false);
58  return 0;
59 }
60 
61 static void test_fs_get(struct m0_fdmi_src_rec *src_rec)
62 {
63  ++g_refcount;
64 }
65 
66 static void test_fs_put(struct m0_fdmi_src_rec *src_rec)
67 {
68  M0_UT_ASSERT(src_rec != NULL);
69  M0_UT_ASSERT(src_rec == &g_src_rec);
70  --g_refcount;
71  if (g_refcount == 0)
73 }
74 
75 static void test_fs_end(struct m0_fdmi_src_rec *src_rec)
76 {
77  M0_UT_ASSERT(src_rec != NULL);
78  M0_UT_ASSERT(src_rec == &g_src_rec);
79  /* Calling of this function is a sign for fdmi_sd_post_record UT
80  * that FDMI finished record processing */
82 }
83 
84 static struct m0_fdmi_src *src_alloc()
85 {
86  struct m0_fdmi_src *src;
87  int rc;
88 
90  M0_UT_ASSERT(rc == 0);
91 
92  src->fs_node_eval = test_fs_node_eval;
93  src->fs_get = test_fs_get;
94  src->fs_put = test_fs_put;
95  src->fs_end = test_fs_end;
96  src->fs_encode = test_fs_encode;
97  src->fs_decode = test_fs_decode;
98  return src;
99 }
100 
102 {
103  struct m0_fdmi_src *src = src_alloc();
104  int rc;
105 
106  static char fdmi_data[] = "hello, FDMI";
107 
108  M0_ENTRY();
113  M0_UT_ASSERT(rc == 0);
114  g_src_rec = (struct m0_fdmi_src_rec) {
115  .fsr_src = src,
116  .fsr_data = fdmi_data,
117  };
119  /* Wait until record is processed and released */
123  M0_UT_ASSERT(src->fs_record_post == NULL);
128  M0_LEAVE();
129 }
130 
131 #undef M0_TRACE_SUBSYSTEM
132 
133 /*
134  * Local variables:
135  * c-indentation-style: "K&R"
136  * c-basic-offset: 8
137  * tab-width: 8
138  * fill-column: 80
139  * scroll-step: 1
140  * End:
141  */
142 /*
143  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
144  */
#define NULL
Definition: misc.h:38
static void test_fs_get(struct m0_fdmi_src_rec *src_rec)
M0_LEAVE()
static struct m0_fdmi_src_rec g_src_rec
int const char const void * value
Definition: dir.c:325
M0_INTERNAL void m0_fdmi_source_free(struct m0_fdmi_src *src)
Definition: source_dock.c:301
void fdmi_sd_post_record(void)
static int test_fs_decode(struct m0_buf *buf, void **handle)
Definition: sock.c:887
static void test_fs_put(struct m0_fdmi_src_rec *src_rec)
struct m0_fdmi_src * fsr_src
Definition: src_rec.h:72
void fdmi_serv_start_ut(const struct m0_filterc_ops *filterc_ops)
Definition: sd_common.c:66
#define M0_ENTRY(...)
Definition: trace.h:170
Definition: buf.h:37
M0_INTERNAL int m0_fdmi_source_alloc(enum m0_fdmi_rec_type_id type_id, struct m0_fdmi_src **src)
Definition: source_dock.c:285
static struct m0_semaphore g_sem2
static int test_fs_encode(struct m0_fdmi_src_rec *src_rec, struct m0_buf *buf)
static struct m0_semaphore g_sem
M0_INTERNAL void m0_fdmi_source_deregister(struct m0_fdmi_src *src)
Definition: source_dock.c:337
M0_INTERNAL int m0_fdmi_source_register(struct m0_fdmi_src *src)
Definition: source_dock.c:311
M0_INTERNAL int m0_semaphore_init(struct m0_semaphore *semaphore, unsigned value)
Definition: semaphore.c:38
void fdmi_serv_stop_ut(void)
Definition: sd_common.c:121
M0_INTERNAL void m0_semaphore_fini(struct m0_semaphore *semaphore)
Definition: semaphore.c:45
#define M0_FDMI_SOURCE_POST_RECORD(_src_rec_ptr)
Definition: source_dock.h:148
static void test_fs_end(struct m0_fdmi_src_rec *src_rec)
static int g_refcount
const struct m0_filterc_ops filterc_stub_ops
Definition: filterc_stub.c:43
M0_INTERNAL void m0_semaphore_down(struct m0_semaphore *semaphore)
Definition: semaphore.c:49
static struct m0_fdmi_src * src_alloc()
M0_INTERNAL void m0_semaphore_up(struct m0_semaphore *semaphore)
Definition: semaphore.c:65
struct m0_pdclust_src_addr src
Definition: fd.c:108
int32_t rc
Definition: trigger_fop.h:47
#define M0_UT_ASSERT(a)
Definition: ut.h:46
static int test_fs_node_eval(struct m0_fdmi_src_rec *src_rec, struct m0_fdmi_flt_var_node *value_desc, struct m0_fdmi_flt_operand *value)