blob: 341dbfc9310efa3fa906bfea933957bde6d83db0 [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
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010011#include <console.h>
Simon Glass8eaaedb2021-05-08 13:46:54 -060012#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Heinrich Schuchardtf433d502020-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 Schuchardt8d9c4c22020-05-06 18:26:08 +020023static int log_test_nolog_err(struct unit_test_state *uts)
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010024{
25 char buf[BUFFSIZE];
26
27 memset(buf, 0, BUFFSIZE);
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010028 log_err("testing %s\n", "log_err");
29 gd->flags &= ~GD_FLG_RECORD;
30 ut_assertok(ut_check_console_line(uts, "testing log_err"));
Simon Glassc579bd42024-08-22 07:58:03 -060031 ut_assert_console_end();
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010032 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);
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010041 log_warning("testing %s\n", "log_warning");
42 gd->flags &= ~GD_FLG_RECORD;
43 ut_assertok(ut_check_console_line(uts, "testing log_warning"));
Simon Glassc579bd42024-08-22 07:58:03 -060044 ut_assert_console_end();
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010045 return 0;
46}
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +020047LOG_TEST(log_test_nolog_warning);
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010048
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +020049static int log_test_nolog_notice(struct unit_test_state *uts)
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010050{
51 char buf[BUFFSIZE];
52
53 memset(buf, 0, BUFFSIZE);
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010054 log_notice("testing %s\n", "log_notice");
55 gd->flags &= ~GD_FLG_RECORD;
56 ut_assertok(ut_check_console_line(uts, "testing log_notice"));
Simon Glassc579bd42024-08-22 07:58:03 -060057 ut_assert_console_end();
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010058 return 0;
59}
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +020060LOG_TEST(log_test_nolog_notice);
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010061
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +020062static int log_test_nolog_info(struct unit_test_state *uts)
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010063{
64 char buf[BUFFSIZE];
65
66 memset(buf, 0, BUFFSIZE);
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010067 log_err("testing %s\n", "log_info");
68 gd->flags &= ~GD_FLG_RECORD;
69 ut_assertok(ut_check_console_line(uts, "testing log_info"));
Simon Glassc579bd42024-08-22 07:58:03 -060070 ut_assert_console_end();
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010071 return 0;
72}
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +020073LOG_TEST(log_test_nolog_info);
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010074
75#undef _DEBUG
76#define _DEBUG 0
77static int nolog_test_nodebug(struct unit_test_state *uts)
78{
79 char buf[BUFFSIZE];
80
81 memset(buf, 0, BUFFSIZE);
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010082 debug("testing %s\n", "debug");
83 gd->flags &= ~GD_FLG_RECORD;
Simon Glassc579bd42024-08-22 07:58:03 -060084 ut_assert_console_end();
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010085 return 0;
86}
87LOG_TEST(nolog_test_nodebug);
88
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +020089static int log_test_nolog_nodebug(struct unit_test_state *uts)
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010090{
91 char buf[BUFFSIZE];
92
93 memset(buf, 0, BUFFSIZE);
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010094 log_debug("testing %s\n", "log_debug");
95 gd->flags &= ~GD_FLG_RECORD;
96 ut_assert(!strcmp(buf, ""));
Simon Glassc579bd42024-08-22 07:58:03 -060097 ut_assert_console_end();
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010098 return 0;
99}
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +0200100LOG_TEST(log_test_nolog_nodebug);
Heinrich Schuchardtf433d502020-02-26 21:48:18 +0100101
102#undef _DEBUG
103#define _DEBUG 1
104static int nolog_test_debug(struct unit_test_state *uts)
105{
106 char buf[BUFFSIZE];
107
108 memset(buf, 0, BUFFSIZE);
Heinrich Schuchardtf433d502020-02-26 21:48:18 +0100109 debug("testing %s\n", "debug");
110 gd->flags &= ~GD_FLG_RECORD;
111 ut_assertok(ut_check_console_line(uts, "testing debug"));
Simon Glassc579bd42024-08-22 07:58:03 -0600112 ut_assert_console_end();
Heinrich Schuchardtf433d502020-02-26 21:48:18 +0100113 return 0;
114}
115LOG_TEST(nolog_test_debug);
116
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +0200117static int log_test_nolog_debug(struct unit_test_state *uts)
Heinrich Schuchardtf433d502020-02-26 21:48:18 +0100118{
119 char buf[BUFFSIZE];
120
121 memset(buf, 0, BUFFSIZE);
Heinrich Schuchardtf433d502020-02-26 21:48:18 +0100122 log_debug("testing %s\n", "log_debug");
Simon Glass8eaaedb2021-05-08 13:46:54 -0600123 log(LOGC_NONE, LOGL_DEBUG, "more %s\n", "log_debug");
Heinrich Schuchardtf433d502020-02-26 21:48:18 +0100124 gd->flags &= ~GD_FLG_RECORD;
125 ut_assertok(ut_check_console_line(uts, "testing log_debug"));
Simon Glass8eaaedb2021-05-08 13:46:54 -0600126 ut_assertok(ut_check_console_line(uts, "more log_debug"));
Simon Glassc579bd42024-08-22 07:58:03 -0600127 ut_assert_console_end();
Heinrich Schuchardtf433d502020-02-26 21:48:18 +0100128 return 0;
129}
Heinrich Schuchardt8d9c4c22020-05-06 18:26:08 +0200130LOG_TEST(log_test_nolog_debug);