]> git.ipfire.org Git - thirdparty/u-boot.git/blame - test/log/nolog_test.c
test: Remove <common.h> and add needed includes
[thirdparty/u-boot.git] / test / log / nolog_test.c
CommitLineData
395041b2
HS
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
395041b2 11#include <console.h>
e1cbd916 12#include <log.h>
401d1c4f 13#include <asm/global_data.h>
395041b2
HS
14#include <test/log.h>
15#include <test/test.h>
16#include <test/suites.h>
17#include <test/ut.h>
18
19DECLARE_GLOBAL_DATA_PTR;
20
21#define BUFFSIZE 32
22
be51c3ca 23static int log_test_nolog_err(struct unit_test_state *uts)
395041b2
HS
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}
be51c3ca 35LOG_TEST(log_test_nolog_err);
395041b2 36
be51c3ca 37static int log_test_nolog_warning(struct unit_test_state *uts)
395041b2
HS
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}
be51c3ca 49LOG_TEST(log_test_nolog_warning);
395041b2 50
be51c3ca 51static int log_test_nolog_notice(struct unit_test_state *uts)
395041b2
HS
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}
be51c3ca 63LOG_TEST(log_test_nolog_notice);
395041b2 64
be51c3ca 65static int log_test_nolog_info(struct unit_test_state *uts)
395041b2
HS
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}
be51c3ca 77LOG_TEST(log_test_nolog_info);
395041b2
HS
78
79#undef _DEBUG
80#define _DEBUG 0
81static 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}
92LOG_TEST(nolog_test_nodebug);
93
be51c3ca 94static int log_test_nolog_nodebug(struct unit_test_state *uts)
395041b2
HS
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}
be51c3ca 106LOG_TEST(log_test_nolog_nodebug);
395041b2
HS
107
108#undef _DEBUG
109#define _DEBUG 1
110static 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}
122LOG_TEST(nolog_test_debug);
123
be51c3ca 124static int log_test_nolog_debug(struct unit_test_state *uts)
395041b2
HS
125{
126 char buf[BUFFSIZE];
127
128 memset(buf, 0, BUFFSIZE);
129 console_record_reset_enable();
130 log_debug("testing %s\n", "log_debug");
e1cbd916 131 log(LOGC_NONE, LOGL_DEBUG, "more %s\n", "log_debug");
395041b2
HS
132 gd->flags &= ~GD_FLG_RECORD;
133 ut_assertok(ut_check_console_line(uts, "testing log_debug"));
e1cbd916 134 ut_assertok(ut_check_console_line(uts, "more log_debug"));
395041b2
HS
135 ut_assertok(ut_check_console_end(uts));
136 return 0;
137}
be51c3ca 138LOG_TEST(log_test_nolog_debug);