Motr  M0
spiel_ut_common.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-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_SPIEL
24 #include "lib/trace.h"
25 
27 #include "spiel/spiel.h"
28 #include "ut/misc.h" /* M0_UT_CONF_PROFILE */
29 #include "ut/ut.h"
30 
32 const char *confd_addr[] = { SERVER_ENDPOINT_ADDR, NULL };
34 
35 static int m0_spiel__ut_rms_start(struct m0_reqh *reqh)
36 {
37  struct m0_reqh_service *service;
38  struct m0_fid fid;
39 
42 }
43 
45  const char *ep_addr)
46 {
47  enum { NR_TMS = 1 };
48  int rc;
49 
53  if (rc != 0)
54  return rc;
55 
60  NR_TMS),
61  NR_TMS);
62  if (rc != 0)
63  goto net;
64 
66  .rhia_dtm = (void *)1,
67  .rhia_mdstore = (void *)1,
68  .rhia_fid = &g_process_fid,
69  );
70  if (rc != 0)
71  goto buf_pool;
72 
79  if (rc != 0)
80  goto reqh;
83  if (rc != 0)
84  goto rm;
85  return 0;
86 rm:
88 reqh:
90 buf_pool:
92 net:
94  return rc;
95 }
96 
98 {
104 }
105 
106 M0_INTERNAL int m0_spiel__ut_rpc_server_start(struct m0_rpc_server_ctx *rpc_srv,
107  const char *ha_ep,
108  const char *confdb_path)
109 {
110  enum {
111  LOG_NAME_MAX_LEN = 128,
112  EP_MAX_LEN = 24,
113  RPC_SIZE_MAX_LEN = 32,
114  };
115 
116  char log_name[LOG_NAME_MAX_LEN];
117  char full_ep[EP_MAX_LEN];
118  char max_rpc_size[RPC_SIZE_MAX_LEN];
119 
120  snprintf(full_ep, EP_MAX_LEN, "%s:%s", M0_NET_XPRT_PREFIX_DEFAULT,
121  ha_ep);
122  snprintf(max_rpc_size, RPC_SIZE_MAX_LEN,
124 
125 #define NAME(ext) "ut_spiel" ext
126  char *argv[] = {
127  NAME(""), "-T", "AD", "-D", NAME(".db"), "-S", NAME(".stob"),
128  "-A", "linuxstob:"NAME("-addb_stob"), "-w", "10",
129  "-e", full_ep, "-H", (char *)ha_ep, "-f", M0_UT_CONF_PROCESS,
130  "-m", max_rpc_size, "-G", full_ep,
131  "-c", (char *)confdb_path
132  };
133 #undef NAME
134 
135  M0_SET0(rpc_srv);
136 
137  rpc_srv->rsx_xprts = m0_net_all_xprt_get();
138  rpc_srv->rsx_xprts_nr = m0_net_xprt_nr();
139  rpc_srv->rsx_argv = argv;
140  /* if !run_io_srv then remove last row of argv array */
141  rpc_srv->rsx_argc = ARRAY_SIZE(argv);
142  snprintf(log_name, LOG_NAME_MAX_LEN, "confd_%s.log", ha_ep);
143  rpc_srv->rsx_log_file_name = log_name;
144 
145  return m0_rpc_server_start(rpc_srv);
146 }
147 
148 M0_INTERNAL void m0_spiel__ut_rpc_server_stop(struct m0_rpc_server_ctx *rpc_srv)
149 {
150  m0_rpc_server_stop(rpc_srv);
151 }
152 
153 M0_INTERNAL void m0_spiel__ut_init(struct m0_spiel *spiel,
154  const char *confd_path,
155  bool cmd_iface)
156 {
157  int rc;
158  const char *client_ep = CLIENT_ENDPOINT_ADDR;
159  const char *profile = M0_UT_CONF_PROFILE;
160 
161  rc = m0_spiel__ut_reqh_init(&ut_reqh, client_ep);
162  M0_UT_ASSERT(rc == 0);
163 
165  confd_addr[0],
166  confd_path);
167  M0_UT_ASSERT(rc == 0);
168 
170  M0_UT_ASSERT(rc == 0);
172  M0_UT_ASSERT(rc == 0);
173  if (cmd_iface) {
175  M0_UT_ASSERT(rc == 0);
176  }
177 }
178 
179 M0_INTERNAL void m0_spiel__ut_fini(struct m0_spiel *spiel, bool cmd_iface)
180 {
181  if (cmd_iface)
186 }
187 
188 #undef M0_TRACE_SUBSYSTEM
189 
190 /*
191  * Local variables:
192  * c-indentation-style: "K&R"
193  * c-basic-offset: 8
194  * tab-width: 8
195  * fill-column: 80
196  * scroll-step: 1
197  * End:
198  */
int m0_spiel_cmd_profile_set(struct m0_spiel *spiel, const char *profile_str)
Definition: spiel.c:100
const char * rm_addr
#define M0_UT_CONF_PROFILE
Definition: misc.h:43
void m0_rpc_machine_fini(struct m0_rpc_machine *machine)
Definition: rpc_machine.c:233
struct m0_spiel_ut_reqh ut_reqh
M0_INTERNAL void m0_reqh_services_terminate(struct m0_reqh *reqh)
Definition: reqh.c:675
void m0_net_domain_fini(struct m0_net_domain *dom)
Definition: domain.c:71
#define NULL
Definition: misc.h:38
static const char * ep_addr
Definition: rpc_machine.c:35
#define M0_REQH_INIT(reqh,...)
Definition: reqh.h:262
char ** rsx_argv
Definition: rpclib.h:77
uint8_t ft_id
Definition: fid.h:101
const struct m0_conf_obj_type M0_CONF_SERVICE_TYPE
Definition: service.c:156
int m0_rpc_server_start(struct m0_rpc_server_ctx *sctx)
Definition: rpclib.c:50
struct m0_rpc_server_ctx sur_confd_srv
void m0_spiel_fini(struct m0_spiel *spiel)
Definition: spiel.c:59
void m0_spiel_rconfc_stop(struct m0_spiel *spiel)
Definition: spiel.c:91
M0_INTERNAL int m0_spiel__ut_reqh_init(struct m0_spiel_ut_reqh *spl_reqh, const char *ep_addr)
static int m0_spiel__ut_rms_start(struct m0_reqh *reqh)
#define M0_SET0(obj)
Definition: misc.h:64
#define CLIENT_ENDPOINT_ADDR
Definition: common.h:32
M0_INTERNAL void m0_reqh_fini(struct m0_reqh *reqh)
Definition: reqh.c:320
#define NAME(ext)
struct m0_fid fid
Definition: di.c:46
M0_INTERNAL void m0_spiel__ut_fini(struct m0_spiel *spiel, bool cmd_iface)
M0_INTERNAL void m0_spiel__ut_reqh_fini(struct m0_spiel_ut_reqh *spl_reqh)
M0_INTERNAL int m0_spiel__ut_rpc_server_start(struct m0_rpc_server_ctx *rpc_srv, const char *ha_ep, const char *confdb_path)
const char * rsx_log_file_name
Definition: rpclib.h:81
#define M0_NET_XPRT_PREFIX_DEFAULT
Definition: net.h:98
const struct m0_fid_type cot_ftype
Definition: obj.h:314
M0_INTERNAL void m0_fid_tgenerate(struct m0_fid *fid, const uint8_t tid)
Definition: fid.c:155
M0_INTERNAL int m0_rpc_net_buffer_pool_setup(struct m0_net_domain *ndom, struct m0_net_buffer_pool *app_pool, uint32_t bufs_nr, uint32_t tm_nr)
Definition: rpc.c:229
M0_INTERNAL uint32_t m0_rpc_bufs_nr(uint32_t len, uint32_t tms_nr)
Definition: rpc.c:271
int m0_net_xprt_nr(void)
Definition: net.c:168
struct m0_reqh sur_reqh
const char * confd_addr[]
M0_INTERNAL int m0_rpc_machine_init(struct m0_rpc_machine *machine, struct m0_net_domain *net_dom, const char *ep_addr, struct m0_reqh *reqh, struct m0_net_buffer_pool *receive_pool, uint32_t colour, m0_bcount_t msg_size, uint32_t queue_len)
Definition: rpc_machine.c:123
struct m0_net_xprt * m0_net_xprt_default_get(void)
Definition: net.c:151
struct m0_net_xprt ** rsx_xprts
Definition: rpclib.h:69
struct m0_net_domain sur_net_dom
Definition: reqh.h:94
M0_INTERNAL int m0_reqh_service_setup(struct m0_reqh_service **out, struct m0_reqh_service_type *stype, struct m0_reqh *reqh, struct m0_reqh_context *rctx, const struct m0_fid *fid)
Definition: reqh_service.c:565
M0_INTERNAL void m0_spiel__ut_init(struct m0_spiel *spiel, const char *confd_path, bool cmd_iface)
static struct m0_spiel_ut_reqh * spl_reqh
Definition: spiel_ut.c:31
struct m0_rpc_machine sur_rmachine
struct m0_reqh_service_type m0_rms_type
Definition: rm_service.c:69
M0_INTERNAL void m0_reqh_start(struct m0_reqh *reqh)
Definition: reqh.c:711
struct m0_reqh reqh
Definition: rm_foms.c:48
static struct m0_fid profile
Definition: rconfc.c:49
int m0_spiel_rconfc_start(struct m0_spiel *spiel, m0_rconfc_cb_t expired_cb)
Definition: spiel.c:66
int m0_net_domain_init(struct m0_net_domain *dom, const struct m0_net_xprt *xprt)
Definition: domain.c:36
int rsx_xprts_nr
Definition: rpclib.h:71
Definition: fid.h:38
#define M0_UT_CONF_PROCESS
Definition: misc.h:45
struct m0_net_xprt ** m0_net_all_xprt_get(void)
Definition: net.c:161
struct m0_spiel spiel
Definition: spiel_conf_ut.c:42
struct m0_net_buffer_pool sur_buf_pool
void m0_rpc_server_stop(struct m0_rpc_server_ctx *sctx)
Definition: rpclib.c:85
static struct m0_addb2_net * net
Definition: net.c:27
static struct m0_net_buffer_pool * buf_pool
Definition: bulkio_ut.c:261
#define SERVER_ENDPOINT_ADDR
Definition: common.h:30
M0_INTERNAL void m0_spiel__ut_rpc_server_stop(struct m0_rpc_server_ctx *rpc_srv)
void m0_rpc_net_buffer_pool_cleanup(struct m0_net_buffer_pool *app_pool)
Definition: rpc.c:264
static struct m0_reqh_service * service[REQH_IN_UT_MAX]
Definition: long_lock_ut.c:46
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
int m0_spiel_init(struct m0_spiel *spiel, struct m0_reqh *reqh)
Definition: spiel.c:44