diff options
author | Simon Glass <sjg@chromium.org> | 2021-05-08 06:59:57 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-06-08 11:39:09 -0400 |
commit | 090d664eac6ff3bdb39c871bb9079df8e22873fc (patch) | |
tree | 9263eff968a58e308683e3f67fbb562e89003b54 | |
parent | c1a2bb4f836a1c96c8e39a67be9795d462ec3356 (diff) | |
download | u-boot-090d664eac6ff3bdb39c871bb9079df8e22873fc.tar.gz u-boot-090d664eac6ff3bdb39c871bb9079df8e22873fc.tar.bz2 u-boot-090d664eac6ff3bdb39c871bb9079df8e22873fc.zip |
test: Detect when expect_str is too small
If a line of more than 256 bytes is generated, the test will fail but the
reason is not clear. Add a check for this condition and print a helpful
message.
Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r-- | test/ut.c | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -68,11 +68,17 @@ static int readline_check(struct unit_test_state *uts) int ut_check_console_line(struct unit_test_state *uts, const char *fmt, ...) { va_list args; + int len; int ret; va_start(args, fmt); - vsnprintf(uts->expect_str, sizeof(uts->expect_str), fmt, args); + 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; + } ret = readline_check(uts); if (ret < 0) return ret; @@ -83,11 +89,17 @@ int ut_check_console_line(struct unit_test_state *uts, const char *fmt, ...) int ut_check_console_linen(struct unit_test_state *uts, const char *fmt, ...) { va_list args; + int len; int ret; va_start(args, fmt); - vsnprintf(uts->expect_str, sizeof(uts->expect_str), fmt, args); + 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; + } ret = readline_check(uts); if (ret < 0) return ret; |