]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
test: Fail when an empty line is expected but not present
authorSimon Glass <sjg@chromium.org>
Thu, 22 Aug 2024 13:57:47 +0000 (07:57 -0600)
committerTom Rini <trini@konsulko.com>
Tue, 27 Aug 2024 00:51:48 +0000 (18:51 -0600)
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 <sjg@chromium.org>
Fixes: 400175b0a7d ("test: Add a way to check each line of console...")
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
common/console.c
include/console.h
test/boot/bootflow.c
test/ut.c

index 63f78004fdbc95f9453f42ca1cf063747e0c1ab8..85f627297edee803b9b21bb221b9312e8aa0f02e 100644 (file)
@@ -845,6 +845,8 @@ int console_record_readline(char *str, int maxlen)
 {
        if (gd->flags & GD_FLG_RECORD_OVF)
                return -ENOSPC;
+       if (console_record_isempty())
+               return -ENOENT;
 
        return membuff_readline((struct membuff *)&gd->console_out, str,
                                maxlen, '\0', false);
index 2617e1600733fd16958813d4b8c66a63d496b73a..6b6d0f9de736175d119689cca0ad8924e8240166 100644 (file)
@@ -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);
 
index 8b46256fa48db72fb2aeabf3d5ac99b410a31735..8bfc2a1b9b4334fcf5e902a246176de009d099d8 100644 (file)
@@ -1151,8 +1151,6 @@ static int bootflow_cmdline(struct unit_test_state *uts)
 
        ut_asserteq(0, run_command("bootflow cmdline set mary abc", 0));
        ut_asserteq(0, run_command("bootflow cmdline set mary", 0));
-       ut_assert_nextline_empty();
-
        ut_assert_console_end();
 
        return 0;
index ae99831ac8ff73854ff2239d47528a5b1f6948ea..7454da3e001f5953989bd702cec0c14c996fea7d 100644 (file)
--- a/test/ut.c
+++ b/test/ut.c
@@ -59,9 +59,11 @@ static int readline_check(struct unit_test_state *uts)
                ut_fail(uts, __FILE__, __LINE__, __func__,
                        "Console record buffer too small - increase CONFIG_CONSOLE_RECORD_OUT_SIZE");
                return ret;
+       } else if (ret == -ENOENT) {
+               strcpy(uts->actual_str, "<no-more-output>");
        }
 
-       return 0;
+       return ret;
 }
 
 int ut_check_console_line(struct unit_test_state *uts, const char *fmt, ...)
@@ -79,8 +81,8 @@ int ut_check_console_line(struct unit_test_state *uts, const char *fmt, ...)
                return -EOVERFLOW;
        }
        ret = readline_check(uts);
-       if (ret < 0)
-               return ret;
+       if (ret == -ENOENT)
+               return 1;
 
        return strcmp(uts->expect_str, uts->actual_str);
 }