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