Motr  M0
st_main.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 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 #include <stdlib.h>
23 #include <stdio.h>
24 #include <unistd.h>
25 #include <ucontext.h> /* getcontext */
26 #include <signal.h> /* struct stack */
27 #include <assert.h> /* assert */
28 
29 #include "lib/getopts.h"
30 #include "lib/thread.h"
31 #include "motr/client.h"
32 #include "motr/idx.h"
33 #include "motr/st/st.h"
34 #include "motr/st/st_misc.h"
35 #include "motr/st/st_assert.h"
36 
38  IDX_MOTR = 1,
40 };
41 
42 /* Client parameters */
43 static char *local_addr;
44 static char *ha_addr;
45 static char *prof;
46 static char *proc_fid;
47 static char *tests;
49 static struct m0_config conf;
50 
51 #include "motr/client_internal.h"
52 #include "sm/sm.h"
53 
56 
57 static int st_init_instance(void)
58 {
59  int rc;
60  struct m0_client *instance = NULL;
61 
62  conf.mc_is_oostore = true;
63  conf.mc_is_read_verify = false;
64  conf.mc_local_addr = local_addr;
65  conf.mc_ha_addr = ha_addr;
66  conf.mc_profile = prof;
67  conf.mc_process_fid = proc_fid;
68  conf.mc_tm_recv_queue_min_len = M0_NET_TM_RECV_QUEUE_DEF_LEN;
69  conf.mc_max_rpc_msg_size = M0_RPC_DEF_MAX_RPC_MSG_SIZE;
70 
71  if (index_service == IDX_MOTR) {
72  conf.mc_idx_service_id = M0_IDX_DIX;
73  /* DIX- Metadata is created by m0dixinit() in ST script. */
74  dix_conf.kc_create_meta = false;
75  conf.mc_idx_service_conf = &dix_conf;
76  } else if (index_service == IDX_CASS) {
77  /* Cassandra index driver */
78  cass_conf.cc_cluster_ep = "127.0.0.1";
79  cass_conf.cc_keyspace = "index_keyspace";
81  conf.mc_idx_service_id = M0_IDX_CASS;
82  conf.mc_idx_service_conf = &cass_conf;
83  } else {
84  rc = -EINVAL;
85  console_printf("Invalid index service configuration.");
86  goto exit;
87  }
88 
89  rc = m0_client_init(&instance, &conf, true);
90  if (rc != 0)
91  goto exit;
92 
94 
95 exit:
96  return rc;
97 }
98 
99 static void st_fini_instance(void)
100 {
102 }
103 
104 static int st_wait_workers(void)
105 {
106  return st_stop_workers();
107 }
108 
109 void st_usage()
110 {
112  "Client System Test Framework: m0st\n"
113  " -- Note: if -l|-u is used, no Client details are needed\n"
114  " otherwise, -m, -h and -p have to be provided\n"
115  "Usage: m0st "
116  "[-l|-u|-r] [-m local] [-h ha] [-p prof_opt] "
117  "[-t tests]\n"
118  " -l List all tests\n"
119  " -m local Local(my) end point address\n"
120  " -h ha HA address \n"
121  " -p prof_opt Profile options for Motr\n"
122  " -f proc_fid Process FID for rmservice@Motr\n"
123  " -t tests Only run the specified tests\n"
124  " -I index service Index service(Cassandra, mock, Motr-KVS)\n"
125  " -r Run tests in a suite in random order\n"
126  " -u Print usage\n"
127  );
128 }
129 
130 void st_get_opts(int argc, char **argv)
131 {
132  int rc;
133 
134  if (argc < 2) {
135  st_usage();
136  exit(-1);
137  }
138 
139  local_addr = NULL;
140  ha_addr = NULL;
141  prof = NULL;
142  proc_fid = NULL;
143  tests = NULL;
144 
145  rc = M0_GETOPTS("st", argc, argv,
146  M0_HELPARG('?'),
147  M0_VOIDARG('i', "more verbose help",
148  LAMBDA(void, (void) {
149  st_usage();
150  exit(0);
151  })),
152  M0_VOIDARG('l', "Lists all client tests",
153  LAMBDA(void, (void) {
154  st_list(true);
155  exit(0);
156  })),
157  M0_STRINGARG('m', "Local endpoint address",
158  LAMBDA(void, (const char *string) {
159  local_addr = (char*)string;
160  })),
161  M0_STRINGARG('h', "HA address",
162  LAMBDA(void, (const char *str) {
163  ha_addr = (char*)str;
164  })),
165  M0_STRINGARG('f', "Process FID",
166  LAMBDA(void, (const char *str) {
167  proc_fid = (char*)str;
168  })),
169  M0_STRINGARG('p', "Profile options for Motr",
170  LAMBDA(void, (const char *str) {
171  prof = (char*)str;
172  })),
173  M0_NUMBERARG('I', "Index service id",
174  LAMBDA(void, (int64_t service_idx) {
175  index_service = service_idx;
176  })),
177  M0_VOIDARG('r', "Ramdom test mode",
178  LAMBDA(void, (void) {
180  ST_RAND_MODE);
181  })),
182  M0_STRINGARG('t', "Lists client tests",
183  LAMBDA(void, (const char *str) {
184  tests = (char*)str;
185  })));
186  /* some checks */
187  if (rc != 0 || local_addr == NULL || ha_addr == NULL ||
188  prof == NULL || proc_fid == NULL)
189  {
190  st_usage();
191  exit(0);
192  }
193 
194  /*
195  * Set tests to be run. If tests == NULL, all ST will
196  * be executed.
197  */
199 }
200 
201 
202 int main(int argc, char **argv)
203 {
204  int rc;
205  static struct m0 instance;
206 
209  if (rc != 0) {
210  fprintf(stderr, "Cannot init module %i\n", rc);
211  return rc;
212  }
213 
214  /* initialise Client ST */
215  st_init();
216  st_add_suites();
217 
218  /* Get input parameters */
219  st_get_opts(argc, argv);
220 
221  /* currently, all threads share the same instance */
222  if (st_init_instance() < 0) {
223  fprintf(stderr, "init failed!\n");
224  return -1;
225  }
226 
227  /* start worker threads */
229  st_cleaner_init();
231 
232  /* wait till all workers complete */
233  rc = st_wait_workers();
234  st_cleaner_fini();
235 
236  /* clean-up */
238  st_fini();
239 
240  return rc;
241 }
242 
243 /*
244  * Local variables:
245  * c-indentation-style: "K&R"
246  * c-basic-offset: 8
247  * tab-width: 8
248  * fill-column: 80
249  * scroll-step: 1
250  * End:
251  */
static char * ha_addr
Definition: st_main.c:44
#define M0_GETOPTS(progname, argc, argv,...)
Definition: getopts.h:169
char * cc_cluster_ep
Definition: idx.h:163
void st_usage()
Definition: st_main.c:109
#define NULL
Definition: misc.h:38
int st_stop_workers(void)
Definition: st_worker.c:258
void m0_client_fini(struct m0_client *m0c, bool fini_m0)
Definition: client_init.c:1711
Definition: idx.h:70
Definition: conf.py:1
M0_INTERNAL void m0_instance_setup(struct m0 *instance)
Definition: instance.c:110
static char * proc_fid
Definition: st_main.c:46
int m0_client_init(struct m0_client **m0c, struct m0_config *conf, bool init_m0)
Definition: client_init.c:1533
void st_list(bool with_tests)
Definition: st.c:435
void st_set_instance(struct m0_client *instance)
Definition: st.c:52
char * cc_keyspace
Definition: idx.h:164
#define M0_VOIDARG(ch, desc, func)
Definition: getopts.h:177
#define M0_NUMBERARG(ch, desc, func)
Definition: getopts.h:187
#define M0_STRINGARG(ch, desc, func)
Definition: getopts.h:207
static struct m0_idx_cass_config cass_conf
Definition: st_main.c:55
static int st_init_instance(void)
Definition: st_main.c:57
void st_fini(void)
Definition: st.c:490
void st_set_nr_workers(int nr)
Definition: st.c:95
void st_add_suites()
Definition: st.c:541
#define LAMBDA(T,...)
Definition: thread.h:153
int main(int argc, char **argv)
Definition: st_main.c:202
int st_init(void)
Definition: st.c:448
static char * tests
Definition: st_main.c:47
static void st_fini_instance(void)
Definition: st_main.c:99
Definition: instance.h:80
void st_set_tests(const char *tests)
Definition: st.c:75
void st_cleaner_fini()
Definition: st_assert.c:307
void st_get_opts(int argc, char **argv)
Definition: st_main.c:130
static int st_wait_workers(void)
Definition: st_main.c:104
void console_printf(const char *fmt,...)
Definition: st_misc.c:155
int st_cleaner_init()
Definition: st_assert.c:259
enum idx_service index_service
Definition: st_main.c:48
idx_service
Definition: st_kmain.c:42
struct m0_client * st_get_instance()
Definition: st.c:57
bool kc_create_meta
Definition: idx.h:183
#define M0_HELPARG(ch)
Definition: getopts.h:242
static struct m0 instance
Definition: main.c:78
static char * prof
Definition: st_main.c:45
static struct m0_idx_dix_config dix_conf
Definition: st_main.c:54
static char * local_addr
Definition: st_main.c:43
struct m0_module i_self
Definition: instance.h:88
int st_start_workers(void)
Definition: st_worker.c:226
int32_t rc
Definition: trigger_fop.h:47
int cc_max_column_family_num
Definition: idx.h:165
void st_set_test_mode(enum st_mode mode)
Definition: st.c:85
M0_INTERNAL int m0_module_init(struct m0_module *module, int level)
Definition: module.c:131