blob: c4c0fa6cf81a055855daf84a8bc0a667825cbf20 [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
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010011#include <console.h>
Simon Glasse1cbd912021-05-08 13:46:54 -060012#include <log.h>
Simon Glass401d1c42020-10-30 21:38:53 -060013#include <asm/global_data.h>
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010014#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
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020023static int log_test_nolog_err(struct unit_test_state *uts)
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010024{
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}
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020035LOG_TEST(log_test_nolog_err);
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010036
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020037static int log_test_nolog_warning(struct unit_test_state *uts)
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010038{
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}
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020049LOG_TEST(log_test_nolog_warning);
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010050
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020051static int log_test_nolog_notice(struct unit_test_state *uts)
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010052{
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}
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020063LOG_TEST(log_test_nolog_notice);
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010064
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020065static int log_test_nolog_info(struct unit_test_state *uts)
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010066{
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}
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020077LOG_TEST(log_test_nolog_info);
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010078
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
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +020094static int log_test_nolog_nodebug(struct unit_test_state *uts)
Heinrich Schuchardt395041b2020-02-26 21:48:18 +010095{
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}
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +0200106LOG_TEST(log_test_nolog_nodebug);
Heinrich Schuchardt395041b2020-02-26 21:48:18 +0100107
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
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +0200124static int log_test_nolog_debug(struct unit_test_state *uts)
Heinrich Schuchardt395041b2020-02-26 21:48:18 +0100125{
126 char buf[BUFFSIZE];
127
128 memset(buf, 0, BUFFSIZE);
129 console_record_reset_enable();
130 log_debug("testing %s\n", "log_debug");
Simon Glasse1cbd912021-05-08 13:46:54 -0600131 log(LOGC_NONE, LOGL_DEBUG, "more %s\n", "log_debug");
Heinrich Schuchardt395041b2020-02-26 21:48:18 +0100132 gd->flags &= ~GD_FLG_RECORD;
133 ut_assertok(ut_check_console_line(uts, "testing log_debug"));
Simon Glasse1cbd912021-05-08 13:46:54 -0600134 ut_assertok(ut_check_console_line(uts, "more log_debug"));
Heinrich Schuchardt395041b2020-02-26 21:48:18 +0100135 ut_assertok(ut_check_console_end(uts));
136 return 0;
137}
Heinrich Schuchardtbe51c3c2020-05-06 18:26:08 +0200138LOG_TEST(log_test_nolog_debug);