blob: c418ed07c9a2e5b51ecd961fc17704238146502b [file] [log] [blame]
Heinrich Schuchardtf433d502020-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>
13#include <test/log.h>
14#include <test/test.h>
15#include <test/suites.h>
16#include <test/ut.h>
17
18DECLARE_GLOBAL_DATA_PTR;
19
20#define BUFFSIZE 32
21
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +020022static int log_test_nolog_err(struct unit_test_state *uts)
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010023{
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}
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +020034LOG_TEST(log_test_nolog_err);
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010035
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +020036static int log_test_nolog_warning(struct unit_test_state *uts)
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010037{
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}
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +020048LOG_TEST(log_test_nolog_warning);
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010049
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +020050static int log_test_nolog_notice(struct unit_test_state *uts)
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010051{
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}
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +020062LOG_TEST(log_test_nolog_notice);
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010063
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +020064static int log_test_nolog_info(struct unit_test_state *uts)
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010065{
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}
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +020076LOG_TEST(log_test_nolog_info);
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010077
78#undef _DEBUG
79#define _DEBUG 0
80static 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}
91LOG_TEST(nolog_test_nodebug);
92
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +020093static int log_test_nolog_nodebug(struct unit_test_state *uts)
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010094{
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}
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +0200105LOG_TEST(log_test_nolog_nodebug);
Heinrich Schuchardtf433d502020-02-26 21:48:18 +0100106
107#undef _DEBUG
108#define _DEBUG 1
109static 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}
121LOG_TEST(nolog_test_debug);
122
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +0200123static int log_test_nolog_debug(struct unit_test_state *uts)
Heinrich Schuchardtf433d502020-02-26 21:48:18 +0100124{
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}
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +0200135LOG_TEST(log_test_nolog_debug);