From 6ba817bee6bb984bd6c3fb548089e9d50675d315 Mon Sep 17 00:00:00 2001 From: ArturX Kloniecki Date: Tue, 13 Nov 2018 14:28:19 +0100 Subject: [PATCH] UT: Fix unit tests after faulty PRs were merged. Signed-off-by: ArturX Kloniecki --- test/cmocka/include/mock_trace.h | 37 ++++++ test/cmocka/src/audio/buffer/mock.c | 22 +--- test/cmocka/src/audio/component/mock.c | 22 +--- test/cmocka/src/audio/mixer/mock.c | 22 +--- .../src/audio/pipeline/pipeline_mocks.c | 26 +--- test/cmocka/src/debugability/macros.c | 114 ++++++++++-------- test/cmocka/src/lib/alloc/alloc.c | 1 + test/cmocka/src/lib/alloc/mock.c | 43 +------ 8 files changed, 116 insertions(+), 171 deletions(-) create mode 100644 test/cmocka/include/mock_trace.h diff --git a/test/cmocka/include/mock_trace.h b/test/cmocka/include/mock_trace.h new file mode 100644 index 000000000..28cd7a2a0 --- /dev/null +++ b/test/cmocka/include/mock_trace.h @@ -0,0 +1,37 @@ +#include + +#define _TRACE_EVENT_NTH_PARAMS(id_count, param_count) \ + uintptr_t log_entry \ + META_SEQ_FROM_0_TO(id_count , META_SEQ_STEP_id_uint32_t) \ + META_SEQ_FROM_0_TO(param_count, META_SEQ_STEP_param_uint32_t) + +#define _TRACE_EVENT_NTH(postfix, param_count) \ + META_FUNC_WITH_VARARGS( \ + _trace_event, META_CONCAT(postfix, param_count),\ + void, _TRACE_EVENT_NTH_PARAMS(2, param_count) \ + ) + +#define META_SEQ_STEP_void_param(i, _) (void)META_CONCAT(param,i); + +#define _TRACE_N(N, mbox, atomic) \ + _TRACE_EVENT_NTH(META_CONCAT(META_IF_ELSE(mbox)(_mbox)(), \ + META_IF_ELSE(atomic)(_atomic)()), N) \ + { \ + (void)log_entry; \ + (void)id_0; \ + (void)id_1; \ + META_SEQ_FROM_0_TO(N, META_SEQ_STEP_void_param) \ + } + +#define _TRACE_GROUP(N) \ + _TRACE_N(N, 0, 0) \ + _TRACE_N(N, 0, 1) \ + _TRACE_N(N, 1, 0) \ + _TRACE_N(N, 1, 1) + +#define TRACE_IMPL() \ + _TRACE_GROUP(0) \ + _TRACE_GROUP(1) \ + _TRACE_GROUP(2) \ + _TRACE_GROUP(3) \ + _TRACE_GROUP(4) diff --git a/test/cmocka/src/audio/buffer/mock.c b/test/cmocka/src/audio/buffer/mock.c index 42580b27d..e2f40e9c9 100644 --- a/test/cmocka/src/audio/buffer/mock.c +++ b/test/cmocka/src/audio/buffer/mock.c @@ -34,27 +34,9 @@ #include #include -void _trace_event0(uint32_t log_entry) -{ - (void)log_entry; -} +#include -void _trace_event1(uint32_t log_entry, uint32_t param) -{ - (void)log_entry; - (void)param; -} - -void _trace_event_mbox_atomic0(uint32_t log_entry) -{ - (void)log_entry; -} - -void _trace_event_mbox_atomic1(uint32_t log_entry, uint32_t param) -{ - (void)log_entry; - (void)param; -} +TRACE_IMPL() void *rzalloc(int zone, uint32_t caps, size_t bytes) { diff --git a/test/cmocka/src/audio/component/mock.c b/test/cmocka/src/audio/component/mock.c index 208dbcf4d..5d0bb476c 100644 --- a/test/cmocka/src/audio/component/mock.c +++ b/test/cmocka/src/audio/component/mock.c @@ -34,27 +34,9 @@ #include #include -void _trace_event0(uint32_t log_entry) -{ - (void)log_entry; -} +#include -void _trace_event1(uint32_t log_entry, uint32_t param) -{ - (void)log_entry; - (void)param; -} - -void _trace_event_mbox_atomic0(uint32_t log_entry) -{ - (void)log_entry; -} - -void _trace_event_mbox_atomic1(uint32_t log_entry, uint32_t param) -{ - (void)log_entry; - (void)param; -} +TRACE_IMPL() void *rzalloc(int zone, uint32_t caps, size_t bytes) { diff --git a/test/cmocka/src/audio/mixer/mock.c b/test/cmocka/src/audio/mixer/mock.c index 4fddb1adc..b66b69168 100644 --- a/test/cmocka/src/audio/mixer/mock.c +++ b/test/cmocka/src/audio/mixer/mock.c @@ -38,27 +38,9 @@ #include "comp_mock.h" -void _trace_event0(uint32_t log_entry) -{ - (void)log_entry; -} +#include -void _trace_event1(uint32_t log_entry, uint32_t param) -{ - (void)log_entry; - (void)param; -} - -void _trace_event_mbox_atomic0(uint32_t log_entry) -{ - (void)log_entry; -} - -void _trace_event_mbox_atomic1(uint32_t log_entry, uint32_t param) -{ - (void)log_entry; - (void)param; -} +TRACE_IMPL() void *rballoc(int zone, uint32_t caps, size_t bytes) { diff --git a/test/cmocka/src/audio/pipeline/pipeline_mocks.c b/test/cmocka/src/audio/pipeline/pipeline_mocks.c index 49fc59003..e13bf6218 100644 --- a/test/cmocka/src/audio/pipeline/pipeline_mocks.c +++ b/test/cmocka/src/audio/pipeline/pipeline_mocks.c @@ -30,6 +30,10 @@ #include "pipeline_mocks.h" +#include + +TRACE_IMPL() + struct ipc *_ipc; void platform_dai_timestamp(struct comp_dev *dai, @@ -81,28 +85,6 @@ int ipc_stream_send_xrun(struct comp_dev *cdev, return 0; } -void _trace_event0(uint32_t log_entry) -{ - (void)log_entry; -} - -void _trace_event1(uint32_t log_entry, uint32_t param) -{ - (void)log_entry; - (void)param; -} - -void _trace_event_mbox_atomic0(uint32_t log_entry) -{ - (void)log_entry; -} - -void _trace_event_mbox_atomic1(uint32_t log_entry, uint32_t param) -{ - (void)log_entry; - (void)param; -} - int arch_cpu_is_core_enabled(int id) { return 1; diff --git a/test/cmocka/src/debugability/macros.c b/test/cmocka/src/debugability/macros.c index 8b4fe50ee..f1db0d40d 100644 --- a/test/cmocka/src/debugability/macros.c +++ b/test/cmocka/src/debugability/macros.c @@ -48,19 +48,35 @@ static void test_debugability_macros_declare_log_entry(void **state) LOG_LEVEL_CRITICAL, "Message", TRACE_CLASS_DMA, + 1, 1 )); const char *should_be_eq = "__attribute__((section(\".static_log.\"" " \"LOG_LEVEL_CRITICAL\"))) " - "static const struct { uint32_t level; uint32_t component_id; " - "uint32_t params_num; uint32_t line_idx; uint32_t file_name_len; " - "const char file_name[sizeof(\"src/debugability/macros.c\")]; " - "uint32_t text_len; const char text[sizeof(\"Message\")]; } " - "log_entry = { 1(6 << 24)152sizeof(\"src/debugability/macros.c\")" - "\"src/debugability/macros.c\"sizeof(\"Message\")\"Message\" }"; + "static const struct " + "{ " + "uint32_t level; " + "uint32_t component_class; " + "uint32_t has_ids; " + "uint32_t params_num; " + "uint32_t line_idx; " + "uint32_t file_name_len; " + "uint32_t text_len; " + "const char file_name[sizeof(\"src/debugability/macros.c\")]; " + "const char text[sizeof(\"Message\")]; " + "} log_entry = { " + "1" + "(6 << 24)" + "1" + "1" + "53" + "sizeof(\"src/debugability/macros.c\")" + "sizeof(\"Message\")" + "\"src/debugability/macros.c\"" + "\"Message\" " + "}"; (void)state; - assert_string_equal(macro_result, should_be_eq); } @@ -83,25 +99,20 @@ static char *get_should_be(const int param_count) { char *result = malloc(sizeof(char) * 1024); char *paramlist = get_param_list(param_count); - char *maybe_comma = ","; - if (param_count) - maybe_comma = ""; - - /* which format: 0 1 2 3 4 5 6 7 8 9*/ - sprintf(result, "%s%d%s%d%s%d%s%s%s%s", + /* which format: 0 1 2 3 4 5 6 7 8*/ + sprintf(result, "%s%d%s%d%s%d%s%s%s", /*0*/"{ __attribute__((unused)) typedef char assertion_failed_" META_QUOTE(BASE_LOG_ASSERT_FAIL_MSG) "[(", /*1*/_TRACE_EVENT_MAX_ARGUMENT_COUNT, /*2*/" >= ", /*3*/param_count, - /*4*/") ? 1 : -1]; log_func log_function = (log_func)& _trace_event", + /*4*/") ? 1 : -1]; _trace_event", /*5*/param_count, - /*6*/"; log_function(&log_entry", - /*7*/maybe_comma, - /*8*/paramlist, - /*9*/");}" + /*6*/" ((uint32_t)&log_entry, 1, 1", + /*7*/paramlist, + /*8*/"); }" ); if (paramlist) free(paramlist); @@ -109,39 +120,42 @@ static char *get_should_be(const int param_count) return result; } -#define test_debugability_macros_base_base(...)\ -do {\ - _DECLARE_LOG_ENTRY(\ - LOG_LEVEL_CRITICAL,\ - "Message",\ - TRACE_CLASS_DMA,\ - META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__)\ - );\ - const char *macro_result = CAPTURE(BASE_LOG(\ - _trace_event,\ - &log_entry,\ - __VA_ARGS__\ - ));\ - char *should_be_eq = get_should_be(\ - META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__));\ -\ - /* to avoid "log_entry not used" warning */\ - assert_true(log_entry.level == log_entry.level);\ -\ - (void)state;\ -\ - assert_string_equal(macro_result, should_be_eq);\ - if (should_be_eq)\ - free(should_be_eq);\ -} while (0)\ +#define test_debugability_macros_base_base(...) \ +do { \ + _DECLARE_LOG_ENTRY( \ + LOG_LEVEL_CRITICAL, \ + "Message", \ + TRACE_CLASS_DMA, \ + META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__), \ + 1 \ + ); \ + const char *macro_result = CAPTURE(BASE_LOG( \ + _trace_event, \ + 1, \ + 1, \ + &log_entry, \ + ##__VA_ARGS__ \ + )); \ + char *should_be_eq = get_should_be( \ + META_COUNT_VARAGS_BEFORE_COMPILE(__VA_ARGS__)); \ + \ + /* to avoid "log_entry not used" warning */ \ + assert_true(log_entry.level == log_entry.level); \ + \ + (void)state; \ + \ + assert_string_equal(macro_result, should_be_eq); \ + if (should_be_eq) \ + free(should_be_eq); \ +} while (0) -#define TEST_FUNC_(param_count, ...)\ -static void META_CONCAT_SEQ_DELIM_(\ - test_debugability_macros_base_log,\ - param_count,\ - params)\ -(void **state)\ -{\ +#define TEST_FUNC_(param_count, ...) \ +static void META_CONCAT_SEQ_DELIM_( \ + test_debugability_macros_base_log, \ + param_count, \ + params) \ +(void **state) \ +{ \ test_debugability_macros_base_base(__VA_ARGS__);\ } diff --git a/test/cmocka/src/lib/alloc/alloc.c b/test/cmocka/src/lib/alloc/alloc.c index cda06221c..6cfa3fcbc 100644 --- a/test/cmocka/src/lib/alloc/alloc.c +++ b/test/cmocka/src/lib/alloc/alloc.c @@ -37,6 +37,7 @@ #include #include +#include extern struct mm memmap; diff --git a/test/cmocka/src/lib/alloc/mock.c b/test/cmocka/src/lib/alloc/mock.c index 9e44524df..43dafb484 100644 --- a/test/cmocka/src/lib/alloc/mock.c +++ b/test/cmocka/src/lib/alloc/mock.c @@ -34,6 +34,10 @@ #include #include +#include + +TRACE_IMPL() + struct dma_copy; struct dma_sg_config; @@ -44,45 +48,6 @@ int rstrlen(const char *s) return 0; } -void _trace_event0(uint32_t log_entry) -{ - (void)log_entry; -} - -void _trace_event1(uint32_t log_entry, uint32_t param) -{ - (void)log_entry; - (void)param; -} - -void _trace_event_mbox_atomic0(uint32_t log_entry) -{ - (void)log_entry; -} - -void _trace_event_mbox_atomic1(uint32_t log_entry, uint32_t param) -{ - (void)log_entry; - (void)param; -} - -void _trace_event_mbox_atomic2(uint32_t log_entry, uint32_t param1, - uint32_t param2) -{ - (void)log_entry; - (void)param1; - (void)param2; -} - -void _trace_event_mbox_atomic3(uint32_t log_entry, uint32_t param1, - uint32_t param2, uint32_t param3) -{ - (void)log_entry; - (void)param1; - (void)param2; - (void)param3; -} - void trace_flush(void) { }