/ tests / console / routing-test.c
routing-test.c
 1  /* SPDX-License-Identifier: GPL-2.0-only */
 2  
 3  #include "../console/init.c"
 4  
 5  #include <console/console.h>
 6  #include <stdlib.h>
 7  #include <string.h>
 8  #include <stdint.h>
 9  #include <tests/test.h>
10  
11  struct log_combinations_t {
12  	int log_lvl;
13  	int msg_lvl;
14  	int behavior;
15  } combinations[] = {
16  	{.log_lvl = -1, .msg_lvl = BIOS_ERR, .behavior = CONSOLE_LOG_NONE},
17  	{.log_lvl = -1, .msg_lvl = BIOS_SPEW, .behavior = CONSOLE_LOG_NONE},
18  
19  	{.log_lvl = BIOS_DEBUG, .msg_lvl = BIOS_ERR, .behavior = CONSOLE_LOG_ALL},
20  	{.log_lvl = BIOS_DEBUG, .msg_lvl = BIOS_DEBUG, .behavior = CONSOLE_LOG_ALL},
21  	{.log_lvl = BIOS_DEBUG, .msg_lvl = BIOS_SPEW, .behavior = CONSOLE_LOG_NONE},
22  
23  	{.log_lvl = BIOS_SPEW, .msg_lvl = BIOS_ERR, .behavior = CONSOLE_LOG_ALL},
24  	{.log_lvl = BIOS_SPEW, .msg_lvl = BIOS_DEBUG, .behavior = CONSOLE_LOG_ALL},
25  	{.log_lvl = BIOS_SPEW, .msg_lvl = BIOS_SPEW, .behavior = CONSOLE_LOG_ALL},
26  
27  #if CONFIG(CONSOLE_CBMEM)
28  	{.log_lvl = BIOS_WARNING, .msg_lvl = BIOS_ERR, .behavior = CONSOLE_LOG_ALL},
29  	{.log_lvl = BIOS_WARNING, .msg_lvl = BIOS_DEBUG, .behavior = CONSOLE_LOG_FAST},
30  	{.log_lvl = BIOS_WARNING, .msg_lvl = BIOS_SPEW, .behavior = CONSOLE_LOG_NONE},
31  
32  #else
33  	{.log_lvl = BIOS_WARNING, .msg_lvl = BIOS_ERR, .behavior = CONSOLE_LOG_ALL},
34  	{.log_lvl = BIOS_WARNING, .msg_lvl = BIOS_DEBUG, .behavior = CONSOLE_LOG_NONE},
35  	{.log_lvl = BIOS_WARNING, .msg_lvl = BIOS_SPEW, .behavior = CONSOLE_LOG_NONE},
36  #endif
37  };
38  
39  
40  static void test_console_log_level(void **state)
41  {
42  	for (int i = 0; i < ARRAY_SIZE(combinations); i++) {
43  		console_loglevel = combinations[i].log_lvl;
44  		assert_int_equal(combinations[i].behavior,
45  				 console_log_level(combinations[i].msg_lvl));
46  	}
47  }
48  
49  static int setup_console_log_level(void **state)
50  {
51  	console_inited = 1;
52  	return 0;
53  }
54  
55  static int teardown_console_log_level(void **state)
56  {
57  	console_inited = 0;
58  	return 0;
59  }
60  
61  int main(void)
62  {
63  	const struct CMUnitTest tests[] = {
64  		cmocka_unit_test_setup_teardown(test_console_log_level, setup_console_log_level,
65  						teardown_console_log_level),
66  	};
67  
68  	return cb_run_group_tests(tests, NULL, NULL);
69  }