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 | |
| 11 | #include <common.h> |
| 12 | #include <console.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); |
| 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 Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 35 | LOG_TEST(log_test_nolog_err); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 36 | |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 37 | static int log_test_nolog_warning(struct unit_test_state *uts) |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 38 | { |
| 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 Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 49 | LOG_TEST(log_test_nolog_warning); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 50 | |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 51 | static int log_test_nolog_notice(struct unit_test_state *uts) |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 52 | { |
| 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 Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 63 | LOG_TEST(log_test_nolog_notice); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 64 | |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 65 | static int log_test_nolog_info(struct unit_test_state *uts) |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 66 | { |
| 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 Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 77 | LOG_TEST(log_test_nolog_info); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 78 | |
| 79 | #undef _DEBUG |
| 80 | #define _DEBUG 0 |
| 81 | static 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 | } |
| 92 | LOG_TEST(nolog_test_nodebug); |
| 93 | |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 94 | static int log_test_nolog_nodebug(struct unit_test_state *uts) |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 95 | { |
| 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 Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 106 | LOG_TEST(log_test_nolog_nodebug); |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 107 | |
| 108 | #undef _DEBUG |
| 109 | #define _DEBUG 1 |
| 110 | static 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 | } |
| 122 | LOG_TEST(nolog_test_debug); |
| 123 | |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 124 | static int log_test_nolog_debug(struct unit_test_state *uts) |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 125 | { |
| 126 | char buf[BUFFSIZE]; |
| 127 | |
| 128 | memset(buf, 0, BUFFSIZE); |
| 129 | console_record_reset_enable(); |
| 130 | log_debug("testing %s\n", "log_debug"); |
| 131 | gd->flags &= ~GD_FLG_RECORD; |
| 132 | ut_assertok(ut_check_console_line(uts, "testing log_debug")); |
| 133 | ut_assertok(ut_check_console_end(uts)); |
| 134 | return 0; |
| 135 | } |
Heinrich Schuchardt | 8d9c4c2 | 2020-05-06 18:26:08 +0200 | [diff] [blame] | 136 | LOG_TEST(log_test_nolog_debug); |