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 <asm/global_data.h>
14 #include <test/log.h>
15 #include <test/test.h>
16 #include <test/suites.h>
17 #include <test/ut.h>
18 
19 DECLARE_GLOBAL_DATA_PTR;
20 
21 #define BUFFSIZE 32
22 
log_test_nolog_err(struct unit_test_state * uts)23 static int log_test_nolog_err(struct unit_test_state *uts)
24 {
25 	char buf[BUFFSIZE];
26 
27 	memset(buf, 0, BUFFSIZE);
28 	console_record_reset_enable();
29 	log_err("testing %s\n", "log_err");
30 	gd->flags &= ~GD_FLG_RECORD;
31 	ut_assertok(ut_check_console_line(uts, "testing log_err"));
32 	ut_assertok(ut_check_console_end(uts));
33 	return 0;
34 }
35 LOG_TEST(log_test_nolog_err);
36 
log_test_nolog_warning(struct unit_test_state * uts)37 static int log_test_nolog_warning(struct unit_test_state *uts)
38 {
39 	char buf[BUFFSIZE];
40 
41 	memset(buf, 0, BUFFSIZE);
42 	console_record_reset_enable();
43 	log_warning("testing %s\n", "log_warning");
44 	gd->flags &= ~GD_FLG_RECORD;
45 	ut_assertok(ut_check_console_line(uts, "testing log_warning"));
46 	ut_assertok(ut_check_console_end(uts));
47 	return 0;
48 }
49 LOG_TEST(log_test_nolog_warning);
50 
log_test_nolog_notice(struct unit_test_state * uts)51 static int log_test_nolog_notice(struct unit_test_state *uts)
52 {
53 	char buf[BUFFSIZE];
54 
55 	memset(buf, 0, BUFFSIZE);
56 	console_record_reset_enable();
57 	log_notice("testing %s\n", "log_notice");
58 	gd->flags &= ~GD_FLG_RECORD;
59 	ut_assertok(ut_check_console_line(uts, "testing log_notice"));
60 	ut_assertok(ut_check_console_end(uts));
61 	return 0;
62 }
63 LOG_TEST(log_test_nolog_notice);
64 
log_test_nolog_info(struct unit_test_state * uts)65 static int log_test_nolog_info(struct unit_test_state *uts)
66 {
67 	char buf[BUFFSIZE];
68 
69 	memset(buf, 0, BUFFSIZE);
70 	console_record_reset_enable();
71 	log_err("testing %s\n", "log_info");
72 	gd->flags &= ~GD_FLG_RECORD;
73 	ut_assertok(ut_check_console_line(uts, "testing log_info"));
74 	ut_assertok(ut_check_console_end(uts));
75 	return 0;
76 }
77 LOG_TEST(log_test_nolog_info);
78 
79 #undef _DEBUG
80 #define _DEBUG 0
nolog_test_nodebug(struct unit_test_state * uts)81 static int nolog_test_nodebug(struct unit_test_state *uts)
82 {
83 	char buf[BUFFSIZE];
84 
85 	memset(buf, 0, BUFFSIZE);
86 	console_record_reset_enable();
87 	debug("testing %s\n", "debug");
88 	gd->flags &= ~GD_FLG_RECORD;
89 	ut_assertok(ut_check_console_end(uts));
90 	return 0;
91 }
92 LOG_TEST(nolog_test_nodebug);
93 
log_test_nolog_nodebug(struct unit_test_state * uts)94 static int log_test_nolog_nodebug(struct unit_test_state *uts)
95 {
96 	char buf[BUFFSIZE];
97 
98 	memset(buf, 0, BUFFSIZE);
99 	console_record_reset_enable();
100 	log_debug("testing %s\n", "log_debug");
101 	gd->flags &= ~GD_FLG_RECORD;
102 	ut_assert(!strcmp(buf, ""));
103 	ut_assertok(ut_check_console_end(uts));
104 	return 0;
105 }
106 LOG_TEST(log_test_nolog_nodebug);
107 
108 #undef _DEBUG
109 #define _DEBUG 1
nolog_test_debug(struct unit_test_state * uts)110 static int nolog_test_debug(struct unit_test_state *uts)
111 {
112 	char buf[BUFFSIZE];
113 
114 	memset(buf, 0, BUFFSIZE);
115 	console_record_reset_enable();
116 	debug("testing %s\n", "debug");
117 	gd->flags &= ~GD_FLG_RECORD;
118 	ut_assertok(ut_check_console_line(uts, "testing debug"));
119 	ut_assertok(ut_check_console_end(uts));
120 	return 0;
121 }
122 LOG_TEST(nolog_test_debug);
123 
log_test_nolog_debug(struct unit_test_state * uts)124 static int log_test_nolog_debug(struct unit_test_state *uts)
125 {
126 	char buf[BUFFSIZE];
127 
128 	memset(buf, 0, BUFFSIZE);
129 	console_record_reset_enable();
130 	log_debug("testing %s\n", "log_debug");
131 	gd->flags &= ~GD_FLG_RECORD;
132 	ut_assertok(ut_check_console_line(uts, "testing log_debug"));
133 	ut_assertok(ut_check_console_end(uts));
134 	return 0;
135 }
136 LOG_TEST(log_test_nolog_debug);
137