Commit 9aee0183 authored by Simon Glass's avatar Simon Glass
Browse files

test: Add a way to skip console checking until a string matches

Some tests produce a lot of output that does not need to be individually
checked by an assertion. Add a macro to handle this.

Series-to: u-boot
Series-links: 258653
Series-version: 2
sandbox: Minor fixes and improvements
This series collects a few patches that correct and improve sandbox and

- Fix a bug in --rm-memory works
- Support an MMC backing file for MMC emulator, to allow filesystems to be
  used without needing the 'host' filesystem
- Allow skipping console output when checking verbose commands
- Suppress unwanted filesystem warnings when probing partitions
- Tidy up a few comments
Signed-off-by: Simon Glass's avatarSimon Glass <>
Change-Id: I44fcf34ce986e97cb281a70e4fc04caed4c26045
parent 6239ce07
Pipeline #9178 canceled with stages
in 1 minute and 5 seconds
......@@ -82,6 +82,21 @@ int ut_check_console_linen(struct unit_test_state *uts, const char *fmt, ...)
int ut_check_skipline(struct unit_test_state *uts);
* ut_check_skip_to_line() - skip output until a line is found
* This creates a string and then checks it against the following lines of
* console output obtained with console_record_readline() until it is found.
* After the function returns, uts->expect_str holds the expected string and
* uts->actual_str holds the actual string read from the console.
* @uts: Test state
* @fmt: printf() format string to look for, followed by args
* @return 0 if OK, -ENOENT if not found, other value on error
int ut_check_skip_to_line(struct unit_test_state *uts, const char *fmt, ...);
* ut_check_console_end() - Check there is no more console output
......@@ -286,6 +301,15 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
} \
/* Assert that a following console output line matches */
#define ut_assert_skip_to_line(fmt, args...) \
if (ut_check_skip_to_line(uts, fmt, ##args)) { \
ut_failf(uts, __FILE__, __LINE__, __func__, \
"console", "\nExpected '%s',\n got to '%s'", \
uts->expect_str, uts->actual_str); \
} \
/* Assert that there is no more console output */
#define ut_assert_console_end() \
if (ut_check_console_end(uts)) { \
......@@ -121,6 +121,32 @@ int ut_check_skipline(struct unit_test_state *uts)
return 0;
int ut_check_skip_to_line(struct unit_test_state *uts, const char *fmt, ...)
va_list args;
int len;
int ret;
va_start(args, fmt);
len = vsnprintf(uts->expect_str, sizeof(uts->expect_str), fmt, args);
if (len >= sizeof(uts->expect_str)) {
ut_fail(uts, __FILE__, __LINE__, __func__,
"unit_test_state->expect_str too small");
return -EOVERFLOW;
while (1) {
if (!console_record_avail())
return -ENOENT;
ret = readline_check(uts);
if (ret < 0)
return ret;
if (!strcmp(uts->expect_str, uts->actual_str))
return 0;
int ut_check_console_end(struct unit_test_state *uts)
int ret;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment