[PATCH v2 09/22] test: Add tests for LOGFF_DENY
Sean Anderson
seanga2 at gmail.com
Sat Oct 10 21:43:34 CEST 2020
This adds some tests for log filters which deny if they match.
Signed-off-by: Sean Anderson <seanga2 at gmail.com>
---
(no changes since v1)
test/log/log_test.c | 69 +++++++++++++++++++++++++++++++++++++++
test/py/tests/test_log.py | 21 ++++++++++--
2 files changed, 88 insertions(+), 2 deletions(-)
diff --git a/test/log/log_test.c b/test/log/log_test.c
index 787f680971..6a71d3db7d 100644
--- a/test/log/log_test.c
+++ b/test/log/log_test.c
@@ -196,6 +196,75 @@ static int log_test(int testnum)
log_io("level %d\n", LOGL_DEBUG_IO);
break;
}
+ case 11: {
+ /* Check denying based on category */
+ int filt1, filt2;
+ enum log_category_t cat_list[] = {
+ log_uc_cat(UCLASS_SPI), LOGC_END
+ };
+
+ ret = log_add_filter("console", cat_list, LOGL_MAX, NULL);
+ if (ret < 0)
+ return ret;
+ filt1 = ret;
+ ret = log_add_filter_flags("console", cat_list, LOGL_MAX, NULL,
+ LOGFF_DENY);
+ if (ret < 0)
+ return ret;
+ filt2 = ret;
+ log_run(UCLASS_SPI, "file");
+ ret = log_remove_filter("console", filt1);
+ if (ret < 0)
+ return ret;
+ ret = log_remove_filter("console", filt2);
+ if (ret < 0)
+ return ret;
+ break;
+ }
+ case 12: {
+ /* Check denying based on file */
+ int filt1, filt2;
+
+ ret = log_add_filter("console", NULL, LOGL_MAX, "file");
+ if (ret < 0)
+ return ret;
+ filt1 = ret;
+ ret = log_add_filter_flags("console", NULL, LOGL_MAX, "file",
+ LOGFF_DENY);
+ if (ret < 0)
+ return ret;
+ filt2 = ret;
+ log_run(UCLASS_SPI, "file");
+ ret = log_remove_filter("console", filt1);
+ if (ret < 0)
+ return ret;
+ ret = log_remove_filter("console", filt2);
+ if (ret < 0)
+ return ret;
+ break;
+ }
+ case 13: {
+ /* Check denying based on level */
+ int filt1, filt2;
+
+ ret = log_add_filter("console", NULL, LOGL_INFO, NULL);
+ if (ret < 0)
+ return ret;
+ filt1 = ret;
+ ret = log_add_filter_flags("console", NULL, LOGL_WARNING, NULL,
+ LOGFF_DENY);
+ if (ret < 0)
+ return ret;
+ filt2 = ret;
+ log_run(UCLASS_SPI, "file");
+ ret = log_remove_filter("console", filt1);
+ if (ret < 0)
+ return ret;
+ ret = log_remove_filter("console", filt2);
+ if (ret < 0)
+ return ret;
+ break;
+ }
}
return 0;
diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py
index ddc28f19ee..fabf3001cb 100644
--- a/test/py/tests/test_log.py
+++ b/test/py/tests/test_log.py
@@ -15,7 +15,8 @@ LOGL_FIRST, LOGL_WARNING, LOGL_INFO = (0, 4, 6)
@pytest.mark.buildconfigspec('cmd_log')
def test_log(u_boot_console):
"""Test that U-Boot logging works correctly."""
- def check_log_entries(lines, mask, max_level=LOGL_INFO):
+ def check_log_entries(lines, mask, max_level=LOGL_INFO,
+ min_level=LOGL_FIRST):
"""Check that the expected log records appear in the output
Args:
@@ -24,8 +25,9 @@ def test_log(u_boot_console):
bit 0: standard log line
bit 1: _log line
max_level: maximum log level to expect in the output
+ min_level: minimum log level to expect in the output
"""
- for i in range(max_level):
+ for i in range(min_level, max_level + 1):
if mask & 1:
assert 'log_run() log %d' % i == next(lines)
if mask & 3:
@@ -92,6 +94,18 @@ def test_log(u_boot_console):
for i in range(7):
assert 'log_test() level %d' % i == next(lines)
+ def test11():
+ lines = run_test(11)
+ assert next(lines, None) == None
+
+ def test12():
+ lines = run_test(12)
+ assert next(lines, None) == None
+
+ def test13():
+ lines = run_test(13)
+ check_log_entries(lines, 1, LOGL_INFO, LOGL_WARNING + 1)
+
# TODO(sjg at chromium.org): Consider structuring this as separate tests
cons = u_boot_console
test0()
@@ -105,6 +119,9 @@ def test_log(u_boot_console):
test8()
test9()
test10()
+ test11()
+ test12()
+ test13()
@pytest.mark.buildconfigspec('cmd_log')
def test_log_format(u_boot_console):
--
2.28.0
More information about the U-Boot
mailing list