
From: Simon Glass <sjg@chromium.org> Add more enum values so we can use these in the tests, instead of adding comments. This makes it easier to adjust tests when new hunters are added. Signed-off-by: Simon Glass <sjg@chromium.org> --- test/boot/bootdev.c | 35 ++++++++++++++++++----------------- test/boot/bootflow.c | 4 ++-- test/boot/bootstd_common.h | 10 ++++++++-- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index 84280caf7b5..cd1d00bfbe0 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -398,7 +398,7 @@ static int bootdev_test_hunter(struct unit_test_state *uts) ut_assert_nextline(" 4 spi_flash sf_bootdev"); ut_assert_nextline(" 5 usb usb_bootdev"); ut_assert_nextline(" 4 virtio virtio_bootdev"); - ut_assert_nextline("(total hunters: 10)"); + ut_assert_nextline("(total hunters: %d)", HUNTER_COUNT); ut_assert_console_end(); ut_assertok(bootdev_hunt("usb1", false)); @@ -406,8 +406,7 @@ static int bootdev_test_hunter(struct unit_test_state *uts) "Bus usb@1: scanning bus usb@1 for devices... 6 USB Device(s) found"); ut_assert_console_end(); - /* USB is 7th in the list, so bit 8 */ - ut_asserteq(BIT(8), std->hunters_used); + ut_asserteq(BIT(HUNTER_USB), std->hunters_used); return 0; } @@ -428,7 +427,7 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts) ut_assert_nextline("Prio Used Uclass Hunter"); ut_assert_nextlinen("----"); ut_assert_nextline(" 6 ethernet eth_bootdev"); - ut_assert_skip_to_line("(total hunters: 10)"); + ut_assert_skip_to_line("(total hunters: %d)", HUNTER_COUNT); ut_assert_console_end(); /* Use the MMC hunter and see that it updates */ @@ -436,7 +435,7 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts) ut_assertok(run_command("bootdev hunt -l", 0)); ut_assert_skip_to_line(" 5 ide ide_bootdev"); ut_assert_nextline(" 2 * mmc mmc_bootdev"); - ut_assert_skip_to_line("(total hunters: 10)"); + ut_assert_skip_to_line("(total hunters: %d)", HUNTER_COUNT); ut_assert_console_end(); /* Scan all hunters */ @@ -477,10 +476,10 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts) ut_assert_nextline(" 4 * spi_flash sf_bootdev"); ut_assert_nextline(" 5 * usb usb_bootdev"); ut_assert_nextline(" 4 * virtio virtio_bootdev"); - ut_assert_nextline("(total hunters: 10)"); + ut_assert_nextline("(total hunters: %d)", HUNTER_COUNT); ut_assert_console_end(); - ut_asserteq(GENMASK(MAX_HUNTER, 0), std->hunters_used); + ut_asserteq(GENMASK(HUNTER_MAX, 0), std->hunters_used); return 0; } @@ -501,7 +500,8 @@ static int bootdev_test_hunt_scan(struct unit_test_state *uts) ut_assertok(bootflow_scan_first(NULL, NULL, &iter, BOOTFLOWIF_SHOW | BOOTFLOWIF_HUNT | BOOTFLOWIF_SKIP_GLOBAL, &bflow)); - ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used); + ut_asserteq(BIT(HUNTER_MMC) | BIT(HUNTER_SIMPLE_BUS), + std->hunters_used); return 0; } @@ -662,8 +662,7 @@ static int bootdev_test_next_label(struct unit_test_state *uts) ut_asserteq_str("scsi.id0lun0.bootdev", dev->name); ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS, mflags); - /* SCSI is 7th in the list, so bit 6 */ - ut_asserteq(BIT(MMC_HUNTER) | BIT(6), std->hunters_used); + ut_asserteq(BIT(HUNTER_MMC) | BIT(HUNTER_SCSI), std->hunters_used); ut_assertok(bootdev_next_label(&iter, &dev, &mflags)); ut_assert_console_end(); @@ -672,8 +671,8 @@ static int bootdev_test_next_label(struct unit_test_state *uts) ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_DHCP_ONLY, mflags); - /* dhcp: Ethernet is first so bit 0 */ - ut_asserteq(BIT(MMC_HUNTER) | BIT(6) | BIT(0), std->hunters_used); + ut_asserteq(BIT(HUNTER_MMC) | BIT(HUNTER_SCSI) | BIT(HUNTER_ETH), + std->hunters_used); ut_assertok(bootdev_next_label(&iter, &dev, &mflags)); ut_assert_console_end(); @@ -682,8 +681,8 @@ static int bootdev_test_next_label(struct unit_test_state *uts) ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_PXE_ONLY, mflags); - /* pxe: Ethernet is first so bit 0 */ - ut_asserteq(BIT(MMC_HUNTER) | BIT(6) | BIT(0), std->hunters_used); + ut_asserteq(BIT(HUNTER_MMC) | BIT(HUNTER_SCSI) | BIT(HUNTER_ETH), + std->hunters_used); mflags = 123; ut_asserteq(-ENODEV, bootdev_next_label(&iter, &dev, &mflags)); @@ -691,7 +690,8 @@ static int bootdev_test_next_label(struct unit_test_state *uts) ut_assert_console_end(); /* no change */ - ut_asserteq(BIT(MMC_HUNTER) | BIT(6) | BIT(0), std->hunters_used); + ut_asserteq(BIT(HUNTER_MMC) | BIT(HUNTER_SCSI) | BIT(HUNTER_ETH), + std->hunters_used); return 0; } @@ -741,7 +741,8 @@ static int bootdev_test_next_prio(struct unit_test_state *uts) ut_assert_nextline("Hunting with: mmc"); ut_assert_console_end(); - ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used); + ut_asserteq(BIT(HUNTER_MMC) | BIT(HUNTER_SIMPLE_BUS), + std->hunters_used); ut_assertok(bootdev_next_prio(&iter, &dev)); ut_asserteq_str("mmc1.bootdev", dev->name); @@ -772,7 +773,7 @@ static int bootdev_test_next_prio(struct unit_test_state *uts) } while (!ret); ut_asserteq(-ENODEV, ret); ut_assertnull(dev); - ut_asserteq(GENMASK(MAX_HUNTER, 0), std->hunters_used); + ut_asserteq(GENMASK(HUNTER_MAX, 0), std->hunters_used); ut_assert_skip_to_line("Hunting with: ethernet"); ut_assert_console_end(); diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index 15d2cb535cb..cac5e0b1a35 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -802,7 +802,7 @@ static int bootflow_cmd_hunt_single(struct unit_test_state *uts) ut_assert_console_end(); /* check that the hunter was used */ - ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used); + ut_asserteq(BIT(HUNTER_MMC) | BIT(1), std->hunters_used); return 0; } @@ -824,7 +824,7 @@ static int bootflow_cmd_hunt_label(struct unit_test_state *uts) ut_assertok(run_command("bootflow scan -l mmc", 0)); /* check that the hunter was used */ - ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used); + ut_asserteq(BIT(HUNTER_MMC) | BIT(1), std->hunters_used); /* check that we got the mmc1 bootflow */ ut_assert_nextline("Scanning for bootflows with label 'mmc'"); diff --git a/test/boot/bootstd_common.h b/test/boot/bootstd_common.h index c61698adc02..945515f7da8 100644 --- a/test/boot/bootstd_common.h +++ b/test/boot/bootstd_common.h @@ -20,9 +20,15 @@ #define TEST_VERSION "U-Boot v2022.04-local2" #define TEST_VERNUM 0x00010002 +/* IDs for hunters, which is dependent on their binding order */ enum { - MAX_HUNTER = 9, - MMC_HUNTER = 3, /* ID of MMC hunter */ + HUNTER_ETH = 0, + HUNTER_SIMPLE_BUS, + HUNTER_MMC = 3, + HUNTER_SCSI = 6, + HUNTER_USB = 8, + HUNTER_COUNT = 10, + HUNTER_MAX = HUNTER_COUNT - 1, }; struct unit_test_state; -- 2.43.0