Motr  M0
service.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-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 
22 #include "lib/memory.h"
23 #include "lib/misc.h"
24 #include "ut/ut.h"
25 
26 #include "fop/fop.h"
27 #include "fop/fom_generic.h"
28 #include "reqh/reqh.h"
29 #include "reqh/reqh_service.h"
30 #include "reqh/ut/service.h"
31 #include "reqh/ut/service_xc.h"
32 #include "rpc/rpc_opcodes.h"
33 #include "ut/ut.h"
34 #include "ut/cs_service.h"
35 #include "ut/cs_fop.h"
36 #include "ut/ut_rpc_machine.h"
37 
38 #include "reqh/ut/reqhut_fom.c"
39 
40 #define DUMMY_DBNAME "dummy-db"
41 #define DUMMY_COB_ID 20
42 #define DUMMY_SERVER_ADDR "0@lo:12345:34:10"
43 
46 
47 enum {
49 };
50 
51 static int m0_reqhut_fop_init(void)
52 {
53  m0_xc_reqh_ut_service_init();
54  m0_reqhut_dummy_xc->xct_flags = M0_XCODE_TYPE_FLAG_DOM_RPC;
56  .name = "Reqh unit test",
58  .xt = m0_reqhut_dummy_xc,
59  .fom_ops = &reqhut_fom_type_ops,
60  .sm = &m0_generic_conf,
61  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST,
62  .svc_type = &ds1_service_type);
63  return 0;
64 }
65 
66 static void m0_reqhut_fop_fini(void)
67 {
69  m0_xc_reqh_ut_service_fini();
70 }
71 
72 static void test_service(void)
73 {
74  int i;
75  int rc;
76  struct m0_reqh *reqh;
77  struct m0_reqh_service_type *svct;
78  struct m0_reqh_service *reqh_svc;
79  struct m0_fop *fop;
80 
83  M0_UT_ASSERT(rc == 0);
84 
85  /* Workaround */
90 
92  svct = m0_reqh_service_type_find("M0_CST_DS1");
93  M0_UT_ASSERT(svct != NULL);
94 
96  M0_UT_ASSERT(rc == 0);
97 
99 
101  M0_UT_ASSERT(rc == 0);
102 
104  M0_UT_ASSERT(fop != NULL);
105 
106  for (i = 0; i < MAX_REQH_UT_FOP; ++i) {
109  }
111 
115 }
116 
118  .ts_name = "reqh-service-ut",
119  .ts_init = NULL,
120  .ts_fini = NULL,
121  .ts_tests = {
122  { "reqh service", test_service },
123  { NULL, NULL }
124  }
125 };
126 M0_EXPORTED(reqh_service_ut);
127 
128 /*
129  * Local variables:
130  * c-indentation-style: "K&R"
131  * c-basic-offset: 8
132  * tab-width: 8
133  * fill-column: 80
134  * scroll-step: 1
135  * End:
136  */
uint64_t id
Definition: cob.h:240
struct m0_reqh_service * reqh_svc
Definition: rm_foms.c:49
M0_INTERNAL int m0_reqh_service_start(struct m0_reqh_service *service)
Definition: reqh_service.c:343
M0_INTERNAL void m0_ut_rpc_mach_init_and_add(struct m0_ut_rpc_mach_ctx *ctx)
#define NULL
Definition: misc.h:38
static void test_service(void)
Definition: service.c:72
static struct m0_semaphore sem
Definition: cp.c:32
#define M0_FOP_TYPE_INIT(ft,...)
Definition: fop.h:307
M0_INTERNAL int m0_reqh_fop_handle(struct m0_reqh *reqh, struct m0_fop *fop)
Definition: reqh.c:546
static int m0_reqhut_fop_init(void)
Definition: service.c:51
struct m0_rpc_machine rmc_rpc
struct m0_reqh_service_type ds1_service_type
Definition: cs_service.c:60
struct m0_cob_domain_id rmc_cob_id
void m0_fop_type_fini(struct m0_fop_type *fopt)
Definition: fop.c:232
static struct m0_fop_type m0_reqhut_dummy_fopt
Definition: service.c:45
static struct m0_ut_rpc_mach_ctx rmach_ctx
Definition: service.c:44
#define M0_SET0(obj)
Definition: misc.h:64
static struct m0_xcode_type ** xt[]
Definition: protocol.c:64
Definition: ut.h:77
const struct m0_sm_conf m0_generic_conf
Definition: fom_generic.c:838
M0_INTERNAL struct m0_reqh_service_type * m0_reqh_service_type_find(const char *sname)
Definition: reqh_service.c:168
int opcode
Definition: crate.c:301
int i
Definition: dir.c:1033
const char * name
Definition: trace.c:110
struct m0_ut_suite reqh_service_ut
Definition: service.c:117
M0_INTERNAL int m0_semaphore_init(struct m0_semaphore *semaphore, unsigned value)
Definition: semaphore.c:38
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
struct m0_reqh rmc_reqh
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
M0_INTERNAL void m0_reqh_idle_wait(struct m0_reqh *reqh)
Definition: reqh.c:606
const char * ts_name
Definition: ut.h:99
#define DUMMY_SERVER_ADDR
Definition: service.c:42
struct m0_reqh reqh
Definition: rm_foms.c:48
static const struct m0_fom_type_ops reqhut_fom_type_ops
Definition: reqhut_fom.c:35
const char * rmc_ep_addr
M0_INTERNAL void m0_ut_rpc_mach_fini(struct m0_ut_rpc_mach_ctx *ctx)
void m0_fop_put_lock(struct m0_fop *fop)
Definition: fop.c:199
static struct m0_fop * fop
Definition: item.c:57
static void m0_reqhut_fop_fini(void)
Definition: service.c:66
M0_INTERNAL void m0_semaphore_down(struct m0_semaphore *semaphore)
Definition: semaphore.c:49
#define DUMMY_COB_ID
Definition: service.c:41
int32_t rc
Definition: trigger_fop.h:47
#define M0_UT_ASSERT(a)
Definition: ut.h:46
Definition: fop.h:79
struct m0_fop * m0_fop_alloc(struct m0_fop_type *fopt, void *data, struct m0_rpc_machine *mach)
Definition: fop.c:96