Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 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 | |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 11 | #include <console.h> |
Simon Glass | 8eaaedb | 2021-05-08 13:46:54 -0600 | [diff] [blame] | 12 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 14 | #include <test/log.h> |
| 15 | #include <test/test.h> |
| 16 | #include <test/suites.h> |
| 17 | #include <test/ut.h> |
| 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
| 21 | #define BUFFSIZE 32 |
| 22 | |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 23 | static int log_test_nolog_err(struct unit_test_state *uts) |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 24 | { |
| 25 | char buf[BUFFSIZE]; |
| 26 | |
| 27 | memset(buf, 0, BUFFSIZE); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 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")); |
Simon Glass | c579bd4 | 2024-08-22 07:58:03 -0600 | [diff] [blame] | 31 | ut_assert_console_end(); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 32 | return 0; |
| 33 | } |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 34 | LOG_TEST(log_test_nolog_err); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 35 | |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 36 | static int log_test_nolog_warning(struct unit_test_state *uts) |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 37 | { |
| 38 | char buf[BUFFSIZE]; |
| 39 | |
| 40 | memset(buf, 0, BUFFSIZE); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 41 | 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 Glass | c579bd4 | 2024-08-22 07:58:03 -0600 | [diff] [blame] | 44 | ut_assert_console_end(); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 45 | return 0; |
| 46 | } |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 47 | LOG_TEST(log_test_nolog_warning); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 48 | |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 49 | static int log_test_nolog_notice(struct unit_test_state *uts) |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 50 | { |
| 51 | char buf[BUFFSIZE]; |
| 52 | |
| 53 | memset(buf, 0, BUFFSIZE); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 54 | 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 Glass | c579bd4 | 2024-08-22 07:58:03 -0600 | [diff] [blame] | 57 | ut_assert_console_end(); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 58 | return 0; |
| 59 | } |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 60 | LOG_TEST(log_test_nolog_notice); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 61 | |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 62 | static int log_test_nolog_info(struct unit_test_state *uts) |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 63 | { |
| 64 | char buf[BUFFSIZE]; |
| 65 | |
| 66 | memset(buf, 0, BUFFSIZE); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 67 | 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 Glass | c579bd4 | 2024-08-22 07:58:03 -0600 | [diff] [blame] | 70 | ut_assert_console_end(); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 71 | return 0; |
| 72 | } |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 73 | LOG_TEST(log_test_nolog_info); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 74 | |
| 75 | #undef _DEBUG |
| 76 | #define _DEBUG 0 |
| 77 | static int nolog_test_nodebug(struct unit_test_state *uts) |
| 78 | { |
| 79 | char buf[BUFFSIZE]; |
| 80 | |
| 81 | memset(buf, 0, BUFFSIZE); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 82 | debug("testing %s\n", "debug"); |
| 83 | gd->flags &= ~GD_FLG_RECORD; |
Simon Glass | c579bd4 | 2024-08-22 07:58:03 -0600 | [diff] [blame] | 84 | ut_assert_console_end(); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | LOG_TEST(nolog_test_nodebug); |
| 88 | |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 89 | static int log_test_nolog_nodebug(struct unit_test_state *uts) |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 90 | { |
| 91 | char buf[BUFFSIZE]; |
| 92 | |
| 93 | memset(buf, 0, BUFFSIZE); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 94 | log_debug("testing %s\n", "log_debug"); |
| 95 | gd->flags &= ~GD_FLG_RECORD; |
| 96 | ut_assert(!strcmp(buf, "")); |
Simon Glass | c579bd4 | 2024-08-22 07:58:03 -0600 | [diff] [blame] | 97 | ut_assert_console_end(); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 98 | return 0; |
| 99 | } |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 100 | LOG_TEST(log_test_nolog_nodebug); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 101 | |
| 102 | #undef _DEBUG |
| 103 | #define _DEBUG 1 |
| 104 | static int nolog_test_debug(struct unit_test_state *uts) |
| 105 | { |
| 106 | char buf[BUFFSIZE]; |
| 107 | |
| 108 | memset(buf, 0, BUFFSIZE); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 109 | debug("testing %s\n", "debug"); |
| 110 | gd->flags &= ~GD_FLG_RECORD; |
| 111 | ut_assertok(ut_check_console_line(uts, "testing debug")); |
Simon Glass | c579bd4 | 2024-08-22 07:58:03 -0600 | [diff] [blame] | 112 | ut_assert_console_end(); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | LOG_TEST(nolog_test_debug); |
| 116 | |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 117 | static int log_test_nolog_debug(struct unit_test_state *uts) |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 118 | { |
| 119 | char buf[BUFFSIZE]; |
| 120 | |
| 121 | memset(buf, 0, BUFFSIZE); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 122 | log_debug("testing %s\n", "log_debug"); |
Simon Glass | 8eaaedb | 2021-05-08 13:46:54 -0600 | [diff] [blame] | 123 | log(LOGC_NONE, LOGL_DEBUG, "more %s\n", "log_debug"); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 124 | gd->flags &= ~GD_FLG_RECORD; |
| 125 | ut_assertok(ut_check_console_line(uts, "testing log_debug")); |
Simon Glass | 8eaaedb | 2021-05-08 13:46:54 -0600 | [diff] [blame] | 126 | ut_assertok(ut_check_console_line(uts, "more log_debug")); |
Simon Glass | c579bd4 | 2024-08-22 07:58:03 -0600 | [diff] [blame] | 127 | ut_assert_console_end(); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 128 | return 0; |
| 129 | } |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 130 | LOG_TEST(log_test_nolog_debug); |