From 88ae69f3b7efaa8de5c9d5d50081d6bf83e77ae9 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 22 Aug 2024 07:57:47 -0600 Subject: test: Fail when an empty line is expected but not present The existing implementation of ut_assert_nextline_empty() cannot distinguish between an empty line and no line at all. It can in fact be called at the end of the recorded output and will happily return success. Adjust the logic so that this condition is detected. Show a failure message in this case. Fix the one test which falls foul of this fix. Signed-off-by: Simon Glass Fixes: 400175b0a7d ("test: Add a way to check each line of console...") Reviewed-by: Mattijs Korpershoek --- include/console.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/console.h b/include/console.h index 2617e160073..6b6d0f9de73 100644 --- a/include/console.h +++ b/include/console.h @@ -73,7 +73,7 @@ int console_record_reset_enable(void); * @str: Place to put string * @maxlen: Maximum length of @str including nul terminator * Return: length of string returned, or -ENOSPC if the console buffer was - * overflowed by the output + * overflowed by the output, or -ENOENT if there was nothing to read */ int console_record_readline(char *str, int maxlen); -- cgit v1.2.3 From 725c438c6271f1870636f61a68d6904dc27a1357 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 22 Aug 2024 07:57:48 -0600 Subject: test: Rename unit-test flags The UT_TESTF_ macros read as 'unit test test flags' which is not right. Rename to UTF ('unit test flags'). This has the benefit of being shorter, which helps keep UNIT_TEST() declarations on a single line. Give the enum a name and reference it from the UNIT_TEST() macros while we are here. Signed-off-by: Simon Glass --- include/dm/test.h | 2 +- include/test/spl.h | 2 +- include/test/test.h | 32 ++++++++++++++++---------------- include/test/ut.h | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) (limited to 'include') diff --git a/include/dm/test.h b/include/dm/test.h index 02737411a16..61776c8dda1 100644 --- a/include/dm/test.h +++ b/include/dm/test.h @@ -143,7 +143,7 @@ extern struct unit_test_state global_dm_test_state; /* Declare a new driver model test */ #define DM_TEST(_name, _flags) \ - UNIT_TEST(_name, UT_TESTF_DM | UT_TESTF_CONSOLE_REC | (_flags), dm_test) + UNIT_TEST(_name, UTF_DM | UTF_CONSOLE_REC | (_flags), dm_test) /* * struct sandbox_sdl_plat - Platform data for the SDL video driver diff --git a/include/test/spl.h b/include/test/spl.h index a2a5f33e328..5fd28d92706 100644 --- a/include/test/spl.h +++ b/include/test/spl.h @@ -154,6 +154,6 @@ SPL_TEST(func##_##type, flags) #define SPL_TEST_DATA_SIZE 4099 /* Flags necessary for accessing DM devices */ -#define DM_FLAGS (UT_TESTF_DM | UT_TESTF_SCAN_FDT) +#define DM_FLAGS (UTF_DM | UTF_SCAN_FDT) #endif /* TEST_SPL_H */ diff --git a/include/test/test.h b/include/test/test.h index 838e3ce8a8f..9ad73daf7f8 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -24,11 +24,11 @@ * @fdt_chksum: crc8 of the device tree contents * @fdt_copy: Copy of the device tree * @fdt_size: Size of the device-tree copy - * @other_fdt: Buffer for the other FDT (UT_TESTF_OTHER_FDT) - * @other_fdt_size: Size of the other FDT (UT_TESTF_OTHER_FDT) + * @other_fdt: Buffer for the other FDT (UTF_OTHER_FDT) + * @other_fdt_size: Size of the other FDT (UTF_OTHER_FDT) * @of_other: Live tree for the other FDT * @runs_per_test: Number of times to run each test (typically 1) - * @force_run: true to run tests marked with the UT_TESTF_MANUAL flag + * @force_run: true to run tests marked with the UTF_MANUAL flag * @expect_str: Temporary string used to hold expected string value * @actual_str: Temporary string used to hold actual string value */ @@ -55,24 +55,24 @@ struct unit_test_state { }; /* Test flags for each test */ -enum { - UT_TESTF_SCAN_PDATA = BIT(0), /* test needs platform data */ - UT_TESTF_PROBE_TEST = BIT(1), /* probe test uclass */ - UT_TESTF_SCAN_FDT = BIT(2), /* scan device tree */ - UT_TESTF_FLAT_TREE = BIT(3), /* test needs flat DT */ - UT_TESTF_LIVE_TREE = BIT(4), /* needs live device tree */ - UT_TESTF_CONSOLE_REC = BIT(5), /* needs console recording */ +enum ut_flags { + UTF_SCAN_PDATA = BIT(0), /* test needs platform data */ + UTF_PROBE_TEST = BIT(1), /* probe test uclass */ + UTF_SCAN_FDT = BIT(2), /* scan device tree */ + UTF_FLAT_TREE = BIT(3), /* test needs flat DT */ + UTF_LIVE_TREE = BIT(4), /* needs live device tree */ + UTF_CONSOLE_REC = BIT(5), /* needs console recording */ /* do extra driver model init and uninit */ - UT_TESTF_DM = BIT(6), - UT_TESTF_OTHER_FDT = BIT(7), /* read in other device tree */ + UTF_DM = BIT(6), + UTF_OTHER_FDT = BIT(7), /* read in other device tree */ /* * Only run if explicitly requested with 'ut -f '. The * test name must end in "_norun" so that pytest detects this also, * since it cannot access the flags. */ - UT_TESTF_MANUAL = BIT(8), - UT_TESTF_ETH_BOOTDEV = BIT(9), /* enable Ethernet bootdevs */ - UT_TESTF_SF_BOOTDEV = BIT(10), /* enable SPI flash bootdevs */ + UTF_MANUAL = BIT(8), + UTF_ETH_BOOTDEV = BIT(9), /* enable Ethernet bootdevs */ + UTF_SF_BOOTDEV = BIT(10), /* enable SPI flash bootdevs */ }; /** @@ -109,7 +109,7 @@ struct unit_test { * @_name: concatenation of name of the test suite, "_test_", and the name * of the test * @_flags: an integer field that can be evaluated by the test suite - * implementation + * implementation (see enum ut_flags) * @_suite: name of the test suite concatenated with "_test" */ #define UNIT_TEST(_name, _flags, _suite) \ diff --git a/include/test/ut.h b/include/test/ut.h index d3172af8083..c8838dad096 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -495,7 +495,7 @@ void test_set_state(struct unit_test_state *uts); * @select_name: Name of a single test to run (from the list provided). If NULL * then all tests are run * @runs_per_test: Number of times to run each test (typically 1) - * @force_run: Run tests that are marked as manual-only (UT_TESTF_MANUAL) + * @force_run: Run tests that are marked as manual-only (UTF_MANUAL) * @test_insert: String describing a test to run after n other tests run, in the * format n:name where n is the number of tests to run before this one and * name is the name of the test to run. This is used to find which test causes -- cgit v1.2.3 From 9b99762eff5eac971cd1ae561e443252afb7b985 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 22 Aug 2024 07:57:50 -0600 Subject: test: Rename UTF_CONSOLE_REC to UTF_CONSOLE The _REC suffix doesn't add much. Really what we want to know is whether the test uses the console, so rename this flag. Signed-off-by: Simon Glass Reviewed-by: Mattijs Korpershoek --- include/dm/test.h | 2 +- include/test/test.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/dm/test.h b/include/dm/test.h index 61776c8dda1..3cbf2c740d4 100644 --- a/include/dm/test.h +++ b/include/dm/test.h @@ -143,7 +143,7 @@ extern struct unit_test_state global_dm_test_state; /* Declare a new driver model test */ #define DM_TEST(_name, _flags) \ - UNIT_TEST(_name, UTF_DM | UTF_CONSOLE_REC | (_flags), dm_test) + UNIT_TEST(_name, UTF_DM | UTF_CONSOLE | (_flags), dm_test) /* * struct sandbox_sdl_plat - Platform data for the SDL video driver diff --git a/include/test/test.h b/include/test/test.h index 9ad73daf7f8..92eec2eb6f9 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -61,7 +61,7 @@ enum ut_flags { UTF_SCAN_FDT = BIT(2), /* scan device tree */ UTF_FLAT_TREE = BIT(3), /* test needs flat DT */ UTF_LIVE_TREE = BIT(4), /* needs live device tree */ - UTF_CONSOLE_REC = BIT(5), /* needs console recording */ + UTF_CONSOLE = BIT(5), /* needs console recording */ /* do extra driver model init and uninit */ UTF_DM = BIT(6), UTF_OTHER_FDT = BIT(7), /* read in other device tree */ -- cgit v1.2.3 From 75c535c37dd2aa90416e7d247d5d8a152be2f701 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 22 Aug 2024 07:58:01 -0600 Subject: test: log: Use UTF_CONSOLE in tests Set this flag rather than doing things manually in the test. Signed-off-by: Simon Glass --- include/test/log.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/test/log.h b/include/test/log.h index e9028914500..e3362b85e99 100644 --- a/include/test/log.h +++ b/include/test/log.h @@ -13,7 +13,8 @@ #define LOGF_TEST (BIT(LOGF_FUNC) | BIT(LOGF_MSG)) /* Declare a new logging test */ -#define LOG_TEST(_name) UNIT_TEST(_name, 0, log_test) -#define LOG_TEST_FLAGS(_name, _flags) UNIT_TEST(_name, _flags, log_test) +#define LOG_TEST(_name) UNIT_TEST(_name, UTF_CONSOLE, log_test) +#define LOG_TEST_FLAGS(_name, _flags) \ + UNIT_TEST(_name, _flags | UTF_CONSOLE, log_test) #endif /* __TEST_LOG_H__ */ -- cgit v1.2.3