Motr  M0
stats_ut.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-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 "ut/ut.h"
23 #include "fop/fop.h"
24 #include "reqh/reqh.h"
25 #include "reqh/reqh_service.h"
26 #include "rpc/rpc_opcodes.h" /* M0_UT_STATS_OPCODE */
27 
28 #include "fop/ut/stats/stats_fom.c"
29 #include "ut/ut_rpc_machine.h"
30 
31 #define DUMMY_DBNAME "dummy-db"
32 #define DUMMY_COB_ID 20
33 #define DUMMY_SERVER_ADDR "0@lo:12345:34:10"
34 
35 extern struct m0_fom_type stats_fom_type;
36 extern const struct m0_fom_type_ops fom_stats_type_ops;
38 static struct m0_reqh_service *service;
39 
40 static void test_stats(void)
41 {
43 }
44 
46 {
47  M0_PRE(service != NULL);
48  return 0;
49 }
50 
52 {
53  M0_PRE(service != NULL);
54 }
55 
57 {
58  M0_PRE(service != NULL);
60 }
61 
64  .rso_stop = ut_stats_service_stop,
65  .rso_fini = ut_stats_service_fini
66 };
67 
69  const struct m0_reqh_service_type *stype)
70 {
71  struct m0_reqh_service *serv;
72 
73  M0_PRE(stype != NULL && service != NULL);
74 
75  M0_ALLOC_PTR(serv);
76  M0_ASSERT(serv != NULL);
77 
78  serv->rs_type = stype;
80  *service = serv;
81  return 0;
82 }
83 
86 };
87 
89  /*
90  * "M0_CST_STATS" name is used by m0_stats_svc_type.
91  * m0_reqh_service_type_register() will fail on precondition
92  * if we reuse a name which is already registered.
93  */
94  .rst_name = "M0_CST_STATS__UT",
95  .rst_ops = &ut_stats_service_type_ops,
96  .rst_level = M0_RS_LEVEL_NORMAL,
97  .rst_typecode = M0_CST_STATS,
98 };
99 
100 static int test_stats_init(void)
101 {
102  int rc;
103 
106  M0_ASSERT(rc == 0);
109  &fom_phases_conf);
110 
111  M0_SET0(&rmach_ctx);
115 
117  M0_ASSERT(rc == 0);
120  M0_ASSERT(rc == 0);
121 
122  return rc;
123 }
124 
125 static int test_stats_fini(void)
126 {
130  return 0;
131 }
132 
134  .ts_name = "fom-stats-ut",
135  .ts_init = test_stats_init,
136  .ts_fini = test_stats_fini,
137  .ts_tests = {
138  { "stats", test_stats },
139  { NULL, NULL }
140  }
141 };
142 
143 /*
144  * Local variables:
145  * c-indentation-style: "K&R"
146  * c-basic-offset: 8
147  * tab-width: 8
148  * fill-column: 80
149  * scroll-step: 1
150  * End:
151  */
uint64_t id
Definition: cob.h:240
static struct m0_reqh_service * service
Definition: stats_ut.c:38
struct m0_fom_type stats_fom_type
Definition: stats_fom.c:80
#define M0_PRE(cond)
M0_INTERNAL void m0_sm_conf_init(struct m0_sm_conf *conf)
Definition: sm.c:340
M0_INTERNAL int m0_reqh_service_start(struct m0_reqh_service *service)
Definition: reqh_service.c:343
M0_INTERNAL void m0_ut_rpc_mach_init_and_add(struct m0_ut_rpc_mach_ctx *ctx)
int(* rso_start)(struct m0_reqh_service *service)
Definition: reqh_service.h:360
#define NULL
Definition: misc.h:38
#define DUMMY_SERVER_ADDR
Definition: stats_ut.c:33
static void test_stats(void)
Definition: stats_ut.c:40
static int ut_stats_service_start(struct m0_reqh_service *service)
Definition: stats_ut.c:45
struct m0_cob_domain_id rmc_cob_id
#define M0_SET0(obj)
Definition: misc.h:64
Definition: ut.h:77
static const struct m0_reqh_service_type_ops ut_stats_service_type_ops
Definition: stats_ut.c:84
static const struct m0_reqh_service_ops ut_stats_service_ops
Definition: stats_ut.c:62
int m0_reqh_service_type_register(struct m0_reqh_service_type *rstype)
Definition: reqh_service.c:473
struct m0_reqh_service_type ut_stats_service_type
Definition: stats_ut.c:88
static const struct socktype stype[]
Definition: sock.c:1156
#define M0_ASSERT(cond)
const char * rst_name
Definition: reqh_service.h:447
const struct m0_fom_type_ops fom_stats_type_ops
Definition: stats_fom.c:75
static int test_stats_fini(void)
Definition: stats_ut.c:125
static struct m0_ut_rpc_mach_ctx rmach_ctx
Definition: stats_ut.c:37
static void ut_stats_service_stop(struct m0_reqh_service *service)
Definition: stats_ut.c:51
M0_INTERNAL void m0_fom_type_init(struct m0_fom_type *type, uint64_t id, const struct m0_fom_type_ops *ops, const struct m0_reqh_service_type *svc_type, const struct m0_sm_conf *sm)
Definition: fom.c:1596
M0_INTERNAL int m0_reqh_service_allocate(struct m0_reqh_service **out, const struct m0_reqh_service_type *stype, struct m0_reqh_context *rctx)
Definition: reqh_service.c:185
struct m0_reqh rmc_reqh
M0_INTERNAL void m0_reqh_service_init(struct m0_reqh_service *service, struct m0_reqh *reqh, const struct m0_fid *fid)
Definition: reqh_service.c:428
#define DUMMY_COB_ID
Definition: stats_ut.c:32
const char * ts_name
Definition: ut.h:99
int(* rsto_service_allocate)(struct m0_reqh_service **service, const struct m0_reqh_service_type *stype)
Definition: reqh_service.h:435
const struct m0_reqh_service_type * rs_type
Definition: reqh_service.h:227
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
const char * rmc_ep_addr
static int ut_stats_service_allocate(struct m0_reqh_service **service, const struct m0_reqh_service_type *stype)
Definition: stats_ut.c:68
M0_INTERNAL void m0_ut_rpc_mach_fini(struct m0_ut_rpc_mach_ctx *ctx)
struct m0_ut_suite m0_fom_stats_ut
Definition: stats_ut.c:133
static void test_stats_req_handle(struct m0_reqh *reqh)
Definition: stats_fom.c:132
static void ut_stats_service_fini(struct m0_reqh_service *service)
Definition: stats_ut.c:56
M0_INTERNAL void m0_sm_conf_fini(struct m0_sm_conf *conf)
Definition: sm.c:376
void m0_free(void *data)
Definition: memory.c:146
void m0_reqh_service_type_unregister(struct m0_reqh_service_type *rstype)
Definition: reqh_service.c:490
int32_t rc
Definition: trigger_fop.h:47
static int test_stats_init(void)
Definition: stats_ut.c:100
const struct m0_reqh_service_ops * rs_ops
Definition: reqh_service.h:254
static struct m0_sm_conf fom_phases_conf
Definition: stats_fom.c:53