UT: Fix unit tests after faulty PRs were merged.

Signed-off-by: ArturX Kloniecki <arturx.kloniecki@linux.intel.com>
This commit is contained in:
ArturX Kloniecki 2018-11-13 14:28:19 +01:00
parent 73475e3fbb
commit 6ba817bee6
8 changed files with 116 additions and 171 deletions

View File

@ -0,0 +1,37 @@
#include <sof/preproc.h>
#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)

View File

@ -34,27 +34,9 @@
#include <sof/alloc.h>
#include <sof/trace.h>
void _trace_event0(uint32_t log_entry)
{
(void)log_entry;
}
#include <mock_trace.h>
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)
{

View File

@ -34,27 +34,9 @@
#include <sof/alloc.h>
#include <sof/trace.h>
void _trace_event0(uint32_t log_entry)
{
(void)log_entry;
}
#include <mock_trace.h>
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)
{

View File

@ -38,27 +38,9 @@
#include "comp_mock.h"
void _trace_event0(uint32_t log_entry)
{
(void)log_entry;
}
#include <mock_trace.h>
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)
{

View File

@ -30,6 +30,10 @@
#include "pipeline_mocks.h"
#include <mock_trace.h>
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;

View File

@ -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__);\
}

View File

@ -37,6 +37,7 @@
#include <sof/sof.h>
#include <sof/alloc.h>
#include <uapi/ipc/header.h>
extern struct mm memmap;

View File

@ -34,6 +34,10 @@
#include <sof/alloc.h>
#include <sof/trace.h>
#include <mock_trace.h>
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)
{
}