Motr  M0
fop_allow_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 "reqh/ut/service_xc.h" /* m0_xc_reqh_ut_service_init */
23 #include "rpc/rpc_opcodes.h" /* M0_REQH_UT_ALLOW_OPCODE */
24 #include "sss/ss_fops.h" /* m0_sss_req */
25 #include "ut/ut.h"
26 
27 #include "rpc/ut/clnt_srv_ctx.c"
28 #include "reqh/ut/reqhut_fom.c"
29 
30 static int fom_tick(struct m0_fom *fom);
31 
32 static char *ut_server_argv[] = {
33  "rpclib_ut", "-T", "AD", "-D", SERVER_DB_NAME,
34  "-f", M0_UT_CONF_PROCESS,
36  "-w", "10", "-e", SERVER_ENDPOINT, "-H", SERVER_ENDPOINT_ADDR,
37  "-c", M0_UT_PATH("conf.xc")
38 };
39 
42 };
43 
44 static const struct m0_fid ut_fid = {
45  .f_container = 0x7300000000000001,
46  .f_key = 26
47 };
48 
49 static const struct m0_fom_ops ut_fom_ops = {
51  .fo_tick = fom_tick,
52  .fo_home_locality = reqhut_find_fom_home_locality
53 };
54 
55 static int fom_create(struct m0_fop *fop,
56  struct m0_fom **out,
57  struct m0_reqh *reqh)
58 {
59  struct m0_fom *fom;
60  struct m0_fop *rfop;
61 
62  M0_PRE(fop != NULL);
63  M0_PRE(out != NULL);
64 
66  if (fom == NULL)
67  return -ENOMEM;
68 
70  M0_UT_ASSERT(rfop != NULL);
71 
73  fop, rfop, reqh);
74 
75  *out = fom;
76 
77  return 0;
78 }
79 
80 static const struct m0_fom_type_ops ut_fom_type_ops = {
82 };
83 
85 
86 static int m0_reqhut_fop_init(void)
87 {
88  m0_xc_reqh_ut_service_init();
89  m0_reqhut_dummy_xc->xct_flags = M0_XCODE_TYPE_FLAG_DOM_RPC;
91  .name = "Reqh unit test",
93  .xt = m0_reqhut_dummy_xc,
94  .fom_ops = &ut_fom_type_ops,
95  .sm = &m0_generic_conf,
96  .rpc_flags = M0_RPC_ITEM_TYPE_REQUEST,
97  .svc_type = &ds1_service_type);
98  return 0;
99 }
100 
101 static void m0_reqhut_fop_fini(void)
102 {
104  m0_xc_reqh_ut_service_fini();
105 }
106 
107 static int fom_tick(struct m0_fom *fom)
108 {
109  if (m0_fom_phase(fom) < M0_FOPH_NR)
110  return m0_fom_tick_generic(fom);
111 
113  return M0_FSO_AGAIN;
114 }
115 
116 static int send_fop()
117 {
118  struct m0_fop *fop;
119  int rc;
120 
122  M0_UT_ASSERT(fop != NULL);
123 
126 
127  return rc;
128 }
129 
130 static struct m0_fop *ut_ssfop_alloc(const char *name, uint32_t cmd)
131 {
132  struct m0_fop *fop;
133  struct m0_sss_req *ss_fop;
134 
135  M0_ALLOC_PTR(fop);
136  M0_UT_ASSERT(fop != NULL);
137 
138  M0_ALLOC_PTR(ss_fop);
139  M0_UT_ASSERT(ss_fop != NULL);
140 
141  m0_buf_init(&ss_fop->ss_name, (void *)name, strlen(name));
142  ss_fop->ss_cmd = cmd;
143  ss_fop->ss_id = ut_fid;
144 
145  m0_fop_init(fop, &m0_fop_ss_fopt, (void *)ss_fop, m0_ss_fop_release);
146 
147  return fop;
148 
149 }
150 
151 static void ut_sss_req(const char *name, uint32_t cmd, int expected_rc,
152  int expected_state)
153 {
154  int rc;
155  struct m0_fop *fop;
156  struct m0_fop *rfop;
157  struct m0_rpc_item *item;
158  struct m0_sss_rep *ss_rfop;
159 
160  fop = ut_ssfop_alloc(name, cmd);
161  item = &fop->f_item;
162 
164  M0_UT_ASSERT(rc == 0);
165 
167  M0_UT_ASSERT(rfop != NULL);
168 
169  ss_rfop = m0_fop_data(rfop);
170  M0_UT_ASSERT(ss_rfop->ssr_rc == expected_rc);
171  if (expected_state != 0)
174 }
175 
176 static void fop_allow_test(void)
177 {
178  int rc;
179 
182 
184  M0_UT_ASSERT(rc == 0);
185 
193 
194  rc = send_fop();
195  M0_UT_ASSERT(rc == -ECONNREFUSED);
196 
197  /* Test reposting of the fop in case of failure. */
198  rc = send_fop();
199  M0_UT_ASSERT(rc == -ECONNREFUSED);
200 
205  rc = send_fop();
206  M0_UT_ASSERT(rc == 0);
207 
210 }
211 
213  .ts_name = "reqh-fop-allow-ut",
214  .ts_tests = {
215  { "reqh-fop-allow", fop_allow_test },
216  { NULL, NULL }
217  }
218 };
219 M0_EXPORTED(reqh_fop_allow_ut);
220 
221 /*
222  * Local variables:
223  * c-indentation-style: "K&R"
224  * c-basic-offset: 8
225  * tab-width: 8
226  * fill-column: 80
227  * scroll-step: 1
228  * End:
229  */
struct m0_ut_suite reqh_fop_allow_ut
Definition: fop_allow_ut.c:212
struct m0_reqh_service_type * ut_stypes[]
Definition: fop_allow_ut.c:40
static int send_fop()
Definition: fop_allow_ut.c:116
#define M0_PRE(cond)
#define NULL
Definition: misc.h:38
#define M0_FOP_TYPE_INIT(ft,...)
Definition: fop.h:307
uint32_t ssr_state
Definition: ss_fops.h:86
M0_INTERNAL void m0_fop_init(struct m0_fop *fop, struct m0_fop_type *fopt, void *data, void(*fop_release)(struct m0_ref *))
Definition: fop.c:79
char ** rsx_argv
Definition: rpclib.h:77
static int fom_create(struct m0_fop *fop, struct m0_fom **out, struct m0_reqh *reqh)
Definition: fop_allow_ut.c:55
int(* fto_create)(struct m0_fop *fop, struct m0_fom **out, struct m0_reqh *reqh)
Definition: fom.h:650
struct m0_reqh_service_type ds1_service_type
Definition: cs_service.c:60
M0_INTERNAL void m0_buf_init(struct m0_buf *buf, void *data, uint32_t nob)
Definition: buf.c:37
static const struct m0_fid ut_fid
Definition: fop_allow_ut.c:44
static struct m0_rpc_client_ctx cctx
Definition: rconfc.c:69
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:220
void m0_fop_type_fini(struct m0_fop_type *fopt)
Definition: fop.c:232
struct m0_fop_type m0_fop_ss_fopt
Definition: ss_fops.c:39
uint32_t ss_cmd
Definition: ss_fops.h:61
static const struct m0_fom_type_ops ut_fom_type_ops
Definition: fop_allow_ut.c:80
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
static struct m0_rpc_item * item
Definition: item.c:56
#define SERVER_STOB_NAME
Definition: filterc_ut.c:53
static int m0_reqhut_fop_init(void)
Definition: fop_allow_ut.c:86
m0_fom_phase
Definition: fom.h:372
struct m0_fom_type ft_fom_type
Definition: fop.h:232
static void ut_sss_req(const char *name, uint32_t cmd, int expected_rc, int expected_state)
Definition: fop_allow_ut.c:151
#define SERVER_DB_NAME
Definition: filterc_ut.c:52
int opcode
Definition: crate.c:301
void m0_fom_init(struct m0_fom *fom, const struct m0_fom_type *fom_type, const struct m0_fom_ops *ops, struct m0_fop *fop, struct m0_fop *reply, struct m0_reqh *reqh)
Definition: fom.c:1372
struct m0_fop_type * f_type
Definition: fop.h:81
struct m0_fid ss_id
Definition: ss_fops.h:71
static const struct m0_fom_ops ut_fom_ops
Definition: fop_allow_ut.c:49
const char * name
Definition: trace.c:110
struct m0_buf ss_name
Definition: ss_fops.h:66
int m0_fom_tick_generic(struct m0_fom *fom)
Definition: fom_generic.c:848
const char * rst_name
Definition: reqh_service.h:447
static void stop_rpc_client_and_server(void)
Definition: note.c:126
static struct m0_fop_type m0_reqhut_allow_fopt
Definition: fop_allow_ut.c:84
struct m0_rpc_item * ri_reply
Definition: item.h:163
static struct m0_rpc_server_ctx sctx
Definition: console.c:88
int m0_rpc_post_sync(struct m0_fop *fop, struct m0_rpc_session *session, const struct m0_rpc_item_ops *ri_ops, m0_time_t deadline)
Definition: rpclib.c:284
uint64_t f_container
Definition: fid.h:39
#define SERVER_ENDPOINT
Definition: common.h:31
#define SERVER_ADDB_STOB_NAME
Definition: filterc_ut.c:54
Definition: reqh.h:94
Definition: dump.c:103
static struct m0_fop * ut_ssfop_alloc(const char *name, uint32_t cmd)
Definition: fop_allow_ut.c:130
static void m0_reqhut_fop_fini(void)
Definition: fop_allow_ut.c:101
static char * ut_server_argv[]
Definition: fop_allow_ut.c:32
struct m0_fop_type m0_fop_generic_reply_fopt
Definition: fom_generic.c:50
struct m0_fop * m0_fop_reply_alloc(struct m0_fop *req, struct m0_fop_type *rept)
Definition: fop.c:129
M0_INTERNAL void m0_ss_fop_release(struct m0_ref *ref)
Definition: ss_fops.c:96
Definition: fom.h:481
const char * ts_name
Definition: ut.h:99
struct m0_reqh reqh
Definition: rm_foms.c:48
struct m0_rpc_session rcx_session
Definition: rpclib.h:147
Definition: fid.h:38
static void fop_allow_test(void)
Definition: fop_allow_ut.c:176
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
#define M0_UT_CONF_PROCESS
Definition: misc.h:45
static void reqhut_fom_fini(struct m0_fom *fom)
Definition: reqhut_fom.c:73
void m0_fop_put_lock(struct m0_fop *fop)
Definition: fop.c:199
static struct m0_fop * fop
Definition: item.c:57
struct m0_fop * m0_rpc_item_to_fop(const struct m0_rpc_item *item)
Definition: fop.c:346
void(* fo_fini)(struct m0_fom *fom)
Definition: fom.h:657
struct m0_rpc_machine rcx_rpc_machine
Definition: rpclib.h:145
#define SERVER_ENDPOINT_ADDR
Definition: common.h:30
int32_t ssr_rc
Definition: ss_fops.h:81
#define M0_UT_PATH(name)
Definition: misc.h:41
#define out(...)
Definition: gen.c:41
void m0_fom_phase_set(struct m0_fom *fom, int phase)
Definition: fom.c:1688
static enum m0_ha_obj_state expected_state
Definition: item.c:50
static int fom_tick(struct m0_fom *fom)
Definition: fop_allow_ut.c:107
struct m0_rpc_item f_item
Definition: fop.h:83
static size_t reqhut_find_fom_home_locality(const struct m0_fom *fom)
Definition: reqhut_fom.c:60
int32_t rc
Definition: trigger_fop.h:47
#define ARRAY_SIZE(a)
Definition: misc.h:45
static void start_rpc_client_and_server(void)
Definition: note.c:111
#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