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