Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Logging support test program |
| 4 | * |
| 5 | * Copyright (c) 2017 Google, Inc |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 10 | #include <command.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 12 | #include <test/log.h> |
| 13 | #include <test/ut.h> |
| 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 16 | |
| 17 | /* emit some sample log records in different ways, for testing */ |
Patrick Delaunay | cc03497 | 2020-11-27 11:20:53 +0100 | [diff] [blame] | 18 | static int do_log_run(struct unit_test_state *uts, int cat, const char *file) |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 19 | { |
| 20 | int i; |
Patrick Delaunay | cc03497 | 2020-11-27 11:20:53 +0100 | [diff] [blame] | 21 | int ret, expected_ret; |
| 22 | |
| 23 | if (gd->flags & GD_FLG_LOG_READY) |
| 24 | expected_ret = 0; |
| 25 | else |
| 26 | expected_ret = -ENOSYS; |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 27 | |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 28 | gd->log_fmt = LOGF_TEST; |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 29 | debug("debug\n"); |
| 30 | for (i = LOGL_FIRST; i < LOGL_COUNT; i++) { |
| 31 | log(cat, i, "log %d\n", i); |
Patrick Delaunay | cc03497 | 2020-11-27 11:20:53 +0100 | [diff] [blame] | 32 | ret = _log(log_uc_cat(cat), i, file, 100 + i, |
| 33 | "func", "_log %d\n", i); |
| 34 | ut_asserteq(ret, expected_ret); |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 35 | } |
Patrick Delaunay | 529e46f | 2020-11-27 11:20:51 +0100 | [diff] [blame] | 36 | /* test with LOGL_COUNT flag */ |
| 37 | for (i = LOGL_FIRST; i < LOGL_COUNT; i++) { |
Patrick Delaunay | cc03497 | 2020-11-27 11:20:53 +0100 | [diff] [blame] | 38 | ret = _log(log_uc_cat(cat), i | LOGL_FORCE_DEBUG, file, 100 + i, |
| 39 | "func", "_log force %d\n", i); |
| 40 | ut_asserteq(ret, expected_ret); |
Patrick Delaunay | 529e46f | 2020-11-27 11:20:51 +0100 | [diff] [blame] | 41 | } |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 42 | |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 43 | gd->log_fmt = log_get_default_format(); |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 44 | return 0; |
| 45 | } |
| 46 | |
Patrick Delaunay | cc03497 | 2020-11-27 11:20:53 +0100 | [diff] [blame] | 47 | #define log_run_cat(cat) do_log_run(uts, cat, "file") |
| 48 | #define log_run_file(file) do_log_run(uts, UCLASS_SPI, file) |
| 49 | #define log_run() do_log_run(uts, UCLASS_SPI, "file") |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 50 | |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 51 | #define EXPECT_LOG BIT(0) |
| 52 | #define EXPECT_DIRECT BIT(1) |
| 53 | #define EXPECT_EXTRA BIT(2) |
Patrick Delaunay | 529e46f | 2020-11-27 11:20:51 +0100 | [diff] [blame] | 54 | #define EXPECT_FORCE BIT(3) |
Patrick Delaunay | 293798c | 2020-11-27 11:20:58 +0100 | [diff] [blame] | 55 | #define EXPECT_DEBUG BIT(4) |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 56 | |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 57 | static int do_check_log_entries(struct unit_test_state *uts, int flags, int min, |
| 58 | int max) |
| 59 | { |
| 60 | int i; |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 61 | |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 62 | for (i = min; i <= max; i++) { |
| 63 | if (flags & EXPECT_LOG) |
| 64 | ut_assert_nextline("do_log_run() log %d", i); |
| 65 | if (flags & EXPECT_DIRECT) |
| 66 | ut_assert_nextline("func() _log %d", i); |
Patrick Delaunay | 293798c | 2020-11-27 11:20:58 +0100 | [diff] [blame] | 67 | if (flags & EXPECT_DEBUG) { |
| 68 | ut_assert_nextline("log %d", i); |
| 69 | ut_assert_nextline("_log %d", i); |
| 70 | } |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 71 | } |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 72 | if (flags & EXPECT_EXTRA) |
| 73 | for (; i <= LOGL_MAX ; i++) |
| 74 | ut_assert_nextline("func() _log %d", i); |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 75 | |
Patrick Delaunay | 529e46f | 2020-11-27 11:20:51 +0100 | [diff] [blame] | 76 | for (i = LOGL_FIRST; i < LOGL_COUNT; i++) { |
| 77 | if (flags & EXPECT_FORCE) |
| 78 | ut_assert_nextline("func() _log force %d", i); |
Patrick Delaunay | 293798c | 2020-11-27 11:20:58 +0100 | [diff] [blame] | 79 | if (flags & EXPECT_DEBUG) |
| 80 | ut_assert_nextline("_log force %d", i); |
Patrick Delaunay | 529e46f | 2020-11-27 11:20:51 +0100 | [diff] [blame] | 81 | } |
| 82 | |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 83 | ut_assert_console_end(); |
| 84 | return 0; |
| 85 | } |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 86 | |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 87 | #define check_log_entries_flags_levels(flags, min, max) do {\ |
| 88 | int ret = do_check_log_entries(uts, flags, min, max); \ |
| 89 | if (ret) \ |
| 90 | return ret; \ |
| 91 | } while (0) |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 92 | |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 93 | #define check_log_entries_flags(flags) \ |
| 94 | check_log_entries_flags_levels(flags, LOGL_FIRST, _LOG_MAX_LEVEL) |
Patrick Delaunay | 529e46f | 2020-11-27 11:20:51 +0100 | [diff] [blame] | 95 | #define check_log_entries() check_log_entries_flags(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE) |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 96 | #define check_log_entries_extra() \ |
Patrick Delaunay | 529e46f | 2020-11-27 11:20:51 +0100 | [diff] [blame] | 97 | check_log_entries_flags(EXPECT_LOG | EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE) |
| 98 | #define check_log_entries_none() check_log_entries_flags(EXPECT_FORCE) |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 99 | |
| 100 | /* Check a category filter using the first category */ |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 101 | int log_test_cat_allow(struct unit_test_state *uts) |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 102 | { |
| 103 | enum log_category_t cat_list[] = { |
| 104 | log_uc_cat(UCLASS_MMC), log_uc_cat(UCLASS_SPI), |
| 105 | LOGC_NONE, LOGC_END |
| 106 | }; |
| 107 | int filt; |
| 108 | |
| 109 | filt = log_add_filter("console", cat_list, LOGL_MAX, NULL); |
| 110 | ut_assert(filt >= 0); |
| 111 | |
| 112 | ut_assertok(console_record_reset_enable()); |
| 113 | log_run_cat(UCLASS_MMC); |
| 114 | check_log_entries_extra(); |
| 115 | |
| 116 | ut_assertok(console_record_reset_enable()); |
| 117 | log_run_cat(UCLASS_SPI); |
| 118 | check_log_entries_extra(); |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 119 | |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 120 | ut_assertok(log_remove_filter("console", filt)); |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 121 | return 0; |
| 122 | } |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 123 | LOG_TEST_FLAGS(log_test_cat_allow, UT_TESTF_CONSOLE_REC); |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 124 | |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 125 | /* Check a category filter that should block log entries */ |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 126 | int log_test_cat_deny_implicit(struct unit_test_state *uts) |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 127 | { |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 128 | enum log_category_t cat_list[] = { |
| 129 | log_uc_cat(UCLASS_MMC), LOGC_NONE, LOGC_END |
| 130 | }; |
| 131 | int filt; |
| 132 | |
| 133 | filt = log_add_filter("console", cat_list, LOGL_MAX, NULL); |
| 134 | ut_assert(filt >= 0); |
| 135 | |
| 136 | ut_assertok(console_record_reset_enable()); |
| 137 | log_run_cat(UCLASS_SPI); |
| 138 | check_log_entries_none(); |
| 139 | |
| 140 | ut_assertok(log_remove_filter("console", filt)); |
| 141 | return 0; |
| 142 | } |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 143 | LOG_TEST_FLAGS(log_test_cat_deny_implicit, UT_TESTF_CONSOLE_REC); |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 144 | |
| 145 | /* Check passing and failing file filters */ |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 146 | int log_test_file(struct unit_test_state *uts) |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 147 | { |
| 148 | int filt; |
| 149 | |
| 150 | filt = log_add_filter("console", NULL, LOGL_MAX, "file"); |
| 151 | ut_assert(filt >= 0); |
| 152 | |
| 153 | ut_assertok(console_record_reset_enable()); |
| 154 | log_run_file("file"); |
Patrick Delaunay | 529e46f | 2020-11-27 11:20:51 +0100 | [diff] [blame] | 155 | check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE); |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 156 | |
| 157 | ut_assertok(console_record_reset_enable()); |
| 158 | log_run_file("file2"); |
| 159 | check_log_entries_none(); |
| 160 | |
| 161 | ut_assertok(log_remove_filter("console", filt)); |
| 162 | return 0; |
| 163 | } |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 164 | LOG_TEST_FLAGS(log_test_file, UT_TESTF_CONSOLE_REC); |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 165 | |
| 166 | /* Check a passing file filter (second in list) */ |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 167 | int log_test_file_second(struct unit_test_state *uts) |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 168 | { |
| 169 | int filt; |
| 170 | |
| 171 | filt = log_add_filter("console", NULL, LOGL_MAX, "file,file2"); |
| 172 | ut_assert(filt >= 0); |
| 173 | |
| 174 | ut_assertok(console_record_reset_enable()); |
| 175 | log_run_file("file2"); |
Patrick Delaunay | 529e46f | 2020-11-27 11:20:51 +0100 | [diff] [blame] | 176 | check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE); |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 177 | |
| 178 | ut_assertok(log_remove_filter("console", filt)); |
| 179 | return 0; |
| 180 | } |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 181 | LOG_TEST_FLAGS(log_test_file_second, UT_TESTF_CONSOLE_REC); |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 182 | |
| 183 | /* Check a passing file filter (middle of list) */ |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 184 | int log_test_file_mid(struct unit_test_state *uts) |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 185 | { |
| 186 | int filt; |
| 187 | |
| 188 | filt = log_add_filter("console", NULL, LOGL_MAX, |
| 189 | "file,file2,log/log_test.c"); |
| 190 | ut_assert(filt >= 0); |
| 191 | |
| 192 | ut_assertok(console_record_reset_enable()); |
| 193 | log_run_file("file2"); |
| 194 | check_log_entries_extra(); |
| 195 | |
| 196 | ut_assertok(log_remove_filter("console", filt)); |
| 197 | return 0; |
| 198 | } |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 199 | LOG_TEST_FLAGS(log_test_file_mid, UT_TESTF_CONSOLE_REC); |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 200 | |
| 201 | /* Check a log level filter */ |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 202 | int log_test_level(struct unit_test_state *uts) |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 203 | { |
| 204 | int filt; |
| 205 | |
| 206 | filt = log_add_filter("console", NULL, LOGL_WARNING, NULL); |
| 207 | ut_assert(filt >= 0); |
| 208 | |
| 209 | ut_assertok(console_record_reset_enable()); |
| 210 | log_run(); |
Patrick Delaunay | 529e46f | 2020-11-27 11:20:51 +0100 | [diff] [blame] | 211 | check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE, |
| 212 | LOGL_FIRST, LOGL_WARNING); |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 213 | |
| 214 | ut_assertok(log_remove_filter("console", filt)); |
| 215 | return 0; |
| 216 | } |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 217 | LOG_TEST_FLAGS(log_test_level, UT_TESTF_CONSOLE_REC); |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 218 | |
| 219 | /* Check two filters, one of which passes everything */ |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 220 | int log_test_double(struct unit_test_state *uts) |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 221 | { |
| 222 | int filt1, filt2; |
| 223 | |
| 224 | filt1 = log_add_filter("console", NULL, LOGL_WARNING, NULL); |
| 225 | ut_assert(filt1 >= 0); |
| 226 | filt2 = log_add_filter("console", NULL, LOGL_MAX, NULL); |
| 227 | ut_assert(filt2 >= 0); |
| 228 | |
| 229 | ut_assertok(console_record_reset_enable()); |
| 230 | log_run(); |
| 231 | check_log_entries_extra(); |
| 232 | |
| 233 | ut_assertok(log_remove_filter("console", filt1)); |
| 234 | ut_assertok(log_remove_filter("console", filt2)); |
| 235 | return 0; |
| 236 | } |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 237 | LOG_TEST_FLAGS(log_test_double, UT_TESTF_CONSOLE_REC); |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 238 | |
| 239 | /* Check three filters, which together pass everything */ |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 240 | int log_test_triple(struct unit_test_state *uts) |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 241 | { |
| 242 | int filt1, filt2, filt3; |
| 243 | |
| 244 | filt1 = log_add_filter("console", NULL, LOGL_MAX, "file)"); |
| 245 | ut_assert(filt1 >= 0); |
| 246 | filt2 = log_add_filter("console", NULL, LOGL_MAX, "file2"); |
| 247 | ut_assert(filt2 >= 0); |
| 248 | filt3 = log_add_filter("console", NULL, LOGL_MAX, "log/log_test.c"); |
| 249 | ut_assert(filt3 >= 0); |
| 250 | |
| 251 | ut_assertok(console_record_reset_enable()); |
| 252 | log_run_file("file2"); |
| 253 | check_log_entries_extra(); |
| 254 | |
| 255 | ut_assertok(log_remove_filter("console", filt1)); |
| 256 | ut_assertok(log_remove_filter("console", filt2)); |
| 257 | ut_assertok(log_remove_filter("console", filt3)); |
| 258 | return 0; |
| 259 | } |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 260 | LOG_TEST_FLAGS(log_test_triple, UT_TESTF_CONSOLE_REC); |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 261 | |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 262 | int do_log_test_helpers(struct unit_test_state *uts) |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 263 | { |
| 264 | int i; |
| 265 | |
| 266 | ut_assertok(console_record_reset_enable()); |
| 267 | log_err("level %d\n", LOGL_EMERG); |
| 268 | log_err("level %d\n", LOGL_ALERT); |
| 269 | log_err("level %d\n", LOGL_CRIT); |
| 270 | log_err("level %d\n", LOGL_ERR); |
| 271 | log_warning("level %d\n", LOGL_WARNING); |
| 272 | log_notice("level %d\n", LOGL_NOTICE); |
| 273 | log_info("level %d\n", LOGL_INFO); |
| 274 | log_debug("level %d\n", LOGL_DEBUG); |
| 275 | log_content("level %d\n", LOGL_DEBUG_CONTENT); |
| 276 | log_io("level %d\n", LOGL_DEBUG_IO); |
| 277 | |
| 278 | for (i = LOGL_EMERG; i <= _LOG_MAX_LEVEL; i++) |
| 279 | ut_assert_nextline("%s() level %d", __func__, i); |
| 280 | ut_assert_console_end(); |
| 281 | return 0; |
| 282 | } |
| 283 | |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 284 | int log_test_helpers(struct unit_test_state *uts) |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 285 | { |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 286 | int ret; |
| 287 | |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 288 | gd->log_fmt = LOGF_TEST; |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 289 | ret = do_log_test_helpers(uts); |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 290 | gd->log_fmt = log_get_default_format(); |
| 291 | return ret; |
| 292 | } |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 293 | LOG_TEST_FLAGS(log_test_helpers, UT_TESTF_CONSOLE_REC); |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 294 | |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 295 | int do_log_test_disable(struct unit_test_state *uts) |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 296 | { |
| 297 | ut_assertok(console_record_reset_enable()); |
| 298 | log_err("default\n"); |
| 299 | ut_assert_nextline("%s() default", __func__); |
| 300 | |
| 301 | ut_assertok(log_device_set_enable(LOG_GET_DRIVER(console), false)); |
| 302 | log_err("disabled\n"); |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 303 | |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 304 | ut_assertok(log_device_set_enable(LOG_GET_DRIVER(console), true)); |
| 305 | log_err("enabled\n"); |
| 306 | ut_assert_nextline("%s() enabled", __func__); |
| 307 | ut_assert_console_end(); |
| 308 | return 0; |
| 309 | } |
| 310 | |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 311 | int log_test_disable(struct unit_test_state *uts) |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 312 | { |
| 313 | int ret; |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 314 | |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 315 | gd->log_fmt = LOGF_TEST; |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 316 | ret = do_log_test_disable(uts); |
Sean Anderson | c182182 | 2020-10-27 19:55:27 -0400 | [diff] [blame] | 317 | gd->log_fmt = log_get_default_format(); |
| 318 | return ret; |
Simon Glass | 14c8a06 | 2017-12-04 13:48:27 -0700 | [diff] [blame] | 319 | } |
Sean Anderson | ba95667 | 2020-10-27 19:55:28 -0400 | [diff] [blame] | 320 | LOG_TEST_FLAGS(log_test_disable, UT_TESTF_CONSOLE_REC); |
Sean Anderson | 14e9986 | 2020-10-27 19:55:29 -0400 | [diff] [blame] | 321 | |
| 322 | /* Check denying based on category */ |
| 323 | int log_test_cat_deny(struct unit_test_state *uts) |
| 324 | { |
| 325 | int filt1, filt2; |
| 326 | enum log_category_t cat_list[] = { |
| 327 | log_uc_cat(UCLASS_SPI), LOGC_END |
| 328 | }; |
| 329 | |
| 330 | filt1 = log_add_filter("console", cat_list, LOGL_MAX, NULL); |
| 331 | ut_assert(filt1 >= 0); |
| 332 | filt2 = log_add_filter_flags("console", cat_list, LOGL_MAX, NULL, |
| 333 | LOGFF_DENY); |
| 334 | ut_assert(filt2 >= 0); |
| 335 | |
| 336 | ut_assertok(console_record_reset_enable()); |
| 337 | log_run_cat(UCLASS_SPI); |
| 338 | check_log_entries_none(); |
| 339 | |
| 340 | ut_assertok(log_remove_filter("console", filt1)); |
| 341 | ut_assertok(log_remove_filter("console", filt2)); |
| 342 | return 0; |
| 343 | } |
| 344 | LOG_TEST_FLAGS(log_test_cat_deny, UT_TESTF_CONSOLE_REC); |
| 345 | |
| 346 | /* Check denying based on file */ |
| 347 | int log_test_file_deny(struct unit_test_state *uts) |
| 348 | { |
| 349 | int filt1, filt2; |
| 350 | |
| 351 | filt1 = log_add_filter("console", NULL, LOGL_MAX, "file"); |
| 352 | ut_assert(filt1 >= 0); |
| 353 | filt2 = log_add_filter_flags("console", NULL, LOGL_MAX, "file", |
| 354 | LOGFF_DENY); |
| 355 | ut_assert(filt2 >= 0); |
| 356 | |
| 357 | ut_assertok(console_record_reset_enable()); |
| 358 | log_run_file("file"); |
| 359 | check_log_entries_none(); |
| 360 | |
| 361 | ut_assertok(log_remove_filter("console", filt1)); |
| 362 | ut_assertok(log_remove_filter("console", filt2)); |
| 363 | return 0; |
| 364 | } |
| 365 | LOG_TEST_FLAGS(log_test_file_deny, UT_TESTF_CONSOLE_REC); |
| 366 | |
| 367 | /* Check denying based on level */ |
| 368 | int log_test_level_deny(struct unit_test_state *uts) |
| 369 | { |
| 370 | int filt1, filt2; |
| 371 | |
| 372 | filt1 = log_add_filter("console", NULL, LOGL_INFO, NULL); |
| 373 | ut_assert(filt1 >= 0); |
| 374 | filt2 = log_add_filter_flags("console", NULL, LOGL_WARNING, NULL, |
| 375 | LOGFF_DENY); |
| 376 | ut_assert(filt2 >= 0); |
| 377 | |
| 378 | ut_assertok(console_record_reset_enable()); |
| 379 | log_run(); |
Patrick Delaunay | 529e46f | 2020-11-27 11:20:51 +0100 | [diff] [blame] | 380 | check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE, |
Sean Anderson | 14e9986 | 2020-10-27 19:55:29 -0400 | [diff] [blame] | 381 | LOGL_WARNING + 1, _LOG_MAX_LEVEL); |
| 382 | |
| 383 | ut_assertok(log_remove_filter("console", filt1)); |
| 384 | ut_assertok(log_remove_filter("console", filt2)); |
| 385 | return 0; |
| 386 | } |
| 387 | LOG_TEST_FLAGS(log_test_level_deny, UT_TESTF_CONSOLE_REC); |
Sean Anderson | 4147317 | 2020-10-27 19:55:31 -0400 | [diff] [blame] | 388 | |
| 389 | /* Check matching based on minimum level */ |
| 390 | int log_test_min(struct unit_test_state *uts) |
| 391 | { |
| 392 | int filt1, filt2; |
| 393 | |
| 394 | filt1 = log_add_filter_flags("console", NULL, LOGL_WARNING, NULL, |
| 395 | LOGFF_LEVEL_MIN); |
| 396 | ut_assert(filt1 >= 0); |
| 397 | filt2 = log_add_filter_flags("console", NULL, LOGL_INFO, NULL, |
| 398 | LOGFF_DENY | LOGFF_LEVEL_MIN); |
| 399 | ut_assert(filt2 >= 0); |
| 400 | |
| 401 | ut_assertok(console_record_reset_enable()); |
| 402 | log_run(); |
Patrick Delaunay | 529e46f | 2020-11-27 11:20:51 +0100 | [diff] [blame] | 403 | check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE, |
Sean Anderson | 4147317 | 2020-10-27 19:55:31 -0400 | [diff] [blame] | 404 | LOGL_WARNING, LOGL_INFO - 1); |
| 405 | |
| 406 | ut_assertok(log_remove_filter("console", filt1)); |
| 407 | ut_assertok(log_remove_filter("console", filt2)); |
| 408 | return 0; |
| 409 | } |
| 410 | LOG_TEST_FLAGS(log_test_min, UT_TESTF_CONSOLE_REC); |
Patrick Delaunay | cc03497 | 2020-11-27 11:20:53 +0100 | [diff] [blame] | 411 | |
| 412 | /* Check dropped traces */ |
| 413 | int log_test_dropped(struct unit_test_state *uts) |
| 414 | { |
| 415 | /* force LOG not ready */ |
| 416 | gd->flags &= ~(GD_FLG_LOG_READY); |
| 417 | gd->log_drop_count = 0; |
| 418 | |
| 419 | ut_assertok(console_record_reset_enable()); |
| 420 | log_run(); |
| 421 | |
| 422 | ut_asserteq(gd->log_drop_count, 3 * (LOGL_COUNT - LOGL_FIRST - 1)); |
Patrick Delaunay | 293798c | 2020-11-27 11:20:58 +0100 | [diff] [blame] | 423 | check_log_entries_flags_levels(EXPECT_DEBUG, LOGL_FIRST, CONFIG_LOG_DEFAULT_LEVEL); |
Patrick Delaunay | cc03497 | 2020-11-27 11:20:53 +0100 | [diff] [blame] | 424 | |
| 425 | gd->flags |= GD_FLG_LOG_READY; |
| 426 | gd->log_drop_count = 0; |
| 427 | |
| 428 | return 0; |
| 429 | } |
| 430 | LOG_TEST_FLAGS(log_test_dropped, UT_TESTF_CONSOLE_REC); |