summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/boot/Makefile1
-rw-r--r--test/boot/bootflow.c2
-rw-r--r--test/boot/bootmeth.c2
-rw-r--r--test/boot/bootstd_common.c49
-rw-r--r--test/boot/bootstd_common.h16
-rw-r--r--test/boot/vbe_fixup.c59
-rw-r--r--test/boot/vbe_simple.c34
-rw-r--r--test/cmd/fdt.c11
-rw-r--r--test/dm/acpi.c14
-rw-r--r--test/dm/core.c17
-rw-r--r--test/dm/devres.c4
-rw-r--r--test/dm/i2c.c8
-rw-r--r--test/dm/test-fdt.c19
-rw-r--r--test/dm/virtio_device.c8
-rw-r--r--test/dm/virtio_rng.c2
-rw-r--r--test/fuzz/cmd_fuzz.c2
-rw-r--r--test/fuzz/virtio.c2
-rw-r--r--test/py/tests/fit_util.py93
-rw-r--r--test/py/tests/test_event_dump.py1
-rwxr-xr-xtest/py/tests/test_fit.py79
-rw-r--r--test/py/tests/test_vbe.py123
-rw-r--r--test/test-main.c11
22 files changed, 407 insertions, 150 deletions
diff --git a/test/boot/Makefile b/test/boot/Makefile
index 9e9d5ae21f3..5bb3f889759 100644
--- a/test/boot/Makefile
+++ b/test/boot/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_BOOTSTD) += bootdev.o bootstd_common.o bootflow.o bootmeth.o
ifdef CONFIG_OF_LIVE
obj-$(CONFIG_BOOTMETH_VBE_SIMPLE) += vbe_simple.o
endif
+obj-$(CONFIG_BOOTMETH_VBE) += vbe_fixup.o
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 85305234e01..1e8ea754bcd 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -329,6 +329,8 @@ static int bootflow_system(struct unit_test_state *uts)
{
struct udevice *dev;
+ if (!IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR))
+ return 0;
ut_assertok(uclass_get_device_by_name(UCLASS_BOOTMETH, "efi_mgr",
&dev));
sandbox_set_fake_efi_mgr_dev(dev, true);
diff --git a/test/boot/bootmeth.c b/test/boot/bootmeth.c
index fb627313396..f0b5ab9adb3 100644
--- a/test/boot/bootmeth.c
+++ b/test/boot/bootmeth.c
@@ -156,7 +156,7 @@ static int bootmeth_state(struct unit_test_state *uts)
struct udevice *dev;
char buf[50];
- ut_assertok(uclass_first_device(UCLASS_BOOTMETH, &dev));
+ ut_assertok(uclass_first_device_err(UCLASS_BOOTMETH, &dev));
ut_assertnonnull(dev);
ut_assertok(bootmeth_get_state_desc(dev, buf, sizeof(buf)));
diff --git a/test/boot/bootstd_common.c b/test/boot/bootstd_common.c
index 05347d87106..7a40836507a 100644
--- a/test/boot/bootstd_common.c
+++ b/test/boot/bootstd_common.c
@@ -9,10 +9,52 @@
#include <common.h>
#include <bootstd.h>
#include <dm.h>
+#include <memalign.h>
+#include <mmc.h>
+#include <linux/log2.h>
#include <test/suites.h>
#include <test/ut.h>
+#include <u-boot/crc.h>
#include "bootstd_common.h"
+/* tracks whether bootstd_setup_for_tests() has been run yet */
+bool vbe_setup_done;
+
+/* set up MMC for VBE tests */
+int bootstd_setup_for_tests(void)
+{
+ ALLOC_CACHE_ALIGN_BUFFER(u8, buf, MMC_MAX_BLOCK_LEN);
+ struct udevice *mmc;
+ struct blk_desc *desc;
+ int ret;
+
+ if (vbe_setup_done)
+ return 0;
+
+ /* Set up the version string */
+ ret = uclass_get_device(UCLASS_MMC, 1, &mmc);
+ if (ret)
+ return log_msg_ret("mmc", -EIO);
+ desc = blk_get_by_device(mmc);
+
+ memset(buf, '\0', MMC_MAX_BLOCK_LEN);
+ strcpy(buf, TEST_VERSION);
+ if (blk_dwrite(desc, VERSION_START_BLK, 1, buf) != 1)
+ return log_msg_ret("wr1", -EIO);
+
+ /* Set up the nvdata */
+ memset(buf, '\0', MMC_MAX_BLOCK_LEN);
+ buf[1] = ilog2(0x40) << 4 | 1;
+ *(u32 *)(buf + 4) = TEST_VERNUM;
+ buf[0] = crc8(0, buf + 1, 0x3f);
+ if (blk_dwrite(desc, NVDATA_START_BLK, 1, buf) != 1)
+ return log_msg_ret("wr2", -EIO);
+
+ vbe_setup_done = true;
+
+ return 0;
+}
+
int bootstd_test_drop_bootdev_order(struct unit_test_state *uts)
{
struct bootstd_priv *priv;
@@ -29,6 +71,13 @@ 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);
const int n_ents = UNIT_TEST_SUITE_COUNT(bootstd_test);
+ int ret;
+
+ ret = bootstd_setup_for_tests();
+ if (ret) {
+ printf("Failed to set up for bootstd tests (err=%d)\n", ret);
+ return CMD_RET_FAILURE;
+ }
return cmd_ut_category("bootstd", "bootstd_test_",
tests, n_ents, argc, argv);
diff --git a/test/boot/bootstd_common.h b/test/boot/bootstd_common.h
index 676ef0a57f9..c5e0fd1ceab 100644
--- a/test/boot/bootstd_common.h
+++ b/test/boot/bootstd_common.h
@@ -9,10 +9,17 @@
#ifndef __bootstd_common_h
#define __bootstd_common_h
+#include <version_string.h>
+
/* Declare a new bootdev test */
#define BOOTSTD_TEST(_name, _flags) \
UNIT_TEST(_name, _flags, bootstd_test)
+#define NVDATA_START_BLK ((0x400 + 0x400) / MMC_MAX_BLOCK_LEN)
+#define VERSION_START_BLK ((0x400 + 0x800) / MMC_MAX_BLOCK_LEN)
+#define TEST_VERSION "U-Boot v2022.04-local2"
+#define TEST_VERNUM 0x00010002
+
struct unit_test_state;
/**
@@ -24,4 +31,13 @@ struct unit_test_state;
*/
int bootstd_test_drop_bootdev_order(struct unit_test_state *uts);
+/**
+ * bootstd_setup_for_tests() - Set up MMC data for VBE tests
+ *
+ * Some data is needed for VBE tests to work. This function sets that up.
+ *
+ * @return 0 if OK, -ve on error
+ */
+int bootstd_setup_for_tests(void);
+
#endif
diff --git a/test/boot/vbe_fixup.c b/test/boot/vbe_fixup.c
new file mode 100644
index 00000000000..1b488e25ab6
--- /dev/null
+++ b/test/boot/vbe_fixup.c
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test for VBE device tree fix-ups
+ *
+ * Copyright 2022 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <dm/ofnode.h>
+#include <linux/libfdt.h>
+#include <test/test.h>
+#include <test/ut.h>
+#include "bootstd_common.h"
+
+/* Basic test of reading nvdata and updating a fwupd node in the device tree */
+static int vbe_test_fixup(struct unit_test_state *uts)
+{
+ ofnode chosen, node;
+ const char *data;
+ oftree tree;
+ int size;
+
+ /*
+ * This test works when called from test_vbe.py and it must use the
+ * flat tree, since device tree fix-ups do not yet support live tree.
+ */
+ if (!working_fdt)
+ return 0;
+
+ tree = oftree_from_fdt(working_fdt);
+ ut_assert(oftree_valid(tree));
+
+ chosen = oftree_path(tree, "/chosen");
+ ut_assert(ofnode_valid(chosen));
+
+ /* check the things set up for the FIT in test_vbe.py */
+ node = ofnode_find_subnode(chosen, "random");
+
+ /* ignore if this test is run on its own */
+ if (!ofnode_valid(node))
+ return 0;
+ data = ofnode_read_prop(node, "data", &size);
+ ut_asserteq(0x40, size);
+
+ node = ofnode_find_subnode(chosen, "aslr2");
+ ut_assert(ofnode_valid(node));
+ data = ofnode_read_prop(node, "data", &size);
+ ut_asserteq(4, size);
+
+ node = ofnode_find_subnode(chosen, "efi-runtime");
+ ut_assert(ofnode_valid(node));
+ data = ofnode_read_prop(node, "data", &size);
+ ut_asserteq(4, size);
+
+ return 0;
+}
+BOOTSTD_TEST(vbe_test_fixup,
+ UT_TESTF_DM | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
diff --git a/test/boot/vbe_simple.c b/test/boot/vbe_simple.c
index 8acd777f4cd..faba9e8f90b 100644
--- a/test/boot/vbe_simple.c
+++ b/test/boot/vbe_simple.c
@@ -10,54 +10,27 @@
#include <bootmeth.h>
#include <dm.h>
#include <image.h>
-#include <memalign.h>
-#include <mmc.h>
#include <of_live.h>
#include <vbe.h>
-#include <version_string.h>
-#include <linux/log2.h>
#include <test/suites.h>
#include <test/ut.h>
-#include <u-boot/crc.h>
#include "bootstd_common.h"
-#define NVDATA_START_BLK ((0x400 + 0x400) / MMC_MAX_BLOCK_LEN)
-#define VERSION_START_BLK ((0x400 + 0x800) / MMC_MAX_BLOCK_LEN)
-#define TEST_VERSION "U-Boot v2022.04-local2"
-#define TEST_VERNUM 0x00010002
-
/* Basic test of reading nvdata and updating a fwupd node in the device tree */
static int vbe_simple_test_base(struct unit_test_state *uts)
{
- ALLOC_CACHE_ALIGN_BUFFER(u8, buf, MMC_MAX_BLOCK_LEN);
const char *version, *bl_version;
struct event_ft_fixup fixup;
- struct udevice *dev, *mmc;
+ struct udevice *dev;
struct device_node *np;
- struct blk_desc *desc;
char fdt_buf[0x400];
char info[100];
int node_ofs;
ofnode node;
u32 vernum;
- /* Set up the version string */
- ut_assertok(uclass_get_device(UCLASS_MMC, 1, &mmc));
- desc = blk_get_by_device(mmc);
- ut_assertnonnull(desc);
-
- memset(buf, '\0', MMC_MAX_BLOCK_LEN);
- strcpy(buf, TEST_VERSION);
- if (blk_dwrite(desc, VERSION_START_BLK, 1, buf) != 1)
- return log_msg_ret("write", -EIO);
-
- /* Set up the nvdata */
- memset(buf, '\0', MMC_MAX_BLOCK_LEN);
- buf[1] = ilog2(0x40) << 4 | 1;
- *(u32 *)(buf + 4) = TEST_VERNUM;
- buf[0] = crc8(0, buf + 1, 0x3f);
- if (blk_dwrite(desc, NVDATA_START_BLK, 1, buf) != 1)
- return log_msg_ret("write", -EIO);
+ /* Set up the VBE info */
+ ut_assertok(bootstd_setup_for_tests());
/* Read the version back */
ut_assertok(vbe_find_by_any("firmware0", &dev));
@@ -90,6 +63,7 @@ static int vbe_simple_test_base(struct unit_test_state *uts)
*
* Two fix this we need image_setup_libfdt() is updated to use ofnode
*/
+ fixup.images = NULL;
ut_assertok(event_notify(EVT_FT_FIXUP, &fixup, sizeof(fixup)));
node = oftree_path(fixup.tree, "/chosen/fwupd/firmware0");
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 100a7ef5ebf..ba9eaa42c14 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -55,6 +55,7 @@ static int fdt_test_addr(struct unit_test_state *uts)
/* The working fdt is not set, so this should fail */
set_working_fdt_addr(0);
+ ut_assert_nextline("Working FDT set to 0");
ut_asserteq(CMD_RET_FAILURE, run_command("fdt addr", 0));
ut_assert_nextline("libfdt fdt_check_header(): FDT_ERR_BADMAGIC");
ut_assertok(ut_check_console_end(uts));
@@ -63,18 +64,22 @@ static int fdt_test_addr(struct unit_test_state *uts)
ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt)));
addr = map_to_sysmem(fdt);
set_working_fdt_addr(addr);
+ ut_assert_nextline("Working FDT set to %lx", addr);
ut_assertok(run_command("fdt addr", 0));
ut_assert_nextline("Working fdt: %08lx", (ulong)map_to_sysmem(fdt));
ut_assertok(ut_check_console_end(uts));
/* Set the working FDT */
set_working_fdt_addr(0);
+ ut_assert_nextline("Working FDT set to 0");
ut_assertok(run_commandf("fdt addr %08x", addr));
+ ut_assert_nextline("Working FDT set to %lx", addr);
ut_asserteq(addr, map_to_sysmem(working_fdt));
ut_assertok(ut_check_console_end(uts));
set_working_fdt_addr(0);
+ ut_assert_nextline("Working FDT set to 0");
- /* Set the working FDT */
+ /* Set the control FDT */
fdt_blob = gd->fdt_blob;
gd->fdt_blob = NULL;
ret = run_commandf("fdt addr -c %08x", addr);
@@ -93,6 +98,7 @@ static int fdt_test_addr(struct unit_test_state *uts)
/* Test detecting an invalid FDT */
fdt[0] = 123;
set_working_fdt_addr(addr);
+ ut_assert_nextline("Working FDT set to %lx", addr);
ut_asserteq(1, run_commandf("fdt addr"));
ut_assert_nextline("libfdt fdt_check_header(): FDT_ERR_BADMAGIC");
ut_assertok(ut_check_console_end(uts));
@@ -115,16 +121,19 @@ static int fdt_test_resize(struct unit_test_state *uts)
/* Test setting and resizing the working FDT to a larger size */
ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt addr %08x %x", addr, newsize));
+ ut_assert_nextline("Working FDT set to %lx", addr);
ut_assertok(ut_check_console_end(uts));
/* Try shrinking it */
ut_assertok(run_commandf("fdt addr %08x %x", addr, sizeof(fdt) / 4));
+ ut_assert_nextline("Working FDT set to %lx", addr);
ut_assert_nextline("New length %d < existing length %d, ignoring",
(int)sizeof(fdt) / 4, newsize);
ut_assertok(ut_check_console_end(uts));
/* ...quietly */
ut_assertok(run_commandf("fdt addr -q %08x %x", addr, sizeof(fdt) / 4));
+ ut_assert_nextline("Working FDT set to %lx", addr);
ut_assertok(ut_check_console_end(uts));
/* We cannot easily provoke errors in fdt_open_into(), so ignore that */
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index edad91329f9..9634fc2e900 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -169,28 +169,28 @@ static int dm_test_acpi_get_name(struct unit_test_state *uts)
ut_asserteq_str("GHIJ", name);
/* Test getting the name from acpi_device_get_name() */
- ut_assertok(uclass_first_device(UCLASS_I2C, &i2c));
+ ut_assertok(uclass_first_device_err(UCLASS_I2C, &i2c));
ut_assertok(acpi_get_name(i2c, name));
ut_asserteq_str("I2C0", name);
- ut_assertok(uclass_first_device(UCLASS_SPI, &spi));
+ ut_assertok(uclass_first_device_err(UCLASS_SPI, &spi));
ut_assertok(acpi_get_name(spi, name));
ut_asserteq_str("SPI0", name);
/* ACPI doesn't know about the timer */
- ut_assertok(uclass_first_device(UCLASS_TIMER, &timer));
+ ut_assertok(uclass_first_device_err(UCLASS_TIMER, &timer));
ut_asserteq(-ENOENT, acpi_get_name(timer, name));
/* May as well test the rest of the cases */
- ut_assertok(uclass_first_device(UCLASS_SOUND, &sound));
+ ut_assertok(uclass_first_device_err(UCLASS_SOUND, &sound));
ut_assertok(acpi_get_name(sound, name));
ut_asserteq_str("HDAS", name);
- ut_assertok(uclass_first_device(UCLASS_PCI, &pci));
+ ut_assertok(uclass_first_device_err(UCLASS_PCI, &pci));
ut_assertok(acpi_get_name(pci, name));
ut_asserteq_str("PCI0", name);
- ut_assertok(uclass_first_device(UCLASS_ROOT, &root));
+ ut_assertok(uclass_first_device_err(UCLASS_ROOT, &root));
ut_assertok(acpi_get_name(root, name));
ut_asserteq_str("\\_SB", name);
@@ -219,7 +219,7 @@ static int dm_test_acpi_create_dmar(struct unit_test_state *uts)
struct acpi_dmar dmar;
struct udevice *cpu;
- ut_assertok(uclass_first_device(UCLASS_CPU, &cpu));
+ ut_assertok(uclass_first_device_err(UCLASS_CPU, &cpu));
ut_assertnonnull(cpu);
ut_assertok(acpi_create_dmar(&dmar, DMAR_INTR_REMAP));
ut_asserteq(DMAR_INTR_REMAP, dmar.flags);
diff --git a/test/dm/core.c b/test/dm/core.c
index fd4d7569728..84eb76ed5fc 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -512,23 +512,15 @@ static int dm_test_leak(struct unit_test_state *uts)
int i;
for (i = 0; i < 2; i++) {
- struct udevice *dev;
int ret;
- int id;
dm_leak_check_start(uts);
ut_assertok(dm_scan_plat(false));
ut_assertok(dm_scan_fdt(false));
- /* Scanning the uclass is enough to probe all the devices */
- for (id = UCLASS_ROOT; id < UCLASS_COUNT; id++) {
- for (ret = uclass_first_device(UCLASS_TEST, &dev);
- dev;
- ret = uclass_next_device(&dev))
- ;
- ut_assertok(ret);
- }
+ ret = uclass_probe_all(UCLASS_TEST);
+ ut_assertok(ret);
ut_assertok(dm_leak_check_end(uts));
}
@@ -653,10 +645,7 @@ static int dm_test_children(struct unit_test_state *uts)
ut_asserteq(2 + NODE_COUNT, dm_testdrv_op_count[DM_TEST_OP_PROBE]);
/* Probe everything */
- for (ret = uclass_first_device(UCLASS_TEST, &dev);
- dev;
- ret = uclass_next_device(&dev))
- ;
+ ret = uclass_probe_all(UCLASS_TEST);
ut_assertok(ret);
ut_asserteq(total, dm_testdrv_op_count[DM_TEST_OP_PROBE]);
diff --git a/test/dm/devres.c b/test/dm/devres.c
index 524114c833c..3df0f64362d 100644
--- a/test/dm/devres.c
+++ b/test/dm/devres.c
@@ -165,8 +165,8 @@ static int dm_test_devres_phase(struct unit_test_state *uts)
ut_asserteq(TEST_DEVRES_SIZE + TEST_DEVRES_SIZE3, stats.total_size);
/* Probing the device should add one allocation */
- ut_assertok(uclass_first_device(UCLASS_TEST_DEVRES, &dev));
- ut_assert(dev != NULL);
+ ut_assertok(uclass_first_device_err(UCLASS_TEST_DEVRES, &dev));
+ ut_assertnonnull(dev);
devres_get_stats(dev, &stats);
ut_asserteq(3, stats.allocs);
ut_asserteq(TEST_DEVRES_SIZE + TEST_DEVRES_SIZE2 + TEST_DEVRES_SIZE3,
diff --git a/test/dm/i2c.c b/test/dm/i2c.c
index 74b20971956..b46a22e79b1 100644
--- a/test/dm/i2c.c
+++ b/test/dm/i2c.c
@@ -124,7 +124,7 @@ static int dm_test_i2c_bytewise(struct unit_test_state *uts)
ut_asserteq_mem(buf, "\0\0\0\0\0", sizeof(buf));
/* Tell the EEPROM to only read/write one register at a time */
- ut_assertok(uclass_first_device(UCLASS_I2C_EMUL, &eeprom));
+ ut_assertok(uclass_first_device_err(UCLASS_I2C_EMUL, &eeprom));
ut_assertnonnull(eeprom);
sandbox_i2c_eeprom_set_test_mode(eeprom, SIE_TEST_MODE_SINGLE_BYTE);
@@ -177,7 +177,7 @@ static int dm_test_i2c_offset(struct unit_test_state *uts)
/* Do a transfer so we can find the emulator */
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
- ut_assertok(uclass_first_device(UCLASS_I2C_EMUL, &eeprom));
+ ut_assertok(uclass_first_device_err(UCLASS_I2C_EMUL, &eeprom));
/* Offset length 0 */
sandbox_i2c_eeprom_set_offset_len(eeprom, 0);
@@ -250,7 +250,7 @@ static int dm_test_i2c_addr_offset(struct unit_test_state *uts)
/* Do a transfer so we can find the emulator */
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
- ut_assertok(uclass_first_device(UCLASS_I2C_EMUL, &eeprom));
+ ut_assertok(uclass_first_device_err(UCLASS_I2C_EMUL, &eeprom));
/* Offset length 0 */
sandbox_i2c_eeprom_set_offset_len(eeprom, 0);
@@ -315,7 +315,7 @@ static int dm_test_i2c_reg_clrset(struct unit_test_state *uts)
/* Do a transfer so we can find the emulator */
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
- ut_assertok(uclass_first_device(UCLASS_I2C_EMUL, &eeprom));
+ ut_assertok(uclass_first_device_err(UCLASS_I2C_EMUL, &eeprom));
/* Dummy data for the test */
ut_assertok(dm_i2c_write(dev, 0, "\xff\x00\xff\x00\x10", 5));
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index 012f2f455f6..1f14513d9f1 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -392,10 +392,10 @@ DM_TEST(dm_test_fdt_offset,
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
/**
- * Test various error conditions with uclass_first_device() and
- * uclass_next_device()
+ * Test various error conditions with uclass_first_device(),
+ * uclass_next_device(), and uclass_probe_all()
*/
-static int dm_test_first_next_device(struct unit_test_state *uts)
+static int dm_test_first_next_device_probeall(struct unit_test_state *uts)
{
struct dm_testprobe_pdata *pdata;
struct udevice *dev, *parent = NULL;
@@ -428,9 +428,20 @@ static int dm_test_first_next_device(struct unit_test_state *uts)
device_remove(parent, DM_REMOVE_NORMAL);
ut_asserteq(-ENOENT, uclass_first_device(UCLASS_TEST_PROBE, &dev));
+ /* Now that broken devices are set up test probe_all */
+ device_remove(parent, DM_REMOVE_NORMAL);
+ /* There are broken devices so an error should be returned */
+ ut_assert(uclass_probe_all(UCLASS_TEST_PROBE) < 0);
+ /* but non-error device should be probed nonetheless */
+ ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 2, &dev));
+ ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
+ ut_assertok(uclass_get_device(UCLASS_TEST_PROBE, 3, &dev));
+ ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
+
return 0;
}
-DM_TEST(dm_test_first_next_device, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_first_next_device_probeall,
+ UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
/* Test iteration through devices in a uclass */
static int dm_test_uclass_foreach(struct unit_test_state *uts)
diff --git a/test/dm/virtio_device.c b/test/dm/virtio_device.c
index d0195e6bf09..b5c4523a028 100644
--- a/test/dm/virtio_device.c
+++ b/test/dm/virtio_device.c
@@ -22,7 +22,7 @@ static int dm_test_virtio_base(struct unit_test_state *uts)
u8 status;
/* check probe success */
- ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus));
+ ut_assertok(uclass_first_device_err(UCLASS_VIRTIO, &bus));
ut_assertnonnull(bus);
/* check the child virtio-rng device is bound */
@@ -60,7 +60,7 @@ static int dm_test_virtio_all_ops(struct unit_test_state *uts)
struct virtqueue *vqs[2];
/* check probe success */
- ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus));
+ ut_assertok(uclass_first_device_err(UCLASS_VIRTIO, &bus));
ut_assertnonnull(bus);
/* check the child virtio-rng device is bound */
@@ -102,7 +102,7 @@ static int dm_test_virtio_remove(struct unit_test_state *uts)
struct udevice *bus, *dev;
/* check probe success */
- ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus));
+ ut_assertok(uclass_first_device_err(UCLASS_VIRTIO, &bus));
ut_assertnonnull(bus);
/* check the child virtio-rng device is bound */
@@ -134,7 +134,7 @@ static int dm_test_virtio_ring(struct unit_test_state *uts)
u8 buffer[2][32];
/* check probe success */
- ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus));
+ ut_assertok(uclass_first_device_err(UCLASS_VIRTIO, &bus));
ut_assertnonnull(bus);
/* check the child virtio-blk device is bound */
diff --git a/test/dm/virtio_rng.c b/test/dm/virtio_rng.c
index ff5646b4e11..8b9a04b1fde 100644
--- a/test/dm/virtio_rng.c
+++ b/test/dm/virtio_rng.c
@@ -28,7 +28,7 @@ static int dm_test_virtio_rng_check_len(struct unit_test_state *uts)
u8 buffer[16];
/* check probe success */
- ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus));
+ ut_assertok(uclass_first_device_err(UCLASS_VIRTIO, &bus));
ut_assertnonnull(bus);
/* check the child virtio-rng device is bound */
diff --git a/test/fuzz/cmd_fuzz.c b/test/fuzz/cmd_fuzz.c
index 0cc01dc199c..e2f44f3ecb6 100644
--- a/test/fuzz/cmd_fuzz.c
+++ b/test/fuzz/cmd_fuzz.c
@@ -29,7 +29,7 @@ static struct udevice *find_fuzzing_engine(void)
{
struct udevice *dev;
- if (uclass_first_device(UCLASS_FUZZING_ENGINE, &dev))
+ if (uclass_first_device_err(UCLASS_FUZZING_ENGINE, &dev))
return NULL;
return dev;
diff --git a/test/fuzz/virtio.c b/test/fuzz/virtio.c
index e5363d5638e..8a47667e778 100644
--- a/test/fuzz/virtio.c
+++ b/test/fuzz/virtio.c
@@ -30,7 +30,7 @@ static int fuzz_vring(const uint8_t *data, size_t size)
return 0;
/* check probe success */
- if (uclass_first_device(UCLASS_VIRTIO, &bus) || !bus)
+ if (uclass_first_device_err(UCLASS_VIRTIO, &bus))
panic("Could not find virtio bus\n");
/* check the child virtio-rng device is bound */
diff --git a/test/py/tests/fit_util.py b/test/py/tests/fit_util.py
new file mode 100644
index 00000000000..79718d431a0
--- /dev/null
+++ b/test/py/tests/fit_util.py
@@ -0,0 +1,93 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2022 Google LLC
+
+"""Common utility functions for FIT tests"""
+
+import os
+
+import u_boot_utils as util
+
+def make_fname(cons, basename):
+ """Make a temporary filename
+
+ Args:
+ cons (ConsoleBase): u_boot_console to use
+ basename (str): Base name of file to create (within temporary directory)
+ Return:
+ Temporary filename
+ """
+
+ return os.path.join(cons.config.build_dir, basename)
+
+def make_its(cons, base_its, params, basename='test.its'):
+ """Make a sample .its file with parameters embedded
+
+ Args:
+ cons (ConsoleBase): u_boot_console to use
+ base_its (str): Template text for the .its file, typically containing
+ %() references
+ params (dict of str): Parameters to embed in the %() strings
+ basename (str): base name to write to (will be placed in the temp dir)
+ Returns:
+ str: Filename of .its file created
+ """
+ its = make_fname(cons, basename)
+ with open(its, 'w', encoding='utf-8') as outf:
+ print(base_its % params, file=outf)
+ return its
+
+def make_fit(cons, mkimage, base_its, params, basename='test.fit', base_fdt=None):
+ """Make a sample .fit file ready for loading
+
+ This creates a .its script with the selected parameters and uses mkimage to
+ turn this into a .fit image.
+
+ Args:
+ cons (ConsoleBase): u_boot_console to use
+ mkimage (str): Filename of 'mkimage' utility
+ base_its (str): Template text for the .its file, typically containing
+ %() references
+ params (dict of str): Parameters to embed in the %() strings
+ basename (str): base name to write to (will be placed in the temp dir)
+ Return:
+ Filename of .fit file created
+ """
+ fit = make_fname(cons, basename)
+ its = make_its(cons, base_its, params)
+ util.run_and_log(cons, [mkimage, '-f', its, fit])
+ if base_fdt:
+ with open(make_fname(cons, 'u-boot.dts'), 'w') as fd:
+ fd.write(base_fdt)
+ return fit
+
+def make_kernel(cons, basename, text):
+ """Make a sample kernel with test data
+
+ Args:
+ cons (ConsoleBase): u_boot_console to use
+ basename (str): base name to write to (will be placed in the temp dir)
+ text (str): Contents of the kernel file (will be repeated 100 times)
+ Returns:
+ str: Full path and filename of the kernel it created
+ """
+ fname = make_fname(cons, basename)
+ data = ''
+ for i in range(100):
+ data += f'this {text} {i} is unlikely to boot\n'
+ with open(fname, 'w', encoding='utf-8') as outf:
+ print(data, file=outf)
+ return fname
+
+def make_dtb(cons, base_fdt, basename):
+ """Make a sample .dts file and compile it to a .dtb
+
+ Returns:
+ cons (ConsoleBase): u_boot_console to use
+ Filename of .dtb file created
+ """
+ src = make_fname(cons, f'{basename}.dts')
+ dtb = make_fname(cons, f'{basename}.dtb')
+ with open(src, 'w', encoding='utf-8') as outf:
+ outf.write(base_fdt)
+ util.run_and_log(cons, ['dtc', src, '-O', 'dtb', '-o', dtb])
+ return dtb
diff --git a/test/py/tests/test_event_dump.py b/test/py/tests/test_event_dump.py
index bc54149e8f2..e63c25df537 100644
--- a/test/py/tests/test_event_dump.py
+++ b/test/py/tests/test_event_dump.py
@@ -16,6 +16,7 @@ def test_event_dump(u_boot_console):
out = util.run_and_log(cons, ['scripts/event_dump.py', sandbox])
expect = '''.*Event type Id Source location
-------------------- ------------------------------ ------------------------------
+EVT_FT_FIXUP bootmeth_vbe_ft_fixup .*boot/vbe_fixup.c:.*
EVT_FT_FIXUP bootmeth_vbe_simple_ft_fixup .*boot/vbe_simple.c:.*
EVT_MISC_INIT_F sandbox_misc_init_f .*arch/sandbox/cpu/start.c:'''
assert re.match(expect, out, re.MULTILINE) is not None
diff --git a/test/py/tests/test_fit.py b/test/py/tests/test_fit.py
index 5856960be23..f45848484eb 100755
--- a/test/py/tests/test_fit.py
+++ b/test/py/tests/test_fit.py
@@ -7,6 +7,7 @@ import os
import pytest
import struct
import u_boot_utils as util
+import fit_util
# Define a base ITS which we can adjust using % and a dictionary
base_its = '''
@@ -126,7 +127,6 @@ def test_fit(u_boot_console):
Return:
Temporary filename
"""
-
return os.path.join(cons.config.build_dir, leaf)
def filesize(fname):
@@ -150,67 +150,6 @@ def test_fit(u_boot_console):
with open(fname, 'rb') as fd:
return fd.read()
- def make_dtb():
- """Make a sample .dts file and compile it to a .dtb
-
- Returns:
- Filename of .dtb file created
- """
- src = make_fname('u-boot.dts')
- dtb = make_fname('u-boot.dtb')
- with open(src, 'w') as fd:
- fd.write(base_fdt)
- util.run_and_log(cons, ['dtc', src, '-O', 'dtb', '-o', dtb])
- return dtb
-
- def make_its(params):
- """Make a sample .its file with parameters embedded
-
- Args:
- params: Dictionary containing parameters to embed in the %() strings
- Returns:
- Filename of .its file created
- """
- its = make_fname('test.its')
- with open(its, 'w') as fd:
- print(base_its % params, file=fd)
- return its
-
- def make_fit(mkimage, params):
- """Make a sample .fit file ready for loading
-
- This creates a .its script with the selected parameters and uses mkimage to
- turn this into a .fit image.
-
- Args:
- mkimage: Filename of 'mkimage' utility
- params: Dictionary containing parameters to embed in the %() strings
- Return:
- Filename of .fit file created
- """
- fit = make_fname('test.fit')
- its = make_its(params)
- util.run_and_log(cons, [mkimage, '-f', its, fit])
- with open(make_fname('u-boot.dts'), 'w') as fd:
- fd.write(base_fdt)
- return fit
-
- def make_kernel(filename, text):
- """Make a sample kernel with test data
-
- Args:
- filename: the name of the file you want to create
- Returns:
- Full path and filename of the kernel it created
- """
- fname = make_fname(filename)
- data = ''
- for i in range(100):
- data += 'this %s %d is unlikely to boot\n' % (text, i)
- with open(fname, 'w') as fd:
- print(data, file=fd)
- return fname
-
def make_ramdisk(filename, text):
"""Make a sample ramdisk with test data
@@ -321,10 +260,10 @@ def test_fit(u_boot_console):
- run code coverage to make sure we are testing all the code
"""
# Set up invariant files
- control_dtb = make_dtb()
- kernel = make_kernel('test-kernel.bin', 'kernel')
+ control_dtb = fit_util.make_dtb(cons, base_fdt, 'u-boot')
+ kernel = fit_util.make_kernel(cons, 'test-kernel.bin', 'kernel')
ramdisk = make_ramdisk('test-ramdisk.bin', 'ramdisk')
- loadables1 = make_kernel('test-loadables1.bin', 'lenrek')
+ loadables1 = fit_util.make_kernel(cons, 'test-loadables1.bin', 'lenrek')
loadables2 = make_ramdisk('test-loadables2.bin', 'ksidmar')
kernel_out = make_fname('kernel-out.bin')
fdt = make_fname('u-boot.dtb')
@@ -372,7 +311,7 @@ def test_fit(u_boot_console):
}
# Make a basic FIT and a script to load it
- fit = make_fit(mkimage, params)
+ fit = fit_util.make_fit(cons, mkimage, base_its, params)
params['fit'] = fit
cmd = base_script % params
@@ -403,7 +342,7 @@ def test_fit(u_boot_console):
# Now a kernel and an FDT
with cons.log.section('Kernel + FDT load'):
params['fdt_load'] = 'load = <%#x>;' % params['fdt_addr']
- fit = make_fit(mkimage, params)
+ fit = fit_util.make_fit(cons, mkimage, base_its, params)
cons.restart_uboot()
output = cons.run_command_list(cmd.splitlines())
check_equal(kernel, kernel_out, 'Kernel not loaded')
@@ -415,7 +354,7 @@ def test_fit(u_boot_console):
with cons.log.section('Kernel + FDT + Ramdisk load'):
params['ramdisk_config'] = 'ramdisk = "ramdisk-1";'
params['ramdisk_load'] = 'load = <%#x>;' % params['ramdisk_addr']
- fit = make_fit(mkimage, params)
+ fit = fit_util.make_fit(cons, mkimage, base_its, params)
cons.restart_uboot()
output = cons.run_command_list(cmd.splitlines())
check_equal(ramdisk, ramdisk_out, 'Ramdisk not loaded')
@@ -427,7 +366,7 @@ def test_fit(u_boot_console):
params['loadables1_addr'])
params['loadables2_load'] = ('load = <%#x>;' %
params['loadables2_addr'])
- fit = make_fit(mkimage, params)
+ fit = fit_util.make_fit(cons, mkimage, base_its, params)
cons.restart_uboot()
output = cons.run_command_list(cmd.splitlines())
check_equal(loadables1, loadables1_out,
@@ -441,7 +380,7 @@ def test_fit(u_boot_console):
params['kernel'] = make_compressed(kernel)
params['fdt'] = make_compressed(fdt)
params['ramdisk'] = make_compressed(ramdisk)
- fit = make_fit(mkimage, params)
+ fit = fit_util.make_fit(cons, mkimage, base_its, params)
cons.restart_uboot()
output = cons.run_command_list(cmd.splitlines())
check_equal(kernel, kernel_out, 'Kernel not loaded')
diff --git a/test/py/tests/test_vbe.py b/test/py/tests/test_vbe.py
new file mode 100644
index 00000000000..559c2918868
--- /dev/null
+++ b/test/py/tests/test_vbe.py
@@ -0,0 +1,123 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2022 Google LLC
+#
+# Test addition of VBE
+
+import pytest
+
+import fit_util
+
+# Define a base ITS which we can adjust using % and a dictionary
+base_its = '''
+/dts-v1/;
+
+/ {
+ description = "Example kernel";
+
+ images {
+ kernel-1 {
+ data = /incbin/("%(kernel)s");
+ type = "kernel";
+ arch = "sandbox";
+ os = "linux";
+ load = <0x40000>;
+ entry = <0x8>;
+ compression = "%(compression)s";
+
+ random {
+ compatible = "vbe,random-rand";
+ vbe,size = <0x40>;
+ vbe,required;
+ };
+ aslr1 {
+ compatible = "vbe,aslr-move";
+ vbe,align = <0x100000>;
+ };
+ aslr2 {
+ compatible = "vbe,aslr-rand";
+ };
+ efi-runtime {
+ compatible = "vbe,efi-runtime-rand";
+ };
+ wibble {
+ compatible = "vbe,wibble";
+ };
+ };
+
+ fdt-1 {
+ description = "snow";
+ data = /incbin/("%(fdt)s");
+ type = "flat_dt";
+ arch = "sandbox";
+ load = <%(fdt_addr)#x>;
+ compression = "%(compression)s";
+ };
+ };
+ configurations {
+ default = "conf-1";
+ conf-1 {
+ kernel = "kernel-1";
+ fdt = "fdt-1";
+ };
+ };
+};
+'''
+
+# Define a base FDT - currently we don't use anything in this
+base_fdt = '''
+/dts-v1/;
+
+/ {
+ chosen {
+ };
+};
+'''
+
+# This is the U-Boot script that is run for each test. First load the FIT,
+# then run the 'bootm' command, then run the unit test which checks that the
+# working tree has the required things filled in according to the OS requests
+# above (random, aslr2, etc.)
+base_script = '''
+host load hostfs 0 %(fit_addr)x %(fit)s
+fdt addr %(fit_addr)x
+bootm start %(fit_addr)x
+bootm loados
+bootm prep
+fdt addr
+fdt print
+ut bootstd vbe_test_fixup
+'''
+
+@pytest.mark.boardspec('sandbox_flattree')
+@pytest.mark.requiredtool('dtc')
+def test_vbe(u_boot_console):
+ cons = u_boot_console
+ kernel = fit_util.make_kernel(cons, 'vbe-kernel.bin', 'kernel')
+ fdt = fit_util.make_dtb(cons, base_fdt, 'vbe-fdt')
+ fdt_out = fit_util.make_fname(cons, 'fdt-out.dtb')
+
+ params = {
+ 'fit_addr' : 0x1000,
+
+ 'kernel' : kernel,
+
+ 'fdt' : fdt,
+ 'fdt_out' : fdt_out,
+ 'fdt_addr' : 0x80000,
+ 'fdt_size' : 0x1000,
+
+ 'compression' : 'none',
+ }
+ mkimage = cons.config.build_dir + '/tools/mkimage'
+ fit = fit_util.make_fit(cons, mkimage, base_its, params, 'test-vbe.fit',
+ base_fdt)
+ params['fit'] = fit
+ cmd = base_script % params
+
+ with cons.log.section('Kernel load'):
+ output = cons.run_command_list(cmd.splitlines())
+
+ # This is a little wonky since there are two tests running in CI. The final
+ # one is the 'ut bootstd' command above
+ failures = [line for line in output if 'Failures' in line]
+ assert len(failures) >= 1 and 'Failures: 0' in failures[-1]
diff --git a/test/test-main.c b/test/test-main.c
index d74df297c43..a98a77d68fc 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -165,16 +165,7 @@ static int dm_test_post_run(struct unit_test_state *uts)
/* Ensure all the test devices are probed */
static int do_autoprobe(struct unit_test_state *uts)
{
- struct udevice *dev;
- int ret;
-
- /* Scanning the uclass is enough to probe all the devices */
- for (ret = uclass_first_device(UCLASS_TEST, &dev);
- dev;
- ret = uclass_next_device(&dev))
- ;
-
- return ret;
+ return uclass_probe_all(UCLASS_TEST);
}
/*