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