Motr  M0
isc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Seagate Technology LLC and/or its Affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * For any questions about this software or licensing,
17  * please email opensource@seagate.com or cortx-questions@seagate.com.
18  *
19  */
20 
21 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_UT
22 #include "lib/trace.h"
23 #include "lib/memory.h"
24 #include "ut/ut.h"
25 #include "ut/misc.h"
26 #include "reqh/reqh.h"
27 #include "reqh/reqh_service.h"
28 #include "rpc/rpc_machine.h"
29 #include "iscservice/isc.h"
30 #include "iscservice/isc_service.h"
31 #include "iscservice/ut/common.h"
32 
33 static struct m0_reqh reqh;
35 static struct m0_reqh_service *isc;
36 
37 static void init(void)
38 {
39  int result;
40 
41  result = M0_REQH_INIT(&reqh,
42  .rhia_db = NULL,
43  .rhia_mdstore = (void *)1,
44  .rhia_fid = &g_process_fid);
45  M0_UT_ASSERT(result == 0);
46  m0_reqh_rpc_mach_tlink_init_at_tail(&rpc_machine,
49  M0_UT_ASSERT(result == 0);
53 }
54 
55 static void fini(void)
56 {
57  m0_reqh_rpc_mach_tlist_pop(&reqh.rh_rpc_machines);
62 }
63 
64 static int null_computation(struct m0_buf *in, struct m0_buf *out,
65  struct m0_isc_comp_private *comp_data, int *rc)
66 {
67  *rc = 0;
68  return M0_FSO_AGAIN;
69 }
70 
71 void comp_register(void *args)
72 {
73  struct thr_args *thr_args = args;
74  struct m0_fid *fid = thr_args->ta_data;
75 
76  /* Wait till the last thread reaches here. */
79  "null_computation", fid);
80 }
81 
82 static void fid_set(void *fid, int tid)
83 {
84  m0_fid_set((struct m0_fid *)fid, 0x1234, tid);
85 }
86 
87 static void test_register(void)
88 {
89  int rc;
90  struct m0_fid fid;
91  struct cnc_cntrl_block *cc_block;
92 
93  M0_ALLOC_PTR(cc_block);
94  M0_UT_ASSERT(cc_block != NULL);
95  M0_SET0(cc_block);
96  init();
97  m0_fid_set(&fid, 0x1234, 0x456);
98  /* Register a new computation. */
99  rc = m0_isc_comp_register(null_computation, "null_computation", &fid);
100  M0_UT_ASSERT(rc == 0);
101  /* Register an existing computation. */
102  rc = m0_isc_comp_register(null_computation, "null_computation", &fid);
103  M0_UT_ASSERT(rc == -EEXIST);
106  /* Unregister. */
109  M0_UT_ASSERT(rc == -ENOENT);
110  cc_block_init(cc_block, sizeof (struct m0_fid), fid_set);
111  cc_block_launch(cc_block, comp_register);
112  fini();
113  m0_free(cc_block);
114 }
115 
116 static void test_init_fini(void)
117 {
118  init();
119  fini();
120 }
121 
123  .ts_name = "isc-api-ut",
124  .ts_init = NULL,
125  .ts_fini = NULL,
126  .ts_tests = {
127  {"init", test_init_fini, "Nachiket"},
128  {"comp-register", test_register, "Nachiket"},
129  {NULL, NULL}
130  }
131 };
static int null_computation(struct m0_buf *in, struct m0_buf *out, struct m0_isc_comp_private *comp_data, int *rc)
Definition: isc.c:64
M0_INTERNAL void cc_block_launch(struct cnc_cntrl_block *cc_block, void(*t_op)(void *))
Definition: common.c:47
M0_INTERNAL int m0_reqh_service_start(struct m0_reqh_service *service)
Definition: reqh_service.c:343
M0_INTERNAL void m0_reqh_service_stop(struct m0_reqh_service *service)
Definition: reqh_service.c:402
static void test_init_fini(void)
Definition: isc.c:116
#define NULL
Definition: misc.h:38
static struct m0_rpc_machine rpc_machine
Definition: isc.c:34
#define M0_REQH_INIT(reqh,...)
Definition: reqh.h:262
M0_INTERNAL void m0_reqh_service_prepare_to_stop(struct m0_reqh_service *service)
Definition: reqh_service.c:375
static void fid_set(void *fid, int tid)
Definition: isc.c:82
#define M0_SET0(obj)
Definition: misc.h:64
Definition: ub.c:49
struct m0_semaphore * ta_barrier
Definition: common.h:37
Definition: ut.h:77
struct m0_ut_suite isc_api_ut
Definition: isc.c:122
struct m0_fid fid
Definition: di.c:46
Definition: buf.h:37
def args
Definition: addb2db.py:716
M0_INTERNAL void m0_fid_set(struct m0_fid *fid, uint64_t container, uint64_t key)
Definition: fid.c:116
struct m0_reqh_service_type m0_iscs_type
Definition: isc_service.c:76
M0_INTERNAL int m0_isc_comp_state_probe(const struct m0_fid *fid)
Definition: isc.c:668
M0_INTERNAL void m0_reqh_service_fini(struct m0_reqh_service *service)
Definition: reqh_service.c:457
struct m0_tl rh_rpc_machines
Definition: reqh.h:135
static struct m0_reqh_service * isc
Definition: isc.c:35
M0_INTERNAL int m0_reqh_service_allocate(struct m0_reqh_service **out, const struct m0_reqh_service_type *stype, struct m0_reqh_context *rctx)
Definition: reqh_service.c:185
Definition: reqh.h:94
M0_INTERNAL void m0_reqh_service_init(struct m0_reqh_service *service, struct m0_reqh *reqh, const struct m0_fid *fid)
Definition: reqh_service.c:428
static void fini(void)
Definition: isc.c:55
static void init(void)
Definition: isc.c:37
M0_INTERNAL void m0_isc_comp_unregister(const struct m0_fid *fid)
Definition: isc.c:652
int ta_rc
Definition: common.h:38
const char * ts_name
Definition: ut.h:99
M0_INTERNAL void m0_reqh_start(struct m0_reqh *reqh)
Definition: reqh.c:711
Definition: fid.h:38
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
M0_INTERNAL void m0_reqh_idle_wait_for(struct m0_reqh *reqh, struct m0_reqh_service *service)
Definition: reqh.c:591
static struct m0_reqh reqh
Definition: isc.c:33
void * ta_data
Definition: common.h:36
#define out(...)
Definition: gen.c:41
void comp_register(void *args)
Definition: isc.c:71
M0_INTERNAL void m0_semaphore_up(struct m0_semaphore *semaphore)
Definition: semaphore.c:65
void m0_free(void *data)
Definition: memory.c:146
M0_INTERNAL int m0_isc_comp_register(int(*ftn)(struct m0_buf *arg_in, struct m0_buf *args_out, struct m0_isc_comp_private *comp_data, int *rc), const char *f_name, const struct m0_fid *ftn_fid)
Definition: isc.c:609
static void test_register(void)
Definition: isc.c:87
int32_t rc
Definition: trigger_fop.h:47
struct m0_fid g_process_fid
Definition: ut.c:689
#define M0_UT_ASSERT(a)
Definition: ut.h:46
M0_INTERNAL void cc_block_init(struct cnc_cntrl_block *cc_block, size_t size, void(*t_data_init)(void *, int))
Definition: common.c:29