1 // SPDX-License-Identifier: GPL-2.0+
3 * Simple unit test library
5 * Copyright (c) 2013 Google, Inc
11 #include <test/test.h>
14 DECLARE_GLOBAL_DATA_PTR;
16 void ut_fail(struct unit_test_state *uts, const char *fname, int line,
17 const char *func, const char *cond)
19 gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
20 printf("%s:%d, %s(): %s\n", fname, line, func, cond);
24 void ut_failf(struct unit_test_state *uts, const char *fname, int line,
25 const char *func, const char *cond, const char *fmt, ...)
29 gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
30 printf("%s:%d, %s(): %s: ", fname, line, func, cond);
38 ulong ut_check_free(void)
40 struct mallinfo info = mallinfo();
45 long ut_check_delta(ulong last)
47 return ut_check_free() - last;
50 int ut_check_console_line(struct unit_test_state *uts, const char *fmt, ...)
55 vsnprintf(uts->expect_str, sizeof(uts->expect_str), fmt, args);
57 console_record_readline(uts->actual_str, sizeof(uts->actual_str));
59 return strcmp(uts->expect_str, uts->actual_str);
62 int ut_check_console_linen(struct unit_test_state *uts, const char *fmt, ...)
67 vsnprintf(uts->expect_str, sizeof(uts->expect_str), fmt, args);
69 console_record_readline(uts->actual_str, sizeof(uts->actual_str));
71 return strncmp(uts->expect_str, uts->actual_str,
72 strlen(uts->expect_str));
75 int ut_check_skipline(struct unit_test_state *uts)
77 if (!console_record_avail())
79 console_record_readline(uts->actual_str, sizeof(uts->actual_str));
84 int ut_check_console_end(struct unit_test_state *uts)
86 if (!console_record_avail())
89 console_record_readline(uts->actual_str, sizeof(uts->actual_str));
94 int ut_check_console_dump(struct unit_test_state *uts, int total_bytes)
96 char *str = uts->actual_str;
99 /* Handle empty dump */
103 for (upto = 0; upto < total_bytes;) {
107 len = console_record_readline(str, sizeof(uts->actual_str));
108 if (str[8] != ':' || str[9] != ' ')
111 bytes = len - 8 - 2 - 3 * 16 - 4;
115 return upto == total_bytes ? 0 : 1;