Motr  M0
ut.h
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 #pragma once
24 
25 #ifndef __MOTR_UT_UT_H__
26 #define __MOTR_UT_UT_H__
27 
28 #include "module/module.h"
29 #include "lib/types.h"
30 #include "lib/list.h" /* m0_list_link, m0_list */
31 #include "fid/fid.h"
32 
33 struct m0_ut_module;
34 
46 # define M0_UT_ASSERT(a) m0_ut_assertimpl((a), #a, __FILE__, __LINE__, __func__)
47 
48 #if defined M0_UT_TRACE && M0_UT_TRACE > 0
49 # define M0_UT_ENTER(FMT, ...) \
50  m0_console_printf("> %s: " FMT "\n", __func__, ## __VA_ARGS__)
51 # define M0_UT_LOG(FMT, ...) \
52  m0_console_printf("* %s: " FMT "\n", __func__, ## __VA_ARGS__)
53 # define M0_UT_RETURN(FMT, ...) \
54  m0_console_printf("< %s: " FMT "\n", __func__, ## __VA_ARGS__)
55 #else
56 # define M0_UT_ENTER(...)
57 # define M0_UT_LOG(...)
58 # define M0_UT_RETURN(...)
59 #endif
60 
64 struct m0_ut {
66  const char *t_name;
68  void (*t_proc)(void);
70  const char *t_owner;
72  bool t_enabled;
73 };
74 
75 enum { M0_UT_SUITE_TESTS_MAX = 128 };
76 
77 struct m0_ut_suite {
85  const struct m0_ut_moddep *ts_deps;
87  unsigned ts_deps_nr;
90  bool ts_enabled;
97  bool ts_masked;
99  const char *ts_name;
101  const char *ts_owners;
112  int (*ts_init)(void);
117  int (*ts_fini)(void);
121  int ts_order;
122 };
123 
124 int m0_ut_init(struct m0 *instance);
125 void m0_ut_fini(void);
126 
134 M0_INTERNAL void m0_ut_add(struct m0_ut_module *m, struct m0_ut_suite *ts,
135  bool enable);
136 
140 M0_INTERNAL void m0_ut_shuffle(unsigned seed);
141 
145 M0_INTERNAL void m0_ut_start_from(const char *suite);
146 
150 M0_INTERNAL int m0_ut_run(void);
151 
155 M0_INTERNAL bool m0_ut_small_credits(void);
156 
163 M0_INTERNAL void m0_ut_list(bool with_tests, bool yaml_output);
164 
168 M0_INTERNAL void m0_ut_list_owners(void);
169 
181 M0_INTERNAL bool m0_ut_assertimpl(bool c, const char *str_c, const char *file,
182  int lno, const char *func);
183 
191 M0_INTERNAL int m0_ut_enable_fault_point(const char *str);
192 
225 M0_INTERNAL int m0_ut_enable_fault_points_from_file(const char *file_name);
226 
227 #ifndef __KERNEL__
228 #include <stdio.h> /* FILE, fpos_t */
229 
231  FILE *ur_stream;
232  int ur_oldfd;
233  int ur_fd;
234  fpos_t ur_pos;
235 };
236 
241 M0_INTERNAL void m0_stream_redirect(FILE * stream, const char *path,
242  struct m0_ut_redirect *redir);
247 M0_INTERNAL void m0_stream_restore(const struct m0_ut_redirect *redir);
248 
255 M0_INTERNAL bool m0_error_mesg_match(FILE * fp, const char *mesg);
256 #endif
257 
258 M0_EXTERN struct m0_fid g_process_fid;
259 
261 #endif /* __MOTR_UT_UT_H__ */
M0_INTERNAL int m0_ut_enable_fault_points_from_file(const char *file_name)
fpos_t ur_pos
Definition: ut.h:234
M0_INTERNAL bool m0_error_mesg_match(FILE *fp, const char *mesg)
Definition: ut.c:123
int ts_order
Definition: ut.h:121
static struct m0_addb2_mach * m
Definition: consumer.c:38
M0_INTERNAL void m0_stream_restore(const struct m0_ut_redirect *redir)
Definition: ut.c:107
struct m0_file file
Definition: di.c:36
const char * t_name
Definition: ut.h:66
const char * ts_yaml_config_string
Definition: ut.h:107
int ur_fd
Definition: ut.h:233
int(* ts_init)(void)
Definition: ut.h:112
bool ts_masked
Definition: ut.h:97
Definition: ut.h:77
void(* t_proc)(void)
Definition: ut.h:68
M0_INTERNAL void m0_ut_fini(void)
Definition: ut.c:95
struct m0_ut ts_tests[M0_UT_SUITE_TESTS_MAX]
Definition: ut.h:119
M0_INTERNAL int m0_ut_init(struct m0 *instance)
Definition: ut.c:64
M0_INTERNAL void m0_ut_start_from(const char *suite)
Definition: ut.c:673
bool ts_enabled
Definition: ut.h:90
unsigned ts_deps_nr
Definition: ut.h:87
int(* ts_fini)(void)
Definition: ut.h:117
static struct m0_addb2_callback c
Definition: consumer.c:41
const struct m0_ut_moddep * ts_deps
Definition: ut.h:85
Definition: instance.h:80
FILE * ur_stream
Definition: ut.h:231
M0_INTERNAL int m0_ut_enable_fault_point(const char *str)
static int lno
int ur_oldfd
Definition: ut.h:232
const char * ts_name
Definition: ut.h:99
bool t_enabled
Definition: ut.h:72
M0_INTERNAL void m0_ut_list_owners(void)
Definition: ut.c:603
M0_INTERNAL bool m0_ut_assertimpl(bool c, const char *str_c, const char *file, int lno, const char *func)
Definition: ut.c:627
const char * ts_owners
Definition: ut.h:101
Definition: fid.h:38
M0_EXTERN struct m0_fid g_process_fid
Definition: ut.h:258
M0_INTERNAL void m0_ut_add(struct m0_ut_module *m, struct m0_ut_suite *ts, bool enable)
Definition: ut.c:101
static struct m0 instance
Definition: main.c:78
M0_INTERNAL bool m0_ut_small_credits(void)
Definition: ut.c:645
M0_INTERNAL void m0_stream_redirect(FILE *stream, const char *path, struct m0_ut_redirect *redir)
Definition: ut.c:87
struct m0_list_link ts_linkage
Definition: ut.h:88
M0_INTERNAL int m0_ut_run(void)
Definition: ut.c:520
M0_INTERNAL void m0_ut_list(bool with_tests, bool yaml_output)
Definition: ut.c:565
Definition: rcv_session.c:58
M0_INTERNAL void m0_ut_shuffle(unsigned seed)
Definition: ut.c:659
const char * t_owner
Definition: ut.h:70
Definition: ut.h:64
struct m0_module ts_module
Definition: ut.h:78