summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2023-05-08 14:31:04 -0400
committerTom Rini <[email protected]>2023-05-08 14:31:04 -0400
commit11910550b65e6072b9542d462c0aa93f4ca81836 (patch)
tree8308c98ffad76d9693654a28090b03f270a7d250 /test
parent9876c8c147144db2c120fcc9ffa6de27f6894441 (diff)
parentf1d33a44ca04fdca241c1d89fd79e2e56c930c7e (diff)
Merge branch 'master' into next
Diffstat (limited to 'test')
-rw-r--r--test/Kconfig6
-rw-r--r--test/boot/bootdev.c14
-rw-r--r--test/cmd/fdt.c2
-rw-r--r--test/common/Makefile1
-rw-r--r--test/common/cread.c93
-rw-r--r--test/dm/Makefile7
-rw-r--r--test/dm/blkmap.c201
-rw-r--r--test/dm/eth.c88
-rw-r--r--test/dm/extcon.c21
-rw-r--r--test/dm/mmc.c14
-rw-r--r--test/dm/nvmxip.c145
-rw-r--r--test/dm/test-fdt.c5
-rw-r--r--test/lib/Kconfig15
-rw-r--r--test/py/requirements.txt8
-rw-r--r--test/py/tests/test_android/test_abootimg.py136
-rw-r--r--test/py/tests/test_efi_bootmgr/conftest.py6
-rw-r--r--test/py/tests/test_efi_capsule/capsule_defs.py2
-rw-r--r--test/py/tests/test_efi_capsule/conftest.py28
-rw-r--r--test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py35
-rw-r--r--test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py41
-rw-r--r--test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py38
-rw-r--r--test/py/tests/test_efi_fit.py4
-rw-r--r--test/py/tests/test_efi_secboot/conftest.py6
-rw-r--r--test/py/tests/test_efi_secboot/defs.py2
-rw-r--r--test/py/tests/test_efi_selftest.py2
-rw-r--r--test/py/tests/test_hush_if_test.py13
-rw-r--r--test/py/tests/test_net.py56
-rw-r--r--test/py/tests/test_ut.py4
28 files changed, 863 insertions, 130 deletions
diff --git a/test/Kconfig b/test/Kconfig
index 465028265b2..6e859fb7d0d 100644
--- a/test/Kconfig
+++ b/test/Kconfig
@@ -3,7 +3,9 @@ config POST
help
See doc/README.POST for more details
-menuconfig UNIT_TEST
+menu "Unit tests"
+
+config UNIT_TEST
bool "Unit tests"
help
Select this to compile in unit tests for various parts of
@@ -107,3 +109,5 @@ source "test/env/Kconfig"
source "test/lib/Kconfig"
source "test/optee/Kconfig"
source "test/overlay/Kconfig"
+
+endmenu
diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c
index 4fe9fd72208..8cf3f30e0f7 100644
--- a/test/boot/bootdev.c
+++ b/test/boot/bootdev.c
@@ -124,7 +124,8 @@ static int bootdev_test_labels(struct unit_test_state *uts)
mflags);
/* Check invalid uclass */
- ut_asserteq(-EINVAL, bootdev_find_by_label("fred0", &dev, &mflags));
+ ut_asserteq(-EPFNOSUPPORT,
+ bootdev_find_by_label("fred0", &dev, &mflags));
/* Check unknown sequence number */
ut_asserteq(-ENOENT, bootdev_find_by_label("mmc6", &dev, &mflags));
@@ -179,9 +180,8 @@ static int bootdev_test_any(struct unit_test_state *uts)
/* Check invalid uclass */
mflags = 123;
- ut_asserteq(-EINVAL, bootdev_find_by_any("fred0", &dev, &mflags));
- ut_assert_nextline("Unknown uclass 'fred0' in label");
- ut_assert_nextline("Cannot find bootdev 'fred0' (err=-22)");
+ ut_asserteq(-EPFNOSUPPORT, bootdev_find_by_any("fred0", &dev, &mflags));
+ ut_assert_nextline("Cannot find bootdev 'fred0' (err=-96)");
ut_asserteq(123, mflags);
ut_assert_console_end();
@@ -376,7 +376,6 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts)
ut_assert_nextline("Hunting with: simple_bus");
ut_assert_nextline("Found 2 extension board(s).");
ut_assert_nextline("Hunting with: ide");
- ut_assert_nextline("Bus 0: not available ");
/* mmc hunter has already been used so should not run again */
@@ -487,7 +486,6 @@ static int bootdev_test_hunt_prio(struct unit_test_state *uts)
/* now try a different priority, verbosely */
ut_assertok(bootdev_hunt_prio(BOOTDEVP_5_SCAN_SLOW, true));
ut_assert_nextline("Hunting with: ide");
- ut_assert_nextline("Bus 0: not available ");
ut_assert_nextline("Hunting with: usb");
ut_assert_nextline(
"Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found");
@@ -512,9 +510,8 @@ static int bootdev_test_hunt_label(struct unit_test_state *uts)
old = (void *)&mflags; /* arbitrary pointer to check against dev */
dev = old;
mflags = 123;
- ut_asserteq(-EINVAL,
+ ut_asserteq(-EPFNOSUPPORT,
bootdev_hunt_and_find_by_label("fred", &dev, &mflags));
- ut_assert_nextline("Unknown uclass 'fred' in label");
ut_asserteq_ptr(old, dev);
ut_asserteq(123, mflags);
ut_assert_console_end();
@@ -525,7 +522,6 @@ static int bootdev_test_hunt_label(struct unit_test_state *uts)
bootdev_hunt_and_find_by_label("mmc4", &dev, &mflags));
ut_asserteq_ptr(old, dev);
ut_asserteq(123, mflags);
- ut_assert_nextline("Unknown seq 4 for label 'mmc4'");
ut_assert_console_end();
ut_assertok(bootstd_test_check_mmc_hunter(uts));
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 7835da232d5..1f103a1d7eb 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -2,7 +2,7 @@
/*
* Tests for fdt command
*
- * Copyright 2022 Google LLCmap_to_sysmem(fdt));
+ * Copyright 2022 Google LLC
*/
#include <common.h>
diff --git a/test/common/Makefile b/test/common/Makefile
index cc918f64e54..a5ab10f6f69 100644
--- a/test/common/Makefile
+++ b/test/common/Makefile
@@ -3,3 +3,4 @@ obj-y += cmd_ut_common.o
obj-$(CONFIG_AUTOBOOT) += test_autoboot.o
obj-$(CONFIG_CYCLIC) += cyclic.o
obj-$(CONFIG_EVENT) += event.o
+obj-y += cread.o
diff --git a/test/common/cread.c b/test/common/cread.c
new file mode 100644
index 00000000000..2fdd29a265f
--- /dev/null
+++ b/test/common/cread.c
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2023 Google LLC
+ */
+
+#include <common.h>
+#include <cli.h>
+#include <test/common.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+static int cli_ch_test(struct unit_test_state *uts)
+{
+ struct cli_ch_state s_cch, *cch = &s_cch;
+
+ cli_ch_init(cch);
+
+ /* should be nothing to return at first */
+ ut_asserteq(0, cli_ch_process(cch, 0));
+
+ /* check normal entry */
+ ut_asserteq('a', cli_ch_process(cch, 'a'));
+ ut_asserteq('b', cli_ch_process(cch, 'b'));
+ ut_asserteq('c', cli_ch_process(cch, 'c'));
+ ut_asserteq(0, cli_ch_process(cch, 0));
+
+ /* send an invalid escape sequence */
+ ut_asserteq(0, cli_ch_process(cch, '\e'));
+ ut_asserteq(0, cli_ch_process(cch, '['));
+
+ /*
+ * with the next char it sees that the sequence is invalid, so starts
+ * emitting it
+ */
+ ut_asserteq('\e', cli_ch_process(cch, 'X'));
+
+ /* now we set 0 bytes to empty the buffer */
+ ut_asserteq('[', cli_ch_process(cch, 0));
+ ut_asserteq('X', cli_ch_process(cch, 0));
+ ut_asserteq(0, cli_ch_process(cch, 0));
+
+ /* things are normal again */
+ ut_asserteq('a', cli_ch_process(cch, 'a'));
+ ut_asserteq(0, cli_ch_process(cch, 0));
+
+ return 0;
+}
+COMMON_TEST(cli_ch_test, 0);
+
+static int cread_test(struct unit_test_state *uts)
+{
+ int duration;
+ ulong start;
+ char buf[10];
+
+ /*
+ * useful for debugging
+ *
+ * gd->flags &= ~GD_FLG_RECORD;
+ * print_buffer(0, buf, 1, 7, 0);
+ */
+
+ console_record_reset_enable();
+
+ /* simple input */
+ *buf = '\0';
+ ut_asserteq(4, console_in_puts("abc\n"));
+ ut_asserteq(3, cli_readline_into_buffer("-> ", buf, 1));
+ ut_asserteq_str("abc", buf);
+
+ /* try an escape sequence (cursor left after the 'c') */
+ *buf = '\0';
+ ut_asserteq(8, console_in_puts("abc\e[Dx\n"));
+ ut_asserteq(4, cli_readline_into_buffer("-> ", buf, 1));
+ ut_asserteq_str("abxc", buf);
+
+ /* invalid escape sequence */
+ *buf = '\0';
+ ut_asserteq(8, console_in_puts("abc\e[Xx\n"));
+ ut_asserteq(7, cli_readline_into_buffer("-> ", buf, 1));
+ ut_asserteq_str("abc\e[Xx", buf);
+
+ /* check timeout, should be between 1000 and 1050ms */
+ start = get_timer(0);
+ *buf = '\0';
+ ut_asserteq(-2, cli_readline_into_buffer("-> ", buf, 1));
+ duration = get_timer(start) - 1000;
+ ut_assert(duration >= 0);
+ ut_assert(duration < 50);
+
+ return 0;
+}
+COMMON_TEST(cread_test, 0);
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 7a79b6e1a25..3799b1ae8fd 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0+
#
# Copyright (c) 2013 Google, Inc
+# Copyright 2023 Arm Limited and/or its affiliates <[email protected]>
obj-$(CONFIG_UT_DM) += test-dm.o
@@ -17,6 +18,10 @@ obj-$(CONFIG_UT_DM) += test-uclass.o
obj-$(CONFIG_UT_DM) += core.o
obj-$(CONFIG_UT_DM) += read.o
obj-$(CONFIG_UT_DM) += phys2bus.o
+ifeq ($(CONFIG_NVMXIP_QSPI)$(CONFIG_SANDBOX64),yy)
+obj-y += nvmxip.o
+endif
+
ifneq ($(CONFIG_SANDBOX),)
ifeq ($(CONFIG_ACPIGEN),y)
obj-y += acpi.o
@@ -29,6 +34,7 @@ obj-$(CONFIG_ADC) += adc.o
obj-$(CONFIG_SOUND) += audio.o
obj-$(CONFIG_AXI) += axi.o
obj-$(CONFIG_BLK) += blk.o
+obj-$(CONFIG_BLKMAP) += blkmap.o
obj-$(CONFIG_BUTTON) += button.o
obj-$(CONFIG_DM_BOOTCOUNT) += bootcount.o
obj-$(CONFIG_DM_REBOOT_MODE) += reboot-mode.o
@@ -43,6 +49,7 @@ obj-$(CONFIG_DM_DSA) += dsa.o
obj-$(CONFIG_ECDSA_VERIFY) += ecdsa.o
obj-$(CONFIG_EFI_MEDIA_SANDBOX) += efi_media.o
obj-$(CONFIG_DM_ETH) += eth.o
+obj-$(CONFIG_EXTCON) += extcon.o
ifneq ($(CONFIG_EFI_PARTITION),)
obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o
endif
diff --git a/test/dm/blkmap.c b/test/dm/blkmap.c
new file mode 100644
index 00000000000..7a163d6eaef
--- /dev/null
+++ b/test/dm/blkmap.c
@@ -0,0 +1,201 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2023 Addiva Elektronik
+ * Author: Tobias Waldekranz <[email protected]>
+ */
+
+#include <common.h>
+#include <blk.h>
+#include <blkmap.h>
+#include <dm.h>
+#include <asm/test.h>
+#include <dm/test.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+#define BLKSZ 0x200
+
+struct mapping {
+ int src;
+ int cnt;
+ int dst;
+};
+
+const struct mapping unordered_mapping[] = {
+ { 0, 1, 3 },
+ { 1, 3, 0 },
+ { 4, 2, 6 },
+ { 6, 2, 4 },
+
+ { 0, 0, 0 }
+};
+
+const struct mapping identity_mapping[] = {
+ { 0, 8, 0 },
+
+ { 0, 0, 0 }
+};
+
+static char identity[8 * BLKSZ];
+static char unordered[8 * BLKSZ];
+static char buffer[8 * BLKSZ];
+
+static void mkblob(void *base, const struct mapping *m)
+{
+ int nr;
+
+ for (; m->cnt; m++) {
+ for (nr = 0; nr < m->cnt; nr++) {
+ memset(base + (m->dst + nr) * BLKSZ,
+ m->src + nr, BLKSZ);
+ }
+ }
+}
+
+static int dm_test_blkmap_read(struct unit_test_state *uts)
+{
+ struct udevice *dev, *blk;
+ const struct mapping *m;
+
+ ut_assertok(blkmap_create("rdtest", &dev));
+ ut_assertok(blk_get_from_parent(dev, &blk));
+
+ /* Generate an ordered and an unordered pattern in memory */
+ mkblob(unordered, unordered_mapping);
+ mkblob(identity, identity_mapping);
+
+ /* Create a blkmap that cancels out the disorder */
+ for (m = unordered_mapping; m->cnt; m++) {
+ ut_assertok(blkmap_map_mem(dev, m->src, m->cnt,
+ unordered + m->dst * BLKSZ));
+ }
+
+ /* Read out the data via the blkmap device to another area,
+ * and verify that it matches the ordered pattern.
+ */
+ ut_asserteq(8, blk_read(blk, 0, 8, buffer));
+ ut_assertok(memcmp(buffer, identity, sizeof(buffer)));
+
+ ut_assertok(blkmap_destroy(dev));
+ return 0;
+}
+DM_TEST(dm_test_blkmap_read, 0);
+
+static int dm_test_blkmap_write(struct unit_test_state *uts)
+{
+ struct udevice *dev, *blk;
+ const struct mapping *m;
+
+ ut_assertok(blkmap_create("wrtest", &dev));
+ ut_assertok(blk_get_from_parent(dev, &blk));
+
+ /* Generate an ordered and an unordered pattern in memory */
+ mkblob(unordered, unordered_mapping);
+ mkblob(identity, identity_mapping);
+
+ /* Create a blkmap that mimics the disorder */
+ for (m = unordered_mapping; m->cnt; m++) {
+ ut_assertok(blkmap_map_mem(dev, m->src, m->cnt,
+ buffer + m->dst * BLKSZ));
+ }
+
+ /* Write the ordered data via the blkmap device to another
+ * area, and verify that the result matches the unordered
+ * pattern.
+ */
+ ut_asserteq(8, blk_write(blk, 0, 8, identity));
+ ut_assertok(memcmp(buffer, unordered, sizeof(buffer)));
+
+ ut_assertok(blkmap_destroy(dev));
+ return 0;
+}
+DM_TEST(dm_test_blkmap_write, 0);
+
+static int dm_test_blkmap_slicing(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+
+ ut_assertok(blkmap_create("slicetest", &dev));
+
+ ut_assertok(blkmap_map_mem(dev, 8, 8, NULL));
+
+ /* Can't overlap on the low end */
+ ut_asserteq(-EBUSY, blkmap_map_mem(dev, 4, 5, NULL));
+ /* Can't be inside */
+ ut_asserteq(-EBUSY, blkmap_map_mem(dev, 10, 2, NULL));
+ /* Can't overlap on the high end */
+ ut_asserteq(-EBUSY, blkmap_map_mem(dev, 15, 4, NULL));
+
+ /* But we should be able to add slices right before and
+ * after
+ */
+ ut_assertok(blkmap_map_mem(dev, 4, 4, NULL));
+ ut_assertok(blkmap_map_mem(dev, 16, 4, NULL));
+
+ ut_assertok(blkmap_destroy(dev));
+ return 0;
+}
+DM_TEST(dm_test_blkmap_slicing, 0);
+
+static int dm_test_blkmap_creation(struct unit_test_state *uts)
+{
+ struct udevice *first, *second;
+
+ ut_assertok(blkmap_create("first", &first));
+
+ /* Can't have two "first"s */
+ ut_asserteq(-EBUSY, blkmap_create("first", &second));
+
+ /* But "second" should be fine */
+ ut_assertok(blkmap_create("second", &second));
+
+ /* Once "first" is destroyed, we should be able to create it
+ * again
+ */
+ ut_assertok(blkmap_destroy(first));
+ ut_assertok(blkmap_create("first", &first));
+
+ ut_assertok(blkmap_destroy(first));
+ ut_assertok(blkmap_destroy(second));
+ return 0;
+}
+DM_TEST(dm_test_blkmap_creation, 0);
+
+static int dm_test_cmd_blkmap(struct unit_test_state *uts)
+{
+ ulong loadaddr = env_get_hex("loadaddr", 0);
+ struct udevice *dev;
+
+ console_record_reset();
+
+ ut_assertok(run_command("blkmap info", 0));
+ ut_assert_console_end();
+
+ ut_assertok(run_command("blkmap create ramdisk", 0));
+ ut_assert_nextline("Created \"ramdisk\"");
+ ut_assert_console_end();
+
+ ut_assertnonnull((dev = blkmap_from_label("ramdisk")));
+
+ ut_assertok(run_commandf("blkmap map ramdisk 0 800 mem 0x%lx", loadaddr));
+ ut_assert_nextline("Block 0x0+0x800 mapped to 0x%lx", loadaddr);
+ ut_assert_console_end();
+
+ ut_assertok(run_command("blkmap info", 0));
+ ut_assert_nextline("Device 0: Vendor: U-Boot Rev: 1.0 Prod: blkmap");
+ ut_assert_nextline(" Type: Hard Disk");
+ ut_assert_nextline(" Capacity: 1.0 MB = 0.0 GB (2048 x 512)");
+ ut_assert_console_end();
+
+ ut_assertok(run_command("blkmap get ramdisk dev devnum", 0));
+ ut_asserteq(dev_seq(dev), env_get_hex("devnum", 0xdeadbeef));
+
+ ut_assertok(run_command("blkmap destroy ramdisk", 0));
+ ut_assert_nextline("Destroyed \"ramdisk\"");
+ ut_assert_console_end();
+
+ ut_assertok(run_command("blkmap info", 0));
+ ut_assert_console_end();
+ return 0;
+}
+DM_TEST(dm_test_cmd_blkmap, 0);
diff --git a/test/dm/eth.c b/test/dm/eth.c
index ebf01d8cf38..d05d2a9abe1 100644
--- a/test/dm/eth.c
+++ b/test/dm/eth.c
@@ -20,6 +20,7 @@
#include <dm/uclass-internal.h>
#include <test/test.h>
#include <test/ut.h>
+#include <ndisc.h>
#define DM_TEST_ETH_NUM 4
@@ -607,3 +608,90 @@ static int dm_test_eth_async_ping_reply(struct unit_test_state *uts)
}
DM_TEST(dm_test_eth_async_ping_reply, UT_TESTF_SCAN_FDT);
+
+#if IS_ENABLED(CONFIG_IPV6_ROUTER_DISCOVERY)
+
+static u8 ip6_ra_buf[] = {0x60, 0xf, 0xc5, 0x4a, 0x0, 0x38, 0x3a, 0xff, 0xfe,
+ 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x85, 0xe6,
+ 0x29, 0x77, 0xcb, 0xc8, 0x53, 0xff, 0x2, 0x0, 0x0,
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+ 0x1, 0x86, 0x0, 0xdc, 0x90, 0x40, 0x80, 0x15, 0x18,
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x4,
+ 0x40, 0xc0, 0x0, 0x0, 0x37, 0xdc, 0x0, 0x0, 0x37,
+ 0x78, 0x0, 0x0, 0x0, 0x0, 0x20, 0x1, 0xca, 0xfe, 0xca,
+ 0xfe, 0xca, 0xfe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0x1, 0x1, 0x0, 0x15, 0x5d, 0xe2, 0x8a, 0x2};
+
+static int dm_test_validate_ra(struct unit_test_state *uts)
+{
+ struct ip6_hdr *ip6 = (struct ip6_hdr *)ip6_ra_buf;
+ struct icmp6hdr *icmp = (struct icmp6hdr *)(ip6 + 1);
+ __be16 temp = 0;
+
+ ut_assert(validate_ra(ip6) == true);
+
+ temp = ip6->payload_len;
+ ip6->payload_len = 15;
+ ut_assert(validate_ra(ip6) == false);
+ ip6->payload_len = temp;
+
+ temp = ip6->saddr.s6_addr16[0];
+ ip6->saddr.s6_addr16[0] = 0x2001;
+ ut_assert(validate_ra(ip6) == false);
+ ip6->saddr.s6_addr16[0] = temp;
+
+ temp = ip6->hop_limit;
+ ip6->hop_limit = 15;
+ ut_assert(validate_ra(ip6) == false);
+ ip6->hop_limit = temp;
+
+ temp = icmp->icmp6_code;
+ icmp->icmp6_code = 15;
+ ut_assert(validate_ra(ip6) == false);
+ icmp->icmp6_code = temp;
+
+ return 0;
+}
+
+DM_TEST(dm_test_validate_ra, 0);
+
+static int dm_test_process_ra(struct unit_test_state *uts)
+{
+ int len = sizeof(ip6_ra_buf);
+ struct ip6_hdr *ip6 = (struct ip6_hdr *)ip6_ra_buf;
+ struct icmp6hdr *icmp = (struct icmp6hdr *)(ip6 + 1);
+ struct ra_msg *msg = (struct ra_msg *)icmp;
+ unsigned char *option = msg->opt;
+ struct icmp6_ra_prefix_info *prefix =
+ (struct icmp6_ra_prefix_info *)option;
+ __be16 temp = 0;
+ unsigned char option_len = option[1];
+
+ ut_assert(process_ra(ip6, len) == 0);
+
+ temp = icmp->icmp6_rt_lifetime;
+ icmp->icmp6_rt_lifetime = 0;
+ ut_assert(process_ra(ip6, len) != 0);
+ icmp->icmp6_rt_lifetime = temp;
+
+ ut_assert(process_ra(ip6, 0) != 0);
+
+ option[1] = 0;
+ ut_assert(process_ra(ip6, len) != 0);
+ option[1] = option_len;
+
+ prefix->on_link = false;
+ ut_assert(process_ra(ip6, len) != 0);
+ prefix->on_link = true;
+
+ temp = prefix->prefix.s6_addr16[0];
+ prefix->prefix.s6_addr16[0] = 0x80fe;
+ ut_assert(process_ra(ip6, len) != 0);
+ prefix->prefix.s6_addr16[0] = temp;
+
+ return 0;
+}
+
+DM_TEST(dm_test_process_ra, 0);
+
+#endif
diff --git a/test/dm/extcon.c b/test/dm/extcon.c
new file mode 100644
index 00000000000..6a4e22bfdc5
--- /dev/null
+++ b/test/dm/extcon.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2023 Svyatoslav Ryhel <[email protected]>
+ */
+
+#include <dm.h>
+#include <dm/test.h>
+#include <extcon.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+static int dm_test_extcon(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+
+ ut_assertok(uclass_get_device_by_name(UCLASS_EXTCON, "extcon", &dev));
+
+ return 0;
+}
+
+DM_TEST(dm_test_extcon, UT_TESTF_SCAN_FDT);
diff --git a/test/dm/mmc.c b/test/dm/mmc.c
index f744452ff24..b1eb8bee2f9 100644
--- a/test/dm/mmc.c
+++ b/test/dm/mmc.c
@@ -30,7 +30,7 @@ static int dm_test_mmc_blk(struct unit_test_state *uts)
struct udevice *dev;
struct blk_desc *dev_desc;
int i;
- char write[1024], read[1024];
+ char write[4 * 512], read[4 * 512];
ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev));
ut_assertok(blk_get_device_by_str("mmc", "0", &dev_desc));
@@ -39,14 +39,14 @@ static int dm_test_mmc_blk(struct unit_test_state *uts)
ut_asserteq(512, dev_desc->blksz);
for (i = 0; i < sizeof(write); i++)
write[i] = i;
- ut_asserteq(2, blk_dwrite(dev_desc, 0, 2, write));
- ut_asserteq(2, blk_dread(dev_desc, 0, 2, read));
+ ut_asserteq(4, blk_dwrite(dev_desc, 0, 4, write));
+ ut_asserteq(4, blk_dread(dev_desc, 0, 4, read));
ut_asserteq_mem(write, read, sizeof(write));
- /* Now erase them */
- memset(write, '\0', sizeof(write));
- ut_asserteq(2, blk_derase(dev_desc, 0, 2));
- ut_asserteq(2, blk_dread(dev_desc, 0, 2, read));
+ /* Now erase two of them [1 - 2] and verify all blocks */
+ memset(&write[512], '\0', 2 * 512);
+ ut_asserteq(2, blk_derase(dev_desc, 1, 2));
+ ut_asserteq(4, blk_dread(dev_desc, 0, 4, read));
ut_asserteq_mem(write, read, sizeof(write));
return 0;
diff --git a/test/dm/nvmxip.c b/test/dm/nvmxip.c
new file mode 100644
index 00000000000..e934748eb5d
--- /dev/null
+++ b/test/dm/nvmxip.c
@@ -0,0 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Functional tests for UCLASS_FFA class
+ *
+ * Copyright 2023 Arm Limited and/or its affiliates <[email protected]>
+ *
+ * Authors:
+ * Abdellatif El Khlifi <[email protected]>
+ */
+
+#include <common.h>
+#include <blk.h>
+#include <console.h>
+#include <dm.h>
+#include <mapmem.h>
+#include <dm/test.h>
+#include <linux/bitops.h>
+#include <test/test.h>
+#include <test/ut.h>
+#include "../../drivers/mtd/nvmxip/nvmxip.h"
+
+/* NVMXIP devices described in the device tree */
+#define SANDBOX_NVMXIP_DEVICES 2
+
+/* reference device tree data for the probed devices */
+static struct nvmxip_plat nvmqspi_refdata[SANDBOX_NVMXIP_DEVICES] = {
+ {0x08000000, 9, 4096}, {0x08200000, 9, 2048}
+};
+
+#define NVMXIP_BLK_START_PATTERN 0x1122334455667788ULL
+#define NVMXIP_BLK_END_PATTERN 0xa1a2a3a4a5a6a7a8ULL
+
+/**
+ * dm_nvmxip_flash_sanity() - check flash data
+ * @uts: test state
+ * @device_idx: the NVMXIP device index
+ * @buffer: the user buffer where the blocks data is copied to
+ *
+ * Mode 1: When buffer is NULL, initialize the flash with pattern data at the start
+ * and at the end of each block. This pattern data will be used to check data consistency
+ * when verifying the data read.
+ * Mode 2: When the user buffer is provided in the argument (not NULL), compare the data
+ * of the start and the end of each block in the user buffer with the expected pattern data.
+ * Return an error when the check fails.
+ *
+ * Return:
+ *
+ * 0 on success. Otherwise, failure
+ */
+static int dm_nvmxip_flash_sanity(struct unit_test_state *uts, u8 device_idx, void *buffer)
+{
+ int i;
+ u64 *ptr;
+ u8 *base;
+ unsigned long blksz;
+
+ blksz = BIT(nvmqspi_refdata[device_idx].lba_shift);
+
+ if (!buffer) {
+ /* Mode 1: point at the flash start address. Pattern data will be written */
+ base = map_sysmem(nvmqspi_refdata[device_idx].phys_base, 0);
+ } else {
+ /* Mode 2: point at the user buffer containing the data read and to be verified */
+ base = buffer;
+ }
+
+ for (i = 0; i < nvmqspi_refdata[device_idx].lba ; i++) {
+ ptr = (u64 *)(base + i * blksz);
+
+ /* write an 8 bytes pattern at the start of the current block */
+ if (!buffer)
+ *ptr = NVMXIP_BLK_START_PATTERN;
+ else
+ ut_asserteq_64(NVMXIP_BLK_START_PATTERN, *ptr);
+
+ ptr = (u64 *)((u8 *)ptr + blksz - sizeof(u64));
+
+ /* write an 8 bytes pattern at the end of the current block */
+ if (!buffer)
+ *ptr = NVMXIP_BLK_END_PATTERN;
+ else
+ ut_asserteq_64(NVMXIP_BLK_END_PATTERN, *ptr);
+ }
+
+ if (!buffer)
+ unmap_sysmem(base);
+
+ return 0;
+}
+
+/**
+ * dm_test_nvmxip() - check flash data
+ * @uts: test state
+ * Return:
+ *
+ * CMD_RET_SUCCESS on success. Otherwise, failure
+ */
+static int dm_test_nvmxip(struct unit_test_state *uts)
+{
+ struct nvmxip_plat *plat_data = NULL;
+ struct udevice *dev = NULL, *bdev = NULL;
+ u8 device_idx;
+ void *buffer = NULL;
+ unsigned long flashsz;
+
+ /* set the flash content first for both devices */
+ dm_nvmxip_flash_sanity(uts, 0, NULL);
+ dm_nvmxip_flash_sanity(uts, 1, NULL);
+
+ /* probing all NVM XIP QSPI devices */
+ for (device_idx = 0, uclass_first_device(UCLASS_NVMXIP, &dev);
+ dev;
+ uclass_next_device(&dev), device_idx++) {
+ plat_data = dev_get_plat(dev);
+
+ /* device tree entries checks */
+ ut_assertok(nvmqspi_refdata[device_idx].phys_base != plat_data->phys_base);
+ ut_assertok(nvmqspi_refdata[device_idx].lba_shift != plat_data->lba_shift);
+ ut_assertok(nvmqspi_refdata[device_idx].lba != plat_data->lba);
+
+ /* before reading all the flash blocks, let's calculate the flash size */
+ flashsz = plat_data->lba << plat_data->lba_shift;
+
+ /* allocate the user buffer where to copy the blocks data to */
+ buffer = calloc(flashsz, 1);
+ ut_assertok(!buffer);
+
+ /* the block device is the child of the parent device probed with DT */
+ ut_assertok(device_find_first_child(dev, &bdev));
+
+ /* reading all the flash blocks */
+ ut_asserteq(plat_data->lba, blk_read(bdev, 0, plat_data->lba, buffer));
+
+ /* compare the data read from flash with the expected data */
+ dm_nvmxip_flash_sanity(uts, device_idx, buffer);
+
+ free(buffer);
+ }
+
+ ut_assertok(device_idx != SANDBOX_NVMXIP_DEVICES);
+
+ return CMD_RET_SUCCESS;
+}
+
+DM_TEST(dm_test_nvmxip, UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index 8e6e42e46b4..eeecd1dc2de 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -617,6 +617,7 @@ static int dm_test_fdt_get_addr_ptr_flat(struct unit_test_state *uts)
{
struct udevice *gpio, *dev;
void *ptr;
+ void *paddr;
/* Test for missing reg property */
ut_assertok(uclass_first_device_err(UCLASS_GPIO, &gpio));
@@ -624,7 +625,9 @@ static int dm_test_fdt_get_addr_ptr_flat(struct unit_test_state *uts)
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev));
ptr = devfdt_get_addr_ptr(dev);
- ut_asserteq_ptr((void *)0x8000, ptr);
+
+ paddr = map_sysmem(0x8000, 0);
+ ut_asserteq_ptr(paddr, ptr);
return 0;
}
diff --git a/test/lib/Kconfig b/test/lib/Kconfig
index dbb03e4a36f..ae0aa2ff7ac 100644
--- a/test/lib/Kconfig
+++ b/test/lib/Kconfig
@@ -1,23 +1,24 @@
# SPDX-License-Identifier: GPL-2.0+
# Copyright 2022 Google LLC
-if SANDBOX
-
config TEST_KCONFIG
bool "Enable detection of Kconfig macro errors"
+ depends on SANDBOX
help
This is used to test that the IF_ENABLED_INT() macro causes a build error
- if the value is used when the CONFIG Is not enabled.
+ if the value is used when the CONFIG is not enabled.
+
+if TEST_KCONFIG
config TEST_KCONFIG_ENABLE
- bool "Option to enable"
+ bool "Provide a value for the Kconfig test"
help
This is the option that controls whether the value is present.
config TEST_KCONFIG_VALUE
- int "Value associated with the option"
+ int "Value used in Kconfig test"
depends on TEST_KCONFIG_ENABLE
help
- This is the value whgch is present if TEST_KCONFIG_ENABLE is enabled.
+ This is the value which is present if TEST_KCONFIG_ENABLE is enabled.
-endif # SANDBOX
+endif # TEST_KCONFIG
diff --git a/test/py/requirements.txt b/test/py/requirements.txt
index e241780f923..86d6266053f 100644
--- a/test/py/requirements.txt
+++ b/test/py/requirements.txt
@@ -8,21 +8,21 @@ fixtures==3.0.0
importlib-metadata==0.23
linecache2==1.0.0
more-itertools==7.2.0
-packaging==19.2
+packaging==21.3
pbr==5.4.3
pluggy==0.13.0
py==1.10.0
pycryptodomex==3.9.8
pyelftools==0.27
pygit2==1.9.2
-pyparsing==2.4.2
+pyparsing==3.0.7
pytest==6.2.5
pytest-xdist==2.5.0
python-mimeparse==1.6.0
python-subunit==1.3.0
-requests==2.25.1
+requests==2.27.1
setuptools==58.3.0
-six==1.12.0
+six==1.16.0
testtools==2.3.0
traceback2==1.4.0
unittest2==1.1.0
diff --git a/test/py/tests/test_android/test_abootimg.py b/test/py/tests/test_android/test_abootimg.py
index 43a7099c466..6a8ff34538b 100644
--- a/test/py/tests/test_android/test_abootimg.py
+++ b/test/py/tests/test_android/test_abootimg.py
@@ -32,6 +32,23 @@ Now one can obtain original boot.img from this hex dump like this:
$ xxd -r -p boot.img.gz.hex boot.img.gz
$ gunzip -9 boot.img.gz
+
+For boot image header version 4, these tests rely on two images that are generated
+using the same steps above :
+
+1- boot.img :
+ $ mkbootimg --kernel ./kernel --ramdisk ./ramdisk.img \
+ --cmdline "cmdline test" --dtb ./dtb.img \
+ --os_version R --os_patch_level 2019-06-05 \
+ --header_version 4 --output ./boot.img
+
+2- vendor_boot.img
+ $ mkbootimg --kernel ./kernel --ramdisk ./ramdisk.img \
+ --cmdline "cmdline test" --dtb ./dtb.img \
+ --os_version R --os_patch_level 2019-06-05 \
+ --pagesize 4096 --vendor_ramdisk ./ramdisk.img \
+ --header_version 4 --vendor_boot ./vboot.img \
+
"""
# boot.img.gz hex dump
@@ -44,6 +61,24 @@ b7762ffff07d345446c1281805e8a0868d81e117a45e111c0d8dc101b253
9c03c41a0c90f17fe85400986d82452b6c3680198a192a0ce17c3610ae34
d4a9820881a70f3873f35352731892f3730b124b32937252a96bb9119ae5
463a5546f82c1f05a360148c8251300a462e000085bf67f200200000"""
+
+# boot img v4 hex dump
+boot_img_hex = """1f8b080827b0cd630203626f6f742e696d6700edd8bd0d82601885d1d7c4
+58d8c808b88195bd098d8d246e40e42b083f1aa0717be99d003d277916b8
+e5bddc8a7b792d8e8788c896ce9b88d32ebe6c971e7ddd3543cae734cd01
+c0ffc84c0000b0766d1a87d4e5afeadd3dab7a6f10000000f84163d5d7cd
+d43a000000000000000060c53e7544995700400000"""
+
+# vendor boot image v4 hex dump
+vboot_img_hex = """1f8b0808baaecd63020376626f6f742e696d6700edd8310b824018c6f1b3
+222a08f41b3436b4280dcdd19c11d16ee9109d18d59042d047ec8b04cd0d
+d19d5a4345534bf6ffc173ef29272f38e93b1d0ec67dd79d548462aa1cd2
+d5d20b0000f8438678f90c18d584b8a4bbb3a557991ecb2a0000f80d6b2f
+f4179b656be5c532f2fc066f040000000080e23936af2755f62a3d918df1
+db2a7ab67f9ffdeb7df7cda3465ecb79c4ce7e5c577562bb9364b74449a5
+1e467e20c53c0a57de763193c1779b3b4fcd9d4ee27c6a0e00000000c0ff
+309ffea7010000000040f1dc004129855400400000"""
+
# Expected response for "abootimg dtb_dump" command
dtb_dump_resp="""## DTB area contents (concat format):
- DTB #0:
@@ -56,15 +91,21 @@ dtb_dump_resp="""## DTB area contents (concat format):
(DTB)compatible = y2,z2"""
# Address in RAM where to load the boot image ('abootimg' looks in $loadaddr)
loadaddr = 0x1000
+# Address in RAM where to load the vendor boot image ('abootimg' looks in $vloadaddr)
+vloadaddr= 0x10000
# Expected DTB #1 offset from the boot image start address
dtb1_offset = 0x187d
+# Expected DTB offset from the vendor boot image start address
+dtb2_offset = 0x207d
# DTB #1 start address in RAM
dtb1_addr = loadaddr + dtb1_offset
+# DTB #2 start address in RAM
+dtb2_addr = vloadaddr + dtb2_offset
class AbootimgTestDiskImage(object):
"""Disk image used by abootimg tests."""
- def __init__(self, u_boot_console):
+ def __init__(self, u_boot_console, image_name, hex_img):
"""Initialize a new AbootimgDiskImage object.
Args:
@@ -74,13 +115,13 @@ class AbootimgTestDiskImage(object):
Nothing.
"""
- gz_hex = u_boot_console.config.persistent_data_dir + '/boot.img.gz.hex'
- gz = u_boot_console.config.persistent_data_dir + '/boot.img.gz'
+ gz_hex = u_boot_console.config.persistent_data_dir + '/' + image_name + '.gz.hex'
+ gz = u_boot_console.config.persistent_data_dir + '/' + image_name + '.gz'
- filename = 'boot.img'
+ filename = image_name
persistent = u_boot_console.config.persistent_data_dir + '/' + filename
self.path = u_boot_console.config.result_dir + '/' + filename
-
+ u_boot_console.log.action('persistent is ' + persistent)
with u_boot_utils.persistent_file_helper(u_boot_console.log, persistent):
if os.path.exists(persistent):
u_boot_console.log.action('Disk image file ' + persistent +
@@ -89,19 +130,17 @@ class AbootimgTestDiskImage(object):
u_boot_console.log.action('Generating ' + persistent)
f = open(gz_hex, "w")
- f.write(img_hex)
+ f.write(hex_img)
f.close()
-
cmd = ('xxd', '-r', '-p', gz_hex, gz)
u_boot_utils.run_and_log(u_boot_console, cmd)
-
cmd = ('gunzip', '-9', gz)
u_boot_utils.run_and_log(u_boot_console, cmd)
cmd = ('cp', persistent, self.path)
u_boot_utils.run_and_log(u_boot_console, cmd)
-gtdi = None
+gtdi1 = None
@pytest.fixture(scope='function')
def abootimg_disk_image(u_boot_console):
"""pytest fixture to provide a AbootimgTestDiskImage object to tests.
@@ -109,10 +148,36 @@ def abootimg_disk_image(u_boot_console):
function-scoped. However, we don't need to actually do any function-scope
work, so this simply returns the same object over and over each time."""
- global gtdi
- if not gtdi:
- gtdi = AbootimgTestDiskImage(u_boot_console)
- return gtdi
+ global gtdi1
+ if not gtdi1:
+ gtdi1 = AbootimgTestDiskImage(u_boot_console, 'boot.img', img_hex)
+ return gtdi1
+
+gtdi2 = None
[email protected](scope='function')
+def abootimgv4_disk_image_vboot(u_boot_console):
+ """pytest fixture to provide a AbootimgTestDiskImage object to tests.
+ This is function-scoped because it uses u_boot_console, which is also
+ function-scoped. However, we don't need to actually do any function-scope
+ work, so this simply returns the same object over and over each time."""
+
+ global gtdi2
+ if not gtdi2:
+ gtdi2 = AbootimgTestDiskImage(u_boot_console, 'vendor_boot.img', vboot_img_hex)
+ return gtdi2
+
+gtdi3 = None
[email protected](scope='function')
+def abootimgv4_disk_image_boot(u_boot_console):
+ """pytest fixture to provide a AbootimgTestDiskImage object to tests.
+ This is function-scoped because it uses u_boot_console, which is also
+ function-scoped. However, we don't need to actually do any function-scope
+ work, so this simply returns the same object over and over each time."""
+
+ global gtdi3
+ if not gtdi3:
+ gtdi3 = AbootimgTestDiskImage(u_boot_console, 'bootv4.img', boot_img_hex)
+ return gtdi3
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('android_boot_image')
@@ -157,3 +222,48 @@ def test_abootimg(abootimg_disk_image, u_boot_console):
u_boot_console.run_command('fdt get value v / model')
response = u_boot_console.run_command('env print v')
assert response == 'v=x2'
+
[email protected]('android_boot_image')
[email protected]('cmd_abootimg')
+def test_abootimgv4(abootimgv4_disk_image_vboot, abootimgv4_disk_image_boot, u_boot_console):
+ """Test the 'abootimg' command with boot image header v4."""
+
+ cons = u_boot_console
+ cons.log.action('Loading disk image to RAM...')
+ cons.run_command('setenv loadaddr 0x%x' % (loadaddr))
+ cons.run_command('setenv vloadaddr 0x%x' % (vloadaddr))
+ cons.run_command('host load hostfs - 0x%x %s' % (vloadaddr,
+ abootimgv4_disk_image_vboot.path))
+ cons.run_command('host load hostfs - 0x%x %s' % (loadaddr,
+ abootimgv4_disk_image_boot.path))
+ cons.run_command('abootimg addr 0x%x 0x%x' % (loadaddr, vloadaddr))
+ cons.log.action('Testing \'abootimg get ver\'...')
+ response = cons.run_command('abootimg get ver')
+ assert response == "4"
+ cons.run_command('abootimg get ver v')
+ response = cons.run_command('env print v')
+ assert response == 'v=4'
+
+ cons.log.action('Testing \'abootimg get recovery_dtbo\'...')
+ response = cons.run_command('abootimg get recovery_dtbo a')
+ assert response == 'Error: header version must be >= 1 and <= 2 to get dtbo'
+
+ cons.log.action('Testing \'abootimg get dtb_load_addr\'...')
+ cons.run_command('abootimg get dtb_load_addr a')
+ response = cons.run_command('env print a')
+ assert response == 'a=11f00000'
+
+ cons.log.action('Testing \'abootimg get dtb --index\'...')
+ cons.run_command('abootimg get dtb --index=1 dtb2_start')
+ response = cons.run_command('env print dtb2_start')
+ correct_str = "dtb2_start=%x" % (dtb2_addr)
+ assert response == correct_str
+
+ cons.run_command('fdt addr $dtb2_start')
+ cons.run_command('fdt get value v / model')
+ response = cons.run_command('env print v')
+ assert response == 'v=x2'
diff --git a/test/py/tests/test_efi_bootmgr/conftest.py b/test/py/tests/test_efi_bootmgr/conftest.py
index a0a754afbe1..eabafa54298 100644
--- a/test/py/tests/test_efi_bootmgr/conftest.py
+++ b/test/py/tests/test_efi_bootmgr/conftest.py
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: GPL-2.0+
-"""Fixture for UEFI bootmanager test
-"""
+"""Fixture for UEFI bootmanager test."""
import os
import shutil
@@ -10,8 +9,7 @@ import pytest
@pytest.fixture(scope='session')
def efi_bootmgr_data(u_boot_config):
- """Set up a file system to be used in UEFI bootmanager
- tests
+ """Set up a file system to be used in UEFI bootmanager tests.
Args:
u_boot_config -- U-boot configuration.
diff --git a/test/py/tests/test_efi_capsule/capsule_defs.py b/test/py/tests/test_efi_capsule/capsule_defs.py
index 59b40f11bd1..3cc695e29b5 100644
--- a/test/py/tests/test_efi_capsule/capsule_defs.py
+++ b/test/py/tests/test_efi_capsule/capsule_defs.py
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: GPL-2.0+
+"""Directoreis used for authentication and capsule tests."""
+
# Directories
CAPSULE_DATA_DIR = '/EFI/CapsuleTestData'
CAPSULE_INSTALL_DIR = '/EFI/UpdateCapsule'
diff --git a/test/py/tests/test_efi_capsule/conftest.py b/test/py/tests/test_efi_capsule/conftest.py
index 4879f2b5c24..a337e629362 100644
--- a/test/py/tests/test_efi_capsule/conftest.py
+++ b/test/py/tests/test_efi_capsule/conftest.py
@@ -2,31 +2,23 @@
# Copyright (c) 2020, Linaro Limited
# Author: AKASHI Takahiro <[email protected]>
-import os
-import os.path
-import re
-from subprocess import call, check_call, check_output, CalledProcessError
-import pytest
-from capsule_defs import *
+"""Fixture for UEFI capsule test."""
-#
-# Fixture for UEFI capsule test
-#
+from subprocess import call, check_call, CalledProcessError
+import pytest
+from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR, EFITOOLS_PATH
@pytest.fixture(scope='session')
def efi_capsule_data(request, u_boot_config):
- """Set up a file system to be used in UEFI capsule and
- authentication test.
+ """Set up a file system and return path to image.
- Args:
- request: Pytest request object.
- u_boot_config: U-boot configuration.
+ The function sets up a file system to be used in UEFI capsule and
+ authentication test and returns a path to disk image to be used
+ for testing.
- Return:
- A path to disk image to be used for testing
+ request -- Pytest request object.
+ u_boot_config -- U-boot configuration.
"""
- global CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR
-
mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule'
data_dir = mnt_point + CAPSULE_DATA_DIR
install_dir = mnt_point + CAPSULE_INSTALL_DIR
diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py
index d28b53a1a15..9ee152818d6 100644
--- a/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py
+++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py
@@ -1,16 +1,13 @@
# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2020, Linaro Limited
# Author: AKASHI Takahiro <[email protected]>
-#
-# U-Boot UEFI: Firmware Update Test
-"""
+"""U-Boot UEFI: Firmware Update Test
This test verifies capsule-on-disk firmware update for FIT images
"""
-from subprocess import check_call, check_output, CalledProcessError
import pytest
-from capsule_defs import *
+from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR
@pytest.mark.boardspec('sandbox_flattree')
@@ -24,15 +21,18 @@ from capsule_defs import *
@pytest.mark.buildconfigspec('cmd_nvedit_efi')
@pytest.mark.buildconfigspec('cmd_sf')
@pytest.mark.slow
-class TestEfiCapsuleFirmwareFit(object):
+class TestEfiCapsuleFirmwareFit():
+ """Test capsule-on-disk firmware update for FIT images
+ """
+
def test_efi_capsule_fw1(
self, u_boot_config, u_boot_console, efi_capsule_data):
- """
- Test Case 1 - Update U-Boot and U-Boot environment on SPI Flash
- but with an incorrect GUID value in the capsule
- No update should happen
- 0x100000-0x150000: U-Boot binary (but dummy)
- 0x150000-0x200000: U-Boot environment (but dummy)
+ """Test Case 1
+ Update U-Boot and U-Boot environment on SPI Flash
+ but with an incorrect GUID value in the capsule
+ No update should happen
+ 0x100000-0x150000: U-Boot binary (but dummy)
+ 0x150000-0x200000: U-Boot environment (but dummy)
"""
# other tests might have run and the
# system might not be in a clean state.
@@ -74,8 +74,6 @@ class TestEfiCapsuleFirmwareFit(object):
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
- capsule_auth = u_boot_config.buildconfig.get(
- 'config_efi_capsule_authenticate')
# reboot
u_boot_console.restart_uboot(expect_reset = capsule_early)
@@ -107,11 +105,12 @@ class TestEfiCapsuleFirmwareFit(object):
def test_efi_capsule_fw2(
self, u_boot_config, u_boot_console, efi_capsule_data):
+ """Test Case 2
+ Update U-Boot and U-Boot environment on SPI Flash
+ 0x100000-0x150000: U-Boot binary (but dummy)
+ 0x150000-0x200000: U-Boot environment (but dummy)
"""
- Test Case 2 - Update U-Boot and U-Boot environment on SPI Flash
- 0x100000-0x150000: U-Boot binary (but dummy)
- 0x150000-0x200000: U-Boot environment (but dummy)
- """
+
disk_img = efi_capsule_data
with u_boot_console.log.section('Test Case 2-a, before reboot'):
output = u_boot_console.run_command_list([
diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py
index 8c2d616fd06..ba8429e83cb 100644
--- a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py
+++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py
@@ -3,10 +3,8 @@
# Copyright (c) 2022, Arm Limited
# Author: AKASHI Takahiro <[email protected]>,
# adapted to FIT images by Vincent StehlĂ© <[email protected]>
-#
-# U-Boot UEFI: Firmware Update (Signed capsule with FIT images) Test
-"""
+"""U-Boot UEFI: Firmware Update (Signed capsule with FIT images) Test
This test verifies capsule-on-disk firmware update
with signed capsule files containing FIT images
"""
@@ -25,15 +23,18 @@ from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR
@pytest.mark.buildconfigspec('cmd_nvedit_efi')
@pytest.mark.buildconfigspec('cmd_sf')
@pytest.mark.slow
-class TestEfiCapsuleFirmwareSignedFit(object):
+class TestEfiCapsuleFirmwareSignedFit():
+ """Capsule-on-disk firmware update test
+ """
+
def test_efi_capsule_auth1(
self, u_boot_config, u_boot_console, efi_capsule_data):
- """
- Test Case 1 - Update U-Boot on SPI Flash, FIT image format
- 0x100000-0x150000: U-Boot binary (but dummy)
+ """Test Case 1
+ Update U-Boot on SPI Flash, FIT image format
+ x150000: U-Boot binary (but dummy)
- If the capsule is properly signed, the authentication
- should pass and the firmware be updated.
+ If the capsule is properly signed, the authentication
+ should pass and the firmware be updated.
"""
disk_img = efi_capsule_data
with u_boot_console.log.section('Test Case 1-a, before reboot'):
@@ -103,13 +104,13 @@ class TestEfiCapsuleFirmwareSignedFit(object):
def test_efi_capsule_auth2(
self, u_boot_config, u_boot_console, efi_capsule_data):
- """
- Test Case 2 - Update U-Boot on SPI Flash, FIT image format
- 0x100000-0x150000: U-Boot binary (but dummy)
+ """Test Case 2
+ Update U-Boot on SPI Flash, FIT image format
+ 0x100000-0x150000: U-Boot binary (but dummy)
- If the capsule is signed but with an invalid key,
- the authentication should fail and the firmware
- not be updated.
+ If the capsule is signed but with an invalid key,
+ the authentication should fail and the firmware
+ not be updated.
"""
disk_img = efi_capsule_data
with u_boot_console.log.section('Test Case 2-a, before reboot'):
@@ -182,12 +183,12 @@ class TestEfiCapsuleFirmwareSignedFit(object):
def test_efi_capsule_auth3(
self, u_boot_config, u_boot_console, efi_capsule_data):
- """
- Test Case 3 - Update U-Boot on SPI Flash, FIT image format
- 0x100000-0x150000: U-Boot binary (but dummy)
+ """Test Case 3
+ Update U-Boot on SPI Flash, FIT image format
+ 0x100000-0x150000: U-Boot binary (but dummy)
- If the capsule is not signed, the authentication
- should fail and the firmware not be updated.
+ If the capsule is not signed, the authentication
+ should fail and the firmware not be updated.
"""
disk_img = efi_capsule_data
with u_boot_console.log.section('Test Case 3-a, before reboot'):
diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py
index 2bbaa9cc55f..710d9925a30 100644
--- a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py
+++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py
@@ -1,10 +1,8 @@
# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2021, Linaro Limited
# Author: AKASHI Takahiro <[email protected]>
-#
-# U-Boot UEFI: Firmware Update (Signed capsule with raw images) Test
-"""
+"""U-Boot UEFI: Firmware Update (Signed capsule with raw images) Test
This test verifies capsule-on-disk firmware update
with signed capsule files containing raw images
"""
@@ -23,15 +21,17 @@ from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR
@pytest.mark.buildconfigspec('cmd_nvedit_efi')
@pytest.mark.buildconfigspec('cmd_sf')
@pytest.mark.slow
-class TestEfiCapsuleFirmwareSignedRaw(object):
+class TestEfiCapsuleFirmwareSignedRaw():
+ """Firmware Update (Signed capsule with raw images) Test
+ """
+
def test_efi_capsule_auth1(
self, u_boot_config, u_boot_console, efi_capsule_data):
- """
- Test Case 1 - Update U-Boot on SPI Flash, raw image format
- 0x100000-0x150000: U-Boot binary (but dummy)
+ """Test Case 1 - Update U-Boot on SPI Flash, raw image format
+ 0x100000-0x150000: U-Boot binary (but dummy)
- If the capsule is properly signed, the authentication
- should pass and the firmware be updated.
+ If the capsule is properly signed, the authentication
+ should pass and the firmware be updated.
"""
disk_img = efi_capsule_data
with u_boot_console.log.section('Test Case 1-a, before reboot'):
@@ -100,13 +100,12 @@ class TestEfiCapsuleFirmwareSignedRaw(object):
def test_efi_capsule_auth2(
self, u_boot_config, u_boot_console, efi_capsule_data):
- """
- Test Case 2 - Update U-Boot on SPI Flash, raw image format
- 0x100000-0x150000: U-Boot binary (but dummy)
+ """Test Case 2 - Update U-Boot on SPI Flash, raw image format
+ 0x100000-0x150000: U-Boot binary (but dummy)
- If the capsule is signed but with an invalid key,
- the authentication should fail and the firmware
- not be updated.
+ If the capsule is signed but with an invalid key,
+ the authentication should fail and the firmware
+ not be updated.
"""
disk_img = efi_capsule_data
with u_boot_console.log.section('Test Case 2-a, before reboot'):
@@ -179,12 +178,11 @@ class TestEfiCapsuleFirmwareSignedRaw(object):
def test_efi_capsule_auth3(
self, u_boot_config, u_boot_console, efi_capsule_data):
- """
- Test Case 3 - Update U-Boot on SPI Flash, raw image format
- 0x100000-0x150000: U-Boot binary (but dummy)
+ """Test Case 3 - Update U-Boot on SPI Flash, raw image format
+ 0x100000-0x150000: U-Boot binary (but dummy)
- If the capsule is not signed, the authentication
- should fail and the firmware not be updated.
+ If the capsule is not signed, the authentication
+ should fail and the firmware not be updated.
"""
disk_img = efi_capsule_data
with u_boot_console.log.section('Test Case 3-a, before reboot'):
diff --git a/test/py/tests/test_efi_fit.py b/test/py/tests/test_efi_fit.py
index 92d071f7839..7b7c98fb04c 100644
--- a/test/py/tests/test_efi_fit.py
+++ b/test/py/tests/test_efi_fit.py
@@ -433,11 +433,13 @@ def test_efi_fit_launch(u_boot_console):
sys_arch = cons.config.buildconfig.get('config_sys_arch', '"sandbox"')[1:-1]
is_sandbox = sys_arch == 'sandbox'
+ if is_sandbox:
+ old_dtb = cons.config.dtb
+
try:
if is_sandbox:
# Use our own device tree file, will be restored afterwards.
control_dtb = make_dtb('internal', False)
- old_dtb = cons.config.dtb
cons.config.dtb = control_dtb
# Run tests
diff --git a/test/py/tests/test_efi_secboot/conftest.py b/test/py/tests/test_efi_secboot/conftest.py
index 65cde7a2f23..30ff7029438 100644
--- a/test/py/tests/test_efi_secboot/conftest.py
+++ b/test/py/tests/test_efi_secboot/conftest.py
@@ -2,7 +2,7 @@
# Copyright (c) 2019, Linaro Limited
# Author: AKASHI Takahiro <[email protected]>
-""" Fixture for UEFI secure boot test """
+"""Fixture for UEFI secure boot test."""
from subprocess import call, check_call, CalledProcessError
import pytest
@@ -132,7 +132,9 @@ def efi_boot_env(request, u_boot_config):
@pytest.fixture(scope='session')
def efi_boot_env_intca(request, u_boot_config):
- """Set up a file system to be used in UEFI secure boot test
+ """Set up file system for secure boot test.
+
+ Set up a file system to be used in UEFI secure boot test
of intermediate certificates.
Args:
diff --git a/test/py/tests/test_efi_secboot/defs.py b/test/py/tests/test_efi_secboot/defs.py
index b7a2a118511..6a2317e295b 100644
--- a/test/py/tests/test_efi_secboot/defs.py
+++ b/test/py/tests/test_efi_secboot/defs.py
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: GPL-2.0+
+"""Constants used for secure boot test."""
+
# Owner guid
GUID = '11111111-2222-3333-4444-123456789abc'
diff --git a/test/py/tests/test_efi_selftest.py b/test/py/tests/test_efi_selftest.py
index e92d63cde6e..43f24245582 100644
--- a/test/py/tests/test_efi_selftest.py
+++ b/test/py/tests/test_efi_selftest.py
@@ -7,7 +7,7 @@
import pytest
@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
-def test_efi_selftest(u_boot_console):
+def test_efi_selftest_base(u_boot_console):
"""Run UEFI unit tests
u_boot_console -- U-Boot console
diff --git a/test/py/tests/test_hush_if_test.py b/test/py/tests/test_hush_if_test.py
index 37c1608bb22..3b4b6fcaf40 100644
--- a/test/py/tests/test_hush_if_test.py
+++ b/test/py/tests/test_hush_if_test.py
@@ -182,3 +182,16 @@ def test_hush_if_test_host_file_exists(u_boot_console):
expr = 'test -e hostfs - ' + test_file
exec_hush_if(u_boot_console, expr, False)
+
+def test_hush_var(u_boot_console):
+ """Test the set and unset of variables"""
+ u_boot_console.run_command('ut_var_nonexistent=')
+ u_boot_console.run_command('ut_var_exists=1')
+ u_boot_console.run_command('ut_var_unset=1')
+ exec_hush_if(u_boot_console, 'test -z "$ut_var_nonexistent"', True)
+ exec_hush_if(u_boot_console, 'test -z "$ut_var_exists"', False)
+ exec_hush_if(u_boot_console, 'test -z "$ut_var_unset"', False)
+ exec_hush_if(u_boot_console, 'ut_var_unset=', True)
+ exec_hush_if(u_boot_console, 'test -z "$ut_var_unset"', True)
+ u_boot_console.run_command('ut_var_exists=')
+ u_boot_console.run_command('ut_var_unset=')
diff --git a/test/py/tests/test_net.py b/test/py/tests/test_net.py
index 9ca6743afd9..cd4b4dc53cb 100644
--- a/test/py/tests/test_net.py
+++ b/test/py/tests/test_net.py
@@ -9,7 +9,7 @@ import u_boot_utils
"""
Note: This test relies on boardenv_* containing configuration values to define
-which the network environment available for testing. Without this, this test
+which network environment is available for testing. Without this, this test
will be automatically skipped.
For example:
@@ -29,6 +29,11 @@ env__net_uses_pci = True
# set to False.
env__net_dhcp_server = True
+# True if a DHCPv6 server is attached to the network, and should be tested.
+# If DHCPv6 testing is not possible or desired, this variable may be omitted or
+# set to False.
+env__net_dhcp6_server = True
+
# A list of environment variables that should be set in order to configure a
# static IP. If solely relying on DHCP, this variable may be omitted or set to
# an empty list.
@@ -55,9 +60,15 @@ env__net_nfs_readable_file = {
'size': 5058624,
'crc32': 'c2244b26',
}
+
+# True if a router advertisement service is connected to the network, and should
+# be tested. If router advertisement testing is not possible or desired, this
+variable may be omitted or set to False.
+env__router_on_net = True
"""
net_set_up = False
+net6_set_up = False
def test_net_pre_commands(u_boot_console):
"""Execute any commands required to enable network hardware.
@@ -93,6 +104,25 @@ def test_net_dhcp(u_boot_console):
global net_set_up
net_set_up = True
[email protected]('cmd_dhcp6')
+def test_net_dhcp6(u_boot_console):
+ """Test the dhcp6 command.
+
+ The boardenv_* file may be used to enable/disable this test; see the
+ comment at the beginning of this file.
+ """
+
+ test_dhcp6 = u_boot_console.config.env.get('env__net_dhcp6_server', False)
+ if not test_dhcp6:
+ pytest.skip('No DHCP6 server available')
+
+ u_boot_console.run_command('setenv autoload no')
+ output = u_boot_console.run_command('dhcp6')
+ assert 'DHCP6 client bound to ' in output
+
+ global net6_set_up
+ net6_set_up = True
+
@pytest.mark.buildconfigspec('net')
def test_net_setup_static(u_boot_console):
"""Set up a static IP configuration.
@@ -126,6 +156,30 @@ def test_net_ping(u_boot_console):
output = u_boot_console.run_command('ping $serverip')
assert 'is alive' in output
[email protected]('IPV6_ROUTER_DISCOVERY')
+def test_net_network_discovery(u_boot_console):
+ """Test the network discovery feature of IPv6.
+
+ An IPv6 network command (ping6 in this case) is run to make U-Boot send a
+ router solicitation packet, receive a router advertisement message, and
+ parse it.
+ A router advertisement service needs to be running for this test to succeed.
+ U-Boot receives the RA, processes it, and if successful, assigns the gateway
+ IP and prefix length.
+ The configuration is provided by the boardenv_* file; see the comment at
+ the beginning of this file.
+ """
+
+ router_on_net = u_boot_console.config.env.get('env__router_on_net', False)
+ if not router_on_net:
+ pytest.skip('No router on network')
+
+ fake_host_ip = 'fe80::215:5dff:fef6:2ec6'
+ output = u_boot_console.run_command('ping6 ' + fake_host_ip)
+ assert 'ROUTER SOLICITATION 1' in output
+ assert 'Set gatewayip6:' in output
+ assert '0000:0000:0000:0000:0000:0000:0000:0000' not in output
+
@pytest.mark.buildconfigspec('cmd_net')
def test_net_tftpboot(u_boot_console):
"""Test the tftpboot command.
diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index e8c8a6d6bd5..0b45863b438 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -213,7 +213,7 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}
str(exc))
finally:
if mounted:
- u_boot_utils.run_and_log(cons, 'sudo umount %s' % mnt)
+ u_boot_utils.run_and_log(cons, 'sudo umount --lazy %s' % mnt)
if loop:
u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop)
@@ -274,7 +274,7 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)
str(exc))
finally:
if mounted:
- u_boot_utils.run_and_log(cons, 'sudo umount %s' % mnt)
+ u_boot_utils.run_and_log(cons, 'sudo umount --lazy %s' % mnt)
if loop:
u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop)