Motr  M0
fis_ut.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2017-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 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_UT
24 #include "lib/trace.h"
25 
26 #include "lib/finject.h"
27 #include "conf/ut/common.h" /* CLIENT_ENDPOINT_ADDR, SERVER_ENDPOINT_ADDR */
28 #include "fis/fi_command.h"
29 #include "rpc/rpclib.h" /* m0_rpc_server_ctx, m0_rpc_client_ctx */
30 #include "ut/misc.h" /* M0_UT_CONF_PROCESS */
31 #include "ut/ut.h"
32 
33 enum {
35 };
36 
38 static struct m0_rpc_client_ctx cctx = {
40  .rcx_local_addr = CLIENT_ENDPOINT_ADDR,
41  .rcx_remote_addr = SERVER_ENDPOINT_ADDR,
42  .rcx_max_rpcs_in_flight = MAX_RPCS_IN_FLIGHT,
43  .rcx_fid = &g_process_fid,
44 };
45 
47 {
48  int rc;
49 #define NAME(ext) "fis-ut" ext
50  char *argv[] = {
51  NAME(""), "-T", "AD", "-D", NAME(".db"), "-j" /* fis enabled */,
52  "-S", NAME(".stob"), "-A", "linuxstob:"NAME("-addb.stob"),
53  "-w", "10", "-e", SERVER_ENDPOINT, "-H", SERVER_ENDPOINT_ADDR,
54  "-f", M0_UT_CONF_PROCESS,
55  "-c", M0_SRC_PATH("fis/ut/fis.xc")
56  };
57  *rctx = (struct m0_rpc_server_ctx) {
58  .rsx_xprts = m0_net_all_xprt_get(),
59  .rsx_xprts_nr = m0_net_xprt_nr(),
60  .rsx_argv = argv,
61  .rsx_argc = ARRAY_SIZE(argv),
62  .rsx_log_file_name = NAME(".log")
63  };
64 #undef NAME
66  M0_UT_ASSERT(rc == 0);
67 }
68 
70 {
72 }
73 
74 static void fis_ut_client_start(void)
75 {
76  int rc;
77 
79  M0_UT_ASSERT(rc == 0);
81  M0_UT_ASSERT(rc == 0);
82 }
83 
84 static void fis_ut_client_stop(void)
85 {
86  int rc = m0_rpc_client_stop(&cctx);
87  M0_UT_ASSERT(rc == 0);
89 }
90 
91 static bool fault_is_injected(void)
92 {
93  return M0_FI_ENABLED("test");
94 }
95 
96 extern struct m0_fop_type m0_fic_req_fopt;
97 
98 static void test_fi_command_post(void)
99 {
100  struct m0_rpc_server_ctx rctx;
101  const char *func = "fault_is_injected";
102  const char *tag = "test";
103  int rc;
104 
105  /* test enabled state */
106  m0_fi_enable(func, tag);
108 
109  m0_fi_disable(func, tag);
110  /* test disabled state */
112 
113  /* Now do control FI via Fault Injection Service */
116 
118  M0_FI_DISP_ENABLE, 0, 0);
119  M0_UT_ASSERT(rc == 0);
120  /* test enabled state */
122  /* make sure of being still enabled */
124 
126  M0_FI_DISP_DISABLE, 0, 0);
127  M0_UT_ASSERT(rc == 0);
128  /* test disabled state */
130 
132  M0_FI_DISP_ENABLE_ONCE, 0, 0);
133  M0_UT_ASSERT(rc == 0);
134  /* make sure of exactly one shot */
137 
139  M0_FI_DISP_RANDOMIZE, 0, 0);
140  M0_UT_ASSERT(rc == 0);
142  M0_FI_DISP_DISABLE, 0, 0);
143  M0_UT_ASSERT(rc == 0);
144 
147  M0_UT_ASSERT(rc == 0);
151 
153  M0_FI_DISP_DISABLE, 0, 0);
154  M0_UT_ASSERT(rc == 0);
156 
157  /* make sure unsupported disposition value not welcomed */
158  rc = m0_fi_command_post_sync(&cctx.rcx_session, func, tag, 255, 0, 0);
159  M0_UT_ASSERT(rc == -EINVAL);
160 
163 }
164 
165 static void test_fi_command_post_fail(void)
166 {
167  struct m0_rpc_server_ctx rctx;
168  const char *func = "fault_is_injected";
169  const char *tag = "test";
170  int rc;
171 
174 
175  /*
176  * Inject 'no_mem' fault to prevent FOM creation. Rpc post is to result
177  * in standard timeout error. Please be prepared to wait for a solid
178  * minute.
179  */
180  m0_fi_enable_once("fi_command_fom_create", "no_mem");
182  M0_FI_DISP_ENABLE, 0, 0);
183  M0_UT_ASSERT(rc == -ETIMEDOUT);
185 
188 }
189 
190 struct m0_ut_suite fis_ut = {
191  .ts_name = "fis-ut",
192  .ts_tests = {
193  { "post", test_fi_command_post },
194  { "post-fail", test_fi_command_post_fail },
195  { NULL, NULL }
196  },
197  .ts_owners = "IV",
198 };
199 
200 #undef M0_TRACE_SUBSYSTEM
201 
202 /*
203  * Local variables:
204  * c-indentation-style: "K&R"
205  * c-basic-offset: 8
206  * tab-width: 8
207  * fill-column: 80
208  * scroll-step: 1
209  * End:
210  */
void m0_net_domain_fini(struct m0_net_domain *dom)
Definition: domain.c:71
#define NULL
Definition: misc.h:38
static uint64_t tag(uint8_t code, uint64_t id)
Definition: addb2.c:1047
int m0_rpc_server_start(struct m0_rpc_server_ctx *sctx)
Definition: rpclib.c:50
static void fis_ut_client_start(void)
Definition: fis_ut.c:74
static struct m0_net_domain client_net_dom
Definition: fis_ut.c:37
#define M0_SRC_PATH(name)
Definition: misc.h:48
#define CLIENT_ENDPOINT_ADDR
Definition: common.h:32
Definition: ut.h:77
static struct m0_rpc_client_ctx cctx
Definition: fis_ut.c:38
struct m0_reqh_context rctx
M0_INTERNAL void m0_fi_disable(const char *fp_func, const char *fp_tag)
Definition: finject.c:485
static void m0_fi_enable(const char *func, const char *tag)
Definition: finject.h:276
static void test_fi_command_post_fail(void)
Definition: fis_ut.c:165
int m0_net_xprt_nr(void)
Definition: net.c:168
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_ut_suite fis_ut
Definition: fis_ut.c:190
#define SERVER_ENDPOINT
Definition: common.h:31
static void fis_ut_motr_start(struct m0_rpc_server_ctx *rctx)
Definition: fis_ut.c:46
struct m0_net_domain * rcx_net_dom
Definition: rpclib.h:128
M0_INTERNAL int m0_fi_command_post_sync(struct m0_rpc_session *sess, const char *func, const char *tag, enum m0_fi_disp disp, uint32_t num1, uint32_t num2)
Definition: fi_command.c:56
static void fis_ut_motr_stop(struct m0_rpc_server_ctx *rctx)
Definition: fis_ut.c:69
static bool fault_is_injected(void)
Definition: fis_ut.c:91
const char * ts_name
Definition: ut.h:99
static void test_fi_command_post(void)
Definition: fis_ut.c:98
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
#define M0_FI_ENABLED(tag)
Definition: finject.h:231
#define M0_UT_CONF_PROCESS
Definition: misc.h:45
struct m0_net_xprt ** m0_net_all_xprt_get(void)
Definition: net.c:161
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
#define SERVER_ENDPOINT_ADDR
Definition: common.h:30
struct m0_fop_type m0_fic_req_fopt
int32_t rc
Definition: trigger_fop.h:47
#define ARRAY_SIZE(a)
Definition: misc.h:45
struct m0_fid g_process_fid
Definition: ut.c:689
#define M0_UT_ASSERT(a)
Definition: ut.h:46
static void fis_ut_client_stop(void)
Definition: fis_ut.c:84
#define NAME(ext)