summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile1
-rw-r--r--test/log/Makefile7
-rw-r--r--test/log/log_test.c205
-rw-r--r--test/py/tests/test_efi_loader.py4
-rw-r--r--test/py/tests/test_efi_selftest.py14
-rw-r--r--test/py/tests/test_log.py101
6 files changed, 330 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile
index 6305afb2119..40f2244b79b 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -10,3 +10,4 @@ obj-$(CONFIG_SANDBOX) += command_ut.o
obj-$(CONFIG_SANDBOX) += compression.o
obj-$(CONFIG_SANDBOX) += print_ut.o
obj-$(CONFIG_UT_TIME) += time_ut.o
+obj-$(CONFIG_$(SPL_)LOG) += log/
diff --git a/test/log/Makefile b/test/log/Makefile
new file mode 100644
index 00000000000..b0da8dee282
--- /dev/null
+++ b/test/log/Makefile
@@ -0,0 +1,7 @@
+#
+# Copyright (c) 2017 Google, Inc
+#
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+obj-$(CONFIG_LOG_TEST) += log_test.o
diff --git a/test/log/log_test.c b/test/log/log_test.c
new file mode 100644
index 00000000000..2c6227703fa
--- /dev/null
+++ b/test/log/log_test.c
@@ -0,0 +1,205 @@
+/*
+ * Logging support test program
+ *
+ * Copyright (c) 2017 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+
+/* emit some sample log records in different ways, for testing */
+static int log_run(enum uclass_id cat, const char *file)
+{
+ int i;
+
+ debug("debug\n");
+ for (i = LOGL_FIRST; i < LOGL_COUNT; i++) {
+ log(cat, i, "log %d\n", i);
+ _log(log_uc_cat(cat), i, file, 100 + i, "func", "_log %d\n",
+ i);
+ }
+
+ return 0;
+}
+
+static int log_test(int testnum)
+{
+ int ret;
+
+ printf("test %d\n", testnum);
+ switch (testnum) {
+ case 0: {
+ /* Check a category filter using the first category */
+ enum log_category_t cat_list[] = {
+ log_uc_cat(UCLASS_MMC), log_uc_cat(UCLASS_SPI),
+ LOGC_NONE, LOGC_END
+ };
+
+ ret = log_add_filter("console", cat_list, LOGL_MAX, NULL);
+ if (ret < 0)
+ return ret;
+ log_run(UCLASS_MMC, "file");
+ ret = log_remove_filter("console", ret);
+ if (ret < 0)
+ return ret;
+ break;
+ }
+ case 1: {
+ /* Check a category filter using the second category */
+ enum log_category_t cat_list[] = {
+ log_uc_cat(UCLASS_MMC), log_uc_cat(UCLASS_SPI), LOGC_END
+ };
+
+ ret = log_add_filter("console", cat_list, LOGL_MAX, NULL);
+ if (ret < 0)
+ return ret;
+ log_run(UCLASS_SPI, "file");
+ ret = log_remove_filter("console", ret);
+ if (ret < 0)
+ return ret;
+ break;
+ }
+ case 2: {
+ /* Check a category filter that should block log entries */
+ enum log_category_t cat_list[] = {
+ log_uc_cat(UCLASS_MMC), LOGC_NONE, LOGC_END
+ };
+
+ ret = log_add_filter("console", cat_list, LOGL_MAX, NULL);
+ if (ret < 0)
+ return ret;
+ log_run(UCLASS_SPI, "file");
+ ret = log_remove_filter("console", ret);
+ if (ret < 0)
+ return ret;
+ break;
+ }
+ case 3: {
+ /* Check a passing file filter */
+ ret = log_add_filter("console", NULL, LOGL_MAX, "file");
+ if (ret < 0)
+ return ret;
+ log_run(UCLASS_SPI, "file");
+ ret = log_remove_filter("console", ret);
+ if (ret < 0)
+ return ret;
+ break;
+ }
+ case 4: {
+ /* Check a failing file filter */
+ ret = log_add_filter("console", NULL, LOGL_MAX, "file");
+ if (ret < 0)
+ return ret;
+ log_run(UCLASS_SPI, "file2");
+ ret = log_remove_filter("console", ret);
+ if (ret < 0)
+ return ret;
+ break;
+ }
+ case 5: {
+ /* Check a passing file filter (second in list) */
+ ret = log_add_filter("console", NULL, LOGL_MAX, "file,file2");
+ if (ret < 0)
+ return ret;
+ log_run(UCLASS_SPI, "file2");
+ ret = log_remove_filter("console", ret);
+ if (ret < 0)
+ return ret;
+ break;
+ }
+ case 6: {
+ /* Check a passing file filter */
+ ret = log_add_filter("console", NULL, LOGL_MAX,
+ "file,file2,log/log_test.c");
+ if (ret < 0)
+ return ret;
+ log_run(UCLASS_SPI, "file2");
+ ret = log_remove_filter("console", ret);
+ if (ret < 0)
+ return ret;
+ break;
+ }
+ case 7: {
+ /* Check a log level filter */
+ ret = log_add_filter("console", NULL, LOGL_WARNING, NULL);
+ if (ret < 0)
+ return ret;
+ log_run(UCLASS_SPI, "file");
+ ret = log_remove_filter("console", ret);
+ if (ret < 0)
+ return ret;
+ break;
+ }
+ case 8: {
+ /* Check two filters, one of which passes everything */
+ int filt1, filt2;
+
+ ret = log_add_filter("console", NULL, LOGL_WARNING, NULL);
+ if (ret < 0)
+ return ret;
+ filt1 = ret;
+ ret = log_add_filter("console", NULL, LOGL_MAX, NULL);
+ 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 9: {
+ /* Check three filters, which together pass everything */
+ int filt1, filt2, filt3;
+
+ ret = log_add_filter("console", NULL, LOGL_MAX, "file)");
+ if (ret < 0)
+ return ret;
+ filt1 = ret;
+ ret = log_add_filter("console", NULL, LOGL_MAX, "file2");
+ if (ret < 0)
+ return ret;
+ filt2 = ret;
+ ret = log_add_filter("console", NULL, LOGL_MAX,
+ "log/log_test.c");
+ if (ret < 0)
+ return ret;
+ filt3 = ret;
+ log_run(UCLASS_SPI, "file2");
+ ret = log_remove_filter("console", filt1);
+ if (ret < 0)
+ return ret;
+ ret = log_remove_filter("console", filt2);
+ if (ret < 0)
+ return ret;
+ ret = log_remove_filter("console", filt3);
+ if (ret < 0)
+ return ret;
+ break;
+ }
+ }
+
+ return 0;
+}
+
+#ifdef CONFIG_LOG_TEST
+int do_log_test(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+ int testnum = 0;
+ int ret;
+
+ if (argc > 1)
+ testnum = simple_strtoul(argv[1], NULL, 10);
+
+ ret = log_test(testnum);
+ if (ret)
+ printf("Test failure (err=%d)\n", ret);
+
+ return ret ? CMD_RET_FAILURE : 0;
+}
+#endif
diff --git a/test/py/tests/test_efi_loader.py b/test/py/tests/test_efi_loader.py
index 5d7f5dbfb23..906ef2feaaa 100644
--- a/test/py/tests/test_efi_loader.py
+++ b/test/py/tests/test_efi_loader.py
@@ -12,7 +12,7 @@ import u_boot_utils
"""
Note: This test relies on boardenv_* containing configuration values to define
-which the network environment available for testing. Without this, the parts
+which network environment is available for testing. Without this, the parts
that rely on network will be automatically skipped.
For example:
@@ -154,6 +154,8 @@ def test_efi_helloworld_net(u_boot_console):
output = u_boot_console.run_command('bootefi %x' % addr)
expected_text = 'Hello, world'
assert expected_text in output
+ expected_text = '## Application terminated, r = 0'
+ assert expected_text in output
@pytest.mark.buildconfigspec('cmd_bootefi_hello')
def test_efi_helloworld_builtin(u_boot_console):
diff --git a/test/py/tests/test_efi_selftest.py b/test/py/tests/test_efi_selftest.py
index 76e282a6c72..66b799bed66 100644
--- a/test/py/tests/test_efi_selftest.py
+++ b/test/py/tests/test_efi_selftest.py
@@ -1,4 +1,3 @@
-# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
# Copyright (c) 2017, Heinrich Schuchardt <xypron.glpk@gmx.de>
#
# SPDX-License-Identifier: GPL-2.0
@@ -14,6 +13,7 @@ def test_efi_selftest(u_boot_console):
Run bootefi selftest
"""
+ u_boot_console.run_command(cmd='setenv efi_selftest')
u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key'])
if m != 0:
@@ -23,3 +23,15 @@ def test_efi_selftest(u_boot_console):
if m != 0:
raise Exception('Reset failed during the EFI selftest')
u_boot_console.restart_uboot();
+
+@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
+def test_efi_selftest_watchdog_reboot(u_boot_console):
+ u_boot_console.run_command(cmd='setenv efi_selftest list')
+ output = u_boot_console.run_command('bootefi selftest')
+ assert '\'watchdog reboot\'' in output
+ u_boot_console.run_command(cmd='setenv efi_selftest watchdog reboot')
+ u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
+ m = u_boot_console.p.expect(['resetting', 'U-Boot'])
+ if m != 0:
+ raise Exception('Reset failed in \'watchdog reboot\' test')
+ u_boot_console.restart_uboot();
diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py
new file mode 100644
index 00000000000..fa9a25e8dc0
--- /dev/null
+++ b/test/py/tests/test_log.py
@@ -0,0 +1,101 @@
+# Copyright (c) 2016, Google Inc.
+#
+# SPDX-License-Identifier: GPL-2.0+
+#
+# U-Boot Verified Boot Test
+
+"""
+This tests U-Boot logging. It uses the 'log test' command with various options
+and checks that the output is correct.
+"""
+
+import pytest
+
+LOGL_FIRST, LOGL_WARNING, LOGL_INFO = (0, 4, 6)
+
+@pytest.mark.buildconfigspec('log')
+def test_log(u_boot_console):
+ """Test that U-Boot logging works correctly."""
+ def check_log_entries(lines, mask, max_level=LOGL_INFO):
+ """Check that the expected log records appear in the output
+
+ Args:
+ lines: iterator containing lines to check
+ mask: bit mask to select which lines to check for:
+ bit 0: standard log line
+ bit 1: _log line
+ max_level: maximum log level to expect in the output
+ """
+ for i in range(max_level):
+ if mask & 1:
+ assert 'log %d' % i == lines.next()
+ if mask & 3:
+ assert '_log %d' % i == lines.next()
+
+ def run_test(testnum):
+ """Run a particular test number (the 'log test' command)
+
+ Args:
+ testnum: Test number to run
+ Returns:
+ iterator containing the lines output from the command
+ """
+
+ with cons.log.section('basic'):
+ output = u_boot_console.run_command('log test %d' % testnum)
+ split = output.replace('\r', '').splitlines()
+ lines = iter(split)
+ assert 'test %d' % testnum == lines.next()
+ return lines
+
+ def test0():
+ lines = run_test(0)
+ check_log_entries(lines, 3)
+
+ def test1():
+ lines = run_test(1)
+ check_log_entries(lines, 3)
+
+ def test2():
+ lines = run_test(2)
+
+ def test3():
+ lines = run_test(3)
+ check_log_entries(lines, 2)
+
+ def test4():
+ lines = run_test(4)
+ assert next(lines, None) == None
+
+ def test5():
+ lines = run_test(5)
+ check_log_entries(lines, 2)
+
+ def test6():
+ lines = run_test(6)
+ check_log_entries(lines, 3)
+
+ def test7():
+ lines = run_test(7)
+ check_log_entries(lines, 3, LOGL_WARNING)
+
+ def test8():
+ lines = run_test(8)
+ check_log_entries(lines, 3)
+
+ def test9():
+ lines = run_test(9)
+ check_log_entries(lines, 3)
+
+ # TODO(sjg@chromium.org): Consider structuring this as separate tests
+ cons = u_boot_console
+ test0()
+ test1()
+ test2()
+ test3()
+ test4()
+ test5()
+ test6()
+ test7()
+ test8()
+ test9()