summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/boot/bootdev.c19
-rw-r--r--test/boot/bootstd_common.c6
-rw-r--r--test/boot/bootstd_common.h8
-rw-r--r--test/cmd/mbr.c172
-rw-r--r--test/py/tests/test_ut.py94
-rw-r--r--test/test-main.c38
6 files changed, 194 insertions, 143 deletions
diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c
index 23ebc61ff52..c635d06ec25 100644
--- a/test/boot/bootdev.c
+++ b/test/boot/bootdev.c
@@ -16,13 +16,6 @@
#include <test/ut.h>
#include "bootstd_common.h"
-/* Allow reseting the USB-started flag */
-#if defined(CONFIG_USB_HOST) || defined(CONFIG_USB_GADGET)
-extern bool usb_started;
-#else
-#include <usb.h>
-#endif
-
/* Check 'bootdev list' command */
static int bootdev_test_cmd_list(struct unit_test_state *uts)
{
@@ -197,7 +190,7 @@ static int bootdev_test_order(struct unit_test_state *uts)
test_set_skip_delays(true);
/* Start up USB which gives us three additional bootdevs */
- usb_started = false;
+ bootstd_reset_usb();
ut_assertok(run_command("usb start", 0));
/*
@@ -313,7 +306,7 @@ static int bootdev_test_prio(struct unit_test_state *uts)
test_set_eth_enable(false);
/* Start up USB which gives us three additional bootdevs */
- usb_started = false;
+ bootstd_reset_usb();
ut_assertok(run_command("usb start", 0));
ut_assertok(bootstd_test_drop_bootdev_order(uts));
@@ -352,7 +345,7 @@ static int bootdev_test_hunter(struct unit_test_state *uts)
{
struct bootstd_priv *std;
- usb_started = false;
+ bootstd_reset_usb();
test_set_skip_delays(true);
/* get access to the used hunters */
@@ -392,7 +385,7 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts)
struct bootstd_priv *std;
test_set_skip_delays(true);
- usb_started = false;
+ bootstd_reset_usb();
/* get access to the used hunters */
ut_assertok(bootstd_get_priv(&std));
@@ -520,7 +513,7 @@ BOOTSTD_TEST(bootdev_test_bootable, UTF_DM | UTF_SCAN_FDT);
/* Check hunting for bootdev of a particular priority */
static int bootdev_test_hunt_prio(struct unit_test_state *uts)
{
- usb_started = false;
+ bootstd_reset_usb();
test_set_skip_delays(true);
ut_assertok(bootdev_hunt_prio(BOOTDEVP_4_SCAN_FAST, false));
@@ -548,7 +541,7 @@ static int bootdev_test_hunt_label(struct unit_test_state *uts)
struct bootstd_priv *std;
int mflags;
- usb_started = false;
+ bootstd_reset_usb();
/* get access to the used hunters */
ut_assertok(bootstd_get_priv(&std));
diff --git a/test/boot/bootstd_common.c b/test/boot/bootstd_common.c
index e50539500a0..ff8ed2303b3 100644
--- a/test/boot/bootstd_common.c
+++ b/test/boot/bootstd_common.c
@@ -11,6 +11,7 @@
#include <dm.h>
#include <memalign.h>
#include <mmc.h>
+#include <usb.h>
#include <linux/log2.h>
#include <test/suites.h>
#include <test/ut.h>
@@ -88,6 +89,11 @@ int bootstd_test_check_mmc_hunter(struct unit_test_state *uts)
return 0;
}
+void bootstd_reset_usb(void)
+{
+ usb_started = false;
+}
+
int do_ut_bootstd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
struct unit_test *tests = UNIT_TEST_SUITE_START(bootstd_test);
diff --git a/test/boot/bootstd_common.h b/test/boot/bootstd_common.h
index 4a126e43ff4..e29036c897c 100644
--- a/test/boot/bootstd_common.h
+++ b/test/boot/bootstd_common.h
@@ -53,4 +53,12 @@ int bootstd_setup_for_tests(void);
*/
int bootstd_test_check_mmc_hunter(struct unit_test_state *uts);
+/**
+ * bootstd_reset_usb() - Reset the USB subsystem
+ *
+ * Resets USB so that it can be started (and scanning) again. This is useful in
+ * tests which need to use USB.
+ */
+void bootstd_reset_usb(void);
+
#endif
diff --git a/test/cmd/mbr.c b/test/cmd/mbr.c
index e1a9cdffb04..b14137e589a 100644
--- a/test/cmd/mbr.c
+++ b/test/cmd/mbr.c
@@ -14,10 +14,14 @@
#include <asm/global_data.h>
#include <dm/device-internal.h>
#include <dm/lists.h>
+#include <linux/sizes.h>
#include <test/suites.h>
#include <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
+
+#define BLKSZ SZ_512 /* block size */
+
/*
* Requirements for running test manually:
* mmc6.img - File size needs to be at least 12 MiB
@@ -50,7 +54,7 @@ static char * mbr_parts_tail = "'";
000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
*/
-static unsigned mbr_cmp_start = 0x1B8;
+static unsigned int mbr_cmp_start = 0x1b8;
static unsigned mbr_cmp_size = 0x48;
static unsigned char mbr_parts_ref_p1[] = {
0x78, 0x56, 0x34, 0x12, 0x00, 0x00, 0x80, 0x05,
@@ -228,9 +232,11 @@ static unsigned build_mbr_parts(char *buf, size_t buf_size, unsigned num_parts)
static int mbr_test_run(struct unit_test_state *uts)
{
struct blk_desc *mmc_dev_desc;
- unsigned char mbr_wbuf[512], ebr_wbuf[512], rbuf[512];
+ unsigned char *mbr_wbuf, *ebr_wbuf, *rbuf;
char mbr_parts_buf[256];
- ulong mbr_wa, ebr_wa, ra, ebr_blk, mbr_parts_max;
+ ulong addr = 0x1000; /* start address for buffers */
+ ulong mbr_wa = addr, ebr_wa = addr + BLKSZ, ra = addr + BLKSZ * 2;
+ ulong ebr_blk, mbr_parts_max;
struct udevice *dev;
ofnode root, node;
@@ -254,10 +260,10 @@ static int mbr_test_run(struct unit_test_state *uts)
ut_assertf(sizeof(mbr_parts_buf) >= mbr_parts_max, "Buffer avail: %ld; buffer req: %ld\n",
sizeof(mbr_parts_buf), mbr_parts_max);
- mbr_wa = map_to_sysmem(mbr_wbuf);
- ebr_wa = map_to_sysmem(ebr_wbuf);
- ra = map_to_sysmem(rbuf);
- ebr_blk = (ulong)0xB00000 / 0x200;
+ mbr_wbuf = map_sysmem(mbr_wa, BLKSZ);
+ ebr_wbuf = map_sysmem(ebr_wa, BLKSZ);
+ rbuf = map_sysmem(ra, BLKSZ);
+ ebr_blk = (ulong)0xb00000 / BLKSZ;
/* Make sure mmc6 exists */
ut_asserteq(6, blk_get_device_by_str("mmc", "6", &mmc_dev_desc));
@@ -267,28 +273,29 @@ static int mbr_test_run(struct unit_test_state *uts)
ut_assert_console_end();
/* Make sure mmc6 is 12+ MiB in size */
- ut_assertok(run_commandf("mmc read 0x%lx 0x%lx 1", ra, (ulong)0xBFFE00 / 0x200));
+ ut_assertok(run_commandf("mmc read %lx %lx 1", ra,
+ (ulong)0xbffe00 / BLKSZ));
/* Test one MBR partition */
init_write_buffers(mbr_wbuf, sizeof(mbr_wbuf), ebr_wbuf, sizeof(ebr_wbuf), __LINE__);
ut_assertok(build_mbr_parts(mbr_parts_buf, sizeof(mbr_parts_buf), 1));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0 1", mbr_wa));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
- ut_assertok(memcmp(mbr_wbuf, rbuf, 512));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0x%lx 1", ebr_wa, ebr_blk));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
+ ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
+ ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ));
+ ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
ut_assertok(run_commandf("mbr write mmc 6"));
ut_assert_nextlinen("MMC read: dev # 6");
ut_assert_nextline("MBR: write success!");
ut_assertok(run_commandf("mbr verify mmc 6"));
ut_assert_nextline("MBR: verify success!");
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assert_console_end();
/*
000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....|
@@ -297,33 +304,33 @@ static int mbr_test_run(struct unit_test_state *uts)
000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
for (unsigned i = 0; i < mbr_cmp_size; i++) {
ut_assertf(rbuf[mbr_cmp_start + i] == mbr_parts_ref_p1[i],
- "1P MBR+0x%04X: expected 0x%02X, actual: 0x%02X\n",
+ "1P MBR+0x%04X: expected %#02X, actual: %#02X\n",
mbr_cmp_start + i, mbr_parts_ref_p1[i], rbuf[mbr_cmp_start + i]);
}
/* Test two MBR partitions */
init_write_buffers(mbr_wbuf, sizeof(mbr_wbuf), ebr_wbuf, sizeof(ebr_wbuf), __LINE__);
ut_assertok(build_mbr_parts(mbr_parts_buf, sizeof(mbr_parts_buf), 2));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0 1", mbr_wa));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
- ut_assertok(memcmp(mbr_wbuf, rbuf, 512));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0x%lx 1", ebr_wa, ebr_blk));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
+ ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
+ ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ));
+ ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
ut_assertok(run_commandf("mbr write mmc 6"));
ut_assert_nextline("MBR: write success!");
ut_assertok(run_commandf("mbr verify mmc 6"));
ut_assert_nextline("MBR: verify success!");
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assert_console_end();
/*
000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....|
@@ -332,33 +339,33 @@ static int mbr_test_run(struct unit_test_state *uts)
000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
for (unsigned i = 0; i < mbr_cmp_size; i++) {
ut_assertf(rbuf[mbr_cmp_start + i] == mbr_parts_ref_p2[i],
- "2P MBR+0x%04X: expected 0x%02X, actual: 0x%02X\n",
+ "2P MBR+0x%04X: expected %#02X, actual: %#02X\n",
mbr_cmp_start + i, mbr_parts_ref_p2[i], rbuf[mbr_cmp_start + i]);
}
/* Test three MBR partitions */
init_write_buffers(mbr_wbuf, sizeof(mbr_wbuf), ebr_wbuf, sizeof(ebr_wbuf), __LINE__);
ut_assertok(build_mbr_parts(mbr_parts_buf, sizeof(mbr_parts_buf), 3));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0 1", mbr_wa));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
- ut_assertok(memcmp(mbr_wbuf, rbuf, 512));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0x%lx 1", ebr_wa, ebr_blk));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
+ ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
+ ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ));
+ ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
ut_assertok(run_commandf("mbr write mmc 6"));
ut_assert_nextline("MBR: write success!");
ut_assertok(run_commandf("mbr verify mmc 6"));
ut_assert_nextline("MBR: verify success!");
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assert_console_end();
/*
000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....|
@@ -367,33 +374,33 @@ static int mbr_test_run(struct unit_test_state *uts)
000001e0 06 01 0e 66 25 01 00 50 00 00 00 08 00 00 00 00 |...f%..P........|
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
for (unsigned i = 0; i < mbr_cmp_size; i++) {
ut_assertf(rbuf[mbr_cmp_start + i] == mbr_parts_ref_p3[i],
- "3P MBR+0x%04X: expected 0x%02X, actual: 0x%02X\n",
+ "3P MBR+0x%04X: expected %#02X, actual: %#02X\n",
mbr_cmp_start + i, mbr_parts_ref_p3[i], rbuf[mbr_cmp_start + i]);
}
/* Test four MBR partitions */
init_write_buffers(mbr_wbuf, sizeof(mbr_wbuf), ebr_wbuf, sizeof(ebr_wbuf), __LINE__);
ut_assertok(build_mbr_parts(mbr_parts_buf, sizeof(mbr_parts_buf), 4));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0 1", mbr_wa));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
- ut_assertok(memcmp(mbr_wbuf, rbuf, 512));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0x%lx 1", ebr_wa, ebr_blk));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
+ ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
+ ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ));
+ ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
ut_assertok(run_commandf("mbr write mmc 6"));
ut_assert_nextline("MBR: write success!");
ut_assertok(run_commandf("mbr verify mmc 6"));
ut_assert_nextline("MBR: verify success!");
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assert_console_end();
/*
000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....|
@@ -402,25 +409,25 @@ static int mbr_test_run(struct unit_test_state *uts)
000001e0 06 01 0e 66 25 01 00 50 00 00 00 08 00 00 00 66 |...f%..P.......f|
000001f0 26 01 0e 87 06 01 00 58 00 00 00 08 00 00 55 aa |&......X......U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
for (unsigned i = 0; i < mbr_cmp_size; i++) {
ut_assertf(rbuf[mbr_cmp_start + i] == mbr_parts_ref_p4[i],
- "4P MBR+0x%04X: expected 0x%02X, actual: 0x%02X\n",
+ "4P MBR+0x%04X: expected %#02X, actual: %#02X\n",
mbr_cmp_start + i, mbr_parts_ref_p4[i], rbuf[mbr_cmp_start + i]);
}
/* Test five MBR partitions */
init_write_buffers(mbr_wbuf, sizeof(mbr_wbuf), ebr_wbuf, sizeof(ebr_wbuf), __LINE__);
ut_assertok(build_mbr_parts(mbr_parts_buf, sizeof(mbr_parts_buf), 5));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0 1", mbr_wa));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
- ut_assertok(memcmp(mbr_wbuf, rbuf, 512));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0x%lx 1", ebr_wa, ebr_blk));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
+ ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
+ ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ));
+ ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
ut_assertf(0 == run_commandf("mbr write mmc 6"), "Invalid partitions string: %s\n", mbr_parts_buf);
ut_assert_nextline("MBR: write success!");
@@ -434,11 +441,11 @@ static int mbr_test_run(struct unit_test_state *uts)
000001e0 06 01 0e 66 25 01 00 50 00 00 00 08 00 00 00 66 |...f%..P.......f|
000001f0 26 01 05 a7 26 01 00 58 00 00 00 10 00 00 55 aa |&...&..X......U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
for (unsigned i = 0; i < mbr_cmp_size; i++) {
ut_assertf(rbuf[mbr_cmp_start + i] == mbr_parts_ref_p5[i],
- "5P MBR+0x%04X: expected 0x%02X, actual: 0x%02X\n",
+ "5P MBR+0x%04X: expected %#02X, actual: %#02X\n",
mbr_cmp_start + i, mbr_parts_ref_p5[i], rbuf[mbr_cmp_start + i]);
}
/*
@@ -448,13 +455,16 @@ static int mbr_test_run(struct unit_test_state *uts)
00b001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00b001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
for (unsigned i = 0; i < ebr_cmp_size; i++) {
ut_assertf(rbuf[ebr_cmp_start + i] == ebr_parts_ref_p5[i],
- "5P EBR+0x%04X: expected 0x%02X, actual: 0x%02X\n",
+ "5P EBR+0x%04X: expected %#02X, actual: %#02X\n",
ebr_cmp_start + i, ebr_parts_ref_p5[i], rbuf[ebr_cmp_start + i]);
}
+ unmap_sysmem(mbr_wbuf);
+ unmap_sysmem(ebr_wbuf);
+ unmap_sysmem(rbuf);
return 0;
}
@@ -469,9 +479,3 @@ int do_ut_mbr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
return cmd_ut_category("mbr", "mbr_test_", tests, n_ents, argc, argv);
}
-
-static int dm_test_cmd_mbr(struct unit_test_state *uts)
-{
- return mbr_test_run(uts);
-}
-DM_TEST(dm_test_cmd_mbr, UTF_SCAN_FDT | UTF_CONSOLE);
diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index 05e15830590..39aa1035e34 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -1,6 +1,12 @@
# SPDX-License-Identifier: GPL-2.0
-# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
+"""
+Unit-test runner
+
+Provides a test_ut() function which is used by conftest.py to run each unit
+test one at a time, as well setting up some files needed by the tests.
+# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
+"""
import collections
import getpass
import gzip
@@ -44,8 +50,8 @@ def setup_image(cons, mmc_dev, part_type, second_part=False):
if second_part:
spec += '\ntype=c'
- u_boot_utils.run_and_log(cons, 'qemu-img create %s 20M' % fname)
- u_boot_utils.run_and_log(cons, 'sudo sfdisk %s' % fname,
+ u_boot_utils.run_and_log(cons, f'qemu-img create {fname} 20M')
+ u_boot_utils.run_and_log(cons, f'sudo sfdisk {fname}',
stdin=spec.encode('utf-8'))
return fname, mnt
@@ -61,13 +67,13 @@ def mount_image(cons, fname, mnt, fstype):
Returns:
str: Name of loop device used
"""
- out = u_boot_utils.run_and_log(cons, 'sudo losetup --show -f -P %s' % fname)
+ out = u_boot_utils.run_and_log(cons, f'sudo losetup --show -f -P {fname}')
loop = out.strip()
part = f'{loop}p1'
u_boot_utils.run_and_log(cons, f'sudo mkfs.{fstype} {part}')
opts = ''
if fstype == 'vfat':
- opts += f' -o uid={os.getuid()},gid={os.getgid()}'
+ opts += f' -o uid={os.getuid()},gid={os.getgid()}'
u_boot_utils.run_and_log(cons, f'sudo mount -o loop {part} {mnt}{opts}')
u_boot_utils.run_and_log(cons, f'sudo chown {getpass.getuser()} {mnt}')
return loop
@@ -82,9 +88,7 @@ def copy_prepared_image(cons, mmc_dev, fname):
"""
infname = os.path.join(cons.config.source_dir,
f'test/py/tests/bootstd/mmc{mmc_dev}.img.xz')
- u_boot_utils.run_and_log(
- cons,
- ['sh', '-c', 'xz -dc %s >%s' % (infname, fname)])
+ u_boot_utils.run_and_log(cons, ['sh', '-c', f'xz -dc {infname} >{fname}'])
def setup_bootmenu_image(cons):
"""Create a 20MB disk image with a single ext4 partition
@@ -101,9 +105,6 @@ def setup_bootmenu_image(cons):
loop = mount_image(cons, fname, mnt, 'ext4')
mounted = True
- vmlinux = 'Image'
- initrd = 'uInitrd'
- dtbdir = 'dtb'
script = '''# DO NOT EDIT THIS FILE
#
# Please edit /boot/armbianEnv.txt to set supported parameters
@@ -177,12 +178,12 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}
# Recompile with:
# mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
-''' % (mmc_dev)
+'''
bootdir = os.path.join(mnt, 'boot')
mkdir_cond(bootdir)
cmd_fname = os.path.join(bootdir, 'boot.cmd')
scr_fname = os.path.join(bootdir, 'boot.scr')
- with open(cmd_fname, 'w') as outf:
+ with open(cmd_fname, 'w', encoding='ascii') as outf:
print(script, file=outf)
infname = os.path.join(cons.config.source_dir,
@@ -212,13 +213,12 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}
complete = True
except ValueError as exc:
- print('Falled to create image, failing back to prepared copy: %s',
- str(exc))
+ print(f'Falled to create image, failing back to prepared copy: {exc}')
finally:
if mounted:
- u_boot_utils.run_and_log(cons, 'sudo umount --lazy %s' % mnt)
+ u_boot_utils.run_and_log(cons, f'sudo umount --lazy {mnt}')
if loop:
- u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop)
+ u_boot_utils.run_and_log(cons, f'sudo losetup -d {loop}')
if not complete:
copy_prepared_image(cons, mmc_dev, fname)
@@ -254,32 +254,32 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)
ext = os.path.join(mnt, 'extlinux')
mkdir_cond(ext)
- with open(os.path.join(ext, 'extlinux.conf'), 'w') as fd:
+ conf = os.path.join(ext, 'extlinux.conf')
+ with open(conf, 'w', encoding='ascii') as fd:
print(script, file=fd)
inf = os.path.join(cons.config.persistent_data_dir, 'inf')
with open(inf, 'wb') as fd:
fd.write(gzip.compress(b'vmlinux'))
- u_boot_utils.run_and_log(cons, 'mkimage -f auto -d %s %s' %
- (inf, os.path.join(mnt, vmlinux)))
+ u_boot_utils.run_and_log(
+ cons, f'mkimage -f auto -d {inf} {os.path.join(mnt, vmlinux)}')
- with open(os.path.join(mnt, initrd), 'w') as fd:
+ with open(os.path.join(mnt, initrd), 'w', encoding='ascii') as fd:
print('initrd', file=fd)
mkdir_cond(os.path.join(mnt, dtbdir))
- dtb_file = os.path.join(mnt, '%s/sandbox.dtb' % dtbdir)
+ dtb_file = os.path.join(mnt, f'{dtbdir}/sandbox.dtb')
u_boot_utils.run_and_log(
- cons, 'dtc -o %s' % dtb_file, stdin=b'/dts-v1/; / {};')
+ cons, f'dtc -o {dtb_file}', stdin=b'/dts-v1/; / {};')
complete = True
except ValueError as exc:
- print('Falled to create image, failing back to prepared copy: %s',
- str(exc))
+ print(f'Falled to create image, failing back to prepared copy: {exc}')
finally:
if mounted:
- u_boot_utils.run_and_log(cons, 'sudo umount --lazy %s' % mnt)
+ u_boot_utils.run_and_log(cons, f'sudo umount --lazy {mnt}')
if loop:
- u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop)
+ u_boot_utils.run_and_log(cons, f'sudo losetup -d {loop}')
if not complete:
copy_prepared_image(cons, mmc_dev, fname)
@@ -303,7 +303,8 @@ def setup_cros_image(cons):
Return:
bytes: Packed-kernel data
"""
- kern_part = os.path.join(cons.config.result_dir, 'kern-part-{arch}.bin')
+ kern_part = os.path.join(cons.config.result_dir,
+ f'kern-part-{arch}.bin')
u_boot_utils.run_and_log(
cons,
f'futility vbutil_kernel --pack {kern_part} '
@@ -332,7 +333,7 @@ def setup_cros_image(cons):
mmc_dev = 5
fname = os.path.join(cons.config.source_dir, f'mmc{mmc_dev}.img')
- u_boot_utils.run_and_log(cons, 'qemu-img create %s 20M' % fname)
+ u_boot_utils.run_and_log(cons, f'qemu-img create {fname} 20M')
#mnt = os.path.join(cons.config.persistent_data_dir, 'mnt')
#mkdir_cond(mnt)
u_boot_utils.run_and_log(cons, f'cgpt create {fname}')
@@ -381,20 +382,20 @@ def setup_cros_image(cons):
u_boot_utils.run_and_log(cons, f'cgpt boot -p {fname}')
out = u_boot_utils.run_and_log(cons, f'cgpt show -q {fname}')
- '''We expect something like this:
- 8239 2048 1 Basic data
- 45 2048 2 ChromeOS kernel
- 8238 1 3 ChromeOS rootfs
- 2093 2048 4 ChromeOS kernel
- 8237 1 5 ChromeOS rootfs
- 41 1 6 ChromeOS kernel
- 42 1 7 ChromeOS rootfs
- 4141 2048 8 Basic data
- 43 1 9 ChromeOS reserved
- 44 1 10 ChromeOS reserved
- 40 1 11 ChromeOS firmware
- 6189 2048 12 EFI System Partition
- '''
+
+ # We expect something like this:
+ # 8239 2048 1 Basic data
+ # 45 2048 2 ChromeOS kernel
+ # 8238 1 3 ChromeOS rootfs
+ # 2093 2048 4 ChromeOS kernel
+ # 8237 1 5 ChromeOS rootfs
+ # 41 1 6 ChromeOS kernel
+ # 42 1 7 ChromeOS rootfs
+ # 4141 2048 8 Basic data
+ # 43 1 9 ChromeOS reserved
+ # 44 1 10 ChromeOS reserved
+ # 40 1 11 ChromeOS firmware
+ # 6189 2048 12 EFI System Partition
# Create a dict (indexed by partition number) containing the above info
for line in out.splitlines():
@@ -446,7 +447,7 @@ def setup_android_image(cons):
mmc_dev = 7
fname = os.path.join(cons.config.source_dir, f'mmc{mmc_dev}.img')
- u_boot_utils.run_and_log(cons, 'qemu-img create %s 20M' % fname)
+ u_boot_utils.run_and_log(cons, f'qemu-img create {fname} 20M')
u_boot_utils.run_and_log(cons, f'cgpt create {fname}')
ptr = 40
@@ -498,11 +499,12 @@ def setup_android_image(cons):
with open(fname, 'wb') as outf:
outf.write(disk_data)
- print('wrote to {}'.format(fname))
+ print(f'wrote to {fname}')
return fname
def setup_cedit_file(cons):
+ """Set up a .dtb file for use with testing expo and configuration editor"""
infname = os.path.join(cons.config.source_dir,
'test/boot/files/expo_layout.dts')
inhname = os.path.join(cons.config.source_dir,
@@ -584,7 +586,7 @@ def test_ut(u_boot_console, ut_subtest):
# ut hush hush_test_simple_dollar prints "Unknown command" on purpose.
with u_boot_console.disable_check('unknown_command'):
output = u_boot_console.run_command('ut ' + ut_subtest)
- assert('Unknown command \'quux\' - try \'help\'' in output)
+ assert 'Unknown command \'quux\' - try \'help\'' in output
else:
output = u_boot_console.run_command('ut ' + ut_subtest)
assert output.endswith('Failures: 0')
diff --git a/test/test-main.c b/test/test-main.c
index 63e8be0ccd1..b3d3e24cdce 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -12,6 +12,7 @@
#include <net.h>
#include <of_live.h>
#include <os.h>
+#include <usb.h>
#include <dm/ofnode.h>
#include <dm/root.h>
#include <dm/test.h>
@@ -289,6 +290,43 @@ static int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
{
ut_assertok(event_init());
+ /*
+ * Remove any USB keyboard, so that we can add and remove USB devices
+ * in tests.
+ *
+ * For UT_TESTF_DM tests, the old driver model state is saved and
+ * restored across each test. Within in each test there is therefore a
+ * new driver model state, which means that any USB keyboard device in
+ * stdio points to the old state.
+ *
+ * This is fine in most cases. But if a non-UT_TESTF_DM test starts up
+ * USB (thus creating a stdio record pointing to the USB keyboard
+ * device) then when the test finishes, the new driver model state is
+ * freed, meaning that there is now a stale pointer in stdio.
+ *
+ * This means that any future UT_TESTF_DM test which uses stdin will
+ * cause the console system to call tstc() on the stale device pointer,
+ * causing a crash.
+ *
+ * We don't want to fix this by enabling UT_TESTF_DM for all tests as
+ * this causes other problems. For example, bootflow_efi relies on
+ * U-Boot going through a proper init - without that we don't have the
+ * TCG measurement working and get an error
+ * 'tcg2 measurement fails(0x8000000000000007)'. Once we tidy up how EFI
+ * runs tests (e.g. get rid of all the restarting of U-Boot) we could
+ * potentially make the bootstd tests set UT_TESTF_DM, but other tests
+ * might do the same thing.
+ *
+ * We could add a test flag to declare that USB is being used, but that
+ * seems unnecessary, at least for now. We could detect USB being used
+ * in a test, but there is no obvious drawback to clearing out stale
+ * pointers always.
+ *
+ * So just remove any USB keyboards from the console tables. This allows
+ * UT_TESTF_DM and non-UT_TESTF_DM tests to coexist happily.
+ */
+ usb_kbd_remove_for_test();
+
if (test->flags & UTF_DM)
ut_assertok(dm_test_pre_run(uts));