Motr  M0
long_lock_ut.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-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 "ut/ut.h"
23 #include "fop/fop.h"
24 #include "reqh/reqh.h"
25 #include "rpc/rpclib.h"
26 #include "rpc/rpc_opcodes.h" /* M0_UT_RDWR_OPCODE */
27 #include "net/lnet/lnet.h"
28 #include "fop/fom_generic.h" /* m0_generic_conf */
29 #include "ut/ut_rpc_machine.h"
30 
31 enum {
34 };
35 
38 
39 static const char *ll_serv_addr[] = { "0@lo:12345:34:1",
40  "0@lo:12345:34:2"
41 };
42 
43 static const int ll_cob_ids[] = { 20, 30 };
44 
47 extern struct m0_fom_type rdwr_fom_type;
48 extern const struct m0_fom_type_ops fom_rdwr_type_ops;
49 
50 static void test_long_lock_n(void)
51 {
52  static struct m0_reqh *r[REQH_IN_UT_MAX] = { &rmach_ctx[0].rmc_reqh,
53  &rmach_ctx[1].rmc_reqh };
55 }
56 
57 static void test_long_lock_1(void)
58 {
59  static struct m0_reqh *r[1] = { &rmach_ctx[0].rmc_reqh };
60 
61  rdwr_send_fop(r, 1);
62 }
63 
65 {
66  M0_PRE(service != NULL);
67  return 0;
68 }
69 
71 {
72  M0_PRE(service != NULL);
73 }
74 
76 {
77  M0_PRE(service != NULL);
79 }
80 
83  .rso_stop = ut_long_lock_service_stop,
84  .rso_fini = ut_long_lock_service_fini
85 };
86 
87 static int
89  const struct m0_reqh_service_type *stype)
90 {
91  struct m0_reqh_service *serv;
92 
93  M0_PRE(stype != NULL && service != NULL);
94 
95  M0_ALLOC_PTR(serv);
96  M0_ASSERT(serv != NULL);
97 
98  serv->rs_type = stype;
100  *service = serv;
101  return 0;
102 }
103 
106 };
107 
109  .rst_name = "ut-long-lock-service",
110  .rst_ops = &ut_long_lock_service_type_ops,
111  .rst_level = M0_RS_LEVEL_NORMAL,
112 };
113 
114 static int test_long_lock_init(void)
115 {
116  int rc;
117  int i;
118 
120  M0_ASSERT(rc == 0);
123  &m0_generic_conf);
124  /*
125  * Instead of using m0d and dealing with network, database and
126  * other subsystems, request handler is initialised in a 'special way'.
127  * This allows it to operate in a 'limited mode' which is enough for
128  * this test.
129  */
130  for (i = 0; i < REQH_IN_UT_MAX; ++i) {
131  M0_SET0(&rmach_ctx[i]);
135  }
136  for (i = 0; i < REQH_IN_UT_MAX; ++i) {
139  M0_ASSERT(rc == 0);
140  m0_reqh_service_init(service[i], &rmach_ctx[i].rmc_reqh, NULL);
142  M0_ASSERT(rc == 0);
143  }
144  return rc;
145 }
146 
147 static int test_long_lock_fini(void)
148 {
149  int i;
150 
151  for (i = 0; i < REQH_IN_UT_MAX; ++i)
153 
155 
156  return 0;
157 }
158 
160  .ts_name = "fop-lock-ut",
161  .ts_init = test_long_lock_init,
162  .ts_fini = test_long_lock_fini,
163  .ts_tests = {
164  { "fop-lock-1reqh", test_long_lock_1 },
165  { "fop-lock-2reqh", test_long_lock_n },
166  { NULL, NULL }
167  }
168 };
169 
170 /*
171  * Local variables:
172  * c-indentation-style: "K&R"
173  * c-basic-offset: 8
174  * tab-width: 8
175  * fill-column: 80
176  * scroll-step: 1
177  * End:
178  */
uint64_t id
Definition: cob.h:240
static void ut_long_lock_service_fini(struct m0_reqh_service *service)
Definition: long_lock_ut.c:75
#define M0_PRE(cond)
M0_INTERNAL int m0_reqh_service_start(struct m0_reqh_service *service)
Definition: reqh_service.c:343
const struct m0_fom_type_ops fom_rdwr_type_ops
Definition: rdwr_fom.c:56
M0_INTERNAL void m0_ut_rpc_mach_init_and_add(struct m0_ut_rpc_mach_ctx *ctx)
int(* rso_start)(struct m0_reqh_service *service)
Definition: reqh_service.h:360
#define NULL
Definition: misc.h:38
static const int ll_cob_ids[]
Definition: long_lock_ut.c:43
static const struct m0_reqh_service_ops ut_long_lock_service_ops
Definition: long_lock_ut.c:81
static const struct m0_reqh_service_type_ops ut_long_lock_service_type_ops
Definition: long_lock_ut.c:104
struct m0_cob_domain_id rmc_cob_id
#define M0_SET0(obj)
Definition: misc.h:64
Definition: ut.h:77
const struct m0_sm_conf m0_generic_conf
Definition: fom_generic.c:838
int m0_reqh_service_type_register(struct m0_reqh_service_type *rstype)
Definition: reqh_service.c:473
static int test_long_lock_init(void)
Definition: long_lock_ut.c:114
struct m0_fom_type rdwr_fom_type
Definition: rdwr_fom.c:61
int i
Definition: dir.c:1033
static const char * ll_serv_addr[]
Definition: long_lock_ut.c:39
static const struct socktype stype[]
Definition: sock.c:1156
#define M0_ASSERT(cond)
const char * rst_name
Definition: reqh_service.h:447
M0_INTERNAL void m0_fom_type_init(struct m0_fom_type *type, uint64_t id, const struct m0_fom_type_ops *ops, const struct m0_reqh_service_type *svc_type, const struct m0_sm_conf *sm)
Definition: fom.c:1596
static void test_long_lock_1(void)
Definition: long_lock_ut.c:57
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
static int ut_long_lock_service_allocate(struct m0_reqh_service **service, const struct m0_reqh_service_type *stype)
Definition: long_lock_ut.c:88
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
const char * ts_name
Definition: ut.h:99
int(* rsto_service_allocate)(struct m0_reqh_service **service, const struct m0_reqh_service_type *stype)
Definition: reqh_service.h:435
static void rdwr_send_fop(struct m0_reqh **reqh, size_t reqh_nr)
const struct m0_reqh_service_type * rs_type
Definition: reqh_service.h:227
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
static void test_long_lock_n(void)
Definition: long_lock_ut.c:50
static int r[NR]
Definition: thread.c:46
const char * rmc_ep_addr
static void ut_long_lock_service_stop(struct m0_reqh_service *service)
Definition: long_lock_ut.c:70
M0_INTERNAL void m0_ut_rpc_mach_fini(struct m0_ut_rpc_mach_ctx *ctx)
static struct m0_ut_rpc_mach_ctx rmach_ctx[REQH_IN_UT_MAX]
Definition: long_lock_ut.c:45
static int test_long_lock_fini(void)
Definition: long_lock_ut.c:147
void m0_free(void *data)
Definition: memory.c:146
struct m0_reqh_service_type ut_long_lock_service_type
Definition: long_lock_ut.c:108
void m0_reqh_service_type_unregister(struct m0_reqh_service_type *rstype)
Definition: reqh_service.c:490
static struct m0_reqh_service * service[REQH_IN_UT_MAX]
Definition: long_lock_ut.c:46
int32_t rc
Definition: trigger_fop.h:47
static int ut_long_lock_service_start(struct m0_reqh_service *service)
Definition: long_lock_ut.c:64
const struct m0_reqh_service_ops * rs_ops
Definition: reqh_service.h:254
struct m0_ut_suite m0_fop_lock_ut
Definition: long_lock_ut.c:159