blob: 4e52e5bed822af34e8bc4e3b6c63a3823dc83995 [file] [log] [blame]
Heinrich Schuchardt395041b2020-02-26 21:48:18 +01001// 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>
Simon Glasse1cbd912021-05-08 13:46:54 -060013#include <log.h>
Simon Glass401d1c42020-10-30 21:38:53 -060014#include <asm/global_data.h>
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010015#include <test/log.h>
16#include <test/test.h>
17#include <test/suites.h>
18#include <test/ut.h>
19
20DECLARE_GLOBAL_DATA_PTR;
21
22#define BUFFSIZE 32
23
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020024static int log_test_nolog_err(struct unit_test_state *uts)
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010025{
26 char buf[BUFFSIZE];
27
28 memset(buf, 0, BUFFSIZE);
29 console_record_reset_enable();
30 log_err("testing %s\n", "log_err");
31 gd->flags &= ~GD_FLG_RECORD;
32 ut_assertok(ut_check_console_line(uts, "testing log_err"));
33 ut_assertok(ut_check_console_end(uts));
34 return 0;
35}
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020036LOG_TEST(log_test_nolog_err);
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010037
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020038static int log_test_nolog_warning(struct unit_test_state *uts)
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010039{
40 char buf[BUFFSIZE];
41
42 memset(buf, 0, BUFFSIZE);
43 console_record_reset_enable();
44 log_warning("testing %s\n", "log_warning");
45 gd->flags &= ~GD_FLG_RECORD;
46 ut_assertok(ut_check_console_line(uts, "testing log_warning"));
47 ut_assertok(ut_check_console_end(uts));
48 return 0;
49}
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020050LOG_TEST(log_test_nolog_warning);
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010051
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020052static int log_test_nolog_notice(struct unit_test_state *uts)
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010053{
54 char buf[BUFFSIZE];
55
56 memset(buf, 0, BUFFSIZE);
57 console_record_reset_enable();
58 log_notice("testing %s\n", "log_notice");
59 gd->flags &= ~GD_FLG_RECORD;
60 ut_assertok(ut_check_console_line(uts, "testing log_notice"));
61 ut_assertok(ut_check_console_end(uts));
62 return 0;
63}
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020064LOG_TEST(log_test_nolog_notice);
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010065
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020066static int log_test_nolog_info(struct unit_test_state *uts)
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010067{
68 char buf[BUFFSIZE];
69
70 memset(buf, 0, BUFFSIZE);
71 console_record_reset_enable();
72 log_err("testing %s\n", "log_info");
73 gd->flags &= ~GD_FLG_RECORD;
74 ut_assertok(ut_check_console_line(uts, "testing log_info"));
75 ut_assertok(ut_check_console_end(uts));
76 return 0;
77}
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020078LOG_TEST(log_test_nolog_info);
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010079
80#undef _DEBUG
81#define _DEBUG 0
82static int nolog_test_nodebug(struct unit_test_state *uts)
83{
84 char buf[BUFFSIZE];
85
86 memset(buf, 0, BUFFSIZE);
87 console_record_reset_enable();
88 debug("testing %s\n", "debug");
89 gd->flags &= ~GD_FLG_RECORD;
90 ut_assertok(ut_check_console_end(uts));
91 return 0;
92}
93LOG_TEST(nolog_test_nodebug);
94
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020095static int log_test_nolog_nodebug(struct unit_test_state *uts)
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010096{
97 char buf[BUFFSIZE];
98
99 memset(buf, 0, BUFFSIZE);
100 console_record_reset_enable();
101 log_debug("testing %s\n", "log_debug");
102 gd->flags &= ~GD_FLG_RECORD;
103 ut_assert(!strcmp(buf, ""));
104 ut_assertok(ut_check_console_end(uts));
105 return 0;
106}
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +0200107LOG_TEST(log_test_nolog_nodebug);
Heinrich Schuchardt395041b2020-02-26 21:48:18 +0100108
109#undef _DEBUG
110#define _DEBUG 1
111static int nolog_test_debug(struct unit_test_state *uts)
112{
113 char buf[BUFFSIZE];
114
115 memset(buf, 0, BUFFSIZE);
116 console_record_reset_enable();
117 debug("testing %s\n", "debug");
118 gd->flags &= ~GD_FLG_RECORD;
119 ut_assertok(ut_check_console_line(uts, "testing debug"));
120 ut_assertok(ut_check_console_end(uts));
121 return 0;
122}
123LOG_TEST(nolog_test_debug);
124
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +0200125static int log_test_nolog_debug(struct unit_test_state *uts)
Heinrich Schuchardt395041b2020-02-26 21:48:18 +0100126{
127 char buf[BUFFSIZE];
128
129 memset(buf, 0, BUFFSIZE);
130 console_record_reset_enable();
131 log_debug("testing %s\n", "log_debug");
Simon Glasse1cbd912021-05-08 13:46:54 -0600132 log(LOGC_NONE, LOGL_DEBUG, "more %s\n", "log_debug");
Heinrich Schuchardt395041b2020-02-26 21:48:18 +0100133 gd->flags &= ~GD_FLG_RECORD;
134 ut_assertok(ut_check_console_line(uts, "testing log_debug"));
Simon Glasse1cbd912021-05-08 13:46:54 -0600135 ut_assertok(ut_check_console_line(uts, "more log_debug"));
Heinrich Schuchardt395041b2020-02-26 21:48:18 +0100136 ut_assertok(ut_check_console_end(uts));
137 return 0;
138}
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +0200139LOG_TEST(log_test_nolog_debug);