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