Motr  M0
rpclib_ut.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-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 #include "ut/ut.h"
24 #include "lib/memory.h"
25 #include "lib/processor.h"
26 #include "lib/trace.h"
27 #include "lib/finject.h"
28 #include "fop/fop.h"
29 #include "reqh/reqh.h"
30 
31 #include "rpc/session.h"
32 #include "rpc/it/ping_fop.h"
33 #include "rpc/it/ping_fop_xc.h"
34 #include "rpc/rpclib.h"
35 #include "net/lnet/lnet.h"
36 
37 #include "ut/cs_service.h"
38 #include "ut/cs_fop.h"
39 #include "ut/cs_fop_xc.h"
40 
41 #include "rpc/ut/clnt_srv_ctx.c" /* sctx, cctx, MAX_RETRIES */
42 
43 #ifdef ENABLE_FAULT_INJECTION
44 static void test_m0_rpc_server_start(void)
45 {
46  int rc;
47 
48  m0_fi_enable_once("m0_cs_init", "fake_error");
49  sctx_reset();
51  M0_UT_ASSERT(rc != 0);
52 
53  m0_fi_enable_once("m0_cs_setup_env", "fake_error");
54  sctx_reset();
56  M0_UT_ASSERT(rc != 0);
57 }
58 
59 static void test_m0_rpc_client_start(void)
60 {
61  int rc;
62 
63  sctx_reset();
65  M0_UT_ASSERT(rc == 0);
66  if (rc != 0)
67  return;
68 
69  m0_fi_enable_once("m0_rpc_machine_init", "fake_error");
71 
72  m0_fi_enable_once("m0_net_end_point_create", "fake_error");
74 
75  m0_fi_enable_once("m0_rpc_conn_create", "fake_error");
77 
78  m0_fi_enable_once("m0_rpc_conn_establish", "fake_error");
80 
81  m0_fi_enable_once("m0_rpc_session_establish", "fake_error");
83 
85 }
86 
87 static void test_rpclib_error_paths(void)
88 {
91 }
92 #else
93 static void test_rpclib_error_paths(void)
94 {
95 }
96 #endif
97 
98 static int send_fop(struct m0_rpc_session *session)
99 {
100  int rc;
101  struct m0_fop *fop;
102  struct cs_ds2_req_fop *cs_ds2_fop;
103 
105  M0_UT_ASSERT(fop != NULL);
106  if (fop == NULL) {
107  rc = -ENOMEM;
108  goto out;
109  }
110 
111  cs_ds2_fop = m0_fop_data(fop);
112  cs_ds2_fop->csr_value = 0xaaf5;
113 
115  0 /* deadline */);
116  M0_UT_ASSERT(rc == 0);
119 
121 out:
122  return rc;
123 }
124 
125 static void test_rpclib(void)
126 {
127  int rc;
128 
129  /*
130  * There is no need to initialize xprt explicitly if client and server
131  * run within a single process, because in this case transport is
132  * initialized by m0_rpc_server_start().
133  */
134 
135  sctx_reset();
137  M0_UT_ASSERT(rc == 0);
138  if (rc != 0)
139  return;
141  M0_UT_ASSERT(rc == 0);
142  if (rc != 0)
143  goto server_fini;
144 
146  M0_UT_ASSERT(rc == 0);
147 
149  M0_UT_ASSERT(rc == 0);
150 
153  return;
154 }
155 
156 static int test_rpclib_init(void)
157 {
158  int rc;
160  M0_ASSERT(rc == 0);
161  return rc;
162 }
163 
164 static int test_rpclib_fini(void)
165 {
167  return 0;
168 }
169 
171  .ts_name = "rpc-lib-ut",
172  .ts_init = test_rpclib_init,
173  .ts_fini = test_rpclib_fini,
174  .ts_tests = {
175  { "rpclib", test_rpclib },
176  { "rpclib_error_paths", test_rpclib_error_paths },
177  { NULL, NULL }
178  }
179 };
180 
181 /*
182  * Local variables:
183  * c-indentation-style: "K&R"
184  * c-basic-offset: 8
185  * tab-width: 8
186  * fill-column: 80
187  * scroll-step: 1
188  * End:
189  */
static void test_m0_rpc_client_start(void)
Definition: rpclib_ut.c:59
static void test_rpclib_error_paths(void)
Definition: rpclib_ut.c:87
void m0_net_domain_fini(struct m0_net_domain *dom)
Definition: domain.c:71
struct m0_ut_suite rpclib_ut
Definition: rpclib_ut.c:170
#define NULL
Definition: misc.h:38
static void sctx_reset(void)
Definition: clnt_srv_ctx.c:68
int m0_rpc_server_start(struct m0_rpc_server_ctx *sctx)
Definition: rpclib.c:50
static int test_rpclib_fini(void)
Definition: rpclib_ut.c:164
int32_t ri_error
Definition: item.h:161
static struct m0_rpc_client_ctx cctx
Definition: rconfc.c:69
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:220
static struct m0_rpc_session session
Definition: formation2.c:38
Definition: ut.h:77
static void test_m0_rpc_server_start(void)
Definition: rpclib_ut.c:44
const struct m0_rpc_item_ops cs_ds_req_fop_rpc_item_ops
Definition: cs_fop.c:47
#define M0_ASSERT(cond)
int m0_rpc_client_stop(struct m0_rpc_client_ctx *cctx)
Definition: rpclib.c:217
struct m0_net_xprt * m0_net_xprt_default_get(void)
Definition: net.c:151
int m0_rpc_client_start(struct m0_rpc_client_ctx *cctx)
Definition: rpclib.c:160
struct m0_rpc_item * ri_reply
Definition: item.h:163
static struct m0_rpc_server_ctx sctx
Definition: console.c:88
static struct m0_net_domain client_net_dom
Definition: rconfc.c:47
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
static void server_fini(struct m0_stob_domain *bdom, uint64_t back_key)
Definition: reqh_fom_ut.c:292
struct m0_fop_type cs_ds2_req_fop_fopt
Definition: cs_fop.c:53
const char * ts_name
Definition: ut.h:99
int m0_net_domain_init(struct m0_net_domain *dom, const struct m0_net_xprt *xprt)
Definition: domain.c:36
struct m0_rpc_session rcx_session
Definition: rpclib.h:147
uint64_t csr_value
Definition: cs_fop.h:86
struct m0_fop * m0_fop_alloc_at(struct m0_rpc_session *sess, struct m0_fop_type *fopt)
Definition: fop.c:122
void m0_fop_put_lock(struct m0_fop *fop)
Definition: fop.c:199
static struct m0_fop * fop
Definition: item.c:57
static int test_rpclib_init(void)
Definition: rpclib_ut.c:156
static void m0_fi_enable_once(const char *func, const char *tag)
Definition: finject.h:301
void m0_rpc_server_stop(struct m0_rpc_server_ctx *sctx)
Definition: rpclib.c:85
static void test_rpclib(void)
Definition: rpclib_ut.c:125
static int send_fop(struct m0_rpc_session *session)
Definition: rpclib_ut.c:98
#define out(...)
Definition: gen.c:41
struct m0_rpc_item f_item
Definition: fop.h:83
int32_t rc
Definition: trigger_fop.h:47
#define M0_UT_ASSERT(a)
Definition: ut.h:46
Definition: fop.h:79