aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/cmd/Makefile3
-rw-r--r--test/cmd/test_pause.c45
-rw-r--r--test/cmd_ut.c12
-rw-r--r--test/dm/rtc.c53
-rw-r--r--test/dm/test-dm.c13
-rw-r--r--test/test-main.c14
6 files changed, 117 insertions, 23 deletions
diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index c331757425..1bb02d93a2 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -5,6 +5,9 @@
ifdef CONFIG_HUSH_PARSER
obj-$(CONFIG_CONSOLE_RECORD) += test_echo.o
endif
+ifdef CONFIG_CONSOLE_RECORD
+obj-$(CONFIG_CMD_PAUSE) += test_pause.o
+endif
obj-y += mem.o
obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
obj-$(CONFIG_CMD_FDT) += fdt.o
diff --git a/test/cmd/test_pause.c b/test/cmd/test_pause.c
new file mode 100644
index 0000000000..2b85cce327
--- /dev/null
+++ b/test/cmd/test_pause.c
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for pause command
+ *
+ * Copyright 2022, Samuel Dionne-Riel <samuel@dionne-riel.com>
+ */
+
+#include <common.h>
+#include <asm/global_data.h>
+#include <test/lib.h>
+#include <test/ut.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static int lib_test_hush_pause(struct unit_test_state *uts)
+{
+ /* Test default message */
+ console_record_reset_enable();
+ /* Cook a newline when the command is expected to pause */
+ console_in_puts("\n");
+ ut_assertok(run_command("pause", 0));
+ console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+ ut_asserteq_str("Press any key to continue...", uts->actual_str);
+ ut_assertok(ut_check_console_end(uts));
+
+ /* Test provided message */
+ console_record_reset_enable();
+ /* Cook a newline when the command is expected to pause */
+ console_in_puts("\n");
+ ut_assertok(run_command("pause 'Prompt for pause...'", 0));
+ console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+ ut_asserteq_str("Prompt for pause...", uts->actual_str);
+ ut_assertok(ut_check_console_end(uts));
+
+ /* Test providing more than one params */
+ console_record_reset_enable();
+ /* No newline cooked here since the command is expected to fail */
+ ut_asserteq(1, run_command("pause a b", 0));
+ console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+ ut_asserteq_str("pause - delay until user input", uts->actual_str);
+ ut_asserteq(1, ut_check_console_end(uts));
+
+ return 0;
+}
+LIB_TEST(lib_test_hush_pause, 0);
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index 3789c6b784..11c219b48a 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -18,10 +18,17 @@ int cmd_ut_category(const char *name, const char *prefix,
struct unit_test *tests, int n_ents,
int argc, char *const argv[])
{
+ int runs_per_text = 1;
int ret;
+ if (argc > 1 && !strncmp("-r", argv[1], 2)) {
+ runs_per_text = dectoul(argv[1] + 2, NULL);
+ argv++;
+ argc++;
+ }
+
ret = ut_run_list(name, prefix, tests, n_ents,
- argc > 1 ? argv[1] : NULL);
+ argc > 1 ? argv[1] : NULL, runs_per_text);
return ret ? CMD_RET_FAILURE : 0;
}
@@ -168,7 +175,8 @@ static char ut_help_text[] =
#ifdef CONFIG_CMD_LOADM
"ut loadm [test-name]- test of parameters and load memory blob\n"
#endif
- ;
+ "All commands accept an optional [-r<runs>] flag before [test-name], to\n"
+ "run each test multiple times (<runs> is in decimal)";
#endif /* CONFIG_SYS_LONGHELP */
U_BOOT_CMD(
diff --git a/test/dm/rtc.c b/test/dm/rtc.c
index c7f9f8f0ce..bf97dbbd2f 100644
--- a/test/dm/rtc.c
+++ b/test/dm/rtc.c
@@ -60,16 +60,27 @@ static int dm_test_rtc_set_get(struct unit_test_state *uts)
{
struct rtc_time now, time, cmp;
struct udevice *dev, *emul;
- long offset, old_offset, old_base_time;
+ long offset, check_offset, old_offset, old_base_time;
+ int i;
ut_assertok(uclass_get_device(UCLASS_RTC, 0, &dev));
- ut_assertok(dm_rtc_get(dev, &now));
ut_assertok(i2c_emul_find(dev, &emul));
- ut_assert(emul != NULL);
+ ut_assertnonnull(emul);
+
+ /* Get the offset, putting the RTC into manual mode */
+ i = 0;
+ do {
+ check_offset = sandbox_i2c_rtc_set_offset(emul, false, 0);
+ ut_assertok(dm_rtc_get(dev, &now));
+
+ /* Tell the RTC to go into manual mode */
+ old_offset = sandbox_i2c_rtc_set_offset(emul, false, 0);
+
+ /* If the times changed in that period, read it again */
+ } while (++i < 2 && check_offset != old_offset);
+ ut_asserteq(check_offset, old_offset);
- /* Tell the RTC to go into manual mode */
- old_offset = sandbox_i2c_rtc_set_offset(emul, false, 0);
old_base_time = sandbox_i2c_rtc_get_set_base_time(emul, -1);
memset(&time, '\0', sizeof(time));
@@ -127,7 +138,8 @@ static int dm_test_rtc_set_get(struct unit_test_state *uts)
ut_asserteq(now.tm_sec + 1, cmp.tm_sec);
}
- old_offset = sandbox_i2c_rtc_set_offset(emul, true, 0);
+ /* return RTC to normal mode */
+ sandbox_i2c_rtc_set_offset(emul, true, 0);
return 0;
}
@@ -161,7 +173,7 @@ static int dm_test_rtc_read_write(struct unit_test_state *uts)
ut_asserteq(memcmp(buf, "at", 3), 0);
ut_assertok(i2c_emul_find(dev, &emul));
- ut_assert(emul != NULL);
+ ut_assertnonnull(emul);
old_offset = sandbox_i2c_rtc_set_offset(emul, false, 0);
ut_assertok(dm_rtc_get(dev, &time));
@@ -240,20 +252,31 @@ static int dm_test_rtc_reset(struct unit_test_state *uts)
struct rtc_time now;
struct udevice *dev, *emul;
long old_base_time, base_time;
+ int i;
ut_assertok(uclass_get_device(UCLASS_RTC, 0, &dev));
ut_assertok(dm_rtc_get(dev, &now));
ut_assertok(i2c_emul_find(dev, &emul));
- ut_assert(emul != NULL);
+ ut_assertnonnull(emul);
+
+ i = 0;
+ do {
+ old_base_time = sandbox_i2c_rtc_get_set_base_time(emul, 0);
- old_base_time = sandbox_i2c_rtc_get_set_base_time(emul, 0);
+ ut_asserteq(0, sandbox_i2c_rtc_get_set_base_time(emul, -1));
- ut_asserteq(0, sandbox_i2c_rtc_get_set_base_time(emul, -1));
+ ut_assertok(dm_rtc_reset(dev));
+ base_time = sandbox_i2c_rtc_get_set_base_time(emul, -1);
- /* Resetting the RTC should put he base time back to normal */
- ut_assertok(dm_rtc_reset(dev));
- base_time = sandbox_i2c_rtc_get_set_base_time(emul, -1);
+ /*
+ * Resetting the RTC should put the base time back to normal.
+ * Allow for a one-timeadjustment in case the time flips over
+ * while this test process is pre-empted (either by a second
+ * or a daylight-saving change), since reset_time() in
+ * i2c_rtc_emul.c reads the time from the OS.
+ */
+ } while (++i < 2 && base_time != old_base_time);
ut_asserteq(old_base_time, base_time);
return 0;
@@ -274,9 +297,9 @@ static int dm_test_rtc_dual(struct unit_test_state *uts)
ut_assertok(dm_rtc_get(dev2, &now2));
ut_assertok(i2c_emul_find(dev1, &emul1));
- ut_assert(emul1 != NULL);
+ ut_assertnonnull(emul1);
ut_assertok(i2c_emul_find(dev2, &emul2));
- ut_assert(emul2 != NULL);
+ ut_assertnonnull(emul2);
offset = sandbox_i2c_rtc_set_offset(emul1, false, -1);
sandbox_i2c_rtc_set_offset(emul2, false, offset + 1);
diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index f5cda81bbf..eb3581333b 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -29,13 +29,14 @@ DECLARE_GLOBAL_DATA_PTR;
* "fdt_pre_reloc"), or NULL to run all
* Return: 0 if all tests passed, 1 if not
*/
-static int dm_test_run(const char *test_name)
+static int dm_test_run(const char *test_name, int runs_per_text)
{
struct unit_test *tests = UNIT_TEST_SUITE_START(dm_test);
const int n_ents = UNIT_TEST_SUITE_COUNT(dm_test);
int ret;
- ret = ut_run_list("driver model", "dm_test_", tests, n_ents, test_name);
+ ret = ut_run_list("driver model", "dm_test_", tests, n_ents, test_name,
+ runs_per_text);
return ret ? CMD_RET_FAILURE : 0;
}
@@ -43,9 +44,15 @@ static int dm_test_run(const char *test_name)
int do_ut_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
const char *test_name = NULL;
+ int runs_per_text = 1;
+ if (argc > 1 && !strncmp("-r", argv[1], 2)) {
+ runs_per_text = dectoul(argv[1] + 2, NULL);
+ argv++;
+ argc++;
+ }
if (argc > 1)
test_name = argv[1];
- return dm_test_run(test_name);
+ return dm_test_run(test_name, runs_per_text);
}
diff --git a/test/test-main.c b/test/test-main.c
index 31837e57a8..4f1c54b0f9 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -390,11 +390,17 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
for (test = tests; test < tests + count; test++) {
const char *test_name = test->name;
- int ret;
+ int ret, i, old_fail_count;
if (!test_matches(prefix, test_name, select_name))
continue;
- ret = ut_run_test_live_flat(uts, test, select_name);
+ old_fail_count = uts->fail_count;
+ for (i = 0; i < uts->runs_per_test; i++)
+ ret = ut_run_test_live_flat(uts, test, select_name);
+ if (uts->fail_count != old_fail_count) {
+ printf("Test %s failed %d times\n", select_name,
+ uts->fail_count - old_fail_count);
+ }
found++;
if (ret == -EAGAIN)
continue;
@@ -408,7 +414,8 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
}
int ut_run_list(const char *category, const char *prefix,
- struct unit_test *tests, int count, const char *select_name)
+ struct unit_test *tests, int count, const char *select_name,
+ int runs_per_test)
{
struct unit_test_state uts = { .fail_count = 0 };
bool has_dm_tests = false;
@@ -432,6 +439,7 @@ int ut_run_list(const char *category, const char *prefix,
printf("Running %d %s tests\n", count, category);
uts.of_root = gd_of_root();
+ uts.runs_per_test = runs_per_test;
ret = ut_run_tests(&uts, prefix, tests, count, select_name);
if (ret == -ENOENT)