diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile | 2 | ||||
-rw-r--r-- | test/bloblist.c | 13 | ||||
-rw-r--r-- | test/cmd/Makefile | 1 | ||||
-rw-r--r-- | test/cmd/mem.c | 2 | ||||
-rw-r--r-- | test/cmd/pwm.c | 47 | ||||
-rw-r--r-- | test/lib/Makefile | 2 | ||||
-rw-r--r-- | test/log/Makefile | 1 | ||||
-rw-r--r-- | test/log/log_test.c | 76 | ||||
-rw-r--r-- | test/log/pr_cont_test.c | 45 | ||||
-rw-r--r-- | test/py/tests/test_log.py | 11 | ||||
-rw-r--r-- | test/str_ut.c | 4 | ||||
-rw-r--r-- | test/ut.c | 18 |
12 files changed, 193 insertions, 29 deletions
diff --git a/test/Makefile b/test/Makefile index d4323f9963..3c7bc8b549 100644 --- a/test/Makefile +++ b/test/Makefile @@ -2,7 +2,7 @@ # # (C) Copyright 2012 The Chromium Authors -ifneq ($(CONFIG_SANDBOX),) +ifneq ($(CONFIG_$(SPL_)BLOBLIST),) obj-$(CONFIG_$(SPL_)CMDLINE) += bloblist.o endif obj-$(CONFIG_$(SPL_)CMDLINE) += bootm.o diff --git a/test/bloblist.c b/test/bloblist.c index 0bb9e2d81e..900299dd68 100644 --- a/test/bloblist.c +++ b/test/bloblist.c @@ -7,7 +7,6 @@ #include <bloblist.h> #include <log.h> #include <mapmem.h> -#include <asm/state.h> #include <test/suites.h> #include <test/test.h> #include <test/ut.h> @@ -240,7 +239,6 @@ BLOBLIST_TEST(bloblist_test_checksum, 0); /* Test the 'bloblist info' command */ static int bloblist_test_cmd_info(struct unit_test_state *uts) { - struct sandbox_state *state = state_get_current(); struct bloblist_hdr *hdr; char *data, *data2; @@ -250,8 +248,7 @@ static int bloblist_test_cmd_info(struct unit_test_state *uts) data2 = bloblist_ensure(TEST_TAG2, TEST_SIZE2); console_record_reset_enable(); - if (!state->show_test_output) - gd->flags |= GD_FLG_SILENT; + ut_silence_console(uts); console_record_reset(); run_command("bloblist info", 0); ut_assert_nextline("base: %lx", (ulong)map_to_sysmem(hdr)); @@ -259,7 +256,7 @@ static int bloblist_test_cmd_info(struct unit_test_state *uts) ut_assert_nextline("alloced: 70 112 Bytes"); ut_assert_nextline("free: 390 912 Bytes"); ut_assert_console_end(); - gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD); + ut_unsilence_console(uts); return 0; } @@ -268,7 +265,6 @@ BLOBLIST_TEST(bloblist_test_cmd_info, 0); /* Test the 'bloblist list' command */ static int bloblist_test_cmd_list(struct unit_test_state *uts) { - struct sandbox_state *state = state_get_current(); struct bloblist_hdr *hdr; char *data, *data2; @@ -278,8 +274,7 @@ static int bloblist_test_cmd_list(struct unit_test_state *uts) data2 = bloblist_ensure(TEST_TAG2, TEST_SIZE2); console_record_reset_enable(); - if (!state->show_test_output) - gd->flags |= GD_FLG_SILENT; + ut_silence_console(uts); console_record_reset(); run_command("bloblist list", 0); ut_assert_nextline("Address Size Tag Name"); @@ -288,7 +283,7 @@ static int bloblist_test_cmd_list(struct unit_test_state *uts) ut_assert_nextline("%08lx %8x 2 SPL hand-off", (ulong)map_to_sysmem(data2), TEST_SIZE2); ut_assert_console_end(); - gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD); + ut_unsilence_console(uts); return 0; } diff --git a/test/cmd/Makefile b/test/cmd/Makefile index b2f71af847..758bc14273 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -4,4 +4,5 @@ obj-y += mem.o obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o +obj-$(CONFIG_CMD_PWM) += pwm.o obj-y += setexpr.o diff --git a/test/cmd/mem.c b/test/cmd/mem.c index fa6770e8c0..fbaa8a4b3c 100644 --- a/test/cmd/mem.c +++ b/test/cmd/mem.c @@ -15,6 +15,6 @@ int do_ut_mem(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) struct unit_test *tests = ll_entry_start(struct unit_test, mem_test); const int n_ents = ll_entry_count(struct unit_test, mem_test); - return cmd_ut_category("cmd_mem", "cmd_mem_", tests, n_ents, argc, + return cmd_ut_category("cmd_mem", "mem_test_", tests, n_ents, argc, argv); } diff --git a/test/cmd/pwm.c b/test/cmd/pwm.c new file mode 100644 index 0000000000..5343af83fa --- /dev/null +++ b/test/cmd/pwm.c @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test for pwm command + * + * Copyright 2020 SiFive, Inc + * + * Authors: + * Pragnesh Patel <pragnesh.patel@sifive.com> + */ + +#include <dm.h> +#include <dm/test.h> +#include <test/test.h> +#include <test/ut.h> + +/* Basic test of 'pwm' command */ +static int dm_test_pwm_cmd(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev)); + ut_assertnonnull(dev); + + ut_assertok(console_record_reset_enable()); + + /* pwm <invert> <pwm_dev_num> <channel> <polarity> */ + ut_assertok(run_command("pwm invert 0 0 1", 0)); + ut_assert_console_end(); + + ut_assertok(run_command("pwm invert 0 0 0", 0)); + ut_assert_console_end(); + + /* pwm <config> <pwm_dev_num> <channel> <period_ns> <duty_ns> */ + ut_assertok(run_command("pwm config 0 0 10 50", 0)); + ut_assert_console_end(); + + /* pwm <enable/disable> <pwm_dev_num> <channel> */ + ut_assertok(run_command("pwm enable 0 0", 0)); + ut_assert_console_end(); + + ut_assertok(run_command("pwm disable 0 0", 0)); + ut_assert_console_end(); + + return 0; +} + +DM_TEST(dm_test_pwm_cmd, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC); diff --git a/test/lib/Makefile b/test/lib/Makefile index 98a9abf40e..97c11e35a8 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -7,7 +7,7 @@ obj-$(CONFIG_EFI_LOADER) += efi_device_path.o obj-$(CONFIG_EFI_SECURE_BOOT) += efi_image_region.o obj-y += hexdump.o obj-y += lmb.o -obj-y += test_print.o +obj-$(CONFIG_CONSOLE_RECORD) += test_print.o obj-$(CONFIG_SSCANF) += sscanf.o obj-y += string.o obj-$(CONFIG_ERRNO_STR) += test_errno_str.o diff --git a/test/log/Makefile b/test/log/Makefile index 88bc573e9f..afdafa502a 100644 --- a/test/log/Makefile +++ b/test/log/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_CMD_LOG) += log_filter.o ifdef CONFIG_UT_LOG obj-y += test-main.o +obj-y += pr_cont_test.o ifdef CONFIG_SANDBOX obj-$(CONFIG_LOG_SYSLOG) += syslog_test.o diff --git a/test/log/log_test.c b/test/log/log_test.c index ea4fc6bc30..82234a6994 100644 --- a/test/log/log_test.c +++ b/test/log/log_test.c @@ -15,29 +15,44 @@ DECLARE_GLOBAL_DATA_PTR; /* emit some sample log records in different ways, for testing */ -static int do_log_run(int cat, const char *file) +static int do_log_run(struct unit_test_state *uts, int cat, const char *file) { int i; + int ret, expected_ret; + + if (gd->flags & GD_FLG_LOG_READY) + expected_ret = 0; + else + expected_ret = -ENOSYS; gd->log_fmt = LOGF_TEST; 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); + ret = _log(log_uc_cat(cat), i, file, 100 + i, + "func", "_log %d\n", i); + ut_asserteq(ret, expected_ret); + } + /* test with LOGL_COUNT flag */ + for (i = LOGL_FIRST; i < LOGL_COUNT; i++) { + ret = _log(log_uc_cat(cat), i | LOGL_FORCE_DEBUG, file, 100 + i, + "func", "_log force %d\n", i); + ut_asserteq(ret, expected_ret); } gd->log_fmt = log_get_default_format(); return 0; } -#define log_run_cat(cat) do_log_run(cat, "file") -#define log_run_file(file) do_log_run(UCLASS_SPI, file) -#define log_run() do_log_run(UCLASS_SPI, "file") +#define log_run_cat(cat) do_log_run(uts, cat, "file") +#define log_run_file(file) do_log_run(uts, UCLASS_SPI, file) +#define log_run() do_log_run(uts, UCLASS_SPI, "file") #define EXPECT_LOG BIT(0) #define EXPECT_DIRECT BIT(1) #define EXPECT_EXTRA BIT(2) +#define EXPECT_FORCE BIT(3) +#define EXPECT_DEBUG BIT(4) static int do_check_log_entries(struct unit_test_state *uts, int flags, int min, int max) @@ -49,11 +64,22 @@ static int do_check_log_entries(struct unit_test_state *uts, int flags, int min, ut_assert_nextline("do_log_run() log %d", i); if (flags & EXPECT_DIRECT) ut_assert_nextline("func() _log %d", i); + if (flags & EXPECT_DEBUG) { + ut_assert_nextline("log %d", i); + ut_assert_nextline("_log %d", i); + } } if (flags & EXPECT_EXTRA) for (; i <= LOGL_MAX ; i++) ut_assert_nextline("func() _log %d", i); + for (i = LOGL_FIRST; i < LOGL_COUNT; i++) { + if (flags & EXPECT_FORCE) + ut_assert_nextline("func() _log force %d", i); + if (flags & EXPECT_DEBUG) + ut_assert_nextline("_log force %d", i); + } + ut_assert_console_end(); return 0; } @@ -66,10 +92,10 @@ static int do_check_log_entries(struct unit_test_state *uts, int flags, int min, #define check_log_entries_flags(flags) \ check_log_entries_flags_levels(flags, LOGL_FIRST, _LOG_MAX_LEVEL) -#define check_log_entries() check_log_entries_flags(EXPECT_LOG | EXPECT_DIRECT) +#define check_log_entries() check_log_entries_flags(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE) #define check_log_entries_extra() \ - check_log_entries_flags(EXPECT_LOG | EXPECT_DIRECT | EXPECT_EXTRA) -#define check_log_entries_none() check_log_entries_flags(0) + check_log_entries_flags(EXPECT_LOG | EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE) +#define check_log_entries_none() check_log_entries_flags(EXPECT_FORCE) /* Check a category filter using the first category */ int log_test_cat_allow(struct unit_test_state *uts) @@ -126,7 +152,7 @@ int log_test_file(struct unit_test_state *uts) ut_assertok(console_record_reset_enable()); log_run_file("file"); - check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA); + check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE); ut_assertok(console_record_reset_enable()); log_run_file("file2"); @@ -147,7 +173,7 @@ int log_test_file_second(struct unit_test_state *uts) ut_assertok(console_record_reset_enable()); log_run_file("file2"); - check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA); + check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE); ut_assertok(log_remove_filter("console", filt)); return 0; @@ -182,8 +208,8 @@ int log_test_level(struct unit_test_state *uts) ut_assertok(console_record_reset_enable()); log_run(); - check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT, LOGL_FIRST, - LOGL_WARNING); + check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE, + LOGL_FIRST, LOGL_WARNING); ut_assertok(log_remove_filter("console", filt)); return 0; @@ -351,7 +377,7 @@ int log_test_level_deny(struct unit_test_state *uts) ut_assertok(console_record_reset_enable()); log_run(); - check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT, + check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE, LOGL_WARNING + 1, _LOG_MAX_LEVEL); ut_assertok(log_remove_filter("console", filt1)); @@ -374,7 +400,7 @@ int log_test_min(struct unit_test_state *uts) ut_assertok(console_record_reset_enable()); log_run(); - check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT, + check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE, LOGL_WARNING, LOGL_INFO - 1); ut_assertok(log_remove_filter("console", filt1)); @@ -382,3 +408,23 @@ int log_test_min(struct unit_test_state *uts) return 0; } LOG_TEST_FLAGS(log_test_min, UT_TESTF_CONSOLE_REC); + +/* Check dropped traces */ +int log_test_dropped(struct unit_test_state *uts) +{ + /* force LOG not ready */ + gd->flags &= ~(GD_FLG_LOG_READY); + gd->log_drop_count = 0; + + ut_assertok(console_record_reset_enable()); + log_run(); + + ut_asserteq(gd->log_drop_count, 3 * (LOGL_COUNT - LOGL_FIRST - 1)); + check_log_entries_flags_levels(EXPECT_DEBUG, LOGL_FIRST, CONFIG_LOG_DEFAULT_LEVEL); + + gd->flags |= GD_FLG_LOG_READY; + gd->log_drop_count = 0; + + return 0; +} +LOG_TEST_FLAGS(log_test_dropped, UT_TESTF_CONSOLE_REC); diff --git a/test/log/pr_cont_test.c b/test/log/pr_cont_test.c new file mode 100644 index 0000000000..236eff4b33 --- /dev/null +++ b/test/log/pr_cont_test.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2021, Heinrich Schuchardt <xypron.glpk@gmx.de> + * + * Test continuation of log messages using pr_cont(). + */ + +#include <common.h> +#include <console.h> +#include <test/log.h> +#include <test/test.h> +#include <test/suites.h> +#include <test/ut.h> +#include <linux/printk.h> + +#define BUFFSIZE 64 + +#undef CONFIG_LOGLEVEL +#define CONFIG_LOGLEVEL 4 + +DECLARE_GLOBAL_DATA_PTR; + +static int log_test_pr_cont(struct unit_test_state *uts) +{ + int log_fmt; + int log_level; + + log_fmt = gd->log_fmt; + log_level = gd->default_log_level; + + /* Write two messages, the second continuing the first */ + gd->log_fmt = BIT(LOGF_MSG); + gd->default_log_level = LOGL_INFO; + console_record_reset_enable(); + pr_err("ea%d ", 1); + pr_cont("cc%d\n", 2); + gd->default_log_level = log_level; + gd->log_fmt = log_fmt; + gd->flags &= ~GD_FLG_RECORD; + ut_assertok(ut_check_console_line(uts, "ea1 cc2")); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} +LOG_TEST(log_test_pr_cont); diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py index 387b392ce9..f889120f2b 100644 --- a/test/py/tests/test_log.py +++ b/test/py/tests/test_log.py @@ -36,3 +36,14 @@ def test_log_format(u_boot_console): run_with_format('FLfm', 'file.c:123-func() msg') run_with_format('lm', 'NOTICE. msg') run_with_format('m', 'msg') + +@pytest.mark.buildconfigspec('debug_uart') +@pytest.mark.boardspec('sandbox') +def test_log_dropped(u_boot_console): + """Test dropped 'log' message when debug_uart is activated""" + + cons = u_boot_console + cons.restart_uboot() + output = cons.get_spawn_output().replace('\r', '') + assert 'sandbox: starting...' in output + assert (not 'debug: main' in output) diff --git a/test/str_ut.c b/test/str_ut.c index ef1205dbbd..cd5045516d 100644 --- a/test/str_ut.c +++ b/test/str_ut.c @@ -19,7 +19,7 @@ static const char str3[] = "0xbI'm sorry you're alive."; /* Declare a new str test */ #define STR_TEST(_name, _flags) UNIT_TEST(_name, _flags, str_test) -static int str_test_upper(struct unit_test_state *uts) +static int str_upper(struct unit_test_state *uts) { char out[TEST_STR_SIZE]; @@ -55,7 +55,7 @@ static int str_test_upper(struct unit_test_state *uts) return 0; } -STR_TEST(str_test_upper, 0); +STR_TEST(str_upper, 0); static int run_strtoul(struct unit_test_state *uts, const char *str, int base, ulong expect_val, int expect_endp_offset, bool upper) @@ -8,6 +8,9 @@ #include <common.h> #include <console.h> #include <malloc.h> +#ifdef CONFIG_SANDBOX +#include <asm/state.h> +#endif #include <test/test.h> #include <test/ut.h> @@ -114,3 +117,18 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes) return upto == total_bytes ? 0 : 1; } + +void ut_silence_console(struct unit_test_state *uts) +{ +#ifdef CONFIG_SANDBOX + struct sandbox_state *state = state_get_current(); + + if (!state->show_test_output) + gd->flags |= GD_FLG_SILENT; +#endif +} + +void ut_unsilence_console(struct unit_test_state *uts) +{ + gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD); +} |