blob: 3cba51f7c45ac662c692913bdc97f1393a00789e [file] [log] [blame]
Patrick Georgiae41dd32021-06-09 16:11:09 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2
Jakub Czapigaab0bcaf2021-06-14 09:32:11 +02003#include "../console/init.c"
4
Patrick Georgiae41dd32021-06-09 16:11:09 +02005#include <console/console.h>
6#include <stdlib.h>
7#include <string.h>
8#include <stdint.h>
9#include <tests/test.h>
10
Patrick Georgiae41dd32021-06-09 16:11:09 +020011struct 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
40static void test_console_log_level(void **state)
41{
42 for (int i = 0; i < ARRAY_SIZE(combinations); i++) {
Jakub Czapigaab0bcaf2021-06-14 09:32:11 +020043 console_loglevel = combinations[i].log_lvl;
Patrick Georgiae41dd32021-06-09 16:11:09 +020044 assert_int_equal(combinations[i].behavior,
Jakub Czapigac08b6a72022-01-10 13:36:47 +000045 console_log_level(combinations[i].msg_lvl));
Patrick Georgiae41dd32021-06-09 16:11:09 +020046 }
47}
48
Jakub Czapigaab0bcaf2021-06-14 09:32:11 +020049static int setup_console_log_level(void **state)
50{
51 console_inited = 1;
52 return 0;
53}
54
55static int teardown_console_log_level(void **state)
56{
57 console_inited = 0;
58 return 0;
59}
60
Patrick Georgiae41dd32021-06-09 16:11:09 +020061int main(void)
62{
63 const struct CMUnitTest tests[] = {
Jakub Czapigac08b6a72022-01-10 13:36:47 +000064 cmocka_unit_test_setup_teardown(test_console_log_level, setup_console_log_level,
Jakub Czapigaab0bcaf2021-06-14 09:32:11 +020065 teardown_console_log_level),
Patrick Georgiae41dd32021-06-09 16:11:09 +020066 };
67
Jakub Czapiga7c6081e2021-08-25 16:27:35 +020068 return cb_run_group_tests(tests, NULL, NULL);
Patrick Georgiae41dd32021-06-09 16:11:09 +020069}