Merge tag 'efi-2020-07-rc2-3' of https://gitlab.denx.de/u-boot/custodians/u-boot-efi
[oweals/u-boot.git] / test / log / nolog_test.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
4  *
5  * Logging function tests for CONFIG_LOG=n.
6  */
7
8 /* Needed for testing log_debug() */
9 #define DEBUG 1
10
11 #include <common.h>
12 #include <console.h>
13 #include <test/log.h>
14 #include <test/test.h>
15 #include <test/suites.h>
16 #include <test/ut.h>
17
18 DECLARE_GLOBAL_DATA_PTR;
19
20 #define BUFFSIZE 32
21
22 static int nolog_test_log_err(struct unit_test_state *uts)
23 {
24         char buf[BUFFSIZE];
25
26         memset(buf, 0, BUFFSIZE);
27         console_record_reset_enable();
28         log_err("testing %s\n", "log_err");
29         gd->flags &= ~GD_FLG_RECORD;
30         ut_assertok(ut_check_console_line(uts, "testing log_err"));
31         ut_assertok(ut_check_console_end(uts));
32         return 0;
33 }
34 LOG_TEST(nolog_test_log_err);
35
36 static int nolog_test_log_warning(struct unit_test_state *uts)
37 {
38         char buf[BUFFSIZE];
39
40         memset(buf, 0, BUFFSIZE);
41         console_record_reset_enable();
42         log_warning("testing %s\n", "log_warning");
43         gd->flags &= ~GD_FLG_RECORD;
44         ut_assertok(ut_check_console_line(uts, "testing log_warning"));
45         ut_assertok(ut_check_console_end(uts));
46         return 0;
47 }
48 LOG_TEST(nolog_test_log_warning);
49
50 static int nolog_test_log_notice(struct unit_test_state *uts)
51 {
52         char buf[BUFFSIZE];
53
54         memset(buf, 0, BUFFSIZE);
55         console_record_reset_enable();
56         log_notice("testing %s\n", "log_notice");
57         gd->flags &= ~GD_FLG_RECORD;
58         ut_assertok(ut_check_console_line(uts, "testing log_notice"));
59         ut_assertok(ut_check_console_end(uts));
60         return 0;
61 }
62 LOG_TEST(nolog_test_log_notice);
63
64 static int nolog_test_log_info(struct unit_test_state *uts)
65 {
66         char buf[BUFFSIZE];
67
68         memset(buf, 0, BUFFSIZE);
69         console_record_reset_enable();
70         log_err("testing %s\n", "log_info");
71         gd->flags &= ~GD_FLG_RECORD;
72         ut_assertok(ut_check_console_line(uts, "testing log_info"));
73         ut_assertok(ut_check_console_end(uts));
74         return 0;
75 }
76 LOG_TEST(nolog_test_log_info);
77
78 #undef _DEBUG
79 #define _DEBUG 0
80 static int nolog_test_nodebug(struct unit_test_state *uts)
81 {
82         char buf[BUFFSIZE];
83
84         memset(buf, 0, BUFFSIZE);
85         console_record_reset_enable();
86         debug("testing %s\n", "debug");
87         gd->flags &= ~GD_FLG_RECORD;
88         ut_assertok(ut_check_console_end(uts));
89         return 0;
90 }
91 LOG_TEST(nolog_test_nodebug);
92
93 static int nolog_test_log_nodebug(struct unit_test_state *uts)
94 {
95         char buf[BUFFSIZE];
96
97         memset(buf, 0, BUFFSIZE);
98         console_record_reset_enable();
99         log_debug("testing %s\n", "log_debug");
100         gd->flags &= ~GD_FLG_RECORD;
101         ut_assert(!strcmp(buf, ""));
102         ut_assertok(ut_check_console_end(uts));
103         return 0;
104 }
105 LOG_TEST(nolog_test_log_nodebug);
106
107 #undef _DEBUG
108 #define _DEBUG 1
109 static int nolog_test_debug(struct unit_test_state *uts)
110 {
111         char buf[BUFFSIZE];
112
113         memset(buf, 0, BUFFSIZE);
114         console_record_reset_enable();
115         debug("testing %s\n", "debug");
116         gd->flags &= ~GD_FLG_RECORD;
117         ut_assertok(ut_check_console_line(uts, "testing debug"));
118         ut_assertok(ut_check_console_end(uts));
119         return 0;
120 }
121 LOG_TEST(nolog_test_debug);
122
123 static int nolog_test_log_debug(struct unit_test_state *uts)
124 {
125         char buf[BUFFSIZE];
126
127         memset(buf, 0, BUFFSIZE);
128         console_record_reset_enable();
129         log_debug("testing %s\n", "log_debug");
130         gd->flags &= ~GD_FLG_RECORD;
131         ut_assertok(ut_check_console_line(uts, "testing log_debug"));
132         ut_assertok(ut_check_console_end(uts));
133         return 0;
134 }
135 LOG_TEST(nolog_test_log_debug);