1 // SPDX-License-Identifier: BSD-3-Clause
2 //
3 // Copyright(c) 2018 Intel Corporation. All rights reserved.
4 //
5 // Author: Michal Jerzy Wierzbicki <michalx.wierzbicki@linux.intel.com>
6 
7 #include <rtos/alloc.h>
8 
9 #include <stdio.h>
10 #include <stdarg.h>
11 #include <setjmp.h>
12 #include <stdint.h>
13 #include <cmocka.h>
14 
15 #ifdef HAVE_MALLOC_H
16 #include <malloc.h>
17 #else
18 #include <stdlib.h>
19 #endif
20 
21 #include <sof/trace/preproc.h>
22 #include <rtos/sof.h>
23 #include <sof/trace/trace.h>
24 #include <user/trace.h>
25 
26 #define CAPTURE(aggr, ...)\
27 	META_RECURSE(META_MAP(1, META_QUOTE, aggr, __VA_ARGS__))
28 
29 static void test_debugability_macros_declare_log_entry(void **state)
30 {
31 	const char *macro_result = CAPTURE(_DECLARE_LOG_ENTRY(
32 		LOG_LEVEL_CRITICAL,
33 		"Message",
34 		0,
35 		1
36 	));
37 	const char *should_be_eq =
38 		"__attribute__((section(\".static_log.\""
39 		" \"LOG_LEVEL_CRITICAL\"))) "
40 		"static const struct "
41 		"{ "
42 			"uint32_t level; "
43 			"uint32_t component_class; "
44 			"uint32_t params_num; "
45 			"uint32_t line_idx; "
46 			"uint32_t file_name_len; "
47 			"uint32_t text_len; "
48 			"const char file_name[sizeof(\"" RELATIVE_FILE "\")]; "
49 			"const char text[sizeof(\"Message\")]; "
50 		"} log_entry = { "
51 			"1"
52 			"0"
53 			"1"
54 			"36"
55 			"sizeof(\"" RELATIVE_FILE "\")"
56 			"sizeof(\"Message\")"
57 			"\"" RELATIVE_FILE "\""
58 			"\"Message\" "
59 		"}";
60 	(void)state;
61 	assert_string_equal(macro_result, should_be_eq);
62 }
63 
64 int main(void)
65 {
66 	const struct CMUnitTest tests[] = {
67 		cmocka_unit_test(test_debugability_macros_declare_log_entry),
68 	};
69 
70 	cmocka_set_message_output(CM_OUTPUT_TAP);
71 
72 	return cmocka_run_group_tests(tests, NULL, NULL);
73 }
74