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