mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-23 13:56:20 +00:00
test: Add helper to skip to partial console line
Sometimes we need to skip to a line but it includes addresses or other information which can vary depending on the runtime conditions. Add a new ut_assert_skip_to_linen() which is similar to the existing ut_assert_skip_to_line() function but only checks that the console line matches up to the length of the provided string. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
4001e5ab9b
commit
30a75e7794
2 changed files with 57 additions and 0 deletions
|
@ -97,6 +97,23 @@ int ut_check_skipline(struct unit_test_state *uts);
|
||||||
*/
|
*/
|
||||||
int ut_check_skip_to_line(struct unit_test_state *uts, const char *fmt, ...);
|
int ut_check_skip_to_line(struct unit_test_state *uts, const char *fmt, ...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ut_check_skip_to_linen() - skip output until a partial 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.
|
||||||
|
* Only the characters up to the length of the string are checked, so the line
|
||||||
|
* may extend further
|
||||||
|
*
|
||||||
|
* 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_linen(struct unit_test_state *uts, const char *fmt, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ut_check_console_end() - Check there is no more console output
|
* ut_check_console_end() - Check there is no more console output
|
||||||
*
|
*
|
||||||
|
@ -359,6 +376,19 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
|
||||||
__ret; \
|
__ret; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/* Assert that a following console output line matches */
|
||||||
|
#define ut_assert_skip_to_linen(fmt, args...) ({ \
|
||||||
|
int __ret = 0; \
|
||||||
|
\
|
||||||
|
if (ut_check_skip_to_linen(uts, fmt, ##args)) { \
|
||||||
|
ut_failf(uts, __FILE__, __LINE__, __func__, \
|
||||||
|
"console", "\nExpected '%s',\n got to '%s'", \
|
||||||
|
uts->expect_str, uts->actual_str); \
|
||||||
|
return CMD_RET_FAILURE; \
|
||||||
|
} \
|
||||||
|
__ret; \
|
||||||
|
})
|
||||||
|
|
||||||
/* Assert that there is no more console output */
|
/* Assert that there is no more console output */
|
||||||
#define ut_assert_console_end() ({ \
|
#define ut_assert_console_end() ({ \
|
||||||
int __ret = 0; \
|
int __ret = 0; \
|
||||||
|
|
27
test/ut.c
27
test/ut.c
|
@ -121,6 +121,33 @@ int ut_check_skipline(struct unit_test_state *uts)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ut_check_skip_to_linen(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);
|
||||||
|
va_end(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 (!strncmp(uts->expect_str, uts->actual_str,
|
||||||
|
strlen(uts->expect_str)))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int ut_check_skip_to_line(struct unit_test_state *uts, const char *fmt, ...)
|
int ut_check_skip_to_line(struct unit_test_state *uts, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
Loading…
Add table
Reference in a new issue