Convert CONFIG_SYS_MEMTEST_START et al to Kconfig
[platform/kernel/u-boot.git] / test / ut.c
index a0fe5fa..28da417 100644 (file)
--- a/test/ut.c
+++ b/test/ut.c
@@ -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;
@@ -109,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);
+       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 (!strcmp(uts->expect_str, uts->actual_str))
+                       return 0;
+       }
+}
+
 int ut_check_console_end(struct unit_test_state *uts)
 {
        int ret;
@@ -139,7 +177,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes)
                if (str[8] != ':' || str[9] != ' ')
                        return 1;
 
-               bytes = len - 8 - 2 - 3 * 16 - 4;
+               bytes = len - 8 - 2 - 3 * 16 - 2;
                upto += bytes;
        }