23 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_UT 46 #define LOG_PREFIX "." 83 for (
i = 0;
i <
m->ut_suites_nr; ++
i) {
105 m->ut_suites[
m->ut_suites_nr++] = ts;
117 for (
i = 0;
i <
m->ut_suites_nr; ++
i)
119 return m->ut_suites[
i];
124 const char *s_name,
const char *
t_name)
134 for (
t =
s->ts_tests;
t->t_name !=
NULL; ++
t)
141 const char *s_name,
const char *
t_name,
154 for (
t =
s->ts_tests;
t->t_name !=
NULL; ++
t)
161 s->ts_enabled =
s->ts_enabled || !
value;
250 subtoken = strchr(
token,
':');
251 if (subtoken !=
NULL)
266 m0_free((
char *)e->ue_suite_name);
267 m0_free((
char *)e->ue_test_name);
308 flag = (
m->ut_tests ==
NULL ||
m->ut_exclude);
310 for (
i = 0;
i <
m->ut_suites_nr; ++
i) {
311 m->ut_suites[
i]->ts_enabled =
flag;
312 for (
t =
m->ut_suites[
i]->ts_tests;
t->t_name !=
NULL; ++
t)
316 if (
m->ut_tests !=
NULL) {
323 e->ue_test_name, !
flag);
333 while (isspace(*str))
341 #ifdef ENABLE_FAULT_INJECTION 344 uint32_t fi_free_idx;
352 for (
i = 0;
i < fi_free_idx; ++
i) {
355 "Fault injection is not disabled: %s(), \"%s\"",
363 static const char padding[256] = { [0 ... 254] =
' ', [255] =
'\0' };
375 if (!
test->t_enabled)
378 name_len = strlen(
test->t_name);
382 name_len += strlen(
test->t_owner) + 2;
396 pad_len =
max_check(name_len, max_name_len) - name_len;
399 mem_used = mem_after - mem_before;
413 uint64_t alloc_before;
414 uint64_t alloc_after;
427 "DISABLED !!!=-\n#\n", suite->
ts_name);
479 alloc_after =
max64(alloc_after, alloc_before);
481 mem_used = mem_after - mem_before;
489 alloc_after - alloc_before)));
500 for (
i = 0;
i <
nr; ++
i) {
512 for (
i =
rc = 0;
i <
m->ut_suites_nr &&
rc == 0; ++
i)
523 const char *leak_str;
524 uint64_t alloc_before;
525 uint64_t alloc_after;
546 mem_after - mem_before));
549 alloc_after - alloc_before));
552 " Mem: %sB, Leaked: %sB, Asserts: %" PRIu64 553 "\nUnit tests status: SUCCESS\n",
565 M0_INTERNAL
void m0_ut_list(
bool with_tests,
bool yaml_output)
574 for (
i = 0;
i <
m->ut_suites_nr; ++
i) {
577 if (
m->ut_suites[
i]->ts_yaml_config_string !=
NULL)
579 m->ut_suites[
i]->ts_yaml_config_string);
586 for (
t =
m->ut_suites[
i]->ts_tests;
t->t_name !=
NULL; ++
t)
598 if (
t->t_owner !=
NULL)
610 for (
i = 0;
i <
m->ut_suites_nr; ++
i) {
612 if (
s->ts_owners ==
NULL) {
613 for (
t =
s->ts_tests;
t->t_name !=
NULL; ++
t) {
614 if (
t->t_owner !=
NULL) {
628 int lno,
const char *func)
630 static char buf[4096];
635 "Unit-test assertion failed: %s", str_c);
637 .pc_expr =
buf, .pc_func = func,
638 .pc_file =
file, .pc_lineno =
lno,
656 return (*s0)->ts_order - (*s1)->ts_order;
667 for (
i = 1;
i <
m->ut_suites_nr; ++
i)
668 m->ut_suites[
i]->ts_order =
rand();
669 qsort(
m->ut_suites + 1,
m->ut_suites_nr - 1,
sizeof m->ut_suites[0],
679 for (
i = 0, o = 0;
i <
m->ut_suites_nr; ++
i, ++o) {
680 if (
m0_streq(
m->ut_suites[
i]->ts_name, suite))
681 o = -
m->ut_suites_nr - 1;
682 m->ut_suites[
i]->ts_order = o;
684 qsort(
m->ut_suites,
m->ut_suites_nr,
sizeof m->ut_suites[0],
692 #undef M0_TRACE_SUBSYSTEM
static void m0_atomic64_inc(struct m0_atomic64 *a)
static struct m0_addb2_philter p
static bool exists(const struct m0_ut_module *m, const char *s_name, const char *t_name)
static struct m0_ut_module * ut_module(void)
static struct m0_list list
struct m0_fi_fpoint_id fps_id
const char * ue_suite_name
static struct m0_addb2_mach * m
static int test_list_create(struct m0_list *list, const struct m0_ut_module *m)
M0_INTERNAL void m0_list_init(struct m0_list *head)
#define M0_LOG(level,...)
M0_INTERNAL size_t m0_allocated_total(void)
void m0_panic(const struct m0_panic_ctx *ctx,...)
void m0_console_printf(const char *fmt,...)
M0_INTERNAL const struct m0_fi_fpoint_state * m0_fi_states_get(void)
uint64_t m0_time_nanoseconds(const m0_time_t time)
static int max_test_name_len(const struct m0_ut_suite **suites, unsigned nr)
static void test_list_destroy(struct m0_list *list)
static int tests_run_all(const struct m0_ut_module *m)
M0_INTERNAL void m0_list_fini(struct m0_list *head)
int const char const void * value
M0_INTERNAL void m0_list_del(struct m0_list_link *old)
M0_INTERNAL struct m0 * m0_get(void)
const char * ue_test_name
static int test_add(struct m0_list *list, const char *suite, const char *test, const struct m0_ut_module *m)
M0_INTERNAL size_t m0_allocated(void)
static struct m0_ut_suite * suite_find(const struct m0_ut_module *m, const char *name)
M0_INTERNAL int m0_fi_init(void)
static void ut_owners_print(const struct m0_ut_suite *suite)
M0_INTERNAL void m0_ut_fini(void)
const char * m0_bcount_with_suffix(char *buf, size_t size, m0_bcount_t c)
static int64_t max64(int64_t a, int64_t b)
#define M0_ERR_INFO(rc, fmt,...)
struct m0_ut ts_tests[M0_UT_SUITE_TESTS_MAX]
static const char * skipspaces(const char *str)
#define M0_FID_TINIT(type, container, key)
M0_INTERNAL int m0_ut_init(struct m0 *instance)
M0_INTERNAL void m0_ut_start_from(const char *suite)
static void duration(struct m0_addb2__context *ctx, const uint64_t *v, char *buf)
m0_time_t m0_time_now(void)
static struct m0_addb2_callback c
static struct m0_thread t[8]
static int test_suites_enable(const struct m0_ut_module *m)
static int cmp(const struct m0_ut_suite **s0, const struct m0_ut_suite **s1)
static int test_list_populate(struct m0_list *list, const char *str, const struct m0_ut_module *m)
static int run_suite(const struct m0_ut_suite *suite, int max_name_len)
static void token(struct ff2c_context *ctx, struct ff2c_term *term, struct ff2c_token *tok)
#define m0_list_entry_forall(var, head, type, member,...)
static void check_all_fi_disabled(void)
uint64_t m0_time_seconds(const m0_time_t time)
static void set_enabled_flag_for(const struct m0_ut_module *m, const char *s_name, const char *t_name, bool value)
static int64_t m0_atomic64_get(const struct m0_atomic64 *a)
M0_INTERNAL void m0_ut_list_owners(void)
M0_INTERNAL void m0_module_dep_add(struct m0_module *m0, int l0, struct m0_module *m1, int l1)
M0_INTERNAL uint32_t m0_fi_states_get_free_idx(void)
M0_INTERNAL bool m0_ut_assertimpl(bool c, const char *str_c, const char *file, int lno, const char *func)
void m0_console_flush(void)
static bool fi_state_enabled(const struct m0_fi_fpoint_state *state)
#define M0_ALLOC_PTR(ptr)
void * i_moddata[M0_MODULE_NR]
M0_INTERNAL void m0_ut_add(struct m0_ut_module *m, struct m0_ut_suite *ts, bool enable)
m0_time_t m0_time_sub(const m0_time_t t1, const m0_time_t t2)
static int start(struct m0_fom *fom)
#define IS_IN_ARRAY(idx, array)
static struct m0 instance
M0_INTERNAL bool m0_ut_small_credits(void)
static struct m0_ut * get_test_by_name(const struct m0_ut_module *m, const char *s_name, const char *t_name)
M0_INTERNAL void m0_ut_suite_module_setup(struct m0_ut_suite *ts, struct m0 *instance)
#define M0_ASSERT_INFO(cond, fmt,...)
M0_INTERNAL int m0_ut_run(void)
M0_INTERNAL void m0_ut_list(bool with_tests, bool yaml_output)
M0_INTERNAL void m0_list_link_init(struct m0_list_link *link)
static const char padding[256]
M0_INTERNAL void m0_list_add_tail(struct m0_list *head, struct m0_list_link *new)
M0_INTERNAL void m0_fi_fini(void)
M0_INTERNAL void m0_ut_shuffle(unsigned seed)
static struct m0_addb2_source * s
static void run_test(const struct m0_ut *test, size_t max_name_len)
struct m0_fid g_process_fid
struct m0_module ts_module
M0_INTERNAL void m0_module_fini(struct m0_module *module, int level)
M0_INTERNAL void m0_cs_gotsignal_reset(void)
M0_INTERNAL int m0_module_init(struct m0_module *module, int level)
struct m0_list_link ue_linkage
struct m0_fi_fpoint_state fi_states[FI_STATES_ARRAY_SIZE]