Motr  M0
module.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-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/module.h"
23 #include "ut/ut.h" /* m0_ut_suite */
24 #include "ut/ut_internal.h" /* m0_ut_sandbox_init */
25 #include "ut/cs_service.h" /* m0_cs_default_stypes_init */
26 #include "module/instance.h" /* m0 */
27 #include "lib/memory.h" /* M0_ALLOC_PTR */
28 
35 static struct m0_module *ut_module_create(struct m0 *instance);
36 
38  .mt_name = "m0_ut_module",
39  .mt_create = ut_module_create
40 };
41 
42 static int level_ut_enter(struct m0_module *module)
43 {
44  switch (module->m_cur + 1) {
45  case M0_LEVEL_UT_PREPARE: {
46  struct m0_ut_module *m = M0_AMB(m, module, ut_module);
47 
48  m0_atomic64_set(&m->ut_asserts, 0);
49  return m0_ut_sandbox_init(m->ut_sandbox);
50  }
51  case M0_LEVEL_UT_KLUDGE:
53  }
54  M0_IMPOSSIBLE("Unexpected level: %d", module->m_cur + 1);
55 }
56 
57 static void level_ut_leave(struct m0_module *module)
58 {
59  struct m0_ut_module *m = M0_AMB(m, module, ut_module);
60 
61  M0_PRE(module->m_cur == M0_LEVEL_UT_PREPARE);
62 
63  m0_ut_sandbox_fini(m->ut_sandbox, m->ut_keep_sandbox);
64 }
65 
66 static const struct m0_modlev levels_ut[] = {
68  .ml_name = "M0_LEVEL_UT_PREPARE",
69  .ml_enter = level_ut_enter,
70  .ml_leave = level_ut_leave
71  },
72  [M0_LEVEL_UT_KLUDGE] = {
73  .ml_name = "M0_LEVEL_UT_KLUDGE",
74  .ml_enter = level_ut_enter,
75  .ml_leave = (void *)m0_cs_default_stypes_fini
76  },
77  [M0_LEVEL_UT_READY] = {
78  .ml_name = "M0_LEVEL_UT_READY"
79  }
80 };
81 
82 static const struct m0_modlev levels_ut_suite[] = {
84  .ml_name = "M0_LEVEL_UT_SUITE_READY"
85  }
86 };
87 
88 /* XXX TODO: Move this logic to some level of m0_ut_module. */
89 M0_INTERNAL void
91 {
92  int i;
93 
94  m0_module_setup(&ts->ts_module, "m0_ut_suite module",
96  for (i = 0; i < ts->ts_deps_nr; ++i) {
97  M0_IMPOSSIBLE("XXX FIXME: This won't work, because we"
98  " don't know the address of a module"
99  " at compile time.");
101  ts->ts_deps[i].ud_module,
102  ts->ts_deps[i].ud_level);
103  }
104 }
105 
106 static struct m0_module *ut_module_create(struct m0 *instance)
107 {
108  static struct m0_ut_module ut;
109 
112 #if 1 /* XXX FIXME
113  *
114  * m0_ut_stob_init(), called when M0_LEVEL_INST_SUBSYSTEMS is entered,
115  * requires a sandbox directory, which is created by
116  * M0_LEVEL_UT_PREPARE's ->ml_enter().
117  *
118  * This is a temporary solution. It should go away together with
119  * M0_LEVEL_INST_SUBSYSTEMS.
120  */
123 #endif
127  return &ut.ut_module;
128 }
129 
#define M0_PRE(cond)
static struct m0_ut_module * ut_module(void)
Definition: ut.c:59
static struct m0_addb2_mach * m
Definition: consumer.c:38
static struct m0_module * ut_module_create(struct m0 *instance)
Definition: module.c:106
int m0_cs_default_stypes_init(void)
Definition: cs_service.c:161
const char * ml_name
Definition: module.h:114
struct m0_module ut_module
Definition: module.h:43
Definition: ut.h:77
static void level_ut_leave(struct m0_module *module)
Definition: module.c:57
int i
Definition: dir.c:1033
int m0_ut_sandbox_init(const char *dir)
Definition: ut.c:25
#define M0_AMB(obj, ptr, field)
Definition: misc.h:320
unsigned ts_deps_nr
Definition: ut.h:87
M0_INTERNAL void m0_module_setup(struct m0_module *module, const char *name, const struct m0_modlev *level, int level_nr, struct m0 *instance)
Definition: module.c:193
const struct m0_ut_moddep * ts_deps
Definition: ut.h:85
Definition: instance.h:80
static const struct m0_modlev levels_ut_suite[]
Definition: module.c:82
static const struct m0_modlev levels_ut[]
Definition: module.c:66
struct m0_module * ud_module
Definition: module.h:36
const struct m0_module_type m0_ut_module_type
Definition: module.c:37
int ud_level
Definition: module.h:37
M0_INTERNAL void m0_module_dep_add(struct m0_module *m0, int l0, struct m0_module *m1, int l1)
Definition: module.c:168
void m0_ut_sandbox_fini(const char *dir, bool keep)
Definition: ut.c:30
void * i_moddata[M0_MODULE_NR]
Definition: instance.h:94
int m_cur
Definition: module.h:160
const char * mt_name
Definition: module.h:186
static struct m0 instance
Definition: main.c:78
static int level_ut_enter(struct m0_module *module)
Definition: module.c:42
M0_INTERNAL void m0_ut_suite_module_setup(struct m0_ut_suite *ts, struct m0 *instance)
Definition: module.c:90
struct m0_module i_self
Definition: instance.h:88
#define ARRAY_SIZE(a)
Definition: misc.h:45
struct m0_module ts_module
Definition: ut.h:78
static void m0_atomic64_set(struct m0_atomic64 *a, int64_t num)
void m0_cs_default_stypes_fini(void)
Definition: cs_service.c:174
#define M0_IMPOSSIBLE(fmt,...)