aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/bootm.c3
-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/common/Makefile1
-rw-r--r--test/common/cyclic.c35
-rw-r--r--test/dm/Makefile1
-rw-r--r--test/dm/blk.c24
-rw-r--r--test/dm/gpio.c30
-rw-r--r--test/dm/rtc.c53
-rw-r--r--test/dm/scsi.c39
-rw-r--r--test/dm/test-dm.c13
-rw-r--r--test/dm/test-fdt.c19
-rw-r--r--test/dm/wdt.c9
-rw-r--r--test/lib/test_print.c3
-rwxr-xr-xtest/nokia_rx51_test.sh103
-rw-r--r--test/py/conftest.py104
-rw-r--r--test/py/pytest.ini1
-rw-r--r--test/py/requirements.txt2
-rw-r--r--test/py/tests/test_bind.py1
-rw-r--r--test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py1
-rw-r--r--test/py/tests/test_eficonfig/conftest.py40
-rw-r--r--test/py/tests/test_eficonfig/test_eficonfig.py354
-rw-r--r--test/py/tests/test_fit_ecdsa.py4
-rw-r--r--test/py/tests/test_fit_hashes.py5
-rw-r--r--test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py1
-rw-r--r--test/py/tests/test_gpio.py1
-rw-r--r--test/py/tests/test_gpt.py3
-rw-r--r--test/py/tests/test_pinmux.py1
-rw-r--r--test/py/tests/test_ut.py9
-rw-r--r--test/py/tests/test_vboot.py6
-rwxr-xr-xtest/run51
-rw-r--r--test/test-main.c17
33 files changed, 890 insertions, 104 deletions
diff --git a/test/bootm.c b/test/bootm.c
index 7d03e1e0c6..4bb3ca0655 100644
--- a/test/bootm.c
+++ b/test/bootm.c
@@ -208,7 +208,8 @@ BOOTM_TEST(bootm_test_silent_var, 0);
/* Test substitution processing in the bootargs variable */
static int bootm_test_subst_var(struct unit_test_state *uts)
{
- env_set("bootargs", NULL);
+ ut_assertok(env_set("silent_linux", "yes"));
+ ut_assertok(env_set("bootargs", NULL));
ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SILENT));
ut_asserteq_str("console=ttynull", env_get("bootargs"));
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/common/Makefile b/test/common/Makefile
index 9087788ba6..cc918f64e5 100644
--- a/test/common/Makefile
+++ b/test/common/Makefile
@@ -1,4 +1,5 @@
# SPDX-License-Identifier: GPL-2.0+
obj-y += cmd_ut_common.o
obj-$(CONFIG_AUTOBOOT) += test_autoboot.o
+obj-$(CONFIG_CYCLIC) += cyclic.o
obj-$(CONFIG_EVENT) += event.o
diff --git a/test/common/cyclic.c b/test/common/cyclic.c
new file mode 100644
index 0000000000..6e758e89db
--- /dev/null
+++ b/test/common/cyclic.c
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2022 Stefan Roese <sr@denx.de>
+ */
+
+#include <common.h>
+#include <cyclic.h>
+#include <dm.h>
+#include <test/common.h>
+#include <test/test.h>
+#include <test/ut.h>
+#include <watchdog.h>
+#include <linux/delay.h>
+
+/* Test that cyclic function is called */
+static bool cyclic_active = false;
+
+static void cyclic_test(void *ctx)
+{
+ cyclic_active = true;
+}
+
+static int dm_test_cyclic_running(struct unit_test_state *uts)
+{
+ cyclic_active = false;
+ ut_assertnonnull(cyclic_register(cyclic_test, 10 * 1000, "cyclic_demo",
+ NULL));
+
+ /* Execute all registered cyclic functions */
+ schedule();
+ ut_asserteq(true, cyclic_active);
+
+ return 0;
+}
+COMMON_TEST(dm_test_cyclic_running, 0);
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 7543df8823..5178daa7cf 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -91,6 +91,7 @@ obj-$(CONFIG_DM_REGULATOR) += regulator.o
obj-$(CONFIG_DM_RNG) += rng.o
obj-$(CONFIG_DM_RTC) += rtc.o
obj-$(CONFIG_SCMI_FIRMWARE) += scmi.o
+obj-$(CONFIG_SCSI) += scsi.o
obj-$(CONFIG_DM_SERIAL) += serial.o
obj-$(CONFIG_DM_SPI_FLASH) += sf.o
obj-$(CONFIG_SIMPLE_BUS) += simple-bus.o
diff --git a/test/dm/blk.c b/test/dm/blk.c
index 85c3a3bd45..35bd5318f0 100644
--- a/test/dm/blk.c
+++ b/test/dm/blk.c
@@ -25,19 +25,19 @@ static int dm_test_blk_base(struct unit_test_state *uts)
/* Create two, one the parent of the other */
ut_assertok(blk_create_device(gd->dm_root, "sandbox_host_blk", "test",
- IF_TYPE_HOST, 1, 512, 2, &blk1));
+ UCLASS_ROOT, 1, 512, 2, &blk1));
ut_assertok(blk_create_device(blk1, "sandbox_host_blk", "test",
- IF_TYPE_HOST, 3, 512, 2, &blk3));
+ UCLASS_ROOT, 3, 512, 2, &blk3));
/* Check we can find them */
- ut_asserteq(-ENODEV, blk_get_device(IF_TYPE_HOST, 0, &dev));
- ut_assertok(blk_get_device(IF_TYPE_HOST, 1, &dev));
+ ut_asserteq(-ENODEV, blk_get_device(UCLASS_ROOT, 0, &dev));
+ ut_assertok(blk_get_device(UCLASS_ROOT, 1, &dev));
ut_asserteq_ptr(blk1, dev);
- ut_assertok(blk_get_device(IF_TYPE_HOST, 3, &dev));
+ ut_assertok(blk_get_device(UCLASS_ROOT, 3, &dev));
ut_asserteq_ptr(blk3, dev);
/* Check we can iterate */
- ut_assertok(blk_first_device(IF_TYPE_HOST, &dev));
+ ut_assertok(blk_first_device(UCLASS_ROOT, &dev));
ut_asserteq_ptr(blk1, dev);
ut_assertok(blk_next_device(&dev));
ut_asserteq_ptr(blk3, dev);
@@ -79,7 +79,7 @@ static int dm_test_blk_usb(struct unit_test_state *uts)
ut_assertok(blk_get_device_by_str("usb", "0", &dev_desc));
/* The parent should be a block device */
- ut_assertok(blk_get_device(IF_TYPE_USB, 0, &dev));
+ ut_assertok(blk_get_device(UCLASS_USB, 0, &dev));
ut_asserteq_ptr(usb_dev, dev_get_parent(dev));
/* Check we have one block device for each mass storage device */
@@ -101,14 +101,14 @@ static int dm_test_blk_find(struct unit_test_state *uts)
struct udevice *blk, *dev;
ut_assertok(blk_create_device(gd->dm_root, "sandbox_host_blk", "test",
- IF_TYPE_HOST, 1, 512, 2, &blk));
- ut_asserteq(-ENODEV, blk_find_device(IF_TYPE_HOST, 0, &dev));
- ut_assertok(blk_find_device(IF_TYPE_HOST, 1, &dev));
+ UCLASS_ROOT, 1, 512, 2, &blk));
+ ut_asserteq(-ENODEV, blk_find_device(UCLASS_ROOT, 0, &dev));
+ ut_assertok(blk_find_device(UCLASS_ROOT, 1, &dev));
ut_asserteq_ptr(blk, dev);
ut_asserteq(false, device_active(dev));
/* Now activate it */
- ut_assertok(blk_get_device(IF_TYPE_HOST, 1, &dev));
+ ut_assertok(blk_get_device(UCLASS_ROOT, 1, &dev));
ut_asserteq_ptr(blk, dev);
ut_asserteq(true, device_active(dev));
@@ -134,7 +134,7 @@ static int dm_test_blk_devnum(struct unit_test_state *uts)
/* Check that the bblock device is attached */
ut_assertok(uclass_get_device_by_seq(UCLASS_MMC, i, &mmc_dev));
- ut_assertok(blk_find_device(IF_TYPE_MMC, i, &dev));
+ ut_assertok(blk_find_device(UCLASS_MMC, i, &dev));
parent = dev_get_parent(dev);
ut_asserteq_ptr(parent, mmc_dev);
ut_asserteq(trailing_strtol(mmc_dev->name), i);
diff --git a/test/dm/gpio.c b/test/dm/gpio.c
index 33ae98701f..a8c35d4370 100644
--- a/test/dm/gpio.c
+++ b/test/dm/gpio.c
@@ -778,3 +778,33 @@ static int dm_test_gpio_get_values_as_int_base3(struct unit_test_state *uts)
}
DM_TEST(dm_test_gpio_get_values_as_int_base3,
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+/* Check that gpio_get_status return the label of a GPIO configured as GPIOD_AF */
+static int dm_test_gpio_function(struct unit_test_state *uts)
+{
+ struct gpio_desc desc;
+ struct udevice *dev;
+ ulong flags;
+ unsigned int offset, gpio;
+ char buf[80];
+
+ ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
+ ut_asserteq_str("a-test", dev->name);
+
+ /* request gpio_b 5 */
+ ut_assertok(gpio_request_by_name(dev, "test-gpios", 2, &desc, 0));
+ /* update gpio_b 5 function to GPIO_AF */
+ ut_assertok(dm_gpio_clrset_flags(&desc, GPIOD_IS_AF, GPIOD_IS_AF));
+ ut_assertok(dm_gpio_get_flags(&desc, &flags));
+ ut_asserteq(GPIOD_IS_AF, flags);
+ /* check using gpio_get_status that label is displayed for a pin with GPIO_AF function */
+ ut_assertok(gpio_lookup_name("b5", &dev, &offset, &gpio));
+ ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
+ ut_asserteq_str("b5: func a-test.test-gpios2", buf);
+
+ ut_assertok(dm_gpio_free(dev, &desc));
+
+ return 0;
+}
+DM_TEST(dm_test_gpio_function,
+ UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
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/scsi.c b/test/dm/scsi.c
new file mode 100644
index 0000000000..380cfc88ba
--- /dev/null
+++ b/test/dm/scsi.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2015 Google, Inc
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <part.h>
+#include <scsi.h>
+#include <dm/test.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+/* Test that sandbox SCSI works correctly */
+static int dm_test_scsi_base(struct unit_test_state *uts)
+{
+ const struct disk_partition *info;
+ const struct disk_part *part;
+ struct udevice *dev;
+
+ ut_assertok(scsi_scan(false));
+
+ /*
+ * We expect some sort of partition on the disk image, created by
+ * test_ut_dm_init()
+ */
+ ut_assertok(uclass_first_device_err(UCLASS_PARTITION, &dev));
+
+ part = dev_get_uclass_plat(dev);
+ ut_asserteq(1, part->partnum);
+
+ info = &part->gpt_part_info;
+ ut_asserteq_str("sda1", info->name);
+ ut_asserteq_str("U-Boot", info->type);
+ ut_asserteq(0x83 /* linux */, info->sys_ind);
+
+ return 0;
+}
+DM_TEST(dm_test_scsi_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
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/dm/test-fdt.c b/test/dm/test-fdt.c
index 6118ad42ca..012f2f455f 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -815,6 +815,8 @@ DM_TEST(dm_test_first_child, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
static int dm_test_read_int(struct unit_test_state *uts)
{
struct udevice *dev;
+ u8 val8;
+ u16 val16;
u32 val32;
s32 sval;
uint val;
@@ -822,6 +824,23 @@ static int dm_test_read_int(struct unit_test_state *uts)
ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev));
ut_asserteq_str("a-test", dev->name);
+
+ ut_assertok(dev_read_u8(dev, "int8-value", &val8));
+ ut_asserteq(0x12, val8);
+
+ ut_asserteq(-EINVAL, dev_read_u8(dev, "missing", &val8));
+ ut_asserteq(6, dev_read_u8_default(dev, "missing", 6));
+
+ ut_asserteq(0x12, dev_read_u8_default(dev, "int8-value", 6));
+
+ ut_assertok(dev_read_u16(dev, "int16-value", &val16));
+ ut_asserteq(0x1234, val16);
+
+ ut_asserteq(-EINVAL, dev_read_u16(dev, "missing", &val16));
+ ut_asserteq(6, dev_read_u16_default(dev, "missing", 6));
+
+ ut_asserteq(0x1234, dev_read_u16_default(dev, "int16-value", 6));
+
ut_assertok(dev_read_u32(dev, "int-value", &val32));
ut_asserteq(1234, val32);
diff --git a/test/dm/wdt.c b/test/dm/wdt.c
index 535f00a874..653d7b1c8b 100644
--- a/test/dm/wdt.c
+++ b/test/dm/wdt.c
@@ -4,6 +4,7 @@
*/
#include <common.h>
+#include <cyclic.h>
#include <dm.h>
#include <wdt.h>
#include <asm/gpio.h>
@@ -130,7 +131,7 @@ static int dm_test_wdt_watchdog_reset(struct unit_test_state *uts)
/* Neither device should be "started", so watchdog_reset() should be a no-op. */
reset_count = state->wdt.reset_count;
val = sandbox_gpio_get_value(gpio, offset);
- watchdog_reset();
+ cyclic_run();
ut_asserteq(reset_count, state->wdt.reset_count);
ut_asserteq(val, sandbox_gpio_get_value(gpio, offset));
@@ -140,19 +141,19 @@ static int dm_test_wdt_watchdog_reset(struct unit_test_state *uts)
/* Make sure both devices have just been pinged. */
timer_test_add_offset(100);
- watchdog_reset();
+ cyclic_run();
reset_count = state->wdt.reset_count;
val = sandbox_gpio_get_value(gpio, offset);
/* The gpio watchdog should be pinged, the sandbox one not. */
timer_test_add_offset(30);
- watchdog_reset();
+ cyclic_run();
ut_asserteq(reset_count, state->wdt.reset_count);
ut_asserteq(!val, sandbox_gpio_get_value(gpio, offset));
/* After another ~30ms, both devices should get pinged. */
timer_test_add_offset(30);
- watchdog_reset();
+ cyclic_run();
ut_asserteq(reset_count + 1, state->wdt.reset_count);
ut_asserteq(val, sandbox_gpio_get_value(gpio, offset));
diff --git a/test/lib/test_print.c b/test/lib/test_print.c
index a60a5a51f1..79b67c7793 100644
--- a/test/lib/test_print.c
+++ b/test/lib/test_print.c
@@ -68,6 +68,9 @@ static int lib_test_print_size(struct unit_test_state *uts)
ut_assertok(test_print_size(uts, 7654321, "7.3 MiB;"));
ut_assertok(test_print_size(uts, 87654321, "83.6 MiB;"));
ut_assertok(test_print_size(uts, 987654321, "941.9 MiB;"));
+ ut_assertok(test_print_size(uts, 1073689395, "1023.9 MiB;"));
+ ut_assertok(test_print_size(uts, 1073689396, "1 GiB;"));
+ ut_assertok(test_print_size(uts, 1073741824, "1 GiB;"));
ut_assertok(test_print_size(uts, 1987654321, "1.9 GiB;"));
ut_assertok(test_print_size(uts, 54321987654321, "49.4 TiB;"));
return 0;
diff --git a/test/nokia_rx51_test.sh b/test/nokia_rx51_test.sh
index 28aa554ed8..a516ec2967 100755
--- a/test/nokia_rx51_test.sh
+++ b/test/nokia_rx51_test.sh
@@ -34,9 +34,20 @@ echo "========== Compiling U-Boot for Nokia RX-51 board =========="
echo "============================================================"
echo
-# First compile u-boot.bin binary for Nokia RX-51 board
+# First compile u-boot-ubifs.bin binary with UBI/UBIFS support for Nokia RX-51 board according to doc/board/nokia/rx51.rst
make nokia_rx51_config
-make -j4 u-boot.bin ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
+cat >> .config << EOF
+CONFIG_CMD_UBI=y
+CONFIG_CMD_UBIFS=y
+CONFIG_MTD_UBI_BEB_LIMIT=10
+EOF
+make olddefconfig
+make -j4 u-boot.bin CROSS_COMPILE=arm-linux-gnueabi-
+mv u-boot.bin u-boot-ubifs.bin
+
+# Then compile standard u-boot.bin binary for Nokia RX-51 board
+make nokia_rx51_config
+make -j4 u-boot.bin CROSS_COMPILE=arm-linux-gnueabi-
# And then do all stuff in temporary directory
mkdir -p nokia_rx51_tmp
@@ -44,6 +55,7 @@ cd nokia_rx51_tmp
test -f mkimage || ln -s ../tools/mkimage .
test -f u-boot.bin || ln -s ../u-boot.bin .
+test -f u-boot-ubifs.bin || ln -s ../u-boot-ubifs.bin .
echo
echo "=========================================================================="
@@ -99,6 +111,10 @@ echo "========== Generating images =========="
echo "======================================="
echo
+# Generate kernel image in zImage and uImage format from FIASCO format
+dd if=kernel_2.6.28/boot/zImage-2.6.28-20103103+0m5.fiasco of=zImage-2.6.28-omap1 skip=95 bs=1
+./mkimage -A arm -O linux -T kernel -C none -a 80008000 -e 80008000 -n zImage-2.6.28-omap1 -d zImage-2.6.28-omap1 uImage-2.6.28-omap1
+
# Generate rootfs directory
mkdir -p rootfs
mkdir -p rootfs/dev/
@@ -123,20 +139,7 @@ echo
EOF
chmod +x rootfs/sbin/preinit
-# Generate ubi config file for ubi rootfs image
-cat > ubi.ini << EOF
-[rootfs]
-mode=ubi
-image=ubifs.img
-vol_id=0
-vol_size=160MiB
-vol_type=dynamic
-vol_name=rootfs
-vol_alignment=1
-vol_flags=autoresize
-EOF
-
-# Generate ubi rootfs image from rootfs directory
+# Generate ubifs image from rootfs directory
# NOTE: Character device on host filesystem can be created only by root
# But we do not need it on host filesystem, just in ubifs image
# So run mknod and mkfs.ubifs commands under fakeroot program
@@ -149,8 +152,35 @@ fakeroot sh -c '
mknod rootfs/dev/console c 5 1;
/usr/sbin/mkfs.ubifs -m 2048 -e 129024 -c 2047 -r rootfs ubifs.img;
'
+
+# Generate ubi image with rootfs on first volume
+cat > ubi.ini << EOF
+[rootfs]
+mode=ubi
+image=ubifs.img
+vol_id=0
+vol_size=230MiB # 1870 LEBs
+vol_type=dynamic
+vol_name=rootfs
+vol_alignment=1
+vol_flags=autoresize
+EOF
/usr/sbin/ubinize -o ubi.img -p 128KiB -m 2048 -s 512 ubi.ini
+# Generate ubi image with rootfs on first volume and kernel in zImage format on second volume for UBI booting
+cp ubi.ini ubi_with_kernel.ini
+cat >> ubi_with_kernel.ini << EOF
+[kernel]
+mode=ubi
+image=zImage-2.6.28-omap1
+vol_id=1
+vol_size=2MiB
+vol_type=dynamic
+vol_name=kernel
+vol_alignment=1
+EOF
+/usr/sbin/ubinize -o ubi_with_kernel.img -p 128KiB -m 2048 -s 512 ubi_with_kernel.ini
+
# Generate bootmenu for U-Boot serial console testing
cat > bootmenu_uboot << EOF
setenv bootmenu_0 'Serial console test=echo; echo "Testing serial console"; echo; echo "Successfully booted"; echo; poweroff';
@@ -178,15 +208,24 @@ setenv bootdelay 1;
EOF
./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_emmc2 -d bootmenu_emmc2 bootmenu_emmc2.scr
-# Generate bootmenu for OneNAND booting
+# Generate bootmenu for OneNAND booting (uImage)
cat > bootmenu_nand << EOF
-setenv bootmenu_0 'uImage-2.6.28-omap1 from OneNAND=mtd read initfs \${kernaddr}; setenv bootargs; setenv setup_omap_atag 1; bootm \${kernaddr}';
+setenv bootmenu_0 'uImage-2.6.28-omap1 from OneNAND=setenv bootargs; setenv setup_omap_atag 1; mtd read initfs \${kernaddr} && bootm \${kernaddr}';
setenv bootmenu_1;
setenv bootmenu_delay 1;
setenv bootdelay 1;
EOF
./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_nand -d bootmenu_nand bootmenu_nand.scr
+# Generate bootmenu for UBI booting (zImage)
+cat > bootmenu_ubi << EOF
+setenv bootmenu_0 'zImage-2.6.28-omap1 from UBI=setenv bootargs; setenv setup_omap_atag 1; ubi part rootfs && ubi read \${kernaddr} kernel && bootz \${kernaddr}';
+setenv bootmenu_1;
+setenv bootmenu_delay 1;
+setenv bootdelay 1;
+EOF
+./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_ubi -d bootmenu_ubi bootmenu_ubi.scr
+
# Generate bootmenu for default booting
cat > bootmenu_default << EOF
setenv bootmenu_delay 1;
@@ -195,9 +234,7 @@ EOF
./mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n bootmenu_default -d bootmenu_default bootmenu_default.scr
# Generate combined image from u-boot and Maemo fiasco kernel
-dd if=kernel_2.6.28/boot/zImage-2.6.28-20103103+0m5.fiasco of=zImage-2.6.28-omap1 skip=95 bs=1
./u-boot-gen-combined u-boot.bin zImage-2.6.28-omap1 combined_zimage.bin
-./mkimage -A arm -O linux -T kernel -C none -a 80008000 -e 80008000 -n zImage-2.6.28-omap1 -d zImage-2.6.28-omap1 uImage-2.6.28-omap1
./u-boot-gen-combined u-boot.bin uImage-2.6.28-omap1 combined_uimage.bin
# Generate combined hack image from u-boot and Maemo fiasco kernel (kernel starts at 2MB offset and qflasher puts 2kB header before supplied image)
@@ -221,11 +258,16 @@ mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_em
mcopy zImage-2.6.28-omap1 ::/zImage-2.6.28-omap1 -i emmc_emmc2.img
mcopy bootmenu_emmc2.scr ::/bootmenu.scr -i emmc_emmc2.img
-# Generate FAT32 eMMC image for OneNAND booting
+# Generate FAT32 eMMC image for OneNAND booting (uImage)
truncate -s 50MiB emmc_nand.img
mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_nand.img
mcopy bootmenu_nand.scr ::/bootmenu.scr -i emmc_nand.img
+# Generate FAT32 eMMC image for UBI booting (zImage)
+truncate -s 50MiB emmc_ubi.img
+mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_ubi.img
+mcopy bootmenu_ubi.scr ::/bootmenu.scr -i emmc_ubi.img
+
# Generate FAT32 eMMC image for default booting
truncate -s 50MiB emmc_default.img
mformat -m 0xf8 -F -h 4 -s 16 -c 1 -t $((50*1024*1024/(4*16*512))) :: -i emmc_default.img
@@ -251,6 +293,10 @@ rm -f mtd_emmc.img
rm -f mtd_nand.img
./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k combined_hack.bin -r ubi.img -m rx51 -p k=4094,i=2 -o mtd_nand.img
+# Generate MTD image for UBI booting from bootloader nolo images, u-boot image with UBI/UBIFS support and rootfs image with kernel volume
+rm -f mtd_ubi.img
+./qflasher -v -x xloader-qemu.bin -s secondary-qemu.bin -k u-boot-ubifs.bin -r ubi_with_kernel.img -m rx51 -o mtd_ubi.img
+
echo
echo "======================================================"
echo "========== Running test images in n900 qemu =========="
@@ -329,6 +375,18 @@ wait -n $sleep_pid $qemu_pid || true
kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
wait || true
+# Run MTD image in qemu and wait for 300s if kernel from UBI is correctly booted
+rm -f qemu_ubi.log
+./qemu-system-arm -M n900 -mtdblock mtd_ubi.img -sd emmc_ubi.img -serial /dev/stdout -display none > qemu_ubi.log &
+qemu_pid=$!
+tail -F qemu_ubi.log &
+tail_pid=$!
+sleep 300 &
+sleep_pid=$!
+wait -n $sleep_pid $qemu_pid || true
+kill -9 $tail_pid $sleep_pid $qemu_pid 2>/dev/null || true
+wait || true
+
echo
echo "============================="
echo "========== Results =========="
@@ -341,10 +399,11 @@ if grep -q 'Successfully booted' qemu_ram2.log; then echo "Kernel (zImage) was s
if grep -q 'Successfully booted' qemu_emmc.log; then echo "Kernel (uImage) was successfully booted from eMMC"; else echo "Failed to boot kernel (uImage) from eMMC"; fi
if grep -q 'Successfully booted' qemu_emmc2.log; then echo "Kernel (zImage) was successfully booted from eMMC"; else echo "Failed to boot kernel (zImage) from eMMC"; fi
if grep -q 'Successfully booted' qemu_nand.log; then echo "Kernel (uImage) was successfully booted from OneNAND"; else echo "Failed to boot kernel (uImage) from OneNAND"; fi
+if grep -q 'Successfully booted' qemu_ubi.log; then echo "Kernel (zImage) was successfully booted from UBI"; else echo "Failed to boot kernel (zImage) from UBI"; fi
echo
-if grep -q 'Successfully booted' qemu_uboot.log && grep -q 'Successfully booted' qemu_ram.log && grep -q 'Successfully booted' qemu_ram2.log && grep -q 'Successfully booted' qemu_emmc.log && grep -q 'Successfully booted' qemu_emmc2.log && grep -q 'Successfully booted' qemu_nand.log; then
+if grep -q 'Successfully booted' qemu_uboot.log && grep -q 'Successfully booted' qemu_ram.log && grep -q 'Successfully booted' qemu_ram2.log && grep -q 'Successfully booted' qemu_emmc.log && grep -q 'Successfully booted' qemu_emmc2.log && grep -q 'Successfully booted' qemu_nand.log && grep -q 'Successfully booted' qemu_ubi.log; then
echo "All tests passed"
exit 0
else
diff --git a/test/py/conftest.py b/test/py/conftest.py
index 2ba34479e0..304e93164a 100644
--- a/test/py/conftest.py
+++ b/test/py/conftest.py
@@ -15,9 +15,11 @@
import atexit
import configparser
import errno
+import filelock
import io
import os
import os.path
+from pathlib import Path
import pytest
import re
from _pytest.runner import runtestprotocol
@@ -27,6 +29,8 @@ import sys
log = None
console = None
+TEST_PY_DIR = os.path.dirname(os.path.abspath(__file__))
+
def mkdir_p(path):
"""Create a directory path.
@@ -76,6 +80,53 @@ def pytest_addoption(parser):
help='Run sandbox under gdbserver. The argument is the channel '+
'over which gdbserver should communicate, e.g. localhost:1234')
+def run_build(config, source_dir, build_dir, board_type, log):
+ """run_build: Build U-Boot
+
+ Args:
+ config: The pytest configuration.
+ soruce_dir (str): Directory containing source code
+ build_dir (str): Directory to build in
+ board_type (str): board_type parameter (e.g. 'sandbox')
+ log (Logfile): Log file to use
+ """
+ if config.getoption('buildman'):
+ if build_dir != source_dir:
+ dest_args = ['-o', build_dir, '-w']
+ else:
+ dest_args = ['-i']
+ cmds = (['buildman', '--board', board_type] + dest_args,)
+ name = 'buildman'
+ else:
+ if build_dir != source_dir:
+ o_opt = 'O=%s' % build_dir
+ else:
+ o_opt = ''
+ cmds = (
+ ['make', o_opt, '-s', board_type + '_defconfig'],
+ ['make', o_opt, '-s', '-j{}'.format(os.cpu_count())],
+ )
+ name = 'make'
+
+ with log.section(name):
+ runner = log.get_runner(name, sys.stdout)
+ for cmd in cmds:
+ runner.run(cmd, cwd=source_dir)
+ runner.close()
+ log.status_pass('OK')
+
+def pytest_xdist_setupnodes(config, specs):
+ """Clear out any 'done' file from a previous build"""
+ global build_done_file
+ build_dir = config.getoption('build_dir')
+ board_type = config.getoption('board_type')
+ source_dir = os.path.dirname(os.path.dirname(TEST_PY_DIR))
+ if not build_dir:
+ build_dir = source_dir + '/build-' + board_type
+ build_done_file = Path(build_dir) / 'build.done'
+ if build_done_file.exists():
+ os.remove(build_done_file)
+
def pytest_configure(config):
"""pytest hook: Perform custom initialization at startup time.
@@ -110,8 +161,7 @@ def pytest_configure(config):
global console
global ubconfig
- test_py_dir = os.path.dirname(os.path.abspath(__file__))
- source_dir = os.path.dirname(os.path.dirname(test_py_dir))
+ source_dir = os.path.dirname(os.path.dirname(TEST_PY_DIR))
board_type = config.getoption('board_type')
board_type_filename = board_type.replace('-', '_')
@@ -142,30 +192,13 @@ def pytest_configure(config):
log = multiplexed_log.Logfile(result_dir + '/test-log.html')
if config.getoption('build'):
- if config.getoption('buildman'):
- if build_dir != source_dir:
- dest_args = ['-o', build_dir, '-w']
- else:
- dest_args = ['-i']
- cmds = (['buildman', '--board', board_type] + dest_args,)
- name = 'buildman'
- else:
- if build_dir != source_dir:
- o_opt = 'O=%s' % build_dir
- else:
- o_opt = ''
- cmds = (
- ['make', o_opt, '-s', board_type + '_defconfig'],
- ['make', o_opt, '-s', '-j{}'.format(os.cpu_count())],
- )
- name = 'make'
-
- with log.section(name):
- runner = log.get_runner(name, sys.stdout)
- for cmd in cmds:
- runner.run(cmd, cwd=source_dir)
- runner.close()
- log.status_pass('OK')
+ worker_id = os.environ.get("PYTEST_XDIST_WORKER")
+ with filelock.FileLock(os.path.join(build_dir, 'build.lock')):
+ build_done_file = Path(build_dir) / 'build.done'
+ if (not worker_id or worker_id == 'master' or
+ not build_done_file.exists()):
+ run_build(config, source_dir, build_dir, board_type, log)
+ build_done_file.touch()
class ArbitraryAttributeContainer(object):
pass
@@ -197,7 +230,7 @@ def pytest_configure(config):
else:
parse_config('include/autoconf.mk')
- ubconfig.test_py_dir = test_py_dir
+ ubconfig.test_py_dir = TEST_PY_DIR
ubconfig.source_dir = source_dir
ubconfig.build_dir = build_dir
ubconfig.result_dir = result_dir
@@ -521,6 +554,22 @@ def setup_requiredtool(item):
if not tool_is_in_path(tool):
pytest.skip('tool "%s" not in $PATH' % tool)
+def setup_singlethread(item):
+ """Process any 'singlethread' marker for a test.
+
+ Skip this test if running in parallel.
+
+ Args:
+ item: The pytest test item.
+
+ Returns:
+ Nothing.
+ """
+ for single in item.iter_markers('singlethread'):
+ worker_id = os.environ.get("PYTEST_XDIST_WORKER")
+ if worker_id and worker_id != 'master':
+ pytest.skip('must run single-threaded')
+
def start_test_section(item):
anchors[item.name] = log.start_section(item.name)
@@ -541,6 +590,7 @@ def pytest_runtest_setup(item):
setup_boardspec(item)
setup_buildconfigspec(item)
setup_requiredtool(item)
+ setup_singlethread(item)
def pytest_runtest_protocol(item, nextitem):
"""pytest hook: Called to execute a test.
diff --git a/test/py/pytest.ini b/test/py/pytest.ini
index e93d010f1f..26d83f83e0 100644
--- a/test/py/pytest.ini
+++ b/test/py/pytest.ini
@@ -11,3 +11,4 @@ markers =
notbuildconfigspec: U-Boot: Describes required disabled Kconfig options.
requiredtool: U-Boot: Required host tools for a test.
slow: U-Boot: Specific test will run slowly.
+ singlethread: Cannot run in parallel
diff --git a/test/py/requirements.txt b/test/py/requirements.txt
index ead92ed8b4..1bf77b59d8 100644
--- a/test/py/requirements.txt
+++ b/test/py/requirements.txt
@@ -2,6 +2,7 @@ atomicwrites==1.4.1
attrs==19.3.0
coverage==4.5.4
extras==1.0.0
+filelock==3.0.12
fixtures==3.0.0
importlib-metadata==0.23
linecache2==1.0.0
@@ -15,6 +16,7 @@ pyelftools==0.27
pygit2==1.9.2
pyparsing==2.4.2
pytest==6.2.5
+pytest-xdist==2.5.0
python-mimeparse==1.6.0
python-subunit==1.3.0
requests==2.25.1
diff --git a/test/py/tests/test_bind.py b/test/py/tests/test_bind.py
index c90c54d266..1376ab5ed2 100644
--- a/test/py/tests/test_bind.py
+++ b/test/py/tests/test_bind.py
@@ -119,6 +119,7 @@ def get_next_line(tree, name):
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_bind')
+@pytest.mark.singlethread
def test_bind_unbind_with_uclass(u_boot_console):
#bind /bind-test
response = u_boot_console.run_command('bind /bind-test simple_bus')
diff --git a/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py b/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
index 75a6e7c962..1bb59d8fcf 100644
--- a/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
+++ b/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
@@ -7,6 +7,7 @@ import pytest
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_efidebug')
@pytest.mark.buildconfigspec('cmd_bootefi_bootmgr')
+@pytest.mark.singlethread
def test_efi_bootmgr(u_boot_console, efi_bootmgr_data):
""" Unit test for UEFI bootmanager
The efidebug command is used to set up UEFI load options.
diff --git a/test/py/tests/test_eficonfig/conftest.py b/test/py/tests/test_eficonfig/conftest.py
new file mode 100644
index 0000000000..f289df0362
--- /dev/null
+++ b/test/py/tests/test_eficonfig/conftest.py
@@ -0,0 +1,40 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+"""Fixture for UEFI eficonfig test
+"""
+
+import os
+import shutil
+from subprocess import check_call
+import pytest
+
+@pytest.fixture(scope='session')
+def efi_eficonfig_data(u_boot_config):
+ """Set up a file system to be used in UEFI "eficonfig" command
+ tests
+
+ Args:
+ u_boot_config -- U-boot configuration.
+
+ Return:
+ A path to disk image to be used for testing
+ """
+ mnt_point = u_boot_config.persistent_data_dir + '/test_efi_eficonfig'
+ image_path = u_boot_config.persistent_data_dir + '/efi_eficonfig.img'
+
+ shutil.rmtree(mnt_point, ignore_errors=True)
+ os.mkdir(mnt_point, mode = 0o755)
+
+ with open(mnt_point + '/initrd-1.img', 'w', encoding = 'ascii') as file:
+ file.write("initrd 1")
+
+ with open(mnt_point + '/initrd-2.img', 'w', encoding = 'ascii') as file:
+ file.write("initrd 2")
+
+ shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/initrddump.efi',
+ mnt_point + '/initrddump.efi')
+
+ check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}',
+ shell=True)
+
+ return image_path
diff --git a/test/py/tests/test_eficonfig/test_eficonfig.py b/test/py/tests/test_eficonfig/test_eficonfig.py
new file mode 100644
index 0000000000..99606d9c4b
--- /dev/null
+++ b/test/py/tests/test_eficonfig/test_eficonfig.py
@@ -0,0 +1,354 @@
+# SPDX-License-Identifier: GPL-2.0+
+""" Unit test for UEFI menu-driven configuration
+"""
+
+import pytest
+import time
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_eficonfig')
+@pytest.mark.buildconfigspec('cmd_bootefi_bootmgr')
+def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
+
+ def send_user_input_and_wait(user_str, expect_str):
+ time.sleep(0.1) # TODO: does not work correctly without sleep
+ u_boot_console.run_command(cmd=user_str, wait_for_prompt=False,
+ wait_for_echo=True, send_nl=False)
+ u_boot_console.run_command(cmd='\x0d', wait_for_prompt=False,
+ wait_for_echo=False, send_nl=False)
+ if expect_str is not None:
+ for i in expect_str:
+ u_boot_console.p.expect([i])
+
+ def press_up_down_enter_and_wait(up_count, down_count, enter, expect_str):
+ # press UP key
+ for i in range(up_count):
+ u_boot_console.run_command(cmd='\x1b\x5b\x41', wait_for_prompt=False,
+ wait_for_echo=False, send_nl=False)
+ # press DOWN key
+ for i in range(down_count):
+ u_boot_console.run_command(cmd='\x1b\x5b\x42', wait_for_prompt=False,
+ wait_for_echo=False, send_nl=False)
+ # press ENTER if requested
+ if enter:
+ u_boot_console.run_command(cmd='\x0d', wait_for_prompt=False,
+ wait_for_echo=False, send_nl=False)
+ # wait expected output
+ if expect_str is not None:
+ for i in expect_str:
+ u_boot_console.p.expect([i])
+
+ def press_escape_key(wait_prompt):
+ u_boot_console.run_command(cmd='\x1b', wait_for_prompt=wait_prompt, wait_for_echo=False, send_nl=False)
+
+ def press_enter_key(wait_prompt):
+ u_boot_console.run_command(cmd='\x0d', wait_for_prompt=wait_prompt,
+ wait_for_echo=False, send_nl=False)
+
+ def check_current_is_maintenance_menu():
+ for i in ('UEFI Maintenance Menu', 'Add Boot Option', 'Edit Boot Option',
+ 'Change Boot Order', 'Delete Boot Option', 'Quit'):
+ u_boot_console.p.expect([i])
+
+ """ Unit test for "eficonfig" command
+ The menu-driven interface is used to set up UEFI load options.
+ The bootefi bootmgr loads initrddump.efi as a payload.
+ The crc32 of the loaded initrd.img is checked
+
+ Args:
+ u_boot_console -- U-Boot console
+ efi__data -- Path to the disk image used for testing.
+ Test disk image has following files.
+ initrd-1.img
+ initrd-2.img
+ initrddump.efi
+
+ """
+
+ # Restart the system to clean the previous state
+ u_boot_console.restart_uboot()
+
+ with u_boot_console.temporary_timeout(500):
+ #
+ # Test Case 1: Check the menu is displayed
+ #
+ u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+ for i in ('UEFI Maintenance Menu', 'Add Boot Option', 'Edit Boot Option',
+ 'Change Boot Order', 'Delete Boot Option', 'Quit'):
+ u_boot_console.p.expect([i])
+ # Select "Add Boot Option"
+ press_enter_key(False)
+ for i in ('Add Boot Option', 'Description:', 'File', 'Initrd File', 'Optional Data',
+ 'Save', 'Quit'):
+ u_boot_console.p.expect([i])
+ press_escape_key(False)
+ check_current_is_maintenance_menu()
+ # return to U-Boot console
+ press_escape_key(True)
+
+ #
+ # Test Case 2: check auto generated media device entry
+ #
+
+ # bind the test disk image for succeeding tests
+ u_boot_console.run_command(cmd = f'host bind 0 {efi_eficonfig_data}')
+
+ u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+
+ # Change the Boot Order
+ press_up_down_enter_and_wait(0, 2, True, 'Quit')
+ for i in ('host 0:1', 'Save', 'Quit'):
+ u_boot_console.p.expect([i])
+ # disable auto generated boot option for succeeding test
+ u_boot_console.run_command(cmd=' ', wait_for_prompt=False,
+ wait_for_echo=False, send_nl=False)
+ # Save the BootOrder
+ press_up_down_enter_and_wait(0, 1, True, None)
+ check_current_is_maintenance_menu()
+
+ #
+ # Test Case 3: Add first Boot Option and load it
+ #
+
+ # Select 'Add Boot Option'
+ press_up_down_enter_and_wait(0, 0, True, 'Quit')
+
+ # Press the enter key to select 'Description:' entry, then enter Description
+ press_up_down_enter_and_wait(0, 0, True, 'enter description:')
+ # Send Description user input, press ENTER key to complete
+ send_user_input_and_wait('test 1', 'Quit')
+
+ # Set EFI image(initrddump.efi)
+ press_up_down_enter_and_wait(0, 1, True, 'Quit')
+ press_up_down_enter_and_wait(0, 0, True, 'host 0:1')
+ # Select 'host 0:1'
+ press_up_down_enter_and_wait(0, 0, True, 'Quit')
+ # Press down key to select "initrddump.efi" entry followed by the enter key
+ press_up_down_enter_and_wait(0, 2, True, 'Quit')
+
+ # Set Initrd file(initrd-1.img)
+ press_up_down_enter_and_wait(0, 2, True, 'Quit')
+ press_up_down_enter_and_wait(0, 0, True, 'host 0:1')
+ # Select 'host 0:1'
+ press_up_down_enter_and_wait(0, 0, True, 'Quit')
+ # Press down key to select "initrd-1.img" entry followed by the enter key
+ press_up_down_enter_and_wait(0, 0, True, 'Quit')
+
+ # Set optional_data
+ press_up_down_enter_and_wait(0, 3, True, 'Optional Data:')
+ # Send Description user input, press ENTER key to complete
+ send_user_input_and_wait('nocolor', None)
+ for i in ('Description: test 1', 'File: host 0:1/initrddump.efi',
+ 'Initrd File: host 0:1/initrd-1.img', 'Optional Data: nocolor', 'Save', 'Quit'):
+ u_boot_console.p.expect([i])
+
+ # Save the Boot Option
+ press_up_down_enter_and_wait(0, 4, True, None)
+ check_current_is_maintenance_menu()
+
+ # Check the newly added Boot Option is handled correctly
+ # Return to U-Boot console
+ press_escape_key(True)
+ u_boot_console.run_command(cmd = 'bootefi bootmgr')
+ response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
+ assert 'crc32: 0x181464af' in response
+ u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
+
+ #
+ # Test Case 4: Add second Boot Option and load it
+ #
+ u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+
+ # Select 'Add Boot Option'
+ press_up_down_enter_and_wait(0, 0, True, 'Quit')
+
+ # Press the enter key to select 'Description:' entry, then enter Description
+ press_up_down_enter_and_wait(0, 0, True, 'enter description:')
+ # Send Description user input, press ENTER key to complete
+ send_user_input_and_wait('test 2', 'Quit')
+
+ # Set EFI image(initrddump.efi)
+ press_up_down_enter_and_wait(0, 1, True, 'Quit')
+ press_up_down_enter_and_wait(0, 0, True, 'host 0:1')
+ # Select 'host 0:1'
+ press_up_down_enter_and_wait(0, 0, True, 'Quit')
+ # Press down key to select "initrddump.efi" entry followed by the enter key
+ press_up_down_enter_and_wait(0, 2, True, 'Quit')
+
+ # Set Initrd file(initrd-2.img)
+ press_up_down_enter_and_wait(0, 2, True, 'Quit')
+ press_up_down_enter_and_wait(0, 0, True, 'host 0:1')
+ # Select 'host 0:1'
+ press_up_down_enter_and_wait(0, 0, True, 'Quit')
+ # Press down key to select "initrd-2.img" entry followed by the enter key
+ press_up_down_enter_and_wait(0, 1, True, 'Quit')
+
+ # Set optional_data
+ press_up_down_enter_and_wait(0, 3, True, 'Optional Data:')
+ # Send Description user input, press ENTER key to complete
+ send_user_input_and_wait('nocolor', None)
+ for i in ('Description: test 2', 'File: host 0:1/initrddump.efi',
+ 'Initrd File: host 0:1/initrd-2.img', 'Optional Data: nocolor', 'Save', 'Quit'):
+ u_boot_console.p.expect([i])
+
+ # Save the Boot Option
+ press_up_down_enter_and_wait(0, 4, True, 'Quit')
+
+ # Change the Boot Order
+ press_up_down_enter_and_wait(0, 2, True, 'Quit')
+ press_up_down_enter_and_wait(0, 1, False, 'Quit')
+ # move 'test 1' to the second entry
+ u_boot_console.run_command(cmd='+', wait_for_prompt=False,
+ wait_for_echo=False, send_nl=False)
+ for i in ('test 2', 'test 1', 'host 0:1', 'Save', 'Quit'):
+ u_boot_console.p.expect([i])
+ # Save the BootOrder
+ press_up_down_enter_and_wait(0, 3, True, None)
+ check_current_is_maintenance_menu()
+
+ # Check the newly added Boot Option is handled correctly
+ # Return to U-Boot console
+ press_escape_key(True)
+ u_boot_console.run_command(cmd = 'bootefi bootmgr')
+ response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
+ assert 'crc32: 0x811d3515' in response
+ u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
+
+ #
+ # Test Case 5: Change BootOrder and load it
+ #
+ u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+
+ # Change the Boot Order
+ press_up_down_enter_and_wait(0, 2, True, None)
+ # Check the curren BootOrder
+ for i in ('test 2', 'test 1', 'host 0:1', 'Save', 'Quit'):
+ u_boot_console.p.expect([i])
+ # move 'test 2' to the second entry
+ u_boot_console.run_command(cmd='-', wait_for_prompt=False,
+ wait_for_echo=False, send_nl=False)
+ for i in ('test 1', 'test 2', 'host 0:1', 'Save', 'Quit'):
+ u_boot_console.p.expect([i])
+ # Save the BootOrder
+ press_up_down_enter_and_wait(0, 2, True, None)
+ check_current_is_maintenance_menu()
+
+ # Return to U-Boot console
+ press_escape_key(True)
+ u_boot_console.run_command(cmd = 'bootefi bootmgr')
+ response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
+ assert 'crc32: 0x181464af' in response
+ u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
+
+ #
+ # Test Case 6: Delete Boot Option(label:test 2)
+ #
+ u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+
+ # Select 'Delete Boot Option'
+ press_up_down_enter_and_wait(0, 3, True, None)
+ # Check the current BootOrder
+ for i in ('test 1', 'test 2', 'Quit'):
+ u_boot_console.p.expect([i])
+
+ # Delete 'test 2'
+ press_up_down_enter_and_wait(0, 1, True, None)
+ for i in ('test 1', 'Quit'):
+ u_boot_console.p.expect([i])
+ press_escape_key(False)
+ check_current_is_maintenance_menu()
+ # Return to U-Boot console
+ press_escape_key(True)
+
+ #
+ # Test Case 7: Edit Boot Option
+ #
+ u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+ # Select 'Edit Boot Option'
+ press_up_down_enter_and_wait(0, 1, True, None)
+ # Check the curren BootOrder
+ for i in ('test 1', 'Quit'):
+ u_boot_console.p.expect([i])
+ press_up_down_enter_and_wait(0, 0, True, None)
+ for i in ('Description: test 1', 'File: host 0:1/initrddump.efi',
+ 'Initrd File: host 0:1/initrd-1.img', 'Optional Data: nocolor', 'Save', 'Quit'):
+ u_boot_console.p.expect([i])
+
+ # Press the enter key to select 'Description:' entry, then enter Description
+ press_up_down_enter_and_wait(0, 0, True, 'enter description:')
+ # Send Description user input, press ENTER key to complete
+ send_user_input_and_wait('test 3', 'Quit')
+
+ # Set EFI image(initrddump.efi)
+ press_up_down_enter_and_wait(0, 1, True, 'Quit')
+ press_up_down_enter_and_wait(0, 0, True, 'host 0:1')
+ # Select 'host 0:1'
+ press_up_down_enter_and_wait(0, 0, True, 'Quit')
+ # Press down key to select "initrddump.efi" entry followed by the enter key
+ press_up_down_enter_and_wait(0, 2, True, 'Quit')
+
+ # Set Initrd file(initrd-2.img)
+ press_up_down_enter_and_wait(0, 2, True, 'Quit')
+ press_up_down_enter_and_wait(0, 0, True, 'host 0:1')
+ # Select 'host 0:1'
+ press_up_down_enter_and_wait(0, 0, True, 'Quit')
+ # Press down key to select "initrd-1.img" entry followed by the enter key
+ press_up_down_enter_and_wait(0, 1, True, 'Quit')
+
+ # Set optional_data
+ press_up_down_enter_and_wait(0, 3, True, 'Optional Data:')
+ # Send Description user input, press ENTER key to complete
+ send_user_input_and_wait('', None)
+ for i in ('Description: test 3', 'File: host 0:1/initrddump.efi',
+ 'Initrd File: host 0:1/initrd-2.img', 'Optional Data:', 'Save', 'Quit'):
+ u_boot_console.p.expect([i])
+
+ # Save the Boot Option
+ press_up_down_enter_and_wait(0, 4, True, 'Quit')
+ press_escape_key(False)
+ check_current_is_maintenance_menu()
+
+ # Check the updated Boot Option is handled correctly
+ # Return to U-Boot console
+ press_escape_key(True)
+ u_boot_console.run_command(cmd = 'bootefi bootmgr')
+ response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
+ assert 'crc32: 0x811d3515' in response
+ u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
+
+ #
+ # Test Case 8: Delete Boot Option(label:test 3)
+ #
+ u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+
+ # Select 'Delete Boot Option'
+ press_up_down_enter_and_wait(0, 3, True, None)
+ # Check the curren BootOrder
+ for i in ('test 3', 'Quit'):
+ u_boot_console.p.expect([i])
+
+ # Delete 'test 3'
+ press_up_down_enter_and_wait(0, 0, True, 'Quit')
+ press_escape_key(False)
+ check_current_is_maintenance_menu()
+ # Return to U-Boot console
+ press_escape_key(True)
+
+ # remove the host device
+ u_boot_console.run_command(cmd = f'host bind -r 0')
+
+ #
+ # Test Case 9: No block device found
+ #
+ u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+
+ # Select 'Add Boot Option'
+ press_up_down_enter_and_wait(0, 0, True, 'Quit')
+
+ # Set EFI image
+ press_up_down_enter_and_wait(0, 1, True, 'Quit')
+ press_up_down_enter_and_wait(0, 0, True, 'No block device found!')
+ press_escape_key(False)
+ check_current_is_maintenance_menu()
+ # Return to U-Boot console
+ press_escape_key(True)
diff --git a/test/py/tests/test_fit_ecdsa.py b/test/py/tests/test_fit_ecdsa.py
index 87b6081222..cc6c0c4dc4 100644
--- a/test/py/tests/test_fit_ecdsa.py
+++ b/test/py/tests/test_fit_ecdsa.py
@@ -10,6 +10,7 @@ signature is then extracted, and verified against pyCryptodome.
This test doesn't run the sandbox. It only checks the host tool 'mkimage'
"""
+import os
import pytest
import u_boot_utils as util
from Cryptodome.Hash import SHA256
@@ -84,7 +85,8 @@ def test_fit_ecdsa(u_boot_console):
cons = u_boot_console
mkimage = cons.config.build_dir + '/tools/mkimage'
datadir = cons.config.source_dir + '/test/py/tests/vboot/'
- tempdir = cons.config.result_dir
+ tempdir = os.path.join(cons.config.result_dir, 'ecdsa')
+ os.makedirs(tempdir, exist_ok=True)
key_file = f'{tempdir}/ecdsa-test-key.pem'
fit_file = f'{tempdir}/test.fit'
dtc('sandbox-kernel.dts')
diff --git a/test/py/tests/test_fit_hashes.py b/test/py/tests/test_fit_hashes.py
index e228ea96d3..4891e77ca2 100644
--- a/test/py/tests/test_fit_hashes.py
+++ b/test/py/tests/test_fit_hashes.py
@@ -10,6 +10,7 @@ output of a fixed data block with known good hashes.
This test doesn't run the sandbox. It only checks the host tool 'mkimage'
"""
+import os
import pytest
import u_boot_utils as util
@@ -93,7 +94,9 @@ def test_mkimage_hashes(u_boot_console):
cons = u_boot_console
mkimage = cons.config.build_dir + '/tools/mkimage'
datadir = cons.config.source_dir + '/test/py/tests/vboot/'
- tempdir = cons.config.result_dir
+ tempdir = os.path.join(cons.config.result_dir, 'hashes')
+ os.makedirs(tempdir, exist_ok=True)
+
fit_file = f'{tempdir}/test.fit'
dtc('sandbox-kernel.dts')
diff --git a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py
index 9eb00d6888..527a556ed8 100644
--- a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py
+++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py
@@ -105,6 +105,7 @@ def sqfs_run_all_ls_tests(u_boot_console):
@pytest.mark.buildconfigspec('cmd_squashfs')
@pytest.mark.buildconfigspec('fs_squashfs')
@pytest.mark.requiredtool('mksquashfs')
+@pytest.mark.singlethread
def test_sqfs_ls(u_boot_console):
""" Executes the sqfsls test suite.
diff --git a/test/py/tests/test_gpio.py b/test/py/tests/test_gpio.py
index fa0af5f82b..0af186f236 100644
--- a/test/py/tests/test_gpio.py
+++ b/test/py/tests/test_gpio.py
@@ -51,6 +51,7 @@ def test_gpio_exit_statuses(u_boot_console):
def test_gpio_read(u_boot_console):
"""Test that gpio read correctly sets the variable to the value of a gpio pin."""
+ u_boot_console.run_command('gpio clear 0')
response = u_boot_console.run_command('gpio read var 0; echo val:$var,rc:$?')
expected_response = 'val:0,rc:0'
assert(expected_response in response)
diff --git a/test/py/tests/test_gpt.py b/test/py/tests/test_gpt.py
index f707d9f253..cb44e1d789 100644
--- a/test/py/tests/test_gpt.py
+++ b/test/py/tests/test_gpt.py
@@ -13,6 +13,9 @@ These tests rely on a 4 MB disk image, which is automatically created by
the test.
"""
+# Mark all tests here as slow
+pytestmark = pytest.mark.slow
+
class GptTestDiskImage(object):
"""Disk Image used by the GPT tests."""
diff --git a/test/py/tests/test_pinmux.py b/test/py/tests/test_pinmux.py
index b3ae2ab024..794994e12d 100644
--- a/test/py/tests/test_pinmux.py
+++ b/test/py/tests/test_pinmux.py
@@ -68,6 +68,7 @@ def test_pinmux_dev(u_boot_console):
def test_pinmux_status(u_boot_console):
"""Test that 'pinmux status' displays selected pincontroller's pin
muxing descriptions."""
+ u_boot_console.run_command('pinmux dev pinctrl')
output = u_boot_console.run_command('pinmux status')
assert (not 'pinctrl-gpio:' in output)
diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index 35fb393c1f..9d42390373 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -114,6 +114,15 @@ def test_ut_dm_init(u_boot_console):
with open(fn, 'wb') as fh:
fh.write(data)
+ # Create a file with a single partition
+ fn = u_boot_console.config.source_dir + '/scsi.img'
+ if not os.path.exists(fn):
+ data = b'\x00' * (2 * 1024 * 1024)
+ with open(fn, 'wb') as fh:
+ fh.write(data)
+ u_boot_utils.run_and_log(
+ u_boot_console, f'sfdisk {fn}', stdin=b'type=83')
+
@pytest.mark.buildconfigspec('cmd_bootflow')
def test_ut_dm_init_bootstd(u_boot_console):
"""Initialise data for bootflow tests"""
diff --git a/test/py/tests/test_vboot.py b/test/py/tests/test_vboot.py
index 040147d88b..e3e7ca4b21 100644
--- a/test/py/tests/test_vboot.py
+++ b/test/py/tests/test_vboot.py
@@ -42,7 +42,7 @@ import vboot_evil
# Only run the full suite on a few combinations, since it doesn't add any more
# test coverage.
-TESTDATA = [
+TESTDATA_IN = [
['sha1-basic', 'sha1', '', None, False, True, False, False],
['sha1-pad', 'sha1', '', '-E -p 0x10000', False, False, False, False],
['sha1-pss', 'sha1', '-pss', None, False, False, False, False],
@@ -60,6 +60,10 @@ TESTDATA = [
['sha256-global-sign-pss', 'sha256', '-pss', '', False, False, False, True],
]
+# Mark all but the first test as slow, so they are not run with '-k not slow'
+TESTDATA = [TESTDATA_IN[0]]
+TESTDATA += [pytest.param(*v, marks=pytest.mark.slow) for v in TESTDATA_IN[1:]]
+
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('fit_signature')
@pytest.mark.requiredtool('dtc')
diff --git a/test/run b/test/run
index 869406cd8d..810b47e08d 100755
--- a/test/run
+++ b/test/run
@@ -13,25 +13,47 @@ run_test() {
[ $? -ne 0 ] && failures=$((failures+1))
}
-# SKip slow tests if requested
-[ "$1" == "quick" ] && mark_expr="not slow"
-[ "$1" == "quick" ] && skip=--skip-net-tests
+# Select test attributes
+ut_mark_expr=test_ut
+if [ "$1" = "quick" ]; then
+ mark_expr="not slow"
+ ut_mark_expr="test_ut and not slow"
+ skip=--skip-net-tests
+fi
+
[ "$1" == "tools" ] && tools_only=y
+if [ "$1" = "parallel" ]; then
+ if ! echo 'import xdist' | python3 2>/dev/null; then
+ echo "Please install python3-pytest-xdist - see doc/develop/py_testing.rst"
+ exit 1
+ fi
+ jobs="$(($(nproc) > 16 ? 16 : $(nproc)))"
+ para="-n${jobs} -q"
+ prompt="Building and..."
+ skip=--skip-net-tests
+ mark_expr="not slow and not bootstd and not spi_flash"
+ ut_mark_expr="test_ut and not slow and not bootstd and not spi_flash"
+ echo "Note: test log is garbled with parallel tests"
+fi
+
failures=0
if [ -z "$tools_only" ]; then
# Run all tests that the standard sandbox build can support
- run_test "sandbox" ./test/py/test.py --bd sandbox --build \
- -m "${mark_expr}"
+ echo "${prompt}"
+ run_test "sandbox" ./test/py/test.py --bd sandbox --build ${para} \
+ -k "${mark_expr}"
fi
# Run tests which require sandbox_spl
-run_test "sandbox_spl" ./test/py/test.py --bd sandbox_spl --build \
+echo "${prompt}"
+run_test "sandbox_spl" ./test/py/test.py --bd sandbox_spl --build ${para} \
-k 'test_ofplatdata or test_handoff or test_spl'
# Run the sane tests with sandbox_noinst (i.e. without OF_PLATDATA_INST)
-run_test "sandbox_spl" ./test/py/test.py --bd sandbox_noinst --build \
+echo "${prompt}"
+run_test "sandbox_spl" ./test/py/test.py --bd sandbox_noinst --build ${para} \
-k 'test_ofplatdata or test_handoff or test_spl'
if [ -z "$tools_only" ]; then
@@ -39,8 +61,9 @@ if [ -z "$tools_only" ]; then
# build which does not enable CONFIG_OF_LIVE for the live device tree, so we can
# check that functionality is the same. The standard sandbox build (above) uses
# CONFIG_OF_LIVE.
+ echo "${prompt}"
run_test "sandbox_flattree" ./test/py/test.py --bd sandbox_flattree \
- --build -k test_ut
+ ${para} --build -k "${ut_mark_expr}"
fi
# Set up a path to dtc (device-tree compiler) and libfdt.py, a library it
@@ -61,10 +84,14 @@ run_test "dtoc" ./tools/dtoc/dtoc -t
# This needs you to set up Python test coverage tools.
# To enable Python test coverage on Debian-type distributions (e.g. Ubuntu):
# $ sudo apt-get install python-pytest python-coverage
-export PATH=$PATH:${TOOLS_DIR}
-run_test "binman code coverage" ./tools/binman/binman test -T
-run_test "dtoc code coverage" ./tools/dtoc/dtoc -T
-run_test "fdt code coverage" ./tools/dtoc/test_fdt -T
+
+# Code-coverage tests cannot run in parallel, so skip them in that case
+if [ -z "${para}" ]; then
+ export PATH=$PATH:${TOOLS_DIR}
+ run_test "binman code coverage" ./tools/binman/binman test -T
+ run_test "dtoc code coverage" ./tools/dtoc/dtoc -T
+ run_test "fdt code coverage" ./tools/dtoc/test_fdt -T
+fi
if [ $failures == 0 ]; then
echo "Tests passed!"
diff --git a/test/test-main.c b/test/test-main.c
index 31837e57a8..ae34002a3d 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -6,6 +6,7 @@
#include <common.h>
#include <console.h>
+#include <cyclic.h>
#include <dm.h>
#include <event.h>
#include <dm/root.h>
@@ -220,6 +221,7 @@ static int dm_test_restore(struct device_node *of_root)
static int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
{
ut_assertok(event_init());
+ ut_assertok(cyclic_init());
if (test->flags & UT_TESTF_DM)
ut_assertok(dm_test_pre_run(uts));
@@ -265,6 +267,7 @@ static int test_post_run(struct unit_test_state *uts, struct unit_test *test)
ut_unsilence_console(uts);
if (test->flags & UT_TESTF_DM)
ut_assertok(dm_test_post_run(uts));
+ ut_assertok(cyclic_uninit());
ut_assertok(event_uninit());
return 0;
@@ -390,11 +393,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 +417,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 +442,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)