From af033ec8b4ebe28dd5e45b19f3abe213b1f4def3 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 5 Nov 2020 01:29:06 +0100 Subject: test: test/lib/test_print.c depends on CONSOLE_RECORD The tests in test/lib/test_print.c fail without CONFIG_CONSOLE_RECORD=y. Add a build dependency. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- test/lib/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/lib/Makefile b/test/lib/Makefile index 98a9abf40e2..97c11e35a88 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 -- cgit v1.2.3 From ef7e264944a21c0a78378bf4d28db5bcacbc5b45 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 8 Nov 2020 21:08:43 -0700 Subject: test: Avoid assuming sandbox board for bloblist test This tests assumes it is running on sandbox. Add a few functions to handle silencing the console on any board and use those instead. Reported-by: Kever Yang Signed-off-by: Simon Glass --- test/bloblist.c | 13 ++++--------- test/ut.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/bloblist.c b/test/bloblist.c index 0bb9e2d81e7..900299dd68e 100644 --- a/test/bloblist.c +++ b/test/bloblist.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -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/ut.c b/test/ut.c index 95bdd66de6a..44ed1ba2d31 100644 --- a/test/ut.c +++ b/test/ut.c @@ -8,6 +8,9 @@ #include #include #include +#ifdef CONFIG_SANDBOX +#include +#endif #include #include @@ -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); +} -- cgit v1.2.3 From 6ea5df39e8d072fbacc1c99645b8df63923f744d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 8 Nov 2020 21:08:44 -0700 Subject: test: Only enable bloblist test when supported This test cannot work unless CONFIG_BLOBLIST is enabled. Update it to add that condition. Reported-by: Kever Yang Signed-off-by: Simon Glass --- test/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/Makefile b/test/Makefile index d4323f99634..3c7bc8b549f 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 -- cgit v1.2.3 From 353df8d3c3ca876704d54a9d2cb94970197ad62f Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Thu, 19 Nov 2020 10:08:42 +0100 Subject: test: correct the test prefix in ut cmd_mem Align the prefix used in cmd_ut_category function and name of tests for ut mem. This patch solves the issues detected by "make qcheck" after previous patch. Fixes: 550a9e7902ce ("cmd: Update the memory-search command") Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- test/cmd/mem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/cmd/mem.c b/test/cmd/mem.c index fa6770e8c03..fbaa8a4b3cf 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); } -- cgit v1.2.3 From 76fde138832c82d87db0a29f62379bdcf21a5442 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Thu, 19 Nov 2020 10:08:43 +0100 Subject: test: correct the test prefix in ut str Align the prefix used in cmd_ut_category function and name of tests for ut str. This patch solves the issues detected by "make qcheck" after previous patch. Fixes: fdc79a6b125d ("lib: Add a function to convert a string to upper case") Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- test/str_ut.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/str_ut.c b/test/str_ut.c index ef1205dbbd0..cd5045516d1 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) -- cgit v1.2.3 From c548a3886eafa5a018d5f1c8f232510ca53be9a2 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 4 Jan 2021 08:02:56 +0100 Subject: test: unit test for pr_err(), pr_cont() Provide a unit test for printing via pr_err() and pr_cont(). Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- test/log/Makefile | 1 + test/log/pr_cont_test.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test/log/pr_cont_test.c (limited to 'test') diff --git a/test/log/Makefile b/test/log/Makefile index 88bc573e9fb..afdafa502ac 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/pr_cont_test.c b/test/log/pr_cont_test.c new file mode 100644 index 00000000000..236eff4b33b --- /dev/null +++ b/test/log/pr_cont_test.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2021, Heinrich Schuchardt + * + * Test continuation of log messages using pr_cont(). + */ + +#include +#include +#include +#include +#include +#include +#include + +#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); -- cgit v1.2.3