summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Kconfig25
-rw-r--r--test/Makefile21
-rw-r--r--test/boot/Makefile10
-rw-r--r--test/boot/bootdev.c114
-rw-r--r--test/boot/bootflow.c358
-rw-r--r--test/boot/bootm.c (renamed from test/bootm.c)37
-rw-r--r--test/boot/bootmeth.c63
-rw-r--r--test/boot/bootstd_common.c29
-rw-r--r--test/boot/bootstd_common.h21
-rw-r--r--test/boot/cedit.c36
-rw-r--r--test/boot/expo.c47
-rw-r--r--test/boot/files/expo_ids.h3
-rw-r--r--test/boot/files/expo_layout.dts5
-rw-r--r--test/boot/image.c2
-rw-r--r--test/boot/measurement.c14
-rw-r--r--test/boot/upl.c427
-rw-r--r--test/boot/vbe_fixup.c5
-rw-r--r--test/boot/vbe_simple.c7
-rw-r--r--test/cmd/Makefile22
-rw-r--r--test/cmd/addrmap.c16
-rw-r--r--test/cmd/armffa.c4
-rw-r--r--test/cmd/bdinfo.c82
-rw-r--r--test/cmd/cmd_ut_cmd.c20
-rw-r--r--test/cmd/command.c109
-rw-r--r--test/cmd/coreboot.c119
-rw-r--r--test/cmd/cpuid.c22
-rw-r--r--test/cmd/exit.c52
-rw-r--r--test/cmd/fdt.c564
-rw-r--r--test/cmd/font.c44
-rw-r--r--test/cmd/hash.c104
-rw-r--r--test/cmd/history.c3
-rw-r--r--test/cmd/loadm.c19
-rw-r--r--test/cmd/mbr.c209
-rw-r--r--test/cmd/mem.c20
-rw-r--r--test/cmd/mem_copy.c4
-rw-r--r--test/cmd/mem_search.c34
-rw-r--r--test/cmd/meminfo.c42
-rw-r--r--test/cmd/msr.c38
-rw-r--r--test/cmd/pci_mps.c17
-rw-r--r--test/cmd/pinmux.c16
-rw-r--r--test/cmd/pwm.c7
-rw-r--r--test/cmd/rw.c6
-rw-r--r--test/cmd/seama.c22
-rw-r--r--test/cmd/setexpr.c84
-rw-r--r--test/cmd/spawn.c32
-rw-r--r--test/cmd/temperature.c6
-rw-r--r--test/cmd/test_echo.c9
-rw-r--r--test/cmd/test_pause.c10
-rw-r--r--test/cmd/wget.c89
-rw-r--r--test/cmd_ut.c485
-rw-r--r--test/command_ut.c105
-rw-r--r--test/common.sh20
-rw-r--r--test/common/Makefile9
-rw-r--r--test/common/bloblist.c (renamed from test/bloblist.c)59
-rw-r--r--test/common/cmd_ut_common.c22
-rw-r--r--test/common/cread.c6
-rw-r--r--test/common/cyclic.c20
-rw-r--r--test/common/event.c5
-rw-r--r--test/common/print.c (renamed from test/print_ut.c)66
-rw-r--r--test/common/test_autoboot.c5
-rw-r--r--test/dm/Kconfig2
-rw-r--r--test/dm/Makefile9
-rw-r--r--test/dm/acpi.c145
-rw-r--r--test/dm/acpi_dp.c5
-rw-r--r--test/dm/acpigen.c137
-rw-r--r--test/dm/adc.c17
-rw-r--r--test/dm/audio.c3
-rw-r--r--test/dm/axi.c10
-rw-r--r--test/dm/blk.c17
-rw-r--r--test/dm/blkmap.c5
-rw-r--r--test/dm/bootcount.c11
-rw-r--r--test/dm/bus.c32
-rw-r--r--test/dm/button.c13
-rw-r--r--test/dm/cache.c3
-rw-r--r--test/dm/clk.c8
-rw-r--r--test/dm/clk_ccf.c4
-rw-r--r--test/dm/core.c148
-rw-r--r--test/dm/cpu.c6
-rw-r--r--test/dm/cros_ec.c19
-rw-r--r--test/dm/cros_ec_pwm.c3
-rw-r--r--test/dm/devres.c14
-rw-r--r--test/dm/dma.c7
-rw-r--r--test/dm/dsa.c14
-rw-r--r--test/dm/dsi_host.c4
-rw-r--r--test/dm/ecdsa.c2
-rw-r--r--test/dm/efi_media.c3
-rw-r--r--test/dm/eth.c102
-rw-r--r--test/dm/extcon.c3
-rw-r--r--test/dm/fastboot.c3
-rw-r--r--test/dm/fdtdec.c5
-rw-r--r--test/dm/ffa.c7
-rw-r--r--test/dm/firmware.c3
-rw-r--r--test/dm/fpga.c3
-rw-r--r--test/dm/fwu_mdata.c22
-rw-r--r--test/dm/gpio.c33
-rw-r--r--test/dm/host.c9
-rw-r--r--test/dm/hwspinlock.c4
-rw-r--r--test/dm/i2c.c20
-rw-r--r--test/dm/i2s.c3
-rw-r--r--test/dm/iommu.c9
-rw-r--r--test/dm/irq.c26
-rw-r--r--test/dm/k210_pll.c1
-rw-r--r--test/dm/led.c111
-rw-r--r--test/dm/mailbox.c3
-rw-r--r--test/dm/mdio.c4
-rw-r--r--test/dm/mdio_mux.c4
-rw-r--r--test/dm/memory.c3
-rw-r--r--test/dm/misc.c4
-rw-r--r--test/dm/mmc.c5
-rw-r--r--test/dm/mux-cmd.c14
-rw-r--r--test/dm/mux-emul.c5
-rw-r--r--test/dm/mux-mmio.c5
-rw-r--r--test/dm/nand.c47
-rw-r--r--test/dm/nop.c4
-rw-r--r--test/dm/nvmxip.c4
-rw-r--r--test/dm/of_extra.c1
-rw-r--r--test/dm/of_platdata.c17
-rw-r--r--test/dm/ofnode.c327
-rw-r--r--test/dm/ofread.c3
-rw-r--r--test/dm/osd.c7
-rw-r--r--test/dm/p2sb.c3
-rw-r--r--test/dm/panel.c5
-rw-r--r--test/dm/part.c7
-rw-r--r--test/dm/pch.c5
-rw-r--r--test/dm/pci.c32
-rw-r--r--test/dm/pci_ep.c4
-rw-r--r--test/dm/phy.c26
-rw-r--r--test/dm/phys2bus.c3
-rw-r--r--test/dm/pinmux.c7
-rw-r--r--test/dm/pmc.c3
-rw-r--r--test/dm/pmic.c14
-rw-r--r--test/dm/power-domain.c14
-rw-r--r--test/dm/pwm.c3
-rw-r--r--test/dm/qfw.c7
-rw-r--r--test/dm/ram.c3
-rw-r--r--test/dm/read.c3
-rw-r--r--test/dm/reboot-mode.c7
-rw-r--r--test/dm/regmap.c20
-rw-r--r--test/dm/regulator.c25
-rw-r--r--test/dm/remoteproc.c8
-rw-r--r--test/dm/reset.c12
-rw-r--r--test/dm/rkmtd.c7
-rw-r--r--test/dm/rng.c7
-rw-r--r--test/dm/rtc.c19
-rw-r--r--test/dm/scmi.c20
-rw-r--r--test/dm/scsi.c3
-rw-r--r--test/dm/serial.c4
-rw-r--r--test/dm/sf.c5
-rw-r--r--test/dm/simple-bus.c3
-rw-r--r--test/dm/simple-pm-bus.c3
-rw-r--r--test/dm/sm.c4
-rw-r--r--test/dm/smem.c3
-rw-r--r--test/dm/soc.c4
-rw-r--r--test/dm/sound.c5
-rw-r--r--test/dm/spi.c7
-rw-r--r--test/dm/spmi.c8
-rw-r--r--test/dm/syscon-reset.c3
-rw-r--r--test/dm/syscon.c7
-rw-r--r--test/dm/sysinfo-gpio.c15
-rw-r--r--test/dm/sysinfo.c10
-rw-r--r--test/dm/sysreset.c9
-rw-r--r--test/dm/tag.c5
-rw-r--r--test/dm/tee.c4
-rw-r--r--test/dm/test-dm.c17
-rw-r--r--test/dm/test-driver.c11
-rw-r--r--test/dm/test-fdt.c84
-rw-r--r--test/dm/test-uclass.c9
-rw-r--r--test/dm/timer.c5
-rw-r--r--test/dm/tpm.c9
-rw-r--r--test/dm/usb.c14
-rw-r--r--test/dm/video.c485
-rw-r--r--test/dm/video_bridge.c67
-rw-r--r--test/dm/virtio.c3
-rw-r--r--test/dm/virtio_device.c9
-rw-r--r--test/dm/virtio_rng.c3
-rw-r--r--test/dm/wdt.c24
-rw-r--r--test/env/Kconfig1
-rw-r--r--test/env/attr.c1
-rw-r--r--test/env/cmd_ut_env.c70
-rw-r--r--test/env/fdt.c1
-rw-r--r--test/env/hashtable.c4
-rw-r--r--test/fdt_overlay/Kconfig (renamed from test/overlay/Kconfig)4
-rw-r--r--test/fdt_overlay/Makefile (renamed from test/overlay/Makefile)6
-rw-r--r--test/fdt_overlay/cmd_ut_fdt_overlay.c (renamed from test/overlay/cmd_ut_overlay.c)230
-rw-r--r--test/fdt_overlay/test-fdt-base.dts (renamed from test/overlay/test-fdt-base.dts)0
-rw-r--r--test/fdt_overlay/test-fdt-overlay-stacked.dtso (renamed from test/overlay/test-fdt-overlay-stacked.dts)0
-rw-r--r--test/fdt_overlay/test-fdt-overlay.dtso (renamed from test/overlay/test-fdt-overlay.dts)0
-rw-r--r--test/fuzz/Makefile2
-rw-r--r--test/fuzz/cmd_fuzz.c1
-rw-r--r--test/fuzz/virtio.c1
-rw-r--r--test/hush/Makefile3
-rw-r--r--test/hush/cmd_ut_hush.c19
-rw-r--r--test/hush/dollar.c48
-rw-r--r--test/hush/loop.c15
-rw-r--r--test/image/spl_load.c5
-rw-r--r--test/image/spl_load_fs.c1
-rw-r--r--test/image/spl_load_net.c1
-rw-r--r--test/image/spl_load_nor.c1
-rw-r--r--test/image/spl_load_os.c55
-rw-r--r--test/image/spl_load_spi.c1
-rw-r--r--test/lib/Makefile17
-rw-r--r--test/lib/abuf.c27
-rw-r--r--test/lib/alist.c495
-rw-r--r--test/lib/asn1.c4
-rw-r--r--test/lib/cmd_ut_lib.c20
-rw-r--r--test/lib/compression.c (renamed from test/compression.c)41
-rw-r--r--test/lib/efi_device_path.c2
-rw-r--r--test/lib/efi_image_region.c3
-rw-r--r--test/lib/getopt.c1
-rw-r--r--test/lib/hexdump.c4
-rw-r--r--test/lib/initjmp.c73
-rw-r--r--test/lib/kconfig.c11
-rw-r--r--test/lib/kconfig_spl.c1
-rw-r--r--test/lib/lmb.c719
-rw-r--r--test/lib/longjmp.c3
-rw-r--r--test/lib/membuf.c239
-rw-r--r--test/lib/rsa.c3
-rw-r--r--test/lib/sscanf.c2
-rw-r--r--test/lib/str.c (renamed from test/str_ut.c)62
-rw-r--r--test/lib/string.c81
-rw-r--r--test/lib/strlcat.c1
-rw-r--r--test/lib/test_aes.c2
-rw-r--r--test/lib/test_crc8.c1
-rw-r--r--test/lib/test_crypt.c2
-rw-r--r--test/lib/test_errno_str.c2
-rw-r--r--test/lib/test_print.c17
-rw-r--r--test/lib/test_sha256_hkdf.c198
-rw-r--r--test/lib/test_sha256_hmac.c294
-rw-r--r--test/lib/time.c (renamed from test/time_ut.c)30
-rw-r--r--test/lib/unicode.c (renamed from test/unicode_ut.c)71
-rw-r--r--test/lib/uthread.c146
-rw-r--r--test/lib/uuid.c126
-rw-r--r--test/log/Makefile2
-rw-r--r--test/log/cont_test.c9
-rw-r--r--test/log/log_filter.c9
-rw-r--r--test/log/log_test.c142
-rw-r--r--test/log/log_ut.c21
-rw-r--r--test/log/nolog_ndebug.c4
-rw-r--r--test/log/nolog_test.c26
-rw-r--r--test/log/pr_cont_test.c5
-rw-r--r--test/log/syslog_test.c2
-rw-r--r--test/log/syslog_test_ndebug.c2
-rw-r--r--test/optee/Kconfig2
-rw-r--r--test/optee/Makefile2
-rw-r--r--test/optee/optee.c (renamed from test/optee/cmd_ut_optee.c)106
-rw-r--r--test/py/conftest.py316
-rw-r--r--test/py/console_base.py (renamed from test/py/u_boot_console_base.py)245
-rw-r--r--test/py/console_board.py (renamed from test/py/u_boot_console_exec_attach.py)37
-rw-r--r--test/py/console_sandbox.py (renamed from test/py/u_boot_console_sandbox.py)10
-rw-r--r--test/py/pytest.ini1
-rw-r--r--test/py/requirements.txt29
-rw-r--r--test/py/spawn.py (renamed from test/py/u_boot_spawn.py)138
-rw-r--r--test/py/tests/bootstd/mmc1.img.xzbin4480 -> 0 bytes
-rw-r--r--test/py/tests/bootstd/mmc4.img.xzbin7072 -> 0 bytes
-rw-r--r--test/py/tests/fit_util.py42
-rw-r--r--test/py/tests/fs_helper.py53
-rw-r--r--test/py/tests/test_000_version.py18
-rw-r--r--test/py/tests/test_android/test_ab.py67
-rw-r--r--test/py/tests/test_android/test_abootimg.py133
-rw-r--r--test/py/tests/test_android/test_avb.py49
-rw-r--r--test/py/tests/test_bind.py86
-rw-r--r--test/py/tests/test_bootmenu.py48
-rw-r--r--test/py/tests/test_bootstage.py60
-rw-r--r--test/py/tests/test_button.py18
-rw-r--r--test/py/tests/test_cat.py37
-rw-r--r--test/py/tests/test_cat/conftest.py36
-rw-r--r--test/py/tests/test_cat/test_cat.py20
-rw-r--r--test/py/tests/test_dfu.py54
-rw-r--r--test/py/tests/test_distro.py61
-rw-r--r--test/py/tests/test_dm.py33
-rw-r--r--test/py/tests/test_efi_bootmgr.py70
-rw-r--r--test/py/tests/test_efi_bootmgr/conftest.py38
-rw-r--r--test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py44
-rw-r--r--test/py/tests/test_efi_capsule/capsule_common.py62
-rw-r--r--test/py/tests/test_efi_capsule/conftest.py51
-rw-r--r--test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py102
-rw-r--r--test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py147
-rw-r--r--test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py106
-rw-r--r--test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py108
-rw-r--r--test/py/tests/test_efi_capsule/version.dtso (renamed from test/py/tests/test_efi_capsule/version.dts)6
-rw-r--r--test/py/tests/test_efi_fit.py247
-rw-r--r--test/py/tests/test_efi_loader.py191
-rw-r--r--test/py/tests/test_efi_secboot/conftest.py62
-rw-r--r--test/py/tests/test_efi_secboot/test_authvar.py124
-rw-r--r--test/py/tests/test_efi_secboot/test_signed.py186
-rw-r--r--test/py/tests/test_efi_secboot/test_signed_intca.py56
-rw-r--r--test/py/tests/test_efi_secboot/test_unsigned.py48
-rw-r--r--test/py/tests/test_efi_selftest.py180
-rw-r--r--test/py/tests/test_eficonfig.py (renamed from test/py/tests/test_eficonfig/test_eficonfig.py)163
-rw-r--r--test/py/tests/test_eficonfig/conftest.py40
-rw-r--r--test/py/tests/test_env.py84
-rw-r--r--test/py/tests/test_event_dump.py11
-rw-r--r--test/py/tests/test_extension.py36
-rwxr-xr-xtest/py/tests/test_fit.py67
-rw-r--r--test/py/tests/test_fit_auto_signed.py35
-rw-r--r--test/py/tests/test_fit_ecdsa.py31
-rw-r--r--test/py/tests/test_fit_hashes.py29
-rw-r--r--test/py/tests/test_fpga.py292
-rw-r--r--test/py/tests/test_fs/conftest.py391
-rw-r--r--test/py/tests/test_fs/fstest_helpers.py4
-rw-r--r--test/py/tests/test_fs/test_basic.py193
-rw-r--r--test/py/tests/test_fs/test_erofs.py76
-rw-r--r--test/py/tests/test_fs/test_ext.py288
-rw-r--r--test/py/tests/test_fs/test_fs_cmd.py4
-rw-r--r--test/py/tests/test_fs/test_fs_fat.py6
-rw-r--r--test/py/tests/test_fs/test_mkdir.py88
-rw-r--r--test/py/tests/test_fs/test_rename.py372
-rw-r--r--test/py/tests/test_fs/test_squashfs/test_sqfs_load.py54
-rw-r--r--test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py64
-rw-r--r--test/py/tests/test_fs/test_symlink.py46
-rw-r--r--test/py/tests/test_fs/test_unlink.py88
-rw-r--r--test/py/tests/test_gpio.py106
-rw-r--r--test/py/tests/test_gpt.py178
-rw-r--r--test/py/tests/test_handoff.py5
-rw-r--r--test/py/tests/test_help.py30
-rw-r--r--test/py/tests/test_i2c.py44
-rw-r--r--test/py/tests/test_kconfig.py16
-rw-r--r--test/py/tests/test_log.py29
-rw-r--r--test/py/tests/test_lsblk.py4
-rw-r--r--test/py/tests/test_md.py22
-rw-r--r--test/py/tests/test_mdio.py32
-rw-r--r--test/py/tests/test_memtest.py34
-rw-r--r--test/py/tests/test_mii.py50
-rw-r--r--test/py/tests/test_mmc.py693
-rw-r--r--test/py/tests/test_mmc_rd.py54
-rw-r--r--test/py/tests/test_mmc_wr.py20
-rw-r--r--test/py/tests/test_net.py297
-rw-r--r--test/py/tests/test_net_boot.py429
-rw-r--r--test/py/tests/test_of_migrate.py43
-rw-r--r--test/py/tests/test_ofplatdata.py11
-rw-r--r--test/py/tests/test_optee_rpmb.py10
-rw-r--r--test/py/tests/test_part.py4
-rw-r--r--test/py/tests/test_pinmux.py32
-rw-r--r--test/py/tests/test_pstore.py48
-rw-r--r--test/py/tests/test_qfw.py8
-rw-r--r--test/py/tests/test_reset.py24
-rw-r--r--test/py/tests/test_sandbox_exit.py28
-rw-r--r--test/py/tests/test_sandbox_opts.py16
-rw-r--r--test/py/tests/test_saveenv.py70
-rw-r--r--test/py/tests/test_scp03.py8
-rw-r--r--test/py/tests/test_scsi.py48
-rw-r--r--test/py/tests/test_semihosting/test_hostfs.py14
-rw-r--r--test/py/tests/test_sf.py66
-rw-r--r--test/py/tests/test_shell_basics.py30
-rw-r--r--test/py/tests/test_sleep.py28
-rw-r--r--test/py/tests/test_smbios.py30
-rw-r--r--test/py/tests/test_source.py45
-rw-r--r--test/py/tests/test_spi.py735
-rw-r--r--test/py/tests/test_spl.py17
-rw-r--r--test/py/tests/test_stackprotector.py8
-rw-r--r--test/py/tests/test_suite.py207
-rw-r--r--test/py/tests/test_tpm2.py196
-rw-r--r--test/py/tests/test_trace.py109
-rw-r--r--test/py/tests/test_ums.py79
-rw-r--r--test/py/tests/test_unknown_cmd.py6
-rw-r--r--test/py/tests/test_upl.py37
-rw-r--r--test/py/tests/test_usb.py368
-rw-r--r--test/py/tests/test_ut.py547
-rw-r--r--test/py/tests/test_vbe.py19
-rw-r--r--test/py/tests/test_vbe_vpl.py33
-rw-r--r--test/py/tests/test_vboot.py188
-rw-r--r--test/py/tests/test_vpl.py13
-rw-r--r--test/py/tests/test_xxd.py40
-rw-r--r--test/py/tests/test_xxd/conftest.py36
-rw-r--r--test/py/tests/test_xxd/test_xxd.py23
-rw-r--r--test/py/tests/test_zynq_secure.py96
-rw-r--r--test/py/tests/test_zynqmp_rpu.py160
-rw-r--r--test/py/tests/test_zynqmp_secure.py42
-rw-r--r--test/py/utils.py (renamed from test/py/u_boot_utils.py)44
-rw-r--r--test/stdint/int-types.c2
-rw-r--r--test/test-main.c273
-rwxr-xr-xtest/trace/test-trace.sh64
-rw-r--r--test/ut.c13
373 files changed, 13901 insertions, 7860 deletions
diff --git a/test/Kconfig b/test/Kconfig
index e2ec0994a2e..31016eedbf8 100644
--- a/test/Kconfig
+++ b/test/Kconfig
@@ -20,9 +20,18 @@ config SPL_UNIT_TEST
of-platdata and SPL handover. To run these tests with the sandbox_spl
board, use the -u (unit test) option.
+if UNIT_TEST
+
+config UNIT_TEST_DURATION
+ bool "Report unit-test duration"
+ default y
+ help
+ Enable this short the time taken by each test suite. This is reported
+ after the suite runs, alongside the pass/fail results. In addition,
+ an overall total is reported if multiple suites are run.
+
config UT_LIB
bool "Unit tests for library functions"
- depends on UNIT_TEST
default y if !SANDBOX_VPL
help
Enables the 'ut lib' command which tests library functions like
@@ -32,7 +41,7 @@ if UT_LIB
config UT_LIB_ASN1
bool "Unit test for asn1 compiler and decoder function"
- depends on SANDBOX
+ depends on SANDBOX && !MBEDTLS_LIB_X509
default y
imply ASYMMETRIC_KEY_TYPE
imply ASYMMETRIC_PUBLIC_KEY_SUBTYPE
@@ -63,16 +72,15 @@ config UT_LIB_RSA
Enables rsa_verify() test, currently rsa_verify_with_pkey only()
only, at the 'ut lib' command.
-endif
+endif # UT_LIB
config UT_BOOTSTD
bool "Unit tests for standard boot"
- depends on UNIT_TEST && BOOTSTD && SANDBOX
+ depends on BOOTSTD && SANDBOX
default y
config UT_COMPRESSION
bool "Unit test for compression"
- depends on UNIT_TEST
depends on CMDLINE && GZIP_COMPRESSED && BZIP2 && LZMA && LZO && LZ4 && ZSTD
default y
help
@@ -81,7 +89,6 @@ config UT_COMPRESSION
config UT_LOG
bool "Unit tests for logging functions"
- depends on UNIT_TEST
default y
help
Enables the 'ut log' command which tests logging functions like
@@ -90,7 +97,6 @@ config UT_LOG
config UT_TIME
bool "Unit tests for time functions"
- depends on UNIT_TEST
help
Enables the 'ut time' command which tests that the time functions
work correctly. The test is fairly simple and will not catch all
@@ -99,7 +105,6 @@ config UT_TIME
config UT_UNICODE
bool "Unit tests for Unicode functions"
- depends on UNIT_TEST
default y
select CHARSET
help
@@ -111,7 +116,9 @@ source "test/env/Kconfig"
source "test/image/Kconfig"
source "test/lib/Kconfig"
source "test/optee/Kconfig"
-source "test/overlay/Kconfig"
+source "test/fdt_overlay/Kconfig"
+
+endif # UNIT_TEST
config POST
bool "Power On Self Test support"
diff --git a/test/Makefile b/test/Makefile
index ed312cd0a48..f7ab9a36b2a 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -4,32 +4,25 @@
obj-y += test-main.o
-ifneq ($(CONFIG_$(SPL_)BLOBLIST),)
-obj-$(CONFIG_$(SPL_)CMDLINE) += bloblist.o
-obj-$(CONFIG_$(SPL_)CMDLINE) += bootm.o
-endif
-obj-$(CONFIG_$(SPL_)CMDLINE) += cmd/
-obj-$(CONFIG_$(SPL_)CMDLINE) += cmd_ut.o
-obj-$(CONFIG_$(SPL_)CMDLINE) += command_ut.o
-obj-$(CONFIG_$(SPL_)UT_COMPRESSION) += compression.o
+obj-$(CONFIG_$(PHASE_)CMDLINE) += cmd/
+obj-$(CONFIG_$(PHASE_)CMDLINE) += cmd_ut.o
obj-y += dm/
obj-$(CONFIG_FUZZ) += fuzz/
ifndef CONFIG_SANDBOX_VPL
obj-$(CONFIG_UNIT_TEST) += lib/
endif
ifneq ($(CONFIG_HUSH_PARSER),)
-obj-$(CONFIG_$(SPL_)CMDLINE) += hush/
+obj-$(CONFIG_$(PHASE_)CMDLINE) += hush/
endif
-obj-$(CONFIG_$(SPL_)CMDLINE) += print_ut.o
-obj-$(CONFIG_$(SPL_)CMDLINE) += str_ut.o
-obj-$(CONFIG_UT_TIME) += time_ut.o
+obj-$(CONFIG_UT_OPTEE) += optee/
obj-y += ut.o
-ifeq ($(CONFIG_SPL_BUILD),)
+ifeq ($(CONFIG_XPL_BUILD),)
obj-y += boot/
obj-$(CONFIG_UNIT_TEST) += common/
+obj-$(CONFIG_UT_ENV) += env/
+obj-$(CONFIG_UT_FDT_OVERLAY) += fdt_overlay/
obj-y += log/
-obj-$(CONFIG_$(SPL_)UT_UNICODE) += unicode_ut.o
else
obj-$(CONFIG_SPL_UT_LOAD) += image/
endif
diff --git a/test/boot/Makefile b/test/boot/Makefile
index 068522cb9e0..00223b44fe0 100644
--- a/test/boot/Makefile
+++ b/test/boot/Makefile
@@ -2,14 +2,22 @@
#
# Copyright 2021 Google LLC
+ifdef CONFIG_UT_BOOTSTD
obj-$(CONFIG_BOOTSTD) += bootdev.o bootstd_common.o bootflow.o bootmeth.o
obj-$(CONFIG_FIT) += image.o
-obj-$(CONFIG_MEASURED_BOOT) += measurement.o
obj-$(CONFIG_EXPO) += expo.o
obj-$(CONFIG_CEDIT) += cedit.o
+endif
+
+ifdef CONFIG_SANDBOX
+obj-$(CONFIG_$(PHASE_)CMDLINE) += bootm.o
+endif
+obj-$(CONFIG_MEASURED_BOOT) += measurement.o
ifdef CONFIG_OF_LIVE
obj-$(CONFIG_BOOTMETH_VBE_SIMPLE) += vbe_simple.o
endif
obj-$(CONFIG_BOOTMETH_VBE) += vbe_fixup.o
+
+obj-$(CONFIG_UPL) += upl.o
diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c
index 0702fccdae6..9af94786870 100644
--- a/test/boot/bootdev.c
+++ b/test/boot/bootdev.c
@@ -6,30 +6,20 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <bootstd.h>
#include <dm.h>
#include <bootdev.h>
#include <bootflow.h>
#include <mapmem.h>
#include <os.h>
-#include <test/suites.h>
#include <test/ut.h>
#include "bootstd_common.h"
-/* Allow reseting the USB-started flag */
-#if defined(CONFIG_USB_HOST) || defined(CONFIG_USB_GADGET)
-extern bool usb_started;
-#else
-#include <usb.h>
-#endif
-
/* Check 'bootdev list' command */
static int bootdev_test_cmd_list(struct unit_test_state *uts)
{
int probed;
- console_record_reset_enable();
for (probed = 0; probed < 2; probed++) {
int probe_ch = probed ? '+' : ' ';
@@ -50,7 +40,7 @@ static int bootdev_test_cmd_list(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootdev_test_cmd_list, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootdev_test_cmd_list, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check 'bootdev select' and 'info' commands */
static int bootdev_test_cmd_select(struct unit_test_state *uts)
@@ -60,7 +50,6 @@ static int bootdev_test_cmd_select(struct unit_test_state *uts)
/* get access to the CLI's cur_bootdev */
ut_assertok(bootstd_get_priv(&std));
- console_record_reset_enable();
ut_asserteq(1, run_command("bootdev info", 0));
ut_assert_nextlinen("Please use");
ut_assert_console_end();
@@ -100,7 +89,7 @@ static int bootdev_test_cmd_select(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootdev_test_cmd_select, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootdev_test_cmd_select, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check bootdev labels */
static int bootdev_test_labels(struct unit_test_state *uts)
@@ -132,13 +121,13 @@ static int bootdev_test_labels(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootdev_test_labels, UT_TESTF_DM | UT_TESTF_SCAN_FDT |
- UT_TESTF_ETH_BOOTDEV);
+BOOTSTD_TEST(bootdev_test_labels, UTF_DM | UTF_SCAN_FDT | UTF_ETH_BOOTDEV);
/* Check bootdev_find_by_any() */
static int bootdev_test_any(struct unit_test_state *uts)
{
struct udevice *dev, *media;
+ char *seq;
int mflags;
/*
@@ -158,9 +147,16 @@ static int bootdev_test_any(struct unit_test_state *uts)
* 8 [ ] OK mmc mmc2.bootdev
* 9 [ + ] OK mmc mmc1.bootdev
* a [ ] OK mmc mmc0.bootdev
+ *
+ * However if DSA_SANDBOX is disabled the dsa-test@{0,1} devices
+ * are not there.
*/
- console_record_reset_enable();
- ut_assertok(bootdev_find_by_any("8", &dev, &mflags));
+ if (CONFIG_IS_ENABLED(DSA_SANDBOX))
+ seq = "8";
+ else
+ seq = "6";
+
+ ut_assertok(bootdev_find_by_any(seq, &dev, &mflags));
ut_asserteq(UCLASS_BOOTDEV, device_get_uclass_id(dev));
ut_asserteq(BOOTFLOW_METHF_SINGLE_DEV, mflags);
media = dev_get_parent(dev);
@@ -187,8 +183,8 @@ static int bootdev_test_any(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootdev_test_any, UT_TESTF_DM | UT_TESTF_SCAN_FDT |
- UT_TESTF_ETH_BOOTDEV);
+BOOTSTD_TEST(bootdev_test_any, UTF_DM | UTF_SCAN_FDT | UTF_ETH_BOOTDEV |
+ UTF_CONSOLE);
/*
* Check bootdev ordering with the bootdev-order property and boot_targets
@@ -202,7 +198,7 @@ static int bootdev_test_order(struct unit_test_state *uts)
test_set_skip_delays(true);
/* Start up USB which gives us three additional bootdevs */
- usb_started = false;
+ bootstd_reset_usb();
ut_assertok(run_command("usb start", 0));
/*
@@ -224,6 +220,10 @@ static int bootdev_test_order(struct unit_test_state *uts)
/* Use the environment variable to override it */
ut_assertok(env_set("boot_targets", "mmc1 mmc2 usb"));
ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow));
+
+ /* get the usb device which has a backing file (flash1.img) */
+ ut_asserteq(0, bootflow_scan_next(&iter, &bflow));
+
ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow));
ut_asserteq(5, iter.num_devs);
ut_asserteq_str("mmc1.bootdev", iter.dev_used[0]->name);
@@ -263,7 +263,11 @@ static int bootdev_test_order(struct unit_test_state *uts)
ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow));
ut_asserteq(2, iter.num_devs);
- /* Now scan past mmc1 and make sure that the 3 USB devices show up */
+ /*
+ * Now scan past mmc1 and make sure that the 3 USB devices show up. The
+ * first one has a backing file so returns success
+ */
+ ut_asserteq(0, bootflow_scan_next(&iter, &bflow));
ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow));
ut_asserteq(6, iter.num_devs);
ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name);
@@ -275,7 +279,7 @@ static int bootdev_test_order(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootdev_test_order, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootdev_test_order, UTF_DM | UTF_SCAN_FDT);
/* Check default bootdev ordering */
static int bootdev_test_order_default(struct unit_test_state *uts)
@@ -302,7 +306,7 @@ static int bootdev_test_order_default(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootdev_test_order_default, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootdev_test_order_default, UTF_DM | UTF_SCAN_FDT);
/* Check bootdev ordering with the uclass priority */
static int bootdev_test_prio(struct unit_test_state *uts)
@@ -318,14 +322,17 @@ static int bootdev_test_prio(struct unit_test_state *uts)
test_set_eth_enable(false);
/* Start up USB which gives us three additional bootdevs */
- usb_started = false;
+ bootstd_reset_usb();
ut_assertok(run_command("usb start", 0));
ut_assertok(bootstd_test_drop_bootdev_order(uts));
/* 3 MMC and 3 USB bootdevs: MMC should come before USB */
- console_record_reset_enable();
ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow));
+
+ /* get the usb device which has a backing file (flash1.img) */
+ ut_asserteq(0, bootflow_scan_next(&iter, &bflow));
+
ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow));
ut_asserteq(6, iter.num_devs);
ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name);
@@ -343,6 +350,10 @@ static int bootdev_test_prio(struct unit_test_state *uts)
bootflow_iter_uninit(&iter);
ut_assertok(bootflow_scan_first(NULL, NULL, &iter, BOOTFLOWIF_HUNT,
&bflow));
+
+ /* get the usb device which has a backing file (flash1.img) */
+ ut_asserteq(0, bootflow_scan_next(&iter, &bflow));
+
ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow));
ut_asserteq(7, iter.num_devs);
ut_asserteq_str("usb_mass_storage.lun0.bootdev",
@@ -351,20 +362,19 @@ static int bootdev_test_prio(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootdev_test_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootdev_test_prio, UTF_DM | UTF_SCAN_FDT);
/* Check listing hunters */
static int bootdev_test_hunter(struct unit_test_state *uts)
{
struct bootstd_priv *std;
- usb_started = false;
+ bootstd_reset_usb();
test_set_skip_delays(true);
/* get access to the used hunters */
ut_assertok(bootstd_get_priv(&std));
- console_record_reset_enable();
bootdev_list_hunters(std);
ut_assert_nextline("Prio Used Uclass Hunter");
ut_assert_nextlinen("----");
@@ -382,8 +392,7 @@ static int bootdev_test_hunter(struct unit_test_state *uts)
ut_assert_console_end();
ut_assertok(bootdev_hunt("usb1", false));
- ut_assert_nextline(
- "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found");
+ ut_assert_skip_to_line("Bus usb@1: 5 USB Device(s) found");
ut_assert_console_end();
/* USB is 7th in the list, so bit 8 */
@@ -391,7 +400,7 @@ static int bootdev_test_hunter(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootdev_test_hunter, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootdev_test_hunter, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check 'bootdev hunt' command */
static int bootdev_test_cmd_hunt(struct unit_test_state *uts)
@@ -399,12 +408,11 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts)
struct bootstd_priv *std;
test_set_skip_delays(true);
- usb_started = false;
+ bootstd_reset_usb();
/* get access to the used hunters */
ut_assertok(bootstd_get_priv(&std));
- console_record_reset_enable();
ut_assertok(run_command("bootdev hunt -l", 0));
ut_assert_nextline("Prio Used Uclass Hunter");
ut_assert_nextlinen("----");
@@ -439,8 +447,7 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts)
ut_assert_nextline("scanning bus for devices...");
ut_assert_skip_to_line("Hunting with: spi_flash");
ut_assert_nextline("Hunting with: usb");
- ut_assert_nextline(
- "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found");
+ ut_assert_skip_to_line("Bus usb@1: 5 USB Device(s) found");
ut_assert_nextline("Hunting with: virtio");
ut_assert_console_end();
@@ -465,8 +472,8 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootdev_test_cmd_hunt, UT_TESTF_DM | UT_TESTF_SCAN_FDT |
- UT_TESTF_ETH_BOOTDEV);
+BOOTSTD_TEST(bootdev_test_cmd_hunt, UTF_DM | UTF_SCAN_FDT | UTF_ETH_BOOTDEV |
+ UTF_CONSOLE);
/* Check searching for bootdevs using the hunters */
static int bootdev_test_hunt_scan(struct unit_test_state *uts)
@@ -486,7 +493,7 @@ static int bootdev_test_hunt_scan(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootdev_test_hunt_scan, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootdev_test_hunt_scan, UTF_DM | UTF_SCAN_FDT);
/* Check that only bootable partitions are processed */
static int bootdev_test_bootable(struct unit_test_state *uts)
@@ -500,6 +507,7 @@ static int bootdev_test_bootable(struct unit_test_state *uts)
iter.part = 0;
ut_assertok(uclass_get_device_by_name(UCLASS_BLK, "mmc1.blk", &blk));
iter.dev = blk;
+ iter.flags = BOOTFLOWIF_ONLY_BOOTABLE;
ut_assertok(device_find_next_child(&iter.dev));
uclass_first_device(UCLASS_BOOTMETH, &bflow.method);
@@ -523,15 +531,14 @@ static int bootdev_test_bootable(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootdev_test_bootable, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootdev_test_bootable, UTF_DM | UTF_SCAN_FDT);
/* Check hunting for bootdev of a particular priority */
static int bootdev_test_hunt_prio(struct unit_test_state *uts)
{
- usb_started = false;
+ bootstd_reset_usb();
test_set_skip_delays(true);
- console_record_reset_enable();
ut_assertok(bootdev_hunt_prio(BOOTDEVP_4_SCAN_FAST, false));
ut_assert_nextline("scanning bus for devices...");
ut_assert_skip_to_line(" Type: Hard Disk");
@@ -542,13 +549,12 @@ static int bootdev_test_hunt_prio(struct unit_test_state *uts)
ut_assertok(bootdev_hunt_prio(BOOTDEVP_5_SCAN_SLOW, true));
ut_assert_nextline("Hunting with: ide");
ut_assert_nextline("Hunting with: usb");
- ut_assert_nextline(
- "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found");
+ ut_assert_skip_to_line("Bus usb@1: 5 USB Device(s) found");
ut_assert_console_end();
return 0;
}
-BOOTSTD_TEST(bootdev_test_hunt_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootdev_test_hunt_prio, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check hunting for bootdevs with a particular label */
static int bootdev_test_hunt_label(struct unit_test_state *uts)
@@ -557,13 +563,12 @@ static int bootdev_test_hunt_label(struct unit_test_state *uts)
struct bootstd_priv *std;
int mflags;
- usb_started = false;
+ bootstd_reset_usb();
/* get access to the used hunters */
ut_assertok(bootstd_get_priv(&std));
/* scan an unknown uclass */
- console_record_reset_enable();
old = (void *)&mflags; /* arbitrary pointer to check against dev */
dev = old;
mflags = 123;
@@ -596,12 +601,12 @@ static int bootdev_test_hunt_label(struct unit_test_state *uts)
ut_assertnonnull(dev);
ut_asserteq_str("usb_mass_storage.lun0.bootdev", dev->name);
ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS, mflags);
- ut_assert_nextlinen("Bus usb@1: scanning bus usb@1");
+ ut_assert_nextline("Bus usb@1: 5 USB Device(s) found");
ut_assert_console_end();
return 0;
}
-BOOTSTD_TEST(bootdev_test_hunt_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootdev_test_hunt_label, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check iterating to the next label in a list */
static int bootdev_test_next_label(struct unit_test_state *uts)
@@ -628,7 +633,6 @@ static int bootdev_test_next_label(struct unit_test_state *uts)
dev = NULL;
mflags = 123;
ut_assertok(bootdev_next_label(&iter, &dev, &mflags));
- console_record_reset_enable();
ut_assert_console_end();
ut_assertnonnull(dev);
ut_asserteq_str("mmc0.bootdev", dev->name);
@@ -639,7 +643,7 @@ static int bootdev_test_next_label(struct unit_test_state *uts)
ut_assertok(bootdev_next_label(&iter, &dev, &mflags));
ut_assert_nextline("scanning bus for devices...");
ut_assert_skip_to_line(
- " Capacity: 1.9 MB = 0.0 GB (4095 x 512)");
+ " Capacity: 2.0 MB = 0.0 GB (4096 x 512)");
ut_assert_console_end();
ut_assertnonnull(dev);
ut_asserteq_str("scsi.id0lun0.bootdev", dev->name);
@@ -678,9 +682,8 @@ static int bootdev_test_next_label(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootdev_test_next_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT |
- UT_TESTF_ETH_BOOTDEV | UT_TESTF_SF_BOOTDEV);
-
+BOOTSTD_TEST(bootdev_test_next_label, UTF_DM | UTF_SCAN_FDT | UTF_ETH_BOOTDEV |
+ UTF_SF_BOOTDEV | UTF_CONSOLE);
/* Check iterating to the next prioirty in a list */
static int bootdev_test_next_prio(struct unit_test_state *uts)
@@ -705,7 +708,6 @@ static int bootdev_test_next_prio(struct unit_test_state *uts)
iter.flags = BOOTFLOWIF_SHOW;
dev = NULL;
- console_record_reset_enable();
ut_assertok(bootdev_next_prio(&iter, &dev));
ut_assertnonnull(dev);
ut_asserteq_str("mmc2.bootdev", dev->name);
@@ -764,5 +766,5 @@ static int bootdev_test_next_prio(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootdev_test_next_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT |
- UT_TESTF_SF_BOOTDEV);
+BOOTSTD_TEST(bootdev_test_next_prio, UTF_DM | UTF_SCAN_FDT | UTF_SF_BOOTDEV |
+ UTF_CONSOLE);
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 674d4c05f83..b261bd5f620 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -6,21 +6,21 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <bootdev.h>
#include <bootflow.h>
#include <bootmeth.h>
#include <bootstd.h>
#include <cli.h>
#include <dm.h>
-#include <efi_default_filename.h>
+#include <efi.h>
+#include <efi_loader.h>
#include <expo.h>
+#include <mapmem.h>
#ifdef CONFIG_SANDBOX
#include <asm/test.h>
#endif
#include <dm/device-internal.h>
#include <dm/lists.h>
-#include <test/suites.h>
#include <test/ut.h>
#include "bootstd_common.h"
#include "../../boot/bootflow_internal.h"
@@ -28,9 +28,13 @@
DECLARE_GLOBAL_DATA_PTR;
+extern U_BOOT_DRIVER(bootmeth_android);
extern U_BOOT_DRIVER(bootmeth_cros);
extern U_BOOT_DRIVER(bootmeth_2script);
+/* Use this as the vendor for EFI to tell the app to exit boot services */
+static u16 __efi_runtime_data test_vendor[] = u"U-Boot testing";
+
static int inject_response(struct unit_test_state *uts)
{
/*
@@ -50,7 +54,6 @@ static int inject_response(struct unit_test_state *uts)
/* Check 'bootflow scan/list' commands */
static int bootflow_cmd(struct unit_test_state *uts)
{
- console_record_reset_enable();
ut_assertok(run_command("bootdev select 1", 0));
ut_assert_console_end();
ut_assertok(run_command("bootflow scan -lH", 0));
@@ -74,16 +77,23 @@ static int bootflow_cmd(struct unit_test_state *uts)
ut_assert_nextline("(1 bootflow, 1 valid)");
ut_assert_console_end();
+ ut_assertok(run_command("bootstd images", 0));
+ ut_assert_nextlinen("Seq");
+ ut_assert_nextlinen("---");
+ ut_assert_nextlinen(" 0 mmc1.bootdev.part_1 extlinux_cfg");
+ ut_assert_nextlinen("---");
+ ut_assert_nextline("(1 image)");
+ ut_assert_console_end();
+
return 0;
}
-BOOTSTD_TEST(bootflow_cmd, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootflow_cmd, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check 'bootflow scan' with a label / seq */
static int bootflow_cmd_label(struct unit_test_state *uts)
{
test_set_eth_enable(false);
- console_record_reset_enable();
ut_assertok(run_command("bootflow scan -lH mmc1", 0));
ut_assert_nextline("Scanning for bootflows with label 'mmc1'");
ut_assert_skip_to_line("(1 bootflow, 1 valid)");
@@ -111,9 +121,17 @@ static int bootflow_cmd_label(struct unit_test_state *uts)
* 8 [ ] OK mmc mmc2.bootdev
* 9 [ + ] OK mmc mmc1.bootdev
* a [ ] OK mmc mmc0.bootdev
+ *
+ * However with CONFIG_DSA_SANDBOX=n we have two fewer (dsa-test@0 and
+ * dsa-test@1).
*/
- ut_assertok(run_command("bootflow scan -lH 9", 0));
- ut_assert_nextline("Scanning for bootflows with label '9'");
+ if (CONFIG_IS_ENABLED(DSA_SANDBOX)) {
+ ut_assertok(run_command("bootflow scan -lH 9", 0));
+ ut_assert_nextline("Scanning for bootflows with label '9'");
+ } else {
+ ut_assertok(run_command("bootflow scan -lH 7", 0));
+ ut_assert_nextline("Scanning for bootflows with label '7'");
+ }
ut_assert_skip_to_line("(1 bootflow, 1 valid)");
ut_assertok(run_command("bootflow scan -lH 0", 0));
@@ -123,15 +141,14 @@ static int bootflow_cmd_label(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootflow_cmd_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT |
- UT_TESTF_ETH_BOOTDEV);
+BOOTSTD_TEST(bootflow_cmd_label, UTF_DM | UTF_SCAN_FDT | UTF_ETH_BOOTDEV |
+ UTF_CONSOLE);
/* Check 'bootflow scan/list' commands using all bootdevs */
static int bootflow_cmd_glob(struct unit_test_state *uts)
{
ut_assertok(bootstd_test_drop_bootdev_order(uts));
- console_record_reset_enable();
ut_assertok(run_command("bootflow scan -lGH", 0));
ut_assert_nextline("Scanning for bootflows in all bootdevs");
ut_assert_nextline("Seq Method State Uclass Part Name Filename");
@@ -156,14 +173,13 @@ static int bootflow_cmd_glob(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootflow_cmd_glob, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootflow_cmd_glob, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check 'bootflow scan -e' */
static int bootflow_cmd_scan_e(struct unit_test_state *uts)
{
ut_assertok(bootstd_test_drop_bootdev_order(uts));
- console_record_reset_enable();
ut_assertok(run_command("bootflow scan -aleGH", 0));
ut_assert_nextline("Scanning for bootflows in all bootdevs");
ut_assert_nextline("Seq Method State Uclass Part Name Filename");
@@ -180,8 +196,9 @@ static int bootflow_cmd_scan_e(struct unit_test_state *uts)
ut_assert_nextline(" 3 efi media mmc 0 mmc1.bootdev.whole ");
ut_assert_nextline(" ** No partition found, err=-2: No such file or directory");
ut_assert_nextline(" 4 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf");
- ut_assert_nextline(" 5 efi fs mmc 1 mmc1.bootdev.part_1 /EFI/BOOT/"
- BOOTEFI_NAME);
+ ut_assert_nextline(
+ " 5 efi fs mmc 1 mmc1.bootdev.part_1 /EFI/BOOT/%s",
+ efi_get_basename());
ut_assert_skip_to_line("Scanning bootdev 'mmc0.bootdev':");
ut_assert_skip_to_line(
@@ -207,12 +224,11 @@ static int bootflow_cmd_scan_e(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootflow_cmd_scan_e, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootflow_cmd_scan_e, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check 'bootflow info' */
static int bootflow_cmd_info(struct unit_test_state *uts)
{
- console_record_reset_enable();
ut_assertok(run_command("bootdev select 1", 0));
ut_assert_console_end();
ut_assertok(run_command("bootflow scan", 0));
@@ -248,12 +264,11 @@ static int bootflow_cmd_info(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootflow_cmd_info, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootflow_cmd_info, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check 'bootflow scan -b' to boot the first available bootdev */
static int bootflow_scan_boot(struct unit_test_state *uts)
{
- console_record_reset_enable();
ut_assertok(inject_response(uts));
ut_assertok(run_command("bootflow scan -b", 0));
ut_assert_nextline(
@@ -270,7 +285,7 @@ static int bootflow_scan_boot(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootflow_scan_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootflow_scan_boot, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check iterating through available bootflows */
static int bootflow_iter(struct unit_test_state *uts)
@@ -282,8 +297,9 @@ static int bootflow_iter(struct unit_test_state *uts)
/* The first device is mmc2.bootdev which has no media */
ut_asserteq(-EPROTONOSUPPORT,
- bootflow_scan_first(NULL, NULL, &iter,
- BOOTFLOWIF_ALL | BOOTFLOWIF_SKIP_GLOBAL, &bflow));
+ bootflow_scan_first(NULL, NULL, &iter, BOOTFLOWIF_ALL |
+ BOOTFLOWIF_SKIP_GLOBAL |
+ BOOTFLOWIF_ONLY_BOOTABLE, &bflow));
ut_asserteq(2, iter.num_methods);
ut_asserteq(0, iter.cur_method);
ut_asserteq(0, iter.part);
@@ -368,7 +384,7 @@ static int bootflow_iter(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootflow_iter, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootflow_iter, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
#if defined(CONFIG_SANDBOX) && defined(CONFIG_BOOTMETH_GLOBAL)
/* Check using the system bootdev */
@@ -386,7 +402,6 @@ static int bootflow_system(struct unit_test_state *uts)
/* We should get a single 'bootmgr' method right at the end */
bootstd_clear_glob();
- console_record_reset_enable();
ut_assertok(run_command("bootflow scan -lH", 0));
ut_assert_skip_to_line(
" 0 efi_mgr ready (none) 0 <NULL> ");
@@ -396,8 +411,8 @@ static int bootflow_system(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootflow_system, UT_TESTF_DM | UT_TESTF_SCAN_PDATA |
- UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootflow_system, UTF_DM | UTF_SCAN_PDATA | UTF_SCAN_FDT |
+ UTF_CONSOLE);
#endif
/* Check disabling a bootmethod if it requests it */
@@ -416,7 +431,6 @@ static int bootflow_iter_disable(struct unit_test_state *uts)
ut_assertok(bootstd_test_drop_bootdev_order(uts));
bootstd_clear_glob();
- console_record_reset_enable();
ut_assertok(inject_response(uts));
ut_assertok(run_command("bootflow scan -lbH", 0));
@@ -438,7 +452,7 @@ static int bootflow_iter_disable(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootflow_iter_disable, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootflow_iter_disable, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check 'bootflow scan' with a bootmeth ordering including a global bootmeth */
static int bootflow_scan_glob_bootmeth(struct unit_test_state *uts)
@@ -452,7 +466,6 @@ static int bootflow_scan_glob_bootmeth(struct unit_test_state *uts)
* Make sure that the -G flag makes the scan fail, since this is not
* supported when an ordering is provided
*/
- console_record_reset_enable();
ut_assertok(bootmeth_set_order("efi firmware0"));
ut_assertok(run_command("bootflow scan -lGH", 0));
ut_assert_nextline("Scanning for bootflows in all bootdevs");
@@ -479,12 +492,12 @@ static int bootflow_scan_glob_bootmeth(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootflow_scan_glob_bootmeth, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootflow_scan_glob_bootmeth, UTF_DM | UTF_SCAN_FDT |
+ UTF_CONSOLE);
/* Check 'bootflow boot' to boot a selected bootflow */
static int bootflow_cmd_boot(struct unit_test_state *uts)
{
- console_record_reset_enable();
ut_assertok(run_command("bootdev select 1", 0));
ut_assert_console_end();
ut_assertok(run_command("bootflow scan", 0));
@@ -508,7 +521,7 @@ static int bootflow_cmd_boot(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootflow_cmd_boot, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/**
* prep_mmc_bootdev() - Set up an mmc bootdev so we can access other distros
@@ -519,12 +532,12 @@ BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
* @uts: Unit test state
* @mmc_dev: MMC device to use, e.g. "mmc4". Note that this must remain valid
* in the caller until
- * @bind_cros: true to bind the ChromiumOS bootmeth
+ * @bind_cros: true to bind the ChromiumOS and Android bootmeths
* @old_orderp: Returns the original bootdev order, which must be restored
* Returns 0 on success, -ve on failure
*/
static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
- bool bind_cros, const char ***old_orderp)
+ bool bind_cros_android, const char ***old_orderp)
{
static const char *order[] = {"mmc2", "mmc1", NULL, NULL};
struct udevice *dev, *bootstd;
@@ -534,7 +547,7 @@ static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
order[2] = mmc_dev;
- /* Enable the mmc4 node since we need a second bootflow */
+ /* Enable the requested mmc node since we need a second bootflow */
root = oftree_root(oftree_default());
node = ofnode_find_subnode(root, mmc_dev);
ut_assert(ofnode_valid(node));
@@ -543,15 +556,22 @@ static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
/* Enable the script bootmeth too */
ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_2script),
- "bootmeth_script", 0, ofnode_null(), &dev));
+ "script", 0, ofnode_null(), &dev));
/* Enable the cros bootmeth if needed */
- if (IS_ENABLED(CONFIG_BOOTMETH_CROS) && bind_cros) {
+ if (IS_ENABLED(CONFIG_BOOTMETH_CROS) && bind_cros_android) {
ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_cros),
"cros", 0, ofnode_null(), &dev));
}
+ /* Enable the android bootmeths if needed */
+ if (IS_ENABLED(CONFIG_BOOTMETH_ANDROID) && bind_cros_android) {
+ ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
+ ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_android),
+ "android", 0, ofnode_null(), &dev));
+ }
+
/* Change the order to include the device */
std = dev_get_priv(bootstd);
old_order = std->bootdev_order;
@@ -578,7 +598,6 @@ static int scan_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
ut_assertok(prep_mmc_bootdev(uts, mmc_dev, bind_cros, &old_order));
- console_record_reset_enable();
ut_assertok(run_command("bootflow scan", 0));
ut_assert_console_end();
@@ -591,6 +610,36 @@ static int scan_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
}
/**
+ * scan_mmc_android_bootdev() - Set up an mmc bootdev so we can access other
+ * distros. Android bootflow might print "ANDROID:*" while scanning
+ *
+ * @uts: Unit test state
+ * @mmc_dev: MMC device to use, e.g. "mmc4"
+ * Returns 0 on success, -ve on failure
+ */
+static int scan_mmc_android_bootdev(struct unit_test_state *uts, const char *mmc_dev)
+{
+ struct bootstd_priv *std;
+ struct udevice *bootstd;
+ const char **old_order;
+
+ ut_assertok(prep_mmc_bootdev(uts, mmc_dev, true, &old_order));
+
+ ut_assertok(run_command("bootflow scan", 0));
+ /* Android bootflow might print one or two 'ANDROID:*' logs */
+ ut_check_skipline(uts);
+ ut_check_skipline(uts);
+ ut_assert_console_end();
+
+ /* Restore the order used by the device tree */
+ ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
+ std = dev_get_priv(bootstd);
+ std->bootdev_order = old_order;
+
+ return 0;
+}
+
+/**
* scan_mmc4_bootdev() - Set up the mmc4 bootdev so we can access a fake Armbian
*
* @uts: Unit test state
@@ -637,7 +686,7 @@ static int bootflow_cmd_menu(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootflow_cmd_menu, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootflow_cmd_menu, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check 'bootflow scan -m' to select a bootflow using a menu */
static int bootflow_scan_menu(struct unit_test_state *uts)
@@ -685,8 +734,7 @@ static int bootflow_scan_menu(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootflow_scan_menu,
- UT_TESTF_DM | UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
+BOOTSTD_TEST(bootflow_scan_menu, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check 'bootflow scan -mb' to select and boot a bootflow using a menu */
static int bootflow_scan_menu_boot(struct unit_test_state *uts)
@@ -732,8 +780,7 @@ static int bootflow_scan_menu_boot(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootflow_scan_menu_boot,
- UT_TESTF_DM | UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
+BOOTSTD_TEST(bootflow_scan_menu_boot, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check searching for a single bootdev using the hunters */
static int bootflow_cmd_hunt_single(struct unit_test_state *uts)
@@ -745,7 +792,6 @@ static int bootflow_cmd_hunt_single(struct unit_test_state *uts)
ut_assertok(bootstd_test_drop_bootdev_order(uts));
- console_record_reset_enable();
ut_assertok(run_command("bootflow scan -l mmc1", 0));
ut_assert_nextline("Scanning for bootflows with label 'mmc1'");
ut_assert_skip_to_line("(1 bootflow, 1 valid)");
@@ -756,7 +802,8 @@ static int bootflow_cmd_hunt_single(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootflow_cmd_hunt_single, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootflow_cmd_hunt_single, UTF_DM | UTF_SCAN_FDT |
+ UTF_CONSOLE);
/* Check searching for a uclass label using the hunters */
static int bootflow_cmd_hunt_label(struct unit_test_state *uts)
@@ -770,7 +817,6 @@ static int bootflow_cmd_hunt_label(struct unit_test_state *uts)
test_set_eth_enable(false);
ut_assertok(bootstd_test_drop_bootdev_order(uts));
- console_record_reset_enable();
ut_assertok(run_command("bootflow scan -l mmc", 0));
/* check that the hunter was used */
@@ -793,7 +839,7 @@ static int bootflow_cmd_hunt_label(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootflow_cmd_hunt_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootflow_cmd_hunt_label, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/**
* check_font() - Check that the font size for an item matches expectations
@@ -825,6 +871,9 @@ static int bootflow_menu_theme(struct unit_test_state *uts)
ofnode node;
int i;
+ if (!CONFIG_IS_ENABLED(BOOTSTD_MENU))
+ return -EAGAIN;
+
ut_assertok(scan_mmc4_bootdev(uts));
ut_assertok(bootflow_menu_new(&exp));
@@ -853,7 +902,7 @@ static int bootflow_menu_theme(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootflow_menu_theme, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootflow_menu_theme, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/**
* check_arg() - Check both the normal case and the buffer-overflow case
@@ -1089,7 +1138,6 @@ static int bootflow_cmdline(struct unit_test_state *uts)
{
ut_assertok(run_command("bootflow scan mmc", 0));
ut_assertok(run_command("bootflow sel 0", 0));
- console_record_reset_enable();
ut_asserteq(1, run_command("bootflow cmdline get fred", 0));
ut_assert_nextline("Argument not found");
@@ -1113,13 +1161,11 @@ static int bootflow_cmdline(struct unit_test_state *uts)
ut_asserteq(0, run_command("bootflow cmdline set mary abc", 0));
ut_asserteq(0, run_command("bootflow cmdline set mary", 0));
- ut_assert_nextline_empty();
-
ut_assert_console_end();
return 0;
}
-BOOTSTD_TEST(bootflow_cmdline, 0);
+BOOTSTD_TEST(bootflow_cmdline, UTF_CONSOLE);
/* test a few special changes to a long command line */
static int bootflow_cmdline_special(struct unit_test_state *uts)
@@ -1156,8 +1202,214 @@ static int bootflow_cros(struct unit_test_state *uts)
ut_assert_nextlinen("---");
ut_assert_skip_to_line("(3 bootflows, 3 valid)");
+ ut_assertok(run_command("bootstd images", 0));
+ ut_assert_nextlinen("Seq");
+ ut_assert_nextlinen("---");
+ ut_assert_nextlinen(" 0 mmc1.bootdev.part_1 extlinux_cfg");
+ ut_assert_nextlinen(" 1 mmc5.bootdev.part_2 x86_setup");
+ ut_assert_nextlinen(" 1 mmc5.bootdev.part_2 cmdline");
+ ut_assert_nextlinen(" 1 mmc5.bootdev.part_2 kernel - 4000 kernel");
+ ut_assert_nextlinen(" 2 mmc5.bootdev.part_4 x86_setup");
+ ut_assert_nextlinen(" 2 mmc5.bootdev.part_4 cmdline");
+ ut_assert_nextlinen(" 2 mmc5.bootdev.part_4 kernel - 4000 kernel");
+ ut_assert_nextlinen("---");
+ ut_assert_nextline("(7 images)");
+
+ ut_assert_console_end();
+
+ return 0;
+}
+BOOTSTD_TEST(bootflow_cros, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT);
+
+/* Test Android bootmeth with boot image version 4 */
+static int bootflow_android_image_v4(struct unit_test_state *uts)
+{
+ if (!IS_ENABLED(CONFIG_BOOTMETH_ANDROID))
+ return -EAGAIN;
+
+ ut_assertok(scan_mmc_android_bootdev(uts, "mmc7"));
+ ut_assertok(run_command("bootflow list", 0));
+
+ ut_assert_nextlinen("Showing all");
+ ut_assert_nextlinen("Seq");
+ ut_assert_nextlinen("---");
+ ut_assert_nextlinen(" 0 extlinux");
+ ut_assert_nextlinen(" 1 android ready mmc 0 mmc7.bootdev.whole ");
+ ut_assert_nextlinen("---");
+ ut_assert_skip_to_line("(2 bootflows, 2 valid)");
+
+ ut_assert_console_end();
+
+ return 0;
+}
+BOOTSTD_TEST(bootflow_android_image_v4, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT);
+
+/* Test Android bootmeth with boot image version 2 */
+static int bootflow_android_image_v2(struct unit_test_state *uts)
+{
+ if (!IS_ENABLED(CONFIG_BOOTMETH_ANDROID))
+ return -EAGAIN;
+
+ ut_assertok(scan_mmc_android_bootdev(uts, "mmc8"));
+ ut_assertok(run_command("bootflow list", 0));
+
+ ut_assert_nextlinen("Showing all");
+ ut_assert_nextlinen("Seq");
+ ut_assert_nextlinen("---");
+ ut_assert_nextlinen(" 0 extlinux");
+ ut_assert_nextlinen(" 1 android ready mmc 0 mmc8.bootdev.whole ");
+ ut_assert_nextlinen("---");
+ ut_assert_skip_to_line("(2 bootflows, 2 valid)");
+
+ ut_assert_console_end();
+
+ return 0;
+}
+BOOTSTD_TEST(bootflow_android_image_v2, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT);
+
+/* Test EFI bootmeth */
+static int bootflow_efi(struct unit_test_state *uts)
+{
+ static const char *order[] = {"mmc1", "usb", NULL};
+ struct bootstd_priv *std;
+ struct udevice *bootstd;
+ const char **old_order;
+
+ ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
+ std = dev_get_priv(bootstd);
+ old_order = std->bootdev_order;
+ std->bootdev_order = order;
+
+ /* disable ethernet since the hunter will run dhcp */
+ test_set_eth_enable(false);
+
+ /* make USB scan without delays */
+ test_set_skip_delays(true);
+
+ bootstd_reset_usb();
+
+ ut_assertok(run_command("bootflow scan", 0));
+ ut_assert_skip_to_line(
+ "Bus usb@1: 5 USB Device(s) found");
+
+ ut_assertok(run_command("bootflow list", 0));
+
+ ut_assert_nextlinen("Showing all");
+ ut_assert_nextlinen("Seq");
+ ut_assert_nextlinen("---");
+ ut_assert_nextlinen(" 0 extlinux");
+ ut_assert_nextlinen(
+ " 1 efi ready usb_mass_ 1 usb_mass_storage.lun0.boo /EFI/BOOT/BOOTSBOX.EFI");
+ ut_assert_nextlinen("---");
+ ut_assert_skip_to_line("(2 bootflows, 2 valid)");
+ ut_assert_console_end();
+
+ ut_assertok(run_command("bootflow select 1", 0));
+ ut_assert_console_end();
+
+ systab.fw_vendor = test_vendor;
+
+ ut_asserteq(1, run_command("bootflow boot", 0));
+ ut_assert_nextline(
+ "** Booting bootflow 'usb_mass_storage.lun0.bootdev.part_1' with efi");
+ if (IS_ENABLED(CONFIG_LOGF_FUNC))
+ ut_assert_skip_to_line(" efi_run_image() Booting /\\EFI\\BOOT\\BOOTSBOX.EFI");
+ else
+ ut_assert_skip_to_line("Booting /\\EFI\\BOOT\\BOOTSBOX.EFI");
+
+ /* TODO: Why the \r ? */
+ ut_assert_nextline("U-Boot test app for EFI_LOADER\r");
+ ut_assert_nextline("Exiting test app");
+ ut_assert_nextline("Boot failed (err=-14)");
+
+ ut_assert_console_end();
+
+ ut_assertok(bootstd_test_drop_bootdev_order(uts));
+
+ return 0;
+}
+BOOTSTD_TEST(bootflow_efi, UTF_CONSOLE);
+
+/* Check 'bootflow scan' provides a list of images */
+static int bootstd_images(struct unit_test_state *uts)
+{
+ static const char *order[] = {"mmc2", "mmc1", "mmc4", "mmc5", NULL};
+ const struct legacy_img_hdr *hdr;
+ const struct bootflow_img *img;
+ const struct bootflow *bflow;
+ struct bootstd_priv *std;
+ const char **old_order;
+ struct udevice *dev;
+ ofnode root, node;
+ ulong data, len;
+ char *ptr;
+
+ /* get access to the current bootflow */
+ ut_assertok(bootstd_get_priv(&std));
+
+ ut_assertok(prep_mmc_bootdev(uts, "mmc4", true, &old_order));
+
+ /* bind mmc5 too, for cros */
+ root = oftree_root(oftree_default());
+ node = ofnode_find_subnode(root, "mmc5");
+ ut_assert(ofnode_valid(node));
+ ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false));
+
+ std->bootdev_order = order;
+ ut_assertok(run_command("bootflow scan", 0));
+ ut_assert_console_end();
+ std->bootdev_order = old_order;
+
+ ut_assertok(run_command("bootflow list", 0));
+ ut_assert_skip_to_line("(4 bootflows, 4 valid)");
+
+ ut_assertok(run_command("bootstd images", 0));
+ ut_assert_nextlinen("Seq");
+ ut_assert_nextlinen("---");
+ ut_assert_nextlinen(" 0 mmc1.bootdev.part_1 extlinux_cfg");
+ ut_assert_nextlinen(" 1 mmc4.bootdev.part_1 script");
+ ut_assert_nextlinen(" 1 mmc4.bootdev.part_1 logo");
+ ut_assert_nextlinen(" 2 mmc5.bootdev.part_2 x86_setup");
+ ut_assert_nextlinen(" 2 mmc5.bootdev.part_2 cmdline");
+ ut_assert_nextlinen(" 2 mmc5.bootdev.part_2 kernel -");
+ ut_assert_nextlinen(" 3 mmc5.bootdev.part_4 x86_setup");
+ ut_assert_nextlinen(" 3 mmc5.bootdev.part_4 cmdline");
+ ut_assert_nextlinen(" 3 mmc5.bootdev.part_4 kernel -");
+ ut_assert_nextlinen("---");
+ ut_assert_nextline("(9 images)");
+
+ /* check the first image */
+ bflow = alist_get(&std->bootflows, 0, struct bootflow);
+ img = alist_get(&bflow->images, 0, struct bootflow_img);
+ ut_asserteq_strn("# extlinux.conf", map_sysmem(img->addr, 0));
+
+ /* check the second image */
+ bflow = alist_get(&std->bootflows, 1, struct bootflow);
+ img = alist_get(&bflow->images, 0, struct bootflow_img);
+
+ /* this is the length of the script in bytes */
+ hdr = map_sysmem(img->addr, 0);
+ image_multi_getimg(hdr, 0, &data, &len);
+ ptr = (void *)data;
+ ut_asserteq_strn("# DO NOT EDIT THIS FILE", ptr);
+
+ /* check the ChromiumOS images */
+ bflow = alist_get(&std->bootflows, 2, struct bootflow);
+ img = alist_get(&bflow->images, 1, struct bootflow_img);
+ ptr = map_sysmem(img->addr, 0);
+ ut_asserteq_strn("BOOT_IMAGE=/vmlinuz-5.15.0-121-generic root=", ptr);
+
+ /*
+ * the x86 setup is not a real binary, so just check that it is empty,
+ * so that if this changes in the future someone will notice and update
+ * this test
+ */
+ img = alist_get(&bflow->images, 0, struct bootflow_img);
+ ptr = map_sysmem(img->addr, 0);
+ ut_asserteq(0, *(ulong *)ptr);
+
ut_assert_console_end();
return 0;
}
-BOOTSTD_TEST(bootflow_cros, 0);
+BOOTSTD_TEST(bootstd_images, UTF_CONSOLE);
diff --git a/test/bootm.c b/test/boot/bootm.c
index 4bb3ca0655c..1d1efe71ad5 100644
--- a/test/bootm.c
+++ b/test/boot/bootm.c
@@ -5,16 +5,14 @@
* Copyright 2020 Google LLC
*/
-#include <common.h>
#include <bootm.h>
#include <asm/global_data.h>
-#include <test/suites.h>
#include <test/test.h>
#include <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
-#define BOOTM_TEST(_name, _flags) UNIT_TEST(_name, _flags, bootm_test)
+#define BOOTM_TEST(_name, _flags) UNIT_TEST(_name, _flags, bootm)
enum {
BUF_SIZE = 1024,
@@ -27,12 +25,16 @@ static int bootm_test_nop(struct unit_test_state *uts)
{
char buf[BUF_SIZE];
+ /* This tests relies on GD_FLG_SILENT not being set */
+ gd->flags &= ~GD_FLG_SILENT;
+ env_set("silent_linux", NULL);
+
*buf = '\0';
- ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, true));
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_ALL));
ut_asserteq_str("", buf);
strcpy(buf, "test");
- ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, true));
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_ALL));
ut_asserteq_str("test", buf);
return 0;
@@ -44,23 +46,26 @@ static int bootm_test_nospace(struct unit_test_state *uts)
{
char buf[BUF_SIZE];
+ /* This tests relies on GD_FLG_SILENT not being set */
+ gd->flags &= ~GD_FLG_SILENT;
+
/* Zero buffer size */
*buf = '\0';
- ut_asserteq(-ENOSPC, bootm_process_cmdline(buf, 0, true));
+ ut_asserteq(-ENOSPC, bootm_process_cmdline(buf, 0, BOOTM_CL_ALL));
/* Buffer string not terminated */
memset(buf, 'a', BUF_SIZE);
- ut_asserteq(-ENOSPC, bootm_process_cmdline(buf, BUF_SIZE, true));
+ ut_asserteq(-ENOSPC, bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_ALL));
/* Not enough space to copy string */
memset(buf, '\0', BUF_SIZE);
memset(buf, 'a', BUF_SIZE / 2);
- ut_asserteq(-ENOSPC, bootm_process_cmdline(buf, BUF_SIZE, true));
+ ut_asserteq(-ENOSPC, bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_ALL));
/* Just enough space */
memset(buf, '\0', BUF_SIZE);
memset(buf, 'a', BUF_SIZE / 2 - 1);
- ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, true));
+ ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_ALL));
return 0;
}
@@ -71,6 +76,9 @@ static int bootm_test_silent(struct unit_test_state *uts)
{
char buf[BUF_SIZE];
+ /* This tests relies on GD_FLG_SILENT not being set */
+ gd->flags &= ~GD_FLG_SILENT;
+
/* 'silent_linux' not set should do nothing */
env_set("silent_linux", NULL);
strcpy(buf, CONSOLE_STR);
@@ -175,6 +183,7 @@ static int bootm_test_subst(struct unit_test_state *uts)
ut_asserteq(0, bootm_process_cmdline(buf, 22, BOOTM_CL_SUBST));
/* Check multiple substitutions */
+ ut_assertok(env_set("bvar", NULL));
ut_assertok(env_set("var", "abc"));
strcpy(buf, "some${var}thing${bvar}else");
ut_asserteq(0, bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SUBST));
@@ -193,6 +202,7 @@ BOOTM_TEST(bootm_test_subst, 0);
/* Test silent processing in the bootargs variable */
static int bootm_test_silent_var(struct unit_test_state *uts)
{
+ ut_assertok(env_set("var", NULL));
env_set("bootargs", NULL);
ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SUBST));
ut_assertnull(env_get("bootargs"));
@@ -238,12 +248,3 @@ static int bootm_test_subst_both(struct unit_test_state *uts)
return 0;
}
BOOTM_TEST(bootm_test_subst_both, 0);
-
-int do_ut_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(bootm_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(bootm_test);
-
- return cmd_ut_category("bootm", "bootm_test_", tests, n_ents,
- argc, argv);
-}
diff --git a/test/boot/bootmeth.c b/test/boot/bootmeth.c
index e498eee036e..577f259fb37 100644
--- a/test/boot/bootmeth.c
+++ b/test/boot/bootmeth.c
@@ -6,18 +6,15 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <bootmeth.h>
#include <bootstd.h>
#include <dm.h>
-#include <test/suites.h>
#include <test/ut.h>
#include "bootstd_common.h"
/* Check 'bootmeth list' command */
static int bootmeth_cmd_list(struct unit_test_state *uts)
{
- console_record_reset_enable();
ut_assertok(run_command("bootmeth list", 0));
ut_assert_nextline("Order Seq Name Description");
ut_assert_nextlinen("---");
@@ -32,13 +29,12 @@ static int bootmeth_cmd_list(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootmeth_cmd_list, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootmeth_cmd_list, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check 'bootmeth order' command */
static int bootmeth_cmd_order(struct unit_test_state *uts)
{
/* Select just one bootmethod */
- console_record_reset_enable();
ut_assertok(run_command("bootmeth order extlinux", 0));
ut_assert_console_end();
ut_assertnonnull(env_get("bootmeths"));
@@ -105,7 +101,7 @@ static int bootmeth_cmd_order(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootmeth_cmd_order, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootmeth_cmd_order, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check 'bootmeth order' command with global bootmeths */
static int bootmeth_cmd_order_glob(struct unit_test_state *uts)
@@ -113,7 +109,6 @@ static int bootmeth_cmd_order_glob(struct unit_test_state *uts)
if (!IS_ENABLED(CONFIG_BOOTMETH_GLOBAL))
return -EAGAIN;
- console_record_reset_enable();
ut_assertok(run_command("bootmeth order \"efi firmware0\"", 0));
ut_assert_console_end();
ut_assertok(run_command("bootmeth list", 0));
@@ -129,7 +124,54 @@ static int bootmeth_cmd_order_glob(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootmeth_cmd_order_glob, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootmeth_cmd_order_glob, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
+
+/* Check 'bootmeth set' command */
+static int bootmeth_cmd_set(struct unit_test_state *uts)
+{
+ /* Check we can enable extlinux fallback */
+ console_record_reset_enable();
+ ut_assertok(run_command("bootmeth set extlinux fallback 1", 0));
+ ut_assert_console_end();
+
+ /* Check we can disable extlinux fallback */
+ console_record_reset_enable();
+ ut_assertok(run_command("bootmeth set extlinux fallback 0", 0));
+ ut_assert_console_end();
+
+ /* Check extlinux fallback unexpected value */
+ console_record_reset_enable();
+ ut_asserteq(1, run_command("bootmeth set extlinux fallback fred", 0));
+ ut_assert_nextline("Unexpected value 'fred'");
+ ut_assert_nextline("Failed (err=-22)");
+ ut_assert_console_end();
+
+ /* Check that we need to provide right number of parameters */
+ ut_asserteq(1, run_command("bootmeth set extlinux fallback", 0));
+ ut_assert_nextline("Required parameters not provided");
+ ut_assert_console_end();
+
+ /* Check that we need to provide a valid bootmethod */
+ ut_asserteq(1, run_command("bootmeth set fred fallback 0", 0));
+ ut_assert_nextline("Unknown bootmeth 'fred'");
+ ut_assert_nextline("Failed (err=-19)");
+ ut_assert_console_end();
+
+ /* Check that we need to provide a valid property */
+ ut_asserteq(1, run_command("bootmeth set extlinux fred 0", 0));
+ ut_assert_nextline("Invalid option");
+ ut_assert_nextline("Failed (err=-22)");
+ ut_assert_console_end();
+
+ /* Check that we need to provide a bootmeth that supports properties */
+ ut_asserteq(1, run_command("bootmeth set efi fallback 0", 0));
+ ut_assert_nextline("set_property not found");
+ ut_assert_nextline("Failed (err=-19)");
+ ut_assert_console_end();
+
+ return 0;
+}
+BOOTSTD_TEST(bootmeth_cmd_set, UTF_DM | UTF_SCAN_FDT);
/* Check 'bootmeths' env var */
static int bootmeth_env(struct unit_test_state *uts)
@@ -139,7 +181,6 @@ static int bootmeth_env(struct unit_test_state *uts)
ut_assertok(bootstd_get_priv(&std));
/* Select just one bootmethod */
- console_record_reset_enable();
ut_assertok(env_set("bootmeths", "extlinux"));
ut_asserteq(1, std->bootmeth_count);
@@ -155,7 +196,7 @@ static int bootmeth_env(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootmeth_env, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootmeth_env, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check the get_state_desc() method */
static int bootmeth_state(struct unit_test_state *uts)
@@ -171,4 +212,4 @@ static int bootmeth_state(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(bootmeth_state, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(bootmeth_state, UTF_DM | UTF_SCAN_FDT);
diff --git a/test/boot/bootstd_common.c b/test/boot/bootstd_common.c
index cc97e255e5c..052c0fe5cc6 100644
--- a/test/boot/bootstd_common.c
+++ b/test/boot/bootstd_common.c
@@ -6,14 +6,13 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <bootdev.h>
#include <bootstd.h>
#include <dm.h>
#include <memalign.h>
#include <mmc.h>
+#include <usb.h>
#include <linux/log2.h>
-#include <test/suites.h>
#include <test/ut.h>
#include <u-boot/crc.h>
#include "bootstd_common.h"
@@ -21,8 +20,14 @@
/* 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)
+/**
+ * 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
+ */
+static int bootstd_setup_for_tests(struct unit_test_state *uts)
{
ALLOC_CACHE_ALIGN_BUFFER(u8, buf, MMC_MAX_BLOCK_LEN);
struct udevice *mmc;
@@ -55,6 +60,7 @@ int bootstd_setup_for_tests(void)
return 0;
}
+BOOTSTD_TEST_INIT(bootstd_setup_for_tests, 0);
int bootstd_test_drop_bootdev_order(struct unit_test_state *uts)
{
@@ -89,18 +95,7 @@ int bootstd_test_check_mmc_hunter(struct unit_test_state *uts)
return 0;
}
-int do_ut_bootstd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+void bootstd_reset_usb(void)
{
- 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);
+ usb_started = false;
}
diff --git a/test/boot/bootstd_common.h b/test/boot/bootstd_common.h
index 4a126e43ff4..c61698adc02 100644
--- a/test/boot/bootstd_common.h
+++ b/test/boot/bootstd_common.h
@@ -12,8 +12,8 @@
#include <version_string.h>
/* Declare a new bootdev test */
-#define BOOTSTD_TEST(_name, _flags) \
- UNIT_TEST(_name, _flags, bootstd_test)
+#define BOOTSTD_TEST(_name, _flags) UNIT_TEST(_name, _flags, bootstd)
+#define BOOTSTD_TEST_INIT(_name, _flags) UNIT_TEST_INIT(_name, _flags, bootstd)
#define NVDATA_START_BLK ((0x400 + 0x400) / MMC_MAX_BLOCK_LEN)
#define VERSION_START_BLK ((0x400 + 0x800) / MMC_MAX_BLOCK_LEN)
@@ -37,15 +37,6 @@ 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);
-
-/**
* bootstd_test_check_mmc_hunter() - Check that the mmc bootdev hunter was used
*
* @uts: Unit test state to use for ut_assert...() functions
@@ -53,4 +44,12 @@ int bootstd_setup_for_tests(void);
*/
int bootstd_test_check_mmc_hunter(struct unit_test_state *uts);
+/**
+ * bootstd_reset_usb() - Reset the USB subsystem
+ *
+ * Resets USB so that it can be started (and scanning) again. This is useful in
+ * tests which need to use USB.
+ */
+void bootstd_reset_usb(void);
+
#endif
diff --git a/test/boot/cedit.c b/test/boot/cedit.c
index aa417190486..4d1b99bc2ea 100644
--- a/test/boot/cedit.c
+++ b/test/boot/cedit.c
@@ -4,7 +4,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <cedit.h>
#include <env.h>
#include <expo.h>
@@ -26,17 +25,17 @@ static int cedit_base(struct unit_test_state *uts)
ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0));
- console_record_reset_enable();
-
/*
* ^N Move down to second menu
* ^M Open menu
* ^N Move down to second item
* ^M Select item
* \e Quit
+ *
+ * cedit_run() returns -EACCESS so this command returns CMD_RET_FAILURE
*/
console_in_puts("\x0e\x0d\x0e\x0d\e");
- ut_assertok(run_command("cedit run", 0));
+ ut_asserteq(1, run_command("cedit run", 0));
exp = cur_exp;
scn = expo_lookup_scene_id(exp, exp->scene_id);
@@ -53,7 +52,7 @@ static int cedit_base(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(cedit_base, 0);
+BOOTSTD_TEST(cedit_base, UTF_CONSOLE);
/* Check the cedit write_fdt and read_fdt commands */
static int cedit_fdt(struct unit_test_state *uts)
@@ -71,7 +70,6 @@ static int cedit_fdt(struct unit_test_state *uts)
void *fdt;
int i;
- console_record_reset_enable();
ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0));
ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn));
@@ -98,14 +96,16 @@ static int cedit_fdt(struct unit_test_state *uts)
ut_asserteq(ID_CPU_SPEED_2,
ofnode_read_u32_default(node, "cpu-speed", 0));
+ ut_asserteq(3,
+ ofnode_read_u32_default(node, "cpu-speed-value", 0));
ut_asserteq_str("2.5 GHz", ofnode_read_string(node, "cpu-speed-str"));
ut_asserteq_str("my-machine", ofnode_read_string(node, "machine-name"));
- /* There should only be 5 properties */
+ /* There should only be 7 properties */
for (i = 0, ofnode_first_property(node, &prop); ofprop_valid(&prop);
i++, ofnode_next_property(&prop))
;
- ut_asserteq(5, i);
+ ut_asserteq(7, i);
ut_assert_console_end();
@@ -123,7 +123,7 @@ static int cedit_fdt(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(cedit_fdt, 0);
+BOOTSTD_TEST(cedit_fdt, UTF_CONSOLE);
/* Check the cedit write_env and read_env commands */
static int cedit_env(struct unit_test_state *uts)
@@ -135,7 +135,6 @@ static int cedit_env(struct unit_test_state *uts)
struct scene *scn;
char *str;
- console_record_reset_enable();
ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0));
ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn));
@@ -152,14 +151,16 @@ static int cedit_env(struct unit_test_state *uts)
strcpy(str, "my-machine");
ut_assertok(run_command("cedit write_env -v", 0));
- ut_assert_nextlinen("c.cpu-speed=7");
+ ut_assert_nextlinen("c.cpu-speed=11");
ut_assert_nextlinen("c.cpu-speed-str=2.5 GHz");
- ut_assert_nextlinen("c.power-loss=10");
+ ut_assert_nextlinen("c.cpu-speed-value=3");
+ ut_assert_nextlinen("c.power-loss=14");
ut_assert_nextlinen("c.power-loss-str=Always Off");
+ ut_assert_nextlinen("c.power-loss-value=0");
ut_assert_nextlinen("c.machine-name=my-machine");
ut_assert_console_end();
- ut_asserteq(7, env_get_ulong("c.cpu-speed", 10, 0));
+ ut_asserteq(11, env_get_ulong("c.cpu-speed", 10, 0));
ut_asserteq_str("2.5 GHz", env_get("c.cpu-speed-str"));
ut_asserteq_str("my-machine", env_get("c.machine-name"));
@@ -168,8 +169,8 @@ static int cedit_env(struct unit_test_state *uts)
*str = '\0';
ut_assertok(run_command("cedit read_env -v", 0));
- ut_assert_nextlinen("c.cpu-speed=7");
- ut_assert_nextlinen("c.power-loss=10");
+ ut_assert_nextlinen("c.cpu-speed=11");
+ ut_assert_nextlinen("c.power-loss=14");
ut_assert_nextlinen("c.machine-name=my-machine");
ut_assert_console_end();
@@ -178,7 +179,7 @@ static int cedit_env(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(cedit_env, 0);
+BOOTSTD_TEST(cedit_env, UTF_CONSOLE);
/* Check the cedit write_cmos and read_cmos commands */
static int cedit_cmos(struct unit_test_state *uts)
@@ -188,7 +189,6 @@ static int cedit_cmos(struct unit_test_state *uts)
extern struct expo *cur_exp;
struct scene *scn;
- console_record_reset_enable();
ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0));
ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn));
@@ -219,4 +219,4 @@ static int cedit_cmos(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(cedit_cmos, 0);
+BOOTSTD_TEST(cedit_cmos, UTF_CONSOLE);
diff --git a/test/boot/expo.c b/test/boot/expo.c
index 714fdfa415d..1d283a2ac95 100644
--- a/test/boot/expo.c
+++ b/test/boot/expo.c
@@ -4,14 +4,12 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <command.h>
#include <dm.h>
#include <expo.h>
#include <menu.h>
#include <video.h>
#include <linux/input.h>
-#include <test/suites.h>
#include <test/ut.h>
#include "bootstd_common.h"
#include <test/cedit-test.h>
@@ -92,7 +90,7 @@ static int expo_base(struct unit_test_state *uts)
*name = '\0';
ut_assertnonnull(exp);
ut_asserteq(0, exp->scene_id);
- ut_asserteq(0, exp->next_id);
+ ut_asserteq(EXPOID_BASE_ID, exp->next_id);
/* Make sure the name was allocated */
ut_assertnonnull(exp->name);
@@ -115,7 +113,7 @@ static int expo_base(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(expo_base, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(expo_base, UTF_DM | UTF_SCAN_FDT);
/* Check creating a scene */
static int expo_scene(struct unit_test_state *uts)
@@ -131,7 +129,7 @@ static int expo_scene(struct unit_test_state *uts)
ut_assertok(expo_new(EXPO_NAME, NULL, &exp));
scn = NULL;
- ut_asserteq(0, exp->next_id);
+ ut_asserteq(EXPOID_BASE_ID, exp->next_id);
strcpy(name, SCENE_NAME1);
id = scene_new(exp, name, SCENE1, &scn);
*name = '\0';
@@ -152,7 +150,7 @@ static int expo_scene(struct unit_test_state *uts)
scn = NULL;
id = scene_new(exp, SCENE_NAME2, 0, &scn);
ut_assertnonnull(scn);
- ut_assertok(scene_title_set(scn, title_id));
+ scn->title_id = title_id;
ut_asserteq(STR_SCENE_TITLE + 1, id);
ut_asserteq(STR_SCENE_TITLE + 2, exp->next_id);
ut_asserteq_ptr(exp, scn->expo);
@@ -166,7 +164,26 @@ static int expo_scene(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(expo_scene, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(expo_scene, UTF_DM | UTF_SCAN_FDT);
+
+/* Check creating a scene with no ID */
+static int expo_scene_no_id(struct unit_test_state *uts)
+{
+ struct scene *scn;
+ struct expo *exp;
+ char name[100];
+ int id;
+
+ ut_assertok(expo_new(EXPO_NAME, NULL, &exp));
+ ut_asserteq(EXPOID_BASE_ID, exp->next_id);
+
+ strcpy(name, SCENE_NAME1);
+ id = scene_new(exp, SCENE_NAME1, 0, &scn);
+ ut_asserteq(EXPOID_BASE_ID, scn->id);
+
+ return 0;
+}
+BOOTSTD_TEST(expo_scene_no_id, UTF_DM | UTF_SCAN_FDT);
/* Check creating a scene with objects */
static int expo_object(struct unit_test_state *uts)
@@ -226,7 +243,7 @@ static int expo_object(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(expo_object, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(expo_object, UTF_DM | UTF_SCAN_FDT);
/* Check setting object attributes and using themes */
static int expo_object_attr(struct unit_test_state *uts)
@@ -287,7 +304,7 @@ static int expo_object_attr(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(expo_object_attr, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(expo_object_attr, UTF_DM | UTF_SCAN_FDT);
/**
* struct test_iter_priv - private data for expo-iterator test
@@ -433,7 +450,7 @@ static int expo_object_menu(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(expo_object_menu, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(expo_object_menu, UTF_DM | UTF_SCAN_FDT);
/* Check rendering a scene */
static int expo_render_image(struct unit_test_state *uts)
@@ -446,7 +463,6 @@ static int expo_render_image(struct unit_test_state *uts)
struct expo *exp;
int id;
- console_record_reset_enable();
ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
ut_assertok(expo_new(EXPO_NAME, NULL, &exp));
@@ -634,7 +650,7 @@ static int expo_render_image(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(expo_render_image, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(expo_render_image, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
/* Check building an expo from a devicetree description */
static int expo_test_build(struct unit_test_state *uts)
@@ -700,17 +716,16 @@ static int expo_test_build(struct unit_test_state *uts)
ut_asserteq(0, item->desc_id);
ut_asserteq(0, item->preview_id);
ut_asserteq(0, item->flags);
+ ut_asserteq(0, item->value);
txt = scene_obj_find(scn, item->label_id, SCENEOBJT_NONE);
ut_asserteq_str("2 GHz", expo_get_str(exp, txt->str_id));
- count = 0;
- list_for_each_entry(item, &menu->item_head, sibling)
- count++;
+ count = list_count_nodes(&menu->item_head);
ut_asserteq(3, count);
expo_destroy(exp);
return 0;
}
-BOOTSTD_TEST(expo_test_build, UT_TESTF_DM);
+BOOTSTD_TEST(expo_test_build, UTF_DM);
diff --git a/test/boot/files/expo_ids.h b/test/boot/files/expo_ids.h
index a86e0d06f6b..ffb511364b1 100644
--- a/test/boot/files/expo_ids.h
+++ b/test/boot/files/expo_ids.h
@@ -4,8 +4,7 @@
*/
enum {
- ZERO,
- ID_PROMPT,
+ ID_PROMPT = EXPOID_BASE_ID,
ID_SCENE1,
ID_SCENE1_TITLE,
diff --git a/test/boot/files/expo_layout.dts b/test/boot/files/expo_layout.dts
index bed552288f4..9bc1e4950b9 100644
--- a/test/boot/files/expo_layout.dts
+++ b/test/boot/files/expo_layout.dts
@@ -39,8 +39,11 @@
item-id = <ID_CPU_SPEED_1 ID_CPU_SPEED_2
ID_CPU_SPEED_3>;
+ /* values for the menu items */
+ item-value = <0 3 6>;
+
start-bit = <0x400>;
- bit-length = <2>;
+ bit-length = <3>;
};
power-loss {
diff --git a/test/boot/image.c b/test/boot/image.c
index 2844b057859..4df7b17ce88 100644
--- a/test/boot/image.c
+++ b/test/boot/image.c
@@ -6,9 +6,7 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <image.h>
-#include <test/suites.h>
#include <test/ut.h>
#include "bootstd_common.h"
diff --git a/test/boot/measurement.c b/test/boot/measurement.c
index 9db2ed324c2..1d38663fc0f 100644
--- a/test/boot/measurement.c
+++ b/test/boot/measurement.c
@@ -6,16 +6,14 @@
* Written by Eddie James <eajames@linux.ibm.com>
*/
-#include <common.h>
#include <bootm.h>
#include <malloc.h>
-#include <test/suites.h>
#include <test/test.h>
#include <test/ut.h>
#include <asm/io.h>
#define MEASUREMENT_TEST(_name, _flags) \
- UNIT_TEST(_name, _flags, measurement_test)
+ UNIT_TEST(_name, _flags, measurement)
static int measure(struct unit_test_state *uts)
{
@@ -54,13 +52,3 @@ static int measure(struct unit_test_state *uts)
return 0;
}
MEASUREMENT_TEST(measure, 0);
-
-int do_ut_measurement(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(measurement_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(measurement_test);
-
- return cmd_ut_category("measurement", "measurement_test_", tests,
- n_ents, argc, argv);
-}
diff --git a/test/boot/upl.c b/test/boot/upl.c
new file mode 100644
index 00000000000..eec89026fc3
--- /dev/null
+++ b/test/boot/upl.c
@@ -0,0 +1,427 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * UPL handoff testing
+ *
+ * Copyright 2024 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <abuf.h>
+#include <mapmem.h>
+#include <upl.h>
+#include <dm/ofnode.h>
+#include <test/test.h>
+#include <test/ut.h>
+#include "bootstd_common.h"
+
+/* Declare a new upl test */
+#define UPL_TEST(_name, _flags) UNIT_TEST(_name, _flags, upl)
+
+static int add_region(struct unit_test_state *uts, struct alist *lst,
+ ulong base, ulong size)
+{
+ struct memregion region;
+
+ region.base = base;
+ region.size = size;
+ ut_assertnonnull(alist_add(lst, region));
+
+ return 0;
+}
+
+int upl_get_test_data(struct unit_test_state *uts, struct upl *upl)
+{
+ struct upl_memmap memmap;
+ struct upl_memres memres;
+ struct upl_image img;
+ struct upl_mem mem;
+
+ upl_init(upl);
+
+ upl->addr_cells = 1;
+ upl->size_cells = 1;
+ upl->smbios = 0x123;
+ upl->acpi = 0x456;
+ upl->bootmode = BIT(UPLBM_DEFAULT) | BIT(UPLBM_S3);
+ upl->fit = 0x789;
+ upl->conf_offset = 0x234;
+ upl->addr_width = 46;
+ upl->acpi_nvs_size = 0x100;
+
+ /* image[0] */
+ img.load = 0x1;
+ img.size = 0x2;
+ img.offset = 0x3;
+ img.description = "U-Boot";
+ ut_assertnonnull(alist_add(&upl->image, img));
+
+ /* image[1] */
+ img.load = 0x4;
+ img.size = 0x5;
+ img.offset = 0x6;
+ img.description = "ATF";
+ ut_assertnonnull(alist_add(&upl->image, img));
+
+ /* mem[0] : 3 regions */
+ memset(&mem, '\0', sizeof(mem));
+ alist_init_struct(&mem.region, struct memregion);
+ ut_assertok(add_region(uts, &mem.region, 0x10, 0x20));
+ ut_assertok(add_region(uts, &mem.region, 0x30, 0x40));
+ ut_assertok(add_region(uts, &mem.region, 0x40, 0x50));
+ ut_assertnonnull(alist_add(&upl->mem, mem));
+
+ /* mem[0] : 1 region */
+ alist_init_struct(&mem.region, struct memregion);
+ ut_assertok(add_region(uts, &mem.region, 0x70, 0x80));
+ mem.hotpluggable = true;
+ ut_assertnonnull(alist_add(&upl->mem, mem));
+ mem.hotpluggable = false;
+
+ /* memmap[0] : 5 regions */
+ alist_init_struct(&memmap.region, struct memregion);
+ memmap.name = "acpi";
+ memmap.usage = BIT(UPLUS_ACPI_RECLAIM);
+ ut_assertok(add_region(uts, &memmap.region, 0x11, 0x12));
+ ut_assertok(add_region(uts, &memmap.region, 0x13, 0x14));
+ ut_assertok(add_region(uts, &memmap.region, 0x15, 0x16));
+ ut_assertok(add_region(uts, &memmap.region, 0x17, 0x18));
+ ut_assertok(add_region(uts, &memmap.region, 0x19, 0x1a));
+ ut_assertnonnull(alist_add(&upl->memmap, memmap));
+
+ /* memmap[1] : 1 region */
+ memmap.name = "u-boot";
+ memmap.usage = BIT(UPLUS_BOOT_DATA);
+ alist_init_struct(&memmap.region, struct memregion);
+ ut_assertok(add_region(uts, &memmap.region, 0x21, 0x22));
+ ut_assertnonnull(alist_add(&upl->memmap, memmap));
+
+ /* memmap[2] : 1 region */
+ alist_init_struct(&memmap.region, struct memregion);
+ memmap.name = "efi";
+ memmap.usage = BIT(UPLUS_RUNTIME_CODE);
+ ut_assertok(add_region(uts, &memmap.region, 0x23, 0x24));
+ ut_assertnonnull(alist_add(&upl->memmap, memmap));
+
+ /* memmap[3]: 2 regions */
+ alist_init_struct(&memmap.region, struct memregion);
+ memmap.name = "empty";
+ memmap.usage = 0;
+ ut_assertok(add_region(uts, &memmap.region, 0x25, 0x26));
+ ut_assertok(add_region(uts, &memmap.region, 0x27, 0x28));
+ ut_assertnonnull(alist_add(&upl->memmap, memmap));
+
+ /* memmap[4]: 1 region */
+ alist_init_struct(&memmap.region, struct memregion);
+ memmap.name = "acpi-things";
+ memmap.usage = BIT(UPLUS_RUNTIME_CODE) | BIT(UPLUS_ACPI_NVS);
+ ut_assertok(add_region(uts, &memmap.region, 0x29, 0x2a));
+ ut_assertnonnull(alist_add(&upl->memmap, memmap));
+
+ /* memres[0]: 1 region */
+ alist_init_struct(&memres.region, struct memregion);
+ memset(&memres, '\0', sizeof(memres));
+ memres.name = "mmio";
+ ut_assertok(add_region(uts, &memres.region, 0x2b, 0x2c));
+ ut_assertnonnull(alist_add(&upl->memres, memres));
+
+ /* memres[1]: 2 regions */
+ alist_init_struct(&memres.region, struct memregion);
+ memres.name = "memory";
+ ut_assertok(add_region(uts, &memres.region, 0x2d, 0x2e));
+ ut_assertok(add_region(uts, &memres.region, 0x2f, 0x30));
+ memres.no_map = true;
+ ut_assertnonnull(alist_add(&upl->memres, memres));
+
+ upl->serial.compatible = "ns16550a";
+ upl->serial.clock_frequency = 1843200;
+ upl->serial.current_speed = 115200;
+ alist_init_struct(&upl->serial.reg, struct memregion);
+ ut_assertok(add_region(uts, &upl->serial.reg, 0xf1de0000, 0x100));
+ upl->serial.reg_io_shift = 2;
+ upl->serial.reg_offset = 0x40;
+ upl->serial.reg_io_width = 1;
+ upl->serial.virtual_reg = 0x20000000;
+ upl->serial.access_type = UPLSAT_MMIO;
+
+ alist_init_struct(&upl->graphics.reg, struct memregion);
+ ut_assertok(add_region(uts, &upl->graphics.reg, 0xd0000000, 0x10000000));
+ upl->graphics.width = 1280;
+ upl->graphics.height = 1280;
+ upl->graphics.stride = upl->graphics.width * 4;
+ upl->graphics.format = UPLGF_ARGB32;
+
+ return 0;
+}
+
+static int compare_upl_image(struct unit_test_state *uts,
+ const struct upl_image *base,
+ const struct upl_image *cmp)
+{
+ ut_asserteq(base->load, cmp->load);
+ ut_asserteq(base->size, cmp->size);
+ ut_asserteq(base->offset, cmp->offset);
+ ut_asserteq_str(base->description, cmp->description);
+
+ return 0;
+}
+
+static int compare_upl_memregion(struct unit_test_state *uts,
+ const struct memregion *base,
+ const struct memregion *cmp)
+{
+ ut_asserteq(base->base, cmp->base);
+ ut_asserteq(base->size, cmp->size);
+
+ return 0;
+}
+
+static int compare_upl_mem(struct unit_test_state *uts,
+ const struct upl_mem *base,
+ const struct upl_mem *cmp)
+{
+ int i;
+
+ ut_asserteq(base->region.count, cmp->region.count);
+ ut_asserteq(base->hotpluggable, cmp->hotpluggable);
+ for (i = 0; i < base->region.count; i++) {
+ ut_assertok(compare_upl_memregion(uts,
+ alist_get(&base->region, i, struct memregion),
+ alist_get(&cmp->region, i, struct memregion)));
+ }
+
+ return 0;
+}
+
+static int check_device_name(struct unit_test_state *uts, const char *base,
+ const char *cmp)
+{
+ const char *p;
+
+ p = strchr(cmp, '@');
+ if (p) {
+ ut_assertnonnull(p);
+ ut_asserteq_strn(base, cmp);
+ ut_asserteq(p - cmp, strlen(base));
+ } else {
+ ut_asserteq_str(base, cmp);
+ }
+
+ return 0;
+}
+
+static int compare_upl_memmap(struct unit_test_state *uts,
+ const struct upl_memmap *base,
+ const struct upl_memmap *cmp)
+{
+ int i;
+
+ ut_assertok(check_device_name(uts, base->name, cmp->name));
+ ut_asserteq(base->region.count, cmp->region.count);
+ ut_asserteq(base->usage, cmp->usage);
+ for (i = 0; i < base->region.count; i++)
+ ut_assertok(compare_upl_memregion(uts,
+ alist_get(&base->region, i, struct memregion),
+ alist_get(&cmp->region, i, struct memregion)));
+
+ return 0;
+}
+
+static int compare_upl_memres(struct unit_test_state *uts,
+ const struct upl_memres *base,
+ const struct upl_memres *cmp)
+{
+ int i;
+
+ ut_assertok(check_device_name(uts, base->name, cmp->name));
+ ut_asserteq(base->region.count, cmp->region.count);
+ ut_asserteq(base->no_map, cmp->no_map);
+ for (i = 0; i < base->region.count; i++)
+ ut_assertok(compare_upl_memregion(uts,
+ alist_get(&base->region, i, struct memregion),
+ alist_get(&cmp->region, i, struct memregion)));
+
+ return 0;
+}
+
+static int compare_upl_serial(struct unit_test_state *uts,
+ struct upl_serial *base, struct upl_serial *cmp)
+{
+ int i;
+
+ ut_asserteq_str(base->compatible, cmp->compatible);
+ ut_asserteq(base->clock_frequency, cmp->clock_frequency);
+ ut_asserteq(base->current_speed, cmp->current_speed);
+ for (i = 0; i < base->reg.count; i++)
+ ut_assertok(compare_upl_memregion(uts,
+ alist_get(&base->reg, i, struct memregion),
+ alist_get(&cmp->reg, i, struct memregion)));
+ ut_asserteq(base->reg_io_shift, cmp->reg_io_shift);
+ ut_asserteq(base->reg_offset, cmp->reg_offset);
+ ut_asserteq(base->reg_io_width, cmp->reg_io_width);
+ ut_asserteq(base->virtual_reg, cmp->virtual_reg);
+ ut_asserteq(base->access_type, cmp->access_type);
+
+ return 0;
+}
+
+static int compare_upl_graphics(struct unit_test_state *uts,
+ struct upl_graphics *base,
+ struct upl_graphics *cmp)
+{
+ int i;
+
+ for (i = 0; i < base->reg.count; i++)
+ ut_assertok(compare_upl_memregion(uts,
+ alist_get(&base->reg, i, struct memregion),
+ alist_get(&cmp->reg, i, struct memregion)));
+ ut_asserteq(base->width, cmp->width);
+ ut_asserteq(base->height, cmp->height);
+ ut_asserteq(base->stride, cmp->stride);
+ ut_asserteq(base->format, cmp->format);
+
+ return 0;
+}
+
+static int compare_upl(struct unit_test_state *uts, struct upl *base,
+ struct upl *cmp)
+{
+ int i;
+
+ ut_asserteq(base->addr_cells, cmp->addr_cells);
+ ut_asserteq(base->size_cells, cmp->size_cells);
+
+ ut_asserteq(base->smbios, cmp->smbios);
+ ut_asserteq(base->acpi, cmp->acpi);
+ ut_asserteq(base->bootmode, cmp->bootmode);
+ ut_asserteq(base->fit, cmp->fit);
+ ut_asserteq(base->conf_offset, cmp->conf_offset);
+ ut_asserteq(base->addr_width, cmp->addr_width);
+ ut_asserteq(base->acpi_nvs_size, cmp->acpi_nvs_size);
+
+ ut_asserteq(base->image.count, cmp->image.count);
+ for (i = 0; i < base->image.count; i++)
+ ut_assertok(compare_upl_image(uts,
+ alist_get(&base->image, i, struct upl_image),
+ alist_get(&cmp->image, i, struct upl_image)));
+
+ ut_asserteq(base->mem.count, cmp->mem.count);
+ for (i = 0; i < base->mem.count; i++)
+ ut_assertok(compare_upl_mem(uts,
+ alist_get(&base->mem, i, struct upl_mem),
+ alist_get(&cmp->mem, i, struct upl_mem)));
+
+ ut_asserteq(base->memmap.count, cmp->memmap.count);
+ for (i = 0; i < base->memmap.count; i++)
+ ut_assertok(compare_upl_memmap(uts,
+ alist_get(&base->memmap, i, struct upl_memmap),
+ alist_get(&cmp->memmap, i, struct upl_memmap)));
+
+ ut_asserteq(base->memres.count, cmp->memres.count);
+ for (i = 0; i < base->memres.count; i++)
+ ut_assertok(compare_upl_memres(uts,
+ alist_get(&base->memres, i, struct upl_memres),
+ alist_get(&cmp->memres, i, struct upl_memres)));
+
+ ut_assertok(compare_upl_serial(uts, &base->serial, &cmp->serial));
+ ut_assertok(compare_upl_graphics(uts, &base->graphics, &cmp->graphics));
+
+ return 0;
+}
+
+/* Basic test of writing and reading UPL handoff */
+static int upl_test_base(struct unit_test_state *uts)
+{
+ oftree tree, check_tree;
+ struct upl upl, check;
+ struct abuf buf;
+
+ if (!CONFIG_IS_ENABLED(OFNODE_MULTI_TREE))
+ return -EAGAIN; /* skip test */
+ ut_assertok(upl_get_test_data(uts, &upl));
+
+ ut_assertok(upl_create_handoff_tree(&upl, &tree));
+ ut_assertok(oftree_to_fdt(tree, &buf));
+
+ /*
+ * strings in check_tree and therefore check are only valid so long as
+ * buf stays around. As soon as we call abuf_uninit they go away
+ */
+ check_tree = oftree_from_fdt(abuf_data(&buf));
+ ut_assert(ofnode_valid(oftree_path(check_tree, "/")));
+
+ ut_assertok(upl_read_handoff(&check, check_tree));
+ ut_assertok(compare_upl(uts, &upl, &check));
+ abuf_uninit(&buf);
+
+ return 0;
+}
+UPL_TEST(upl_test_base, 0);
+
+/* Test 'upl info' command */
+static int upl_test_info(struct unit_test_state *uts)
+{
+ gd_set_upl(NULL);
+ ut_assertok(run_command("upl info", 0));
+ ut_assert_nextline("UPL state: inactive");
+ ut_assert_console_end();
+
+ gd_set_upl((struct upl *)uts); /* set it to any non-zero value */
+ ut_assertok(run_command("upl info", 0));
+ ut_assert_nextline("UPL state: active");
+ ut_assert_console_end();
+ gd_set_upl(NULL);
+
+ return 0;
+}
+UPL_TEST(upl_test_info, UTF_CONSOLE);
+
+/* Test 'upl read' and 'upl_write' commands */
+static int upl_test_read_write(struct unit_test_state *uts)
+{
+ ulong addr;
+
+ if (!CONFIG_IS_ENABLED(OFNODE_MULTI_TREE))
+ return -EAGAIN; /* skip test */
+ ut_assertok(run_command("upl write", 0));
+
+ addr = env_get_hex("upladdr", 0);
+ ut_assert_nextline("UPL handoff written to %lx size %lx", addr,
+ env_get_hex("uplsize", 0));
+ ut_assert_console_end();
+
+ ut_assertok(run_command("upl read ${upladdr}", 0));
+ ut_assert_nextline("Reading UPL at %lx", addr);
+ ut_assert_console_end();
+
+ return 0;
+}
+UPL_TEST(upl_test_read_write, UTF_CONSOLE);
+
+/* Test UPL passthrough */
+static int upl_test_info_norun(struct unit_test_state *uts)
+{
+ const struct upl_image *img;
+ struct upl *upl = gd_upl();
+ const void *fit;
+
+ ut_assertok(run_command("upl info -v", 0));
+ ut_assert_nextline("UPL state: active");
+ ut_assert_nextline("fit %lx", upl->fit);
+ ut_assert_nextline("conf_offset %x", upl->conf_offset);
+ ut_assert_nextlinen("image 0");
+ ut_assert_nextlinen("image 1");
+ ut_assert_console_end();
+
+ /* check the offsets */
+ fit = map_sysmem(upl->fit, 0);
+ ut_asserteq_str("conf-1", fdt_get_name(fit, upl->conf_offset, NULL));
+
+ ut_asserteq(2, upl->image.count);
+
+ img = alist_get(&upl->image, 1, struct upl_image);
+ ut_asserteq_str("firmware-1", fdt_get_name(fit, img->offset, NULL));
+ ut_asserteq(CONFIG_TEXT_BASE, img->load);
+
+ return 0;
+}
+UPL_TEST(upl_test_info_norun, UTF_CONSOLE | UTF_MANUAL);
diff --git a/test/boot/vbe_fixup.c b/test/boot/vbe_fixup.c
index eba5c4ebe6c..5bc026dbb59 100644
--- a/test/boot/vbe_fixup.c
+++ b/test/boot/vbe_fixup.c
@@ -6,7 +6,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <dm/ofnode.h>
#include <linux/libfdt.h>
#include <test/test.h>
@@ -52,5 +51,5 @@ static int vbe_test_fixup_norun(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(vbe_test_fixup_norun, UT_TESTF_DM | UT_TESTF_SCAN_FDT |
- UT_TESTF_FLAT_TREE | UT_TESTF_MANUAL);
+BOOTSTD_TEST(vbe_test_fixup_norun, UTF_DM | UTF_SCAN_FDT | UTF_FLAT_TREE |
+ UTF_MANUAL);
diff --git a/test/boot/vbe_simple.c b/test/boot/vbe_simple.c
index 5e61840652c..c37de627c52 100644
--- a/test/boot/vbe_simple.c
+++ b/test/boot/vbe_simple.c
@@ -6,13 +6,11 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <bootmeth.h>
#include <dm.h>
#include <image.h>
#include <of_live.h>
#include <vbe.h>
-#include <test/suites.h>
#include <test/ut.h>
#include "bootstd_common.h"
@@ -34,9 +32,6 @@ static int vbe_simple_test_base(struct unit_test_state *uts)
ofnode node;
u32 vernum;
- /* Set up the VBE info */
- ut_assertok(bootstd_setup_for_tests());
-
/* Read the version back */
ut_assertok(vbe_find_by_any("firmware0", &dev));
ut_assertok(bootmeth_get_state_desc(dev, info, sizeof(info)));
@@ -86,4 +81,4 @@ static int vbe_simple_test_base(struct unit_test_state *uts)
return 0;
}
-BOOTSTD_TEST(vbe_simple_test_base, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+BOOTSTD_TEST(vbe_simple_test_base, UTF_DM | UTF_SCAN_FDT);
diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index 478ef4c6f05..595e4cfcada 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -3,34 +3,40 @@
# Copyright (c) 2013 Google, Inc
# Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
-obj-y += cmd_ut_cmd.o
-
+obj-$(CONFIG_$(PHASE_)CMDLINE) += command.o
ifdef CONFIG_HUSH_PARSER
obj-$(CONFIG_CONSOLE_RECORD) += test_echo.o
endif
ifdef CONFIG_CONSOLE_RECORD
obj-$(CONFIG_CMD_PAUSE) += test_pause.o
endif
-obj-y += exit.o mem.o
+obj-y += exit.o
+obj-$(CONFIG_X86) += cpuid.o msr.o
obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
obj-$(CONFIG_CMD_BDI) += bdinfo.o
+obj-$(CONFIG_COREBOOT_SYSINFO) += coreboot.o
obj-$(CONFIG_CMD_FDT) += fdt.o
obj-$(CONFIG_CONSOLE_TRUETYPE) += font.o
+obj-$(CONFIG_CMD_HASH) += hash.o
obj-$(CONFIG_CMD_HISTORY) += history.o
obj-$(CONFIG_CMD_LOADM) += loadm.o
-obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o
+obj-$(CONFIG_CMD_MEMINFO) += meminfo.o
obj-$(CONFIG_CMD_MEMORY) += mem_copy.o
+obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o
ifdef CONFIG_CMD_PCI
obj-$(CONFIG_CMD_PCI_MPS) += pci_mps.o
endif
-obj-$(CONFIG_CMD_PINMUX) += pinmux.o
-obj-$(CONFIG_CMD_PWM) += pwm.o
obj-$(CONFIG_CMD_SEAMA) += seama.o
ifdef CONFIG_SANDBOX
obj-$(CONFIG_CMD_MBR) += mbr.o
+obj-$(CONFIG_CMD_PINMUX) += pinmux.o
+obj-$(CONFIG_CMD_PWM) += pwm.o
obj-$(CONFIG_CMD_READ) += rw.o
obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
-obj-$(CONFIG_ARM_FFA_TRANSPORT) += armffa.o
-endif
obj-$(CONFIG_CMD_TEMPERATURE) += temperature.o
+ifdef CONFIG_NET
obj-$(CONFIG_CMD_WGET) += wget.o
+endif
+obj-$(CONFIG_ARM_FFA_TRANSPORT) += armffa.o
+endif
+obj-$(CONFIG_CMD_SPAWN) += spawn.o
diff --git a/test/cmd/addrmap.c b/test/cmd/addrmap.c
index 1eb5955db17..72798b96edd 100644
--- a/test/cmd/addrmap.c
+++ b/test/cmd/addrmap.c
@@ -5,18 +5,15 @@
* Copyright (C) 2021, Bin Meng <bmeng.cn@gmail.com>
*/
-#include <common.h>
#include <console.h>
-#include <test/suites.h>
#include <test/ut.h>
/* Declare a new addrmap test */
-#define ADDRMAP_TEST(_name, _flags) UNIT_TEST(_name, _flags, addrmap_test)
+#define ADDRMAP_TEST(_name, _flags) UNIT_TEST(_name, _flags, addrmap)
/* Test 'addrmap' command output */
static int addrmap_test_basic(struct unit_test_state *uts)
{
- ut_assertok(console_record_reset_enable());
ut_assertok(run_command("addrmap", 0));
ut_assert_nextline(" vaddr paddr size");
ut_assert_nextline("================ ================ ================");
@@ -25,13 +22,4 @@ static int addrmap_test_basic(struct unit_test_state *uts)
return 0;
}
-ADDRMAP_TEST(addrmap_test_basic, UT_TESTF_CONSOLE_REC);
-
-int do_ut_addrmap(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(addrmap_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(addrmap_test);
-
- return cmd_ut_category("cmd_addrmap", "cmd_addrmap_", tests, n_ents,
- argc, argv);
-}
+ADDRMAP_TEST(addrmap_test_basic, UTF_CONSOLE);
diff --git a/test/cmd/armffa.c b/test/cmd/armffa.c
index 9a44a397e8a..fd578f3087f 100644
--- a/test/cmd/armffa.c
+++ b/test/cmd/armffa.c
@@ -8,7 +8,6 @@
* Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
*/
-#include <common.h>
#include <string.h>
#include <asm/sandbox_arm_ffa.h>
#include <dm/test.h>
@@ -29,5 +28,4 @@ static int dm_test_armffa_cmd(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_armffa_cmd, UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
+DM_TEST(dm_test_armffa_cmd, UTF_SCAN_FDT | UTF_CONSOLE);
diff --git a/test/cmd/bdinfo.c b/test/cmd/bdinfo.c
index 4977d01f62d..09f44ee41ed 100644
--- a/test/cmd/bdinfo.c
+++ b/test/cmd/bdinfo.c
@@ -5,12 +5,11 @@
* Copyright 2023 Marek Vasut <marek.vasut+renesas@mailbox.org>
*/
-#include <common.h>
+#include <alist.h>
#include <console.h>
#include <mapmem.h>
#include <asm/global_data.h>
#include <dm/uclass.h>
-#include <test/suites.h>
#include <test/ut.h>
#include <dm.h>
#include <env.h>
@@ -26,7 +25,7 @@
DECLARE_GLOBAL_DATA_PTR;
/* Declare a new bdinfo test */
-#define BDINFO_TEST(_name, _flags) UNIT_TEST(_name, _flags, bdinfo_test)
+#define BDINFO_TEST(_name, _flags) UNIT_TEST(_name, _flags, bdinfo)
static int test_num_l(struct unit_test_state *uts, const char *name,
ulong value)
@@ -100,44 +99,39 @@ static int test_video_info(struct unit_test_state *uts)
}
static int lmb_test_dump_region(struct unit_test_state *uts,
- struct lmb_region *rgn, char *name)
+ struct alist *lmb_rgn_lst, char *name)
{
+ struct lmb_region *rgn = lmb_rgn_lst->data;
unsigned long long base, size, end;
- enum lmb_flags flags;
+ u32 flags;
int i;
- ut_assert_nextline(" %s.cnt = 0x%lx / max = 0x%lx", name, rgn->cnt, rgn->max);
+ ut_assert_nextline(" %s.count = %#x", name, lmb_rgn_lst->count);
- for (i = 0; i < rgn->cnt; i++) {
- base = rgn->region[i].base;
- size = rgn->region[i].size;
+ for (i = 0; i < lmb_rgn_lst->count; i++) {
+ base = rgn[i].base;
+ size = rgn[i].size;
end = base + size - 1;
- flags = rgn->region[i].flags;
-
- /*
- * this entry includes the stack (get_sp()) on many platforms
- * so will different each time lmb_init_and_reserve() is called.
- * We could instead have the bdinfo command put its lmb region
- * in a known location, so we can check it directly, rather than
- * calling lmb_init_and_reserve() to create a new (and hopefully
- * identical one). But for now this seems good enough.
- */
+ flags = rgn[i].flags;
+
if (!IS_ENABLED(CONFIG_SANDBOX) && i == 3) {
ut_assert_nextlinen(" %s[%d]\t[", name, i);
continue;
}
- ut_assert_nextline(" %s[%d]\t[0x%llx-0x%llx], 0x%08llx bytes flags: %x",
- name, i, base, end, size, flags);
+ ut_assert_nextlinen(" %s[%d]\t[%#llx-%#llx], %#llx bytes, flags: ",
+ name, i, base, end, size);
}
return 0;
}
-static int lmb_test_dump_all(struct unit_test_state *uts, struct lmb *lmb)
+static int lmb_test_dump_all(struct unit_test_state *uts)
{
+ struct lmb *lmb = lmb_get();
+
ut_assert_nextline("lmb_dump_all:");
- ut_assertok(lmb_test_dump_region(uts, &lmb->memory, "memory"));
- ut_assertok(lmb_test_dump_region(uts, &lmb->reserved, "reserved"));
+ ut_assertok(lmb_test_dump_region(uts, &lmb->available_mem, "memory"));
+ ut_assertok(lmb_test_dump_region(uts, &lmb->used_mem, "reserved"));
return 0;
}
@@ -186,9 +180,6 @@ static int bdinfo_test_all(struct unit_test_state *uts)
ut_assert(map_to_sysmem(gd->fdt_blob) == env_get_hex("fdtcontroladdr", 0x1234));
ut_assertok(test_num_l(uts, "fdt_blob",
(ulong)map_to_sysmem(gd->fdt_blob)));
- ut_assertok(test_num_l(uts, "new_fdt",
- (ulong)map_to_sysmem(gd->new_fdt)));
- ut_assertok(test_num_l(uts, "fdt_size", (ulong)gd->fdt_size));
if (IS_ENABLED(CONFIG_VIDEO))
ut_assertok(test_video_info(uts));
@@ -199,10 +190,7 @@ static int bdinfo_test_all(struct unit_test_state *uts)
#endif
if (IS_ENABLED(CONFIG_LMB) && gd->fdt_blob) {
- struct lmb lmb;
-
- lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
- ut_assertok(lmb_test_dump_all(uts, &lmb));
+ ut_assertok(lmb_test_dump_all(uts));
if (IS_ENABLED(CONFIG_OF_REAL))
ut_assert_nextline("devicetree = %s", fdtdec_get_srcname());
}
@@ -236,22 +224,19 @@ static int bdinfo_test_all(struct unit_test_state *uts)
static int bdinfo_test_full(struct unit_test_state *uts)
{
/* Test BDINFO full print */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("bdinfo"));
ut_assertok(bdinfo_test_all(uts));
ut_assertok(run_commandf("bdinfo -a"));
ut_assertok(bdinfo_test_all(uts));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
-
-BDINFO_TEST(bdinfo_test_full, UT_TESTF_CONSOLE_REC);
+BDINFO_TEST(bdinfo_test_full, UTF_CONSOLE);
static int bdinfo_test_help(struct unit_test_state *uts)
{
/* Test BDINFO unknown option help text print */
- ut_assertok(console_record_reset_enable());
if (!CONFIG_IS_ENABLED(GETOPT)) {
ut_asserteq(0, run_commandf("bdinfo -h"));
ut_assertok(bdinfo_test_all(uts));
@@ -263,49 +248,36 @@ static int bdinfo_test_help(struct unit_test_state *uts)
ut_assert_nextlinen("Usage:");
ut_assert_nextlinen("bdinfo");
}
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
-
-BDINFO_TEST(bdinfo_test_help, UT_TESTF_CONSOLE_REC);
+BDINFO_TEST(bdinfo_test_help, UTF_CONSOLE);
static int bdinfo_test_memory(struct unit_test_state *uts)
{
/* Test BDINFO memory layout only print */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("bdinfo -m"));
if (!CONFIG_IS_ENABLED(GETOPT))
ut_assertok(bdinfo_test_all(uts));
else
ut_assertok(bdinfo_check_mem(uts));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
-
-BDINFO_TEST(bdinfo_test_memory, UT_TESTF_CONSOLE_REC);
+BDINFO_TEST(bdinfo_test_memory, UTF_CONSOLE);
static int bdinfo_test_eth(struct unit_test_state *uts)
{
/* Test BDINFO ethernet settings only print */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("bdinfo -e"));
if (!CONFIG_IS_ENABLED(GETOPT))
ut_assertok(bdinfo_test_all(uts));
else if (IS_ENABLED(CONFIG_CMD_NET))
ut_assertok(test_eth(uts));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
-
-BDINFO_TEST(bdinfo_test_eth, UT_TESTF_CONSOLE_REC);
-
-int do_ut_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(bdinfo_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(bdinfo_test);
-
- return cmd_ut_category("bdinfo", "bdinfo_test_", tests, n_ents, argc, argv);
-}
+BDINFO_TEST(bdinfo_test_eth, UTF_CONSOLE);
diff --git a/test/cmd/cmd_ut_cmd.c b/test/cmd/cmd_ut_cmd.c
deleted file mode 100644
index e77fa1c7f01..00000000000
--- a/test/cmd/cmd_ut_cmd.c
+++ /dev/null
@@ -1,20 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * Copyright 2023 Google LLC
- * Written by Simon Glass <sjg@chromium.org>
- *
- * Unit tests for command functions
- */
-
-#include <command.h>
-#include <test/cmd.h>
-#include <test/suites.h>
-#include <test/ut.h>
-
-int do_ut_cmd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(cmd_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(cmd_test);
-
- return cmd_ut_category("cmd", "cmd_test_", tests, n_ents, argc, argv);
-}
diff --git a/test/cmd/command.c b/test/cmd/command.c
new file mode 100644
index 00000000000..5b1e5a77e5d
--- /dev/null
+++ b/test/cmd/command.c
@@ -0,0 +1,109 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2012, The Chromium Authors
+ */
+
+#define DEBUG
+
+#include <command.h>
+#include <env.h>
+#include <log.h>
+#include <string.h>
+#include <linux/errno.h>
+#include <test/cmd.h>
+#include <test/ut.h>
+
+static const char test_cmd[] = "setenv list 1\n setenv list ${list}2; "
+ "setenv list ${list}3\0"
+ "setenv list ${list}4";
+
+static int command_test(struct unit_test_state *uts)
+{
+ char long_str[CONFIG_SYS_CBSIZE + 42];
+
+ printf("%s: Testing commands\n", __func__);
+ run_command("env default -f -a", 0);
+
+ /* commands separated by \n */
+ run_command_list("setenv list 1\n setenv list ${list}1", -1, 0);
+ ut_assert(!strcmp("11", env_get("list")));
+
+ /* command followed by \n and nothing else */
+ run_command_list("setenv list 1${list}\n", -1, 0);
+ ut_assert(!strcmp("111", env_get("list")));
+
+ /* a command string with \0 in it. Stuff after \0 should be ignored */
+ run_command("setenv list", 0);
+ run_command_list(test_cmd, sizeof(test_cmd), 0);
+ ut_assert(!strcmp("123", env_get("list")));
+
+ /*
+ * a command list where we limit execution to only the first command
+ * using the length parameter.
+ */
+ run_command_list("setenv list 1\n setenv list ${list}2; "
+ "setenv list ${list}3", strlen("setenv list 1"), 0);
+ ut_assert(!strcmp("1", env_get("list")));
+
+ ut_assertok(run_command("echo", 0));
+ ut_assertok(run_command_list("echo", -1, 0));
+
+ if (IS_ENABLED(CONFIG_HUSH_PARSER)) {
+ ut_asserteq(1, run_command("false", 0));
+ ut_asserteq(1, run_command_list("false", -1, 0));
+ run_command("setenv foo 'setenv black 1\nsetenv adder 2'", 0);
+ run_command("run foo", 0);
+ ut_assertnonnull(env_get("black"));
+ ut_asserteq(0, strcmp("1", env_get("black")));
+ ut_assertnonnull(env_get("adder"));
+ ut_asserteq(0, strcmp("2", env_get("adder")));
+ ut_assertok(run_command("", 0));
+ ut_assertok(run_command(" ", 0));
+ }
+
+ ut_asserteq(1, run_command("'", 0));
+
+ /* Variadic function test-cases */
+ if (IS_ENABLED(CONFIG_HUSH_PARSER)) {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-zero-length"
+ ut_assertok(run_commandf(""));
+#pragma GCC diagnostic pop
+ ut_assertok(run_commandf(" "));
+ }
+ ut_asserteq(1, run_commandf("'"));
+
+ ut_assertok(run_commandf("env %s %s", "delete -f", "list"));
+ /*
+ * Expected: "## Error: "list" not defined"
+ * (disabled to avoid pytest bailing out)
+ *
+ * ut_asserteq(1, run_commandf("printenv list"));
+ */
+
+ memset(long_str, 'x', sizeof(long_str));
+ ut_asserteq(-ENOSPC, run_commandf("Truncation case: %s", long_str));
+
+ if (IS_ENABLED(CONFIG_HUSH_PARSER)) {
+ ut_assertok(run_commandf("env %s %s %s %s", "delete -f",
+ "adder", "black", "foo"));
+ ut_assertok(run_commandf(
+ "setenv foo 'setenv %s 1\nsetenv %s 2'",
+ "black", "adder"));
+ ut_assertok(run_command("run foo", 0));
+ ut_assertnonnull(env_get("black"));
+ ut_asserteq(0, strcmp("1", env_get("black")));
+ ut_assertnonnull(env_get("adder"));
+ ut_asserteq(0, strcmp("2", env_get("adder")));
+ }
+
+ /* Clean up before exit */
+ ut_assertok(run_command("env default -f -a", 0));
+
+ /* put back the FDT environment */
+ ut_assertok(env_set("from_fdt", "yes"));
+
+ printf("%s: Everything went swimmingly\n", __func__);
+ return 0;
+}
+CMD_TEST(command_test, 0);
diff --git a/test/cmd/coreboot.c b/test/cmd/coreboot.c
new file mode 100644
index 00000000000..a99898d15c4
--- /dev/null
+++ b/test/cmd/coreboot.c
@@ -0,0 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test for coreboot commands
+ *
+ * Copyright 2023 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <cedit.h>
+#include <command.h>
+#include <dm.h>
+#include <expo.h>
+#include <rtc.h>
+#include <test/cedit-test.h>
+#include <test/cmd.h>
+#include <test/test.h>
+#include <test/ut.h>
+#include "../../boot/scene_internal.h"
+
+enum {
+ CSUM_LOC = 0x3f0 / 8,
+};
+
+/**
+ * test_cmd_cbsysinfo() - test the cbsysinfo command produces expected output
+ *
+ * This includes ensuring that the coreboot build has the expected options
+ * enabled
+ */
+static int test_cmd_cbsysinfo(struct unit_test_state *uts)
+{
+ ut_assertok(run_command("cbsysinfo", 0));
+ ut_assert_nextlinen("Coreboot table at");
+
+ /* Make sure CMOS options are enabled */
+ ut_assert_skip_to_line(
+ " 1c0 1 e 1 power_on_after_fail 0:Disable 1:Enable");
+ ut_assert_skip_to_line("CMOS start : 1c0");
+ ut_assert_nextline(" CMOS end : 1cf");
+ ut_assert_nextline(" CMOS csum loc: 3f0");
+
+ /* Make sure the linear frame buffer is enabled */
+ ut_assert_skip_to_linen("Framebuffer");
+ ut_assert_nextlinen(" Phys addr");
+
+ ut_assert_skip_to_line("Chrome OS VPD: 00000000");
+ ut_assert_nextlinen("RSDP");
+ ut_assert_nextlinen("Unimpl.");
+ ut_assert_console_end();
+
+ return 0;
+}
+CMD_TEST(test_cmd_cbsysinfo, UTF_CONSOLE);
+
+/* test cbcmos command */
+static int test_cmd_cbcmos(struct unit_test_state *uts)
+{
+ u16 old_csum, new_csum;
+ struct udevice *dev;
+
+ /* initially the checksum should be correct */
+ ut_assertok(run_command("cbcmos check", 0));
+ ut_assert_console_end();
+
+ /* make a change to the checksum */
+ ut_assertok(uclass_first_device_err(UCLASS_RTC, &dev));
+ ut_assertok(rtc_read16(dev, CSUM_LOC, &old_csum));
+ ut_assertok(rtc_write16(dev, CSUM_LOC, old_csum + 1));
+
+ /* now the command should fail */
+ ut_asserteq(1, run_command("cbcmos check", 0));
+ ut_assert_nextline("Checksum %04x error: calculated %04x",
+ old_csum + 1, old_csum);
+ ut_assert_console_end();
+
+ /* now get it to fix the checksum */
+ ut_assertok(run_command("cbcmos update", 0));
+ ut_assert_nextline("Checksum %04x written", old_csum);
+ ut_assert_console_end();
+
+ /* check the RTC looks right */
+ ut_assertok(rtc_read16(dev, CSUM_LOC, &new_csum));
+ ut_asserteq(old_csum, new_csum);
+ ut_assert_console_end();
+
+ return 0;
+}
+CMD_TEST(test_cmd_cbcmos, UTF_CONSOLE);
+
+/* test 'cedit cb_load' command */
+static int test_cmd_cedit_cb_load(struct unit_test_state *uts)
+{
+ struct scene_obj_menu *menu;
+ struct video_priv *vid_priv;
+ struct scene_obj_txt *txt;
+ struct scene *scn;
+ struct expo *exp;
+ int scn_id;
+
+ ut_assertok(run_command("cedit cb_load", 0));
+ ut_assertok(run_command("cedit read_cmos", 0));
+ ut_assert_console_end();
+
+ exp = cur_exp;
+ scn_id = cedit_prepare(exp, &vid_priv, &scn);
+ ut_assert(scn_id > 0);
+ ut_assertnonnull(scn);
+
+ /* just do a very basic test that the first menu is present */
+ menu = scene_obj_find(scn, scn->highlight_id, SCENEOBJT_NONE);
+ ut_assertnonnull(menu);
+
+ txt = scene_obj_find(scn, menu->title_id, SCENEOBJT_NONE);
+ ut_assertnonnull(txt);
+ ut_asserteq_str("Boot option", expo_get_str(exp, txt->str_id));
+
+ return 0;
+}
+CMD_TEST(test_cmd_cedit_cb_load, UTF_CONSOLE);
diff --git a/test/cmd/cpuid.c b/test/cmd/cpuid.c
new file mode 100644
index 00000000000..e07f5fd4696
--- /dev/null
+++ b/test/cmd/cpuid.c
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for cpuid command
+ *
+ * Copyright 2024 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <test/cmd.h>
+#include <test/ut.h>
+
+static int cmd_test_cpuid(struct unit_test_state *uts)
+{
+ ut_assertok(run_commandf("cpuid 1"));
+ ut_assert_nextline("eax 00060fb1");
+ ut_assert_nextline("ebx 00000800");
+ ut_assert_nextline("ecx 80002001");
+ ut_assert_nextline("edx 078bfbfd");
+
+ return 0;
+}
+CMD_TEST(cmd_test_cpuid, UTF_CONSOLE);
diff --git a/test/cmd/exit.c b/test/cmd/exit.c
index 7e160f7e4bb..fdde054b928 100644
--- a/test/cmd/exit.c
+++ b/test/cmd/exit.c
@@ -5,17 +5,15 @@
* Copyright 2022 Marek Vasut <marex@denx.de>
*/
-#include <common.h>
#include <console.h>
#include <mapmem.h>
#include <asm/global_data.h>
-#include <test/suites.h>
#include <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
/* Declare a new exit test */
-#define EXIT_TEST(_name, _flags) UNIT_TEST(_name, _flags, exit_test)
+#define EXIT_TEST(_name, _flags) UNIT_TEST(_name, _flags, exit)
/* Test 'exit addr' getting/setting address */
static int cmd_exit_test(struct unit_test_state *uts)
@@ -34,102 +32,80 @@ static int cmd_exit_test(struct unit_test_state *uts)
* - return value can be printed outside of 'run' command
*/
for (i = -3; i <= 3; i++) {
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("setenv foo 'echo bar ; exit %d ; echo baz' ; run foo ; echo $?", i));
ut_assert_nextline("bar");
ut_assert_nextline("%d", i > 0 ? i : 0);
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("setenv foo 'echo bar ; exit %d ; echo baz' ; run foo && echo quux ; echo $?", i));
ut_assert_nextline("bar");
if (i <= 0)
ut_assert_nextline("quux");
ut_assert_nextline("%d", i > 0 ? i : 0);
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("setenv foo 'echo bar ; exit %d ; echo baz' ; run foo || echo quux ; echo $?", i));
ut_assert_nextline("bar");
if (i > 0)
ut_assert_nextline("quux");
/* Either 'exit' returns 0, or 'echo quux' returns 0 */
ut_assert_nextline("0");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
}
/* Validate that 'exit' behaves the same way as 'exit 0' */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("setenv foo 'echo bar ; exit ; echo baz' ; run foo ; echo $?"));
ut_assert_nextline("bar");
ut_assert_nextline("0");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("setenv foo 'echo bar ; exit ; echo baz' ; run foo && echo quux ; echo $?"));
ut_assert_nextline("bar");
ut_assert_nextline("quux");
ut_assert_nextline("0");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("setenv foo 'echo bar ; exit ; echo baz' ; run foo || echo quux ; echo $?"));
ut_assert_nextline("bar");
/* Either 'exit' returns 0, or 'echo quux' returns 0 */
ut_assert_nextline("0");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Validate that return value still propagates from 'run' command */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("setenv foo 'echo bar ; true' ; run foo ; echo $?"));
ut_assert_nextline("bar");
ut_assert_nextline("0");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("setenv foo 'echo bar ; true' ; run foo && echo quux ; echo $?"));
ut_assert_nextline("bar");
ut_assert_nextline("quux");
ut_assert_nextline("0");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("setenv foo 'echo bar ; true' ; run foo || echo quux ; echo $?"));
ut_assert_nextline("bar");
/* The 'true' returns 0 */
ut_assert_nextline("0");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("setenv foo 'echo bar ; false' ; run foo ; echo $?"));
ut_assert_nextline("bar");
ut_assert_nextline("1");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("setenv foo 'echo bar ; false' ; run foo && echo quux ; echo $?"));
ut_assert_nextline("bar");
ut_assert_nextline("1");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("setenv foo 'echo bar ; false' ; run foo || echo quux ; echo $?"));
ut_assert_nextline("bar");
ut_assert_nextline("quux");
/* The 'echo quux' returns 0 */
ut_assert_nextline("0");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
-
-EXIT_TEST(cmd_exit_test, UT_TESTF_CONSOLE_REC);
-
-int do_ut_exit(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(exit_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(exit_test);
-
- return cmd_ut_category("cmd_exit", "exit_test_", tests, n_ents,
- argc, argv);
-}
+EXIT_TEST(cmd_exit_test, UTF_CONSOLE);
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 54708552175..c11c181c807 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -5,13 +5,11 @@
* Copyright 2022 Google LLC
*/
-#include <common.h>
#include <console.h>
#include <fdt_support.h>
#include <mapmem.h>
#include <asm/global_data.h>
#include <linux/libfdt.h>
-#include <test/suites.h>
#include <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -24,40 +22,54 @@ DECLARE_GLOBAL_DATA_PTR;
*/
/* Declare a new fdt test */
-#define FDT_TEST(_name, _flags) UNIT_TEST(_name, _flags, fdt_test)
+#define FDT_TEST(_name, _flags) UNIT_TEST(_name, _flags, fdt)
/**
* make_test_fdt() - Create an FDT with just a root node
*
- * The size is set to the minimum needed
+ * The size is set to the minimum needed. This also sets the working FDT and
+ * checks that the expected output is received from doing so.
*
* @uts: Test state
* @fdt: Place to write FDT
* @size: Maximum size of space for fdt
+ * @addrp: Returns address of the devicetree
*/
-static int make_test_fdt(struct unit_test_state *uts, void *fdt, int size)
+static int make_test_fdt(struct unit_test_state *uts, void *fdt, int size,
+ ulong *addrp)
{
+ ulong addr;
+
ut_assertok(fdt_create(fdt, size));
ut_assertok(fdt_finish_reservemap(fdt));
ut_assert(fdt_begin_node(fdt, "") >= 0);
ut_assertok(fdt_end_node(fdt));
ut_assertok(fdt_finish(fdt));
+ addr = map_to_sysmem(fdt);
+ set_working_fdt_addr(addr);
+ ut_assert_nextline("Working FDT set to %lx", addr);
+ *addrp = addr;
+
return 0;
}
/**
* make_fuller_fdt() - Create an FDT with root node and properties
*
- * The size is set to the minimum needed
+ * The size is set to the minimum needed. This also sets the working FDT and
+ * checks that the expected output is received from doing so.
*
* @uts: Test state
* @fdt: Place to write FDT
* @size: Maximum size of space for fdt
+ * @addrp: Returns address of the devicetree
*/
-static int make_fuller_fdt(struct unit_test_state *uts, void *fdt, int size)
+static int make_fuller_fdt(struct unit_test_state *uts, void *fdt, int size,
+ ulong *addrp)
{
fdt32_t regs[2] = { cpu_to_fdt32(0x1234), cpu_to_fdt32(0x1000) };
+ ulong addr;
/*
* Assemble the following DT for test purposes:
@@ -139,6 +151,11 @@ static int make_fuller_fdt(struct unit_test_state *uts, void *fdt, int size)
ut_assertok(fdt_end_node(fdt));
ut_assertok(fdt_finish(fdt));
+ addr = map_to_sysmem(fdt);
+ set_working_fdt_addr(addr);
+ ut_assert_nextline("Working FDT set to %lx", addr);
+ *addrp = addr;
+
return 0;
}
@@ -150,11 +167,10 @@ static int fdt_test_addr(struct unit_test_state *uts)
ulong addr;
int ret;
- ut_assertok(console_record_reset_enable());
ut_assertok(run_command("fdt addr -c", 0));
ut_assert_nextline("Control fdt: %08lx",
(ulong)map_to_sysmem(gd->fdt_blob));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* The working fdt is not set, so this should fail */
set_working_fdt_addr(0);
@@ -167,16 +183,13 @@ static int fdt_test_addr(struct unit_test_state *uts)
*/
if (IS_ENABLED(CONFIG_SANDBOX))
ut_assert_nextline("libfdt fdt_check_header(): FDT_ERR_BADMAGIC");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Set up a working FDT and try again */
- 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(make_test_fdt(uts, fdt, sizeof(fdt), &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));
+ ut_assert_console_end();
/* Set the working FDT */
set_working_fdt_addr(0);
@@ -184,7 +197,7 @@ static int fdt_test_addr(struct unit_test_state *uts)
ut_assertok(run_commandf("fdt addr %08lx", 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));
+ ut_assert_console_end();
set_working_fdt_addr(0);
ut_assert_nextline("Working FDT set to 0");
@@ -196,13 +209,13 @@ static int fdt_test_addr(struct unit_test_state *uts)
gd->fdt_blob = fdt_blob;
ut_assertok(ret);
ut_asserteq(addr, map_to_sysmem(new_fdt));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test setting an invalid FDT */
fdt[0] = 123;
ut_asserteq(1, run_commandf("fdt addr %08lx", addr));
ut_assert_nextline("libfdt fdt_check_header(): FDT_ERR_BADMAGIC");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test detecting an invalid FDT */
fdt[0] = 123;
@@ -210,11 +223,11 @@ static int fdt_test_addr(struct unit_test_state *uts)
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));
+ ut_assert_console_end();
return 0;
}
-FDT_TEST(fdt_test_addr, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_addr, UTF_CONSOLE);
/* Test 'fdt addr' resizing an fdt */
static int fdt_test_addr_resize(struct unit_test_state *uts)
@@ -223,32 +236,29 @@ static int fdt_test_addr_resize(struct unit_test_state *uts)
const int newsize = sizeof(fdt) / 2;
ulong addr;
- ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt)));
- addr = map_to_sysmem(fdt);
- set_working_fdt_addr(addr);
+ ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt), &addr));
/* Test setting and resizing the working FDT to a larger size */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt addr %08lx %x", addr, newsize));
ut_assert_nextline("Working FDT set to %lx", addr);
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Try shrinking it */
ut_assertok(run_commandf("fdt addr %08lx %zx", 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));
+ ut_assert_console_end();
/* ...quietly */
ut_assertok(run_commandf("fdt addr -q %08lx %zx", addr, sizeof(fdt) / 4));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* We cannot easily provoke errors in fdt_open_into(), so ignore that */
return 0;
}
-FDT_TEST(fdt_test_addr_resize, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_addr_resize, UTF_CONSOLE);
static int fdt_test_move(struct unit_test_state *uts)
{
@@ -259,30 +269,26 @@ static int fdt_test_move(struct unit_test_state *uts)
void *buf;
/* Original source DT */
- ut_assertok(make_test_fdt(uts, fdt, size));
+ ut_assertok(make_test_fdt(uts, fdt, size, &addr));
ts = fdt_totalsize(fdt);
- addr = map_to_sysmem(fdt);
- set_working_fdt_addr(addr);
/* Moved target DT location */
buf = map_sysmem(newaddr, size);
memset(buf, 0, size);
/* Test moving the working FDT to a new location */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt move %08lx %08lx %x", addr, newaddr, ts));
ut_assert_nextline("Working FDT set to %lx", newaddr);
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Compare the source and destination DTs */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("cmp.b %08lx %08lx %x", addr, newaddr, ts));
ut_assert_nextline("Total of %d byte(s) were the same", ts);
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
-FDT_TEST(fdt_test_move, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_move, UTF_CONSOLE);
static int fdt_test_resize(struct unit_test_state *uts)
{
@@ -292,21 +298,18 @@ static int fdt_test_resize(struct unit_test_state *uts)
ulong addr;
/* Original source DT */
- ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt)));
+ ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt), &addr));
fdt_shrink_to_minimum(fdt, 0); /* Resize with 0 extra bytes */
ts = fdt_totalsize(fdt);
- addr = map_to_sysmem(fdt);
- set_working_fdt_addr(addr);
/* Test resizing the working FDT and verify the new space was added */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt resize %x", newsize));
ut_asserteq(ts + newsize, fdt_totalsize(fdt));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
-FDT_TEST(fdt_test_resize, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_resize, UTF_CONSOLE);
static int fdt_test_print_list_common(struct unit_test_state *uts,
const char *opc, const char *node)
@@ -315,56 +318,50 @@ static int fdt_test_print_list_common(struct unit_test_state *uts,
* Test printing/listing the working FDT
* subnode $node/subnode
*/
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt %s %s/subnode", opc, node));
ut_assert_nextline("subnode {");
ut_assert_nextline("\t#address-cells = <0x00000000>;");
ut_assert_nextline("\t#size-cells = <0x00000000>;");
ut_assert_nextline("\tcompatible = \"u-boot,fdt-subnode-test-device\";");
ut_assert_nextline("};");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/*
* Test printing/listing the working FDT
* path / string property model
*/
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt %s / model", opc));
ut_assert_nextline("model = \"U-Boot FDT test\"");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/*
* Test printing/listing the working FDT
* path $node string property compatible
*/
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt %s %s compatible", opc, node));
ut_assert_nextline("compatible = \"u-boot,fdt-test-device1\"");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/*
* Test printing/listing the working FDT
* path $node stringlist property clock-names
*/
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt %s %s clock-names", opc, node));
ut_assert_nextline("clock-names = \"fixed\", \"i2c\", \"spi\", \"uart2\", \"uart1\"");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/*
* Test printing/listing the working FDT
* path $node u32 property clock-frequency
*/
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt %s %s clock-frequency", opc, node));
ut_assert_nextline("clock-frequency = <0x00fde800>");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/*
* Test printing/listing the working FDT
* path $node empty property u-boot,empty-property
*/
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt %s %s u-boot,empty-property", opc, node));
/*
* This is the only 'fdt print' / 'fdt list' incantation which
@@ -372,16 +369,15 @@ static int fdt_test_print_list_common(struct unit_test_state *uts,
* since the beginning of the command 'fdt', keep it.
*/
ut_assert_nextline("%s u-boot,empty-property", node);
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/*
* Test printing/listing the working FDT
* path $node prop-encoded array property regs
*/
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt %s %s regs", opc, node));
ut_assert_nextline("regs = <0x00001234 0x00001000>");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
@@ -394,12 +390,9 @@ static int fdt_test_print_list(struct unit_test_state *uts, bool print)
int ret;
/* Original source DT */
- ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
- addr = map_to_sysmem(fdt);
- set_working_fdt_addr(addr);
+ ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt), &addr));
/* Test printing/listing the working FDT -- node / */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt %s", opc));
ut_assert_nextline("/ {");
ut_assert_nextline("\t#address-cells = <0x00000001>;");
@@ -430,7 +423,7 @@ static int fdt_test_print_list(struct unit_test_state *uts, bool print)
}
ut_assert_nextline("\t};");
ut_assert_nextline("};");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
ret = fdt_test_print_list_common(uts, opc, "/test-node@1234");
if (!ret)
@@ -443,13 +436,13 @@ static int fdt_test_print(struct unit_test_state *uts)
{
return fdt_test_print_list(uts, true);
}
-FDT_TEST(fdt_test_print, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_print, UTF_CONSOLE);
static int fdt_test_list(struct unit_test_state *uts)
{
return fdt_test_print_list(uts, false);
}
-FDT_TEST(fdt_test_list, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_list, UTF_CONSOLE);
/* Test 'fdt get value' reading an fdt */
static int fdt_test_get_value_string(struct unit_test_state *uts,
@@ -457,15 +450,13 @@ static int fdt_test_get_value_string(struct unit_test_state *uts,
const char *idx, const char *strres,
const int intres)
{
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt get value var %s %s %s",
node, prop, idx ? : ""));
- if (strres) {
+ if (strres)
ut_asserteq_str(strres, env_get("var"));
- } else {
+ else
ut_asserteq(intres, env_get_hex("var", 0x1234));
- }
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
@@ -474,16 +465,20 @@ static int fdt_test_get_value_common(struct unit_test_state *uts,
const char *node)
{
/* Test getting default element of $node node clock-names property */
- fdt_test_get_value_string(uts, node, "clock-names", NULL, "fixed", 0);
+ ut_assertok(fdt_test_get_value_string(uts, node, "clock-names", NULL,
+ "fixed", 0));
/* Test getting 0th element of $node node clock-names property */
- fdt_test_get_value_string(uts, node, "clock-names", "0", "fixed", 0);
+ ut_assertok(fdt_test_get_value_string(uts, node, "clock-names", "0",
+ "fixed", 0));
/* Test getting 1st element of $node node clock-names property */
- fdt_test_get_value_string(uts, node, "clock-names", "1", "i2c", 0);
+ ut_assertok(fdt_test_get_value_string(uts, node, "clock-names", "1",
+ "i2c", 0));
/* Test getting 2nd element of $node node clock-names property */
- fdt_test_get_value_string(uts, node, "clock-names", "2", "spi", 0);
+ ut_assertok(fdt_test_get_value_string(uts, node, "clock-names", "2",
+ "spi", 0));
/*
* Test getting default element of $node node regs property.
@@ -492,29 +487,29 @@ static int fdt_test_get_value_common(struct unit_test_state *uts,
* but only if the array is shorter than 40 characters. Anything
* longer is an error. This is a special case for handling hashes.
*/
- fdt_test_get_value_string(uts, node, "regs", NULL, "3412000000100000", 0);
+ ut_assertok(fdt_test_get_value_string(uts, node, "regs", NULL,
+ "3412000000100000", 0));
/* Test getting 0th element of $node node regs property */
- fdt_test_get_value_string(uts, node, "regs", "0", NULL, 0x1234);
+ ut_assertok(fdt_test_get_value_string(uts, node, "regs", "0", NULL,
+ 0x1234));
/* Test getting 1st element of $node node regs property */
- fdt_test_get_value_string(uts, node, "regs", "1", NULL, 0x1000);
+ ut_assertok(fdt_test_get_value_string(uts, node, "regs", "1", NULL,
+ 0x1000));
/* Test missing 10th element of $node node clock-names property */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt get value ften %s clock-names 10", node));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test missing 10th element of $node node regs property */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt get value ften %s regs 10", node));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting default element of $node node nonexistent property */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt get value fnone %s nonexistent", node));
ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
@@ -523,118 +518,97 @@ static int fdt_test_get_value(struct unit_test_state *uts)
{
char fdt[4096];
ulong addr;
- int ret;
- ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
- addr = map_to_sysmem(fdt);
- set_working_fdt_addr(addr);
+ ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt), &addr));
- ret = fdt_test_get_value_common(uts, "/test-node@1234");
- if (!ret)
- ret = fdt_test_get_value_common(uts, "testnodealias");
- if (ret)
- return ret;
+ ut_assertok(fdt_test_get_value_common(uts, "/test-node@1234"));
+ ut_assertok(fdt_test_get_value_common(uts, "testnodealias"));
/* Test getting default element of /nonexistent node */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt get value fnode /nonexistent nonexistent", 1));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting default element of bad alias */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt get value vbadalias badalias nonexistent", 1));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting default element of nonexistent alias */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt get value vnoalias noalias nonexistent", 1));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
-FDT_TEST(fdt_test_get_value, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_get_value, UTF_CONSOLE);
static int fdt_test_get_name(struct unit_test_state *uts)
{
char fdt[4096];
ulong addr;
- ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
- addr = map_to_sysmem(fdt);
- set_working_fdt_addr(addr);
+ ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt), &addr));
/* Test getting name of node 0 in /, which is /aliases node */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_command("fdt get name nzero / 0", 0));
ut_asserteq_str("aliases", env_get("nzero"));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting name of node 1 in /, which is /test-node@1234 node */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_command("fdt get name none / 1", 0));
ut_asserteq_str("test-node@1234", env_get("none"));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting name of node -1 in /, which is /aliases node, same as 0 */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_command("fdt get name nmone / -1", 0));
ut_asserteq_str("aliases", env_get("nmone"));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting name of node 2 in /, which does not exist */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt get name ntwo / 2", 1));
ut_assert_nextline("libfdt node not found");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting name of node 0 in /test-node@1234, which is /subnode node */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_command("fdt get name snzero /test-node@1234 0", 0));
ut_asserteq_str("subnode", env_get("snzero"));
ut_assertok(run_command("fdt get name asnzero testnodealias 0", 0));
ut_asserteq_str("subnode", env_get("asnzero"));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting name of node 1 in /test-node@1234, which does not exist */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt get name snone /test-node@1234 1", 1));
ut_assert_nextline("libfdt node not found");
ut_asserteq(1, run_command("fdt get name asnone testnodealias 1", 1));
ut_assert_nextline("libfdt node not found");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting name of node -1 in /test-node@1234, which is /subnode node, same as 0 */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_command("fdt get name snmone /test-node@1234 -1", 0));
ut_asserteq_str("subnode", env_get("snmone"));
ut_assertok(run_command("fdt get name asnmone testnodealias -1", 0));
ut_asserteq_str("subnode", env_get("asnmone"));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting name of nonexistent node */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt get name nonode /nonexistent 0", 1));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting name of bad alias */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt get name vbadalias badalias 0", 1));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting name of nonexistent alias */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt get name vnoalias noalias 0", 1));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
-FDT_TEST(fdt_test_get_name, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_get_name, UTF_CONSOLE);
static int fdt_test_get_addr_common(struct unit_test_state *uts, char *fdt,
const char *path, const char *prop)
@@ -650,11 +624,10 @@ static int fdt_test_get_addr_common(struct unit_test_state *uts, char *fdt,
ut_assertnonnull(prop_ptr);
offset = (char *)prop_ptr - fdt;
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt get addr pstr %s %s", path, prop));
ut_asserteq((ulong)map_sysmem(env_get_hex("fdtaddr", 0x1234), 0),
(ulong)(map_sysmem(env_get_hex("pstr", 0x1234), 0) - offset));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
@@ -664,57 +637,60 @@ static int fdt_test_get_addr(struct unit_test_state *uts)
char fdt[4096];
ulong addr;
- ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
- addr = map_to_sysmem(fdt);
- set_working_fdt_addr(addr);
+ ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt), &addr));
/* Test getting address of root node / string property "compatible" */
- fdt_test_get_addr_common(uts, fdt, "/", "compatible");
+ ut_assertok(fdt_test_get_addr_common(uts, fdt, "/", "compatible"));
/* Test getting address of node /test-node@1234 stringlist property "clock-names" */
- fdt_test_get_addr_common(uts, fdt, "/test-node@1234", "clock-names");
- fdt_test_get_addr_common(uts, fdt, "testnodealias", "clock-names");
+ ut_assertok(fdt_test_get_addr_common(uts, fdt, "/test-node@1234",
+ "clock-names"));
+ ut_assertok(fdt_test_get_addr_common(uts, fdt, "testnodealias",
+ "clock-names"));
/* Test getting address of node /test-node@1234 u32 property "clock-frequency" */
- fdt_test_get_addr_common(uts, fdt, "/test-node@1234", "clock-frequency");
- fdt_test_get_addr_common(uts, fdt, "testnodealias", "clock-frequency");
+ ut_assertok(fdt_test_get_addr_common(uts, fdt, "/test-node@1234",
+ "clock-frequency"));
+ ut_assertok(fdt_test_get_addr_common(uts, fdt, "testnodealias",
+ "clock-frequency"));
/* Test getting address of node /test-node@1234 empty property "u-boot,empty-property" */
- fdt_test_get_addr_common(uts, fdt, "/test-node@1234", "u-boot,empty-property");
- fdt_test_get_addr_common(uts, fdt, "testnodealias", "u-boot,empty-property");
+ ut_assertok(fdt_test_get_addr_common(uts, fdt, "/test-node@1234",
+ "u-boot,empty-property"));
+ ut_assertok(fdt_test_get_addr_common(uts, fdt, "testnodealias",
+ "u-boot,empty-property"));
/* Test getting address of node /test-node@1234 array property "regs" */
- fdt_test_get_addr_common(uts, fdt, "/test-node@1234", "regs");
- fdt_test_get_addr_common(uts, fdt, "testnodealias", "regs");
+ ut_assertok(fdt_test_get_addr_common(uts, fdt, "/test-node@1234",
+ "regs"));
+ ut_assertok(fdt_test_get_addr_common(uts, fdt, "testnodealias",
+ "regs"));
/* Test getting address of node /test-node@1234/subnode non-existent property "noprop" */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt get addr pnoprop /test-node@1234/subnode noprop", 1));
ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting address of non-existent node /test-node@1234/nonode@1 property "noprop" */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt get addr pnonode /test-node@1234/nonode@1 noprop", 1));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
-FDT_TEST(fdt_test_get_addr, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_get_addr, UTF_CONSOLE);
static int fdt_test_get_size_common(struct unit_test_state *uts,
const char *path, const char *prop,
const unsigned int val)
{
- ut_assertok(console_record_reset_enable());
if (prop) {
ut_assertok(run_commandf("fdt get size sstr %s %s", path, prop));
} else {
ut_assertok(run_commandf("fdt get size sstr %s", path));
}
ut_asserteq(val, env_get_hex("sstr", 0x1234));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
@@ -724,71 +700,72 @@ static int fdt_test_get_size(struct unit_test_state *uts)
char fdt[4096];
ulong addr;
- ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
- addr = map_to_sysmem(fdt);
- set_working_fdt_addr(addr);
+ ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt), &addr));
/* Test getting size of root node / string property "compatible" */
- fdt_test_get_size_common(uts, "/", "compatible", 16);
+ ut_assertok(fdt_test_get_size_common(uts, "/", "compatible", 16));
/* Test getting size of node /test-node@1234 stringlist property "clock-names" */
- fdt_test_get_size_common(uts, "/test-node@1234", "clock-names", 26);
- fdt_test_get_size_common(uts, "testnodealias", "clock-names", 26);
+ ut_assertok(fdt_test_get_size_common(uts, "/test-node@1234",
+ "clock-names", 26));
+ ut_assertok(fdt_test_get_size_common(uts, "testnodealias",
+ "clock-names", 26));
/* Test getting size of node /test-node@1234 u32 property "clock-frequency" */
- fdt_test_get_size_common(uts, "/test-node@1234", "clock-frequency", 4);
- fdt_test_get_size_common(uts, "testnodealias", "clock-frequency", 4);
+ ut_assertok(fdt_test_get_size_common(uts, "/test-node@1234",
+ "clock-frequency", 4));
+ ut_assertok(fdt_test_get_size_common(uts, "testnodealias",
+ "clock-frequency", 4));
/* Test getting size of node /test-node@1234 empty property "u-boot,empty-property" */
- fdt_test_get_size_common(uts, "/test-node@1234", "u-boot,empty-property", 0);
- fdt_test_get_size_common(uts, "testnodealias", "u-boot,empty-property", 0);
+ ut_assertok(fdt_test_get_size_common(uts, "/test-node@1234",
+ "u-boot,empty-property", 0));
+ ut_assertok(fdt_test_get_size_common(uts, "testnodealias",
+ "u-boot,empty-property", 0));
/* Test getting size of node /test-node@1234 array property "regs" */
- fdt_test_get_size_common(uts, "/test-node@1234", "regs", 8);
- fdt_test_get_size_common(uts, "testnodealias", "regs", 8);
+ ut_assertok(fdt_test_get_size_common(uts, "/test-node@1234", "regs",
+ 8));
+ ut_assertok(fdt_test_get_size_common(uts, "testnodealias", "regs", 8));
/* Test getting node count of node / */
- fdt_test_get_size_common(uts, "/", NULL, 2);
+ ut_assertok(fdt_test_get_size_common(uts, "/", NULL, 2));
/* Test getting node count of node /test-node@1234/subnode */
- fdt_test_get_size_common(uts, "/test-node@1234/subnode", NULL, 0);
- fdt_test_get_size_common(uts, "subnodealias", NULL, 0);
+ ut_assertok(fdt_test_get_size_common(uts, "/test-node@1234/subnode",
+ NULL, 0));
+ ut_assertok(fdt_test_get_size_common(uts, "subnodealias", NULL, 0));
/* Test getting size of node /test-node@1234/subnode non-existent property "noprop" */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt get size pnoprop /test-node@1234/subnode noprop", 1));
ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND");
ut_asserteq(1, run_command("fdt get size pnoprop subnodealias noprop", 1));
ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting size of non-existent node /test-node@1234/nonode@1 property "noprop" */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt get size pnonode /test-node@1234/nonode@1 noprop", 1));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting node count of non-existent node /test-node@1234/nonode@1 */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt get size pnonode /test-node@1234/nonode@1", 1));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting node count of bad alias badalias */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt get size pnonode badalias noprop", 1));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting node count of non-existent alias noalias */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt get size pnonode noalias", 1));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
-FDT_TEST(fdt_test_get_size, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_get_size, UTF_CONSOLE);
static int fdt_test_set_single(struct unit_test_state *uts,
const char *path, const char *prop,
@@ -800,7 +777,6 @@ static int fdt_test_set_single(struct unit_test_state *uts,
* => fdt set /path property integer
* => fdt set /path property
*/
- ut_assertok(console_record_reset_enable());
if (sval)
ut_assertok(run_commandf("fdt set %s %s %s", path, prop, sval));
else if (integer)
@@ -816,7 +792,7 @@ static int fdt_test_set_single(struct unit_test_state *uts,
ut_asserteq(ival, env_get_hex("svar", 0x1234));
else
ut_assertnull(env_get("svar"));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
@@ -838,7 +814,6 @@ static int fdt_test_set_multi(struct unit_test_state *uts,
* new array is correctly sized and read past the new array length
* triggers failure.
*/
- ut_assertok(console_record_reset_enable());
if (sval1 && sval2) {
ut_assertok(run_commandf("fdt set %s %s %s %s end", path, prop, sval1, sval2));
ut_assertok(run_commandf("fdt set %s %s %s %s", path, prop, sval1, sval2));
@@ -866,7 +841,7 @@ static int fdt_test_set_multi(struct unit_test_state *uts,
ut_asserteq(ival2, env_get_hex("svar2", 0x1234));
ut_assertnull(env_get("svarn"));
}
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
@@ -874,14 +849,14 @@ static int fdt_test_set_multi(struct unit_test_state *uts,
static int fdt_test_set_node(struct unit_test_state *uts,
const char *path, const char *prop)
{
- fdt_test_set_single(uts, path, prop, "new", 0, false);
- fdt_test_set_single(uts, path, prop, "rewrite", 0, false);
- fdt_test_set_single(uts, path, prop, NULL, 42, true);
- fdt_test_set_single(uts, path, prop, NULL, 0, false);
- fdt_test_set_multi(uts, path, prop, NULL, NULL, 42, 1701);
- fdt_test_set_multi(uts, path, prop, NULL, NULL, 74656, 9);
- fdt_test_set_multi(uts, path, prop, "42", "1701", 0, 0);
- fdt_test_set_multi(uts, path, prop, "74656", "9", 0, 0);
+ ut_assertok(fdt_test_set_single(uts, path, prop, "new", 0, false));
+ ut_assertok(fdt_test_set_single(uts, path, prop, "rewrite", 0, false));
+ ut_assertok(fdt_test_set_single(uts, path, prop, NULL, 42, true));
+ ut_assertok(fdt_test_set_single(uts, path, prop, NULL, 0, false));
+ ut_assertok(fdt_test_set_multi(uts, path, prop, NULL, NULL, 42, 1701));
+ ut_assertok(fdt_test_set_multi(uts, path, prop, NULL, NULL, 74656, 9));
+ ut_assertok(fdt_test_set_multi(uts, path, prop, "42", "1701", 0, 0));
+ ut_assertok(fdt_test_set_multi(uts, path, prop, "74656", "9", 0, 0));
return 0;
}
@@ -891,198 +866,173 @@ static int fdt_test_set(struct unit_test_state *uts)
char fdt[8192];
ulong addr;
- ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
+ ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt), &addr));
fdt_shrink_to_minimum(fdt, 4096); /* Resize with 4096 extra bytes */
- addr = map_to_sysmem(fdt);
- set_working_fdt_addr(addr);
/* Test setting of root node / existing property "compatible" */
- fdt_test_set_node(uts, "/", "compatible");
+ ut_assertok(fdt_test_set_node(uts, "/", "compatible"));
/* Test setting of root node / new property "newproperty" */
- fdt_test_set_node(uts, "/", "newproperty");
+ ut_assertok(fdt_test_set_node(uts, "/", "newproperty"));
/* Test setting of subnode existing property "compatible" */
- fdt_test_set_node(uts, "/test-node@1234/subnode", "compatible");
- fdt_test_set_node(uts, "subnodealias", "compatible");
+ ut_assertok(fdt_test_set_node(uts, "/test-node@1234/subnode",
+ "compatible"));
+ ut_assertok(fdt_test_set_node(uts, "subnodealias", "compatible"));
/* Test setting of subnode new property "newproperty" */
- fdt_test_set_node(uts, "/test-node@1234/subnode", "newproperty");
- fdt_test_set_node(uts, "subnodealias", "newproperty");
+ ut_assertok(fdt_test_set_node(uts, "/test-node@1234/subnode",
+ "newproperty"));
+ ut_assertok(fdt_test_set_node(uts, "subnodealias", "newproperty"));
/* Test setting property of non-existent node */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt set /no-node noprop", 1));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test setting property of non-existent alias */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt set noalias noprop", 1));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test setting property of bad alias */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt set badalias noprop", 1));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
-FDT_TEST(fdt_test_set, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_set, UTF_CONSOLE);
static int fdt_test_mknode(struct unit_test_state *uts)
{
char fdt[8192];
ulong addr;
- ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
+ ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt), &addr));
fdt_shrink_to_minimum(fdt, 4096); /* Resize with 4096 extra bytes */
- addr = map_to_sysmem(fdt);
- set_working_fdt_addr(addr);
/* Test creation of new node in / */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt mknode / newnode"));
ut_assertok(run_commandf("fdt list /newnode"));
ut_assert_nextline("newnode {");
ut_assert_nextline("};");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test creation of new node in /test-node@1234 */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt mknode /test-node@1234 newsubnode"));
ut_assertok(run_commandf("fdt list /test-node@1234/newsubnode"));
ut_assert_nextline("newsubnode {");
ut_assert_nextline("};");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test creation of new node in /test-node@1234 by alias */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt mknode testnodealias newersubnode"));
ut_assertok(run_commandf("fdt list testnodealias/newersubnode"));
ut_assert_nextline("newersubnode {");
ut_assert_nextline("};");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test creation of new node in /test-node@1234 over existing node */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt mknode testnodealias newsubnode"));
ut_assert_nextline("libfdt fdt_add_subnode(): FDT_ERR_EXISTS");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test creation of new node in /test-node@1234 by alias over existing node */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt mknode testnodealias newersubnode"));
ut_assert_nextline("libfdt fdt_add_subnode(): FDT_ERR_EXISTS");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test creation of new node in non-existent node */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt mknode /no-node newnosubnode"));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test creation of new node in non-existent alias */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt mknode noalias newfailsubnode"));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test creation of new node in bad alias */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt mknode badalias newbadsubnode"));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
-FDT_TEST(fdt_test_mknode, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_mknode, UTF_CONSOLE);
static int fdt_test_rm(struct unit_test_state *uts)
{
char fdt[4096];
ulong addr;
- ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
- addr = map_to_sysmem(fdt);
- set_working_fdt_addr(addr);
+ ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt), &addr));
/* Test removal of property in root node / */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt print / compatible"));
ut_assert_nextline("compatible = \"u-boot,fdt-test\"");
ut_assertok(run_commandf("fdt rm / compatible"));
ut_asserteq(1, run_commandf("fdt print / compatible"));
ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test removal of property clock-names in subnode /test-node@1234 */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt print /test-node@1234 clock-names"));
ut_assert_nextline("clock-names = \"fixed\", \"i2c\", \"spi\", \"uart2\", \"uart1\"");
ut_assertok(run_commandf("fdt rm /test-node@1234 clock-names"));
ut_asserteq(1, run_commandf("fdt print /test-node@1234 clock-names"));
ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test removal of property u-boot,empty-property in subnode /test-node@1234 by alias */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt print testnodealias u-boot,empty-property"));
ut_assert_nextline("testnodealias u-boot,empty-property");
ut_assertok(run_commandf("fdt rm testnodealias u-boot,empty-property"));
ut_asserteq(1, run_commandf("fdt print testnodealias u-boot,empty-property"));
ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test removal of non-existent property noprop in subnode /test-node@1234 */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt rm /test-node@1234 noprop"));
ut_assert_nextline("libfdt fdt_delprop(): FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test removal of non-existent node /no-node@5678 */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt rm /no-node@5678"));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test removal of subnode /test-node@1234/subnode by alias */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt rm subnodealias"));
ut_asserteq(1, run_commandf("fdt print /test-node@1234/subnode"));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test removal of node by non-existent alias */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt rm noalias"));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test removal of node by bad alias */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt rm noalias"));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test removal of node /test-node@1234 */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt rm /test-node@1234"));
ut_asserteq(1, run_commandf("fdt print /test-node@1234"));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test removal of node / */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt rm /"));
ut_asserteq(1, run_commandf("fdt print /"));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
-FDT_TEST(fdt_test_rm, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_rm, UTF_CONSOLE);
static int fdt_test_bootcpu(struct unit_test_state *uts)
{
@@ -1090,46 +1040,39 @@ static int fdt_test_bootcpu(struct unit_test_state *uts)
ulong addr;
int i;
- ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt)));
- addr = map_to_sysmem(fdt);
- set_working_fdt_addr(addr);
+ ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt), &addr));
/* Test getting default bootcpu entry */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt header get bootcpu boot_cpuid_phys"));
ut_asserteq(0, env_get_ulong("bootcpu", 10, 0x1234));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test setting and getting new bootcpu entry, twice, to test overwrite */
for (i = 42; i <= 43; i++) {
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt bootcpu %d", i));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting new bootcpu entry */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt header get bootcpu boot_cpuid_phys"));
ut_asserteq(i, env_get_ulong("bootcpu", 10, 0x1234));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
}
return 0;
}
-FDT_TEST(fdt_test_bootcpu, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_bootcpu, UTF_CONSOLE);
static int fdt_test_header_get(struct unit_test_state *uts,
const char *field, const unsigned long val)
{
/* Test getting valid header entry */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt header get fvar %s", field));
ut_asserteq(val, env_get_hex("fvar", 0x1234));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test getting malformed header entry */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt header get fvar typo%stypo", field));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
@@ -1139,12 +1082,9 @@ static int fdt_test_header(struct unit_test_state *uts)
char fdt[256];
ulong addr;
- ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt)));
- addr = map_to_sysmem(fdt);
- set_working_fdt_addr(addr);
+ ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt), &addr));
/* Test header print */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt header"));
ut_assert_nextline("magic:\t\t\t0x%x", fdt_magic(fdt));
ut_assert_nextline("totalsize:\t\t0x%x (%d)", fdt_totalsize(fdt), fdt_totalsize(fdt));
@@ -1158,23 +1098,30 @@ static int fdt_test_header(struct unit_test_state *uts)
ut_assert_nextline("size_dt_struct:\t\t0x%x", fdt_size_dt_struct(fdt));
ut_assert_nextline("number mem_rsv:\t\t0x%x", fdt_num_mem_rsv(fdt));
ut_assert_nextline_empty();
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test header get */
- fdt_test_header_get(uts, "magic", fdt_magic(fdt));
- fdt_test_header_get(uts, "totalsize", fdt_totalsize(fdt));
- fdt_test_header_get(uts, "off_dt_struct", fdt_off_dt_struct(fdt));
- fdt_test_header_get(uts, "off_dt_strings", fdt_off_dt_strings(fdt));
- fdt_test_header_get(uts, "off_mem_rsvmap", fdt_off_mem_rsvmap(fdt));
- fdt_test_header_get(uts, "version", fdt_version(fdt));
- fdt_test_header_get(uts, "last_comp_version", fdt_last_comp_version(fdt));
- fdt_test_header_get(uts, "boot_cpuid_phys", fdt_boot_cpuid_phys(fdt));
- fdt_test_header_get(uts, "size_dt_strings", fdt_size_dt_strings(fdt));
- fdt_test_header_get(uts, "size_dt_struct", fdt_size_dt_struct(fdt));
+ ut_assertok(fdt_test_header_get(uts, "magic", fdt_magic(fdt)));
+ ut_assertok(fdt_test_header_get(uts, "totalsize", fdt_totalsize(fdt)));
+ ut_assertok(fdt_test_header_get(uts, "off_dt_struct",
+ fdt_off_dt_struct(fdt)));
+ ut_assertok(fdt_test_header_get(uts, "off_dt_strings",
+ fdt_off_dt_strings(fdt)));
+ ut_assertok(fdt_test_header_get(uts, "off_mem_rsvmap",
+ fdt_off_mem_rsvmap(fdt)));
+ ut_assertok(fdt_test_header_get(uts, "version", fdt_version(fdt)));
+ ut_assertok(fdt_test_header_get(uts, "last_comp_version",
+ fdt_last_comp_version(fdt)));
+ ut_assertok(fdt_test_header_get(uts, "boot_cpuid_phys",
+ fdt_boot_cpuid_phys(fdt)));
+ ut_assertok(fdt_test_header_get(uts, "size_dt_strings",
+ fdt_size_dt_strings(fdt)));
+ ut_assertok(fdt_test_header_get(uts, "size_dt_struct",
+ fdt_size_dt_struct(fdt)));
return 0;
}
-FDT_TEST(fdt_test_header, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_header, UTF_CONSOLE);
static int fdt_test_memory_cells(struct unit_test_state *uts,
const unsigned int cells)
@@ -1218,16 +1165,16 @@ static int fdt_test_memory_cells(struct unit_test_state *uts,
fdt_shrink_to_minimum(fdt, 4096); /* Resize with 4096 extra bytes */
addr = map_to_sysmem(fdt);
set_working_fdt_addr(addr);
+ ut_assert_nextline("Working FDT set to %lx", addr);
/* Test updating the memory node */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt memory 0x%s 0x%s", seta, sets));
ut_assertok(run_commandf("fdt print /memory"));
ut_assert_nextline("memory {");
ut_assert_nextline("\tdevice_type = \"memory\";");
ut_assert_nextline("\treg = <%s %s>;", pada, pads);
ut_assert_nextline("};");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
free(sets);
free(seta);
@@ -1245,8 +1192,8 @@ static int fdt_test_memory(struct unit_test_state *uts)
* so far unsupported and fails because of simple_stroull() being
* 64bit tops in the 'fdt memory' command implementation.
*/
- fdt_test_memory_cells(uts, 1);
- fdt_test_memory_cells(uts, 2);
+ ut_assertok(fdt_test_memory_cells(uts, 1));
+ ut_assertok(fdt_test_memory_cells(uts, 2));
/*
* The 'fdt memory' command is limited to /memory node, it does
@@ -1257,31 +1204,27 @@ static int fdt_test_memory(struct unit_test_state *uts)
return 0;
}
-FDT_TEST(fdt_test_memory, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_memory, UTF_CONSOLE);
static int fdt_test_rsvmem(struct unit_test_state *uts)
{
char fdt[8192];
ulong addr;
- ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt)));
+ ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt), &addr));
fdt_shrink_to_minimum(fdt, 4096); /* Resize with 4096 extra bytes */
fdt_add_mem_rsv(fdt, 0x42, 0x1701);
fdt_add_mem_rsv(fdt, 0x74656, 0x9);
- addr = map_to_sysmem(fdt);
- set_working_fdt_addr(addr);
/* Test default reserved memory node presence */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt rsvmem print"));
ut_assert_nextline("index\t\t start\t\t size");
ut_assert_nextline("------------------------------------------------");
ut_assert_nextline(" %x\t%016x\t%016x", 0, 0x42, 0x1701);
ut_assert_nextline(" %x\t%016x\t%016x", 1, 0x74656, 0x9);
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test add new reserved memory node */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt rsvmem add 0x1234 0x5678"));
ut_assertok(run_commandf("fdt rsvmem print"));
ut_assert_nextline("index\t\t start\t\t size");
@@ -1289,20 +1232,18 @@ static int fdt_test_rsvmem(struct unit_test_state *uts)
ut_assert_nextline(" %x\t%016x\t%016x", 0, 0x42, 0x1701);
ut_assert_nextline(" %x\t%016x\t%016x", 1, 0x74656, 0x9);
ut_assert_nextline(" %x\t%016x\t%016x", 2, 0x1234, 0x5678);
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test delete reserved memory node */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt rsvmem delete 0"));
ut_assertok(run_commandf("fdt rsvmem print"));
ut_assert_nextline("index\t\t start\t\t size");
ut_assert_nextline("------------------------------------------------");
ut_assert_nextline(" %x\t%016x\t%016x", 0, 0x74656, 0x9);
ut_assert_nextline(" %x\t%016x\t%016x", 1, 0x1234, 0x5678);
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test re-add new reserved memory node */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt rsvmem add 0x42 0x1701"));
ut_assertok(run_commandf("fdt rsvmem print"));
ut_assert_nextline("index\t\t start\t\t size");
@@ -1310,17 +1251,16 @@ static int fdt_test_rsvmem(struct unit_test_state *uts)
ut_assert_nextline(" %x\t%016x\t%016x", 0, 0x74656, 0x9);
ut_assert_nextline(" %x\t%016x\t%016x", 1, 0x1234, 0x5678);
ut_assert_nextline(" %x\t%016x\t%016x", 2, 0x42, 0x1701);
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test delete nonexistent reserved memory node */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt rsvmem delete 10"));
ut_assert_nextline("libfdt fdt_del_mem_rsv(): FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
-FDT_TEST(fdt_test_rsvmem, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_rsvmem, UTF_CONSOLE);
static int fdt_test_chosen(struct unit_test_state *uts)
{
@@ -1328,30 +1268,29 @@ static int fdt_test_chosen(struct unit_test_state *uts)
char fdt[8192];
ulong addr;
- ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt)));
+ ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt), &addr));
fdt_shrink_to_minimum(fdt, 4096); /* Resize with 4096 extra bytes */
- addr = map_to_sysmem(fdt);
- set_working_fdt_addr(addr);
/* Test default chosen node presence, fail as there is no /chosen node */
- ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt print /chosen"));
ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test add new chosen node without initrd */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt chosen"));
ut_assertok(run_commandf("fdt print /chosen"));
ut_assert_nextline("chosen {");
ut_assert_nextlinen("\tu-boot,version = "); /* Ignore the version string */
if (env_bootargs)
ut_assert_nextline("\tbootargs = \"%s\";", env_bootargs);
+ if (IS_ENABLED(CONFIG_DM_RNG) &&
+ !IS_ENABLED(CONFIG_MEASURED_BOOT) &&
+ !IS_ENABLED(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT))
+ ut_assert_nextlinen("\tkaslr-seed = ");
ut_assert_nextline("};");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test add new chosen node with initrd */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt chosen 0x1234 0x5678"));
ut_assertok(run_commandf("fdt print /chosen"));
ut_assert_nextline("chosen {");
@@ -1363,12 +1302,16 @@ static int fdt_test_chosen(struct unit_test_state *uts)
ut_assert_nextlinen("\tu-boot,version = "); /* Ignore the version string */
if (env_bootargs)
ut_assert_nextline("\tbootargs = \"%s\";", env_bootargs);
+ if (IS_ENABLED(CONFIG_DM_RNG) &&
+ !IS_ENABLED(CONFIG_MEASURED_BOOT) &&
+ !IS_ENABLED(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT))
+ ut_assert_nextlinen("\tkaslr-seed = ");
ut_assert_nextline("};");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
-FDT_TEST(fdt_test_chosen, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_chosen, UTF_CONSOLE);
static int fdt_test_apply(struct unit_test_state *uts)
{
@@ -1386,6 +1329,7 @@ static int fdt_test_apply(struct unit_test_state *uts)
fdt_shrink_to_minimum(fdt, 4096); /* Resize with 4096 extra bytes */
addr = map_to_sysmem(fdt);
set_working_fdt_addr(addr);
+ ut_assert_nextline("Working FDT set to %lx", addr);
/* Create DTO which adds single property to root node / */
ut_assertok(fdt_create(fdto, sizeof(fdto)));
@@ -1401,16 +1345,14 @@ static int fdt_test_apply(struct unit_test_state *uts)
addro = map_to_sysmem(fdto);
/* Test default DT print */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt print /"));
ut_assert_nextline("/ {");
ut_assert_nextline("\t__symbols__ {");
ut_assert_nextline("\t};");
ut_assert_nextline("};");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test simple DTO application */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt apply 0x%08lx", addro));
ut_assertok(run_commandf("fdt print /"));
ut_assert_nextline("/ {");
@@ -1418,7 +1360,7 @@ static int fdt_test_apply(struct unit_test_state *uts)
ut_assert_nextline("\t__symbols__ {");
ut_assert_nextline("\t};");
ut_assert_nextline("};");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/*
* Create complex DTO which:
@@ -1455,7 +1397,6 @@ static int fdt_test_apply(struct unit_test_state *uts)
addro = map_to_sysmem(fdto);
/* Test complex DTO application */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt apply 0x%08lx", addro));
ut_assertok(run_commandf("fdt print /"));
ut_assert_nextline("/ {");
@@ -1472,7 +1413,7 @@ static int fdt_test_apply(struct unit_test_state *uts)
ut_assert_nextline("\t\tsubnodephandle = \"/subnode\";");
ut_assert_nextline("\t};");
ut_assert_nextline("};");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/*
* Create complex DTO which:
@@ -1499,7 +1440,6 @@ static int fdt_test_apply(struct unit_test_state *uts)
addro = map_to_sysmem(fdto);
/* Test complex DTO application */
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt apply 0x%08lx", addro));
ut_assertok(run_commandf("fdt print /"));
ut_assert_nextline("/ {");
@@ -1516,16 +1456,8 @@ static int fdt_test_apply(struct unit_test_state *uts)
ut_assert_nextline("\t\tsubnodephandle = \"/subnode\";");
ut_assert_nextline("\t};");
ut_assert_nextline("};");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
-FDT_TEST(fdt_test_apply, UT_TESTF_CONSOLE_REC);
-
-int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(fdt_test);
-
- return cmd_ut_category("fdt", "fdt_test_", tests, n_ents, argc, argv);
-}
+FDT_TEST(fdt_test_apply, UTF_CONSOLE);
diff --git a/test/cmd/font.c b/test/cmd/font.c
index 1fe05c1ead5..7ae648d7395 100644
--- a/test/cmd/font.c
+++ b/test/cmd/font.c
@@ -5,15 +5,13 @@
* Copyright 2022 Google LLC
*/
-#include <common.h>
#include <console.h>
#include <dm.h>
#include <video_console.h>
-#include <test/suites.h>
#include <test/ut.h>
/* Declare a new fdt test */
-#define FONT_TEST(_name, _flags) UNIT_TEST(_name, _flags, font_test)
+#define FONT_TEST(_name, _flags) UNIT_TEST(_name, _flags, font)
/* Test 'fdt addr' resizing an fdt */
static int font_test_base(struct unit_test_state *uts)
@@ -27,16 +25,21 @@ static int font_test_base(struct unit_test_state *uts)
ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
ut_assertok(uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev));
- ut_assertok(console_record_reset_enable());
ut_assertok(run_command("font list", 0));
- ut_assert_nextline("nimbus_sans_l_regular");
+ if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_NIMBUS))
+ ut_assert_nextline("nimbus_sans_l_regular");
+ if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_ANKACODER))
+ ut_assert_nextline("ankacoder_c75_r");
if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE))
ut_assert_nextline("cantoraone_regular");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
ut_assertok(vidconsole_get_font_size(dev, &name, &size));
- ut_asserteq_str("nimbus_sans_l_regular", name);
- ut_asserteq(18, size);
+ if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_ANKACODER))
+ ut_asserteq_str("ankacoder_c75_r", name);
+ else
+ ut_asserteq_str("nimbus_sans_l_regular", name);
+ ut_asserteq(CONFIG_CONSOLE_TRUETYPE_SIZE, size);
if (!IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE))
return 0;
@@ -50,18 +53,27 @@ static int font_test_base(struct unit_test_state *uts)
if (max_metrics < 2) {
ut_asserteq(1, ret);
ut_assert_nextline("Failed (error -7)");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
ut_assertok(ret);
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
ut_assertok(vidconsole_get_font_size(dev, &name, &size));
ut_asserteq_str("cantoraone_regular", name);
ut_asserteq(40, size);
+ ut_assertok(ut_check_console_end(uts));
+
+ ut_assertok(run_command("font size", 0));
+ ut_assert_nextline("40");
+ ut_assertok(ut_check_console_end(uts));
ut_assertok(run_command("font size 30", 0));
+ ut_assert_console_end();
+
+ ut_assertok(run_command("font size", 0));
+ ut_assert_nextline("30");
ut_assertok(ut_check_console_end(uts));
ut_assertok(vidconsole_get_font_size(dev, &name, &size));
@@ -70,13 +82,5 @@ static int font_test_base(struct unit_test_state *uts)
return 0;
}
-FONT_TEST(font_test_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT |
- UT_TESTF_CONSOLE_REC | UT_TESTF_DM);
-
-int do_ut_font(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(font_Test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(font_test);
-
- return cmd_ut_category("font", "font_test_", tests, n_ents, argc, argv);
-}
+FONT_TEST(font_test_base, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE |
+ UTF_DM);
diff --git a/test/cmd/hash.c b/test/cmd/hash.c
new file mode 100644
index 00000000000..296dd762b31
--- /dev/null
+++ b/test/cmd/hash.c
@@ -0,0 +1,104 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Tests for hash command
+ *
+ * Copyright 2024, Heinrich Schuchardt <heinrich.schuchardt@canoncal.com>
+ */
+
+#include <command.h>
+#include <dm.h>
+#include <dm/test.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+static int dm_test_cmd_hash_md5(struct unit_test_state *uts)
+{
+ if (!CONFIG_IS_ENABLED(MD5)) {
+ ut_assert(run_command("hash md5 $loadaddr 0", 0));
+
+ return 0;
+ }
+
+ ut_assertok(run_command("hash md5 $loadaddr 0", 0));
+ console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+ ut_asserteq_ptr(uts->actual_str,
+ strstr(uts->actual_str, "md5 for "));
+ ut_assert(strstr(uts->actual_str,
+ "d41d8cd98f00b204e9800998ecf8427e"));
+ ut_assert_console_end();
+
+ ut_assertok(run_command("hash md5 $loadaddr 0 foo; echo $foo", 0));
+ console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+ ut_asserteq_ptr(uts->actual_str,
+ strstr(uts->actual_str, "md5 for "));
+ ut_assert(strstr(uts->actual_str,
+ "d41d8cd98f00b204e9800998ecf8427e"));
+ ut_assertok(ut_check_console_line(uts,
+ "d41d8cd98f00b204e9800998ecf8427e"));
+
+ if (!CONFIG_IS_ENABLED(HASH_VERIFY)) {
+ ut_assert(run_command("hash -v sha256 $loadaddr 0 foo", 0));
+ ut_assertok(ut_check_console_line(
+ uts, "hash - compute hash message digest"));
+
+ return 0;
+ }
+
+ ut_assertok(run_command("hash -v md5 $loadaddr 0 foo", 0));
+ ut_assert_console_end();
+
+ env_set("foo", "ffffffffffffffffffffffffffffffff");
+ ut_assert(run_command("hash -v md5 $loadaddr 0 foo", 0));
+ console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+ ut_assert(strstr(uts->actual_str, "!="));
+ ut_assert_console_end();
+
+ return 0;
+}
+DM_TEST(dm_test_cmd_hash_md5, UTF_CONSOLE);
+
+static int dm_test_cmd_hash_sha256(struct unit_test_state *uts)
+{
+ if (!CONFIG_IS_ENABLED(SHA256)) {
+ ut_assert(run_command("hash sha256 $loadaddr 0", 0));
+
+ return 0;
+ }
+
+ ut_assertok(run_command("hash sha256 $loadaddr 0", 0));
+ console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+ ut_asserteq_ptr(uts->actual_str,
+ strstr(uts->actual_str, "sha256 for "));
+ ut_assert(strstr(uts->actual_str,
+ "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
+ ut_assert_console_end();
+
+ ut_assertok(run_command("hash sha256 $loadaddr 0 foo; echo $foo", 0));
+ console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+ ut_asserteq_ptr(uts->actual_str,
+ strstr(uts->actual_str, "sha256 for "));
+ ut_assert(strstr(uts->actual_str,
+ "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
+ ut_assertok(ut_check_console_line(
+ uts, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
+
+ if (!CONFIG_IS_ENABLED(HASH_VERIFY)) {
+ ut_assert(run_command("hash -v sha256 $loadaddr 0 foo", 0));
+ ut_assertok(ut_check_console_line(
+ uts, "hash - compute hash message digest"));
+
+ return 0;
+ }
+
+ ut_assertok(run_command("hash -v sha256 $loadaddr 0 foo", 0));
+ ut_assert_console_end();
+
+ env_set("foo", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
+ ut_assert(run_command("hash -v sha256 $loadaddr 0 foo", 0));
+ console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+ ut_assert(strstr(uts->actual_str, "!="));
+ ut_assert_console_end();
+
+ return 0;
+}
+DM_TEST(dm_test_cmd_hash_sha256, UTF_CONSOLE);
diff --git a/test/cmd/history.c b/test/cmd/history.c
index 06517fcdbb5..6d9d2288483 100644
--- a/test/cmd/history.c
+++ b/test/cmd/history.c
@@ -6,7 +6,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <cli.h>
#include <command.h>
#include <test/lib.h>
@@ -46,4 +45,4 @@ static int lib_test_history(struct unit_test_state *uts)
return 0;
}
-LIB_TEST(lib_test_history, UT_TESTF_CONSOLE_REC);
+LIB_TEST(lib_test_history, UTF_CONSOLE);
diff --git a/test/cmd/loadm.c b/test/cmd/loadm.c
index 41e005ac592..043cd25dfb6 100644
--- a/test/cmd/loadm.c
+++ b/test/cmd/loadm.c
@@ -9,22 +9,19 @@
* Rui Miguel Silva <rui.silva@linaro.org>
*/
-#include <common.h>
#include <console.h>
#include <mapmem.h>
#include <asm/global_data.h>
#include <dm/test.h>
-#include <test/suites.h>
#include <test/test.h>
#include <test/ut.h>
#define BUF_SIZE 0x100
-#define LOADM_TEST(_name, _flags) UNIT_TEST(_name, _flags, loadm_test)
+#define LOADM_TEST(_name, _flags) UNIT_TEST(_name, _flags, loadm)
static int loadm_test_params(struct unit_test_state *uts)
{
- ut_assertok(console_record_reset_enable());
run_command("loadm", 0);
ut_assert_nextline("loadm - load binary blob from source address to destination address");
@@ -42,7 +39,7 @@ static int loadm_test_params(struct unit_test_state *uts)
return 0;
}
-LOADM_TEST(loadm_test_params, UT_TESTF_CONSOLE_REC);
+LOADM_TEST(loadm_test_params, UTF_CONSOLE);
static int loadm_test_load (struct unit_test_state *uts)
{
@@ -52,7 +49,6 @@ static int loadm_test_load (struct unit_test_state *uts)
memset(buf, '\0', BUF_SIZE);
memset(buf, 0xaa, BUF_SIZE / 2);
- ut_assertok(console_record_reset_enable());
run_command("loadm 0x0 0x80 0x80", 0);
ut_assert_nextline("loaded bin to memory: size: 128");
@@ -60,13 +56,4 @@ static int loadm_test_load (struct unit_test_state *uts)
return 0;
}
-LOADM_TEST(loadm_test_load, UT_TESTF_CONSOLE_REC);
-
-int do_ut_loadm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(loadm_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(loadm_test);
-
- return cmd_ut_category("loadm", "loadm_test_", tests, n_ents, argc,
- argv);
-}
+LOADM_TEST(loadm_test_load, UTF_CONSOLE);
diff --git a/test/cmd/mbr.c b/test/cmd/mbr.c
index 235b363290e..e651256a4cb 100644
--- a/test/cmd/mbr.c
+++ b/test/cmd/mbr.c
@@ -14,10 +14,13 @@
#include <asm/global_data.h>
#include <dm/device-internal.h>
#include <dm/lists.h>
-#include <test/suites.h>
+#include <linux/sizes.h>
#include <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
+
+#define BLKSZ SZ_512 /* block size */
+
/*
* Requirements for running test manually:
* mmc6.img - File size needs to be at least 12 MiB
@@ -50,7 +53,7 @@ static char * mbr_parts_tail = "'";
000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
*/
-static unsigned mbr_cmp_start = 0x1B8;
+static unsigned int mbr_cmp_start = 0x1b8;
static unsigned mbr_cmp_size = 0x48;
static unsigned char mbr_parts_ref_p1[] = {
0x78, 0x56, 0x34, 0x12, 0x00, 0x00, 0x80, 0x05,
@@ -228,9 +231,11 @@ static unsigned build_mbr_parts(char *buf, size_t buf_size, unsigned num_parts)
static int mbr_test_run(struct unit_test_state *uts)
{
struct blk_desc *mmc_dev_desc;
- unsigned char mbr_wbuf[512], ebr_wbuf[512], rbuf[512];
+ unsigned char *mbr_wbuf, *ebr_wbuf, *rbuf;
char mbr_parts_buf[256];
- ulong mbr_wa, ebr_wa, ra, ebr_blk, mbr_parts_max;
+ ulong addr = 0x1000; /* start address for buffers */
+ ulong mbr_wa = addr, ebr_wa = addr + BLKSZ, ra = addr + BLKSZ * 2;
+ ulong ebr_blk, mbr_parts_max;
struct udevice *dev;
ofnode root, node;
@@ -251,46 +256,46 @@ static int mbr_test_run(struct unit_test_state *uts)
strlen(mbr_parts_p3) +
max(strlen(mbr_parts_p4), strlen(mbr_parts_p5)) +
strlen(mbr_parts_tail);
- ut_assertf(sizeof(mbr_parts_buf) >= mbr_parts_max, "Buffer avail: %ld; buffer req: %ld\n",
- sizeof(mbr_parts_buf), mbr_parts_max);
+ ut_assertf(sizeof(mbr_parts_buf) >= mbr_parts_max, "Buffer avail: %zd; buffer req: %ld\n",
+ sizeof(mbr_parts_buf), mbr_parts_max);
- mbr_wa = map_to_sysmem(mbr_wbuf);
- ebr_wa = map_to_sysmem(ebr_wbuf);
- ra = map_to_sysmem(rbuf);
- ebr_blk = (ulong)0xB00000 / 0x200;
+ mbr_wbuf = map_sysmem(mbr_wa, BLKSZ);
+ ebr_wbuf = map_sysmem(ebr_wa, BLKSZ);
+ rbuf = map_sysmem(ra, BLKSZ);
+ ebr_blk = (ulong)0xb00000 / BLKSZ;
/* Make sure mmc6 exists */
ut_asserteq(6, blk_get_device_by_str("mmc", "6", &mmc_dev_desc));
- ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("mmc dev 6"));
ut_assert_nextline("switch to partitions #0, OK");
ut_assert_nextline("mmc6 is current device");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Make sure mmc6 is 12+ MiB in size */
- ut_assertok(run_commandf("mmc read 0x%lx 0x%lx 1", ra, (ulong)0xBFFE00 / 0x200));
+ ut_assertok(run_commandf("mmc read %lx %lx 1", ra,
+ (ulong)0xbffe00 / BLKSZ));
/* Test one MBR partition */
- init_write_buffers(mbr_wbuf, sizeof(mbr_wbuf), ebr_wbuf, sizeof(ebr_wbuf), __LINE__);
+ init_write_buffers(mbr_wbuf, BLKSZ, ebr_wbuf, BLKSZ, __LINE__);
ut_assertok(build_mbr_parts(mbr_parts_buf, sizeof(mbr_parts_buf), 1));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0 1", mbr_wa));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
- ut_assertok(memcmp(mbr_wbuf, rbuf, 512));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0x%lx 1", ebr_wa, ebr_blk));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
- ut_assertok(console_record_reset_enable());
+ ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
+ ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ));
+ ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
ut_assertok(run_commandf("mbr write mmc 6"));
+ ut_assert_nextlinen("MMC read: dev # 6");
ut_assert_nextline("MBR: write success!");
ut_assertok(run_commandf("mbr verify mmc 6"));
ut_assert_nextline("MBR: verify success!");
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
- ut_assertok(ut_check_console_end(uts));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
+ ut_assert_console_end();
/*
000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....|
000001c0 05 01 0e 25 24 01 00 40 00 00 00 08 00 00 00 00 |...%$..@........|
@@ -298,35 +303,34 @@ static int mbr_test_run(struct unit_test_state *uts)
000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
for (unsigned i = 0; i < mbr_cmp_size; i++) {
ut_assertf(rbuf[mbr_cmp_start + i] == mbr_parts_ref_p1[i],
- "1P MBR+0x%04X: expected 0x%02X, actual: 0x%02X\n",
+ "1P MBR+0x%04X: expected %#02X, actual: %#02X\n",
mbr_cmp_start + i, mbr_parts_ref_p1[i], rbuf[mbr_cmp_start + i]);
}
/* Test two MBR partitions */
init_write_buffers(mbr_wbuf, sizeof(mbr_wbuf), ebr_wbuf, sizeof(ebr_wbuf), __LINE__);
ut_assertok(build_mbr_parts(mbr_parts_buf, sizeof(mbr_parts_buf), 2));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0 1", mbr_wa));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
- ut_assertok(memcmp(mbr_wbuf, rbuf, 512));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0x%lx 1", ebr_wa, ebr_blk));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
- ut_assertok(console_record_reset_enable());
+ ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
+ ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ));
+ ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
ut_assertok(run_commandf("mbr write mmc 6"));
ut_assert_nextline("MBR: write success!");
ut_assertok(run_commandf("mbr verify mmc 6"));
ut_assert_nextline("MBR: verify success!");
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
- ut_assertok(ut_check_console_end(uts));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
+ ut_assert_console_end();
/*
000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....|
000001c0 05 01 0e 25 24 01 00 40 00 00 00 08 00 00 00 25 |...%$..@.......%|
@@ -334,35 +338,34 @@ static int mbr_test_run(struct unit_test_state *uts)
000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
for (unsigned i = 0; i < mbr_cmp_size; i++) {
ut_assertf(rbuf[mbr_cmp_start + i] == mbr_parts_ref_p2[i],
- "2P MBR+0x%04X: expected 0x%02X, actual: 0x%02X\n",
+ "2P MBR+0x%04X: expected %#02X, actual: %#02X\n",
mbr_cmp_start + i, mbr_parts_ref_p2[i], rbuf[mbr_cmp_start + i]);
}
/* Test three MBR partitions */
init_write_buffers(mbr_wbuf, sizeof(mbr_wbuf), ebr_wbuf, sizeof(ebr_wbuf), __LINE__);
ut_assertok(build_mbr_parts(mbr_parts_buf, sizeof(mbr_parts_buf), 3));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0 1", mbr_wa));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
- ut_assertok(memcmp(mbr_wbuf, rbuf, 512));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0x%lx 1", ebr_wa, ebr_blk));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
- ut_assertok(console_record_reset_enable());
+ ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
+ ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ));
+ ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
ut_assertok(run_commandf("mbr write mmc 6"));
ut_assert_nextline("MBR: write success!");
ut_assertok(run_commandf("mbr verify mmc 6"));
ut_assert_nextline("MBR: verify success!");
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
- ut_assertok(ut_check_console_end(uts));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
+ ut_assert_console_end();
/*
000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....|
000001c0 05 01 0e 25 24 01 00 40 00 00 00 08 00 00 00 25 |...%$..@.......%|
@@ -370,35 +373,34 @@ static int mbr_test_run(struct unit_test_state *uts)
000001e0 06 01 0e 66 25 01 00 50 00 00 00 08 00 00 00 00 |...f%..P........|
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
for (unsigned i = 0; i < mbr_cmp_size; i++) {
ut_assertf(rbuf[mbr_cmp_start + i] == mbr_parts_ref_p3[i],
- "3P MBR+0x%04X: expected 0x%02X, actual: 0x%02X\n",
+ "3P MBR+0x%04X: expected %#02X, actual: %#02X\n",
mbr_cmp_start + i, mbr_parts_ref_p3[i], rbuf[mbr_cmp_start + i]);
}
/* Test four MBR partitions */
init_write_buffers(mbr_wbuf, sizeof(mbr_wbuf), ebr_wbuf, sizeof(ebr_wbuf), __LINE__);
ut_assertok(build_mbr_parts(mbr_parts_buf, sizeof(mbr_parts_buf), 4));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0 1", mbr_wa));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
- ut_assertok(memcmp(mbr_wbuf, rbuf, 512));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0x%lx 1", ebr_wa, ebr_blk));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
- ut_assertok(console_record_reset_enable());
+ ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
+ ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ));
+ ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
ut_assertok(run_commandf("mbr write mmc 6"));
ut_assert_nextline("MBR: write success!");
ut_assertok(run_commandf("mbr verify mmc 6"));
ut_assert_nextline("MBR: verify success!");
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
- ut_assertok(ut_check_console_end(uts));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
+ ut_assert_console_end();
/*
000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....|
000001c0 05 01 0e 25 24 01 00 40 00 00 00 08 00 00 00 25 |...%$..@.......%|
@@ -406,32 +408,31 @@ static int mbr_test_run(struct unit_test_state *uts)
000001e0 06 01 0e 66 25 01 00 50 00 00 00 08 00 00 00 66 |...f%..P.......f|
000001f0 26 01 0e 87 06 01 00 58 00 00 00 08 00 00 55 aa |&......X......U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
for (unsigned i = 0; i < mbr_cmp_size; i++) {
ut_assertf(rbuf[mbr_cmp_start + i] == mbr_parts_ref_p4[i],
- "4P MBR+0x%04X: expected 0x%02X, actual: 0x%02X\n",
+ "4P MBR+0x%04X: expected %#02X, actual: %#02X\n",
mbr_cmp_start + i, mbr_parts_ref_p4[i], rbuf[mbr_cmp_start + i]);
}
/* Test five MBR partitions */
init_write_buffers(mbr_wbuf, sizeof(mbr_wbuf), ebr_wbuf, sizeof(ebr_wbuf), __LINE__);
ut_assertok(build_mbr_parts(mbr_parts_buf, sizeof(mbr_parts_buf), 5));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0 1", mbr_wa));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
- ut_assertok(memcmp(mbr_wbuf, rbuf, 512));
- ut_assertok(run_commandf("write mmc 6:0 0x%lx 0x%lx 1", ebr_wa, ebr_blk));
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
- ut_assertok(memcmp(ebr_wbuf, rbuf, 512));
- ut_assertok(console_record_reset_enable());
+ ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
+ ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ));
+ ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
+ ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
ut_assertf(0 == run_commandf("mbr write mmc 6"), "Invalid partitions string: %s\n", mbr_parts_buf);
ut_assert_nextline("MBR: write success!");
ut_assertok(run_commandf("mbr verify mmc 6"));
ut_assert_nextline("MBR: verify success!");
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/*
000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....|
000001c0 05 01 0e 25 24 01 00 40 00 00 00 08 00 00 00 25 |...%$..@.......%|
@@ -439,11 +440,11 @@ static int mbr_test_run(struct unit_test_state *uts)
000001e0 06 01 0e 66 25 01 00 50 00 00 00 08 00 00 00 66 |...f%..P.......f|
000001f0 26 01 05 a7 26 01 00 58 00 00 00 10 00 00 55 aa |&...&..X......U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0 1", ra));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
for (unsigned i = 0; i < mbr_cmp_size; i++) {
ut_assertf(rbuf[mbr_cmp_start + i] == mbr_parts_ref_p5[i],
- "5P MBR+0x%04X: expected 0x%02X, actual: 0x%02X\n",
+ "5P MBR+0x%04X: expected %#02X, actual: %#02X\n",
mbr_cmp_start + i, mbr_parts_ref_p5[i], rbuf[mbr_cmp_start + i]);
}
/*
@@ -453,31 +454,19 @@ static int mbr_test_run(struct unit_test_state *uts)
00b001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00b001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
- ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk));
+ memset(rbuf, '\0', BLKSZ);
+ ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
for (unsigned i = 0; i < ebr_cmp_size; i++) {
ut_assertf(rbuf[ebr_cmp_start + i] == ebr_parts_ref_p5[i],
- "5P EBR+0x%04X: expected 0x%02X, actual: 0x%02X\n",
+ "5P EBR+0x%04X: expected %#02X, actual: %#02X\n",
ebr_cmp_start + i, ebr_parts_ref_p5[i], rbuf[ebr_cmp_start + i]);
}
+ unmap_sysmem(mbr_wbuf);
+ unmap_sysmem(ebr_wbuf);
+ unmap_sysmem(rbuf);
return 0;
}
/* Declare mbr test */
-UNIT_TEST(mbr_test_run, UT_TESTF_CONSOLE_REC, mbr_test);
-
-int do_ut_mbr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(mbr_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(mbr_test);
-
- return cmd_ut_category("mbr", "mbr_test_", tests, n_ents, argc, argv);
-}
-
-static int dm_test_cmd_mbr(struct unit_test_state *uts)
-{
- return mbr_test_run(uts);
-}
-
-DM_TEST(dm_test_cmd_mbr, UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
+UNIT_TEST(mbr_test_run, UTF_CONSOLE, mbr);
diff --git a/test/cmd/mem.c b/test/cmd/mem.c
deleted file mode 100644
index d76f47cf311..00000000000
--- a/test/cmd/mem.c
+++ /dev/null
@@ -1,20 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Executes tests for memory-related commands
- *
- * Copyright 2020 Google LLC
- */
-
-#include <common.h>
-#include <command.h>
-#include <test/suites.h>
-#include <test/test.h>
-
-int do_ut_mem(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(mem_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(mem_test);
-
- return cmd_ut_category("cmd_mem", "mem_test_", tests, n_ents, argc,
- argv);
-}
diff --git a/test/cmd/mem_copy.c b/test/cmd/mem_copy.c
index 1ba0cebbbe0..3e904fc4e4b 100644
--- a/test/cmd/mem_copy.c
+++ b/test/cmd/mem_copy.c
@@ -12,7 +12,7 @@
#define BUF_SIZE 256
/* Declare a new mem test */
-#define MEM_TEST(_name) UNIT_TEST(_name, 0, mem_test)
+#define MEM_TEST(_name) UNIT_TEST(_name, 0, mem)
struct param {
int d, s, count;
@@ -21,7 +21,7 @@ struct param {
static int do_test(struct unit_test_state *uts,
const char *suffix, int d, int s, int count)
{
- const long addr = 0x1000;
+ const long addr = CONFIG_SYS_LOAD_ADDR + 0x1000;
u8 shadow[BUF_SIZE];
u8 *buf;
int i, w, bytes;
diff --git a/test/cmd/mem_search.c b/test/cmd/mem_search.c
index f80c9c40687..df8938bdb6c 100644
--- a/test/cmd/mem_search.c
+++ b/test/cmd/mem_search.c
@@ -6,7 +6,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <console.h>
#include <mapmem.h>
#include <dm/test.h>
@@ -15,7 +14,7 @@
#define BUF_SIZE 0x100
/* Declare a new mem test */
-#define MEM_TEST(_name, _flags) UNIT_TEST(_name, _flags, mem_test)
+#define MEM_TEST(_name, _flags) UNIT_TEST(_name, _flags, mem)
/* Test 'ms' command with bytes */
static int mem_test_ms_b(struct unit_test_state *uts)
@@ -28,7 +27,6 @@ static int mem_test_ms_b(struct unit_test_state *uts)
buf[0x31] = 0x12;
buf[0xff] = 0x12;
buf[0x100] = 0x12;
- ut_assertok(console_record_reset_enable());
run_command("ms.b 1 ff 12", 0);
ut_assert_nextline("00000030: 00 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................");
ut_assert_nextline("--");
@@ -44,7 +42,7 @@ static int mem_test_ms_b(struct unit_test_state *uts)
return 0;
}
-MEM_TEST(mem_test_ms_b, UT_TESTF_CONSOLE_REC);
+MEM_TEST(mem_test_ms_b, UTF_CONSOLE);
/* Test 'ms' command with 16-bit values */
static int mem_test_ms_w(struct unit_test_state *uts)
@@ -55,7 +53,6 @@ static int mem_test_ms_w(struct unit_test_state *uts)
memset(buf, '\0', BUF_SIZE);
buf[0x34 / 2] = 0x1234;
buf[BUF_SIZE / 2] = 0x1234;
- ut_assertok(console_record_reset_enable());
run_command("ms.w 0 80 1234", 0);
ut_assert_nextline("00000030: 0000 0000 1234 0000 0000 0000 0000 0000 ....4...........");
ut_assert_nextline("1 match");
@@ -69,7 +66,7 @@ static int mem_test_ms_w(struct unit_test_state *uts)
return 0;
}
-MEM_TEST(mem_test_ms_w, UT_TESTF_CONSOLE_REC);
+MEM_TEST(mem_test_ms_w, UTF_CONSOLE);
/* Test 'ms' command with 32-bit values */
static int mem_test_ms_l(struct unit_test_state *uts)
@@ -80,7 +77,6 @@ static int mem_test_ms_l(struct unit_test_state *uts)
memset(buf, '\0', BUF_SIZE);
buf[0x38 / 4] = 0x12345678;
buf[BUF_SIZE / 4] = 0x12345678;
- ut_assertok(console_record_reset_enable());
run_command("ms 0 40 12345678", 0);
ut_assert_nextline("00000030: 00000000 00000000 12345678 00000000 ........xV4.....");
ut_assert_nextline("1 match");
@@ -90,7 +86,6 @@ static int mem_test_ms_l(struct unit_test_state *uts)
ut_asserteq(0x38, env_get_hex("memaddr", 0));
ut_asserteq(0x38 / 4, env_get_hex("mempos", 0));
- ut_assertok(console_record_reset_enable());
run_command("ms 0 80 12345679", 0);
ut_assert_nextline("0 matches");
ut_assert_console_end();
@@ -103,7 +98,7 @@ static int mem_test_ms_l(struct unit_test_state *uts)
return 0;
}
-MEM_TEST(mem_test_ms_l, UT_TESTF_CONSOLE_REC);
+MEM_TEST(mem_test_ms_l, UTF_CONSOLE);
/* Test 'ms' command with continuation */
static int mem_test_ms_cont(struct unit_test_state *uts)
@@ -117,7 +112,6 @@ static int mem_test_ms_cont(struct unit_test_state *uts)
memset(buf, '\0', BUF_SIZE);
for (i = 5; i < 0x33; i += 3)
buf[i] = 0x34;
- ut_assertok(console_record_reset_enable());
run_command("ms.b 0 100 34", 0);
ut_assert_nextlinen("00000000: 00 00 00 00 00 34 00 00 34 00 00 34 00 00 34 00");
ut_assert_nextline("--");
@@ -135,7 +129,6 @@ static int mem_test_ms_cont(struct unit_test_state *uts)
* run_command() ignoes the repeatable flag when using hush, so call
* cmd_process() directly
*/
- ut_assertok(console_record_reset_enable());
cmd_process(CMD_FLAG_REPEAT, 4, args, &repeatable, NULL);
ut_assert_nextlinen("00000020: 34 00 00 34 00 00 34 00 00 34 00 00 34 00 00 34");
ut_assert_nextline("--");
@@ -153,7 +146,7 @@ static int mem_test_ms_cont(struct unit_test_state *uts)
return 0;
}
-MEM_TEST(mem_test_ms_cont, UT_TESTF_CONSOLE_REC);
+MEM_TEST(mem_test_ms_cont, UTF_CONSOLE);
/* Test that an 'ms' command with continuation stops at the end of the range */
static int mem_test_ms_cont_end(struct unit_test_state *uts)
@@ -168,7 +161,6 @@ static int mem_test_ms_cont_end(struct unit_test_state *uts)
buf[0x31] = 0x12;
buf[0xff] = 0x12;
buf[0x100] = 0x12;
- ut_assertok(console_record_reset_enable());
run_command("ms.b 1 ff 12", 0);
ut_assert_nextlinen("00000030");
ut_assert_nextlinen("--");
@@ -182,13 +174,11 @@ static int mem_test_ms_cont_end(struct unit_test_state *uts)
*
* This should produce no matches.
*/
- ut_assertok(console_record_reset_enable());
cmd_process(CMD_FLAG_REPEAT, 4, args, &repeatable, NULL);
ut_assert_nextlinen("0 matches");
ut_assert_console_end();
/* One more time */
- ut_assertok(console_record_reset_enable());
cmd_process(CMD_FLAG_REPEAT, 4, args, &repeatable, NULL);
ut_assert_nextlinen("0 matches");
ut_assert_console_end();
@@ -197,7 +187,7 @@ static int mem_test_ms_cont_end(struct unit_test_state *uts)
return 0;
}
-MEM_TEST(mem_test_ms_cont_end, UT_TESTF_CONSOLE_REC);
+MEM_TEST(mem_test_ms_cont_end, UTF_CONSOLE);
/* Test 'ms' command with multiple values */
static int mem_test_ms_mult(struct unit_test_state *uts)
@@ -226,7 +216,7 @@ static int mem_test_ms_mult(struct unit_test_state *uts)
return 0;
}
-MEM_TEST(mem_test_ms_mult, UT_TESTF_CONSOLE_REC);
+MEM_TEST(mem_test_ms_mult, UTF_CONSOLE);
/* Test 'ms' command with string */
static int mem_test_ms_s(struct unit_test_state *uts)
@@ -240,7 +230,6 @@ static int mem_test_ms_s(struct unit_test_state *uts)
strcpy(buf + 0x1e, str);
strcpy(buf + 0x63, str);
strcpy(buf + 0xa1, str2);
- ut_assertok(console_record_reset_enable());
run_command("ms.s 0 100 hello", 0);
ut_assert_nextline("00000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 68 65 ..............he");
ut_assert_nextline("00000020: 6c 6c 6f 00 00 00 00 00 00 00 00 00 00 00 00 00 llo.............");
@@ -255,7 +244,6 @@ static int mem_test_ms_s(struct unit_test_state *uts)
ut_asserteq(0xa1, env_get_hex("memaddr", 0));
ut_asserteq(0xa1, env_get_hex("mempos", 0));
- ut_assertok(console_record_reset_enable());
run_command("ms.s 0 100 hello there", 0);
ut_assert_nextline("000000a0: 00 68 65 6c 6c 6f 74 68 65 72 65 00 00 00 00 00 .hellothere.....");
ut_assert_nextline("1 match");
@@ -269,7 +257,7 @@ static int mem_test_ms_s(struct unit_test_state *uts)
return 0;
}
-MEM_TEST(mem_test_ms_s, UT_TESTF_CONSOLE_REC);
+MEM_TEST(mem_test_ms_s, UTF_CONSOLE);
/* Test 'ms' command with limit */
static int mem_test_ms_limit(struct unit_test_state *uts)
@@ -282,7 +270,6 @@ static int mem_test_ms_limit(struct unit_test_state *uts)
buf[0x31] = 0x12;
buf[0x62] = 0x12;
buf[0x76] = 0x12;
- ut_assertok(console_record_reset_enable());
run_command("ms.b -l2 1 ff 12", 0);
ut_assert_nextline("00000030: 00 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................");
ut_assert_nextline("--");
@@ -298,7 +285,7 @@ static int mem_test_ms_limit(struct unit_test_state *uts)
return 0;
}
-MEM_TEST(mem_test_ms_limit, UT_TESTF_CONSOLE_REC);
+MEM_TEST(mem_test_ms_limit, UTF_CONSOLE);
/* Test 'ms' command in quiet mode */
static int mem_test_ms_quiet(struct unit_test_state *uts)
@@ -311,7 +298,6 @@ static int mem_test_ms_quiet(struct unit_test_state *uts)
buf[0x31] = 0x12;
buf[0x62] = 0x12;
buf[0x76] = 0x12;
- ut_assertok(console_record_reset_enable());
run_command("ms.b -q -l2 1 ff 12", 0);
ut_assert_console_end();
unmap_sysmem(buf);
@@ -322,4 +308,4 @@ static int mem_test_ms_quiet(struct unit_test_state *uts)
return 0;
}
-MEM_TEST(mem_test_ms_quiet, UT_TESTF_CONSOLE_REC);
+MEM_TEST(mem_test_ms_quiet, UTF_CONSOLE);
diff --git a/test/cmd/meminfo.c b/test/cmd/meminfo.c
new file mode 100644
index 00000000000..53b41e3b49e
--- /dev/null
+++ b/test/cmd/meminfo.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test for 'meminfo' command
+ *
+ * Copyright 2024 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <dm/test.h>
+#include <test/cmd.h>
+#include <test/ut.h>
+
+/* Test 'meminfo' command */
+static int cmd_test_meminfo(struct unit_test_state *uts)
+{
+ ut_assertok(run_command("meminfo", 0));
+ ut_assert_nextline("DRAM: 256 MiB");
+ ut_assert_nextline_empty();
+
+ ut_assert_nextline("Region Base Size End Gap");
+ ut_assert_nextlinen("-");
+
+ /* For now we don't worry about checking the values */
+ ut_assert_nextlinen("video");
+ ut_assert_nextlinen("code");
+ ut_assert_nextlinen("malloc");
+ ut_assert_nextlinen("board_info");
+ ut_assert_nextlinen("global_data");
+ ut_assert_nextlinen("devicetree");
+ ut_assert_nextlinen("bootstage");
+ ut_assert_nextlinen("bloblist");
+ ut_assert_nextlinen("stack");
+
+ /* we expect at least one lmb line, but don't know how many */
+ ut_assert_nextlinen("lmb");
+ ut_assert_skip_to_linen("free");
+
+ ut_assert_console_end();
+
+ return 0;
+}
+CMD_TEST(cmd_test_meminfo, UTF_CONSOLE);
diff --git a/test/cmd/msr.c b/test/cmd/msr.c
new file mode 100644
index 00000000000..e9a152ee5bf
--- /dev/null
+++ b/test/cmd/msr.c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for msr command
+ *
+ * Copyright 2024 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <test/cmd.h>
+#include <test/ut.h>
+
+static int cmd_test_msr(struct unit_test_state *uts)
+{
+ ut_assertok(run_commandf("msr read 200"));
+ ut_assert_nextline("00000000 ffe00006");
+ ut_assert_console_end();
+
+ /* change the first variable msr and see it reflected in the mtrr cmd */
+ ut_assertok(run_commandf("mtrr"));
+ ut_assert_nextline("CPU 65537:");
+ ut_assert_nextlinen("Reg");
+ ut_assert_nextlinen("0 Y Back 00000000ffe00000");
+ ut_assertok(console_record_reset_enable());
+
+ /* change the type from 6 to 5 */
+ ut_assertok(run_commandf("msr write 200 0 ffe00005"));
+ ut_assert_console_end();
+
+ /* Now it shows 'Protect' */
+ ut_assertok(run_commandf("mtrr"));
+ ut_assert_nextline("CPU 65537:");
+ ut_assert_nextlinen("Reg");
+ ut_assert_nextlinen("0 Y Protect 00000000ffe00000");
+ ut_assertok(console_record_reset_enable());
+
+ return 0;
+}
+CMD_TEST(cmd_test_msr, UTF_CONSOLE);
diff --git a/test/cmd/pci_mps.c b/test/cmd/pci_mps.c
index fd96f4fba6c..6618c247d13 100644
--- a/test/cmd/pci_mps.c
+++ b/test/cmd/pci_mps.c
@@ -7,12 +7,10 @@
* Written by Stephen Carlson <stcarlso@linux.microsoft.com>
*/
-#include <common.h>
#include <console.h>
-#include <test/suites.h>
#include <test/ut.h>
-#define PCI_MPS_TEST(_name, _flags) UNIT_TEST(_name, _flags, pci_mps_test)
+#define PCI_MPS_TEST(_name, _flags) UNIT_TEST(_name, _flags, pci_mps)
/* Test "pci_mps" command in safe "s" mode */
static int test_pci_mps_safe(struct unit_test_state *uts)
@@ -28,15 +26,4 @@ static int test_pci_mps_safe(struct unit_test_state *uts)
return 0;
}
-
-PCI_MPS_TEST(test_pci_mps_safe, UT_TESTF_CONSOLE_REC);
-
-int do_ut_pci_mps(struct cmd_tbl *cmdtp, int flag, int argc,
- char * const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(pci_mps_test);
- const int n = UNIT_TEST_SUITE_COUNT(pci_mps_test);
-
- return cmd_ut_category("cmd_pci_mps", "pci_mps_test_", tests, n,
- argc, argv);
-}
+PCI_MPS_TEST(test_pci_mps_safe, UTF_CONSOLE);
diff --git a/test/cmd/pinmux.c b/test/cmd/pinmux.c
index df40bb77435..65974d03f88 100644
--- a/test/cmd/pinmux.c
+++ b/test/cmd/pinmux.c
@@ -5,7 +5,6 @@
* Copyright (C) 2021, STMicroelectronics - All Rights Reserved
*/
-#include <common.h>
#include <command.h>
#include <dm.h>
#include <dm/test.h>
@@ -19,23 +18,26 @@ static int dm_test_cmd_pinmux_status_pinname(struct unit_test_state *uts)
ut_assertok(uclass_get_device(UCLASS_LED, 2, &dev));
/* Test that 'pinmux status <pinname>' displays the selected pin. */
- console_record_reset();
run_command("pinmux status a5", 0);
ut_assert_nextlinen("a5 : gpio output .");
ut_assert_console_end();
- console_record_reset();
run_command("pinmux status P7", 0);
ut_assert_nextlinen("P7 : GPIO2 bias-pull-down input-enable.");
ut_assert_console_end();
- console_record_reset();
run_command("pinmux status P9", 0);
- ut_assert_nextlinen("single-pinctrl pinctrl-single-no-width: missing register width");
+ if (IS_ENABLED(CONFIG_LOGF_FUNC)) {
+ ut_assert_nextlinen(
+ " single_of_to_plat() single-pinctrl pinctrl-single-no-width: missing register width");
+ } else {
+ ut_assert_nextlinen(
+ "single-pinctrl pinctrl-single-no-width: missing register width");
+ }
ut_assert_nextlinen("P9 not found");
ut_assert_console_end();
return 0;
}
-
-DM_TEST(dm_test_cmd_pinmux_status_pinname, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_cmd_pinmux_status_pinname, UTF_SCAN_PDATA | UTF_SCAN_FDT |
+ UTF_CONSOLE);
diff --git a/test/cmd/pwm.c b/test/cmd/pwm.c
index cf7ee0e0e65..0d47e2d8abb 100644
--- a/test/cmd/pwm.c
+++ b/test/cmd/pwm.c
@@ -22,8 +22,6 @@ static int dm_test_pwm_cmd(struct unit_test_state *uts)
ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev));
ut_assertnonnull(dev);
- ut_assertok(console_record_reset_enable());
-
/* pwm <invert> <pwm_dev_num> <channel> <polarity> */
/* cros-ec-pwm doesn't support invert */
ut_asserteq(1, run_command("pwm invert 0 0 1", 0));
@@ -49,8 +47,6 @@ static int dm_test_pwm_cmd(struct unit_test_state *uts)
ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev));
ut_assertnonnull(dev);
- ut_assertok(console_record_reset_enable());
-
/* pwm <invert> <pwm_dev_num> <channel> <polarity> */
ut_assertok(run_command("pwm invert 1 0 1", 0));
ut_assert_console_end();
@@ -71,5 +67,4 @@ static int dm_test_pwm_cmd(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_pwm_cmd, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
+DM_TEST(dm_test_pwm_cmd, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE);
diff --git a/test/cmd/rw.c b/test/cmd/rw.c
index 98302bf047b..0a856c44ede 100644
--- a/test/cmd/rw.c
+++ b/test/cmd/rw.c
@@ -3,7 +3,6 @@
* Tests for read and write commands
*/
-#include <common.h>
#include <dm/test.h>
#include <mapmem.h>
#include <part.h>
@@ -88,17 +87,14 @@ static int dm_test_read_write(struct unit_test_state *uts)
ut_assertok(memcmp(wbuf, rbuf, sizeof(wbuf)));
/* Read/write outside partition bounds should be rejected upfront. */
- console_record_reset_enable();
ut_asserteq(1, run_commandf("read mmc 2#data 0x%lx 3 2", ra));
ut_assert_nextlinen("read out of range");
ut_assert_console_end();
- console_record_reset_enable();
ut_asserteq(1, run_commandf("write mmc 2#log 0x%lx 9 2", wa));
ut_assert_nextlinen("write out of range");
ut_assert_console_end();
return 0;
}
-
-DM_TEST(dm_test_read_write, UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
+DM_TEST(dm_test_read_write, UTF_SCAN_FDT | UTF_CONSOLE);
diff --git a/test/cmd/seama.c b/test/cmd/seama.c
index b1b56930c64..39f85f1c502 100644
--- a/test/cmd/seama.c
+++ b/test/cmd/seama.c
@@ -5,19 +5,16 @@
* Copyright (C) 2021 Linus Walleij <linus.walleij@linaro.org>
*/
-#include <common.h>
#include <command.h>
#include <dm.h>
-#include <test/suites.h>
#include <test/test.h>
#include <test/ut.h>
-#define SEAMA_TEST(_name, _flags) UNIT_TEST(_name, _flags, seama_test)
+#define SEAMA_TEST(_name, _flags) UNIT_TEST(_name, _flags, seama)
static int seama_test_noargs(struct unit_test_state *uts)
{
/* Test that 'seama' with no arguments fails gracefully */
- console_record_reset();
run_command("seama", 0);
ut_assert_nextlinen("seama - Load the SEAMA image and sets envs");
ut_assert_skipline();
@@ -27,12 +24,11 @@ static int seama_test_noargs(struct unit_test_state *uts)
ut_assert_console_end();
return 0;
}
-SEAMA_TEST(seama_test_noargs, UT_TESTF_CONSOLE_REC);
+SEAMA_TEST(seama_test_noargs, UTF_CONSOLE);
static int seama_test_addr(struct unit_test_state *uts)
{
/* Test that loads SEAMA image 0 to address 0x01000000 */
- console_record_reset();
run_command("seama 0x01000000", 0);
ut_assert_nextlinen("Loading SEAMA image 0 from nand0");
ut_assert_nextlinen("SEMA IMAGE:");
@@ -43,12 +39,11 @@ static int seama_test_addr(struct unit_test_state *uts)
ut_assert_console_end();
return 0;
}
-SEAMA_TEST(seama_test_addr, UT_TESTF_CONSOLE_REC);
+SEAMA_TEST(seama_test_addr, UTF_CONSOLE);
static int seama_test_index(struct unit_test_state *uts)
{
/* Test that loads SEAMA image 0 exlicitly specified */
- console_record_reset();
run_command("seama 0x01000000 0", 0);
ut_assert_nextlinen("Loading SEAMA image 0 from nand0");
ut_assert_nextlinen("SEMA IMAGE:");
@@ -59,13 +54,4 @@ static int seama_test_index(struct unit_test_state *uts)
ut_assert_console_end();
return 0;
}
-SEAMA_TEST(seama_test_index, UT_TESTF_CONSOLE_REC);
-
-int do_ut_seama(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(seama_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(seama_test);
-
- return cmd_ut_category("seama", "seama_test_", tests, n_ents, argc,
- argv);
-}
+SEAMA_TEST(seama_test_index, UTF_CONSOLE);
diff --git a/test/cmd/setexpr.c b/test/cmd/setexpr.c
index ee329e94b85..85803eb54b8 100644
--- a/test/cmd/setexpr.c
+++ b/test/cmd/setexpr.c
@@ -6,17 +6,15 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <console.h>
#include <mapmem.h>
#include <dm/test.h>
-#include <test/suites.h>
#include <test/ut.h>
#define BUF_SIZE 0x100
/* Declare a new setexpr test */
-#define SETEXPR_TEST(_name, _flags) UNIT_TEST(_name, _flags, setexpr_test)
+#define SETEXPR_TEST(_name, _flags) UNIT_TEST(_name, _flags, setexpr)
/* Test 'setexpr' command with simply setting integers */
static int setexpr_test_int(struct unit_test_state *uts)
@@ -64,7 +62,7 @@ static int setexpr_test_int(struct unit_test_state *uts)
return 0;
}
-SETEXPR_TEST(setexpr_test_int, UT_TESTF_CONSOLE_REC);
+SETEXPR_TEST(setexpr_test_int, UTF_CONSOLE);
/* Test 'setexpr' command with + operator */
static int setexpr_test_plus(struct unit_test_state *uts)
@@ -106,7 +104,7 @@ static int setexpr_test_plus(struct unit_test_state *uts)
return 0;
}
-SETEXPR_TEST(setexpr_test_plus, UT_TESTF_CONSOLE_REC);
+SETEXPR_TEST(setexpr_test_plus, UTF_CONSOLE);
/* Test 'setexpr' command with other operators */
static int setexpr_test_oper(struct unit_test_state *uts)
@@ -149,7 +147,7 @@ static int setexpr_test_oper(struct unit_test_state *uts)
return 0;
}
-SETEXPR_TEST(setexpr_test_oper, UT_TESTF_CONSOLE_REC);
+SETEXPR_TEST(setexpr_test_oper, UTF_CONSOLE);
/* Test 'setexpr' command with regex */
static int setexpr_test_regex(struct unit_test_state *uts)
@@ -193,7 +191,7 @@ static int setexpr_test_regex(struct unit_test_state *uts)
return 0;
}
-SETEXPR_TEST(setexpr_test_regex, UT_TESTF_CONSOLE_REC);
+SETEXPR_TEST(setexpr_test_regex, UTF_CONSOLE);
/* Test 'setexpr' command with regex replacement that expands the string */
static int setexpr_test_regex_inc(struct unit_test_state *uts)
@@ -210,7 +208,7 @@ static int setexpr_test_regex_inc(struct unit_test_state *uts)
return 0;
}
-SETEXPR_TEST(setexpr_test_regex_inc, UT_TESTF_CONSOLE_REC);
+SETEXPR_TEST(setexpr_test_regex_inc, UTF_CONSOLE);
/* Test setexpr_regex_sub() directly to check buffer usage */
static int setexpr_test_sub(struct unit_test_state *uts)
@@ -250,7 +248,7 @@ static int setexpr_test_sub(struct unit_test_state *uts)
return 0;
}
-SETEXPR_TEST(setexpr_test_sub, UT_TESTF_CONSOLE_REC);
+SETEXPR_TEST(setexpr_test_sub, UTF_CONSOLE);
/* Test setexpr_regex_sub() with back references */
static int setexpr_test_backref(struct unit_test_state *uts)
@@ -293,92 +291,58 @@ static int setexpr_test_backref(struct unit_test_state *uts)
return 0;
}
-SETEXPR_TEST(setexpr_test_backref, UT_TESTF_CONSOLE_REC);
+SETEXPR_TEST(setexpr_test_backref, UTF_CONSOLE);
/* Test 'setexpr' command with setting strings */
static int setexpr_test_str(struct unit_test_state *uts)
{
- ulong start_mem;
char *buf;
buf = map_sysmem(0, BUF_SIZE);
memset(buf, '\xff', BUF_SIZE);
- /*
- * Set 'fred' to the same length as we expect to get below, to avoid a
- * new allocation in 'setexpr'. That way we can check for memory leaks.
- */
ut_assertok(env_set("fred", "x"));
- start_mem = ut_check_free();
- strcpy(buf, "hello");
- ut_asserteq(1, run_command("setexpr.s fred 0", 0));
- ut_assertok(ut_check_delta(start_mem));
+ ut_asserteq(0, run_command("setexpr.s fred 0", 0));
+ ut_asserteq_str("0", env_get("fred"));
+ strcpy(buf, "hello");
ut_assertok(env_set("fred", "12345"));
- start_mem = ut_check_free();
ut_assertok(run_command("setexpr.s fred *0", 0));
ut_asserteq_str("hello", env_get("fred"));
- /*
- * This fails in CI at present.
- *
- * ut_assertok(ut_check_delta(start_mem));
- */
unmap_sysmem(buf);
return 0;
}
-SETEXPR_TEST(setexpr_test_str, UT_TESTF_CONSOLE_REC);
-
+SETEXPR_TEST(setexpr_test_str, UTF_CONSOLE);
/* Test 'setexpr' command with concatenating strings */
static int setexpr_test_str_oper(struct unit_test_state *uts)
{
- ulong start_mem;
char *buf;
+ /* Test concatenation of strings */
+ ut_assertok(run_command("setexpr.s fred '1' + '3'", 0));
+ ut_asserteq_str("13", env_get("fred"));
+
buf = map_sysmem(0, BUF_SIZE);
memset(buf, '\xff', BUF_SIZE);
strcpy(buf, "hello");
strcpy(buf + 0x10, " there");
- ut_assertok(console_record_reset_enable());
- start_mem = ut_check_free();
ut_asserteq(1, run_command("setexpr.s fred *0 * *10", 0));
- ut_assertok(ut_check_delta(start_mem));
ut_assert_nextline("invalid op");
ut_assert_console_end();
- /*
- * Set 'fred' to the same length as we expect to get below, to avoid a
- * new allocation in 'setexpr'. That way we can check for memory leaks.
- */
ut_assertok(env_set("fred", "12345012345"));
- start_mem = ut_check_free();
ut_assertok(run_command("setexpr.s fred *0 + *10", 0));
ut_asserteq_str("hello there", env_get("fred"));
- /*
- * This check does not work with sandbox_flattree, apparently due to
- * memory allocations in env_set().
- *
- * The truetype console produces lots of memory allocations even though
- * the LCD display is not visible. But even without these, it does not
- * work.
- *
- * A better test would be for dlmalloc to record the allocs and frees
- * for a particular caller, but that is not supported.
- *
- * For now, drop this test.
- *
- * ut_assertok(ut_check_delta(start_mem));
- */
-
unmap_sysmem(buf);
return 0;
}
-SETEXPR_TEST(setexpr_test_str_oper, UT_TESTF_CONSOLE_REC);
+SETEXPR_TEST(setexpr_test_str_oper, UTF_CONSOLE);
/* Test 'setexpr' command with a string that is too long */
static int setexpr_test_str_long(struct unit_test_state *uts)
@@ -398,7 +362,7 @@ static int setexpr_test_str_long(struct unit_test_state *uts)
return 0;
}
-SETEXPR_TEST(setexpr_test_str_long, UT_TESTF_CONSOLE_REC);
+SETEXPR_TEST(setexpr_test_str_long, UTF_CONSOLE);
#ifdef CONFIG_CMD_SETEXPR_FMT
/* Test 'setexpr' command with simply setting integers */
@@ -480,15 +444,5 @@ static int setexpr_test_fmt(struct unit_test_state *uts)
return 0;
}
-
-SETEXPR_TEST(setexpr_test_fmt, UT_TESTF_CONSOLE_REC);
+SETEXPR_TEST(setexpr_test_fmt, UTF_CONSOLE);
#endif
-
-int do_ut_setexpr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(setexpr_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(setexpr_test);
-
- return cmd_ut_category("cmd_setexpr", "setexpr_test_", tests, n_ents,
- argc, argv);
-}
diff --git a/test/cmd/spawn.c b/test/cmd/spawn.c
new file mode 100644
index 00000000000..8f48f5ee25c
--- /dev/null
+++ b/test/cmd/spawn.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Tests for spawn and wait commands
+ *
+ * Copyright 2025, Linaro Ltd.
+ */
+
+#include <command.h>
+#include <test/cmd.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+static int test_cmd_spawn(struct unit_test_state *uts)
+{
+ ut_assertok(run_command("wait; spawn sleep 2; setenv j ${job_id}; "
+ "spawn setenv spawned true; "
+ "setenv jj ${job_id}; wait; "
+ "echo ${j} ${jj} ${spawned}", 0));
+ console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+ ut_asserteq_ptr(uts->actual_str,
+ strstr(uts->actual_str, "1 2 true"));
+
+ ut_assertok(run_command("spawn true; wait; setenv t $?; spawn false; "
+ "wait; setenv f $?; wait; echo $t $f $?", 0));
+ console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+ ut_asserteq_ptr(uts->actual_str,
+ strstr(uts->actual_str, "0 1 0"));
+ ut_assert_console_end();
+
+ return 0;
+}
+CMD_TEST(test_cmd_spawn, UTF_CONSOLE);
diff --git a/test/cmd/temperature.c b/test/cmd/temperature.c
index 2a1ea0611dc..309693aa1e8 100644
--- a/test/cmd/temperature.c
+++ b/test/cmd/temperature.c
@@ -5,7 +5,6 @@
* Copyright (C) 2022 Sartura Ltd.
*/
-#include <common.h>
#include <command.h>
#include <dm.h>
#include <dm/test.h>
@@ -19,8 +18,6 @@ static int dm_test_cmd_temperature(struct unit_test_state *uts)
ut_assertok(uclass_get_device(UCLASS_THERMAL, 0, &dev));
ut_assertnonnull(dev);
- ut_assertok(console_record_reset_enable());
-
/* Test that "temperature list" shows the sandbox device */
ut_assertok(run_command("temperature list", 0));
ut_assert_nextline("| Device | Driver | Parent");
@@ -35,5 +32,4 @@ static int dm_test_cmd_temperature(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_cmd_temperature, UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
+DM_TEST(dm_test_cmd_temperature, UTF_SCAN_FDT | UTF_CONSOLE);
diff --git a/test/cmd/test_echo.c b/test/cmd/test_echo.c
index 091e4f823c9..8b306cc907f 100644
--- a/test/cmd/test_echo.c
+++ b/test/cmd/test_echo.c
@@ -5,7 +5,6 @@
* Copyright 2020, Heinrich Schuchadt <xypron.glpk@gmx.de>
*/
-#include <common.h>
#include <command.h>
#include <asm/global_data.h>
#include <display_options.h>
@@ -46,16 +45,12 @@ static int lib_test_hush_echo(struct unit_test_state *uts)
int i;
for (i = 0; i < ARRAY_SIZE(echo_data); ++i) {
- ut_silence_console(uts);
- console_record_reset_enable();
ut_assertok(run_command(echo_data[i].cmd, 0));
- ut_unsilence_console(uts);
console_record_readline(uts->actual_str,
sizeof(uts->actual_str));
ut_asserteq_str(echo_data[i].expected, uts->actual_str);
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
}
return 0;
}
-
-LIB_TEST(lib_test_hush_echo, 0);
+LIB_TEST(lib_test_hush_echo, UTF_CONSOLE);
diff --git a/test/cmd/test_pause.c b/test/cmd/test_pause.c
index 2b85cce3271..174c31a3852 100644
--- a/test/cmd/test_pause.c
+++ b/test/cmd/test_pause.c
@@ -5,7 +5,6 @@
* Copyright 2022, Samuel Dionne-Riel <samuel@dionne-riel.com>
*/
-#include <common.h>
#include <asm/global_data.h>
#include <test/lib.h>
#include <test/ut.h>
@@ -15,25 +14,22 @@ DECLARE_GLOBAL_DATA_PTR;
static int lib_test_hush_pause(struct unit_test_state *uts)
{
/* Test default message */
- console_record_reset_enable();
/* Cook a newline when the command is expected to pause */
console_in_puts("\n");
ut_assertok(run_command("pause", 0));
console_record_readline(uts->actual_str, sizeof(uts->actual_str));
ut_asserteq_str("Press any key to continue...", uts->actual_str);
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test provided message */
- console_record_reset_enable();
/* Cook a newline when the command is expected to pause */
console_in_puts("\n");
ut_assertok(run_command("pause 'Prompt for pause...'", 0));
console_record_readline(uts->actual_str, sizeof(uts->actual_str));
ut_asserteq_str("Prompt for pause...", uts->actual_str);
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Test providing more than one params */
- console_record_reset_enable();
/* No newline cooked here since the command is expected to fail */
ut_asserteq(1, run_command("pause a b", 0));
console_record_readline(uts->actual_str, sizeof(uts->actual_str));
@@ -42,4 +38,4 @@ static int lib_test_hush_pause(struct unit_test_state *uts)
return 0;
}
-LIB_TEST(lib_test_hush_pause, 0);
+LIB_TEST(lib_test_hush_pause, UTF_CONSOLE);
diff --git a/test/cmd/wget.c b/test/cmd/wget.c
index ed83fc94a5e..445750660c2 100644
--- a/test/cmd/wget.c
+++ b/test/cmd/wget.c
@@ -6,7 +6,6 @@
* Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
*/
-#include <common.h>
#include <command.h>
#include <dm.h>
#include <env.h>
@@ -20,12 +19,13 @@
#include <dm/test.h>
#include <dm/device-internal.h>
#include <dm/uclass-internal.h>
-#include <test/lib.h>
+#include <test/cmd.h>
#include <test/test.h>
#include <test/ut.h>
#define SHIFT_TO_TCPHDRLEN_FIELD(x) ((x) << 4)
#define LEN_B_TO_DW(x) ((x) >> 2)
+#define GET_TCP_HDR_LEN_IN_BYTES(x) ((x) >> 2)
static int sb_arp_handler(struct udevice *dev, void *packet,
unsigned int len)
@@ -63,12 +63,14 @@ static int sb_syn_handler(struct udevice *dev, void *packet,
eth_send = (void *)priv->recv_packet_buffer[priv->recv_packets];
memcpy(eth_send->et_dest, eth->et_src, ARP_HLEN);
memcpy(eth_send->et_src, priv->fake_host_hwaddr, ARP_HLEN);
+ priv->irs = ntohl(tcp->tcp_seq);
+ priv->iss = ~priv->irs; /* just to differ from irs */
eth_send->et_protlen = htons(PROT_IP);
tcp_send = (void *)eth_send + ETHER_HDR_SIZE;
tcp_send->tcp_src = tcp->tcp_dst;
tcp_send->tcp_dst = tcp->tcp_src;
- tcp_send->tcp_seq = htonl(0);
- tcp_send->tcp_ack = htonl(ntohl(tcp->tcp_seq) + 1);
+ tcp_send->tcp_seq = htonl(priv->iss);
+ tcp_send->tcp_ack = htonl(priv->irs + 1);
tcp_send->tcp_hlen = SHIFT_TO_TCPHDRLEN_FIELD(LEN_B_TO_DW(TCP_HDR_SIZE));
tcp_send->tcp_flags = TCP_SYN | TCP_ACK;
tcp_send->tcp_win = htons(PKTBUFSRX * TCP_MSS >> TCP_SCALE);
@@ -103,9 +105,24 @@ static int sb_ack_handler(struct udevice *dev, void *packet,
void *data;
int pkt_len;
int payload_len = 0;
- const char *payload1 = "HTTP/1.1 200 OK\r\n"
- "Content-Length: 30\r\n\r\n\r\n"
- "<html><body>Hi</body></html>\r\n";
+ u32 tcp_seq, tcp_ack;
+ int tcp_data_len;
+ const char *payload1 =
+ /* response status line */
+ "HTTP/1.1 200 OK\r\n"
+ /* response header fields */
+ "Date: Mon, 23 Dec 2024 05:18:23 GMT\r\n"
+ "Server: Apache/2.4.62 (Debian)\r\n"
+ "Last-Modified: Mon, 23 Dec 2024 05:04:50 GMT\r\n"
+ "ETag: \"1d-629e8efb09e7b\"\r\n"
+ "Accept-Ranges: bytes\r\n"
+ "Content-Length: 29\r\n"
+ "Connection: close\r\n"
+ "Content-Type: text/html\r\n"
+ /* response header fields end marker */
+ "\r\n"
+ /* file data (for HTTP GET requests) */
+ "<html><body>Hi</body></html>\n";
/* Don't allow the buffer to overrun */
if (priv->recv_packets >= PKTBUFSRX)
@@ -120,17 +137,32 @@ static int sb_ack_handler(struct udevice *dev, void *packet,
tcp_send->tcp_dst = tcp->tcp_src;
data = (void *)tcp_send + IP_TCP_HDR_SIZE;
- if (ntohl(tcp->tcp_seq) == 1 && ntohl(tcp->tcp_ack) == 1) {
- tcp_send->tcp_seq = htonl(ntohl(tcp->tcp_ack));
- tcp_send->tcp_ack = htonl(ntohl(tcp->tcp_seq) + 1);
+ tcp_seq = ntohl(tcp->tcp_seq) - priv->irs;
+ tcp_ack = ntohl(tcp->tcp_ack) - priv->iss;
+ tcp_data_len = len - ETHER_HDR_SIZE - IP_HDR_SIZE - GET_TCP_HDR_LEN_IN_BYTES(tcp->tcp_hlen);
+
+ if (tcp->tcp_flags & TCP_FIN)
+ tcp_data_len++;
+
+ tcp_send->tcp_seq = htonl(ntohl(tcp->tcp_ack));
+ tcp_send->tcp_ack = htonl(ntohl(tcp->tcp_seq) + tcp_data_len);
+
+ if (tcp_seq == 1 && tcp_ack == 1) {
+ if (tcp_data_len == 0) {
+ /* no data, wait for GET/HEAD request */
+ return -1;
+ }
+
+ /* reply to GET/HEAD request */
payload_len = strlen(payload1);
memcpy(data, payload1, payload_len);
tcp_send->tcp_flags = TCP_ACK;
- } else if (ntohl(tcp->tcp_seq) == 2) {
- tcp_send->tcp_seq = htonl(ntohl(tcp->tcp_ack));
- tcp_send->tcp_ack = htonl(ntohl(tcp->tcp_seq) + 1);
+ } else if (tcp_ack == 1 + strlen(payload1)) {
payload_len = 0;
tcp_send->tcp_flags = TCP_ACK | TCP_FIN;
+ } else if (tcp_ack == 2 + strlen(payload1)) {
+ payload_len = 0;
+ tcp_send->tcp_flags = TCP_ACK;
}
tcp_send->tcp_hlen = SHIFT_TO_TCPHDRLEN_FIELD(LEN_B_TO_DW(TCP_HDR_SIZE));
@@ -149,11 +181,9 @@ static int sb_ack_handler(struct udevice *dev, void *packet,
pkt_len,
IPPROTO_TCP);
- if (ntohl(tcp->tcp_seq) == 1 || ntohl(tcp->tcp_seq) == 2) {
- priv->recv_packet_length[priv->recv_packets] =
- ETHER_HDR_SIZE + IP_TCP_HDR_SIZE + payload_len;
- ++priv->recv_packets;
- }
+ priv->recv_packet_length[priv->recv_packets] =
+ ETHER_HDR_SIZE + IP_TCP_HDR_SIZE + payload_len;
+ ++priv->recv_packets;
return 0;
}
@@ -185,22 +215,29 @@ static int sb_http_handler(struct udevice *dev, void *packet,
static int net_test_wget(struct unit_test_state *uts)
{
+ char *prev_ethact = env_get("ethact");
+ char *prev_ethrotate = env_get("ethrotate");
+
sandbox_eth_set_tx_handler(0, sb_http_handler);
sandbox_eth_set_priv(0, uts);
env_set("ethact", "eth@10002000");
env_set("ethrotate", "no");
- env_set("loadaddr", "0x20000");
- ut_assertok(run_command("wget ${loadaddr} 1.1.2.2:/index.html", 0));
+ env_set("wgetaddr", "0x20000");
+ ut_assertok(run_command("wget ${wgetaddr} 1.1.2.2:/index.html", 0));
+ ut_assert_nextline_empty();
+ ut_assert_nextline("Packets received 5, Transfer Successful");
+ ut_assert_nextline("Bytes transferred = 29 (1d hex)");
sandbox_eth_set_tx_handler(0, NULL);
- ut_assertok(console_record_reset_enable());
- run_command("md5sum ${loadaddr} ${filesize}", 0);
- ut_assert_nextline("md5 for 00020000 ... 0002001f ==> 234af48e94b0085060249ecb5942ab57");
- ut_assertok(ut_check_console_end(uts));
+ run_command("md5sum ${wgetaddr} ${filesize}", 0);
+ ut_assert_nextline("md5 for 00020000 ... 0002001c ==> 847d5e7320a27462e90bc1ed75eb8cd8");
+ ut_assert_console_end();
+
+ env_set("ethact", prev_ethact);
+ env_set("ethrotate", prev_ethrotate);
return 0;
}
-
-LIB_TEST(net_test_wget, 0);
+CMD_TEST(net_test_wget, UTF_CONSOLE);
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index 0677ce0cd17..44e5fdfdaa6 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -4,258 +4,333 @@
* Joe Hershberger, National Instruments, joe.hershberger@ni.com
*/
-#include <common.h>
#include <command.h>
#include <console.h>
-#include <test/suites.h>
+#include <vsprintf.h>
#include <test/test.h>
#include <test/ut.h>
-static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[]);
+/**
+ * struct suite - A set of tests for a certain topic
+ *
+ * All tests end up in a single 'struct unit_test' linker-list array, in order
+ * of the suite they are in
+ *
+ * @name: Name of suite
+ * @start: First test in suite
+ * @end: End test in suite (points to the first test in the next suite)
+ * @help: Help-string to show for this suite
+ */
+struct suite {
+ const char *name;
+ struct unit_test *start;
+ struct unit_test *end;
+ const char *help;
+};
+
+static int do_ut_all(struct unit_test_state *uts, const char *select_name,
+ int runs_per_test, bool force_run,
+ const char *test_insert);
-static int do_ut_info(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[]);
+static int do_ut_info(bool show_suites);
+
+/* declare linker-list symbols for the start and end of a suite */
+#define SUITE_DECL(_name) \
+ ll_start_decl(suite_start_ ## _name, struct unit_test, ut_ ## _name); \
+ ll_end_decl(suite_end_ ## _name, struct unit_test, ut_ ## _name)
+
+/* declare a test suite which can be run directly without a subcommand */
+#define SUITE(_name, _help) { \
+ #_name, \
+ suite_start_ ## _name, \
+ suite_end_ ## _name, \
+ _help, \
+ }
-int cmd_ut_category(const char *name, const char *prefix,
- struct unit_test *tests, int n_ents,
- int argc, char *const argv[])
+SUITE_DECL(addrmap);
+SUITE_DECL(bdinfo);
+SUITE_DECL(bloblist);
+SUITE_DECL(bootm);
+SUITE_DECL(bootstd);
+SUITE_DECL(cmd);
+SUITE_DECL(common);
+SUITE_DECL(dm);
+SUITE_DECL(env);
+SUITE_DECL(exit);
+SUITE_DECL(fdt);
+SUITE_DECL(fdt_overlay);
+SUITE_DECL(font);
+SUITE_DECL(hush);
+SUITE_DECL(lib);
+SUITE_DECL(loadm);
+SUITE_DECL(log);
+SUITE_DECL(mbr);
+SUITE_DECL(measurement);
+SUITE_DECL(mem);
+SUITE_DECL(optee);
+SUITE_DECL(pci_mps);
+SUITE_DECL(seama);
+SUITE_DECL(setexpr);
+SUITE_DECL(upl);
+
+static struct suite suites[] = {
+ SUITE(addrmap, "very basic test of addrmap command"),
+ SUITE(bdinfo, "bdinfo (board info) command"),
+ SUITE(bloblist, "bloblist implementation"),
+ SUITE(bootm, "bootm command"),
+ SUITE(bootstd, "standard boot implementation"),
+ SUITE(cmd, "various commands"),
+ SUITE(common, "tests for common/ directory"),
+ SUITE(dm, "driver model"),
+ SUITE(env, "environment"),
+ SUITE(exit, "shell exit and variables"),
+ SUITE(fdt, "fdt command"),
+ SUITE(fdt_overlay, "device tree overlays"),
+ SUITE(font, "font command"),
+ SUITE(hush, "hush behaviour"),
+ SUITE(lib, "library functions"),
+ SUITE(loadm, "loadm command parameters and loading memory blob"),
+ SUITE(log, "logging functions"),
+ SUITE(mbr, "mbr command"),
+ SUITE(measurement, "TPM-based measured boot"),
+ SUITE(mem, "memory-related commands"),
+ SUITE(optee, "OP-TEE"),
+ SUITE(pci_mps, "PCI Express Maximum Payload Size"),
+ SUITE(seama, "seama command parameters loading and decoding"),
+ SUITE(setexpr, "setexpr command"),
+ SUITE(upl, "Universal payload support"),
+};
+
+/**
+ * has_tests() - Check if a suite has tests, i.e. is supported in this build
+ *
+ * If the suite is run using a command, we have to assume that tests may be
+ * present, since we have no visibility
+ *
+ * @ste: Suite to check
+ * Return: true if supported, false if not
+ */
+static bool has_tests(struct suite *ste)
{
- const char *test_insert = NULL;
- int runs_per_text = 1;
- bool force_run = false;
+ int n_ents = ste->end - ste->start;
+
+ return n_ents;
+}
+
+/** run_suite() - Run a suite of tests */
+static int run_suite(struct unit_test_state *uts, struct suite *ste,
+ const char *select_name, int runs_per_test, bool force_run,
+ const char *test_insert)
+{
+ int n_ents = ste->end - ste->start;
+ char prefix[30];
int ret;
- while (argc > 1 && *argv[1] == '-') {
- const char *str = argv[1];
+ /* use a standard prefix */
+ snprintf(prefix, sizeof(prefix), "%s_test_", ste->name);
- switch (str[1]) {
- case 'r':
- runs_per_text = dectoul(str + 2, NULL);
- break;
- case 'f':
- force_run = true;
- break;
- case 'I':
- test_insert = str + 2;
- break;
- }
- argv++;
- argc--;
- }
+ ret = ut_run_list(uts, ste->name, prefix, ste->start, n_ents,
+ select_name, runs_per_test, force_run, test_insert);
+
+ return ret;
+}
+
+static void show_stats(struct unit_test_state *uts)
+{
+ if (uts->run_count < 2)
+ return;
- ret = ut_run_list(name, prefix, tests, n_ents,
- cmd_arg1(argc, argv), runs_per_text, force_run,
- test_insert);
+ ut_report(&uts->total, uts->run_count);
+ if (CONFIG_IS_ENABLED(UNIT_TEST_DURATION) &&
+ uts->total.test_count && uts->worst) {
+ ulong avg = uts->total.duration_ms / uts->total.test_count;
- return ret ? CMD_RET_FAILURE : 0;
+ printf("Average test time: %ld ms, worst case '%s' took %d ms\n",
+ avg, uts->worst->name, uts->worst_ms);
+ }
}
-static struct cmd_tbl cmd_ut_sub[] = {
- U_BOOT_CMD_MKENT(all, CONFIG_SYS_MAXARGS, 1, do_ut_all, "", ""),
- U_BOOT_CMD_MKENT(info, 1, 1, do_ut_info, "", ""),
-#ifdef CONFIG_CMD_BDI
- U_BOOT_CMD_MKENT(bdinfo, CONFIG_SYS_MAXARGS, 1, do_ut_bdinfo, "", ""),
-#endif
-#ifdef CONFIG_UT_BOOTSTD
- U_BOOT_CMD_MKENT(bootstd, CONFIG_SYS_MAXARGS, 1, do_ut_bootstd,
- "", ""),
-#endif
-#ifdef CONFIG_CMDLINE
- U_BOOT_CMD_MKENT(cmd, CONFIG_SYS_MAXARGS, 1, do_ut_cmd, "", ""),
-#endif
- U_BOOT_CMD_MKENT(common, CONFIG_SYS_MAXARGS, 1, do_ut_common, "", ""),
-#if defined(CONFIG_UT_DM)
- U_BOOT_CMD_MKENT(dm, CONFIG_SYS_MAXARGS, 1, do_ut_dm, "", ""),
-#endif
-#if defined(CONFIG_UT_ENV)
- U_BOOT_CMD_MKENT(env, CONFIG_SYS_MAXARGS, 1, do_ut_env, "", ""),
-#endif
- U_BOOT_CMD_MKENT(exit, CONFIG_SYS_MAXARGS, 1, do_ut_exit, "", ""),
-#ifdef CONFIG_CMD_FDT
- U_BOOT_CMD_MKENT(fdt, CONFIG_SYS_MAXARGS, 1, do_ut_fdt, "", ""),
-#endif
-#ifdef CONFIG_CONSOLE_TRUETYPE
- U_BOOT_CMD_MKENT(font, CONFIG_SYS_MAXARGS, 1, do_ut_font, "", ""),
-#endif
-#ifdef CONFIG_UT_OPTEE
- U_BOOT_CMD_MKENT(optee, CONFIG_SYS_MAXARGS, 1, do_ut_optee, "", ""),
-#endif
-#ifdef CONFIG_UT_OVERLAY
- U_BOOT_CMD_MKENT(overlay, CONFIG_SYS_MAXARGS, 1, do_ut_overlay, "", ""),
-#endif
-#ifdef CONFIG_UT_LIB
- U_BOOT_CMD_MKENT(lib, CONFIG_SYS_MAXARGS, 1, do_ut_lib, "", ""),
-#endif
-#ifdef CONFIG_UT_LOG
- U_BOOT_CMD_MKENT(log, CONFIG_SYS_MAXARGS, 1, do_ut_log, "", ""),
-#endif
-#if defined(CONFIG_SANDBOX) && defined(CONFIG_CMD_MBR) && defined(CONFIG_CMD_MMC) \
- && defined(CONFIG_MMC_SANDBOX) && defined(CONFIG_MMC_WRITE)
- U_BOOT_CMD_MKENT(mbr, CONFIG_SYS_MAXARGS, 1, do_ut_mbr, "", ""),
-#endif
- U_BOOT_CMD_MKENT(mem, CONFIG_SYS_MAXARGS, 1, do_ut_mem, "", ""),
-#if defined(CONFIG_SANDBOX) && defined(CONFIG_CMD_SETEXPR)
- U_BOOT_CMD_MKENT(setexpr, CONFIG_SYS_MAXARGS, 1, do_ut_setexpr, "",
- ""),
-#endif
- U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_ut_print, "", ""),
-#ifdef CONFIG_UT_TIME
- U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
-#endif
-#if CONFIG_IS_ENABLED(UT_UNICODE) && !defined(API_BUILD)
- U_BOOT_CMD_MKENT(unicode, CONFIG_SYS_MAXARGS, 1, do_ut_unicode, "", ""),
-#endif
-#ifdef CONFIG_MEASURED_BOOT
- U_BOOT_CMD_MKENT(measurement, CONFIG_SYS_MAXARGS, 1, do_ut_measurement,
- "", ""),
-#endif
-#ifdef CONFIG_SANDBOX
- U_BOOT_CMD_MKENT(compression, CONFIG_SYS_MAXARGS, 1, do_ut_compression,
- "", ""),
- U_BOOT_CMD_MKENT(bloblist, CONFIG_SYS_MAXARGS, 1, do_ut_bloblist,
- "", ""),
- U_BOOT_CMD_MKENT(bootm, CONFIG_SYS_MAXARGS, 1, do_ut_bootm, "", ""),
-#endif
- U_BOOT_CMD_MKENT(str, CONFIG_SYS_MAXARGS, 1, do_ut_str, "", ""),
-#ifdef CONFIG_CMD_ADDRMAP
- U_BOOT_CMD_MKENT(addrmap, CONFIG_SYS_MAXARGS, 1, do_ut_addrmap, "", ""),
-#endif
-#if CONFIG_IS_ENABLED(HUSH_PARSER)
- U_BOOT_CMD_MKENT(hush, CONFIG_SYS_MAXARGS, 1, do_ut_hush, "", ""),
-#endif
-#ifdef CONFIG_CMD_LOADM
- U_BOOT_CMD_MKENT(loadm, CONFIG_SYS_MAXARGS, 1, do_ut_loadm, "", ""),
-#endif
-#ifdef CONFIG_CMD_PCI_MPS
- U_BOOT_CMD_MKENT(pci_mps, CONFIG_SYS_MAXARGS, 1, do_ut_pci_mps, "", ""),
-#endif
-#ifdef CONFIG_CMD_SEAMA
- U_BOOT_CMD_MKENT(seama, CONFIG_SYS_MAXARGS, 1, do_ut_seama, "", ""),
-#endif
-};
+static void update_stats(struct unit_test_state *uts, const struct suite *ste)
+{
+ if (CONFIG_IS_ENABLED(UNIT_TEST_DURATION) && uts->cur.test_count) {
+ ulong avg;
-static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[])
+ avg = uts->cur.duration_ms ?
+ uts->cur.duration_ms /
+ uts->cur.test_count : 0;
+ if (avg > uts->worst_ms) {
+ uts->worst_ms = avg;
+ uts->worst = ste;
+ }
+ }
+}
+
+static int do_ut_all(struct unit_test_state *uts, const char *select_name,
+ int runs_per_test, bool force_run, const char *test_insert)
{
int i;
int retval;
int any_fail = 0;
- for (i = 1; i < ARRAY_SIZE(cmd_ut_sub); i++) {
- printf("----Running %s tests----\n", cmd_ut_sub[i].name);
- retval = cmd_ut_sub[i].cmd(cmdtp, flag, 1, &cmd_ut_sub[i].name);
- if (!any_fail)
- any_fail = retval;
+ for (i = 0; i < ARRAY_SIZE(suites); i++) {
+ struct suite *ste = &suites[i];
+
+ if (has_tests(ste)) {
+ printf("----Running %s tests----\n", ste->name);
+ retval = run_suite(uts, ste, select_name, runs_per_test,
+ force_run, test_insert);
+ if (!any_fail)
+ any_fail = retval;
+ update_stats(uts, ste);
+ }
}
return any_fail;
}
-static int do_ut_info(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[])
+static int do_ut_info(bool show_suites)
{
- printf("Test suites: %d\n", (int)ARRAY_SIZE(cmd_ut_sub));
+ int suite_count, i;
+
+ for (suite_count = 0, i = 0; i < ARRAY_SIZE(suites); i++) {
+ struct suite *ste = &suites[i];
+
+ if (has_tests(ste))
+ suite_count++;
+ }
+
+ printf("Test suites: %d\n", suite_count);
printf("Total tests: %d\n", (int)UNIT_TEST_ALL_COUNT());
+ if (show_suites) {
+ int i, total;
+
+ puts("\nTests Suite Purpose");
+ puts("\n----- ------------ -------------------------\n");
+ for (i = 0, total = 0; i < ARRAY_SIZE(suites); i++) {
+ struct suite *ste = &suites[i];
+ long n_ent = ste->end - ste->start;
+
+ if (n_ent) {
+ printf("%5ld %-13.13s %s\n", n_ent, ste->name,
+ ste->help);
+ total += n_ent;
+ }
+ }
+ puts("----- ------------ -------------------------\n");
+ printf("%5d %-13.13s\n", total, "Total");
+
+ if (UNIT_TEST_ALL_COUNT() != total)
+ puts("Error: Suite test-count does not match total\n");
+ }
+
return 0;
}
-static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+static struct suite *find_suite(const char *name)
{
- struct cmd_tbl *cp;
+ struct suite *ste;
+ int i;
- if (argc < 2)
- return CMD_RET_USAGE;
+ for (i = 0, ste = suites; i < ARRAY_SIZE(suites); i++, ste++) {
+ if (!strcmp(ste->name, name))
+ return ste;
+ }
+
+ return NULL;
+}
+
+static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+ const char *test_insert = NULL, *select_name;
+ struct unit_test_state uts;
+ bool show_suites = false;
+ bool force_run = false;
+ int runs_per_text = 1;
+ struct suite *ste;
+ char *name;
+ int ret;
/* drop initial "ut" arg */
argc--;
argv++;
- cp = find_cmd_tbl(argv[0], cmd_ut_sub, ARRAY_SIZE(cmd_ut_sub));
+ while (argc > 0 && *argv[0] == '-') {
+ const char *str = argv[0];
+
+ switch (str[1]) {
+ case 'r':
+ runs_per_text = dectoul(str + 2, NULL);
+ break;
+ case 'f':
+ force_run = true;
+ break;
+ case 'I':
+ test_insert = str + 2;
+ if (!strchr(test_insert, ':'))
+ return CMD_RET_USAGE;
+ break;
+ case 's':
+ show_suites = true;
+ break;
+ }
+ argv++;
+ argc--;
+ }
+
+ if (argc < 1)
+ return CMD_RET_USAGE;
- if (cp)
- return cp->cmd(cmdtp, flag, argc, argv);
+ ut_init_state(&uts);
+ name = argv[0];
+ select_name = cmd_arg1(argc, argv);
+ if (!strcmp(name, "all")) {
+ ret = do_ut_all(&uts, select_name, runs_per_text, force_run,
+ test_insert);
+ } else if (!strcmp(name, "info")) {
+ ret = do_ut_info(show_suites);
+ } else {
+ int any_fail = 0;
+ const char *p;
- return CMD_RET_USAGE;
+ for (; p = strsep(&name, ","), p; name = NULL) {
+ ste = find_suite(p);
+ if (!ste) {
+ printf("Suite '%s' not found\n", p);
+ return CMD_RET_FAILURE;
+ } else if (!has_tests(ste)) {
+ /* perhaps a Kconfig option needs to be set? */
+ printf("Suite '%s' is not enabled\n", p);
+ return CMD_RET_FAILURE;
+ }
+
+ ret = run_suite(&uts, ste, select_name, runs_per_text,
+ force_run, test_insert);
+ if (!any_fail)
+ any_fail = ret;
+ update_stats(&uts, ste);
+ }
+ ret = any_fail;
+ }
+ show_stats(&uts);
+ if (ret)
+ return ret;
+ ut_uninit_state(&uts);
+
+ return 0;
}
U_BOOT_LONGHELP(ut,
- "[-r] [-f] [<suite>] - run unit tests\n"
+ "[-rs] [-f] [-I<n>:<one_test>][<suites>] - run unit tests\n"
" -r<runs> Number of times to run each test\n"
" -f Force 'manual' tests to run as well\n"
- " <suite> Test suite to run, or all\n"
+ " -I Test to run after <n> other tests have run\n"
+ " -s Show all suites with ut info\n"
+ " <suites> Comma-separated list of suites to run\n"
"\n"
- "\nOptions for <suite>:"
- "\nall - execute all enabled tests"
- "\ninfo - show info about tests"
-#ifdef CONFIG_CMD_ADDRMAP
- "\naddrmap - very basic test of addrmap command"
-#endif
-#ifdef CONFIG_CMD_BDI
- "\nbdinfo - bdinfo command"
-#endif
-#ifdef CONFIG_SANDBOX
- "\nbloblist - bloblist implementation"
-#endif
-#ifdef CONFIG_BOOTSTD
- "\nbootstd - standard boot implementation"
-#endif
-#ifdef CONFIG_CMDLINE
- "\ncmd - test various commands"
-#endif
-#ifdef CONFIG_SANDBOX
- "\ncompression - compressors and bootm decompression"
-#endif
-#ifdef CONFIG_UT_DM
- "\ndm - driver model"
-#endif
-#ifdef CONFIG_UT_ENV
- "\nenv - environment"
-#endif
-#ifdef CONFIG_CMD_FDT
- "\nfdt - fdt command"
-#endif
-#ifdef CONFIG_CONSOLE_TRUETYPE
- "\nfont - font command"
-#endif
-#if CONFIG_IS_ENABLED(HUSH_PARSER)
- "\nhush - Test hush behavior"
-#endif
-#ifdef CONFIG_CMD_LOADM
- "\nloadm - loadm command parameters and loading memory blob"
-#endif
-#ifdef CONFIG_UT_LIB
- "\nlib - library functions"
-#endif
-#ifdef CONFIG_UT_LOG
- "\nlog - logging functions"
-#endif
- "\nmem - memory-related commands"
-#ifdef CONFIG_UT_OPTEE
- "\noptee - test OP-TEE"
-#endif
-#ifdef CONFIG_UT_OVERLAY
- "\noverlay - device tree overlays"
-#endif
-#ifdef CONFIG_CMD_PCI_MPS
- "\npci_mps - PCI Express Maximum Payload Size"
-#endif
- "\nprint - printing things to the console"
- "\nsetexpr - setexpr command"
-#ifdef CONFIG_SANDBOX
- "\nstr - basic test of string functions"
-#endif
-#ifdef CONFIG_CMD_SEAMA
- "\nseama - seama command parameters loading and decoding"
-#endif
-#ifdef CONFIG_UT_TIME
- "\ntime - very basic test of time functions"
-#endif
-#if defined(CONFIG_UT_UNICODE) && \
- !defined(CONFIG_SPL_BUILD) && !defined(API_BUILD)
- "\nunicode - Unicode functions"
-#endif
+ "Options for <suite>:\n"
+ "all - execute all enabled tests\n"
+ "info - show info about tests [and suites]"
);
U_BOOT_CMD(
diff --git a/test/command_ut.c b/test/command_ut.c
deleted file mode 100644
index a74bd109e15..00000000000
--- a/test/command_ut.c
+++ /dev/null
@@ -1,105 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright (c) 2012, The Chromium Authors
- */
-
-#define DEBUG
-
-#include <common.h>
-#include <command.h>
-#include <env.h>
-#include <log.h>
-#include <string.h>
-#include <linux/errno.h>
-
-static const char test_cmd[] = "setenv list 1\n setenv list ${list}2; "
- "setenv list ${list}3\0"
- "setenv list ${list}4";
-
-static int do_ut_cmd(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[])
-{
- char long_str[CONFIG_SYS_CBSIZE + 42];
-
- printf("%s: Testing commands\n", __func__);
- run_command("env default -f -a", 0);
-
- /* commands separated by \n */
- run_command_list("setenv list 1\n setenv list ${list}1", -1, 0);
- assert(!strcmp("11", env_get("list")));
-
- /* command followed by \n and nothing else */
- run_command_list("setenv list 1${list}\n", -1, 0);
- assert(!strcmp("111", env_get("list")));
-
- /* a command string with \0 in it. Stuff after \0 should be ignored */
- run_command("setenv list", 0);
- run_command_list(test_cmd, sizeof(test_cmd), 0);
- assert(!strcmp("123", env_get("list")));
-
- /*
- * a command list where we limit execution to only the first command
- * using the length parameter.
- */
- run_command_list("setenv list 1\n setenv list ${list}2; "
- "setenv list ${list}3", strlen("setenv list 1"), 0);
- assert(!strcmp("1", env_get("list")));
-
- assert(run_command("false", 0) == 1);
- assert(run_command("echo", 0) == 0);
- assert(run_command_list("false", -1, 0) == 1);
- assert(run_command_list("echo", -1, 0) == 0);
-
-#ifdef CONFIG_HUSH_PARSER
- run_command("setenv foo 'setenv black 1\nsetenv adder 2'", 0);
- run_command("run foo", 0);
- assert(env_get("black") != NULL);
- assert(!strcmp("1", env_get("black")));
- assert(env_get("adder") != NULL);
- assert(!strcmp("2", env_get("adder")));
-#endif
-
- assert(run_command("", 0) == 0);
- assert(run_command(" ", 0) == 0);
-
- assert(run_command("'", 0) == 1);
-
- /* Variadic function test-cases */
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wformat-zero-length"
- assert(run_commandf("") == 0);
-#pragma GCC diagnostic pop
- assert(run_commandf(" ") == 0);
- assert(run_commandf("'") == 1);
-
- assert(run_commandf("env %s %s", "delete -f", "list") == 0);
- /* Expected: "Error: "list" not defined" */
- assert(run_commandf("printenv list") == 1);
-
- memset(long_str, 'x', sizeof(long_str));
- assert(run_commandf("Truncation case: %s", long_str) == -ENOSPC);
-
- if (IS_ENABLED(CONFIG_HUSH_PARSER)) {
- assert(run_commandf("env %s %s %s %s", "delete -f", "adder",
- "black", "foo") == 0);
- assert(run_commandf("setenv foo 'setenv %s 1\nsetenv %s 2'",
- "black", "adder") == 0);
- run_command("run foo", 0);
- assert(env_get("black"));
- assert(!strcmp("1", env_get("black")));
- assert(env_get("adder"));
- assert(!strcmp("2", env_get("adder")));
- }
-
- /* Clean up before exit */
- run_command("env default -f -a", 0);
-
- printf("%s: Everything went swimmingly\n", __func__);
- return 0;
-}
-
-U_BOOT_CMD(
- ut_cmd, 5, 1, do_ut_cmd,
- "Very basic test of command parsers",
- ""
-);
diff --git a/test/common.sh b/test/common.sh
deleted file mode 100644
index 904d579b7bf..00000000000
--- a/test/common.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/sh
-
-OUTPUT_DIR=sandbox
-
-fail() {
- echo "Test failed: $1"
- if [ -n ${tmp} ]; then
- rm ${tmp}
- fi
- exit 1
-}
-
-build_uboot() {
- echo "Build sandbox"
- OPTS="O=${OUTPUT_DIR} $1"
- NUM_CPUS=$(nproc)
- echo ${OPTS}
- make ${OPTS} sandbox_config
- make ${OPTS} -s -j${NUM_CPUS}
-}
diff --git a/test/common/Makefile b/test/common/Makefile
index 12c65f8c951..baefc7b3622 100644
--- a/test/common/Makefile
+++ b/test/common/Makefile
@@ -1,6 +1,13 @@
# SPDX-License-Identifier: GPL-2.0+
-obj-y += cmd_ut_common.o
obj-$(CONFIG_AUTOBOOT) += test_autoboot.o
+
+ifneq ($(CONFIG_$(PHASE_)BLOBLIST),)
+ifdef CONFIG_BLOBLIST_FIXED
+obj-$(CONFIG_$(PHASE_)CMDLINE) += bloblist.o
+endif
+endif
+
obj-$(CONFIG_CYCLIC) += cyclic.o
obj-$(CONFIG_EVENT_DYNAMIC) += event.o
obj-y += cread.o
+obj-$(CONFIG_$(PHASE_)CMDLINE) += print.o
diff --git a/test/bloblist.c b/test/common/bloblist.c
index 1c60bbac36c..797bde27025 100644
--- a/test/bloblist.c
+++ b/test/common/bloblist.c
@@ -3,20 +3,15 @@
* Copyright (c) 2018, Google Inc. All rights reserved.
*/
-#include <common.h>
#include <bloblist.h>
#include <log.h>
#include <mapmem.h>
-#include <asm/global_data.h>
-#include <test/suites.h>
#include <test/test.h>
#include <test/ut.h>
-DECLARE_GLOBAL_DATA_PTR;
-
/* Declare a new bloblist test */
#define BLOBLIST_TEST(_name, _flags) \
- UNIT_TEST(_name, _flags, bloblist_test)
+ UNIT_TEST(_name, _flags, bloblist)
enum {
TEST_TAG = BLOBLISTT_U_BOOT_SPL_HANDOFF,
@@ -95,17 +90,19 @@ static int bloblist_test_init(struct unit_test_state *uts)
return 1;
}
-BLOBLIST_TEST(bloblist_test_init, 0);
+BLOBLIST_TEST(bloblist_test_init, UFT_BLOBLIST);
static int bloblist_test_blob(struct unit_test_state *uts)
{
struct bloblist_hdr *hdr;
struct bloblist_rec *rec, *rec2;
char *data;
+ int size = 0;
/* At the start there should be no records */
hdr = clear_bloblist();
ut_assertnull(bloblist_find(TEST_TAG, TEST_BLOBLIST_SIZE));
+ ut_assertnull(bloblist_get_blob(TEST_TAG, &size));
ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0));
ut_asserteq(sizeof(struct bloblist_hdr), bloblist_get_size());
ut_asserteq(TEST_BLOBLIST_SIZE, bloblist_get_total_size());
@@ -118,6 +115,8 @@ static int bloblist_test_blob(struct unit_test_state *uts)
ut_asserteq_addr(rec + 1, data);
data = bloblist_find(TEST_TAG, TEST_SIZE);
ut_asserteq_addr(rec + 1, data);
+ ut_asserteq_addr(bloblist_get_blob(TEST_TAG, &size), data);
+ ut_asserteq(size, TEST_SIZE);
/* Check the data is zeroed */
ut_assertok(check_zero(data, TEST_SIZE));
@@ -135,7 +134,7 @@ static int bloblist_test_blob(struct unit_test_state *uts)
return 0;
}
-BLOBLIST_TEST(bloblist_test_blob, 0);
+BLOBLIST_TEST(bloblist_test_blob, UFT_BLOBLIST);
/* Check bloblist_ensure_size_ret() */
static int bloblist_test_blob_ensure(struct unit_test_state *uts)
@@ -169,7 +168,7 @@ static int bloblist_test_blob_ensure(struct unit_test_state *uts)
return 0;
}
-BLOBLIST_TEST(bloblist_test_blob_ensure, 0);
+BLOBLIST_TEST(bloblist_test_blob_ensure, UFT_BLOBLIST);
static int bloblist_test_bad_blob(struct unit_test_state *uts)
{
@@ -185,7 +184,7 @@ static int bloblist_test_bad_blob(struct unit_test_state *uts)
return 0;
}
-BLOBLIST_TEST(bloblist_test_bad_blob, 0);
+BLOBLIST_TEST(bloblist_test_bad_blob, UFT_BLOBLIST);
static int bloblist_test_checksum(struct unit_test_state *uts)
{
@@ -258,7 +257,7 @@ static int bloblist_test_checksum(struct unit_test_state *uts)
return 0;
}
-BLOBLIST_TEST(bloblist_test_checksum, 0);
+BLOBLIST_TEST(bloblist_test_checksum, UFT_BLOBLIST);
/* Test the 'bloblist info' command */
static int bloblist_test_cmd_info(struct unit_test_state *uts)
@@ -271,20 +270,15 @@ static int bloblist_test_cmd_info(struct unit_test_state *uts)
data = bloblist_ensure(TEST_TAG, TEST_SIZE);
data2 = bloblist_ensure(TEST_TAG2, TEST_SIZE2);
- console_record_reset_enable();
- ut_silence_console(uts);
- console_record_reset();
run_command("bloblist info", 0);
ut_assert_nextline("base: %lx", (ulong)map_to_sysmem(hdr));
ut_assert_nextline("total size: 400 1 KiB");
ut_assert_nextline("used size: 50 80 Bytes");
ut_assert_nextline("free: 3b0 944 Bytes");
- ut_assert_console_end();
- ut_unsilence_console(uts);
return 0;
}
-BLOBLIST_TEST(bloblist_test_cmd_info, 0);
+BLOBLIST_TEST(bloblist_test_cmd_info, UFT_BLOBLIST | UTF_CONSOLE);
/* Test the 'bloblist list' command */
static int bloblist_test_cmd_list(struct unit_test_state *uts)
@@ -297,21 +291,16 @@ static int bloblist_test_cmd_list(struct unit_test_state *uts)
data = bloblist_ensure(TEST_TAG, TEST_SIZE);
data2 = bloblist_ensure(TEST_TAG2, TEST_SIZE2);
- console_record_reset_enable();
- ut_silence_console(uts);
- console_record_reset();
run_command("bloblist list", 0);
ut_assert_nextline("Address Size Tag Name");
ut_assert_nextline("%08lx %8x fff000 SPL hand-off",
(ulong)map_to_sysmem(data), TEST_SIZE);
ut_assert_nextline("%08lx %8x 202 Chrome OS vboot context",
(ulong)map_to_sysmem(data2), TEST_SIZE2);
- ut_assert_console_end();
- ut_unsilence_console(uts);
return 0;
}
-BLOBLIST_TEST(bloblist_test_cmd_list, 0);
+BLOBLIST_TEST(bloblist_test_cmd_list, UFT_BLOBLIST | UTF_CONSOLE);
/* Test alignment of bloblist blobs */
static int bloblist_test_align(struct unit_test_state *uts)
@@ -369,7 +358,7 @@ static int bloblist_test_align(struct unit_test_state *uts)
return 0;
}
-BLOBLIST_TEST(bloblist_test_align, 0);
+BLOBLIST_TEST(bloblist_test_align, UFT_BLOBLIST);
/* Test relocation of a bloblist */
static int bloblist_test_reloc(struct unit_test_state *uts)
@@ -403,7 +392,7 @@ static int bloblist_test_reloc(struct unit_test_state *uts)
return 0;
}
-BLOBLIST_TEST(bloblist_test_reloc, 0);
+BLOBLIST_TEST(bloblist_test_reloc, UFT_BLOBLIST);
/* Test expansion of a blob */
static int bloblist_test_grow(struct unit_test_state *uts)
@@ -456,7 +445,7 @@ static int bloblist_test_grow(struct unit_test_state *uts)
return 0;
}
-BLOBLIST_TEST(bloblist_test_grow, 0);
+BLOBLIST_TEST(bloblist_test_grow, UFT_BLOBLIST);
/* Test shrinking of a blob */
static int bloblist_test_shrink(struct unit_test_state *uts)
@@ -506,7 +495,7 @@ static int bloblist_test_shrink(struct unit_test_state *uts)
return 0;
}
-BLOBLIST_TEST(bloblist_test_shrink, 0);
+BLOBLIST_TEST(bloblist_test_shrink, UFT_BLOBLIST);
/* Test failing to adjust a blob size */
static int bloblist_test_resize_fail(struct unit_test_state *uts)
@@ -541,7 +530,7 @@ static int bloblist_test_resize_fail(struct unit_test_state *uts)
return 0;
}
-BLOBLIST_TEST(bloblist_test_resize_fail, 0);
+BLOBLIST_TEST(bloblist_test_resize_fail, UFT_BLOBLIST);
/* Test expanding the last blob in a bloblist */
static int bloblist_test_resize_last(struct unit_test_state *uts)
@@ -592,7 +581,7 @@ static int bloblist_test_resize_last(struct unit_test_state *uts)
return 0;
}
-BLOBLIST_TEST(bloblist_test_resize_last, 0);
+BLOBLIST_TEST(bloblist_test_resize_last, UFT_BLOBLIST);
/* Check a completely full bloblist */
static int bloblist_test_blob_maxsize(struct unit_test_state *uts)
@@ -615,14 +604,4 @@ static int bloblist_test_blob_maxsize(struct unit_test_state *uts)
return 0;
}
-BLOBLIST_TEST(bloblist_test_blob_maxsize, 0);
-
-int do_ut_bloblist(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(bloblist_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(bloblist_test);
-
- return cmd_ut_category("bloblist", "bloblist_test_",
- tests, n_ents, argc, argv);
-}
+BLOBLIST_TEST(bloblist_test_blob_maxsize, UFT_BLOBLIST);
diff --git a/test/common/cmd_ut_common.c b/test/common/cmd_ut_common.c
deleted file mode 100644
index 2c0267801b2..00000000000
--- a/test/common/cmd_ut_common.c
+++ /dev/null
@@ -1,22 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * Copyright (c) 2019 Heinrich Schuchardt <xypron.glpk@gmx.de>
- * Copyright (c) 2021 Steffen Jaeckel <jaeckel-floss@eyet-services.de>
- *
- * Unit tests for common functions
- */
-
-#include <common.h>
-#include <command.h>
-#include <test/common.h>
-#include <test/suites.h>
-#include <test/ut.h>
-
-int do_ut_common(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(common_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(common_test);
-
- return cmd_ut_category("common", "common_test_", tests, n_ents, argc,
- argv);
-}
diff --git a/test/common/cread.c b/test/common/cread.c
index 4edc7739604..4926c216803 100644
--- a/test/common/cread.c
+++ b/test/common/cread.c
@@ -3,8 +3,8 @@
* Copyright 2023 Google LLC
*/
-#include <common.h>
#include <cli.h>
+#include <time.h>
#include <test/common.h>
#include <test/test.h>
#include <test/ut.h>
@@ -66,8 +66,6 @@ static int cread_test(struct unit_test_state *uts)
* print_buffer(0, buf, 1, 7, 0);
*/
- console_record_reset_enable();
-
/* simple input */
*buf = '\0';
ut_asserteq(4, console_in_puts("abc\n"));
@@ -102,4 +100,4 @@ static int cread_test(struct unit_test_state *uts)
return 0;
}
-COMMON_TEST(cread_test, 0);
+COMMON_TEST(cread_test, UTF_CONSOLE);
diff --git a/test/common/cyclic.c b/test/common/cyclic.c
index 6e758e89dbd..51a07c576b6 100644
--- a/test/common/cyclic.c
+++ b/test/common/cyclic.c
@@ -3,7 +3,6 @@
* Copyright (C) 2022 Stefan Roese <sr@denx.de>
*/
-#include <common.h>
#include <cyclic.h>
#include <dm.h>
#include <test/common.h>
@@ -13,22 +12,27 @@
#include <linux/delay.h>
/* Test that cyclic function is called */
-static bool cyclic_active = false;
+static struct cyclic_test {
+ struct cyclic_info cyclic;
+ bool called;
+} cyclic_test;
-static void cyclic_test(void *ctx)
+static void test_cb(struct cyclic_info *c)
{
- cyclic_active = true;
+ struct cyclic_test *t = container_of(c, struct cyclic_test, cyclic);
+ t->called = true;
}
static int dm_test_cyclic_running(struct unit_test_state *uts)
{
- cyclic_active = false;
- ut_assertnonnull(cyclic_register(cyclic_test, 10 * 1000, "cyclic_demo",
- NULL));
+ cyclic_test.called = false;
+ cyclic_register(&cyclic_test.cyclic, test_cb, 10 * 1000, "cyclic_test");
/* Execute all registered cyclic functions */
schedule();
- ut_asserteq(true, cyclic_active);
+ ut_asserteq(true, cyclic_test.called);
+
+ cyclic_unregister(&cyclic_test.cyclic);
return 0;
}
diff --git a/test/common/event.c b/test/common/event.c
index b462694fc3b..e77e020b00b 100644
--- a/test/common/event.c
+++ b/test/common/event.c
@@ -6,7 +6,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <dm.h>
#include <event.h>
#include <test/common.h>
@@ -92,7 +91,7 @@ static int test_event_probe(struct unit_test_state *uts)
struct test_state state;
struct udevice *dev;
- if (!IS_ENABLED(SANDBOX))
+ if (!IS_ENABLED(CONFIG_SANDBOX))
return -EAGAIN;
state.val = 0;
@@ -107,4 +106,4 @@ static int test_event_probe(struct unit_test_state *uts)
return 0;
}
-COMMON_TEST(test_event_probe, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+COMMON_TEST(test_event_probe, UTF_DM | UTF_SCAN_FDT);
diff --git a/test/print_ut.c b/test/common/print.c
index bb844d2542b..c48efc2783f 100644
--- a/test/print_ut.c
+++ b/test/common/print.c
@@ -3,15 +3,15 @@
* Copyright (c) 2012, The Chromium Authors
*/
-#include <common.h>
#include <command.h>
#include <efi_api.h>
#include <display_options.h>
#include <log.h>
#include <mapmem.h>
#include <version_string.h>
+#include <stdio.h>
#include <vsprintf.h>
-#include <test/suites.h>
+#include <test/common.h>
#include <test/test.h>
#include <test/ut.h>
@@ -20,9 +20,6 @@
#define FAKE_BUILD_TAG "jenkins-u-boot-denx_uboot_dm-master-build-aarch64" \
"and a lot more text to come"
-/* Declare a new print test */
-#define PRINT_TEST(_name, _flags) UNIT_TEST(_name, _flags, print_test)
-
#if CONFIG_IS_ENABLED(LIB_UUID)
/* Test printing GUIDs */
static int print_guid(struct unit_test_state *uts)
@@ -48,18 +45,18 @@ static int print_guid(struct unit_test_state *uts)
sprintf(str, "%pUL", guid);
ut_asserteq_str("04030201-0605-0807-090A-0B0C0D0E0F10", str);
sprintf(str, "%pUs", guid_esp);
- if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)) { /* brace needed */
- ut_asserteq_str("system", str);
- } else {
+ if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID) ||
+ IS_ENABLED(CONFIG_CMD_EFIDEBUG) || IS_ENABLED(CONFIG_EFI))
+ ut_asserteq_str("EFI System Partition", str);
+ else
ut_asserteq_str("c12a7328-f81f-11d2-ba4b-00a0c93ec93b", str);
- }
ret = snprintf(str, 4, "%pUL", guid);
ut_asserteq(0, str[3]);
ut_asserteq(36, ret);
return 0;
}
-PRINT_TEST(print_guid, 0);
+COMMON_TEST(print_guid, 0);
#endif
#if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD)
@@ -95,7 +92,7 @@ static int print_efi_ut(struct unit_test_state *uts)
return 0;
}
-PRINT_TEST(print_efi_ut, 0);
+COMMON_TEST(print_efi_ut, 0);
#endif
static int print_printf(struct unit_test_state *uts)
@@ -118,8 +115,10 @@ static int print_printf(struct unit_test_state *uts)
snprintf(str, 0, "testing none");
ut_asserteq('x', *str);
- sprintf(big_str, "_%ls_", u"foo");
- ut_assertok(strcmp("_foo_", big_str));
+ if (CONFIG_IS_ENABLED(EFI_LOADER) || IS_ENABLED(CONFIG_EFI_APP)) {
+ sprintf(big_str, "_%ls_", u"foo");
+ ut_assertok(strcmp("_foo_", big_str));
+ }
/* Test the banner function */
s = display_options_get_banner(true, str, sizeof(str));
@@ -163,7 +162,7 @@ static int print_printf(struct unit_test_state *uts)
return 0;
}
-PRINT_TEST(print_printf, 0);
+COMMON_TEST(print_printf, 0);
static int print_display_buffer(struct unit_test_state *uts)
{
@@ -180,14 +179,12 @@ static int print_display_buffer(struct unit_test_state *uts)
buf[i] = i * 0x11;
/* bytes */
- console_record_reset();
print_buffer(0, buf, 1, 0x12, 0);
ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........");
ut_assert_nextline("00000010: 10 00 ..");
ut_assert_console_end();
/* line length */
- console_record_reset();
print_buffer(0, buf, 1, 0x12, 8);
ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 ..\"3DUfw");
ut_assert_nextline("00000008: 88 99 aa bb cc dd ee ff ........");
@@ -195,7 +192,6 @@ static int print_display_buffer(struct unit_test_state *uts)
ut_assert_console_end();
/* long line */
- console_record_reset();
buf[0x41] = 0x41;
print_buffer(0, buf, 1, 0x42, 0x40);
ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ..\"3DUfw........................................................");
@@ -203,35 +199,30 @@ static int print_display_buffer(struct unit_test_state *uts)
ut_assert_console_end();
/* address */
- console_record_reset();
print_buffer(0x12345678, buf, 1, 0x12, 0);
ut_assert_nextline("12345678: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........");
ut_assert_nextline("12345688: 10 00 ..");
ut_assert_console_end();
/* 16-bit */
- console_record_reset();
print_buffer(0, buf, 2, 9, 0);
ut_assert_nextline("00000000: 1100 3322 5544 7766 9988 bbaa ddcc ffee ..\"3DUfw........");
ut_assert_nextline("00000010: 0010 ..");
ut_assert_console_end();
/* 32-bit */
- console_record_reset();
print_buffer(0, buf, 4, 5, 0);
ut_assert_nextline("00000000: 33221100 77665544 bbaa9988 ffeeddcc ..\"3DUfw........");
ut_assert_nextline("00000010: 00000010 ....");
ut_assert_console_end();
/* 64-bit */
- console_record_reset();
print_buffer(0, buf, 8, 3, 0);
ut_assert_nextline("00000000: 7766554433221100 ffeeddccbbaa9988 ..\"3DUfw........");
ut_assert_nextline("00000010: 0000000000000010 ........");
ut_assert_console_end();
/* ASCII */
- console_record_reset();
buf[1] = 31;
buf[2] = 32;
buf[3] = 33;
@@ -246,11 +237,11 @@ static int print_display_buffer(struct unit_test_state *uts)
return 0;
}
-PRINT_TEST(print_display_buffer, UT_TESTF_CONSOLE_REC);
+COMMON_TEST(print_display_buffer, UTF_CONSOLE);
static int print_hexdump_line(struct unit_test_state *uts)
{
- char *linebuf;
+ u8 *linebuf;
u8 *buf;
int i;
@@ -263,16 +254,16 @@ static int print_hexdump_line(struct unit_test_state *uts)
linebuf = map_sysmem(0x400, BUF_SIZE);
memset(linebuf, '\xff', BUF_SIZE);
ut_asserteq(-ENOSPC, hexdump_line(0, buf, 1, 0x10, 0, linebuf, 75));
- ut_asserteq(-1, linebuf[0]);
+ ut_asserteq(0xff, linebuf[0]);
ut_asserteq(0x10, hexdump_line(0, buf, 1, 0x10, 0, linebuf, 76));
- ut_asserteq(0, linebuf[75]);
- ut_asserteq(-1, linebuf[76]);
+ ut_asserteq('\0', linebuf[75]);
+ ut_asserteq(0xff, linebuf[76]);
unmap_sysmem(buf);
return 0;
}
-PRINT_TEST(print_hexdump_line, UT_TESTF_CONSOLE_REC);
+COMMON_TEST(print_hexdump_line, UTF_CONSOLE);
static int print_do_hex_dump(struct unit_test_state *uts)
{
@@ -289,7 +280,6 @@ static int print_do_hex_dump(struct unit_test_state *uts)
buf[i] = i * 0x11;
/* bytes */
- console_record_reset();
print_hex_dump_bytes("", DUMP_PREFIX_ADDRESS, buf, 0x12);
ut_assert_nextline("%0*lx: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........",
IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL);
@@ -298,7 +288,6 @@ static int print_do_hex_dump(struct unit_test_state *uts)
ut_assert_console_end();
/* line length */
- console_record_reset();
print_hex_dump("", DUMP_PREFIX_ADDRESS, 8, 1, buf, 0x12, true);
ut_assert_nextline("%0*lx: 00 11 22 33 44 55 66 77 ..\"3DUfw",
IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL);
@@ -310,7 +299,6 @@ static int print_do_hex_dump(struct unit_test_state *uts)
unmap_sysmem(buf);
/* long line */
- console_record_reset();
buf[0x41] = 0x41;
print_hex_dump("", DUMP_PREFIX_ADDRESS, 0x40, 1, buf, 0x42, true);
ut_assert_nextline("%0*lx: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ..\"3DUfw........................................................",
@@ -320,7 +308,6 @@ static int print_do_hex_dump(struct unit_test_state *uts)
ut_assert_console_end();
/* 16-bit */
- console_record_reset();
print_hex_dump("", DUMP_PREFIX_ADDRESS, 0, 2, buf, 0x12, true);
ut_assert_nextline("%0*lx: 1100 3322 5544 7766 9988 bbaa ddcc ffee ..\"3DUfw........",
IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL);
@@ -330,7 +317,6 @@ static int print_do_hex_dump(struct unit_test_state *uts)
unmap_sysmem(buf);
/* 32-bit */
- console_record_reset();
print_hex_dump("", DUMP_PREFIX_ADDRESS, 0, 4, buf, 0x14, true);
ut_assert_nextline("%0*lx: 33221100 77665544 bbaa9988 ffeeddcc ..\"3DUfw........",
IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL);
@@ -340,7 +326,6 @@ static int print_do_hex_dump(struct unit_test_state *uts)
unmap_sysmem(buf);
/* 64-bit */
- console_record_reset();
print_hex_dump("", DUMP_PREFIX_ADDRESS, 16, 8, buf, 0x18, true);
ut_assert_nextline("%0*lx: 7766554433221100 ffeeddccbbaa9988 ..\"3DUfw........",
IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL);
@@ -350,7 +335,6 @@ static int print_do_hex_dump(struct unit_test_state *uts)
unmap_sysmem(buf);
/* ASCII */
- console_record_reset();
buf[1] = 31;
buf[2] = 32;
buf[3] = 33;
@@ -365,7 +349,7 @@ static int print_do_hex_dump(struct unit_test_state *uts)
return 0;
}
-PRINT_TEST(print_do_hex_dump, UT_TESTF_CONSOLE_REC);
+COMMON_TEST(print_do_hex_dump, UTF_CONSOLE);
static int snprint(struct unit_test_state *uts)
{
@@ -391,12 +375,4 @@ static int snprint(struct unit_test_state *uts)
ut_asserteq(8, ret);
return 0;
}
-PRINT_TEST(snprint, 0);
-
-int do_ut_print(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(print_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(print_test);
-
- return cmd_ut_category("print", "print_", tests, n_ents, argc, argv);
-}
+COMMON_TEST(snprint, 0);
diff --git a/test/common/test_autoboot.c b/test/common/test_autoboot.c
index 42a1e4ab1fa..e3050d02c60 100644
--- a/test/common/test_autoboot.c
+++ b/test/common/test_autoboot.c
@@ -6,7 +6,6 @@
*/
#include <autoboot.h>
-#include <common.h>
#include <test/common.h>
#include <test/test.h>
#include <test/ut.h>
@@ -21,7 +20,6 @@ static int check_for_input(struct unit_test_state *uts, const char *in,
const char *autoboot_prompt =
"Enter password \"a\" in 1 seconds to stop autoboot";
- console_record_reset_enable();
console_in_puts(in);
/* turn on keyed autoboot for the test, if possible */
@@ -92,5 +90,4 @@ static int test_autoboot(struct unit_test_state *uts)
return CMD_RET_SUCCESS;
}
-
-COMMON_TEST(test_autoboot, 0);
+COMMON_TEST(test_autoboot, UTF_CONSOLE);
diff --git a/test/dm/Kconfig b/test/dm/Kconfig
index e5b341e523a..640421c2a79 100644
--- a/test/dm/Kconfig
+++ b/test/dm/Kconfig
@@ -1,6 +1,6 @@
config UT_DM
bool "Enable driver model unit test command"
- depends on SANDBOX && UNIT_TEST
+ depends on SANDBOX
help
This enables the 'ut dm' command which runs a series of unit
tests on the driver model code. Each subsystem (uclass) is tested.
diff --git a/test/dm/Makefile b/test/dm/Makefile
index a3ce7b3889f..917dafe7d22 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -3,11 +3,9 @@
# Copyright (c) 2013 Google, Inc
# Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
-obj-$(CONFIG_UT_DM) += test-dm.o
-
# Tests for particular subsystems - when enabling driver model for a new
# subsystem you must add sandbox tests here.
-ifeq ($(CONFIG_SPL_BUILD),y)
+ifeq ($(CONFIG_XPL_BUILD),y)
obj-$(CONFIG_SPL_OF_PLATDATA) += of_platdata.o
else
obj-$(CONFIG_UT_DM) += bus.o
@@ -42,7 +40,7 @@ obj-$(CONFIG_CLK) += clk.o clk_ccf.o
obj-$(CONFIG_CPU) += cpu.o
obj-$(CONFIG_CROS_EC) += cros_ec.o
obj-$(CONFIG_PWM_CROS_EC) += cros_ec_pwm.o
-obj-$(CONFIG_$(SPL_TPL_)DEVRES) += devres.o
+obj-$(CONFIG_$(PHASE_)DEVRES) += devres.o
obj-$(CONFIG_DMA) += dma.o
obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi_host.o
obj-$(CONFIG_DM_DSA) += dsa.o
@@ -63,6 +61,7 @@ obj-$(CONFIG_SOUND) += i2s.o
obj-$(CONFIG_CLK_K210_SET_RATE) += k210_pll.o
obj-$(CONFIG_IOMMU) += iommu.o
obj-$(CONFIG_LED) += led.o
+obj-$(CONFIG_VIDEO_BRIDGE_LVDS_CODEC) += video_bridge.o
obj-$(CONFIG_DM_MAILBOX) += mailbox.o
obj-$(CONFIG_DM_MDIO) += mdio.o
obj-$(CONFIG_DM_MDIO_MUX) += mdio_mux.o
@@ -102,7 +101,7 @@ obj-$(CONFIG_DM_RESET) += reset.o
obj-$(CONFIG_SYSRESET) += sysreset.o
obj-$(CONFIG_DM_REGULATOR) += regulator.o
obj-$(CONFIG_CMD_RKMTD) += rkmtd.o
-obj-$(CONFIG_DM_RNG) += rng.o
+obj-$(CONFIG_$(PHASE_)DM_RNG) += rng.o
obj-$(CONFIG_DM_RTC) += rtc.o
obj-$(CONFIG_SCMI_FIRMWARE) += scmi.o
obj-$(CONFIG_SCSI) += scsi.o
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index f14b3962f84..db012b6d2f1 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -6,7 +6,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <console.h>
#include <dm.h>
#include <malloc.h>
@@ -96,6 +95,21 @@ static int testacpi_get_name(const struct udevice *dev, char *out_name)
return acpi_copy_name(out_name, ACPI_TEST_DEV_NAME);
}
+static int testacpi_fill_madt(const struct udevice *dev, struct acpi_ctx *ctx)
+{
+ u64 *data = ctx->current;
+
+ /* Only fill madt once */
+ if (device_get_uclass_id(dev->parent) != UCLASS_TEST_ACPI)
+ return 0;
+
+ *data = 0xdeadbeef;
+
+ acpi_inc(ctx, sizeof(u64));
+
+ return 0;
+}
+
static int testacpi_fill_ssdt(const struct udevice *dev, struct acpi_ctx *ctx)
{
const char *data;
@@ -125,6 +139,7 @@ static int testacpi_inject_dsdt(const struct udevice *dev, struct acpi_ctx *ctx)
struct acpi_ops testacpi_ops = {
.get_name = testacpi_get_name,
.write_tables = testacpi_write_tables,
+ .fill_madt = testacpi_fill_madt,
.fill_ssdt = testacpi_fill_ssdt,
.inject_dsdt = testacpi_inject_dsdt,
};
@@ -196,7 +211,7 @@ static int dm_test_acpi_get_name(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_get_name, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_get_name, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test acpi_get_table_revision() */
static int dm_test_acpi_get_table_revision(struct unit_test_state *uts)
@@ -208,8 +223,7 @@ static int dm_test_acpi_get_table_revision(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_get_table_revision,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_get_table_revision, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test acpi_create_dmar() */
static int dm_test_acpi_create_dmar(struct unit_test_state *uts)
@@ -226,7 +240,7 @@ static int dm_test_acpi_create_dmar(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_create_dmar, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_create_dmar, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test acpi_fill_header() */
static int dm_test_acpi_fill_header(struct unit_test_state *uts)
@@ -237,7 +251,6 @@ static int dm_test_acpi_fill_header(struct unit_test_state *uts)
hdr.length = 0x11;
hdr.revision = 0x22;
hdr.checksum = 0x33;
- hdr.creator_revision = 0x44;
acpi_fill_header(&hdr, "ABCD");
ut_asserteq_mem("ABCD", hdr.signature, sizeof(hdr.signature));
@@ -249,11 +262,11 @@ static int dm_test_acpi_fill_header(struct unit_test_state *uts)
sizeof(hdr.oem_table_id));
ut_asserteq(OEM_REVISION, hdr.oem_revision);
ut_asserteq_mem(ASLC_ID, hdr.creator_id, sizeof(hdr.creator_id));
- ut_asserteq(0x44, hdr.creator_revision);
+ ut_asserteq(ASL_REVISION, hdr.creator_revision);
return 0;
}
-DM_TEST(dm_test_acpi_fill_header, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_fill_header, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test ACPI write_tables() */
static int dm_test_acpi_write_tables(struct unit_test_state *uts)
@@ -296,10 +309,12 @@ static int dm_test_acpi_write_tables(struct unit_test_state *uts)
}
ut_asserteq(0, ctx.rsdt->entry[3]);
ut_asserteq(0, ctx.xsdt->entry[3]);
+ unmap_sysmem(buf);
+ free(buf);
return 0;
}
-DM_TEST(dm_test_acpi_write_tables, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_write_tables, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test basic ACPI functions */
static int dm_test_acpi_basic(struct unit_test_state *uts)
@@ -327,7 +342,7 @@ static int dm_test_acpi_basic(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_basic, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_basic, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test setup_ctx_and_base_tables */
static int dm_test_acpi_ctx_and_base_tables(struct unit_test_state *uts)
@@ -373,11 +388,12 @@ static int dm_test_acpi_ctx_and_base_tables(struct unit_test_state *uts)
ut_asserteq(nomap_to_sysmem(rsdt), rsdp->rsdt_address);
ut_asserteq(nomap_to_sysmem(xsdt), rsdp->xsdt_address);
+ unmap_sysmem(buf);
+ free(buf);
return 0;
}
-DM_TEST(dm_test_acpi_ctx_and_base_tables,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_ctx_and_base_tables, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test 'acpi list' command */
static int dm_test_acpi_cmd_list(struct unit_test_state *uts)
@@ -393,7 +409,6 @@ static int dm_test_acpi_cmd_list(struct unit_test_state *uts)
ut_assertok(acpi_write_dev_tables(&ctx));
- console_record_reset();
run_command("acpi list", 0);
ut_assert_nextline("Name Base Size Detail");
ut_assert_nextline("---- ---------------- ----- ----------------------------");
@@ -417,10 +432,58 @@ static int dm_test_acpi_cmd_list(struct unit_test_state *uts)
ut_assert_nextline("DMAR %16lx %5zx v01 U-BOOT U-BOOTBL %x INTL 0",
addr, sizeof(struct acpi_dmar), OEM_REVISION);
ut_assert_console_end();
+ unmap_sysmem(buf);
+ free(buf);
+
+ return 0;
+}
+DM_TEST(dm_test_acpi_cmd_list, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE);
+
+/* Test 'acpi list -c' command */
+static int dm_test_acpi_cmd_list_chksum(struct unit_test_state *uts)
+{
+ struct acpi_ctx ctx;
+ ulong addr;
+ void *buf;
+
+ buf = memalign(16, BUF_SIZE);
+ ut_assertnonnull(buf);
+ addr = map_to_sysmem(buf);
+ ut_assertok(setup_ctx_and_base_tables(uts, &ctx, addr));
+
+ ut_assertok(acpi_write_dev_tables(&ctx));
+
+ run_command("acpi list -c", 0);
+ ut_assert_nextline("Name Base Size Detail");
+ ut_assert_nextline("---- ---------------- ----- ----------------------------");
+ ut_assert_nextline("RSDP %16lx %5zx v02 U-BOOT OK OK", addr,
+ sizeof(struct acpi_rsdp));
+ addr = ALIGN(addr + sizeof(struct acpi_rsdp), 16);
+ ut_assert_nextline("RSDT %16lx %5zx v01 U-BOOT U-BOOTBL %x INTL 0 OK",
+ addr, sizeof(struct acpi_table_header) +
+ 3 * sizeof(u32), OEM_REVISION);
+ addr = ALIGN(addr + sizeof(struct acpi_rsdt), 16);
+ ut_assert_nextline("XSDT %16lx %5zx v01 U-BOOT U-BOOTBL %x INTL 0 OK",
+ addr, sizeof(struct acpi_table_header) +
+ 3 * sizeof(u64), OEM_REVISION);
+ addr = ALIGN(addr + sizeof(struct acpi_xsdt), 64);
+ ut_assert_nextline("DMAR %16lx %5zx v01 U-BOOT U-BOOTBL %x INTL 0 OK",
+ addr, sizeof(struct acpi_dmar), OEM_REVISION);
+ addr = ALIGN(addr + sizeof(struct acpi_dmar), 16);
+ ut_assert_nextline("DMAR %16lx %5zx v01 U-BOOT U-BOOTBL %x INTL 0 OK",
+ addr, sizeof(struct acpi_dmar), OEM_REVISION);
+ addr = ALIGN(addr + sizeof(struct acpi_dmar), 16);
+ ut_assert_nextline("DMAR %16lx %5zx v01 U-BOOT U-BOOTBL %x INTL 0 OK",
+ addr, sizeof(struct acpi_dmar), OEM_REVISION);
+ ut_assert_console_end();
+ ut_assert_console_end();
+ unmap_sysmem(buf);
+ free(buf);
return 0;
}
-DM_TEST(dm_test_acpi_cmd_list, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_cmd_list_chksum,
+ UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE);
/* Test 'acpi dump' command */
static int dm_test_acpi_cmd_dump(struct unit_test_state *uts)
@@ -437,22 +500,22 @@ static int dm_test_acpi_cmd_dump(struct unit_test_state *uts)
ut_assertok(acpi_write_dev_tables(&ctx));
/* First search for a non-existent table */
- console_record_reset();
run_command("acpi dump rdst", 0);
ut_assert_nextline("Table 'RDST' not found");
ut_assert_console_end();
/* Now a real table */
- console_record_reset();
run_command("acpi dump dmar", 0);
addr = ALIGN(nomap_to_sysmem(ctx.xsdt) + sizeof(struct acpi_xsdt), 64);
ut_assert_nextline("DMAR @ %16lx", addr);
ut_assert_nextlines_are_dump(0x30);
ut_assert_console_end();
+ unmap_sysmem(buf);
+ free(buf);
return 0;
}
-DM_TEST(dm_test_acpi_cmd_dump, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_cmd_dump, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE);
/* Test acpi_device_path() */
static int dm_test_acpi_device_path(struct unit_test_state *uts)
@@ -489,7 +552,7 @@ static int dm_test_acpi_device_path(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_device_path, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_device_path, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test acpi_device_status() */
static int dm_test_acpi_device_status(struct unit_test_state *uts)
@@ -501,7 +564,7 @@ static int dm_test_acpi_device_status(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_device_status, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_device_status, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test acpi_fill_ssdt() */
static int dm_test_acpi_fill_ssdt(struct unit_test_state *uts)
@@ -532,7 +595,34 @@ static int dm_test_acpi_fill_ssdt(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_fill_ssdt, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_fill_ssdt, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+
+/* Test acpi_fill_madt() */
+static int dm_test_acpi_fill_madt(struct unit_test_state *uts)
+{
+ struct acpi_ctx ctx;
+ u64 *buf;
+
+ buf = malloc(BUF_SIZE);
+ ut_assertnonnull(buf);
+
+ acpi_reset_items();
+ ctx.current = buf;
+ buf[1] = 'z'; /* sentinel */
+ ut_assertok(acpi_fill_madt_subtbl(&ctx));
+
+ /*
+ * These values come from acpi-test2's acpi-ssdt-test-data property.
+ * This device comes first because of u-boot,acpi-ssdt-order
+ */
+ ut_asserteq(0xdeadbeef, buf[0]);
+
+ ut_asserteq('z', buf[1]);
+
+ return 0;
+}
+
+DM_TEST(dm_test_acpi_fill_madt, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test acpi_inject_dsdt() */
static int dm_test_acpi_inject_dsdt(struct unit_test_state *uts)
@@ -563,7 +653,7 @@ static int dm_test_acpi_inject_dsdt(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_inject_dsdt, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_inject_dsdt, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test 'acpi items' command */
static int dm_test_acpi_cmd_items(struct unit_test_state *uts)
@@ -579,7 +669,6 @@ static int dm_test_acpi_cmd_items(struct unit_test_state *uts)
acpi_reset_items();
ctx.current = buf;
ut_assertok(acpi_fill_ssdt(&ctx));
- console_record_reset();
run_command("acpi items", 0);
ut_assert_nextline("Seq Type Base Size Device/Writer");
ut_assert_nextline("--- ----- -------- ---- -------------");
@@ -590,7 +679,6 @@ static int dm_test_acpi_cmd_items(struct unit_test_state *uts)
acpi_reset_items();
ctx.current = buf;
ut_assertok(acpi_inject_dsdt(&ctx));
- console_record_reset();
run_command("acpi items", 0);
ut_assert_nextlinen("Seq");
ut_assert_nextlinen("---");
@@ -598,7 +686,6 @@ static int dm_test_acpi_cmd_items(struct unit_test_state *uts)
ut_assert_nextline(" 1 dsdt %8lx 2 acpi-test2", addr + 2);
ut_assert_console_end();
- console_record_reset();
run_command("acpi items -d", 0);
ut_assert_nextlinen("Seq");
ut_assert_nextlinen("---");
@@ -609,10 +696,12 @@ static int dm_test_acpi_cmd_items(struct unit_test_state *uts)
ut_assert_nextlines_are_dump(2);
ut_assert_nextline("%s", "");
ut_assert_console_end();
+ unmap_sysmem(buf);
+ free(buf);
return 0;
}
-DM_TEST(dm_test_acpi_cmd_items, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_cmd_items, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE);
/* Test 'acpi set' command */
static int dm_test_acpi_cmd_set(struct unit_test_state *uts)
@@ -623,7 +712,6 @@ static int dm_test_acpi_cmd_set(struct unit_test_state *uts)
gd_set_acpi_start(0);
- console_record_reset();
ut_asserteq(0, gd_acpi_start());
ut_assertok(run_command("acpi set", 0));
ut_assert_nextline("ACPI pointer: 0");
@@ -647,10 +735,12 @@ static int dm_test_acpi_cmd_set(struct unit_test_state *uts)
ut_asserteq(addr, gd_acpi_start());
ut_assert_console_end();
+ unmap_sysmem(buf);
+ free(buf);
return 0;
}
-DM_TEST(dm_test_acpi_cmd_set, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_cmd_set, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE);
/**
* dm_test_write_test_table() - create test ACPI table
@@ -742,6 +832,7 @@ static int dm_test_acpi_find_table(struct unit_test_state *uts)
/* Restore previous ACPI tables */
gd_set_acpi_start(acpi_start);
+ unmap_sysmem(buf);
free(buf);
return 0;
diff --git a/test/dm/acpi_dp.c b/test/dm/acpi_dp.c
index 44bcabda6bc..038806004b5 100644
--- a/test/dm/acpi_dp.c
+++ b/test/dm/acpi_dp.c
@@ -6,9 +6,8 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <dm.h>
-#include <uuid.h>
+#include <u-boot/uuid.h>
#include <acpi/acpigen.h>
#include <acpi/acpi_dp.h>
#include <asm/unaligned.h>
@@ -489,4 +488,4 @@ static int dm_test_acpi_dp_copy(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_dp_copy, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_dp_copy, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/acpigen.c b/test/dm/acpigen.c
index 15b2b6f64a0..ee9517f9c29 100644
--- a/test/dm/acpigen.c
+++ b/test/dm/acpigen.c
@@ -6,11 +6,10 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <dm.h>
#include <irq.h>
#include <malloc.h>
-#include <uuid.h>
+#include <u-boot/uuid.h>
#include <acpi/acpigen.h>
#include <acpi/acpi_device.h>
#include <acpi/acpi_table.h>
@@ -168,7 +167,7 @@ static int dm_test_acpi_interrupt(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_interrupt, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_interrupt, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test emitting a GPIO descriptor */
static int dm_test_acpi_gpio(struct unit_test_state *uts)
@@ -213,7 +212,7 @@ static int dm_test_acpi_gpio(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_gpio, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_gpio, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test emitting a GPIO descriptor with an interrupt */
static int dm_test_acpi_gpio_irq(struct unit_test_state *uts)
@@ -258,7 +257,7 @@ static int dm_test_acpi_gpio_irq(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_gpio_irq, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_gpio_irq, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test emitting either a GPIO or interrupt descriptor */
static int dm_test_acpi_interrupt_or_gpio(struct unit_test_state *uts)
@@ -297,8 +296,7 @@ static int dm_test_acpi_interrupt_or_gpio(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_interrupt_or_gpio,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_interrupt_or_gpio, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test emitting an I2C descriptor */
static int dm_test_acpi_i2c(struct unit_test_state *uts)
@@ -330,7 +328,7 @@ static int dm_test_acpi_i2c(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_i2c, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_i2c, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test emitting a SPI descriptor */
static int dm_test_acpi_spi(struct unit_test_state *uts)
@@ -366,7 +364,7 @@ static int dm_test_acpi_spi(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_spi, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_spi, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test emitting a length */
static int dm_test_acpi_len(struct unit_test_state *uts)
@@ -807,7 +805,7 @@ static int dm_test_acpi_gpio_toggle(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_gpio_toggle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_gpio_toggle, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test writing ACPI code to output power-sequence info */
static int dm_test_acpi_power_seq(struct unit_test_state *uts)
@@ -874,7 +872,7 @@ static int dm_test_acpi_power_seq(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_power_seq, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_power_seq, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test writing values */
static int dm_test_acpi_write_values(struct unit_test_state *uts)
@@ -948,7 +946,7 @@ static int dm_test_acpi_scope(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_acpi_scope, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_acpi_scope, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test writing a resource template */
static int dm_test_acpi_resource_template(struct unit_test_state *uts)
@@ -1744,3 +1742,118 @@ static int dm_test_acpi_write_tsd_package(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_acpi_write_tsd_package, 0);
+
+static int dm_test_acpi_iort_smmu_v3(struct unit_test_state *uts)
+{
+ struct acpi_ctx *ctx;
+ int smmu_offset;
+ u8 *ptr;
+
+ ut_assertok(alloc_context(&ctx));
+ ctx->tab_start = ctx->current;
+ acpi_inc(ctx, sizeof(struct acpi_table_iort));
+
+ ptr = acpigen_get_current(ctx);
+
+ smmu_offset = acpi_iort_add_smmu_v3(ctx,
+ 0xaabbccddeeffULL, // Base address
+ 1, // Flags
+ 0xffeeddccaabbULL, // VATOS address
+ 0, // SMMUv3 Model
+ 3, // Event
+ 4, // Pri
+ 5, // Gerror
+ 6, // Sync
+ 7, // Proximity domain
+ 8, // DevIDMappingIndex
+ 0,
+ NULL);
+ ut_assert(smmu_offset);
+
+ ut_asserteq(ACPI_IORT_NODE_SMMU_V3, ptr[0]);
+ ut_asserteq(68, get_unaligned((u16 *)(ptr + 1)));
+ ut_asserteq(0, get_unaligned((u16 *)(ptr + 4)));
+ ut_asserteq(0, get_unaligned((u32 *)(ptr + 8)));
+ ut_asserteq(0, get_unaligned((u32 *)(ptr + 12)));
+
+ ut_asserteq_64(0xaabbccddeeffULL, get_unaligned((u64 *)(ptr + 16)));
+ ut_asserteq(1, get_unaligned((u32 *)(ptr + 24)));
+ ut_asserteq(0, get_unaligned((u32 *)(ptr + 28)));
+ ut_asserteq_64(0xffeeddccaabbULL, get_unaligned((u64 *)(ptr + 32)));
+ ut_asserteq(0, get_unaligned((u32 *)(ptr + 40)));
+ ut_asserteq(3, get_unaligned((u32 *)(ptr + 44)));
+ ut_asserteq(4, get_unaligned((u32 *)(ptr + 48)));
+ ut_asserteq(5, get_unaligned((u32 *)(ptr + 52)));
+ ut_asserteq(6, get_unaligned((u32 *)(ptr + 56)));
+ ut_asserteq(7, get_unaligned((u32 *)(ptr + 60)));
+ ut_asserteq(8, get_unaligned((u32 *)(ptr + 64)));
+
+ free_context(&ctx);
+
+ return 0;
+}
+DM_TEST(dm_test_acpi_iort_smmu_v3, 0);
+
+static int dm_test_acpi_iort_rc(struct unit_test_state *uts)
+{
+ struct acpi_ctx *ctx;
+ int its_group_offset, offset;
+ u8 *ptr;
+
+ ut_assertok(alloc_context(&ctx));
+ ctx->tab_start = ctx->current;
+ acpi_inc(ctx, sizeof(struct acpi_table_iort));
+
+ u32 identifiers[] = { 0 };
+
+ its_group_offset = acpi_iort_add_its_group(ctx, ARRAY_SIZE(identifiers),
+ identifiers);
+
+ ptr = acpigen_get_current(ctx);
+
+ struct acpi_iort_id_mapping map_rc[] = {
+ {0, 0xfff, 0, its_group_offset, 0},
+ {0x1000, 0xffff, 0x1000, its_group_offset, 0}
+ };
+
+ offset = acpi_iort_add_rc(ctx,
+ 0xaabbccddeeffULL, // Mem Access Properties
+ 2, // ATS attributes
+ 3, // PCI segment
+ 4, // Memory address size limit
+ ARRAY_SIZE(map_rc),
+ map_rc);
+
+ ut_assert(offset);
+ ut_asserteq(ACPI_IORT_NODE_PCI_ROOT_COMPLEX, ptr[0]);
+ ut_asserteq(36 + ARRAY_SIZE(map_rc) * sizeof(struct acpi_iort_id_mapping),
+ get_unaligned((u16 *)(ptr + 1)));
+ ut_asserteq(0, get_unaligned((u16 *)(ptr + 4)));
+ ut_asserteq(2, get_unaligned((u32 *)(ptr + 8)));
+ ut_asserteq(36, get_unaligned((u32 *)(ptr + 12)));
+
+ ut_asserteq_64(0xaabbccddeeffULL, get_unaligned((u64 *)(ptr + 16)));
+ ut_asserteq(2, get_unaligned((u32 *)(ptr + 24)));
+ ut_asserteq(3, get_unaligned((u32 *)(ptr + 28)));
+ ut_asserteq(4, ptr[32]);
+ ut_asserteq(0, ptr[33]);
+ ut_asserteq(0, ptr[34]);
+ ut_asserteq(0, ptr[35]);
+
+ ut_asserteq(0, get_unaligned((u32 *)(ptr + 36)));
+ ut_asserteq(0xfff, get_unaligned((u32 *)(ptr + 40)));
+ ut_asserteq(0, get_unaligned((u32 *)(ptr + 44)));
+ ut_asserteq(its_group_offset, get_unaligned((u32 *)(ptr + 48)));
+ ut_asserteq(0, get_unaligned((u32 *)(ptr + 52)));
+
+ ut_asserteq(0x1000, get_unaligned((u32 *)(ptr + 56)));
+ ut_asserteq(0xffff, get_unaligned((u32 *)(ptr + 60)));
+ ut_asserteq(0x1000, get_unaligned((u32 *)(ptr + 64)));
+ ut_asserteq(its_group_offset, get_unaligned((u32 *)(ptr + 68)));
+ ut_asserteq(0, get_unaligned((u32 *)(ptr + 72)));
+
+ free_context(&ctx);
+
+ return 0;
+}
+DM_TEST(dm_test_acpi_iort_rc, 0); \ No newline at end of file
diff --git a/test/dm/adc.c b/test/dm/adc.c
index 740167e16b8..e27302b449e 100644
--- a/test/dm/adc.c
+++ b/test/dm/adc.c
@@ -6,7 +6,6 @@
* Przemyslaw Marczak <p.marczak@samsung.com>
*/
-#include <common.h>
#include <adc.h>
#include <dm.h>
#include <dm/root.h>
@@ -33,7 +32,7 @@ static int dm_test_adc_bind(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_adc_bind, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_adc_bind, UTF_SCAN_FDT);
static int dm_test_adc_wrong_channel_selection(struct unit_test_state *uts)
{
@@ -44,7 +43,7 @@ static int dm_test_adc_wrong_channel_selection(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_adc_wrong_channel_selection, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_adc_wrong_channel_selection, UTF_SCAN_FDT);
static int dm_test_adc_supply(struct unit_test_state *uts)
{
@@ -80,7 +79,7 @@ static int dm_test_adc_supply(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_adc_supply, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_adc_supply, UTF_SCAN_FDT);
struct adc_channel adc_channel_test_data[] = {
{ 0, SANDBOX_ADC_CHANNEL0_DATA },
@@ -105,7 +104,7 @@ static int dm_test_adc_single_channel_conversion(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_adc_single_channel_conversion, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_adc_single_channel_conversion, UTF_SCAN_FDT);
static int dm_test_adc_multi_channel_conversion(struct unit_test_state *uts)
{
@@ -128,7 +127,7 @@ static int dm_test_adc_multi_channel_conversion(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_adc_multi_channel_conversion, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_adc_multi_channel_conversion, UTF_SCAN_FDT);
static int dm_test_adc_single_channel_shot(struct unit_test_state *uts)
{
@@ -144,7 +143,7 @@ static int dm_test_adc_single_channel_shot(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_adc_single_channel_shot, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_adc_single_channel_shot, UTF_SCAN_FDT);
static int dm_test_adc_multi_channel_shot(struct unit_test_state *uts)
{
@@ -164,7 +163,7 @@ static int dm_test_adc_multi_channel_shot(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_adc_multi_channel_shot, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_adc_multi_channel_shot, UTF_SCAN_FDT);
static const int dm_test_adc_uV_data[SANDBOX_ADC_CHANNELS] = {
((u64)SANDBOX_ADC_CHANNEL0_DATA * SANDBOX_BUCK2_INITIAL_EXPECTED_UV) /
@@ -195,4 +194,4 @@ static int dm_test_adc_raw_to_uV(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_adc_raw_to_uV, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_adc_raw_to_uV, UTF_SCAN_FDT);
diff --git a/test/dm/audio.c b/test/dm/audio.c
index add15ae20e0..f4d3346c90a 100644
--- a/test/dm/audio.c
+++ b/test/dm/audio.c
@@ -4,7 +4,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <audio_codec.h>
#include <dm.h>
#include <dm/test.h>
@@ -32,4 +31,4 @@ static int dm_test_audio(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_audio, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_audio, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/axi.c b/test/dm/axi.c
index dc029df5e44..45c46a19739 100644
--- a/test/dm/axi.c
+++ b/test/dm/axi.c
@@ -4,7 +4,6 @@
* Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
*/
-#include <common.h>
#include <axi.h>
#include <dm.h>
#include <log.h>
@@ -22,8 +21,7 @@ static int dm_test_axi_base(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_axi_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_axi_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that sandbox PCI bus numbering works correctly */
static int dm_test_axi_busnum(struct unit_test_state *uts)
@@ -34,8 +32,7 @@ static int dm_test_axi_busnum(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_axi_busnum, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_axi_busnum, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that we can use the store device correctly */
static int dm_test_axi_store(struct unit_test_state *uts)
@@ -75,5 +72,4 @@ static int dm_test_axi_store(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_axi_store, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_axi_store, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/blk.c b/test/dm/blk.c
index 799f1e4dc75..aa5cbc63777 100644
--- a/test/dm/blk.c
+++ b/test/dm/blk.c
@@ -3,7 +3,6 @@
* Copyright (C) 2015 Google, Inc
*/
-#include <common.h>
#include <blk.h>
#include <dm.h>
#include <part.h>
@@ -44,7 +43,7 @@ static int dm_test_blk_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_blk_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_blk_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int count_blk_devices(void)
{
@@ -93,7 +92,7 @@ static int dm_test_blk_usb(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_blk_usb, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_blk_usb, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that we can find block devices without probing them */
static int dm_test_blk_find(struct unit_test_state *uts)
@@ -115,7 +114,7 @@ static int dm_test_blk_find(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_blk_find, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_blk_find, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that block device numbering works as expected */
static int dm_test_blk_devnum(struct unit_test_state *uts)
@@ -150,7 +149,7 @@ static int dm_test_blk_devnum(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_blk_devnum, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_blk_devnum, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that we can get a block from its parent */
static int dm_test_blk_get_from_parent(struct unit_test_state *uts)
@@ -168,7 +167,7 @@ static int dm_test_blk_get_from_parent(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_blk_get_from_parent, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_blk_get_from_parent, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test iteration through block devices */
static int dm_test_blk_iter(struct unit_test_state *uts)
@@ -223,7 +222,7 @@ static int dm_test_blk_iter(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_blk_iter, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_blk_iter, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test finding fixed/removable block devices */
static int dm_test_blk_flags(struct unit_test_state *uts)
@@ -288,7 +287,7 @@ static int dm_test_blk_flags(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_blk_flags, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_blk_flags, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test blk_foreach() and friend */
static int dm_test_blk_foreach(struct unit_test_state *uts)
@@ -334,4 +333,4 @@ static int dm_test_blk_foreach(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_blk_foreach, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_blk_foreach, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/blkmap.c b/test/dm/blkmap.c
index 7a163d6eaef..a6a0b4d4e20 100644
--- a/test/dm/blkmap.c
+++ b/test/dm/blkmap.c
@@ -4,7 +4,6 @@
* Author: Tobias Waldekranz <tobias@waldekranz.com>
*/
-#include <common.h>
#include <blk.h>
#include <blkmap.h>
#include <dm.h>
@@ -166,8 +165,6 @@ 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();
@@ -198,4 +195,4 @@ static int dm_test_cmd_blkmap(struct unit_test_state *uts)
ut_assert_console_end();
return 0;
}
-DM_TEST(dm_test_cmd_blkmap, 0);
+DM_TEST(dm_test_cmd_blkmap, UTF_CONSOLE);
diff --git a/test/dm/bootcount.c b/test/dm/bootcount.c
index b77b472d1f2..f66927a5d37 100644
--- a/test/dm/bootcount.c
+++ b/test/dm/bootcount.c
@@ -3,7 +3,6 @@
* (C) 2018 Theobroma Systems Design und Consulting GmbH
*/
-#include <common.h>
#include <dm.h>
#include <bootcount.h>
#include <log.h>
@@ -36,8 +35,7 @@ static int dm_test_bootcount_rtc(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_bootcount_rtc, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_bootcount_rtc, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_bootcount_syscon_four_bytes(struct unit_test_state *uts)
{
@@ -56,9 +54,8 @@ static int dm_test_bootcount_syscon_four_bytes(struct unit_test_state *uts)
return 0;
}
-
DM_TEST(dm_test_bootcount_syscon_four_bytes,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_bootcount_syscon_two_bytes(struct unit_test_state *uts)
{
@@ -77,6 +74,4 @@ static int dm_test_bootcount_syscon_two_bytes(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_bootcount_syscon_two_bytes,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_bootcount_syscon_two_bytes, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/bus.c b/test/dm/bus.c
index 89a6aa6554c..166a8427406 100644
--- a/test/dm/bus.c
+++ b/test/dm/bus.c
@@ -3,7 +3,6 @@
* Copyright (c) 2014 Google, Inc
*/
-#include <common.h>
#ifdef CONFIG_SANDBOX
#include <log.h>
#include <os.h>
@@ -15,6 +14,7 @@
#include <dm/test.h>
#include <dm/uclass-internal.h>
#include <dm/util.h>
+#include <linux/list.h>
#include <test/test.h>
#include <test/ut.h>
@@ -28,20 +28,20 @@ static int dm_test_bus_children(struct unit_test_state *uts)
struct uclass *uc;
ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc));
- ut_asserteq(num_devices, list_count_items(&uc->dev_head));
+ ut_asserteq(num_devices, list_count_nodes(&uc->dev_head));
/* Probe the bus, which should yield 3 more devices */
ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
num_devices += 3;
ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc));
- ut_asserteq(num_devices, list_count_items(&uc->dev_head));
+ ut_asserteq(num_devices, list_count_nodes(&uc->dev_head));
ut_assert(!dm_check_devices(uts, num_devices));
return 0;
}
-DM_TEST(dm_test_bus_children, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_bus_children, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test our functions for accessing children */
static int dm_test_bus_children_funcs(struct unit_test_state *uts)
@@ -81,7 +81,7 @@ static int dm_test_bus_children_funcs(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_bus_children_funcs, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_bus_children_funcs, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_bus_children_of_offset(struct unit_test_state *uts)
{
@@ -105,7 +105,7 @@ static int dm_test_bus_children_of_offset(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_bus_children_of_offset,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_FLAT_TREE);
/* Test that we can iterate through children */
static int dm_test_bus_children_iterators(struct unit_test_state *uts)
@@ -136,7 +136,7 @@ static int dm_test_bus_children_iterators(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_bus_children_iterators,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that the bus can store data about each child */
static int test_bus_parent_data(struct unit_test_state *uts)
@@ -203,7 +203,7 @@ static int dm_test_bus_parent_data(struct unit_test_state *uts)
{
return test_bus_parent_data(uts);
}
-DM_TEST(dm_test_bus_parent_data, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_bus_parent_data, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* As above but the size is controlled by the uclass */
static int dm_test_bus_parent_data_uclass(struct unit_test_state *uts)
@@ -233,7 +233,7 @@ static int dm_test_bus_parent_data_uclass(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_bus_parent_data_uclass,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that the bus ops are called when a child is probed/removed */
static int dm_test_bus_parent_ops(struct unit_test_state *uts)
@@ -270,7 +270,7 @@ static int dm_test_bus_parent_ops(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_bus_parent_ops, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_bus_parent_ops, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int test_bus_parent_plat(struct unit_test_state *uts)
{
@@ -345,7 +345,7 @@ static int dm_test_bus_parent_plat(struct unit_test_state *uts)
{
return test_bus_parent_plat(uts);
}
-DM_TEST(dm_test_bus_parent_plat, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_bus_parent_plat, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* As above but the size is controlled by the uclass */
static int dm_test_bus_parent_plat_uclass(struct unit_test_state *uts)
@@ -374,7 +374,7 @@ static int dm_test_bus_parent_plat_uclass(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_bus_parent_plat_uclass,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that the child post_bind method is called */
static int dm_test_bus_child_post_bind(struct unit_test_state *uts)
@@ -395,7 +395,7 @@ static int dm_test_bus_child_post_bind(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_bus_child_post_bind, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_bus_child_post_bind, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that the child post_bind method is called */
static int dm_test_bus_child_post_bind_uclass(struct unit_test_state *uts)
@@ -417,7 +417,7 @@ static int dm_test_bus_child_post_bind_uclass(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_bus_child_post_bind_uclass,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
/*
* Test that the bus' uclass' child_pre_probe() is called before the
@@ -451,7 +451,7 @@ static int dm_test_bus_child_pre_probe_uclass(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_bus_child_pre_probe_uclass,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
/*
* Test that the bus' uclass' child_post_probe() is called after the
@@ -484,4 +484,4 @@ static int dm_test_bus_child_post_probe_uclass(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_bus_child_post_probe_uclass,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/button.c b/test/dm/button.c
index 830d96fbef3..3612f308f02 100644
--- a/test/dm/button.c
+++ b/test/dm/button.c
@@ -5,7 +5,6 @@
* Based on led.c
*/
-#include <common.h>
#include <dm.h>
#include <adc.h>
#include <button.h>
@@ -38,7 +37,7 @@ static int dm_test_button_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_button_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_button_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test of the button uclass using the button_gpio driver */
static int dm_test_button_gpio(struct unit_test_state *uts)
@@ -63,7 +62,7 @@ static int dm_test_button_gpio(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_button_gpio, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_button_gpio, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test obtaining a BUTTON by label */
static int dm_test_button_label(struct unit_test_state *uts)
@@ -84,7 +83,7 @@ static int dm_test_button_label(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_button_label, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_button_label, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test button has linux,code */
static int dm_test_button_linux_code(struct unit_test_state *uts)
@@ -96,7 +95,7 @@ static int dm_test_button_linux_code(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_button_linux_code, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_button_linux_code, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test adc-keys driver */
static int dm_test_button_keys_adc(struct unit_test_state *uts)
@@ -130,7 +129,7 @@ static int dm_test_button_keys_adc(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_button_keys_adc, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_button_keys_adc, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test of the button uclass using the button_gpio driver */
static int dm_test_button_cmd(struct unit_test_state *uts)
@@ -226,4 +225,4 @@ static int dm_test_button_cmd(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_button_cmd, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_button_cmd, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/cache.c b/test/dm/cache.c
index bbd8f98d007..e03e029f1dd 100644
--- a/test/dm/cache.c
+++ b/test/dm/cache.c
@@ -3,7 +3,6 @@
* Copyright (C) 2019 Intel Corporation <www.intel.com>
*/
-#include <common.h>
#include <dm.h>
#include <dm/test.h>
@@ -19,4 +18,4 @@ static int dm_test_reset(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_reset, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_reset, UTF_SCAN_FDT);
diff --git a/test/dm/clk.c b/test/dm/clk.c
index 57fabbdce08..790968e6477 100644
--- a/test/dm/clk.c
+++ b/test/dm/clk.c
@@ -3,7 +3,6 @@
* Copyright (C) 2015 Google, Inc
*/
-#include <common.h>
#include <clk.h>
#include <dm.h>
#include <log.h>
@@ -47,8 +46,7 @@ static int dm_test_clk_base(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_clk_base, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_clk_base, UTF_SCAN_FDT);
static int dm_test_clk(struct unit_test_state *uts)
{
@@ -188,7 +186,7 @@ static int dm_test_clk(struct unit_test_state *uts)
ut_assertok(device_remove(dev_test, DM_REMOVE_NORMAL));
return 0;
}
-DM_TEST(dm_test_clk, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_clk, UTF_SCAN_FDT);
static int dm_test_clk_bulk(struct unit_test_state *uts)
{
@@ -226,4 +224,4 @@ static int dm_test_clk_bulk(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_clk_bulk, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_clk_bulk, UTF_SCAN_FDT);
diff --git a/test/dm/clk_ccf.c b/test/dm/clk_ccf.c
index 61dad8d8527..ac56f17b775 100644
--- a/test/dm/clk_ccf.c
+++ b/test/dm/clk_ccf.c
@@ -4,7 +4,6 @@
* Lukasz Majewski, DENX Software Engineering, lukma@denx.de
*/
-#include <common.h>
#include <clk.h>
#include <dm.h>
#include <asm/clk.h>
@@ -209,5 +208,4 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
return 1;
}
-
-DM_TEST(dm_test_clk_ccf, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_clk_ccf, UTF_SCAN_FDT);
diff --git a/test/dm/core.c b/test/dm/core.c
index 7f3f8d183bc..959b834576f 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -5,7 +5,6 @@
* Copyright (c) 2013 Google, Inc
*/
-#include <common.h>
#include <errno.h>
#include <dm.h>
#include <fdtdec.h>
@@ -17,6 +16,7 @@
#include <dm/util.h>
#include <dm/test.h>
#include <dm/uclass-internal.h>
+#include <linux/list.h>
#include <test/test.h>
#include <test/ut.h>
@@ -124,15 +124,15 @@ static int dm_test_autobind(struct unit_test_state *uts)
* device with no children.
*/
ut_assert(uts->root);
- ut_asserteq(1, list_count_items(gd->uclass_root));
- ut_asserteq(0, list_count_items(&gd->dm_root->child_head));
+ ut_asserteq(1, list_count_nodes(gd->uclass_root));
+ ut_asserteq(0, list_count_nodes(&gd->dm_root->child_head));
ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]);
ut_assertok(dm_scan_plat(false));
/* We should have our test class now at least, plus more children */
- ut_assert(1 < list_count_items(gd->uclass_root));
- ut_assert(0 < list_count_items(&gd->dm_root->child_head));
+ ut_assert(1 < list_count_nodes(gd->uclass_root));
+ ut_assert(0 < list_count_nodes(&gd->dm_root->child_head));
/* Our 3 dm_test_infox children should be bound to the test uclass */
ut_asserteq(3, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]);
@@ -175,7 +175,7 @@ static int dm_test_autobind_uclass_pdata_alloc(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_autobind_uclass_pdata_alloc, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_autobind_uclass_pdata_alloc, UTF_SCAN_PDATA);
/* compare node names ignoring the unit address */
static int dm_test_compare_node_name(struct unit_test_state *uts)
@@ -186,10 +186,29 @@ static int dm_test_compare_node_name(struct unit_test_state *uts)
ut_assert(ofnode_valid(node));
ut_assert(ofnode_name_eq(node, "mmio-bus"));
+ ut_assert(!ofnode_name_eq(node, "mmio-bus@0"));
+
return 0;
}
+DM_TEST(dm_test_compare_node_name, UTF_SCAN_PDATA);
-DM_TEST(dm_test_compare_node_name, UT_TESTF_SCAN_PDATA);
+/* compare node names ignoring the unit address */
+static int dm_test_compare_node_name_unit(struct unit_test_state *uts)
+{
+ ofnode node;
+
+ node = ofnode_path("/mmio-bus@0");
+ ut_assert(ofnode_valid(node));
+ ut_assert(ofnode_name_eq_unit(node, "mmio-bus"));
+
+ ut_assert(ofnode_name_eq_unit(node, "mmio-bus@0"));
+ ut_assert(!ofnode_name_eq_unit(node, "mmio-bus@1"));
+ ut_assert(!ofnode_name_eq_unit(node, "mmio-bu"));
+ ut_assert(!ofnode_name_eq_unit(node, "mmio-buss@0"));
+
+ return 0;
+}
+DM_TEST(dm_test_compare_node_name_unit, UTF_SCAN_PDATA);
/* Test that binding with uclass plat setting occurs correctly */
static int dm_test_autobind_uclass_pdata_valid(struct unit_test_state *uts)
@@ -215,7 +234,7 @@ static int dm_test_autobind_uclass_pdata_valid(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_autobind_uclass_pdata_valid, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_autobind_uclass_pdata_valid, UTF_SCAN_PDATA);
/* Test that autoprobe finds all the expected devices */
static int dm_test_autoprobe(struct unit_test_state *uts)
@@ -282,7 +301,7 @@ static int dm_test_autoprobe(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_autoprobe, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_autoprobe, UTF_SCAN_PDATA);
/* Check that we see the correct plat in each device */
static int dm_test_plat(struct unit_test_state *uts)
@@ -300,7 +319,7 @@ static int dm_test_plat(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_plat, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_plat, UTF_SCAN_PDATA);
/* Test that we can bind, probe, remove, unbind a driver */
static int dm_test_lifecycle(struct unit_test_state *uts)
@@ -369,7 +388,7 @@ static int dm_test_lifecycle(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_lifecycle, UT_TESTF_SCAN_PDATA | UT_TESTF_PROBE_TEST);
+DM_TEST(dm_test_lifecycle, UTF_SCAN_PDATA | UTF_PROBE_TEST);
/* Test that we can bind/unbind and the lists update correctly */
static int dm_test_ordering(struct unit_test_state *uts)
@@ -424,7 +443,7 @@ static int dm_test_ordering(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ordering, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_ordering, UTF_SCAN_PDATA);
/* Check that we can perform operations on a device (do a ping) */
int dm_check_operations(struct unit_test_state *uts, struct udevice *dev,
@@ -482,7 +501,7 @@ static int dm_test_operations(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_operations, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_operations, UTF_SCAN_PDATA);
/* Remove all drivers and check that things work */
static int dm_test_remove(struct unit_test_state *uts)
@@ -504,7 +523,7 @@ static int dm_test_remove(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_remove, UT_TESTF_SCAN_PDATA | UT_TESTF_PROBE_TEST);
+DM_TEST(dm_test_remove, UTF_SCAN_PDATA | UTF_PROBE_TEST);
/* Remove and recreate everything, check for memory leaks */
static int dm_test_leak(struct unit_test_state *uts)
@@ -1000,6 +1019,56 @@ static int dm_test_remove_vital(struct unit_test_state *uts)
}
DM_TEST(dm_test_remove_vital, 0);
+/* Test removal of 'active' devices */
+static int dm_test_remove_active(struct unit_test_state *uts)
+{
+ struct udevice *normal, *dma, *vital, *dma_vital;
+
+ /* Skip the behaviour in test_post_probe() */
+ uts->skip_post_probe = 1;
+
+ ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
+ &normal));
+ ut_assertnonnull(normal);
+
+ ut_assertok(device_bind_by_name(uts->root, false, &driver_info_act_dma,
+ &dma));
+ ut_assertnonnull(dma);
+
+ ut_assertok(device_bind_by_name(uts->root, false,
+ &driver_info_vital_clk, &vital));
+ ut_assertnonnull(vital);
+
+ ut_assertok(device_bind_by_name(uts->root, false,
+ &driver_info_act_dma_vital_clk,
+ &dma_vital));
+ ut_assertnonnull(dma_vital);
+
+ /* Probe the devices */
+ ut_assertok(device_probe(normal));
+ ut_assertok(device_probe(dma));
+ ut_assertok(device_probe(vital));
+ ut_assertok(device_probe(dma_vital));
+
+ /* Check that devices are active right now */
+ ut_asserteq(true, device_active(normal));
+ ut_asserteq(true, device_active(dma));
+ ut_asserteq(true, device_active(vital));
+ ut_asserteq(true, device_active(dma_vital));
+
+ /* Remove active devices in an ordered way */
+ dm_remove_devices_active();
+
+ /* Check that all devices are inactive right now */
+ ut_asserteq(true, device_active(normal));
+ ut_asserteq(false, device_active(dma));
+ ut_asserteq(true, device_active(vital));
+ ut_asserteq(false, device_active(dma_vital));
+
+ return 0;
+}
+DM_TEST(dm_test_remove_active, 0);
+
static int dm_test_uclass_before_ready(struct unit_test_state *uts)
{
struct uclass *uc;
@@ -1007,7 +1076,6 @@ static int dm_test_uclass_before_ready(struct unit_test_state *uts)
ut_assertok(uclass_get(UCLASS_TEST, &uc));
gd->dm_root = NULL;
- gd->dm_root_f = NULL;
memset(&gd->uclass_root, '\0', sizeof(gd->uclass_root));
ut_asserteq_ptr(NULL, uclass_find(UCLASS_TEST));
@@ -1034,7 +1102,7 @@ static int dm_test_uclass_devices_find(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_uclass_devices_find, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_uclass_devices_find, UTF_SCAN_PDATA);
static int dm_test_uclass_devices_find_by_name(struct unit_test_state *uts)
{
@@ -1071,7 +1139,7 @@ static int dm_test_uclass_devices_find_by_name(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_uclass_devices_find_by_name, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_uclass_devices_find_by_name, UTF_SCAN_FDT);
static int dm_test_uclass_devices_get(struct unit_test_state *uts)
{
@@ -1087,7 +1155,7 @@ static int dm_test_uclass_devices_get(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_uclass_devices_get, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_uclass_devices_get, UTF_SCAN_PDATA);
static int dm_test_uclass_devices_get_by_name(struct unit_test_state *uts)
{
@@ -1130,7 +1198,7 @@ static int dm_test_uclass_devices_get_by_name(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_uclass_devices_get_by_name, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_uclass_devices_get_by_name, UTF_SCAN_FDT);
static int dm_test_device_get_uclass_id(struct unit_test_state *uts)
{
@@ -1141,7 +1209,7 @@ static int dm_test_device_get_uclass_id(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_device_get_uclass_id, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_device_get_uclass_id, UTF_SCAN_PDATA);
static int dm_test_uclass_names(struct unit_test_state *uts)
{
@@ -1152,7 +1220,7 @@ static int dm_test_uclass_names(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_uclass_names, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_uclass_names, UTF_SCAN_PDATA);
static int dm_test_inactive_child(struct unit_test_state *uts)
{
@@ -1182,7 +1250,7 @@ static int dm_test_inactive_child(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_inactive_child, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_inactive_child, UTF_SCAN_PDATA);
/* Make sure all bound devices have a sequence number */
static int dm_test_all_have_seq(struct unit_test_state *uts)
@@ -1201,7 +1269,7 @@ static int dm_test_all_have_seq(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_all_have_seq, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_all_have_seq, UTF_SCAN_PDATA);
#if CONFIG_IS_ENABLED(DM_DMA)
static int dm_test_dma_offset(struct unit_test_state *uts)
@@ -1232,7 +1300,7 @@ static int dm_test_dma_offset(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_dma_offset, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_dma_offset, UTF_SCAN_PDATA | UTF_SCAN_FDT);
#endif
/* Test dm_get_stats() */
@@ -1246,7 +1314,7 @@ static int dm_test_get_stats(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_get_stats, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_get_stats, UTF_SCAN_FDT);
/* Test uclass_find_device_by_name() */
static int dm_test_uclass_find_device(struct unit_test_state *uts)
@@ -1261,7 +1329,7 @@ static int dm_test_uclass_find_device(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_uclass_find_device, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_uclass_find_device, UTF_SCAN_FDT);
/* Test getting information about tags attached to devices */
static int dm_test_dev_get_attach(struct unit_test_state *uts)
@@ -1289,7 +1357,7 @@ static int dm_test_dev_get_attach(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_dev_get_attach, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_dev_get_attach, UTF_SCAN_FDT);
/* Test getting information about tags attached to bus devices */
static int dm_test_dev_get_attach_bus(struct unit_test_state *uts)
@@ -1341,7 +1409,7 @@ static int dm_test_dev_get_attach_bus(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_dev_get_attach_bus, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_dev_get_attach_bus, UTF_SCAN_FDT);
/* Test getting information about tags attached to bus devices */
static int dm_test_dev_get_mem(struct unit_test_state *uts)
@@ -1352,4 +1420,26 @@ static int dm_test_dev_get_mem(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_dev_get_mem, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_dev_get_mem, UTF_SCAN_FDT);
+
+/* Test uclass_try_first_device() */
+static int dm_test_try_first_device(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+
+ /* Check that it doesn't create a device or uclass */
+ ut_assertnull(uclass_find(UCLASS_TEST));
+ ut_assertnull(uclass_try_first_device(UCLASS_TEST));
+ ut_assertnull(uclass_try_first_device(UCLASS_TEST));
+ ut_assertnull(uclass_find(UCLASS_TEST));
+
+ /* Create a test device */
+ ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
+ &dev));
+ dev = uclass_try_first_device(UCLASS_TEST);
+ ut_assertnonnull(dev);
+ ut_asserteq(UCLASS_TEST, device_get_uclass_id(dev));
+
+ return 0;
+}
+DM_TEST(dm_test_try_first_device, 0);
diff --git a/test/dm/cpu.c b/test/dm/cpu.c
index 5734cd0a92d..9b2f90ee1e5 100644
--- a/test/dm/cpu.c
+++ b/test/dm/cpu.c
@@ -4,7 +4,6 @@
* Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
*/
-#include <common.h>
#include <dm.h>
#include <log.h>
#include <dm/test.h>
@@ -44,7 +43,8 @@ static int dm_test_cpu(struct unit_test_state *uts)
ut_assertok(cpu_get_vendor(dev, text, sizeof(text)));
ut_assertok(strcmp(text, "Languid Example Garbage Inc."));
+ ut_assertok(cpu_release_core(dev, 0));
+
return 0;
}
-
-DM_TEST(dm_test_cpu, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_cpu, UTF_SCAN_FDT);
diff --git a/test/dm/cros_ec.c b/test/dm/cros_ec.c
index 30cb70e0882..089f6670a3f 100644
--- a/test/dm/cros_ec.c
+++ b/test/dm/cros_ec.c
@@ -3,7 +3,6 @@
* Copyright 2021 Google LLC
*/
-#include <common.h>
#include <cros_ec.h>
#include <dm.h>
#include <asm/test.h>
@@ -29,7 +28,7 @@ static int dm_test_cros_ec_hello(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_cros_ec_hello, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_cros_ec_hello, UTF_SCAN_FDT);
static int dm_test_cros_ec_sku_id(struct unit_test_state *uts)
{
@@ -39,14 +38,13 @@ static int dm_test_cros_ec_sku_id(struct unit_test_state *uts)
ut_asserteq(1234, cros_ec_get_sku_id(dev));
/* try the command */
- console_record_reset();
ut_assertok(run_command("crosec sku", 0));
ut_assert_nextline("1234");
ut_assert_console_end();
return 0;
}
-DM_TEST(dm_test_cros_ec_sku_id, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_cros_ec_sku_id, UTF_SCAN_FDT | UTF_CONSOLE);
static int dm_test_cros_ec_features(struct unit_test_state *uts)
{
@@ -65,7 +63,6 @@ static int dm_test_cros_ec_features(struct unit_test_state *uts)
ut_asserteq(true, cros_ec_check_feature(dev, EC_FEATURE_ISH));
/* try the command */
- console_record_reset();
ut_assertok(run_command("crosec features", 0));
ut_assert_nextline("flash");
ut_assert_nextline("i2c");
@@ -76,7 +73,7 @@ static int dm_test_cros_ec_features(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_cros_ec_features, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_cros_ec_features, UTF_SCAN_FDT | UTF_CONSOLE);
static int dm_test_cros_ec_switches(struct unit_test_state *uts)
{
@@ -86,7 +83,6 @@ static int dm_test_cros_ec_switches(struct unit_test_state *uts)
ut_asserteq(0, cros_ec_get_switches(dev));
/* try the command */
- console_record_reset();
ut_assertok(run_command("crosec switches", 0));
ut_assert_console_end();
@@ -95,14 +91,13 @@ static int dm_test_cros_ec_switches(struct unit_test_state *uts)
ut_asserteq(EC_SWITCH_LID_OPEN, cros_ec_get_switches(dev));
/* try the command */
- console_record_reset();
ut_assertok(run_command("crosec switches", 0));
ut_assert_nextline("lid open");
ut_assert_console_end();
return 0;
}
-DM_TEST(dm_test_cros_ec_switches, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_cros_ec_switches, UTF_SCAN_FDT | UTF_CONSOLE);
static int dm_test_cros_ec_events(struct unit_test_state *uts)
{
@@ -114,7 +109,6 @@ static int dm_test_cros_ec_events(struct unit_test_state *uts)
ut_asserteq(0, events);
/* try the command */
- console_record_reset();
ut_assertok(run_command("crosec events", 0));
ut_assert_nextline("00000000");
ut_assert_console_end();
@@ -125,7 +119,6 @@ static int dm_test_cros_ec_events(struct unit_test_state *uts)
ut_asserteq(EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN), events);
/* try the command */
- console_record_reset();
ut_assertok(run_command("crosec events", 0));
ut_assert_nextline("00000002");
ut_assert_nextline("lid_open");
@@ -139,7 +132,7 @@ static int dm_test_cros_ec_events(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_cros_ec_events, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_cros_ec_events, UTF_SCAN_FDT | UTF_CONSOLE);
static int dm_test_cros_ec_vstore(struct unit_test_state *uts)
{
@@ -175,4 +168,4 @@ static int dm_test_cros_ec_vstore(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_cros_ec_vstore, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_cros_ec_vstore, UTF_SCAN_FDT);
diff --git a/test/dm/cros_ec_pwm.c b/test/dm/cros_ec_pwm.c
index f8d6e1e6c40..0b6ca8b8861 100644
--- a/test/dm/cros_ec_pwm.c
+++ b/test/dm/cros_ec_pwm.c
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: GPL-2.0+
-#include <common.h>
#include <cros_ec.h>
#include <dm.h>
#include <pwm.h>
@@ -57,4 +56,4 @@ static int dm_test_cros_ec_pwm(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_cros_ec_pwm, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_cros_ec_pwm, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/devres.c b/test/dm/devres.c
index 3df0f64362d..efc5c72ae2a 100644
--- a/test/dm/devres.c
+++ b/test/dm/devres.c
@@ -5,7 +5,6 @@
* Copyright 2019 Google LLC
*/
-#include <common.h>
#include <errno.h>
#include <dm.h>
#include <log.h>
@@ -40,7 +39,7 @@ static int dm_test_devres_alloc(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_devres_alloc, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_devres_alloc, UTF_SCAN_PDATA);
/* Test devm_kfree() can be used to free memory too */
static int dm_test_devres_free(struct unit_test_state *uts)
@@ -68,8 +67,7 @@ static int dm_test_devres_free(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_devres_free, UT_TESTF_SCAN_PDATA);
-
+DM_TEST(dm_test_devres_free, UTF_SCAN_PDATA);
/* Test that kzalloc() returns memory that is zeroed */
static int dm_test_devres_kzalloc(struct unit_test_state *uts)
@@ -88,7 +86,7 @@ static int dm_test_devres_kzalloc(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_devres_kzalloc, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_devres_kzalloc, UTF_SCAN_PDATA);
/* Test that devm_kmalloc_array() allocates an array that can be set */
static int dm_test_devres_kmalloc_array(struct unit_test_state *uts)
@@ -111,7 +109,7 @@ static int dm_test_devres_kmalloc_array(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_devres_kmalloc_array, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_devres_kmalloc_array, UTF_SCAN_PDATA);
/* Test that devm_kcalloc() allocates a zeroed array */
static int dm_test_devres_kcalloc(struct unit_test_state *uts)
@@ -140,7 +138,7 @@ static int dm_test_devres_kcalloc(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_devres_kcalloc, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_devres_kcalloc, UTF_SCAN_PDATA);
/* Test devres releases resources automatically as expected */
static int dm_test_devres_phase(struct unit_test_state *uts)
@@ -183,4 +181,4 @@ static int dm_test_devres_phase(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_devres_phase, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_devres_phase, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/dma.c b/test/dm/dma.c
index cce47cb2180..be3862963b1 100644
--- a/test/dm/dma.c
+++ b/test/dm/dma.c
@@ -6,7 +6,6 @@
* Grygorii Strashko <grygorii.strashko@ti.com>
*/
-#include <common.h>
#include <dm.h>
#include <malloc.h>
#include <dm/test.h>
@@ -35,7 +34,7 @@ static int dm_test_dma_m2m(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_dma_m2m, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_dma_m2m, UTF_SCAN_FDT);
static int dm_test_dma(struct unit_test_state *uts)
{
@@ -77,7 +76,7 @@ static int dm_test_dma(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_dma, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_dma, UTF_SCAN_FDT);
static int dm_test_dma_rx(struct unit_test_state *uts)
{
@@ -122,4 +121,4 @@ static int dm_test_dma_rx(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_dma_rx, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_dma_rx, UTF_SCAN_FDT);
diff --git a/test/dm/dsa.c b/test/dm/dsa.c
index c857106eaf4..9a31ae39d95 100644
--- a/test/dm/dsa.c
+++ b/test/dm/dsa.c
@@ -56,27 +56,25 @@ static int dm_test_dsa_probe(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_dsa_probe, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_dsa_probe, UTF_SCAN_FDT);
/* This test sends ping requests with the local address through each DSA port
* via the sandbox DSA master Eth.
*/
static int dm_test_dsa(struct unit_test_state *uts)
{
- net_ping_ip = string_to_ip("1.2.3.5");
+ char *argv[] = { "ping", "1.1.2.2" };
env_set("ethact", "eth2");
- ut_assertok(net_loop(PING));
+ ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
env_set("ethact", "lan0");
- ut_assertok(net_loop(PING));
+ ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
env_set("ethact", "lan1");
- ut_assertok(net_loop(PING));
+ ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
env_set("ethact", "");
return 0;
}
-
-DM_TEST(dm_test_dsa, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_dsa, UTF_SCAN_FDT);
diff --git a/test/dm/dsi_host.c b/test/dm/dsi_host.c
index 6e0a5df704f..b92742472d4 100644
--- a/test/dm/dsi_host.c
+++ b/test/dm/dsi_host.c
@@ -4,7 +4,6 @@
* Author(s): Yannick Fertre <yannick.fertre@st.com> for STMicroelectronics.
*/
-#include <common.h>
#include <dm.h>
#include <dsi_host.h>
#include <asm/state.h>
@@ -55,5 +54,4 @@ static int dm_test_dsi_host(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_dsi_host, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_dsi_host, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/ecdsa.c b/test/dm/ecdsa.c
index da535c98b59..d7eac7115f7 100644
--- a/test/dm/ecdsa.c
+++ b/test/dm/ecdsa.c
@@ -35,4 +35,4 @@ static int dm_test_ecdsa_verify(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ecdsa_verify, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ecdsa_verify, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/efi_media.c b/test/dm/efi_media.c
index e343a0e9c85..0cf7e37e987 100644
--- a/test/dm/efi_media.c
+++ b/test/dm/efi_media.c
@@ -5,7 +5,6 @@
* Copyright 2021 Google LLC
*/
-#include <common.h>
#include <dm.h>
#include <asm/test.h>
#include <dm/test.h>
@@ -21,4 +20,4 @@ static int dm_test_efi_media(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_efi_media, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_efi_media, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/eth.c b/test/dm/eth.c
index bb3dcc6b954..1087ae9572d 100644
--- a/test/dm/eth.c
+++ b/test/dm/eth.c
@@ -6,7 +6,6 @@
* Joe Hershberger <joe.hershberger@ni.com>
*/
-#include <common.h>
#include <dm.h>
#include <env.h>
#include <fdtdec.h>
@@ -167,72 +166,73 @@ static int dm_test_ip6_make_lladdr(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ip6_make_lladdr, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ip6_make_lladdr, UTF_SCAN_FDT);
#endif
static int dm_test_eth(struct unit_test_state *uts)
{
- net_ping_ip = string_to_ip("1.1.2.2");
+ char *argv[] = { "ping", "1.1.2.2" };
env_set("ethact", "eth@10002000");
- ut_assertok(net_loop(PING));
+ ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
ut_asserteq_str("eth@10002000", env_get("ethact"));
env_set("ethact", "eth@10003000");
- ut_assertok(net_loop(PING));
+ ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
ut_asserteq_str("eth@10003000", env_get("ethact"));
env_set("ethact", "eth@10004000");
- ut_assertok(net_loop(PING));
+ ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
ut_asserteq_str("eth@10004000", env_get("ethact"));
return 0;
}
-DM_TEST(dm_test_eth, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_eth, UTF_SCAN_FDT);
static int dm_test_eth_alias(struct unit_test_state *uts)
{
- net_ping_ip = string_to_ip("1.1.2.2");
+ char *argv[] = { "ping", "1.1.2.2" };
+
env_set("ethact", "eth0");
- ut_assertok(net_loop(PING));
+ ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
ut_asserteq_str("eth@10002000", env_get("ethact"));
env_set("ethact", "eth6");
- ut_assertok(net_loop(PING));
+ ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
ut_asserteq_str("eth@10004000", env_get("ethact"));
/* Expected to fail since eth1 is not defined in the device tree */
env_set("ethact", "eth1");
- ut_assertok(net_loop(PING));
+ ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
ut_asserteq_str("eth@10002000", env_get("ethact"));
env_set("ethact", "eth5");
- ut_assertok(net_loop(PING));
+ ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
ut_asserteq_str("eth@10003000", env_get("ethact"));
return 0;
}
-DM_TEST(dm_test_eth_alias, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_eth_alias, UTF_SCAN_FDT);
static int dm_test_eth_prime(struct unit_test_state *uts)
{
- net_ping_ip = string_to_ip("1.1.2.2");
+ char *argv[] = { "ping", "1.1.2.2" };
/* Expected to be "eth@10003000" because of ethprime variable */
env_set("ethact", NULL);
env_set("ethprime", "eth5");
- ut_assertok(net_loop(PING));
+ ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
ut_asserteq_str("eth@10003000", env_get("ethact"));
/* Expected to be "eth@10002000" because it is first */
env_set("ethact", NULL);
env_set("ethprime", NULL);
- ut_assertok(net_loop(PING));
+ ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
ut_asserteq_str("eth@10002000", env_get("ethact"));
return 0;
}
-DM_TEST(dm_test_eth_prime, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_eth_prime, UTF_SCAN_FDT);
/**
* This test case is trying to test the following scenario:
@@ -250,6 +250,7 @@ DM_TEST(dm_test_eth_prime, UT_TESTF_SCAN_FDT);
*/
static int dm_test_eth_act(struct unit_test_state *uts)
{
+ char *argv[] = { "ping", "1.1.2.2" };
struct udevice *dev[DM_TEST_ETH_NUM];
const char *ethname[DM_TEST_ETH_NUM] = {"eth@10002000", "eth@10003000",
"sbe5", "eth@10004000"};
@@ -259,7 +260,6 @@ static int dm_test_eth_act(struct unit_test_state *uts)
int i;
memset(ethaddr, '\0', sizeof(ethaddr));
- net_ping_ip = string_to_ip("1.1.2.2");
/* Prepare the test scenario */
for (i = 0; i < DM_TEST_ETH_NUM; i++) {
@@ -282,7 +282,7 @@ static int dm_test_eth_act(struct unit_test_state *uts)
env_set("ethact", ethname[0]);
/* Segment fault might happen if something is wrong */
- ut_asserteq(-ENODEV, net_loop(PING));
+ ut_asserteq(CMD_RET_FAILURE, do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
for (i = 0; i < DM_TEST_ETH_NUM; i++) {
/* Restore the env */
@@ -297,7 +297,7 @@ static int dm_test_eth_act(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_eth_act, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_eth_act, UTF_SCAN_FDT);
/* Ensure that all addresses are loaded properly */
static int dm_test_ethaddr(struct unit_test_state *uts)
@@ -330,20 +330,22 @@ static int dm_test_ethaddr(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ethaddr, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ethaddr, UTF_SCAN_FDT);
/* The asserts include a return on fail; cleanup in the caller */
static int _dm_test_eth_rotate1(struct unit_test_state *uts)
{
+ char *argv[] = { "ping", "1.1.2.2" };
+
/* Make sure that the default is to rotate to the next interface */
env_set("ethact", "eth@10004000");
- ut_assertok(net_loop(PING));
+ ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
ut_asserteq_str("eth@10002000", env_get("ethact"));
/* If ethrotate is no, then we should fail on a bad MAC */
env_set("ethact", "eth@10004000");
env_set("ethrotate", "no");
- ut_asserteq(-EINVAL, net_loop(PING));
+ ut_asserteq(CMD_RET_FAILURE, do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
ut_asserteq_str("eth@10004000", env_get("ethact"));
return 0;
@@ -351,14 +353,16 @@ static int _dm_test_eth_rotate1(struct unit_test_state *uts)
static int _dm_test_eth_rotate2(struct unit_test_state *uts)
{
+ char *argv[] = { "ping", "1.1.2.2" };
+
/* Make sure we can skip invalid devices */
env_set("ethact", "eth@10004000");
- ut_assertok(net_loop(PING));
+ ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
ut_asserteq_str("eth@10004000", env_get("ethact"));
/* Make sure we can handle device name which is not eth# */
env_set("ethact", "sbe5");
- ut_assertok(net_loop(PING));
+ ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
ut_asserteq_str("sbe5", env_get("ethact"));
return 0;
@@ -369,9 +373,6 @@ static int dm_test_eth_rotate(struct unit_test_state *uts)
char ethaddr[18];
int retval;
- /* Set target IP to mock ping */
- net_ping_ip = string_to_ip("1.1.2.2");
-
/* Invalidate eth1's MAC address */
memset(ethaddr, '\0', sizeof(ethaddr));
strncpy(ethaddr, env_get("eth6addr"), 17);
@@ -397,36 +398,39 @@ static int dm_test_eth_rotate(struct unit_test_state *uts)
/* Restore the env */
env_set("ethaddr", ethaddr);
}
+
/* Restore the env */
env_set(".flags", NULL);
return retval;
}
-DM_TEST(dm_test_eth_rotate, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_eth_rotate, UTF_SCAN_FDT);
/* The asserts include a return on fail; cleanup in the caller */
static int _dm_test_net_retry(struct unit_test_state *uts)
{
+ char *argv[] = { "ping", "1.1.2.2" };
+
/*
- * eth1 is disabled and netretry is yes, so the ping should succeed and
- * the active device should be eth0
+ * eth0 is disabled and netretry is yes, so the ping should succeed and
+ * the active device should be eth1
*/
- sandbox_eth_disable_response(1, true);
- env_set("ethact", "lan1");
+ sandbox_eth_disable_response(0, true);
+ env_set("ethact", "eth@10002000");
env_set("netretry", "yes");
sandbox_eth_skip_timeout();
- ut_assertok(net_loop(PING));
- ut_asserteq_str("eth@10002000", env_get("ethact"));
+ ut_assertok(do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
+ ut_asserteq_str("eth@10003000", env_get("ethact"));
/*
- * eth1 is disabled and netretry is no, so the ping should fail and the
- * active device should be eth1
+ * eth0 is disabled and netretry is no, so the ping should fail and the
+ * active device should be eth0
*/
- env_set("ethact", "lan1");
+ env_set("ethact", "eth@10002000");
env_set("netretry", "no");
sandbox_eth_skip_timeout();
- ut_asserteq(-ENONET, net_loop(PING));
- ut_asserteq_str("lan1", env_get("ethact"));
+ ut_asserteq(CMD_RET_FAILURE, do_ping(NULL, 0, ARRAY_SIZE(argv), argv));
+ ut_asserteq_str("eth@10002000", env_get("ethact"));
return 0;
}
@@ -435,8 +439,6 @@ static int dm_test_net_retry(struct unit_test_state *uts)
{
int retval;
- net_ping_ip = string_to_ip("1.1.2.2");
-
retval = _dm_test_net_retry(uts);
/* Restore the env */
@@ -445,8 +447,9 @@ static int dm_test_net_retry(struct unit_test_state *uts)
return retval;
}
-DM_TEST(dm_test_net_retry, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_net_retry, UTF_SCAN_FDT);
+#if CONFIG_IS_ENABLED(NET)
static int sb_check_arp_reply(struct udevice *dev, void *packet,
unsigned int len)
{
@@ -512,7 +515,9 @@ static int sb_with_async_arp_handler(struct udevice *dev, void *packet,
return sb_check_arp_reply(dev, packet, len);
}
+#endif
+#if CONFIG_IS_ENABLED(NET)
static int dm_test_eth_async_arp_reply(struct unit_test_state *uts)
{
net_ping_ip = string_to_ip("1.1.2.2");
@@ -529,9 +534,10 @@ static int dm_test_eth_async_arp_reply(struct unit_test_state *uts)
return 0;
}
+DM_TEST(dm_test_eth_async_arp_reply, UTF_SCAN_FDT);
+#endif
-DM_TEST(dm_test_eth_async_arp_reply, UT_TESTF_SCAN_FDT);
-
+#if CONFIG_IS_ENABLED(NET)
static int sb_check_ping_reply(struct udevice *dev, void *packet,
unsigned int len)
{
@@ -614,8 +620,8 @@ static int dm_test_eth_async_ping_reply(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_eth_async_ping_reply, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_eth_async_ping_reply, UTF_SCAN_FDT);
+#endif
#if IS_ENABLED(CONFIG_IPV6_ROUTER_DISCOVERY)
@@ -660,7 +666,6 @@ static int dm_test_validate_ra(struct unit_test_state *uts)
return 0;
}
-
DM_TEST(dm_test_validate_ra, 0);
static int dm_test_process_ra(struct unit_test_state *uts)
@@ -699,7 +704,6 @@ static int dm_test_process_ra(struct unit_test_state *uts)
return 0;
}
-
DM_TEST(dm_test_process_ra, 0);
#endif
diff --git a/test/dm/extcon.c b/test/dm/extcon.c
index 6a4e22bfdc5..91358abb5f0 100644
--- a/test/dm/extcon.c
+++ b/test/dm/extcon.c
@@ -17,5 +17,4 @@ static int dm_test_extcon(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_extcon, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_extcon, UTF_SCAN_FDT);
diff --git a/test/dm/fastboot.c b/test/dm/fastboot.c
index 758538d0e85..73c43f82924 100644
--- a/test/dm/fastboot.c
+++ b/test/dm/fastboot.c
@@ -3,7 +3,6 @@
* Copyright (C) 2015 Google, Inc
*/
-#include <common.h>
#include <dm.h>
#include <fastboot.h>
#include <fb_mmc.h>
@@ -92,4 +91,4 @@ static int dm_test_fastboot_mmc_part(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_fastboot_mmc_part, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_fastboot_mmc_part, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/fdtdec.c b/test/dm/fdtdec.c
index 087d4846da8..1f24f1d5dff 100644
--- a/test/dm/fdtdec.c
+++ b/test/dm/fdtdec.c
@@ -3,7 +3,6 @@
* Copyright 2020 NXP
*/
-#include <common.h>
#include <dm.h>
#include <asm/global_data.h>
#include <dm/of_extra.h>
@@ -56,7 +55,7 @@ static int dm_test_fdtdec_set_carveout(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_fdtdec_set_carveout,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_FLAT_TREE);
static int dm_test_fdtdec_add_reserved_memory(struct unit_test_state *uts)
{
@@ -129,4 +128,4 @@ static int dm_test_fdtdec_add_reserved_memory(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_fdtdec_add_reserved_memory,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_FLAT_TREE);
diff --git a/test/dm/ffa.c b/test/dm/ffa.c
index 6912666bb46..593b7177fce 100644
--- a/test/dm/ffa.c
+++ b/test/dm/ffa.c
@@ -8,7 +8,6 @@
* Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
*/
-#include <common.h>
#include <console.h>
#include <dm.h>
#include <asm/sandbox_arm_ffa.h>
@@ -198,8 +197,7 @@ static int dm_test_ffa_ack(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_ffa_ack, UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
+DM_TEST(dm_test_ffa_ack, UTF_SCAN_FDT | UTF_CONSOLE);
static int dm_test_ffa_nack(struct unit_test_state *uts)
{
@@ -257,5 +255,4 @@ static int dm_test_ffa_nack(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_ffa_nack, UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
+DM_TEST(dm_test_ffa_nack, UTF_SCAN_FDT | UTF_CONSOLE);
diff --git a/test/dm/firmware.c b/test/dm/firmware.c
index f37bccfe4a8..795f6d5e403 100644
--- a/test/dm/firmware.c
+++ b/test/dm/firmware.c
@@ -3,7 +3,6 @@
* Copyright (C) 2018 Xilinx, Inc.
*/
-#include <common.h>
#include <dm.h>
#include <syscon.h>
#include <asm/test.h>
@@ -20,4 +19,4 @@ static int dm_test_firmware_probe(struct unit_test_state *uts)
"sandbox-firmware", &dev));
return 0;
}
-DM_TEST(dm_test_firmware_probe, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_firmware_probe, UTF_SCAN_FDT);
diff --git a/test/dm/fpga.c b/test/dm/fpga.c
index 8bb35358532..fe9f287f8c7 100644
--- a/test/dm/fpga.c
+++ b/test/dm/fpga.c
@@ -16,5 +16,4 @@ static int dm_test_fpga(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_fpga, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_fpga, UTF_SCAN_FDT);
diff --git a/test/dm/fwu_mdata.c b/test/dm/fwu_mdata.c
index 52018f610fe..b7680632f95 100644
--- a/test/dm/fwu_mdata.c
+++ b/test/dm/fwu_mdata.c
@@ -5,7 +5,6 @@
*/
#include <blk.h>
-#include <common.h>
#include <dm.h>
#include <fwu.h>
#include <fwu_mdata.h>
@@ -93,6 +92,10 @@ static int dm_test_fwu_mdata_read(struct unit_test_state *uts)
struct udevice *dev;
struct fwu_mdata mdata = { 0 };
+ ut_assertok(setup_blk_device(uts));
+ ut_assertok(populate_mmc_disk_image(uts));
+ ut_assertok(write_mmc_blk_device(uts));
+
/*
* Trigger lib/fwu_updates/fwu.c fwu_boottime_checks()
* to populate g_dev global pointer in that library.
@@ -100,9 +103,7 @@ static int dm_test_fwu_mdata_read(struct unit_test_state *uts)
event_notify_null(EVT_MAIN_LOOP);
ut_assertok(uclass_first_device_err(UCLASS_FWU_MDATA, &dev));
- ut_assertok(setup_blk_device(uts));
- ut_assertok(populate_mmc_disk_image(uts));
- ut_assertok(write_mmc_blk_device(uts));
+ ut_assertok(fwu_init());
ut_assertok(fwu_get_mdata(&mdata));
@@ -110,7 +111,7 @@ static int dm_test_fwu_mdata_read(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_fwu_mdata_read, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_fwu_mdata_read, UTF_SCAN_FDT);
static int dm_test_fwu_mdata_write(struct unit_test_state *uts)
{
@@ -118,18 +119,19 @@ static int dm_test_fwu_mdata_write(struct unit_test_state *uts)
struct udevice *dev;
struct fwu_mdata mdata = { 0 };
+ ut_assertok(setup_blk_device(uts));
+ ut_assertok(populate_mmc_disk_image(uts));
+ ut_assertok(write_mmc_blk_device(uts));
+
/*
* Trigger lib/fwu_updates/fwu.c fwu_boottime_checks()
* to populate g_dev global pointer in that library.
*/
event_notify_null(EVT_MAIN_LOOP);
- ut_assertok(setup_blk_device(uts));
- ut_assertok(populate_mmc_disk_image(uts));
- ut_assertok(write_mmc_blk_device(uts));
-
ut_assertok(uclass_first_device_err(UCLASS_FWU_MDATA, &dev));
+ ut_assertok(fwu_init());
ut_assertok(fwu_get_mdata(&mdata));
active_idx = (mdata.active_index + 1) % CONFIG_FWU_NUM_BANKS;
@@ -140,4 +142,4 @@ static int dm_test_fwu_mdata_write(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_fwu_mdata_write, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_fwu_mdata_write, UTF_SCAN_FDT);
diff --git a/test/dm/gpio.c b/test/dm/gpio.c
index 0d88ec24bda..b45946c143c 100644
--- a/test/dm/gpio.c
+++ b/test/dm/gpio.c
@@ -3,7 +3,6 @@
* Copyright (C) 2013 Google, Inc
*/
-#include <common.h>
#include <fdtdec.h>
#include <dm.h>
#include <log.h>
@@ -146,7 +145,7 @@ static int dm_test_gpio(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_gpio, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_gpio, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that GPIO open-drain/open-source emulation works correctly */
static int dm_test_gpio_opendrain_opensource(struct unit_test_state *uts)
@@ -245,7 +244,7 @@ static int dm_test_gpio_opendrain_opensource(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_gpio_opendrain_opensource,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that sandbox anonymous GPIOs work correctly */
static int dm_test_gpio_anon(struct unit_test_state *uts)
@@ -267,7 +266,7 @@ static int dm_test_gpio_anon(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_gpio_anon, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_gpio_anon, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that gpio_requestf() works as expected */
static int dm_test_gpio_requestf(struct unit_test_state *uts)
@@ -285,7 +284,7 @@ static int dm_test_gpio_requestf(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_gpio_requestf, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_gpio_requestf, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that gpio_request() copies its string */
static int dm_test_gpio_copy(struct unit_test_state *uts)
@@ -307,7 +306,7 @@ static int dm_test_gpio_copy(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_gpio_copy, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_gpio_copy, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that we don't leak memory with GPIOs */
static int dm_test_gpio_leak(struct unit_test_state *uts)
@@ -319,7 +318,7 @@ static int dm_test_gpio_leak(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_gpio_leak, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_gpio_leak, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that we can find GPIOs using phandles */
static int dm_test_gpio_phandles(struct unit_test_state *uts)
@@ -393,7 +392,7 @@ static int dm_test_gpio_phandles(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_gpio_phandles, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_gpio_phandles, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Check the gpio pin configuration get from device tree information */
static int dm_test_gpio_get_dir_flags(struct unit_test_state *uts)
@@ -429,7 +428,7 @@ static int dm_test_gpio_get_dir_flags(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_gpio_get_dir_flags, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_gpio_get_dir_flags, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test of gpio_get_acpi() */
static int dm_test_gpio_get_acpi(struct unit_test_state *uts)
@@ -458,7 +457,7 @@ static int dm_test_gpio_get_acpi(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_gpio_get_acpi, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_gpio_get_acpi, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test of gpio_get_acpi() with an interrupt GPIO */
static int dm_test_gpio_get_acpi_irq(struct unit_test_state *uts)
@@ -490,7 +489,7 @@ static int dm_test_gpio_get_acpi_irq(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_gpio_get_acpi_irq, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_gpio_get_acpi_irq, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that we can get/release GPIOs using managed API */
static int dm_test_gpio_devm(struct unit_test_state *uts)
@@ -591,7 +590,7 @@ static int dm_test_gpio_devm(struct unit_test_state *uts)
device_remove(dev2, DM_REMOVE_NORMAL);
return 0;
}
-DM_TEST(dm_test_gpio_devm, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_gpio_devm, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_clrset_flags(struct unit_test_state *uts)
{
@@ -632,7 +631,7 @@ static int dm_test_clrset_flags(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_clrset_flags, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_clrset_flags, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Check that an active-low GPIO works as expected */
static int dm_test_clrset_flags_invert(struct unit_test_state *uts)
@@ -679,7 +678,7 @@ static int dm_test_clrset_flags_invert(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_clrset_flags_invert, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_clrset_flags_invert, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int set_gpios(struct unit_test_state *uts, struct gpio_desc *desc,
int count, uint value)
@@ -720,7 +719,7 @@ static int dm_test_gpio_get_values_as_int(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_gpio_get_values_as_int,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Check that an active-low GPIO works as expected */
static int dm_test_gpio_get_values_as_int_base3(struct unit_test_state *uts)
@@ -777,7 +776,7 @@ static int dm_test_gpio_get_values_as_int_base3(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_gpio_get_values_as_int_base3,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Check that gpio_get_status return the label of a GPIO configured as GPIOD_AF */
static int dm_test_gpio_function(struct unit_test_state *uts)
@@ -807,4 +806,4 @@ static int dm_test_gpio_function(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_gpio_function,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/host.c b/test/dm/host.c
index ca05a36b313..f577377da6a 100644
--- a/test/dm/host.c
+++ b/test/dm/host.c
@@ -4,7 +4,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <blk.h>
#include <dm.h>
#include <fs.h>
@@ -73,7 +72,7 @@ static int dm_test_host(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_host, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_host, UTF_SCAN_FDT);
/* reusing the same label should work */
static int dm_test_host_dup(struct unit_test_state *uts)
@@ -107,7 +106,7 @@ static int dm_test_host_dup(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_host_dup, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_host_dup, UTF_SCAN_FDT);
/* Basic test of 'host' command */
static int dm_test_cmd_host(struct unit_test_state *uts)
@@ -116,8 +115,6 @@ static int dm_test_cmd_host(struct unit_test_state *uts)
struct blk_desc *desc;
char fname[256];
- console_record_reset();
-
/* first check 'host info' with binding */
ut_assertok(run_command("host info", 0));
ut_assert_nextline("dev blocks blksz label path");
@@ -200,4 +197,4 @@ static int dm_test_cmd_host(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_cmd_host, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_cmd_host, UTF_SCAN_FDT | UTF_CONSOLE);
diff --git a/test/dm/hwspinlock.c b/test/dm/hwspinlock.c
index 995759d4d7e..58bba52182e 100644
--- a/test/dm/hwspinlock.c
+++ b/test/dm/hwspinlock.c
@@ -3,7 +3,6 @@
* Copyright (C) 2018, STMicroelectronics - All Rights Reserved
*/
-#include <common.h>
#include <dm.h>
#include <hwspinlock.h>
#include <asm/state.h>
@@ -37,5 +36,4 @@ static int dm_test_hwspinlock_base(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_hwspinlock_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_hwspinlock_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/i2c.c b/test/dm/i2c.c
index b46a22e79b1..40f1f26b671 100644
--- a/test/dm/i2c.c
+++ b/test/dm/i2c.c
@@ -5,7 +5,6 @@
* Note: Test coverage does not include 10-bit addressing
*/
-#include <common.h>
#include <dm.h>
#include <fdtdec.h>
#include <i2c.h>
@@ -39,7 +38,7 @@ static int dm_test_i2c_find(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_i2c_find, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_i2c_find, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_i2c_read_write(struct unit_test_state *uts)
{
@@ -56,7 +55,7 @@ static int dm_test_i2c_read_write(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_i2c_read_write, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_i2c_read_write, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_i2c_speed(struct unit_test_state *uts)
{
@@ -78,7 +77,7 @@ static int dm_test_i2c_speed(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_i2c_speed, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_i2c_speed, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_i2c_offset_len(struct unit_test_state *uts)
{
@@ -95,7 +94,7 @@ static int dm_test_i2c_offset_len(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_i2c_offset_len, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_i2c_offset_len, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_i2c_probe_empty(struct unit_test_state *uts)
{
@@ -110,7 +109,7 @@ static int dm_test_i2c_probe_empty(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_i2c_probe_empty, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_i2c_probe_empty, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_i2c_bytewise(struct unit_test_state *uts)
{
@@ -165,7 +164,7 @@ static int dm_test_i2c_bytewise(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_i2c_bytewise, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_i2c_bytewise, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_i2c_offset(struct unit_test_state *uts)
{
@@ -238,7 +237,7 @@ static int dm_test_i2c_offset(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_i2c_offset, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_i2c_offset, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_i2c_addr_offset(struct unit_test_state *uts)
{
@@ -302,8 +301,7 @@ static int dm_test_i2c_addr_offset(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_i2c_addr_offset, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_i2c_addr_offset, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_i2c_reg_clrset(struct unit_test_state *uts)
{
@@ -332,4 +330,4 @@ static int dm_test_i2c_reg_clrset(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_i2c_reg_clrset, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_i2c_reg_clrset, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/i2s.c b/test/dm/i2s.c
index c2bf4d5604b..cc336690e60 100644
--- a/test/dm/i2s.c
+++ b/test/dm/i2s.c
@@ -4,7 +4,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <dm.h>
#include <i2s.h>
#include <asm/test.h>
@@ -30,4 +29,4 @@ static int dm_test_i2s(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_i2s, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_i2s, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/iommu.c b/test/dm/iommu.c
index 62d38f1214a..c5dd917f00c 100644
--- a/test/dm/iommu.c
+++ b/test/dm/iommu.c
@@ -3,7 +3,6 @@
* Copyright (C) 2021 Mark Kettenis <kettenis@openbsd.org>
*/
-#include <common.h>
#include <dm.h>
#include <dm/test.h>
#include <dm/uclass-internal.h>
@@ -39,7 +38,7 @@ static int dm_test_iommu(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_iommu, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_iommu, UTF_SCAN_FDT);
static int dm_test_iommu_noiommu(struct unit_test_state *uts)
{
@@ -67,7 +66,7 @@ static int dm_test_iommu_noiommu(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_iommu_noiommu, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_iommu_noiommu, UTF_SCAN_FDT);
static int dm_test_iommu_pci(struct unit_test_state *uts)
{
@@ -82,7 +81,7 @@ static int dm_test_iommu_pci(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_iommu_pci, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_iommu_pci, UTF_SCAN_FDT);
static int dm_test_iommu_pci_noiommu(struct unit_test_state *uts)
{
@@ -97,4 +96,4 @@ static int dm_test_iommu_pci_noiommu(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_iommu_pci_noiommu, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_iommu_pci_noiommu, UTF_SCAN_FDT);
diff --git a/test/dm/irq.c b/test/dm/irq.c
index 51dd5e4abb4..ca3e1880656 100644
--- a/test/dm/irq.c
+++ b/test/dm/irq.c
@@ -5,7 +5,6 @@
* Copyright 2019 Google LLC
*/
-#include <common.h>
#include <dm.h>
#include <irq.h>
#include <acpi/acpi_device.h>
@@ -31,7 +30,7 @@ static int dm_test_irq_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_irq_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_irq_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test of irq_first_device_type() */
static int dm_test_irq_type(struct unit_test_state *uts)
@@ -43,7 +42,7 @@ static int dm_test_irq_type(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_irq_type, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_irq_type, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test of irq_read_and_clear() */
static int dm_test_read_and_clear(struct unit_test_state *uts)
@@ -60,7 +59,7 @@ static int dm_test_read_and_clear(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_read_and_clear, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_read_and_clear, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test of irq_request() */
static int dm_test_request(struct unit_test_state *uts)
@@ -75,7 +74,22 @@ static int dm_test_request(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_request, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_request, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+
+/* Test of irq_get_by_index() */
+static int dm_test_irq_get_by_index(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ struct irq irq;
+
+ ut_assertok(uclass_get_device_by_name(UCLASS_TEST_FDT, "f-test",
+ &dev));
+ ut_assertok(irq_get_by_index(dev, 0, &irq));
+ ut_asserteq(4, irq.id);
+
+ return 0;
+}
+DM_TEST(dm_test_irq_get_by_index, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test of irq_get_acpi() */
static int dm_test_irq_get_acpi(struct unit_test_state *uts)
@@ -97,4 +111,4 @@ static int dm_test_irq_get_acpi(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_irq_get_acpi, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_irq_get_acpi, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/k210_pll.c b/test/dm/k210_pll.c
index 354720f61e2..2a581499634 100644
--- a/test/dm/k210_pll.c
+++ b/test/dm/k210_pll.c
@@ -3,7 +3,6 @@
* Copyright (C) 2020 Sean Anderson <seanga2@gmail.com>
*/
-#include <common.h>
/* For DIV_ROUND_DOWN_ULL, defined in linux/kernel.h */
#include <div64.h>
#include <dm/test.h>
diff --git a/test/dm/led.c b/test/dm/led.c
index eed3f4654c5..36652c2833a 100644
--- a/test/dm/led.c
+++ b/test/dm/led.c
@@ -3,7 +3,6 @@
* Copyright (C) 2015 Google, Inc
*/
-#include <common.h>
#include <dm.h>
#include <led.h>
#include <asm/gpio.h>
@@ -21,11 +20,16 @@ static int dm_test_led_base(struct unit_test_state *uts)
ut_assertok(uclass_get_device(UCLASS_LED, 1, &dev));
ut_assertok(uclass_get_device(UCLASS_LED, 2, &dev));
ut_assertok(uclass_get_device(UCLASS_LED, 3, &dev));
- ut_asserteq(-ENODEV, uclass_get_device(UCLASS_LED, 4, &dev));
+ ut_assertok(uclass_get_device(UCLASS_LED, 4, &dev));
+ ut_assertok(uclass_get_device(UCLASS_LED, 5, &dev));
+ ut_assertok(uclass_get_device(UCLASS_LED, 6, &dev));
+ ut_assertok(uclass_get_device(UCLASS_LED, 7, &dev));
+ ut_assertok(uclass_get_device(UCLASS_LED, 8, &dev));
+ ut_asserteq(-ENODEV, uclass_get_device(UCLASS_LED, 9, &dev));
return 0;
}
-DM_TEST(dm_test_led_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_led_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test of the LED 'default-state' device tree property */
static int dm_test_led_default_state(struct unit_test_state *uts)
@@ -42,7 +46,7 @@ static int dm_test_led_default_state(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_led_default_state, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_led_default_state, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test of the led uclass using the led_gpio driver */
static int dm_test_led_gpio(struct unit_test_state *uts)
@@ -67,7 +71,7 @@ static int dm_test_led_gpio(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_led_gpio, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_led_gpio, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that we can toggle LEDs */
static int dm_test_led_toggle(struct unit_test_state *uts)
@@ -92,7 +96,7 @@ static int dm_test_led_toggle(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_led_toggle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_led_toggle, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test obtaining an LED by label */
static int dm_test_led_label(struct unit_test_state *uts)
@@ -111,9 +115,24 @@ static int dm_test_led_label(struct unit_test_state *uts)
ut_asserteq(-ENODEV, led_get_by_label("sandbox:blue", &dev));
+ /* Test if function, color and function-enumerator naming works */
+ ut_assertok(led_get_by_label("red:status-20", &dev));
+
+ /* Test if function, color naming works */
+ ut_assertok(led_get_by_label("green:status", &dev));
+
+ /* Test if function, without color naming works */
+ ut_assertok(led_get_by_label(":status", &dev));
+
+ /* Test if color without function naming works */
+ ut_assertok(led_get_by_label("green:", &dev));
+
+ /* Test if function, color naming is ignored if label is found */
+ ut_assertok(led_get_by_label("sandbox:function", &dev));
+
return 0;
}
-DM_TEST(dm_test_led_label, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_led_label, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test LED blinking */
#ifdef CONFIG_LED_BLINK
@@ -136,5 +155,81 @@ static int dm_test_led_blink(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_led_blink, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_led_blink, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+#endif
+
+/* Test LED boot */
+#ifdef CONFIG_LED_BOOT
+static int dm_test_led_boot(struct unit_test_state *uts)
+{
+ struct udevice *dev
+
+ /* options/u-boot/boot-led is set to phandle to "sandbox:green" */
+ ut_assertok(led_get_by_label("sandbox:green", &dev));
+ ut_asserteq(LEDST_OFF, led_get_state(dev));
+ ut_assertok(led_boot_on());
+ ut_asserteq(LEDST_ON, led_get_state(dev));
+ ut_assertok(led_boot_off());
+ ut_asserteq(LEDST_OFF, led_get_state(dev));
+
+ return 0;
+}
+DM_TEST(dm_test_led_boot, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+
+/* Test LED boot blink fallback */
+#ifndef CONFIG_LED_BLINK
+static int dm_test_led_boot_blink(struct unit_test_state *uts)
+{
+ struct udevice *dev
+
+ /* options/u-boot/boot-led is set to phandle to "sandbox:green" */
+ ut_assertok(led_get_by_label("sandbox:green", &dev));
+ ut_asserteq(LEDST_OFF, led_get_state(dev));
+ ut_assertok(led_boot_blink());
+ ut_asserteq(LEDST_ON, led_get_state(dev));
+ ut_assertok(led_boot_off());
+ ut_asserteq(LEDST_OFF, led_get_state(dev));
+
+ return 0;
+}
+DM_TEST(dm_test_led_boot_blink, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+#endif
+#endif
+
+/* Test LED activity */
+#ifdef CONFIG_LED_ACTIVITY
+static int dm_test_led_activity(struct unit_test_state *uts)
+{
+ struct udevice *dev
+
+ /* options/u-boot/activity-led is set to phandle to "sandbox:red" */
+ ut_assertok(led_get_by_label("sandbox:red", &dev));
+ ut_asserteq(LEDST_OFF, led_get_state(dev));
+ ut_assertok(led_activity_on());
+ ut_asserteq(LEDST_ON, led_get_state(dev));
+ ut_assertok(led_activity_off());
+ ut_asserteq(LEDST_OFF, led_get_state(dev));
+
+ return 0;
+}
+DM_TEST(dm_test_led_activity, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+
+/* Test LED activity blink fallback */
+#ifndef CONFIG_LED_BLINK
+static int dm_test_led_activityt_blink(struct unit_test_state *uts)
+{
+ struct udevice *dev
+
+ /* options/u-boot/activity-led is set to phandle to "sandbox:red" */
+ ut_assertok(led_get_by_label("sandbox:red", &dev));
+ ut_asserteq(LEDST_OFF, led_get_state(dev));
+ ut_assertok(led_activity_blink());
+ ut_asserteq(LEDST_ON, led_get_state(dev));
+ ut_assertok(led_activity_off());
+ ut_asserteq(LEDST_OFF, led_get_state(dev));
+
+ return 0;
+}
+DM_TEST(dm_test_led_activityt_blink, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+#endif
#endif
diff --git a/test/dm/mailbox.c b/test/dm/mailbox.c
index 7ad8a1cbba2..4a0648b9277 100644
--- a/test/dm/mailbox.c
+++ b/test/dm/mailbox.c
@@ -3,7 +3,6 @@
* Copyright (c) 2016, NVIDIA CORPORATION.
*/
-#include <common.h>
#include <dm.h>
#include <malloc.h>
#include <dm/test.h>
@@ -29,4 +28,4 @@ static int dm_test_mailbox(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_mailbox, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_mailbox, UTF_SCAN_FDT);
diff --git a/test/dm/mdio.c b/test/dm/mdio.c
index f863c52645b..6760c98898a 100644
--- a/test/dm/mdio.c
+++ b/test/dm/mdio.c
@@ -4,7 +4,6 @@
* Alex Marginean, NXP
*/
-#include <common.h>
#include <dm.h>
#include <log.h>
#include <miiphy.h>
@@ -54,5 +53,4 @@ static int dm_test_mdio(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_mdio, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_mdio, UTF_SCAN_FDT);
diff --git a/test/dm/mdio_mux.c b/test/dm/mdio_mux.c
index bfe3518221f..866feb26381 100644
--- a/test/dm/mdio_mux.c
+++ b/test/dm/mdio_mux.c
@@ -4,7 +4,6 @@
* Alex Marginean, NXP
*/
-#include <common.h>
#include <dm.h>
#include <miiphy.h>
#include <misc.h>
@@ -77,5 +76,4 @@ static int dm_test_mdio_mux(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_mdio_mux, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_mdio_mux, UTF_SCAN_FDT);
diff --git a/test/dm/memory.c b/test/dm/memory.c
index 7d9500aa91d..34e64ba0187 100644
--- a/test/dm/memory.c
+++ b/test/dm/memory.c
@@ -17,5 +17,4 @@ static int dm_test_memory(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_memory, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_memory, UTF_SCAN_FDT);
diff --git a/test/dm/misc.c b/test/dm/misc.c
index 8bdd8c64bca..250885dcf51 100644
--- a/test/dm/misc.c
+++ b/test/dm/misc.c
@@ -4,7 +4,6 @@
* Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
*/
-#include <common.h>
#include <dm.h>
#include <dm/test.h>
#include <misc.h>
@@ -80,5 +79,4 @@ static int dm_test_misc(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_misc, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_misc, UTF_SCAN_FDT);
diff --git a/test/dm/mmc.c b/test/dm/mmc.c
index b1eb8bee2f9..cdebb955196 100644
--- a/test/dm/mmc.c
+++ b/test/dm/mmc.c
@@ -3,7 +3,6 @@
* Copyright (C) 2015 Google, Inc
*/
-#include <common.h>
#include <dm.h>
#include <mmc.h>
#include <part.h>
@@ -23,7 +22,7 @@ static int dm_test_mmc_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_mmc_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_mmc_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_mmc_blk(struct unit_test_state *uts)
{
@@ -51,4 +50,4 @@ static int dm_test_mmc_blk(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_mmc_blk, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_mmc_blk, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/mux-cmd.c b/test/dm/mux-cmd.c
index 11c237b5da9..bd02cda84db 100644
--- a/test/dm/mux-cmd.c
+++ b/test/dm/mux-cmd.c
@@ -3,7 +3,6 @@
* Copyright (C) 2020 Texas Instruments Inc.
* Pratyush Yadav <p.yadav@ti.com>
*/
-#include <common.h>
#include <dm.h>
#include <mux.h>
#include <mux-internal.h>
@@ -13,6 +12,7 @@
#include <test/ut.h>
#include <console.h>
#include <rand.h>
+#include <time.h>
#define BUF_SIZE 256
@@ -26,8 +26,6 @@ static int dm_test_cmd_mux_list(struct unit_test_state *uts)
int i;
unsigned long val;
- sandbox_set_enable_memio(true);
-
ut_assertok(uclass_get_device_by_name(UCLASS_MUX, "a-mux-controller",
&dev));
chip = dev_get_uclass_priv(dev);
@@ -109,7 +107,7 @@ static int dm_test_cmd_mux_list(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_cmd_mux_list, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_cmd_mux_list, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE);
static int dm_test_cmd_mux_select(struct unit_test_state *uts)
{
@@ -119,8 +117,6 @@ static int dm_test_cmd_mux_select(struct unit_test_state *uts)
char cmd[BUF_SIZE];
unsigned int i, state;
- sandbox_set_enable_memio(true);
-
ut_assertok(uclass_get_device_by_name(UCLASS_MUX, "a-mux-controller",
&dev));
chip = dev_get_uclass_priv(dev);
@@ -143,7 +139,7 @@ static int dm_test_cmd_mux_select(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_cmd_mux_select, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_cmd_mux_select, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_cmd_mux_deselect(struct unit_test_state *uts)
{
@@ -153,8 +149,6 @@ static int dm_test_cmd_mux_deselect(struct unit_test_state *uts)
char cmd[BUF_SIZE];
unsigned int i, state;
- sandbox_set_enable_memio(true);
-
ut_assertok(uclass_get_device_by_name(UCLASS_MUX, "a-mux-controller",
&dev));
chip = dev_get_uclass_priv(dev);
@@ -174,4 +168,4 @@ static int dm_test_cmd_mux_deselect(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_cmd_mux_deselect, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_cmd_mux_deselect, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/mux-emul.c b/test/dm/mux-emul.c
index c6aeeb7e1f1..de231e4e5b2 100644
--- a/test/dm/mux-emul.c
+++ b/test/dm/mux-emul.c
@@ -3,7 +3,6 @@
* Copyright (C) 2020 Texas Instruments Incorporated - https://www.ti.com/
* Pratyush Yadav <p.yadav@ti.com>
*/
-#include <common.h>
#include <dm.h>
#include <mux.h>
#include <mux-internal.h>
@@ -80,7 +79,7 @@ static int dm_test_mux_emul_default_state(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_mux_emul_default_state, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_mux_emul_default_state, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_mux_emul_select_deselect(struct unit_test_state *uts)
{
@@ -103,4 +102,4 @@ static int dm_test_mux_emul_select_deselect(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_mux_emul_select_deselect, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_mux_emul_select_deselect, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/mux-mmio.c b/test/dm/mux-mmio.c
index 27c881dabde..3bb1e49b8c9 100644
--- a/test/dm/mux-mmio.c
+++ b/test/dm/mux-mmio.c
@@ -4,7 +4,6 @@
* Jean-Jacques Hiblot <jjhiblot@ti.com>
*/
-#include <common.h>
#include <dm.h>
#include <mux.h>
#include <regmap.h>
@@ -86,7 +85,7 @@ static int dm_test_mux_mmio_select(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_mux_mmio_select, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_mux_mmio_select, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that managed API for mux work correctly */
static int dm_test_devm_mux_mmio(struct unit_test_state *uts)
@@ -135,4 +134,4 @@ static int dm_test_devm_mux_mmio(struct unit_test_state *uts)
device_remove(dev_b, DM_REMOVE_NORMAL);
return 0;
}
-DM_TEST(dm_test_devm_mux_mmio, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_devm_mux_mmio, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/nand.c b/test/dm/nand.c
index 0b992fdce1c..c7e09850503 100644
--- a/test/dm/nand.c
+++ b/test/dm/nand.c
@@ -12,7 +12,7 @@
#include <linux/mtd/mtd.h>
#include <linux/mtd/rawnand.h>
-static int dm_test_nand(struct unit_test_state *uts, int dev, bool end)
+static int run_test_nand(struct unit_test_state *uts, int dev, bool end)
{
nand_erase_options_t opts = { };
struct mtd_info *mtd;
@@ -88,17 +88,34 @@ static int dm_test_nand(struct unit_test_state *uts, int dev, bool end)
return 0;
}
-#define DM_NAND_TEST(dev) \
-static int dm_test_nand##dev##_start(struct unit_test_state *uts) \
-{ \
- return dm_test_nand(uts, dev, false); \
-} \
-DM_TEST(dm_test_nand##dev##_start, UT_TESTF_SCAN_FDT); \
-static int dm_test_nand##dev##_end(struct unit_test_state *uts) \
-{ \
- return dm_test_nand(uts, dev, true); \
-} \
-DM_TEST(dm_test_nand##dev##_end, UT_TESTF_SCAN_FDT)
-
-DM_NAND_TEST(0);
-DM_NAND_TEST(1);
+static int dm_test_nand0_start(struct unit_test_state *uts)
+{
+ ut_assertok(run_test_nand(uts, 0, false));
+
+ return 0;
+}
+DM_TEST(dm_test_nand0_start, UTF_SCAN_FDT);
+
+static int dm_test_nand1_start(struct unit_test_state *uts)
+{
+ ut_assertok(run_test_nand(uts, 1, false));
+
+ return 0;
+}
+DM_TEST(dm_test_nand1_start, UTF_SCAN_FDT);
+
+static int dm_test_nand0_end(struct unit_test_state *uts)
+{
+ ut_assertok(run_test_nand(uts, 0, true));
+
+ return 0;
+}
+DM_TEST(dm_test_nand0_end, UTF_SCAN_FDT);
+
+static int dm_test_nand1_end(struct unit_test_state *uts)
+{
+ ut_assertok(run_test_nand(uts, 1, true));
+
+ return 0;
+}
+DM_TEST(dm_test_nand1_end, UTF_SCAN_FDT);
diff --git a/test/dm/nop.c b/test/dm/nop.c
index f7d9a0f3df3..a6f5f820f6a 100644
--- a/test/dm/nop.c
+++ b/test/dm/nop.c
@@ -6,7 +6,6 @@
* Jean-Jacques Hiblot <jjhiblot@ti.com>
*/
-#include <common.h>
#include <dm.h>
#include <dm/ofnode.h>
#include <dm/lists.h>
@@ -70,5 +69,4 @@ static int dm_test_nop(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_nop, UT_TESTF_FLAT_TREE | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_nop, UTF_FLAT_TREE | UTF_SCAN_FDT);
diff --git a/test/dm/nvmxip.c b/test/dm/nvmxip.c
index f0ad47d4efe..a702d0aec3f 100644
--- a/test/dm/nvmxip.c
+++ b/test/dm/nvmxip.c
@@ -8,7 +8,6 @@
* Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
*/
-#include <common.h>
#include <blk.h>
#include <console.h>
#include <dm.h>
@@ -143,5 +142,4 @@ static int dm_test_nvmxip(struct unit_test_state *uts)
return CMD_RET_SUCCESS;
}
-
-DM_TEST(dm_test_nvmxip, UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
+DM_TEST(dm_test_nvmxip, UTF_SCAN_FDT | UTF_CONSOLE);
diff --git a/test/dm/of_extra.c b/test/dm/of_extra.c
index ac2d886892d..3c31bfcd31f 100644
--- a/test/dm/of_extra.c
+++ b/test/dm/of_extra.c
@@ -4,7 +4,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <dm.h>
#include <dm/of_extra.h>
#include <dm/test.h>
diff --git a/test/dm/of_platdata.c b/test/dm/of_platdata.c
index a241c427936..6e35bcaf62c 100644
--- a/test/dm/of_platdata.c
+++ b/test/dm/of_platdata.c
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: GPL-2.0+
-#include <common.h>
#include <clk.h>
#include <dm.h>
#include <dt-structs.h>
@@ -21,7 +20,7 @@ static int dm_test_of_plat_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_of_plat_base, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_of_plat_base, UTF_SCAN_PDATA);
/* Test that we can read properties from a device */
static int dm_test_of_plat_props(struct unit_test_state *uts)
@@ -92,7 +91,7 @@ static int dm_test_of_plat_props(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_of_plat_props, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_of_plat_props, UTF_SCAN_PDATA);
/*
* find_driver_info - recursively find the driver_info for a device
@@ -174,7 +173,7 @@ static int dm_test_of_plat_dev(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_of_plat_dev, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_of_plat_dev, UTF_SCAN_PDATA);
/* Test handling of phandles that point to other devices */
static int dm_test_of_plat_phandle(struct unit_test_state *uts)
@@ -207,7 +206,7 @@ static int dm_test_of_plat_phandle(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_of_plat_phandle, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_of_plat_phandle, UTF_SCAN_PDATA);
#if CONFIG_IS_ENABLED(OF_PLATDATA_PARENT)
/* Test that device parents are correctly set up */
@@ -221,7 +220,7 @@ static int dm_test_of_plat_parent(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_of_plat_parent, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_of_plat_parent, UTF_SCAN_PDATA);
#endif
/* Test clocks with of-platdata */
@@ -240,7 +239,7 @@ static int dm_test_of_plat_clk(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_of_plat_clk, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_of_plat_clk, UTF_SCAN_PDATA);
/* Test irqs with of-platdata */
static int dm_test_of_plat_irq(struct unit_test_state *uts)
@@ -259,7 +258,7 @@ static int dm_test_of_plat_irq(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_of_plat_irq, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_of_plat_irq, UTF_SCAN_PDATA);
/* Test GPIOs with of-platdata */
static int dm_test_of_plat_gpio(struct unit_test_state *uts)
@@ -278,4 +277,4 @@ static int dm_test_of_plat_gpio(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_of_plat_gpio, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_of_plat_gpio, UTF_SCAN_PDATA);
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index a5bc43aea4e..0f60c2a6281 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -16,7 +16,6 @@
* behaviour of each ofnode function, since that is done by the normal ones.
*/
-#include <common.h>
#include <abuf.h>
#include <dm.h>
#include <log.h>
@@ -24,6 +23,7 @@
#include <dm/device-internal.h>
#include <dm/lists.h>
#include <dm/of_extra.h>
+#include <dm/ofnode_graph.h>
#include <dm/root.h>
#include <dm/test.h>
#include <dm/uclass-internal.h>
@@ -48,7 +48,7 @@ oftree get_other_oftree(struct unit_test_state *uts)
/* An invalid tree may cause failure or crashes */
if (!oftree_valid(tree))
- ut_reportf("test needs the UT_TESTF_OTHER_FDT flag");
+ ut_reportf("test needs the UTF_OTHER_FDT flag");
return tree;
}
@@ -104,7 +104,7 @@ static int dm_test_ofnode_compatible(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_ofnode_compatible,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* check ofnode_device_is_compatible() with the 'other' FDT */
static int dm_test_ofnode_compatible_ot(struct unit_test_state *uts)
@@ -117,7 +117,7 @@ static int dm_test_ofnode_compatible_ot(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_compatible_ot, UT_TESTF_SCAN_FDT | UT_TESTF_OTHER_FDT);
+DM_TEST(dm_test_ofnode_compatible_ot, UTF_SCAN_FDT | UTF_OTHER_FDT);
static int dm_test_ofnode_get_by_phandle(struct unit_test_state *uts)
{
@@ -135,23 +135,30 @@ static int dm_test_ofnode_get_by_phandle(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_get_by_phandle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_get_by_phandle, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* test oftree_get_by_phandle() with a the 'other' oftree */
static int dm_test_ofnode_get_by_phandle_ot(struct unit_test_state *uts)
{
oftree otree = get_other_oftree(uts);
ofnode node;
+ u32 idx;
+ int ret;
- ut_assert(ofnode_valid(oftree_get_by_phandle(oftree_default(), 1)));
- node = oftree_get_by_phandle(otree, 1);
+ node = oftree_path(otree, "/node");
+ ut_assert(ofnode_valid(node));
+
+ ret = ofnode_read_u32(node, "other-phandle", &idx);
+ ut_assertok(ret);
+
+ node = oftree_get_by_phandle(otree, idx);
ut_assert(ofnode_valid(node));
ut_asserteq_str("target", ofnode_get_name(node));
return 0;
}
DM_TEST(dm_test_ofnode_get_by_phandle_ot,
- UT_TESTF_SCAN_FDT | UT_TESTF_OTHER_FDT);
+ UTF_SCAN_FDT | UTF_OTHER_FDT);
static int check_prop_values(struct unit_test_state *uts, ofnode start,
const char *propname, const char *propval,
@@ -190,7 +197,7 @@ static int dm_test_ofnode_by_prop_value(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_by_prop_value, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_by_prop_value, UTF_SCAN_FDT);
/* test ofnode_by_prop_value() with a the 'other' oftree */
static int dm_test_ofnode_by_prop_value_ot(struct unit_test_state *uts)
@@ -203,7 +210,7 @@ static int dm_test_ofnode_by_prop_value_ot(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_ofnode_by_prop_value_ot,
- UT_TESTF_SCAN_FDT | UT_TESTF_OTHER_FDT);
+ UTF_SCAN_FDT | UTF_OTHER_FDT);
/* test ofnode_read_fmap_entry() */
static int dm_test_ofnode_fmap(struct unit_test_state *uts)
@@ -219,7 +226,7 @@ static int dm_test_ofnode_fmap(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_fmap, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_fmap, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* test ofnode_read_prop() */
static int dm_test_ofnode_read(struct unit_test_state *uts)
@@ -249,7 +256,7 @@ static int dm_test_ofnode_read(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_read, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_read, UTF_SCAN_FDT);
/* test ofnode_read_prop() with the 'other' tree */
static int dm_test_ofnode_read_ot(struct unit_test_state *uts)
@@ -272,17 +279,18 @@ static int dm_test_ofnode_read_ot(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_read_ot, UT_TESTF_SCAN_FDT | UT_TESTF_OTHER_FDT);
+DM_TEST(dm_test_ofnode_read_ot, UTF_SCAN_FDT | UTF_OTHER_FDT);
-/* test ofnode_count_/parse_phandle_with_args() */
+/* test ofnode_count_/parse/_phandle_with_args() */
static int dm_test_ofnode_phandle(struct unit_test_state *uts)
{
struct ofnode_phandle_args args;
- ofnode node;
+ ofnode node, phandle, target;
int ret;
const char prop[] = "test-gpios";
const char cell[] = "#gpio-cells";
const char prop2[] = "phandle-value";
+ const char prop3[] = "phandle-nodes";
node = ofnode_path("/a-test");
ut_assert(ofnode_valid(node));
@@ -346,38 +354,121 @@ static int dm_test_ofnode_phandle(struct unit_test_state *uts)
ret = ofnode_parse_phandle_with_args(node, prop2, NULL, 1, 3, &args);
ut_asserteq(-ENOENT, ret);
+ /* Test ofnode_parse_phandle */
+ phandle = ofnode_parse_phandle(node, "missing", 0);
+ ut_assert(ofnode_equal(ofnode_null(), phandle));
+
+ target = ofnode_path("/phandle-node-1");
+ ut_assert(ofnode_valid(target));
+ phandle = ofnode_parse_phandle(node, prop3, 0);
+ ut_assert(ofnode_equal(target, phandle));
+
+ target = ofnode_path("/phandle-node-2");
+ ut_assert(ofnode_valid(target));
+ phandle = ofnode_parse_phandle(node, prop3, 1);
+ ut_assert(ofnode_equal(target, phandle));
+
+ phandle = ofnode_parse_phandle(node, prop3, 3);
+ ut_assert(ofnode_equal(ofnode_null(), phandle));
+
return 0;
}
-DM_TEST(dm_test_ofnode_phandle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_phandle, UTF_SCAN_PDATA | UTF_SCAN_FDT);
-/* test ofnode_count_/parse_phandle_with_args() with 'other' tree */
+/* test oftree_count_/parse/_phandle_with_args() with 'other' tree */
static int dm_test_ofnode_phandle_ot(struct unit_test_state *uts)
{
oftree otree = get_other_oftree(uts);
struct ofnode_phandle_args args;
- ofnode node;
+ ofnode node, phandle, target;
int ret;
+ const char prop[] = "other-test-gpios";
+ const char cell[] = "#gpio-cells";
+ const char prop2[] = "other-phandle-value";
+ const char prop3[] = "other-phandle-nodes";
- node = oftree_path(otree, "/node");
+ node = oftree_path(otree, "/other-a-test");
+ ut_assert(ofnode_valid(node));
- /* Test ofnode_count_phandle_with_args with cell name */
- ret = ofnode_count_phandle_with_args(node, "missing", "#gpio-cells", 0);
+ /* Test oftree_count_phandle_with_args with cell name */
+ ret = oftree_count_phandle_with_args(otree, node, "missing", cell, 0);
ut_asserteq(-ENOENT, ret);
- ret = ofnode_count_phandle_with_args(node, "target", "#invalid", 0);
+ ret = oftree_count_phandle_with_args(otree, node, prop, "#invalid", 0);
ut_asserteq(-EINVAL, ret);
- ret = ofnode_count_phandle_with_args(node, "target", "#gpio-cells", 0);
- ut_asserteq(1, ret);
+ ret = oftree_count_phandle_with_args(otree, node, prop, cell, 0);
+ ut_asserteq(5, ret);
- ret = ofnode_parse_phandle_with_args(node, "target", "#gpio-cells", 0,
- 0, &args);
+ /* Test oftree_parse_phandle_with_args with cell name */
+ ret = oftree_parse_phandle_with_args(otree, node, "missing", cell, 0, 0,
+ &args);
+ ut_asserteq(-ENOENT, ret);
+ ret = oftree_parse_phandle_with_args(otree, node, prop, "#invalid", 0, 0,
+ &args);
+ ut_asserteq(-EINVAL, ret);
+ ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 0, &args);
ut_assertok(ret);
- ut_asserteq(2, args.args_count);
- ut_asserteq(3, args.args[0]);
- ut_asserteq(4, args.args[1]);
+ ut_asserteq(1, args.args_count);
+ ut_asserteq(1, args.args[0]);
+ ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 1, &args);
+ ut_assertok(ret);
+ ut_asserteq(1, args.args_count);
+ ut_asserteq(4, args.args[0]);
+ ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 2, &args);
+ ut_assertok(ret);
+ ut_asserteq(5, args.args_count);
+ ut_asserteq(5, args.args[0]);
+ ut_asserteq(1, args.args[4]);
+ ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 3, &args);
+ ut_asserteq(-ENOENT, ret);
+ ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 4, &args);
+ ut_assertok(ret);
+ ut_asserteq(1, args.args_count);
+ ut_asserteq(12, args.args[0]);
+ ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 5, &args);
+ ut_asserteq(-ENOENT, ret);
+
+ /* Test oftree_count_phandle_with_args with cell count */
+ ret = oftree_count_phandle_with_args(otree, node, "missing", NULL, 2);
+ ut_asserteq(-ENOENT, ret);
+ ret = oftree_count_phandle_with_args(otree, node, prop2, NULL, 1);
+ ut_asserteq(3, ret);
+
+ /* Test oftree_parse_phandle_with_args with cell count */
+ ret = oftree_parse_phandle_with_args(otree, node, prop2, NULL, 1, 0, &args);
+ ut_assertok(ret);
+ ut_asserteq(1, ofnode_valid(args.node));
+ ut_asserteq(1, args.args_count);
+ ut_asserteq(10, args.args[0]);
+ ret = oftree_parse_phandle_with_args(otree, node, prop2, NULL, 1, 1, &args);
+ ut_asserteq(-EINVAL, ret);
+ ret = oftree_parse_phandle_with_args(otree, node, prop2, NULL, 1, 2, &args);
+ ut_assertok(ret);
+ ut_asserteq(1, ofnode_valid(args.node));
+ ut_asserteq(1, args.args_count);
+ ut_asserteq(30, args.args[0]);
+ ret = oftree_parse_phandle_with_args(otree, node, prop2, NULL, 1, 3, &args);
+ ut_asserteq(-ENOENT, ret);
+
+ /* Test oftree_parse_phandle */
+ phandle = oftree_parse_phandle(otree, node, "missing", 0);
+ ut_assert(ofnode_equal(ofnode_null(), phandle));
+
+ target = oftree_path(otree, "/other-phandle-node-1");
+ ut_assert(ofnode_valid(target));
+ phandle = oftree_parse_phandle(otree, node, prop3, 0);
+ ut_assert(ofnode_equal(target, phandle));
+
+ target = oftree_path(otree, "/other-phandle-node-2");
+ ut_assert(ofnode_valid(target));
+ phandle = oftree_parse_phandle(otree, node, prop3, 1);
+ ut_assert(ofnode_equal(target, phandle));
+
+ phandle = oftree_parse_phandle(otree, node, prop3, 3);
+ ut_assert(ofnode_equal(ofnode_null(), phandle));
return 0;
}
-DM_TEST(dm_test_ofnode_phandle_ot, UT_TESTF_OTHER_FDT);
+DM_TEST(dm_test_ofnode_phandle_ot, UTF_OTHER_FDT);
/* test ofnode_read_chosen_string/node/prop() */
static int dm_test_ofnode_read_chosen(struct unit_test_state *uts)
@@ -407,7 +498,7 @@ static int dm_test_ofnode_read_chosen(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_read_chosen, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_read_chosen, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* test ofnode_get_aliases_node/prop() */
static int dm_test_ofnode_read_aliases(struct unit_test_state *uts)
@@ -430,7 +521,7 @@ static int dm_test_ofnode_read_aliases(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_read_aliases, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_read_aliases, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_ofnode_get_child_count(struct unit_test_state *uts)
{
@@ -451,7 +542,7 @@ static int dm_test_ofnode_get_child_count(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_ofnode_get_child_count,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* test ofnode_get_child_count() with 'other' tree */
static int dm_test_ofnode_get_child_count_ot(struct unit_test_state *uts)
@@ -474,7 +565,7 @@ static int dm_test_ofnode_get_child_count_ot(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_ofnode_get_child_count_ot,
- UT_TESTF_SCAN_FDT | UT_TESTF_OTHER_FDT);
+ UTF_SCAN_FDT | UTF_OTHER_FDT);
static int dm_test_ofnode_is_enabled(struct unit_test_state *uts)
{
@@ -486,7 +577,7 @@ static int dm_test_ofnode_is_enabled(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_is_enabled, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_is_enabled, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* test ofnode_is_enabled() with 'other' tree */
static int dm_test_ofnode_is_enabled_ot(struct unit_test_state *uts)
@@ -500,7 +591,7 @@ static int dm_test_ofnode_is_enabled_ot(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_is_enabled_ot, UT_TESTF_OTHER_FDT);
+DM_TEST(dm_test_ofnode_is_enabled_ot, UTF_OTHER_FDT);
/* test ofnode_get_addr/size() */
static int dm_test_ofnode_get_reg(struct unit_test_state *uts)
@@ -537,7 +628,7 @@ static int dm_test_ofnode_get_reg(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_get_reg, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_get_reg, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* test ofnode_get_addr() with 'other' tree */
static int dm_test_ofnode_get_reg_ot(struct unit_test_state *uts)
@@ -551,7 +642,7 @@ static int dm_test_ofnode_get_reg_ot(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_get_reg_ot, UT_TESTF_SCAN_FDT | UT_TESTF_OTHER_FDT);
+DM_TEST(dm_test_ofnode_get_reg_ot, UTF_SCAN_FDT | UTF_OTHER_FDT);
static int dm_test_ofnode_get_path(struct unit_test_state *uts)
{
@@ -572,7 +663,7 @@ static int dm_test_ofnode_get_path(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_get_path, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_get_path, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* test ofnode_get_path() with 'other' tree */
static int dm_test_ofnode_get_path_ot(struct unit_test_state *uts)
@@ -592,7 +683,7 @@ static int dm_test_ofnode_get_path_ot(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_get_path_ot, UT_TESTF_SCAN_FDT | UT_TESTF_OTHER_FDT);
+DM_TEST(dm_test_ofnode_get_path_ot, UTF_SCAN_FDT | UTF_OTHER_FDT);
/* test ofnode_conf_read_bool/int/str() */
static int dm_test_ofnode_conf(struct unit_test_state *uts)
@@ -608,12 +699,32 @@ static int dm_test_ofnode_conf(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_conf, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_conf, UTF_SCAN_FDT);
static int dm_test_ofnode_options(struct unit_test_state *uts)
{
u64 bootscr_address, bootscr_offset;
u64 bootscr_flash_offset, bootscr_flash_size;
+ ofnode node, phandle_node, target;
+
+ node = ofnode_path("/options/u-boot");
+ ut_assert(ofnode_valid(node));
+
+ ut_assert(!ofnode_options_read_bool("missing"));
+ ut_assert(ofnode_options_read_bool("testing-bool"));
+
+ ut_asserteq(123, ofnode_options_read_int("testing-int", 0));
+ ut_asserteq(6, ofnode_options_read_int("missing", 6));
+
+ ut_assertnull(ofnode_options_read_str("missing"));
+ ut_asserteq_str("testing", ofnode_options_read_str("testing-str"));
+
+ ut_asserteq(-EINVAL, ofnode_options_get_by_phandle("missing", &phandle_node));
+
+ target = ofnode_path("/phandle-node-1");
+ ut_assert(ofnode_valid(target));
+ ut_assertok(ofnode_options_get_by_phandle("testing-phandle", &phandle_node));
+ ut_assert(ofnode_equal(target, phandle_node));
ut_assertok(ofnode_read_bootscript_address(&bootscr_address,
&bootscr_offset));
@@ -645,7 +756,7 @@ static int dm_test_ofnode_for_each_compatible_node(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_for_each_compatible_node, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_for_each_compatible_node, UTF_SCAN_FDT);
/* test dm_test_ofnode_string_count/index/list() */
static int dm_test_ofnode_string(struct unit_test_state *uts)
@@ -693,7 +804,7 @@ static int dm_test_ofnode_string(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_string, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_string, UTF_SCAN_FDT);
/* test error returns from ofnode_read_string_count/index/list() */
static int dm_test_ofnode_string_err(struct unit_test_state *uts)
@@ -743,7 +854,7 @@ static int dm_test_ofnode_string_err(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_string_err, UT_TESTF_LIVE_TREE);
+DM_TEST(dm_test_ofnode_string_err, UTF_LIVE_TREE);
static int dm_test_ofnode_read_phy_mode(struct unit_test_state *uts)
{
@@ -765,7 +876,7 @@ static int dm_test_ofnode_read_phy_mode(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_read_phy_mode, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_read_phy_mode, UTF_SCAN_FDT);
/**
* make_ofnode_fdt() - Create an FDT for testing with ofnode
@@ -812,7 +923,7 @@ static int dm_test_ofnode_aliases(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_aliases, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_aliases, UTF_SCAN_FDT);
/**
* dm_test_ofnode_root_mult() - Check aliaes on control and 'other' tree
@@ -851,7 +962,7 @@ static int dm_test_ofnode_root_mult(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_root_mult, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_root_mult, UTF_SCAN_FDT);
/* test ofnode_set_enabled(), ofnode_write_prop() on a livetree */
static int dm_test_ofnode_livetree_writing(struct unit_test_state *uts)
@@ -898,7 +1009,7 @@ static int dm_test_ofnode_livetree_writing(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_ofnode_livetree_writing,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int check_write_prop(struct unit_test_state *uts, ofnode node)
{
@@ -941,7 +1052,7 @@ static int dm_test_ofnode_write_copy(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_write_copy, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_write_copy, UTF_SCAN_FDT);
/* test writing a property to the 'other' tree */
static int dm_test_ofnode_write_copy_ot(struct unit_test_state *uts)
@@ -958,7 +1069,7 @@ static int dm_test_ofnode_write_copy_ot(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_write_copy_ot, UT_TESTF_SCAN_FDT | UT_TESTF_OTHER_FDT);
+DM_TEST(dm_test_ofnode_write_copy_ot, UTF_SCAN_FDT | UTF_OTHER_FDT);
/* test ofnode_read_u32_index/default() */
static int dm_test_ofnode_u32(struct unit_test_state *uts)
@@ -986,7 +1097,7 @@ static int dm_test_ofnode_u32(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_u32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_u32, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* test ofnode_read_u32_array() */
static int dm_test_ofnode_u32_array(struct unit_test_state *uts)
@@ -1013,7 +1124,7 @@ static int dm_test_ofnode_u32_array(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_u32_array, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_u32_array, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* test ofnode_read_u64() and ofnode_write_u64() */
static int dm_test_ofnode_u64(struct unit_test_state *uts)
@@ -1047,7 +1158,7 @@ static int dm_test_ofnode_u64(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_u64, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_u64, UTF_SCAN_FDT);
static int dm_test_ofnode_add_subnode(struct unit_test_state *uts)
{
@@ -1116,7 +1227,7 @@ static int dm_test_ofnode_add_subnode(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_add_subnode, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_add_subnode, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_ofnode_for_each_prop(struct unit_test_state *uts)
{
@@ -1140,7 +1251,7 @@ static int dm_test_ofnode_for_each_prop(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_for_each_prop, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_for_each_prop, UTF_SCAN_FDT);
static int dm_test_ofnode_by_compatible(struct unit_test_state *uts)
{
@@ -1156,7 +1267,7 @@ static int dm_test_ofnode_by_compatible(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_by_compatible, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_by_compatible, UTF_SCAN_FDT);
/* check ofnode_by_compatible() on the 'other' tree */
static int dm_test_ofnode_by_compatible_ot(struct unit_test_state *uts)
@@ -1174,7 +1285,7 @@ static int dm_test_ofnode_by_compatible_ot(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_by_compatible_ot, UT_TESTF_SCAN_FDT | UT_TESTF_OTHER_FDT);
+DM_TEST(dm_test_ofnode_by_compatible_ot, UTF_SCAN_FDT | UTF_OTHER_FDT);
static int dm_test_ofnode_find_subnode(struct unit_test_state *uts)
{
@@ -1191,7 +1302,26 @@ static int dm_test_ofnode_find_subnode(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_find_subnode, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_find_subnode, UTF_SCAN_FDT);
+
+/* check ofnode_find_subnode() with unit addresses */
+static int dm_test_ofnode_find_subnode_unit(struct unit_test_state *uts)
+{
+ ofnode node, subnode;
+
+ node = ofnode_path("/some-bus");
+ ut_assert(ofnode_valid(node));
+ subnode = ofnode_find_subnode_unit(node, "c-test@5");
+ ut_assert(ofnode_valid(subnode));
+ ut_asserteq_str("c-test@5", ofnode_get_name(subnode));
+
+ subnode = ofnode_find_subnode_unit(node, "c-test");
+ ut_assert(ofnode_valid(subnode));
+ ut_asserteq_str("c-test@5", ofnode_get_name(subnode));
+
+ return 0;
+}
+DM_TEST(dm_test_ofnode_find_subnode_unit, UTF_SCAN_FDT);
/* test ofnode_find_subnode() on the 'other' tree */
static int dm_test_ofnode_find_subnode_ot(struct unit_test_state *uts)
@@ -1210,7 +1340,7 @@ static int dm_test_ofnode_find_subnode_ot(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_find_subnode_ot, UT_TESTF_OTHER_FDT);
+DM_TEST(dm_test_ofnode_find_subnode_ot, UTF_OTHER_FDT);
static int dm_test_ofnode_get_name(struct unit_test_state *uts)
{
@@ -1223,7 +1353,7 @@ static int dm_test_ofnode_get_name(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_get_name, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_get_name, UTF_SCAN_FDT);
/* try to access more FDTs than is supported */
static int dm_test_ofnode_too_many(struct unit_test_state *uts)
@@ -1260,7 +1390,7 @@ static int dm_test_ofnode_too_many(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_too_many, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_too_many, UTF_SCAN_FDT);
static int check_copy_props(struct unit_test_state *uts, ofnode dst, ofnode src)
{
@@ -1305,7 +1435,7 @@ static int dm_test_ofnode_copy_props(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_copy_props, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_copy_props, UTF_SCAN_FDT);
/* test ofnode_copy_props() with the 'other' tree */
static int dm_test_ofnode_copy_props_ot(struct unit_test_state *uts)
@@ -1319,7 +1449,7 @@ static int dm_test_ofnode_copy_props_ot(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_copy_props_ot, UT_TESTF_SCAN_FDT | UT_TESTF_OTHER_FDT);
+DM_TEST(dm_test_ofnode_copy_props_ot, UTF_SCAN_FDT | UTF_OTHER_FDT);
/* check that the livetree is aligned to a structure boundary */
static int dm_test_livetree_align(struct unit_test_state *uts)
@@ -1345,7 +1475,7 @@ static int dm_test_livetree_align(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_livetree_align, UT_TESTF_SCAN_FDT | UT_TESTF_LIVE_TREE);
+DM_TEST(dm_test_livetree_align, UTF_SCAN_FDT | UTF_LIVE_TREE);
/* check that it is possible to load an arbitrary livetree */
static int dm_test_livetree_ensure(struct unit_test_state *uts)
@@ -1364,7 +1494,7 @@ static int dm_test_livetree_ensure(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_livetree_ensure, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_livetree_ensure, UTF_SCAN_FDT);
static int dm_test_oftree_new(struct unit_test_state *uts)
{
@@ -1380,7 +1510,7 @@ static int dm_test_oftree_new(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_oftree_new, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_oftree_new, UTF_SCAN_FDT);
static int check_copy_node(struct unit_test_state *uts, ofnode dst, ofnode src,
ofnode *nodep)
@@ -1429,7 +1559,7 @@ static int dm_test_ofnode_copy_node(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_copy_node, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_copy_node, UTF_SCAN_FDT);
/* test ofnode_copy_node() with the 'other' tree */
static int dm_test_ofnode_copy_node_ot(struct unit_test_state *uts)
@@ -1443,7 +1573,7 @@ static int dm_test_ofnode_copy_node_ot(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofnode_copy_node_ot, UT_TESTF_SCAN_FDT | UT_TESTF_OTHER_FDT);
+DM_TEST(dm_test_ofnode_copy_node_ot, UTF_SCAN_FDT | UTF_OTHER_FDT);
static int dm_test_ofnode_delete(struct unit_test_state *uts)
{
@@ -1470,11 +1600,11 @@ static int dm_test_ofnode_delete(struct unit_test_state *uts)
ut_assert(!ofnode_valid(node));
ut_assert(!ofnode_valid(ofnode_path("/leds/default_on")));
- ut_asserteq(2, ofnode_get_child_count(ofnode_path("/leds")));
+ ut_asserteq(7, ofnode_get_child_count(ofnode_path("/leds")));
return 0;
}
-DM_TEST(dm_test_ofnode_delete, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_delete, UTF_SCAN_FDT);
static int dm_test_oftree_to_fdt(struct unit_test_state *uts)
{
@@ -1496,7 +1626,7 @@ static int dm_test_oftree_to_fdt(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_oftree_to_fdt, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_oftree_to_fdt, UTF_SCAN_FDT);
/* test ofnode_read_bool() and ofnode_write_bool() */
static int dm_test_bool(struct unit_test_state *uts)
@@ -1521,4 +1651,57 @@ static int dm_test_bool(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_bool, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_bool, UTF_SCAN_FDT);
+
+/* test all helpers found in drivers/core/ofnode_graph.c */
+static int dm_test_ofnode_graph(struct unit_test_state *uts)
+{
+ /* 3 ports with 5 endpoints (2-1-2) */
+ ofnode graph1 = ofnode_path("/graph1");
+ /* 1 port with 1 endpoint */
+ ofnode graph2 = ofnode_path("/graph2");
+ ofnode node;
+ u32 id;
+
+ ut_asserteq(ofnode_graph_get_endpoint_count(graph1), 5);
+ ut_asserteq(ofnode_graph_get_endpoint_count(graph2), 1);
+
+ ut_asserteq(ofnode_graph_get_port_count(graph1), 3);
+ ut_asserteq(ofnode_graph_get_port_count(graph2), 1);
+
+ /* Request port with reg 2 */
+ node = ofnode_graph_get_port_by_id(graph1, 2);
+ ofnode_read_u32(node, "reg", &id);
+ ut_asserteq(id, 2);
+
+ /* Reqest parent from prev requested endpoint */
+ node = ofnode_graph_get_port_parent(node);
+ ut_asserteq_str(ofnode_get_name(node), "graph1");
+
+ /* Request endpoint under port 1 */
+ node = ofnode_graph_get_endpoint_by_regs(graph1, 1, -1);
+ ut_assert(ofnode_has_property(node, "test-property-0"));
+
+ /* Reqest remote endpoint from graph2 in graph1 */
+ node = ofnode_graph_get_endpoint_by_regs(graph2, -1, -1);
+ node = ofnode_graph_get_remote_endpoint(node);
+ ut_assert(ofnode_has_property(node, "test-property-1"));
+
+ /* Reqest remote parent from graph2 linked endpoint */
+ node = ofnode_graph_get_endpoint_by_regs(graph2, -1, -1);
+ node = ofnode_graph_get_remote_port_parent(node);
+ ut_asserteq_str(ofnode_get_name(node), "graph1");
+
+ /* Reqest remote port from graph2 linked endpoint */
+ node = ofnode_graph_get_endpoint_by_regs(graph2, -1, -1);
+ node = ofnode_graph_get_remote_port(node);
+ ofnode_read_u32(node, "reg", &id);
+ ut_asserteq(id, 2);
+
+ /* Reqest remote parent from graph2 linked endpoint */
+ node = ofnode_graph_get_remote_node(graph2, -1, -1);
+ ut_asserteq_str(ofnode_get_name(node), "graph1");
+
+ return 0;
+}
+DM_TEST(dm_test_ofnode_graph, UTF_SCAN_FDT);
diff --git a/test/dm/ofread.c b/test/dm/ofread.c
index 3523860d2b3..069551a31af 100644
--- a/test/dm/ofread.c
+++ b/test/dm/ofread.c
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: GPL-2.0+
-#include <common.h>
#include <dm.h>
#include <dm/test.h>
#include <test/ut.h>
@@ -46,4 +45,4 @@ static int dm_test_ofprop_get_property(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofprop_get_property, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofprop_get_property, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/osd.c b/test/dm/osd.c
index 6279b391ca5..5fb27a3d822 100644
--- a/test/dm/osd.c
+++ b/test/dm/osd.c
@@ -4,7 +4,6 @@
* Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
*/
-#include <common.h>
#include <display_options.h>
#include <dm.h>
#include <video_osd.h>
@@ -131,8 +130,7 @@ static int dm_test_osd_basics(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_osd_basics, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_osd_basics, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_osd_extended(struct unit_test_state *uts)
{
@@ -215,5 +213,4 @@ static int dm_test_osd_extended(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_osd_extended, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_osd_extended, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/p2sb.c b/test/dm/p2sb.c
index df24709141a..4cc374e04ed 100644
--- a/test/dm/p2sb.c
+++ b/test/dm/p2sb.c
@@ -5,7 +5,6 @@
* Copyright 2019 Google LLC
*/
-#include <common.h>
#include <dm.h>
#include <p2sb.h>
#include <asm/test.h>
@@ -25,4 +24,4 @@ static int dm_test_p2sb_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_p2sb_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_p2sb_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/panel.c b/test/dm/panel.c
index 4d435a0d255..ec85a9b1e6e 100644
--- a/test/dm/panel.c
+++ b/test/dm/panel.c
@@ -6,7 +6,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <backlight.h>
#include <dm.h>
#include <panel.h>
@@ -34,7 +33,7 @@ static int dm_test_panel(struct unit_test_state *uts)
ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
&enable, &polarity));
ut_asserteq(false, enable);
- ut_asserteq(false, regulator_get_enable(reg));
+ ut_asserteq(true, regulator_get_enable(reg));
ut_assertok(panel_enable_backlight(dev));
ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
@@ -77,4 +76,4 @@ static int dm_test_panel(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_panel, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_panel, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/part.c b/test/dm/part.c
index d6e43458127..c5c4b3fdba1 100644
--- a/test/dm/part.c
+++ b/test/dm/part.c
@@ -3,7 +3,6 @@
* Copyright (C) 2020 Sean Anderson <sean.anderson@seco.com>
*/
-#include <common.h>
#include <dm.h>
#include <mmc.h>
#include <part.h>
@@ -94,7 +93,7 @@ static int dm_test_part(struct unit_test_state *uts)
env_set("bootdevice", oldbootdevice);
return ret;
}
-DM_TEST(dm_test_part, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_part, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_part_bootable(struct unit_test_state *uts)
{
@@ -107,7 +106,7 @@ static int dm_test_part_bootable(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_part_bootable, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_part_bootable, UTF_SCAN_FDT);
static int do_get_info_test(struct unit_test_state *uts,
struct blk_desc *dev_desc, int part, int part_type,
@@ -194,4 +193,4 @@ static int dm_test_part_get_info_by_type(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_part_get_info_by_type, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_part_get_info_by_type, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/pch.c b/test/dm/pch.c
index 53f7bbf180c..88e924dc2a6 100644
--- a/test/dm/pch.c
+++ b/test/dm/pch.c
@@ -3,7 +3,6 @@
* Copyright 2018 Google LLC
*/
-#include <common.h>
#include <dm.h>
#include <pch.h>
#include <asm/test.h>
@@ -34,7 +33,7 @@ static int dm_test_pch_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_pch_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pch_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test sandbox PCH ioctl */
static int dm_test_pch_ioctl(struct unit_test_state *uts)
@@ -53,4 +52,4 @@ static int dm_test_pch_ioctl(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_pch_ioctl, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pch_ioctl, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/pci.c b/test/dm/pci.c
index 8c5e7da9e62..6eb19f6fea3 100644
--- a/test/dm/pci.c
+++ b/test/dm/pci.c
@@ -3,7 +3,6 @@
* Copyright (C) 2015 Google, Inc
*/
-#include <common.h>
#include <dm.h>
#include <asm/io.h>
#include <asm/test.h>
@@ -20,7 +19,7 @@ static int dm_test_pci_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_pci_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pci_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that sandbox PCI bus numbering and device works correctly */
static int dm_test_pci_busdev(struct unit_test_state *uts)
@@ -55,7 +54,7 @@ static int dm_test_pci_busdev(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_pci_busdev, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pci_busdev, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that we can use the swapcase device correctly */
static int dm_test_pci_swapcase(struct unit_test_state *uts)
@@ -108,7 +107,7 @@ static int dm_test_pci_swapcase(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_pci_swapcase, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pci_swapcase, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that we can dynamically bind the device driver correctly */
static int dm_test_pci_drvdata(struct unit_test_state *uts)
@@ -130,7 +129,7 @@ static int dm_test_pci_drvdata(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_pci_drvdata, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pci_drvdata, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that devices on PCI bus#2 can be accessed correctly */
static int dm_test_pci_mixed(struct unit_test_state *uts)
@@ -193,7 +192,7 @@ static int dm_test_pci_mixed(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_pci_mixed, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pci_mixed, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test looking up PCI capability and extended capability */
static int dm_test_pci_cap(struct unit_test_state *uts)
@@ -245,7 +244,7 @@ static int dm_test_pci_cap(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_pci_cap, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pci_cap, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test looking up BARs in EA capability structure */
static int dm_test_pci_ea(struct unit_test_state *uts)
@@ -294,7 +293,7 @@ static int dm_test_pci_ea(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_pci_ea, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pci_ea, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test the dev_read_addr_pci() function */
static int dm_test_pci_addr_flat(struct unit_test_state *uts)
@@ -319,14 +318,14 @@ static int dm_test_pci_addr_flat(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_pci_addr_flat, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT |
- UT_TESTF_FLAT_TREE);
+DM_TEST(dm_test_pci_addr_flat, UTF_SCAN_PDATA | UTF_SCAN_FDT |
+ UTF_FLAT_TREE);
/*
* Test the dev_read_addr_pci() function with livetree. That function is
* not currently fully implemented, in that it fails to return the BAR address.
* Once that is implemented this test can be removed and dm_test_pci_addr_flat()
- * can be used for both flattree and livetree by removing the UT_TESTF_FLAT_TREE
+ * can be used for both flattree and livetree by removing the UTF_FLAT_TREE
* flag above.
*/
static int dm_test_pci_addr_live(struct unit_test_state *uts)
@@ -344,8 +343,7 @@ static int dm_test_pci_addr_live(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_pci_addr_live, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT |
- UT_TESTF_LIVE_TREE);
+DM_TEST(dm_test_pci_addr_live, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_LIVE_TREE);
/* Test device_is_on_pci_bus() */
static int dm_test_pci_on_bus(struct unit_test_state *uts)
@@ -359,7 +357,7 @@ static int dm_test_pci_on_bus(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_pci_on_bus, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pci_on_bus, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/*
* Test support for multiple memory regions enabled via
@@ -381,7 +379,7 @@ static int dm_test_pci_region_multi(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_pci_region_multi, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pci_region_multi, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/*
* Test the translation of PCI bus addresses to physical addresses using the
@@ -434,7 +432,7 @@ static int dm_test_pci_bus_to_phys(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_pci_bus_to_phys, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pci_bus_to_phys, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/*
* Test the translation of physical addresses to PCI bus addresses using the
@@ -487,4 +485,4 @@ static int dm_test_pci_phys_to_bus(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_pci_phys_to_bus, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pci_phys_to_bus, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/pci_ep.c b/test/dm/pci_ep.c
index 9941abd4ceb..068b72a20c0 100644
--- a/test/dm/pci_ep.c
+++ b/test/dm/pci_ep.c
@@ -3,7 +3,6 @@
* Copyright (C) 2019 Ramon Fried
*/
-#include <common.h>
#include <dm.h>
#include <hexdump.h>
#include <pci_ep.h>
@@ -60,5 +59,4 @@ static int dm_test_pci_ep_base(struct unit_test_state *uts)
ut_asserteq(sandbox_get_pci_ep_irq_count(bus), 10);
return 0;
}
-
-DM_TEST(dm_test_pci_ep_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pci_ep_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/phy.c b/test/dm/phy.c
index 0cf3689fdec..194cad0bf70 100644
--- a/test/dm/phy.c
+++ b/test/dm/phy.c
@@ -4,7 +4,6 @@
* Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
*/
-#include <common.h>
#include <dm.h>
#include <generic-phy.h>
#include <log.h>
@@ -69,7 +68,7 @@ static int dm_test_phy_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_phy_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_phy_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test of the phy uclass using the sandbox phy driver operations */
static int dm_test_phy_ops(struct unit_test_state *uts)
@@ -141,7 +140,7 @@ static int dm_test_phy_ops(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_phy_ops, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_phy_ops, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_phy_bulk(struct unit_test_state *uts)
{
@@ -174,7 +173,7 @@ static int dm_test_phy_bulk(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_phy_bulk, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_phy_bulk, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_phy_multi_exit(struct unit_test_state *uts)
{
@@ -233,7 +232,7 @@ static int dm_test_phy_multi_exit(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_phy_multi_exit, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_phy_multi_exit, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_phy_setup(struct unit_test_state *uts)
{
@@ -244,22 +243,29 @@ static int dm_test_phy_setup(struct unit_test_state *uts)
"gen_phy_user", &parent));
/* normal */
- ut_assertok(generic_setup_phy(parent, &phy, 0));
+ ut_assertok(generic_setup_phy(parent, &phy, 0, PHY_MODE_USB_HOST, 0));
+ ut_assertok(generic_shutdown_phy(&phy));
+
+ /* set_mode as USB Host passes, anything else is not supported */
+ ut_assertok(generic_setup_phy(parent, &phy, 0, PHY_MODE_USB_HOST, 0));
+ ut_assertok(generic_phy_set_mode(&phy, PHY_MODE_USB_HOST, 0));
+ ut_asserteq(-EOPNOTSUPP, generic_phy_set_mode(&phy, PHY_MODE_USB_HOST, 1));
+ ut_asserteq(-EINVAL, generic_phy_set_mode(&phy, PHY_MODE_USB_DEVICE, 0));
ut_assertok(generic_shutdown_phy(&phy));
/* power_off fail with -EIO */
- ut_assertok(generic_setup_phy(parent, &phy, 1));
+ ut_assertok(generic_setup_phy(parent, &phy, 1, PHY_MODE_USB_HOST, 0));
ut_asserteq(-EIO, generic_shutdown_phy(&phy));
/* power_on fail with -EIO */
- ut_asserteq(-EIO, generic_setup_phy(parent, &phy, 2));
+ ut_asserteq(-EIO, generic_setup_phy(parent, &phy, 2, PHY_MODE_USB_HOST, 0));
ut_assertok(generic_shutdown_phy(&phy));
/* generic_phy_get_by_index fail with -ENOENT */
ut_asserteq(-ENOENT, generic_phy_get_by_index(parent, 3, &phy));
- ut_assertok(generic_setup_phy(parent, &phy, 3));
+ ut_assertok(generic_setup_phy(parent, &phy, 3, PHY_MODE_USB_HOST, 0));
ut_assertok(generic_shutdown_phy(&phy));
return 0;
}
-DM_TEST(dm_test_phy_setup, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_phy_setup, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/phys2bus.c b/test/dm/phys2bus.c
index 342f2fa8eba..0f30c7e37fd 100644
--- a/test/dm/phys2bus.c
+++ b/test/dm/phys2bus.c
@@ -3,7 +3,6 @@
* Copyright (c) 2020 Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
*/
-#include <common.h>
#include <dm.h>
#include <mapmem.h>
#include <phys2bus.h>
@@ -34,4 +33,4 @@ static int dm_test_phys_to_bus(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_phys_to_bus, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_phys_to_bus, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/pinmux.c b/test/dm/pinmux.c
index 6880b2d2cd9..92e5bc83802 100644
--- a/test/dm/pinmux.c
+++ b/test/dm/pinmux.c
@@ -3,7 +3,6 @@
* Copyright (C) 2020 Sean Anderson <seanga2@gmail.com>
*/
-#include <common.h>
#include <dm.h>
#include <dm/pinctrl.h>
#include <dm/test.h>
@@ -69,8 +68,7 @@ static int dm_test_pinmux(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_pinmux, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pinmux, UTF_SCAN_FDT);
static int dm_test_pinctrl_single(struct unit_test_state *uts)
{
@@ -144,5 +142,4 @@ static int dm_test_pinctrl_single(struct unit_test_state *uts)
ut_asserteq(-EINVAL, ret);
return 0;
}
-
-DM_TEST(dm_test_pinctrl_single, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pinctrl_single, UTF_SCAN_FDT);
diff --git a/test/dm/pmc.c b/test/dm/pmc.c
index e70227e7800..00122798b71 100644
--- a/test/dm/pmc.c
+++ b/test/dm/pmc.c
@@ -5,7 +5,6 @@
* Copyright 2019 Google LLC
*/
-#include <common.h>
#include <dm.h>
#include <power/acpi_pmc.h>
#include <dm/test.h>
@@ -30,4 +29,4 @@ static int dm_test_pmc_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_pmc_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pmc_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/pmic.c b/test/dm/pmic.c
index ce671202fbc..70dd18f5df0 100644
--- a/test/dm/pmic.c
+++ b/test/dm/pmic.c
@@ -6,7 +6,6 @@
* Przemyslaw Marczak <p.marczak@samsung.com>
*/
-#include <common.h>
#include <errno.h>
#include <dm.h>
#include <fdtdec.h>
@@ -44,7 +43,7 @@ static int dm_test_power_pmic_get(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_power_pmic_get, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_power_pmic_get, UTF_SCAN_FDT);
/* PMIC get method - MC34708 - for 3 bytes transmission */
static int dm_test_power_pmic_mc34708_get(struct unit_test_state *uts)
@@ -53,8 +52,7 @@ static int dm_test_power_pmic_mc34708_get(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_power_pmic_mc34708_get, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_power_pmic_mc34708_get, UTF_SCAN_FDT);
/* Test PMIC I/O */
static int dm_test_power_pmic_io(struct unit_test_state *uts)
@@ -83,7 +81,7 @@ static int dm_test_power_pmic_io(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_power_pmic_io, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_power_pmic_io, UTF_SCAN_FDT);
#define MC34708_PMIC_REG_COUNT 64
#define MC34708_PMIC_TEST_VAL 0x125534
@@ -100,8 +98,7 @@ static int dm_test_power_pmic_mc34708_regs_check(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_power_pmic_mc34708_regs_check, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_power_pmic_mc34708_regs_check, UTF_SCAN_FDT);
static int dm_test_power_pmic_mc34708_rw_val(struct unit_test_state *uts)
{
@@ -127,5 +124,4 @@ static int dm_test_power_pmic_mc34708_rw_val(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_power_pmic_mc34708_rw_val, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_power_pmic_mc34708_rw_val, UTF_SCAN_FDT);
diff --git a/test/dm/power-domain.c b/test/dm/power-domain.c
index 8604b5d72dc..1002d831764 100644
--- a/test/dm/power-domain.c
+++ b/test/dm/power-domain.c
@@ -3,7 +3,6 @@
* Copyright (c) 2016, NVIDIA CORPORATION.
*/
-#include <common.h>
#include <dm.h>
#include <malloc.h>
#include <dm/test.h>
@@ -28,7 +27,7 @@ static int dm_test_power_domain(struct unit_test_state *uts)
ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "power-domain-test",
&dev_test));
- ut_asserteq(1, sandbox_power_domain_query(dev_power_domain,
+ ut_asserteq(0, sandbox_power_domain_query(dev_power_domain,
TEST_POWER_DOMAIN));
ut_assertok(sandbox_power_domain_test_get(dev_test));
@@ -36,14 +35,23 @@ static int dm_test_power_domain(struct unit_test_state *uts)
ut_asserteq(0, sandbox_power_domain_query(dev_power_domain, 0));
ut_asserteq(1, sandbox_power_domain_query(dev_power_domain,
TEST_POWER_DOMAIN));
+ ut_asserteq(-EALREADY, sandbox_power_domain_test_on_ll(dev_test));
+ ut_asserteq(1, sandbox_power_domain_query(dev_power_domain,
+ TEST_POWER_DOMAIN));
+ ut_asserteq(-EBUSY, sandbox_power_domain_test_off_ll(dev_test));
+ ut_asserteq(1, sandbox_power_domain_query(dev_power_domain,
+ TEST_POWER_DOMAIN));
ut_assertok(sandbox_power_domain_test_off(dev_test));
ut_asserteq(0, sandbox_power_domain_query(dev_power_domain, 0));
ut_asserteq(0, sandbox_power_domain_query(dev_power_domain,
TEST_POWER_DOMAIN));
+ ut_asserteq(-EALREADY, sandbox_power_domain_test_off_ll(dev_test));
+ ut_asserteq(0, sandbox_power_domain_query(dev_power_domain,
+ TEST_POWER_DOMAIN));
ut_assertok(sandbox_power_domain_test_free(dev_test));
return 0;
}
-DM_TEST(dm_test_power_domain, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_power_domain, UTF_SCAN_FDT);
diff --git a/test/dm/pwm.c b/test/dm/pwm.c
index dff626c771a..5ccd8bc89b9 100644
--- a/test/dm/pwm.c
+++ b/test/dm/pwm.c
@@ -3,7 +3,6 @@
* Copyright (C) 2017 Google, Inc
*/
-#include <common.h>
#include <dm.h>
#include <pwm.h>
#include <asm/test.h>
@@ -42,4 +41,4 @@ static int dm_test_pwm_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_pwm_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pwm_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/qfw.c b/test/dm/qfw.c
index f3f35689830..b6be5c5baa5 100644
--- a/test/dm/qfw.c
+++ b/test/dm/qfw.c
@@ -3,7 +3,6 @@
* Copyright 2021 Asherah Connor <ashe@kivikakk.ee>
*/
-#include <common.h>
#include <qfw.h>
#include <dm.h>
#include <asm/test.h>
@@ -24,8 +23,7 @@ static int dm_test_qfw_cpus(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_qfw_cpus, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_qfw_cpus, UTF_SCAN_PDATA);
static int dm_test_qfw_firmware_list(struct unit_test_state *uts)
{
@@ -38,5 +36,4 @@ static int dm_test_qfw_firmware_list(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_qfw_firmware_list, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_qfw_firmware_list, UTF_SCAN_PDATA);
diff --git a/test/dm/ram.c b/test/dm/ram.c
index f624343138d..f3710b1f691 100644
--- a/test/dm/ram.c
+++ b/test/dm/ram.c
@@ -3,7 +3,6 @@
* Copyright (C) 2015 Google, Inc
*/
-#include <common.h>
#include <dm.h>
#include <ram.h>
#include <asm/global_data.h>
@@ -26,4 +25,4 @@ static int dm_test_ram_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ram_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ram_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/read.c b/test/dm/read.c
index 7768aa29688..0aa822195a8 100644
--- a/test/dm/read.c
+++ b/test/dm/read.c
@@ -3,7 +3,6 @@
* Copyright (c) 2020 Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
*/
-#include <common.h>
#include <dm.h>
#include <dm/device.h>
#include <dm/ofnode.h>
@@ -46,4 +45,4 @@ static int dm_test_dma_ranges(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_dma_ranges, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_dma_ranges, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/reboot-mode.c b/test/dm/reboot-mode.c
index fbb9c3a5426..9a3b2bf0a43 100644
--- a/test/dm/reboot-mode.c
+++ b/test/dm/reboot-mode.c
@@ -3,7 +3,6 @@
* (C) 2018 Theobroma Systems Design und Consulting GmbH
*/
-#include <common.h>
#include <dm.h>
#include <reboot-mode/reboot-mode.h>
#include <env.h>
@@ -40,9 +39,8 @@ static int dm_test_reboot_mode_gpio(struct unit_test_state *uts)
return 0;
}
-
DM_TEST(dm_test_reboot_mode_gpio,
- UT_TESTF_PROBE_TEST | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
+ UTF_PROBE_TEST | UTF_SCAN_FDT | UTF_FLAT_TREE);
static int dm_test_reboot_mode_rtc(struct unit_test_state *uts)
{
@@ -66,6 +64,5 @@ static int dm_test_reboot_mode_rtc(struct unit_test_state *uts)
return 0;
}
-
DM_TEST(dm_test_reboot_mode_rtc,
- UT_TESTF_PROBE_TEST | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
+ UTF_PROBE_TEST | UTF_SCAN_FDT | UTF_FLAT_TREE);
diff --git a/test/dm/regmap.c b/test/dm/regmap.c
index 8560f2afc2d..5024b47c7a2 100644
--- a/test/dm/regmap.c
+++ b/test/dm/regmap.c
@@ -3,13 +3,13 @@
* Copyright (C) 2015 Google, Inc
*/
-#include <common.h>
#include <dm.h>
#include <log.h>
#include <mapmem.h>
#include <regmap.h>
#include <syscon.h>
#include <rand.h>
+#include <time.h>
#include <asm/test.h>
#include <dm/test.h>
#include <dm/devres.h>
@@ -69,7 +69,7 @@ static int dm_test_regmap_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_regmap_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_regmap_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test we can access a regmap through syscon */
static int dm_test_regmap_syscon(struct unit_test_state *uts)
@@ -94,8 +94,7 @@ static int dm_test_regmap_syscon(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_regmap_syscon, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_regmap_syscon, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Read/Write/Modify test */
static int dm_test_regmap_rw(struct unit_test_state *uts)
@@ -128,8 +127,7 @@ static int dm_test_regmap_rw(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_regmap_rw, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_regmap_rw, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Get/Set test */
static int dm_test_regmap_getset(struct unit_test_state *uts)
@@ -159,8 +157,7 @@ static int dm_test_regmap_getset(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_regmap_getset, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_regmap_getset, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Read polling test */
static int dm_test_regmap_poll(struct unit_test_state *uts)
@@ -187,8 +184,7 @@ static int dm_test_regmap_poll(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_regmap_poll, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_regmap_poll, UTF_SCAN_PDATA | UTF_SCAN_FDT);
struct regmaptest_priv {
struct regmap *cfg_regmap; /* For testing regmap_config options. */
@@ -324,7 +320,7 @@ static int dm_test_devm_regmap(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_devm_regmap, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_devm_regmap, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int test_one_field(struct unit_test_state *uts,
struct regmap *regmap,
@@ -383,4 +379,4 @@ static int dm_test_devm_regmap_field(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_devm_regmap_field, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_devm_regmap_field, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/regulator.c b/test/dm/regulator.c
index 86f4862d9dd..449748ad52f 100644
--- a/test/dm/regulator.c
+++ b/test/dm/regulator.c
@@ -6,7 +6,6 @@
* Przemyslaw Marczak <p.marczak@samsung.com>
*/
-#include <common.h>
#include <errno.h>
#include <dm.h>
#include <fdtdec.h>
@@ -90,7 +89,7 @@ static int dm_test_power_regulator_get(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_power_regulator_get, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_power_regulator_get, UTF_SCAN_FDT);
/* Test regulator set and get Voltage method */
static int dm_test_power_regulator_set_get_voltage(struct unit_test_state *uts)
@@ -117,7 +116,7 @@ static int dm_test_power_regulator_set_get_voltage(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_power_regulator_set_get_voltage, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_power_regulator_set_get_voltage, UTF_SCAN_FDT);
/* Test regulator set and get Current method */
static int dm_test_power_regulator_set_get_current(struct unit_test_state *uts)
@@ -156,7 +155,7 @@ static int dm_test_power_regulator_set_get_current(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_power_regulator_set_get_current, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_power_regulator_set_get_current, UTF_SCAN_FDT);
/* Test regulator set and get Enable method */
static int dm_test_power_regulator_set_get_enable(struct unit_test_state *uts)
@@ -175,7 +174,7 @@ static int dm_test_power_regulator_set_get_enable(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_power_regulator_set_get_enable, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_power_regulator_set_get_enable, UTF_SCAN_FDT);
/* Test regulator set and get enable if allowed method */
static
@@ -187,7 +186,7 @@ int dm_test_power_regulator_set_enable_if_allowed(struct unit_test_state *uts)
/* Get BUCK1 - always on regulator */
platname = regulator_names[BUCK1][PLATNAME];
- ut_assertok(regulator_autoset_by_name(platname, &dev_autoset));
+ ut_asserteq(-EALREADY, regulator_autoset_by_name(platname, &dev_autoset));
ut_assertok(regulator_get_by_platname(platname, &dev));
/* Try disabling always-on regulator */
@@ -196,7 +195,7 @@ int dm_test_power_regulator_set_enable_if_allowed(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_power_regulator_set_enable_if_allowed, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_power_regulator_set_enable_if_allowed, UTF_SCAN_FDT);
/* Test regulator set and get mode method */
static int dm_test_power_regulator_set_get_mode(struct unit_test_state *uts)
@@ -215,7 +214,7 @@ static int dm_test_power_regulator_set_get_mode(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_power_regulator_set_get_mode, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_power_regulator_set_get_mode, UTF_SCAN_FDT);
/* Test regulator set and get suspend Voltage method */
static int dm_test_power_regulator_set_get_suspend_voltage(struct unit_test_state *uts)
@@ -245,7 +244,7 @@ static int dm_test_power_regulator_set_get_suspend_voltage(struct unit_test_stat
}
return 0;
}
-DM_TEST(dm_test_power_regulator_set_get_suspend_voltage, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_power_regulator_set_get_suspend_voltage, UTF_SCAN_FDT);
/* Test regulator set and get suspend Enable method */
static int dm_test_power_regulator_set_get_suspend_enable(struct unit_test_state *uts)
@@ -272,7 +271,7 @@ static int dm_test_power_regulator_set_get_suspend_enable(struct unit_test_state
}
return 0;
}
-DM_TEST(dm_test_power_regulator_set_get_suspend_enable, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_power_regulator_set_get_suspend_enable, UTF_SCAN_FDT);
/* Test regulator autoset method */
static int dm_test_power_regulator_autoset(struct unit_test_state *uts)
@@ -289,7 +288,7 @@ static int dm_test_power_regulator_autoset(struct unit_test_state *uts)
* Expected output state: uV=1200000; uA=200000; output enabled
*/
platname = regulator_names[BUCK1][PLATNAME];
- ut_assertok(regulator_autoset_by_name(platname, &dev_autoset));
+ ut_asserteq(-EALREADY, regulator_autoset_by_name(platname, &dev_autoset));
/* Check, that the returned device is proper */
ut_assertok(regulator_get_by_platname(platname, &dev));
@@ -305,7 +304,7 @@ static int dm_test_power_regulator_autoset(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_power_regulator_autoset, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_power_regulator_autoset, UTF_SCAN_FDT);
/*
* Struct setting: to keep the expected output settings.
@@ -401,4 +400,4 @@ static int dm_test_power_regulator_autoset_list(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_power_regulator_autoset_list, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_power_regulator_autoset_list, UTF_SCAN_FDT);
diff --git a/test/dm/remoteproc.c b/test/dm/remoteproc.c
index f6f9e509e27..921314ba930 100644
--- a/test/dm/remoteproc.c
+++ b/test/dm/remoteproc.c
@@ -3,7 +3,8 @@
* (C) Copyright 2015
* Texas Instruments Incorporated - https://www.ti.com/
*/
-#include <common.h>
+
+#include <config.h>
#include <dm.h>
#include <elf.h>
#include <errno.h>
@@ -27,7 +28,6 @@ static int dm_test_remoteproc_base(struct unit_test_state *uts)
/* Ensure we are initialized */
ut_asserteq(true, rproc_is_initialized());
-
/* platform data device 1 */
ut_assertok(rproc_stop(0));
ut_assertok(rproc_reset(0));
@@ -68,7 +68,7 @@ static int dm_test_remoteproc_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_remoteproc_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_remoteproc_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
#define DEVICE_TO_PHYSICAL_OFFSET 0x1000
/**
@@ -256,4 +256,4 @@ static int dm_test_remoteproc_elf(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_remoteproc_elf, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_remoteproc_elf, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/reset.c b/test/dm/reset.c
index e2d6f456230..dceb6a1dad3 100644
--- a/test/dm/reset.c
+++ b/test/dm/reset.c
@@ -3,7 +3,6 @@
* Copyright (c) 2016, NVIDIA CORPORATION.
*/
-#include <common.h>
#include <dm.h>
#include <dm/device-internal.h>
#include <log.h>
@@ -67,8 +66,7 @@ static int dm_test_reset_base(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_reset_base, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_reset_base, UTF_SCAN_FDT);
static int dm_test_reset(struct unit_test_state *uts)
{
@@ -95,7 +93,7 @@ static int dm_test_reset(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_reset, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_reset, UTF_SCAN_FDT);
static int dm_test_reset_devm(struct unit_test_state *uts)
{
@@ -120,7 +118,7 @@ static int dm_test_reset_devm(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_reset_devm, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_reset_devm, UTF_SCAN_FDT);
static int dm_test_reset_bulk(struct unit_test_state *uts)
{
@@ -150,7 +148,7 @@ static int dm_test_reset_bulk(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_reset_bulk, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_reset_bulk, UTF_SCAN_FDT);
static int dm_test_reset_bulk_devm(struct unit_test_state *uts)
{
@@ -182,4 +180,4 @@ static int dm_test_reset_bulk_devm(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_reset_bulk_devm, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_reset_bulk_devm, UTF_SCAN_FDT);
diff --git a/test/dm/rkmtd.c b/test/dm/rkmtd.c
index 3c3e8efa92f..d1ca5d1acac 100644
--- a/test/dm/rkmtd.c
+++ b/test/dm/rkmtd.c
@@ -8,7 +8,6 @@
* Copyright (C) 2023 Johan Jonker <jbx6244@gmail.com>
*/
-#include <common.h>
#include <blk.h>
#include <dm.h>
#include <fs.h>
@@ -86,7 +85,7 @@ static int dm_test_rkmtd(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_rkmtd, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_rkmtd, UTF_SCAN_FDT);
/* Reusing the same label should work */
static int dm_test_rkmtd_dup(struct unit_test_state *uts)
@@ -113,7 +112,7 @@ static int dm_test_rkmtd_dup(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_rkmtd_dup, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_rkmtd_dup, UTF_SCAN_FDT);
/* Basic test of the 'rkmtd' command */
static int dm_test_rkmtd_cmd(struct unit_test_state *uts)
@@ -197,4 +196,4 @@ static int dm_test_rkmtd_cmd(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_rkmtd_cmd, UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
+DM_TEST(dm_test_rkmtd_cmd, UTF_SCAN_FDT | UTF_CONSOLE);
diff --git a/test/dm/rng.c b/test/dm/rng.c
index 6d1f68848d5..d7ef0722ff5 100644
--- a/test/dm/rng.c
+++ b/test/dm/rng.c
@@ -3,7 +3,6 @@
* Copyright (c) 2019, Linaro Limited
*/
-#include <common.h>
#include <dm.h>
#include <log.h>
#include <rng.h>
@@ -24,7 +23,7 @@ static int dm_test_rng_read(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_rng_read, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_rng_read, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test the rng command */
static int dm_test_rng_cmd(struct unit_test_state *uts)
@@ -34,8 +33,6 @@ static int dm_test_rng_cmd(struct unit_test_state *uts)
ut_assertok(uclass_get_device(UCLASS_RNG, 0, &dev));
ut_assertnonnull(dev);
- ut_assertok(console_record_reset_enable());
-
run_command("rng", 0);
ut_assert_nextlinen("00000000:");
ut_assert_nextlinen("00000010:");
@@ -53,4 +50,4 @@ static int dm_test_rng_cmd(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_rng_cmd, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
+DM_TEST(dm_test_rng_cmd, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE);
diff --git a/test/dm/rtc.c b/test/dm/rtc.c
index bf97dbbd2f9..88f080b64a8 100644
--- a/test/dm/rtc.c
+++ b/test/dm/rtc.c
@@ -4,7 +4,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <console.h>
#include <dm.h>
#include <i2c.h>
@@ -28,7 +27,7 @@ static int dm_test_rtc_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_rtc_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_rtc_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static void show_time(const char *msg, struct rtc_time *time)
{
@@ -143,7 +142,7 @@ static int dm_test_rtc_set_get(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_rtc_set_get, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_rtc_set_get, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_rtc_read_write(struct unit_test_state *uts)
{
@@ -187,13 +186,11 @@ static int dm_test_rtc_read_write(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_rtc_read_write, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_rtc_read_write, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test 'rtc list' command */
static int dm_test_rtc_cmd_list(struct unit_test_state *uts)
{
- console_record_reset();
-
run_command("rtc list", 0);
ut_assert_nextline("RTC #0 - rtc@43");
ut_assert_nextline("RTC #1 - rtc@61");
@@ -201,13 +198,11 @@ static int dm_test_rtc_cmd_list(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_rtc_cmd_list, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_rtc_cmd_list, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE);
/* Test 'rtc read' and 'rtc write' commands */
static int dm_test_rtc_cmd_rw(struct unit_test_state *uts)
{
- console_record_reset();
-
run_command("rtc dev 0", 0);
ut_assert_nextline("RTC #0 - rtc@43");
ut_assert_console_end();
@@ -244,7 +239,7 @@ static int dm_test_rtc_cmd_rw(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_rtc_cmd_rw, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_rtc_cmd_rw, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE);
/* Reset the time */
static int dm_test_rtc_reset(struct unit_test_state *uts)
@@ -281,7 +276,7 @@ static int dm_test_rtc_reset(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_rtc_reset, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_rtc_reset, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Check that two RTC devices can be used independently */
static int dm_test_rtc_dual(struct unit_test_state *uts)
@@ -313,4 +308,4 @@ static int dm_test_rtc_dual(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_rtc_dual, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_rtc_dual, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/scmi.c b/test/dm/scmi.c
index adf36ffaab1..3655594c26d 100644
--- a/test/dm/scmi.c
+++ b/test/dm/scmi.c
@@ -12,14 +12,13 @@
* unknown SCMI protocol ID.
*/
-#include <common.h>
#include <clk.h>
#include <dm.h>
#include <reset.h>
#include <scmi_agent.h>
#include <scmi_agent-uclass.h>
#include <scmi_protocols.h>
-#include <vsprintf.h>
+#include <stdio.h>
#include <asm/scmi_test.h>
#include <dm/device-internal.h>
#include <dm/test.h>
@@ -96,7 +95,7 @@ static int dm_test_scmi_sandbox_agent(struct unit_test_state *uts)
return ret;
}
-DM_TEST(dm_test_scmi_sandbox_agent, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_scmi_sandbox_agent, UTF_SCAN_FDT);
static int dm_test_scmi_base(struct unit_test_state *uts)
{
@@ -203,8 +202,7 @@ static int dm_test_scmi_base(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_scmi_base, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_scmi_base, UTF_SCAN_FDT);
static int dm_test_scmi_cmd(struct unit_test_state *uts)
{
@@ -283,8 +281,7 @@ static int dm_test_scmi_cmd(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_scmi_cmd, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_scmi_cmd, UTF_SCAN_FDT | UTF_CONSOLE);
static int dm_test_scmi_power_domains(struct unit_test_state *uts)
{
@@ -389,8 +386,7 @@ static int dm_test_scmi_power_domains(struct unit_test_state *uts)
return release_sandbox_scmi_test_devices(uts, dev);
}
-
-DM_TEST(dm_test_scmi_power_domains, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_scmi_power_domains, UTF_SCAN_FDT);
static int dm_test_scmi_clocks(struct unit_test_state *uts)
{
@@ -459,7 +455,7 @@ static int dm_test_scmi_clocks(struct unit_test_state *uts)
return release_sandbox_scmi_test_devices(uts, dev);
}
-DM_TEST(dm_test_scmi_clocks, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_scmi_clocks, UTF_SCAN_FDT);
static int dm_test_scmi_resets(struct unit_test_state *uts)
{
@@ -497,7 +493,7 @@ static int dm_test_scmi_resets(struct unit_test_state *uts)
return release_sandbox_scmi_test_devices(uts, dev);
}
-DM_TEST(dm_test_scmi_resets, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_scmi_resets, UTF_SCAN_FDT);
static int dm_test_scmi_voltage_domains(struct unit_test_state *uts)
{
@@ -552,4 +548,4 @@ static int dm_test_scmi_voltage_domains(struct unit_test_state *uts)
return release_sandbox_scmi_test_devices(uts, dev);
}
-DM_TEST(dm_test_scmi_voltage_domains, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_scmi_voltage_domains, UTF_SCAN_FDT);
diff --git a/test/dm/scsi.c b/test/dm/scsi.c
index 380cfc88bab..fbc36a74244 100644
--- a/test/dm/scsi.c
+++ b/test/dm/scsi.c
@@ -3,7 +3,6 @@
* Copyright (C) 2015 Google, Inc
*/
-#include <common.h>
#include <dm.h>
#include <part.h>
#include <scsi.h>
@@ -36,4 +35,4 @@ static int dm_test_scsi_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_scsi_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_scsi_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/serial.c b/test/dm/serial.c
index 34b783e062e..4acb14f41bc 100644
--- a/test/dm/serial.c
+++ b/test/dm/serial.c
@@ -3,7 +3,6 @@
* Copyright (c) 2018, STMicroelectronics
*/
-#include <common.h>
#include <log.h>
#include <serial.h>
#include <dm.h>
@@ -88,5 +87,4 @@ static int dm_test_serial(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_serial, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_serial, UTF_SCAN_FDT);
diff --git a/test/dm/sf.c b/test/dm/sf.c
index 17d43fef3bc..3684d021709 100644
--- a/test/dm/sf.c
+++ b/test/dm/sf.c
@@ -3,7 +3,6 @@
* Copyright (C) 2013 Google, Inc
*/
-#include <common.h>
#include <command.h>
#include <dm.h>
#include <fdtdec.h>
@@ -73,7 +72,7 @@ static int dm_test_spi_flash(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_spi_flash, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_spi_flash, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Functional test that sandbox SPI flash works correctly */
static int dm_test_spi_flash_func(struct unit_test_state *uts)
@@ -101,4 +100,4 @@ static int dm_test_spi_flash_func(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_spi_flash_func, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_spi_flash_func, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/simple-bus.c b/test/dm/simple-bus.c
index 3530b47fac2..d9534830b16 100644
--- a/test/dm/simple-bus.c
+++ b/test/dm/simple-bus.c
@@ -3,7 +3,6 @@
* Copyright (C) 2021, Bin Meng <bmeng.cn@gmail.com>
*/
-#include <common.h>
#include <dm.h>
#include <dm/test.h>
#include <dm/simple_bus.h>
@@ -30,4 +29,4 @@ static int dm_test_simple_bus(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_simple_bus, UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
+DM_TEST(dm_test_simple_bus, UTF_SCAN_FDT | UTF_FLAT_TREE);
diff --git a/test/dm/simple-pm-bus.c b/test/dm/simple-pm-bus.c
index 792c7450580..8ae5e7754a9 100644
--- a/test/dm/simple-pm-bus.c
+++ b/test/dm/simple-pm-bus.c
@@ -3,7 +3,6 @@
* Copyright (C) 2020 Sean Anderson <seanga2@gmail.com>
*/
-#include <common.h>
#include <dm.h>
#include <dm/test.h>
#include <dm/device-internal.h>
@@ -42,4 +41,4 @@ static int dm_test_simple_pm_bus(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_simple_pm_bus, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_simple_pm_bus, UTF_SCAN_FDT);
diff --git a/test/dm/sm.c b/test/dm/sm.c
index 7ebb0c9c85e..cf4dab6a722 100644
--- a/test/dm/sm.c
+++ b/test/dm/sm.c
@@ -5,7 +5,6 @@
* Author: Alexey Romanov <avromanov@salutedevices.com>
*/
-#include <common.h>
#include <dm.h>
#include <sm.h>
#include <sandbox-sm.h>
@@ -61,5 +60,4 @@ static int dm_test_sm(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_sm, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_sm, UTF_SCAN_FDT);
diff --git a/test/dm/smem.c b/test/dm/smem.c
index 289fb59ba13..89e74cccc57 100644
--- a/test/dm/smem.c
+++ b/test/dm/smem.c
@@ -3,7 +3,6 @@
* Copyright (C) 2018 Ramon Fried <ramon.fried@gmail.com>
*/
-#include <common.h>
#include <dm.h>
#include <smem.h>
#include <dm/test.h>
@@ -24,4 +23,4 @@ static int dm_test_smem_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_smem_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_smem_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/soc.c b/test/dm/soc.c
index 8f6c97fa790..a6b82e5376d 100644
--- a/test/dm/soc.c
+++ b/test/dm/soc.c
@@ -6,7 +6,6 @@
* Dave Gerlach <d-gerlach@ti.com>
*/
-#include <common.h>
#include <dm.h>
#include <dm/test.h>
#include <dm/uclass-internal.h>
@@ -116,5 +115,4 @@ static int dm_test_soc(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_soc, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_soc, UTF_SCAN_FDT);
diff --git a/test/dm/sound.c b/test/dm/sound.c
index 15d545ab5a3..7b5556738dc 100644
--- a/test/dm/sound.c
+++ b/test/dm/sound.c
@@ -4,7 +4,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <dm.h>
#include <sound.h>
#include <dm/test.h>
@@ -44,7 +43,7 @@ static int dm_test_sound(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_sound, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_sound, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test of the 'start beep' operations */
static int dm_test_sound_beep(struct unit_test_state *uts)
@@ -65,4 +64,4 @@ static int dm_test_sound_beep(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_sound_beep, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_sound_beep, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/spi.c b/test/dm/spi.c
index 325799bbf10..249a9238fed 100644
--- a/test/dm/spi.c
+++ b/test/dm/spi.c
@@ -3,7 +3,6 @@
* Copyright (C) 2013 Google, Inc
*/
-#include <common.h>
#include <dm.h>
#include <fdtdec.h>
#include <spi.h>
@@ -90,7 +89,7 @@ static int dm_test_spi_find(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_spi_find, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_spi_find, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* dm_test_spi_switch_slaves - Helper function to check whether spi_claim_bus
* operates correctly with two spi slaves.
@@ -169,7 +168,7 @@ static int dm_test_spi_claim_bus(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_spi_claim_bus, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_spi_claim_bus, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that sandbox SPI works correctly */
static int dm_test_spi_xfer(struct unit_test_state *uts)
@@ -200,4 +199,4 @@ static int dm_test_spi_xfer(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_spi_xfer, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_spi_xfer, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/spmi.c b/test/dm/spmi.c
index 97bb0eb30fc..d706fc981ca 100644
--- a/test/dm/spmi.c
+++ b/test/dm/spmi.c
@@ -3,7 +3,6 @@
* (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
*/
-#include <common.h>
#include <fdtdec.h>
#include <dm.h>
#include <malloc.h>
@@ -44,7 +43,7 @@ static int dm_test_spmi_probe(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_spmi_probe, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_spmi_probe, UTF_SCAN_FDT);
/* Test if it's possible to read bus directly and indirectly */
static int dm_test_spmi_access(struct unit_test_state *uts)
@@ -69,8 +68,7 @@ static int dm_test_spmi_access(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_spmi_access, UT_TESTF_SCAN_FDT);
-
+DM_TEST(dm_test_spmi_access, UTF_SCAN_FDT);
/* Test if it's possible to access GPIO that should be in pmic */
static int dm_test_spmi_access_peripheral(struct unit_test_state *uts)
@@ -110,4 +108,4 @@ static int dm_test_spmi_access_peripheral(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_spmi_access_peripheral, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_spmi_access_peripheral, UTF_SCAN_FDT);
diff --git a/test/dm/syscon-reset.c b/test/dm/syscon-reset.c
index eeaddf88392..5f51c1b96f1 100644
--- a/test/dm/syscon-reset.c
+++ b/test/dm/syscon-reset.c
@@ -3,7 +3,6 @@
* Copyright (C) 2020 Sean Anderson <seanga2@gmail.com>
*/
-#include <common.h>
#include <dm.h>
#include <dm/test.h>
#include <regmap.h>
@@ -56,4 +55,4 @@ static int dm_test_syscon_reset(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_syscon_reset, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_syscon_reset, UTF_SCAN_FDT);
diff --git a/test/dm/syscon.c b/test/dm/syscon.c
index be232972336..9855859721b 100644
--- a/test/dm/syscon.c
+++ b/test/dm/syscon.c
@@ -3,7 +3,6 @@
* Copyright (C) 2015 Google, Inc
*/
-#include <common.h>
#include <dm.h>
#include <log.h>
#include <syscon.h>
@@ -29,7 +28,7 @@ static int dm_test_syscon_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_syscon_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_syscon_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test system controller finding */
static int dm_test_syscon_by_driver_data(struct unit_test_state *uts)
@@ -46,7 +45,7 @@ static int dm_test_syscon_by_driver_data(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_syscon_by_driver_data, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_syscon_by_driver_data, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test system controller by phandle */
static int dm_test_syscon_by_phandle(struct unit_test_state *uts)
@@ -81,4 +80,4 @@ static int dm_test_syscon_by_phandle(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_syscon_by_phandle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_syscon_by_phandle, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/sysinfo-gpio.c b/test/dm/sysinfo-gpio.c
index 2e494b3f341..de9483c4291 100644
--- a/test/dm/sysinfo-gpio.c
+++ b/test/dm/sysinfo-gpio.c
@@ -3,7 +3,6 @@
* Copyright (C) 2021 Sean Anderson <sean.anderson@seco.com>
*/
-#include <common.h>
#include <dm.h>
#include <log.h>
#include <sysinfo.h>
@@ -30,9 +29,9 @@ static int dm_test_sysinfo_gpio(struct unit_test_state *uts)
sandbox_gpio_set_flags(gpio, 16, GPIOD_EXT_PULL_DOWN);
sandbox_gpio_set_flags(gpio, 17, 0);
ut_assertok(sysinfo_detect(sysinfo));
- ut_assertok(sysinfo_get_int(sysinfo, SYSINFO_ID_BOARD_MODEL, &val));
+ ut_assertok(sysinfo_get_int(sysinfo, SYSID_BOARD_MODEL, &val));
ut_asserteq(19, val);
- ut_assertok(sysinfo_get_str(sysinfo, SYSINFO_ID_BOARD_MODEL, sizeof(buf),
+ ut_assertok(sysinfo_get_str(sysinfo, SYSID_BOARD_MODEL, sizeof(buf),
buf));
ut_asserteq_str("rev_a", buf);
@@ -44,9 +43,9 @@ static int dm_test_sysinfo_gpio(struct unit_test_state *uts)
sandbox_gpio_set_flags(gpio, 16, GPIOD_EXT_PULL_UP);
sandbox_gpio_set_flags(gpio, 17, GPIOD_EXT_PULL_DOWN);
ut_assertok(sysinfo_detect(sysinfo));
- ut_assertok(sysinfo_get_int(sysinfo, SYSINFO_ID_BOARD_MODEL, &val));
+ ut_assertok(sysinfo_get_int(sysinfo, SYSID_BOARD_MODEL, &val));
ut_asserteq(5, val);
- ut_assertok(sysinfo_get_str(sysinfo, SYSINFO_ID_BOARD_MODEL, sizeof(buf),
+ ut_assertok(sysinfo_get_str(sysinfo, SYSID_BOARD_MODEL, sizeof(buf),
buf));
ut_asserteq_str("foo", buf);
@@ -58,12 +57,12 @@ static int dm_test_sysinfo_gpio(struct unit_test_state *uts)
sandbox_gpio_set_flags(gpio, 16, 0);
sandbox_gpio_set_flags(gpio, 17, GPIOD_EXT_PULL_UP);
ut_assertok(sysinfo_detect(sysinfo));
- ut_assertok(sysinfo_get_int(sysinfo, SYSINFO_ID_BOARD_MODEL, &val));
+ ut_assertok(sysinfo_get_int(sysinfo, SYSID_BOARD_MODEL, &val));
ut_asserteq(15, val);
- ut_assertok(sysinfo_get_str(sysinfo, SYSINFO_ID_BOARD_MODEL, sizeof(buf),
+ ut_assertok(sysinfo_get_str(sysinfo, SYSID_BOARD_MODEL, sizeof(buf),
buf));
ut_asserteq_str("unknown", buf);
return 0;
}
-DM_TEST(dm_test_sysinfo_gpio, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_sysinfo_gpio, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/sysinfo.c b/test/dm/sysinfo.c
index 96b3a8ebaba..14ebe6b42e7 100644
--- a/test/dm/sysinfo.c
+++ b/test/dm/sysinfo.c
@@ -4,7 +4,6 @@
* Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
*/
-#include <common.h>
#include <dm.h>
#include <log.h>
#include <dm/test.h>
@@ -20,6 +19,9 @@ static int dm_test_sysinfo(struct unit_test_state *uts)
bool called_detect = false;
char str[64];
int i;
+ void *data = NULL;
+ size_t data_size = 0;
+ u32 gdata[] = {0xabcdabcd, 0xdeadbeef};
ut_assertok(sysinfo_get(&sysinfo));
ut_assert(sysinfo);
@@ -58,7 +60,9 @@ static int dm_test_sysinfo(struct unit_test_state *uts)
str));
ut_assertok(strcmp(str, "Yuggoth"));
+ ut_assertok(sysinfo_get_data(sysinfo, DATA_TEST, &data, &data_size));
+ ut_assertok(memcmp(gdata, data, data_size));
+
return 0;
}
-
-DM_TEST(dm_test_sysinfo, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_sysinfo, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/sysreset.c b/test/dm/sysreset.c
index 5aa69e04618..8431aaa0a9e 100644
--- a/test/dm/sysreset.c
+++ b/test/dm/sysreset.c
@@ -3,7 +3,6 @@
* Copyright (C) 2015 Google, Inc
*/
-#include <common.h>
#include <dm.h>
#include <sysreset.h>
#include <asm/state.h>
@@ -46,7 +45,7 @@ static int dm_test_sysreset_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_sysreset_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_sysreset_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_sysreset_get_status(struct unit_test_state *uts)
{
@@ -65,7 +64,7 @@ static int dm_test_sysreset_get_status(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_sysreset_get_status, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_sysreset_get_status, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that we can walk through the sysreset devices */
static int dm_test_sysreset_walk(struct unit_test_state *uts)
@@ -96,7 +95,7 @@ static int dm_test_sysreset_walk(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_sysreset_walk, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_sysreset_walk, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_sysreset_get_last(struct unit_test_state *uts)
{
@@ -115,4 +114,4 @@ static int dm_test_sysreset_get_last(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_sysreset_get_last, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_sysreset_get_last, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/tag.c b/test/dm/tag.c
index 8ae8a1fcd65..1412171738c 100644
--- a/test/dm/tag.c
+++ b/test/dm/tag.c
@@ -6,7 +6,6 @@
* Author: AKASHI Takahiro
*/
-#include <common.h>
#include <dm/tag.h>
#include <dm/test.h> /* DM_TEST() */
#include <test/test.h> /* struct unit_test_state */
@@ -30,7 +29,6 @@ static int dm_test_tag_ptr(struct unit_test_state *uts)
return 0;
}
-
DM_TEST(dm_test_tag_ptr, 0);
/*
@@ -50,7 +48,6 @@ static int dm_test_tag_val(struct unit_test_state *uts)
return 0;
}
-
DM_TEST(dm_test_tag_val, 0);
/*
@@ -64,7 +61,6 @@ static int dm_test_tag_inval(struct unit_test_state *uts)
return 0;
}
-
DM_TEST(dm_test_tag_inval, 0);
/*
@@ -80,5 +76,4 @@ static int dm_test_tag_del_all(struct unit_test_state *uts)
return 0;
}
-
DM_TEST(dm_test_tag_del_all, 0);
diff --git a/test/dm/tee.c b/test/dm/tee.c
index 7a11bf89138..b56c982eb75 100644
--- a/test/dm/tee.c
+++ b/test/dm/tee.c
@@ -3,7 +3,6 @@
* Copyright (C) 2018 Linaro Limited
*/
-#include <common.h>
#include <dm.h>
#include <log.h>
#include <malloc.h>
@@ -216,5 +215,4 @@ out:
return rc;
}
-
-DM_TEST(dm_test_tee, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_tee, UTF_SCAN_FDT);
diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
deleted file mode 100644
index e73a1dd8f81..00000000000
--- a/test/dm/test-dm.c
+++ /dev/null
@@ -1,17 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright (c) 2013 Google, Inc
- */
-
-#include <common.h>
-#include <test/suites.h>
-#include <test/test.h>
-
-int do_ut_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(dm_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(dm_test);
-
- return cmd_ut_category("driver model", "dm_test_", tests, n_ents, argc,
- argv);
-}
diff --git a/test/dm/test-driver.c b/test/dm/test-driver.c
index 02cb974b0f7..759de3a5f77 100644
--- a/test/dm/test-driver.c
+++ b/test/dm/test-driver.c
@@ -6,7 +6,6 @@
* Pavel Herrmann <morpheus.ibis@gmail.com>
*/
-#include <common.h>
#include <dm.h>
#include <errno.h>
#include <log.h>
@@ -36,7 +35,7 @@ static const struct test_ops test_ops = {
static int test_bind(struct udevice *dev)
{
- struct unit_test_state *uts = test_get_state();
+ struct unit_test_state *uts = ut_get_state();
/* Private data should not be allocated */
ut_assert(!dev_get_priv(dev));
@@ -47,7 +46,7 @@ static int test_bind(struct udevice *dev)
static int test_probe(struct udevice *dev)
{
- struct unit_test_state *uts = test_get_state();
+ struct unit_test_state *uts = ut_get_state();
struct dm_test_priv *priv = dev_get_priv(dev);
/* Private data should be allocated */
@@ -60,7 +59,7 @@ static int test_probe(struct udevice *dev)
static int test_remove(struct udevice *dev)
{
- struct unit_test_state *uts = test_get_state();
+ struct unit_test_state *uts = ut_get_state();
/* Private data should still be allocated */
ut_assert(dev_get_priv(dev));
@@ -71,7 +70,7 @@ static int test_remove(struct udevice *dev)
static int test_unbind(struct udevice *dev)
{
- struct unit_test_state *uts = test_get_state();
+ struct unit_test_state *uts = ut_get_state();
/* Private data should not be allocated */
ut_assert(!dev_get_priv(dev));
@@ -122,7 +121,7 @@ static int test_manual_bind(struct udevice *dev)
static int test_manual_probe(struct udevice *dev)
{
- struct unit_test_state *uts = test_get_state();
+ struct unit_test_state *uts = ut_get_state();
dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
if (!uts->force_fail_alloc)
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index 72d0eb57e21..295fdcaa0d8 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -3,7 +3,6 @@
* Copyright (c) 2013 Google, Inc
*/
-#include <common.h>
#include <dm.h>
#include <errno.h>
#include <fdtdec.h>
@@ -20,6 +19,7 @@
#include <dm/util.h>
#include <dm/of_access.h>
#include <linux/ioport.h>
+#include <linux/list.h>
#include <test/test.h>
#include <test/ut.h>
@@ -163,7 +163,7 @@ static int dm_test_fdt(struct unit_test_state *uts)
ut_assert(!ret);
/* These are num_devices compatible root-level device tree nodes */
- ut_asserteq(num_devices, list_count_items(&uc->dev_head));
+ ut_asserteq(num_devices, list_count_nodes(&uc->dev_head));
/* Each should have platform data but no private data */
for (i = 0; i < num_devices; i++) {
@@ -218,7 +218,7 @@ static int dm_test_fdt_pre_reloc(struct unit_test_state *uts)
* one with "bootph-all" property (a-test node), and the other
* one whose driver marked with DM_FLAG_PRE_RELOC flag (h-test node).
*/
- ut_asserteq(2, list_count_items(&uc->dev_head));
+ ut_asserteq(2, list_count_nodes(&uc->dev_head));
return 0;
}
@@ -296,7 +296,7 @@ static int dm_test_fdt_uclass_seq(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_fdt_uclass_seq, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_fdt_uclass_seq, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* More tests for sequence numbers */
static int dm_test_fdt_uclass_seq_manual(struct unit_test_state *uts)
@@ -321,7 +321,7 @@ static int dm_test_fdt_uclass_seq_manual(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_fdt_uclass_seq_manual, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_fdt_uclass_seq_manual, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts)
{
@@ -360,7 +360,7 @@ static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_fdt_uclass_seq_more, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_fdt_uclass_seq_more, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that we can find a device by device tree offset */
static int dm_test_fdt_offset(struct unit_test_state *uts)
@@ -390,7 +390,7 @@ static int dm_test_fdt_offset(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_fdt_offset,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_FLAT_TREE);
/**
* Test various error conditions with uclass_first_device(),
@@ -455,7 +455,7 @@ static int dm_test_first_next_device_probeall(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_first_next_device_probeall,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test iteration through devices in a uclass */
static int dm_test_uclass_foreach(struct unit_test_state *uts)
@@ -476,7 +476,7 @@ static int dm_test_uclass_foreach(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_uclass_foreach, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_uclass_foreach, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/**
* check_devices() - Check return values and pointers
@@ -556,7 +556,7 @@ static int dm_test_first_next_ok_device(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_first_next_ok_device, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_first_next_ok_device, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static const struct udevice_id fdt_dummy_ids[] = {
{ .compatible = "denx,u-boot-fdt-dummy", },
@@ -611,7 +611,7 @@ static int dm_test_fdt_translation(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_fdt_translation, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_fdt_translation, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_fdt_get_addr_ptr_flat(struct unit_test_state *uts)
{
@@ -632,7 +632,7 @@ static int dm_test_fdt_get_addr_ptr_flat(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_fdt_get_addr_ptr_flat,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_FLAT_TREE);
static int dm_test_fdt_remap_addr_flat(struct unit_test_state *uts)
{
@@ -652,7 +652,7 @@ static int dm_test_fdt_remap_addr_flat(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_fdt_remap_addr_flat,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_FLAT_TREE);
static int dm_test_fdt_remap_addr_index_flat(struct unit_test_state *uts)
{
@@ -674,7 +674,7 @@ static int dm_test_fdt_remap_addr_index_flat(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_fdt_remap_addr_index_flat,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_FLAT_TREE);
static int dm_test_fdt_remap_addr_name_flat(struct unit_test_state *uts)
{
@@ -696,7 +696,7 @@ static int dm_test_fdt_remap_addr_name_flat(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_fdt_remap_addr_name_flat,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_FLAT_TREE);
static int dm_test_fdt_remap_addr_live(struct unit_test_state *uts)
{
@@ -716,7 +716,7 @@ static int dm_test_fdt_remap_addr_live(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_fdt_remap_addr_live,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_fdt_remap_addr_index_live(struct unit_test_state *uts)
{
@@ -738,7 +738,7 @@ static int dm_test_fdt_remap_addr_index_live(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_fdt_remap_addr_index_live,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_fdt_remap_addr_name_live(struct unit_test_state *uts)
{
@@ -760,7 +760,7 @@ static int dm_test_fdt_remap_addr_name_live(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_fdt_remap_addr_name_live,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_fdt_disable_enable_by_path(struct unit_test_state *uts)
{
@@ -787,13 +787,12 @@ static int dm_test_fdt_disable_enable_by_path(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_fdt_disable_enable_by_path, UT_TESTF_SCAN_PDATA |
- UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_fdt_disable_enable_by_path, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test a few uclass phandle functions */
static int dm_test_fdt_phandle(struct unit_test_state *uts)
{
- struct udevice *back, *dev, *dev2;
+ struct udevice *back, *dispc, *panel, *dev, *dev2;
ut_assertok(uclass_find_first_device(UCLASS_PANEL_BACKLIGHT, &back));
ut_assertnonnull(back);
@@ -808,9 +807,27 @@ static int dm_test_fdt_phandle(struct unit_test_state *uts)
"power-supply", &dev2));
ut_asserteq_ptr(dev, dev2);
+ /* Test uclass_get_device_by_endpoint() */
+ ut_assertok(uclass_find_device_by_name(UCLASS_VIDEO_BRIDGE, "lvds-encoder", &dispc));
+ ut_assertnonnull(dispc);
+ ut_asserteq(0, device_active(dispc));
+ ut_assertok(uclass_find_device_by_name(UCLASS_PANEL, "panel", &panel));
+ ut_assertnonnull(panel);
+ ut_asserteq(0, device_active(panel));
+
+ ut_asserteq(-ENODEV, uclass_get_device_by_endpoint(UCLASS_PANEL_BACKLIGHT, dispc, 1, -1, &dev));
+ ut_asserteq(-EINVAL, uclass_get_device_by_endpoint(UCLASS_PANEL, dispc, 0, -1, &dev));
+ ut_assertok(uclass_get_device_by_endpoint(UCLASS_PANEL, dispc, 1, -1, &dev));
+ ut_asserteq_ptr(panel, dev);
+
+ ut_asserteq(-ENODEV, uclass_get_device_by_endpoint(UCLASS_PANEL_BACKLIGHT, panel, -1, -1, &dev2));
+ ut_asserteq(-EINVAL, uclass_get_device_by_endpoint(UCLASS_VIDEO_BRIDGE, panel, 1, -1, &dev2));
+ ut_assertok(uclass_get_device_by_endpoint(UCLASS_VIDEO_BRIDGE, panel, -1, -1, &dev2));
+ ut_asserteq_ptr(dispc, dev2);
+
return 0;
}
-DM_TEST(dm_test_fdt_phandle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_fdt_phandle, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test device_find_first_child_by_uclass() */
static int dm_test_first_child(struct unit_test_state *uts)
@@ -837,7 +854,7 @@ static int dm_test_first_child(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_first_child, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_first_child, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test integer functions in dm_read_...() */
static int dm_test_read_int(struct unit_test_state *uts)
@@ -901,7 +918,7 @@ static int dm_test_read_int(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_read_int, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_read_int, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_read_int_index(struct unit_test_state *uts)
{
@@ -930,7 +947,7 @@ static int dm_test_read_int_index(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_read_int_index, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_read_int_index, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_read_phandle(struct unit_test_state *uts)
{
@@ -995,7 +1012,7 @@ static int dm_test_read_phandle(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_read_phandle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_read_phandle, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test iteration through devices by drvdata */
static int dm_test_uclass_drvdata(struct unit_test_state *uts)
@@ -1016,7 +1033,7 @@ static int dm_test_uclass_drvdata(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_uclass_drvdata, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_uclass_drvdata, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test device_first_child_ofdata_err(), etc. */
static int dm_test_child_ofdata(struct unit_test_state *uts)
@@ -1035,7 +1052,7 @@ static int dm_test_child_ofdata(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_child_ofdata, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_child_ofdata, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test device_first_child_err(), etc. */
static int dm_test_first_child_probe(struct unit_test_state *uts)
@@ -1054,7 +1071,7 @@ static int dm_test_first_child_probe(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_first_child_probe, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_first_child_probe, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that ofdata is read for parents before children */
static int dm_test_ofdata_order(struct unit_test_state *uts)
@@ -1079,7 +1096,7 @@ static int dm_test_ofdata_order(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_ofdata_order, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofdata_order, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test dev_decode_display_timing() */
static int dm_test_decode_display_timing(struct unit_test_state *uts)
@@ -1159,7 +1176,7 @@ static int dm_test_decode_display_timing(struct unit_test_state *uts)
ut_assert(dev_decode_display_timing(dev, 3, &timing));
return 0;
}
-DM_TEST(dm_test_decode_display_timing, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_decode_display_timing, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test dev_decode_panel_timing() */
static int dm_test_decode_panel_timing(struct unit_test_state *uts)
@@ -1194,7 +1211,7 @@ static int dm_test_decode_panel_timing(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_decode_panel_timing, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_decode_panel_timing, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test read_resourcee() */
static int dm_test_read_resource(struct unit_test_state *uts)
@@ -1225,5 +1242,4 @@ static int dm_test_read_resource(struct unit_test_state *uts)
return 0;
}
-
-DM_TEST(dm_test_read_resource, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_read_resource, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c
index 067701734a0..be4108bbecb 100644
--- a/test/dm/test-uclass.c
+++ b/test/dm/test-uclass.c
@@ -6,7 +6,6 @@
* Pavel Herrmann <morpheus.ibis@gmail.com>
*/
-#include <common.h>
#include <log.h>
#include <malloc.h>
#include <dm.h>
@@ -29,7 +28,7 @@ int test_ping(struct udevice *dev, int pingval, int *pingret)
static int test_post_bind(struct udevice *dev)
{
- struct unit_test_state *uts = test_get_state();
+ struct unit_test_state *uts = ut_get_state();
struct dm_test_perdev_uc_pdata *uc_pdata;
dm_testdrv_op_count[DM_TEST_OP_POST_BIND]++;
@@ -55,7 +54,7 @@ static int test_pre_unbind(struct udevice *dev)
static int test_pre_probe(struct udevice *dev)
{
struct dm_test_uclass_perdev_priv *priv = dev_get_uclass_priv(dev);
- struct unit_test_state *uts = test_get_state();
+ struct unit_test_state *uts = ut_get_state();
dm_testdrv_op_count[DM_TEST_OP_PRE_PROBE]++;
ut_assert(priv);
@@ -66,7 +65,7 @@ static int test_pre_probe(struct udevice *dev)
static int test_post_probe(struct udevice *dev)
{
- struct unit_test_state *uts = test_get_state();
+ struct unit_test_state *uts = ut_get_state();
struct udevice *prev = list_entry(dev->uclass_node.prev,
struct udevice, uclass_node);
@@ -101,7 +100,7 @@ static int test_pre_remove(struct udevice *dev)
static int test_init(struct uclass *uc)
{
- struct unit_test_state *uts = test_get_state();
+ struct unit_test_state *uts = ut_get_state();
dm_testdrv_op_count[DM_TEST_OP_INIT]++;
ut_assert(uclass_get_priv(uc));
diff --git a/test/dm/timer.c b/test/dm/timer.c
index 9f94d476920..a32059d560d 100644
--- a/test/dm/timer.c
+++ b/test/dm/timer.c
@@ -3,7 +3,6 @@
* Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
*/
-#include <common.h>
#include <dm.h>
#include <timer.h>
#include <dm/test.h>
@@ -24,7 +23,7 @@ static int dm_test_timer_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_timer_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_timer_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/*
* Test of timebase fallback
@@ -47,4 +46,4 @@ static int dm_test_timer_timebase_fallback(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_timer_timebase_fallback,
- UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+ UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/tpm.c b/test/dm/tpm.c
index cde933ab284..962a3fd1943 100644
--- a/test/dm/tpm.c
+++ b/test/dm/tpm.c
@@ -4,7 +4,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <dm.h>
#include <tpm_api.h>
#include <dm/test.h>
@@ -57,7 +56,7 @@ static int dm_test_tpm(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_tpm, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_tpm, UTF_SCAN_FDT);
/* Test report_state */
static int dm_test_tpm_report_state(struct unit_test_state *uts)
@@ -78,7 +77,7 @@ static int dm_test_tpm_report_state(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_tpm_report_state, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_tpm_report_state, UTF_SCAN_FDT);
/**
* test_tpm_autostart() - check the tpm_auto_start() call
@@ -115,7 +114,7 @@ static int dm_test_tpm_autostart(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_tpm_autostart, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_tpm_autostart, UTF_SCAN_FDT);
static int dm_test_tpm_autostart_reinit(struct unit_test_state *uts)
{
@@ -124,4 +123,4 @@ static int dm_test_tpm_autostart_reinit(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_tpm_autostart_reinit, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_tpm_autostart_reinit, UTF_SCAN_FDT);
diff --git a/test/dm/usb.c b/test/dm/usb.c
index 7671ef156d8..fa894c1096e 100644
--- a/test/dm/usb.c
+++ b/test/dm/usb.c
@@ -3,7 +3,6 @@
* Copyright (C) 2015 Google, Inc
*/
-#include <common.h>
#include <console.h>
#include <dm.h>
#include <part.h>
@@ -34,7 +33,7 @@ static int dm_test_usb_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_usb_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_usb_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/*
* Test that we can use the flash stick. This is more of a functional test. It
@@ -83,7 +82,7 @@ static int dm_test_usb_flash(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_usb_flash, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_usb_flash, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* test that we can handle multiple storage devices */
static int dm_test_usb_multi(struct unit_test_state *uts)
@@ -99,7 +98,7 @@ static int dm_test_usb_multi(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_usb_multi, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_usb_multi, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* test that we have an associated ofnode with the usb device */
static int dm_test_usb_fdt_node(struct unit_test_state *uts)
@@ -121,7 +120,7 @@ static int dm_test_usb_fdt_node(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_usb_fdt_node, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_usb_fdt_node, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int count_usb_devices(void)
{
@@ -165,7 +164,7 @@ static int dm_test_usb_stop(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_usb_stop, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_usb_stop, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/**
* dm_test_usb_keyb() - test USB keyboard driver
@@ -424,7 +423,6 @@ static int dm_test_usb_keyb(struct unit_test_state *uts)
{0x00, 0x00, "\0"}
};
-
state_set_skip_delays(true);
ut_assertok(usb_init());
@@ -457,4 +455,4 @@ static int dm_test_usb_keyb(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_usb_keyb, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_usb_keyb, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/video.c b/test/dm/video.c
index d907f681600..ecf74605b5c 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -4,7 +4,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <bzlib.h>
#include <dm.h>
#include <gzip.h>
@@ -18,8 +17,10 @@
#include <asm/sdl.h>
#include <dm/test.h>
#include <dm/uclass-internal.h>
+#include <test/lib.h>
#include <test/test.h>
#include <test/ut.h>
+#include <test/video.h>
/*
* These tests use the standard sandbox frame buffer, the resolution of which
@@ -43,55 +44,48 @@ static int dm_test_video_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_video_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
-/**
- * compress_frame_buffer() - Compress the frame buffer and return its size
- *
- * We want to write tests which perform operations on the video console and
- * check that the frame buffer ends up with the correct contents. But it is
- * painful to store 'known good' images for comparison with the frame
- * buffer. As an alternative, we can compress the frame buffer and check the
- * size of the compressed data. This provides a pretty good level of
- * certainty and the resulting tests need only check a single value.
- *
- * If the copy framebuffer is enabled, this compares it to the main framebuffer
- * too.
- *
- * @uts: Test state
- * @dev: Video device
- * Return: compressed size of the frame buffer, or -ve on error
- */
-static int compress_frame_buffer(struct unit_test_state *uts,
- struct udevice *dev)
+int video_compress_fb(struct unit_test_state *uts, struct udevice *dev,
+ bool use_copy)
{
struct video_priv *priv = dev_get_uclass_priv(dev);
- struct video_priv *uc_priv = dev_get_uclass_priv(dev);
uint destlen;
void *dest;
int ret;
+ if (!IS_ENABLED(CONFIG_VIDEO_COPY))
+ use_copy = false;
+
destlen = priv->fb_size;
dest = malloc(priv->fb_size);
if (!dest)
return -ENOMEM;
ret = BZ2_bzBuffToBuffCompress(dest, &destlen,
- priv->fb, priv->fb_size,
+ use_copy ? priv->copy_fb : priv->fb,
+ priv->fb_size,
3, 0, 0);
free(dest);
if (ret)
return ret;
- /* Check here that the copy frame buffer is working correctly */
- if (IS_ENABLED(CONFIG_VIDEO_COPY)) {
- ut_assertf(!memcmp(uc_priv->fb, uc_priv->copy_fb,
- uc_priv->fb_size),
- "Copy framebuffer does not match fb");
- }
-
return destlen;
}
+int video_check_copy_fb(struct unit_test_state *uts, struct udevice *dev)
+{
+ struct video_priv *priv = dev_get_uclass_priv(dev);
+
+ if (!IS_ENABLED(CONFIG_VIDEO_COPY))
+ return 0;
+
+ video_sync(dev, false);
+ ut_assertf(!memcmp(priv->fb, priv->copy_fb, priv->fb_size),
+ "Copy framebuffer does not match fb");
+
+ return 0;
+}
+
/*
* Call this function at any point to halt and show the current display. Be
* sure to run the test with the -l flag.
@@ -154,29 +148,35 @@ static int dm_test_video_text(struct unit_test_state *uts)
ut_assertok(video_get_nologo(uts, &dev));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
ut_assertok(vidconsole_select_font(con, "8x16", 0));
- ut_asserteq(46, compress_frame_buffer(uts, dev));
+ ut_asserteq(46, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
vidconsole_putc_xy(con, 0, 0, 'a');
- ut_asserteq(79, compress_frame_buffer(uts, dev));
+ ut_asserteq(79, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
vidconsole_putc_xy(con, 0, 0, ' ');
- ut_asserteq(46, compress_frame_buffer(uts, dev));
+ ut_asserteq(46, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
for (i = 0; i < 20; i++)
vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
- ut_asserteq(273, compress_frame_buffer(uts, dev));
+ ut_asserteq(273, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
vidconsole_set_row(con, 0, WHITE);
- ut_asserteq(46, compress_frame_buffer(uts, dev));
+ ut_asserteq(46, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
for (i = 0; i < 20; i++)
vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
- ut_asserteq(273, compress_frame_buffer(uts, dev));
+ ut_asserteq(273, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
return 0;
}
-DM_TEST(dm_test_video_text, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_text, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_video_text_12x22(struct unit_test_state *uts)
{
@@ -190,29 +190,35 @@ static int dm_test_video_text_12x22(struct unit_test_state *uts)
ut_assertok(video_get_nologo(uts, &dev));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
ut_assertok(vidconsole_select_font(con, "12x22", 0));
- ut_asserteq(46, compress_frame_buffer(uts, dev));
+ ut_asserteq(46, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
vidconsole_putc_xy(con, 0, 0, 'a');
- ut_asserteq(89, compress_frame_buffer(uts, dev));
+ ut_asserteq(89, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
vidconsole_putc_xy(con, 0, 0, ' ');
- ut_asserteq(46, compress_frame_buffer(uts, dev));
+ ut_asserteq(46, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
for (i = 0; i < 20; i++)
vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
- ut_asserteq(363, compress_frame_buffer(uts, dev));
+ ut_asserteq(363, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
vidconsole_set_row(con, 0, WHITE);
- ut_asserteq(46, compress_frame_buffer(uts, dev));
+ ut_asserteq(46, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
for (i = 0; i < 20; i++)
vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
- ut_asserteq(363, compress_frame_buffer(uts, dev));
+ ut_asserteq(363, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
return 0;
}
-DM_TEST(dm_test_video_text_12x22, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_text_12x22, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test handling of special characters in the console */
static int dm_test_video_chars(struct unit_test_state *uts)
@@ -225,11 +231,12 @@ static int dm_test_video_chars(struct unit_test_state *uts)
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
ut_assertok(vidconsole_select_font(con, "8x16", 0));
vidconsole_put_string(con, test_string);
- ut_asserteq(466, compress_frame_buffer(uts, dev));
+ ut_asserteq(466, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
return 0;
}
-DM_TEST(dm_test_video_chars, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_chars, UTF_SCAN_PDATA | UTF_SCAN_FDT);
#ifdef CONFIG_VIDEO_ANSI
#define ANSI_ESC "\x1b"
@@ -246,24 +253,28 @@ static int dm_test_video_ansi(struct unit_test_state *uts)
/* reference clear: */
video_clear(con->parent);
video_sync(con->parent, false);
- ut_asserteq(46, compress_frame_buffer(uts, dev));
+ ut_asserteq(46, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
/* test clear escape sequence: [2J */
vidconsole_put_string(con, "A\tB\tC"ANSI_ESC"[2J");
- ut_asserteq(46, compress_frame_buffer(uts, dev));
+ ut_asserteq(46, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
/* test set-cursor: [%d;%df */
vidconsole_put_string(con, "abc"ANSI_ESC"[2;2fab"ANSI_ESC"[4;4fcd");
- ut_asserteq(143, compress_frame_buffer(uts, dev));
+ ut_asserteq(143, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
/* test colors (30-37 fg color, 40-47 bg color) */
vidconsole_put_string(con, ANSI_ESC"[30;41mfoo"); /* black on red */
vidconsole_put_string(con, ANSI_ESC"[33;44mbar"); /* yellow on blue */
- ut_asserteq(272, compress_frame_buffer(uts, dev));
+ ut_asserteq(272, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
return 0;
}
-DM_TEST(dm_test_video_ansi, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_ansi, UTF_SCAN_PDATA | UTF_SCAN_FDT);
#endif
/**
@@ -291,24 +302,28 @@ static int check_vidconsole_output(struct unit_test_state *uts, int rot,
ut_assertok(video_get_nologo(uts, &dev));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
ut_assertok(vidconsole_select_font(con, "8x16", 0));
- ut_asserteq(46, compress_frame_buffer(uts, dev));
+ ut_asserteq(46, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
/* Check display wrap */
for (i = 0; i < 120; i++)
vidconsole_put_char(con, 'A' + i % 50);
- ut_asserteq(wrap_size, compress_frame_buffer(uts, dev));
+ ut_asserteq(wrap_size, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
/* Check display scrolling */
for (i = 0; i < SCROLL_LINES; i++) {
vidconsole_put_char(con, 'A' + i % 50);
vidconsole_put_char(con, '\n');
}
- ut_asserteq(scroll_size, compress_frame_buffer(uts, dev));
+ ut_asserteq(scroll_size, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
/* If we scroll enough, the screen becomes blank again */
for (i = 0; i < SCROLL_LINES; i++)
vidconsole_put_char(con, '\n');
- ut_asserteq(46, compress_frame_buffer(uts, dev));
+ ut_asserteq(46, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
return 0;
}
@@ -321,7 +336,7 @@ static int dm_test_video_context(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_video_context, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_context, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test rotated text output through the console uclass */
static int dm_test_video_rotation1(struct unit_test_state *uts)
@@ -330,7 +345,7 @@ static int dm_test_video_rotation1(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_video_rotation1, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_rotation1, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test rotated text output through the console uclass */
static int dm_test_video_rotation2(struct unit_test_state *uts)
@@ -339,7 +354,7 @@ static int dm_test_video_rotation2(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_video_rotation2, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_rotation2, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test rotated text output through the console uclass */
static int dm_test_video_rotation3(struct unit_test_state *uts)
@@ -348,7 +363,7 @@ static int dm_test_video_rotation3(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_video_rotation3, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_rotation3, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Read a file into memory and return a pointer to it */
static int read_file(struct unit_test_state *uts, const char *fname,
@@ -382,11 +397,12 @@ static int dm_test_video_bmp(struct unit_test_state *uts)
ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
- ut_asserteq(1368, compress_frame_buffer(uts, dev));
+ ut_asserteq(1368, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
return 0;
}
-DM_TEST(dm_test_video_bmp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_bmp, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test drawing a bitmap file on a 8bpp display */
static int dm_test_video_bmp8(struct unit_test_state *uts)
@@ -401,11 +417,12 @@ static int dm_test_video_bmp8(struct unit_test_state *uts)
ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
- ut_asserteq(1247, compress_frame_buffer(uts, dev));
+ ut_asserteq(1247, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
return 0;
}
-DM_TEST(dm_test_video_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_bmp8, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test drawing a bitmap file on a 16bpp display */
static int dm_test_video_bmp16(struct unit_test_state *uts)
@@ -424,11 +441,12 @@ static int dm_test_video_bmp16(struct unit_test_state *uts)
&src_len));
ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
- ut_asserteq(3700, compress_frame_buffer(uts, dev));
+ ut_asserteq(3700, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
return 0;
}
-DM_TEST(dm_test_video_bmp16, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_bmp16, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test drawing a 24bpp bitmap file on a 16bpp display */
static int dm_test_video_bmp24(struct unit_test_state *uts)
@@ -447,11 +465,12 @@ static int dm_test_video_bmp24(struct unit_test_state *uts)
&src_len));
ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
- ut_asserteq(3656, compress_frame_buffer(uts, dev));
+ ut_asserteq(3656, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
return 0;
}
-DM_TEST(dm_test_video_bmp24, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_bmp24, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test drawing a 24bpp bitmap file on a 32bpp display */
static int dm_test_video_bmp24_32(struct unit_test_state *uts)
@@ -470,11 +489,12 @@ static int dm_test_video_bmp24_32(struct unit_test_state *uts)
&src_len));
ut_assertok(video_bmp_display(dev, dst, 0, 0, false));
- ut_asserteq(6827, compress_frame_buffer(uts, dev));
+ ut_asserteq(6827, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
return 0;
}
-DM_TEST(dm_test_video_bmp24_32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_bmp24_32, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test drawing a bitmap file on a 32bpp display */
static int dm_test_video_bmp32(struct unit_test_state *uts)
@@ -488,11 +508,12 @@ static int dm_test_video_bmp32(struct unit_test_state *uts)
ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
- ut_asserteq(2024, compress_frame_buffer(uts, dev));
+ ut_asserteq(2024, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
return 0;
}
-DM_TEST(dm_test_video_bmp32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_bmp32, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test drawing a compressed bitmap file */
static int dm_test_video_bmp_comp(struct unit_test_state *uts)
@@ -504,11 +525,12 @@ static int dm_test_video_bmp_comp(struct unit_test_state *uts)
ut_assertok(read_file(uts, "tools/logos/denx-comp.bmp", &addr));
ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
- ut_asserteq(1368, compress_frame_buffer(uts, dev));
+ ut_asserteq(1368, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
return 0;
}
-DM_TEST(dm_test_video_bmp_comp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_bmp_comp, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test drawing a bitmap file on a 32bpp display */
static int dm_test_video_comp_bmp32(struct unit_test_state *uts)
@@ -523,11 +545,12 @@ static int dm_test_video_comp_bmp32(struct unit_test_state *uts)
ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
- ut_asserteq(2024, compress_frame_buffer(uts, dev));
+ ut_asserteq(2024, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
return 0;
}
-DM_TEST(dm_test_video_comp_bmp32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_comp_bmp32, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test drawing a bitmap file on a 8bpp display */
static int dm_test_video_comp_bmp8(struct unit_test_state *uts)
@@ -542,11 +565,12 @@ static int dm_test_video_comp_bmp8(struct unit_test_state *uts)
ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
- ut_asserteq(1247, compress_frame_buffer(uts, dev));
+ ut_asserteq(1247, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
return 0;
}
-DM_TEST(dm_test_video_comp_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_comp_bmp8, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test TrueType console */
static int dm_test_video_truetype(struct unit_test_state *uts)
@@ -557,11 +581,13 @@ static int dm_test_video_truetype(struct unit_test_state *uts)
ut_assertok(video_get_nologo(uts, &dev));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
vidconsole_put_string(con, test_string);
- ut_asserteq(12174, compress_frame_buffer(uts, dev));
+ vidconsole_put_stringn(con, test_string, 30);
+ ut_asserteq(13184, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
return 0;
}
-DM_TEST(dm_test_video_truetype, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_truetype, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test scrolling TrueType console */
static int dm_test_video_truetype_scroll(struct unit_test_state *uts)
@@ -578,11 +604,12 @@ static int dm_test_video_truetype_scroll(struct unit_test_state *uts)
ut_assertok(video_get_nologo(uts, &dev));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
vidconsole_put_string(con, test_string);
- ut_asserteq(34287, compress_frame_buffer(uts, dev));
+ ut_asserteq(34287, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
return 0;
}
-DM_TEST(dm_test_video_truetype_scroll, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_truetype_scroll, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test TrueType backspace, within and across lines */
static int dm_test_video_truetype_bs(struct unit_test_state *uts)
@@ -599,8 +626,300 @@ static int dm_test_video_truetype_bs(struct unit_test_state *uts)
ut_assertok(video_get_nologo(uts, &dev));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
vidconsole_put_string(con, test_string);
- ut_asserteq(29471, compress_frame_buffer(uts, dev));
+ ut_asserteq(29471, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
+
+ return 0;
+}
+DM_TEST(dm_test_video_truetype_bs, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+
+/* Test partial rendering onto hardware frame buffer */
+static int dm_test_video_copy(struct unit_test_state *uts)
+{
+ struct sandbox_sdl_plat *plat;
+ struct video_uc_plat *uc_plat;
+ struct udevice *dev, *con;
+ struct video_priv *priv;
+ const char *test_string = "\n\tCriticism may not be agreeable, but it is necessary.\t";
+ ulong addr;
+
+ if (!IS_ENABLED(CONFIG_VIDEO_COPY))
+ return -EAGAIN;
+
+ ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
+ ut_assertnonnull(dev);
+ uc_plat = dev_get_uclass_plat(dev);
+ uc_plat->hide_logo = true;
+ plat = dev_get_plat(dev);
+ plat->font_size = 32;
+ ut_assert(!device_active(dev));
+ ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
+ ut_assertnonnull(dev);
+ priv = dev_get_uclass_priv(dev);
+
+ ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
+ ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
+
+ ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
+ vidconsole_put_string(con, "\n\n\n\n\n");
+ vidconsole_put_string(con, test_string);
+ vidconsole_put_string(con, test_string);
+
+ ut_asserteq(6678, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
+
+ /*
+ * Secretly clear the hardware frame buffer, but in a different
+ * color (black) to see which parts will be overwritten.
+ */
+ memset(priv->copy_fb, 0, priv->fb_size);
+
+ /*
+ * We should have the full content on the main buffer, but only
+ * 'damage' should have been copied to the copy buffer. This consists
+ * of a while rectangle with the Denx logo and four lines of text. The
+ * rest of the display is black.
+ *
+ * An easy way to try this is by changing video_sync() to call
+ * sandbox_sdl_sync(priv->copy_fb) instead of priv->fb then running the
+ * unit test:
+ *
+ * ./u-boot -Tl
+ * ut dm dm_test_video_copy
+ */
+ vidconsole_put_string(con, test_string);
+ vidconsole_put_string(con, test_string);
+ video_sync(dev, true);
+ ut_asserteq(7589, video_compress_fb(uts, dev, false));
+ ut_asserteq(7704, video_compress_fb(uts, dev, true));
+
+ return 0;
+}
+DM_TEST(dm_test_video_copy, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+
+/* Test video damage tracking */
+static int dm_test_video_damage(struct unit_test_state *uts)
+{
+ struct sandbox_sdl_plat *plat;
+ struct udevice *dev, *con;
+ struct video_priv *priv;
+ const char *test_string_1 = "Criticism may not be agreeable, ";
+ const char *test_string_2 = "but it is necessary.";
+ const char *test_string_3 = "It fulfils the same function as pain in the human body.";
+
+ if (!IS_ENABLED(CONFIG_VIDEO_DAMAGE))
+ return -EAGAIN;
+
+ ut_assertok(uclass_find_device(UCLASS_VIDEO, 0, &dev));
+ ut_assert(!device_active(dev));
+ plat = dev_get_plat(dev);
+ plat->font_size = 32;
+
+ ut_assertok(video_get_nologo(uts, &dev));
+ ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
+ priv = dev_get_uclass_priv(dev);
+
+ vidconsole_position_cursor(con, 14, 10);
+ vidconsole_put_string(con, test_string_2);
+ ut_asserteq(449, priv->damage.xstart);
+ ut_asserteq(325, priv->damage.ystart);
+ ut_asserteq(661, priv->damage.xend);
+ ut_asserteq(350, priv->damage.yend);
+
+ vidconsole_position_cursor(con, 7, 5);
+ vidconsole_put_string(con, test_string_1);
+ ut_asserteq(225, priv->damage.xstart);
+ ut_asserteq(164, priv->damage.ystart);
+ ut_asserteq(661, priv->damage.xend);
+ ut_asserteq(350, priv->damage.yend);
+
+ vidconsole_position_cursor(con, 21, 15);
+ vidconsole_put_string(con, test_string_3);
+ ut_asserteq(225, priv->damage.xstart);
+ ut_asserteq(164, priv->damage.ystart);
+ ut_asserteq(1280, priv->damage.xend);
+ ut_asserteq(510, priv->damage.yend);
+
+ video_sync(dev, true);
+ ut_asserteq(priv->xsize, priv->damage.xstart);
+ ut_asserteq(priv->ysize, priv->damage.ystart);
+ ut_asserteq(0, priv->damage.xend);
+ ut_asserteq(0, priv->damage.yend);
+
+ ut_asserteq(7339, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
+
+ return 0;
+}
+DM_TEST(dm_test_video_damage, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+
+/* Test font measurement */
+static int dm_test_font_measure(struct unit_test_state *uts)
+{
+ const char *test_string = "There is always much\nto be said for not "
+ "attempting more than you can do and for making a certainty of "
+ "what you try. But this principle, like others in life and "
+ "war, has its exceptions.";
+ const struct vidconsole_mline *line;
+ struct vidconsole_bbox bbox;
+ struct video_priv *priv;
+ struct udevice *dev, *con;
+ const int limit = 0x320;
+ struct alist lines;
+ int nl;
+
+ ut_assertok(uclass_get_device(UCLASS_VIDEO, 0, &dev));
+ priv = dev_get_uclass_priv(dev);
+ ut_asserteq(1366, priv->xsize);
+ ut_asserteq(768, priv->ysize);
+
+ /* this is using the Nimbus font with size of 18 pixels */
+ ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
+ vidconsole_position_cursor(con, 0, 0);
+ alist_init_struct(&lines, struct vidconsole_mline);
+ ut_assertok(vidconsole_measure(con, NULL, 0, test_string, -1, &bbox,
+ &lines));
+ ut_asserteq(0, bbox.x0);
+ ut_asserteq(0, bbox.y0);
+ ut_asserteq(0x3ea, bbox.x1);
+ ut_asserteq(0x24, bbox.y1);
+ ut_asserteq(2, lines.count);
+
+ nl = strchr(test_string, '\n') - test_string;
+
+ line = alist_get(&lines, 0, struct vidconsole_mline);
+ ut_assertnonnull(line);
+ ut_asserteq(0, line->bbox.x0);
+ ut_asserteq(0, line->bbox.y0);
+ ut_asserteq(0x8c, line->bbox.x1);
+ ut_asserteq(0x12, line->bbox.y1);
+ ut_asserteq(0, line->start);
+ ut_asserteq(20, line->len);
+ ut_asserteq(nl, line->len);
+
+ line++;
+ ut_asserteq(0x0, line->bbox.x0);
+ ut_asserteq(0x12, line->bbox.y0);
+ ut_asserteq(0x3ea, line->bbox.x1);
+ ut_asserteq(0x24, line->bbox.y1);
+ ut_asserteq(21, line->start);
+ ut_asserteq(nl + 1, line->start);
+ ut_asserteq(163, line->len);
+ ut_asserteq(strlen(test_string + nl + 1), line->len);
+
+ /* now use a limit on the width */
+ ut_assertok(vidconsole_measure(con, NULL, 0, test_string, limit, &bbox,
+ &lines));
+ ut_asserteq(0, bbox.x0);
+ ut_asserteq(0, bbox.y0);
+ ut_asserteq(0x31e, bbox.x1);
+ ut_asserteq(0x36, bbox.y1);
+ ut_asserteq(3, lines.count);
+
+ nl = strchr(test_string, '\n') - test_string;
+
+ line = alist_get(&lines, 0, struct vidconsole_mline);
+ ut_assertnonnull(line);
+ ut_asserteq(0, line->bbox.x0);
+ ut_asserteq(0, line->bbox.y0);
+ ut_asserteq(0x8c, line->bbox.x1);
+ ut_asserteq(0x12, line->bbox.y1);
+ ut_asserteq(0, line->start);
+ ut_asserteq(20, line->len);
+ ut_asserteq(nl, line->len);
+ printf("line0 '%.*s'\n", line->len, test_string + line->start);
+ ut_asserteq_strn("There is always much",
+ test_string + line->start);
+
+ line++;
+ ut_asserteq(0x0, line->bbox.x0);
+ ut_asserteq(0x12, line->bbox.y0);
+ ut_asserteq(0x31e, line->bbox.x1);
+ ut_asserteq(0x24, line->bbox.y1);
+ ut_asserteq(21, line->start);
+ ut_asserteq(nl + 1, line->start);
+ ut_asserteq(129, line->len);
+ printf("line1 '%.*s'\n", line->len, test_string + line->start);
+ ut_asserteq_strn("to be said for not attempting more than you can do "
+ "and for making a certainty of what you try. But this "
+ "principle, like others in",
+ test_string + line->start);
+
+ line++;
+ ut_asserteq(0x0, line->bbox.x0);
+ ut_asserteq(0x24, line->bbox.y0);
+ ut_asserteq(0xc8, line->bbox.x1);
+ ut_asserteq(0x36, line->bbox.y1);
+ ut_asserteq(21 + 130, line->start);
+ ut_asserteq(33, line->len);
+ printf("line2 '%.*s'\n", line->len, test_string + line->start);
+ ut_asserteq_strn("life and war, has its exceptions.",
+ test_string + line->start);
+
+ /*
+ * all characters should be accounted for, except the newline and the
+ * space which is consumed in the wordwrap
+ */
+ ut_asserteq(strlen(test_string) - 2,
+ line[-2].len + line[-1].len + line->len);
+
+ return 0;
+}
+DM_TEST(dm_test_font_measure, UTF_SCAN_FDT);
+
+/* Test silencing the video console */
+static int dm_test_video_silence(struct unit_test_state *uts)
+{
+ struct udevice *dev, *con;
+ struct stdio_dev *sdev;
+
+ ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
+
+ /*
+ * use the old console device from before when dm_test_pre_run() was
+ * called, since that is what is in stdio / console
+ */
+ sdev = stdio_get_by_name("vidconsole");
+ ut_assertnonnull(sdev);
+ con = sdev->priv;
+ ut_assertok(vidconsole_clear_and_reset(con));
+ ut_unsilence_console(uts);
+
+ printf("message 1: console\n");
+ vidconsole_put_string(con, "message 1: video\n");
+
+ vidconsole_set_quiet(con, true);
+ printf("second message: console\n");
+ vidconsole_put_string(con, "second message: video\n");
+
+ vidconsole_set_quiet(con, false);
+ printf("final message: console\n");
+ vidconsole_put_string(con, "final message: video\n");
+
+ ut_asserteq(3892, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
+
+ return 0;
+}
+DM_TEST(dm_test_video_silence, UTF_SCAN_FDT);
+
+/* test drawing a box */
+static int dm_test_video_box(struct unit_test_state *uts)
+{
+ struct video_priv *priv;
+ struct udevice *dev;
+
+ ut_assertok(video_get_nologo(uts, &dev));
+ priv = dev_get_uclass_priv(dev);
+ video_draw_box(dev, 100, 100, 200, 200, 3,
+ video_index_to_colour(priv, VID_LIGHT_BLUE));
+ video_draw_box(dev, 300, 100, 400, 200, 1,
+ video_index_to_colour(priv, VID_MAGENTA));
+ video_draw_box(dev, 500, 100, 600, 200, 20,
+ video_index_to_colour(priv, VID_LIGHT_RED));
+ ut_asserteq(133, video_compress_fb(uts, dev, false));
+ ut_assertok(video_check_copy_fb(uts, dev));
return 0;
}
-DM_TEST(dm_test_video_truetype_bs, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_video_box, UTF_SCAN_FDT);
diff --git a/test/dm/video_bridge.c b/test/dm/video_bridge.c
new file mode 100644
index 00000000000..f55a333c0b8
--- /dev/null
+++ b/test/dm/video_bridge.c
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test for video bridge uclass
+ *
+ * Copyright (c) 2025 Svyatoslav Ryhel <clamor95@gmail.com>
+ */
+
+#include <backlight.h>
+#include <dm.h>
+#include <panel.h>
+#include <video.h>
+#include <video_bridge.h>
+#include <asm/gpio.h>
+#include <asm/test.h>
+#include <dm/test.h>
+#include <power/regulator.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+/* Basic test of the video uclass, test is based on driven panel */
+static int dm_test_video_bridge(struct unit_test_state *uts)
+{
+ struct udevice *dev, *pwm, *gpio, *reg;
+ uint period_ns, duty_ns;
+ bool enable, polarity;
+ struct display_timing timing;
+
+ ut_assertok(uclass_first_device_err(UCLASS_VIDEO_BRIDGE, &dev));
+ ut_assertok(uclass_get_device_by_name(UCLASS_PWM, "pwm", &pwm));
+ ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio));
+ ut_assertok(regulator_get_by_platname("VDD_EMMC_1.8V", &reg));
+ ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
+ &enable, &polarity));
+ ut_asserteq(false, enable);
+ ut_asserteq(true, regulator_get_enable(reg));
+
+ /* bridge calls panel_enable_backlight() of panel */
+ ut_assertok(video_bridge_attach(dev));
+ ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
+ &enable, &polarity));
+ ut_asserteq(1000, period_ns);
+ ut_asserteq(170 * 1000 / 255, duty_ns);
+ ut_asserteq(true, enable);
+ ut_asserteq(false, polarity);
+ ut_asserteq(1, sandbox_gpio_get_value(gpio, 1));
+ ut_asserteq(true, regulator_get_enable(reg));
+
+ /* bridge calls panel_set_backlight() of panel */
+ ut_assertok(video_bridge_set_backlight(dev, BACKLIGHT_DEFAULT));
+ ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
+ &enable, &polarity));
+ ut_asserteq(true, enable);
+ ut_asserteq(170 * 1000 / 255, duty_ns);
+
+ /* bridge should be active */
+ ut_assertok(video_bridge_set_active(dev, true));
+
+ /* bridge is internal and has no hotplug gpio */
+ ut_asserteq(-ENOENT, video_bridge_check_attached(dev));
+
+ /* check passing timings and EDID */
+ ut_assertok(video_bridge_get_display_timing(dev, &timing));
+ ut_assertok(video_bridge_read_edid(dev, NULL, 0));
+
+ return 0;
+}
+DM_TEST(dm_test_video_bridge, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/virtio.c b/test/dm/virtio.c
index 3e108cdc35d..2574c4da624 100644
--- a/test/dm/virtio.c
+++ b/test/dm/virtio.c
@@ -3,7 +3,6 @@
* Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
*/
-#include <common.h>
#include <dm.h>
#include <virtio_types.h>
#include <virtio.h>
@@ -30,4 +29,4 @@ static int dm_test_virtio_missing_ops(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_virtio_missing_ops, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_virtio_missing_ops, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/virtio_device.c b/test/dm/virtio_device.c
index fdda4da4178..53414e4d3a4 100644
--- a/test/dm/virtio_device.c
+++ b/test/dm/virtio_device.c
@@ -3,7 +3,6 @@
* Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
*/
-#include <common.h>
#include <dm.h>
#include <virtio_types.h>
#include <virtio.h>
@@ -45,7 +44,7 @@ static int dm_test_virtio_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_virtio_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_virtio_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test all of the virtio uclass ops */
static int dm_test_virtio_all_ops(struct unit_test_state *uts)
@@ -94,7 +93,7 @@ static int dm_test_virtio_all_ops(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_virtio_all_ops, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_virtio_all_ops, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test removal of virtio device driver */
static int dm_test_virtio_remove(struct unit_test_state *uts)
@@ -123,7 +122,7 @@ static int dm_test_virtio_remove(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_virtio_remove, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_virtio_remove, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test all of the virtio ring */
static int dm_test_virtio_ring(struct unit_test_state *uts)
@@ -195,4 +194,4 @@ static int dm_test_virtio_ring(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_virtio_ring, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_virtio_ring, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/virtio_rng.c b/test/dm/virtio_rng.c
index 8b9a04b1fde..e404b08484e 100644
--- a/test/dm/virtio_rng.c
+++ b/test/dm/virtio_rng.c
@@ -4,7 +4,6 @@
* Written by Andrew Scull <ascull@google.com>
*/
-#include <common.h>
#include <dm.h>
#include <virtio_types.h>
#include <virtio.h>
@@ -49,4 +48,4 @@ static int dm_test_virtio_rng_check_len(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_virtio_rng_check_len, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_virtio_rng_check_len, UTF_SCAN_PDATA | UTF_SCAN_FDT);
diff --git a/test/dm/wdt.c b/test/dm/wdt.c
index 2bbebcdbf28..bef29591d5a 100644
--- a/test/dm/wdt.c
+++ b/test/dm/wdt.c
@@ -3,9 +3,8 @@
* Copyright 2017 Google, Inc
*/
-#include <common.h>
-#include <cyclic.h>
#include <dm.h>
+#include <time.h>
#include <wdt.h>
#include <asm/gpio.h>
#include <asm/state.h>
@@ -14,6 +13,7 @@
#include <test/test.h>
#include <test/ut.h>
#include <linux/delay.h>
+#include <u-boot/schedule.h>
#include <watchdog.h>
/* Test that watchdog driver functions are called */
@@ -43,7 +43,7 @@ static int dm_test_wdt_base(struct unit_test_state *uts)
return 0;
}
-DM_TEST(dm_test_wdt_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_wdt_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_wdt_gpio_toggle(struct unit_test_state *uts)
{
@@ -71,11 +71,11 @@ static int dm_test_wdt_gpio_toggle(struct unit_test_state *uts)
ut_assertok(wdt_reset(wdt));
ut_asserteq(val, sandbox_gpio_get_value(gpio, offset));
- ut_asserteq(-ENOSYS, wdt_stop(wdt));
+ ut_asserteq(-EOPNOTSUPP, wdt_stop(wdt));
return 0;
}
-DM_TEST(dm_test_wdt_gpio_toggle, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_wdt_gpio_toggle, UTF_SCAN_FDT);
static int dm_test_wdt_gpio_level(struct unit_test_state *uts)
{
@@ -103,11 +103,11 @@ static int dm_test_wdt_gpio_level(struct unit_test_state *uts)
ut_assertok(wdt_reset(wdt));
ut_asserteq(val, sandbox_gpio_get_value(gpio, offset));
- ut_asserteq(-ENOSYS, wdt_stop(wdt));
+ ut_asserteq(-EOPNOTSUPP, wdt_stop(wdt));
return 0;
}
-DM_TEST(dm_test_wdt_gpio_level, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_wdt_gpio_level, UTF_SCAN_FDT);
static int dm_test_wdt_watchdog_reset(struct unit_test_state *uts)
{
@@ -131,7 +131,7 @@ static int dm_test_wdt_watchdog_reset(struct unit_test_state *uts)
/* Neither device should be "started", so watchdog_reset() should be a no-op. */
reset_count = state->wdt.reset_count;
val = sandbox_gpio_get_value(gpio, offset);
- cyclic_run();
+ schedule();
ut_asserteq(reset_count, state->wdt.reset_count);
ut_asserteq(val, sandbox_gpio_get_value(gpio, offset));
@@ -141,22 +141,22 @@ static int dm_test_wdt_watchdog_reset(struct unit_test_state *uts)
/* Make sure both devices have just been pinged. */
timer_test_add_offset(100);
- cyclic_run();
+ schedule();
reset_count = state->wdt.reset_count;
val = sandbox_gpio_get_value(gpio, offset);
/* The gpio watchdog should be pinged, the sandbox one not. */
timer_test_add_offset(30);
- cyclic_run();
+ schedule();
ut_asserteq(reset_count, state->wdt.reset_count);
ut_asserteq(!val, sandbox_gpio_get_value(gpio, offset));
/* After another ~30ms, both devices should get pinged. */
timer_test_add_offset(30);
- cyclic_run();
+ schedule();
ut_asserteq(reset_count + 1, state->wdt.reset_count);
ut_asserteq(val, sandbox_gpio_get_value(gpio, offset));
return 0;
}
-DM_TEST(dm_test_wdt_watchdog_reset, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_wdt_watchdog_reset, UTF_SCAN_FDT);
diff --git a/test/env/Kconfig b/test/env/Kconfig
index 6cb82337b36..21d88f47a6d 100644
--- a/test/env/Kconfig
+++ b/test/env/Kconfig
@@ -1,6 +1,5 @@
config UT_ENV
bool "Enable env unit tests"
- depends on UNIT_TEST
default y
help
This enables the 'ut env' command which runs a series of unit
diff --git a/test/env/attr.c b/test/env/attr.c
index 8d5c0f1c3df..de5d5d4ee27 100644
--- a/test/env/attr.c
+++ b/test/env/attr.c
@@ -4,7 +4,6 @@
* Joe Hershberger, National Instruments, joe.hershberger@ni.com
*/
-#include <common.h>
#include <command.h>
#include <env_attr.h>
#include <test/env.h>
diff --git a/test/env/cmd_ut_env.c b/test/env/cmd_ut_env.c
index d65a32179ce..43f1b7d1cef 100644
--- a/test/env/cmd_ut_env.c
+++ b/test/env/cmd_ut_env.c
@@ -4,17 +4,71 @@
* Joe Hershberger, National Instruments, joe.hershberger@ni.com
*/
-#include <common.h>
-#include <command.h>
#include <test/env.h>
-#include <test/suites.h>
#include <test/ut.h>
-int do_ut_env(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+static int env_test_env_cmd(struct unit_test_state *uts)
{
- struct unit_test *tests = UNIT_TEST_SUITE_START(env_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(env_test);
+ ut_assertok(run_command("setenv non_default_var1 1", 0));
+ ut_assert_console_end();
- return cmd_ut_category("environment", "env_test_",
- tests, n_ents, argc, argv);
+ ut_assertok(run_command("setenv non_default_var2 2", 0));
+ ut_assert_console_end();
+
+ ut_assertok(run_command("env print non_default_var1", 0));
+ ut_assert_nextline("non_default_var1=1");
+ ut_assert_console_end();
+
+ ut_assertok(run_command("env default non_default_var1", 0));
+ ut_assert_nextline("WARNING: 'non_default_var1' not in imported env, deleting it!");
+ ut_assert_console_end();
+
+ ut_asserteq(1, run_command("env exists non_default_var1", 0));
+ ut_assert_console_end();
+
+ ut_asserteq(0, run_command("env exists non_default_var2", 0));
+ ut_assert_console_end();
+
+ ut_assertok(run_command("setenv non_default_var1 3", 0));
+ ut_assert_console_end();
+
+ ut_assertok(run_command("env default -k non_default_var1", 0));
+ ut_assert_console_end();
+
+ ut_asserteq(0, run_command("env exists non_default_var1", 0));
+ ut_assert_console_end();
+
+ ut_asserteq(0, run_command("env exists non_default_var2", 0));
+ ut_assert_console_end();
+
+ ut_assertok(run_command("env default -k -a -f", 0));
+ ut_assert_nextline("## Resetting to default environment");
+ ut_assert_console_end();
+
+ ut_asserteq(0, run_command("env exists non_default_var1", 0));
+ ut_assert_console_end();
+
+ ut_asserteq(0, run_command("env exists non_default_var2", 0));
+ ut_assert_console_end();
+
+ /*
+ * While the following test of "env default -a" by itself
+ * works, it unfortunately causes an unrelated test case,
+ * env_test_fdt_import(), to fail, because the "from_fdt"
+ * variable would be removed.
+ */
+#if 0
+ ut_assertok(run_command("env default -a", 0));
+ ut_assert_nextline("## Resetting to default environment");
+ ut_assert_console_end();
+
+ ut_asserteq(1, run_command("env exists non_default_var1", 0));
+ ut_assert_console_end();
+
+ ut_asserteq(1, run_command("env exists non_default_var2", 0));
+ ut_assert_console_end();
+#endif
+
+ return 0;
}
+ENV_TEST(env_test_env_cmd, UTF_CONSOLE);
diff --git a/test/env/fdt.c b/test/env/fdt.c
index 30bfa88c355..c495ac7b307 100644
--- a/test/env/fdt.c
+++ b/test/env/fdt.c
@@ -1,4 +1,3 @@
-#include <common.h>
#include <command.h>
#include <env_attr.h>
#include <test/env.h>
diff --git a/test/env/hashtable.c b/test/env/hashtable.c
index 70102f9121c..16e49358888 100644
--- a/test/env/hashtable.c
+++ b/test/env/hashtable.c
@@ -4,11 +4,11 @@
* Roman Kapl, SYSGO, rka@sysgo.com
*/
-#include <common.h>
#include <command.h>
#include <log.h>
#include <search.h>
#include <stdio.h>
+#include <vsprintf.h>
#include <test/env.h>
#include <test/ut.h>
@@ -101,7 +101,6 @@ static int env_test_htab_fill(struct unit_test_state *uts)
hdestroy_r(&htab);
return 0;
}
-
ENV_TEST(env_test_htab_fill, 0);
/* Fill the hashtable up halfway an repeateadly delete/create elements
@@ -122,5 +121,4 @@ static int env_test_htab_deletes(struct unit_test_state *uts)
hdestroy_r(&htab);
return 0;
}
-
ENV_TEST(env_test_htab_deletes, 0);
diff --git a/test/overlay/Kconfig b/test/fdt_overlay/Kconfig
index a4f154415db..c50b8822544 100644
--- a/test/overlay/Kconfig
+++ b/test/fdt_overlay/Kconfig
@@ -1,6 +1,6 @@
-config UT_OVERLAY
+config UT_FDT_OVERLAY
bool "Enable Device Tree Overlays Unit Tests"
- depends on UNIT_TEST && OF_CONTROL
+ depends on OF_CONTROL && SANDBOX
default y
select OF_LIBFDT_OVERLAY
help
diff --git a/test/overlay/Makefile b/test/fdt_overlay/Makefile
index 2deec929abf..5625c0d8885 100644
--- a/test/overlay/Makefile
+++ b/test/fdt_overlay/Makefile
@@ -4,11 +4,11 @@
# Copyright (c) 2016 Free Electrons
# Test files
-obj-y += cmd_ut_overlay.o
+obj-y += cmd_ut_fdt_overlay.o
DTC_FLAGS += -@
# DT overlays
obj-y += test-fdt-base.dtb.o
-obj-y += test-fdt-overlay.dtb.o
-obj-y += test-fdt-overlay-stacked.dtb.o
+obj-y += test-fdt-overlay.dtbo.o
+obj-y += test-fdt-overlay-stacked.dtbo.o
diff --git a/test/overlay/cmd_ut_overlay.c b/test/fdt_overlay/cmd_ut_fdt_overlay.c
index 56a3df17138..0084033b6ca 100644
--- a/test/overlay/cmd_ut_overlay.c
+++ b/test/fdt_overlay/cmd_ut_fdt_overlay.c
@@ -4,9 +4,9 @@
* Copyright (c) 2016 Free Electrons
*/
-#include <common.h>
#include <command.h>
#include <errno.h>
+#include <fdtdec.h>
#include <fdt_support.h>
#include <image.h>
#include <log.h>
@@ -14,45 +14,73 @@
#include <linux/sizes.h>
+#include <test/fdt_overlay.h>
#include <test/ut.h>
-#include <test/overlay.h>
-#include <test/suites.h>
/* 4k ought to be enough for anybody */
#define FDT_COPY_SIZE (4 * SZ_1K)
extern u32 __dtb_test_fdt_base_begin;
-extern u32 __dtb_test_fdt_overlay_begin;
-extern u32 __dtb_test_fdt_overlay_stacked_begin;
+extern u32 __dtbo_test_fdt_overlay_begin;
+extern u32 __dtbo_test_fdt_overlay_stacked_begin;
static void *fdt;
-static int ut_fdt_getprop_u32_by_index(void *fdt, const char *path,
- const char *name, int index,
- u32 *out)
+static int fdt_overlay_init(struct unit_test_state *uts)
{
- const fdt32_t *val;
- int node_off;
- int len;
+ void *fdt_base = &__dtb_test_fdt_base_begin;
+ void *fdt_overlay = &__dtbo_test_fdt_overlay_begin;
+ void *fdt_overlay_stacked = &__dtbo_test_fdt_overlay_stacked_begin;
+ void *fdt_overlay_copy, *fdt_overlay_stacked_copy;
- node_off = fdt_path_offset(fdt, path);
- if (node_off < 0)
- return node_off;
+ ut_assertok(fdt_check_header(fdt_base));
+ ut_assertok(fdt_check_header(fdt_overlay));
- val = fdt_getprop(fdt, node_off, name, &len);
- if (!val || (len < (sizeof(uint32_t) * (index + 1))))
- return -FDT_ERR_NOTFOUND;
+ fdt = malloc(FDT_COPY_SIZE);
+ fdt_overlay_copy = malloc(FDT_COPY_SIZE);
+ fdt_overlay_stacked_copy = malloc(FDT_COPY_SIZE);
+ ut_assertnonnull(fdt);
+ ut_assertnonnull(fdt_overlay_copy);
+ ut_assertnonnull(fdt_overlay_stacked_copy);
- *out = fdt32_to_cpu(*(val + index));
+ /*
+ * Resize the FDT to 4k so that we have room to operate on
+ *
+ * (and relocate it since the memory might be mapped
+ * read-only)
+ */
+ ut_assertok(fdt_open_into(fdt_base, fdt, FDT_COPY_SIZE));
- return 0;
-}
+ /*
+ * Resize the overlay to 4k so that we have room to operate on
+ *
+ * (and relocate it since the memory might be mapped
+ * read-only)
+ */
+ ut_assertok(fdt_open_into(fdt_overlay, fdt_overlay_copy,
+ FDT_COPY_SIZE));
-static int ut_fdt_getprop_u32(void *fdt, const char *path, const char *name,
- u32 *out)
-{
- return ut_fdt_getprop_u32_by_index(fdt, path, name, 0, out);
+ /*
+ * Resize the stacked overlay to 4k so that we have room to operate on
+ *
+ * (and relocate it since the memory might be mapped
+ * read-only)
+ */
+ ut_assertok(fdt_open_into(fdt_overlay_stacked, fdt_overlay_stacked_copy,
+ FDT_COPY_SIZE));
+
+ /* Apply the overlay */
+ ut_assertok(fdt_overlay_apply(fdt, fdt_overlay_copy));
+
+ /* Apply the stacked overlay */
+ ut_assertok(fdt_overlay_apply(fdt, fdt_overlay_stacked_copy));
+
+ free(fdt_overlay_stacked_copy);
+ free(fdt_overlay_copy);
+
+ return 0;
}
+FDT_OVERLAY_TEST_INIT(fdt_overlay_init, 0);
static int fdt_getprop_str(void *fdt, const char *path, const char *name,
const char **out)
@@ -69,19 +97,20 @@ static int fdt_getprop_str(void *fdt, const char *path, const char *name,
return len < 0 ? len : 0;
}
-static int fdt_overlay_change_int_property(struct unit_test_state *uts)
+static int fdt_overlay_test_change_int_property(struct unit_test_state *uts)
{
- u32 val = 0;
+ int off;
- ut_assertok(ut_fdt_getprop_u32(fdt, "/test-node", "test-int-property",
- &val));
- ut_asserteq(43, val);
+ off = fdt_path_offset(fdt, "/test-node");
+ ut_assert(off >= 0);
+
+ ut_asserteq(43, fdtdec_get_uint(fdt, off, "test-int-property", 0));
return CMD_RET_SUCCESS;
}
-OVERLAY_TEST(fdt_overlay_change_int_property, 0);
+FDT_OVERLAY_TEST(fdt_overlay_test_change_int_property, 0);
-static int fdt_overlay_change_str_property(struct unit_test_state *uts)
+static int fdt_overlay_test_change_str_property(struct unit_test_state *uts)
{
const char *val = NULL;
@@ -91,9 +120,9 @@ static int fdt_overlay_change_str_property(struct unit_test_state *uts)
return CMD_RET_SUCCESS;
}
-OVERLAY_TEST(fdt_overlay_change_str_property, 0);
+FDT_OVERLAY_TEST(fdt_overlay_test_change_str_property, 0);
-static int fdt_overlay_add_str_property(struct unit_test_state *uts)
+static int fdt_overlay_test_add_str_property(struct unit_test_state *uts)
{
const char *val = NULL;
@@ -103,9 +132,9 @@ static int fdt_overlay_add_str_property(struct unit_test_state *uts)
return CMD_RET_SUCCESS;
}
-OVERLAY_TEST(fdt_overlay_add_str_property, 0);
+FDT_OVERLAY_TEST(fdt_overlay_test_add_str_property, 0);
-static int fdt_overlay_add_node_by_phandle(struct unit_test_state *uts)
+static int fdt_overlay_test_add_node_by_phandle(struct unit_test_state *uts)
{
int off;
@@ -116,9 +145,9 @@ static int fdt_overlay_add_node_by_phandle(struct unit_test_state *uts)
return CMD_RET_SUCCESS;
}
-OVERLAY_TEST(fdt_overlay_add_node_by_phandle, 0);
+FDT_OVERLAY_TEST(fdt_overlay_test_add_node_by_phandle, 0);
-static int fdt_overlay_add_node_by_path(struct unit_test_state *uts)
+static int fdt_overlay_test_add_node_by_path(struct unit_test_state *uts)
{
int off;
@@ -129,9 +158,9 @@ static int fdt_overlay_add_node_by_path(struct unit_test_state *uts)
return CMD_RET_SUCCESS;
}
-OVERLAY_TEST(fdt_overlay_add_node_by_path, 0);
+FDT_OVERLAY_TEST(fdt_overlay_test_add_node_by_path, 0);
-static int fdt_overlay_add_subnode_property(struct unit_test_state *uts)
+static int fdt_overlay_test_add_subnode_property(struct unit_test_state *uts)
{
int off;
@@ -143,12 +172,12 @@ static int fdt_overlay_add_subnode_property(struct unit_test_state *uts)
return CMD_RET_SUCCESS;
}
-OVERLAY_TEST(fdt_overlay_add_subnode_property, 0);
+FDT_OVERLAY_TEST(fdt_overlay_test_add_subnode_property, 0);
-static int fdt_overlay_local_phandle(struct unit_test_state *uts)
+static int fdt_overlay_test_local_phandle(struct unit_test_state *uts)
{
uint32_t local_phandle;
- u32 val = 0;
+ u32 val[2];
int off;
off = fdt_path_offset(fdt, "/new-local-node");
@@ -157,22 +186,19 @@ static int fdt_overlay_local_phandle(struct unit_test_state *uts)
local_phandle = fdt_get_phandle(fdt, off);
ut_assert(local_phandle);
- ut_assertok(ut_fdt_getprop_u32_by_index(fdt, "/", "test-several-phandle",
- 0, &val));
- ut_asserteq(local_phandle, val);
-
- ut_assertok(ut_fdt_getprop_u32_by_index(fdt, "/", "test-several-phandle",
- 1, &val));
- ut_asserteq(local_phandle, val);
+ ut_assertok(fdtdec_get_int_array(fdt, 0, "test-several-phandle", val,
+ ARRAY_SIZE(val)));
+ ut_asserteq(local_phandle, val[0]);
+ ut_asserteq(local_phandle, val[1]);
return CMD_RET_SUCCESS;
}
-OVERLAY_TEST(fdt_overlay_local_phandle, 0);
+FDT_OVERLAY_TEST(fdt_overlay_test_local_phandle, 0);
-static int fdt_overlay_local_phandles(struct unit_test_state *uts)
+static int fdt_overlay_test_local_phandles(struct unit_test_state *uts)
{
uint32_t local_phandle, test_phandle;
- u32 val = 0;
+ u32 val[2];
int off;
off = fdt_path_offset(fdt, "/new-local-node");
@@ -187,99 +213,25 @@ static int fdt_overlay_local_phandles(struct unit_test_state *uts)
test_phandle = fdt_get_phandle(fdt, off);
ut_assert(test_phandle);
- ut_assertok(ut_fdt_getprop_u32_by_index(fdt, "/", "test-phandle", 0,
- &val));
- ut_asserteq(test_phandle, val);
-
- ut_assertok(ut_fdt_getprop_u32_by_index(fdt, "/", "test-phandle", 1,
- &val));
- ut_asserteq(local_phandle, val);
-
- return CMD_RET_SUCCESS;
-}
-OVERLAY_TEST(fdt_overlay_local_phandles, 0);
-
-static int fdt_overlay_stacked(struct unit_test_state *uts)
-{
- u32 val = 0;
-
- ut_assertok(ut_fdt_getprop_u32(fdt, "/new-local-node",
- "stacked-test-int-property", &val));
- ut_asserteq(43, val);
+ ut_assertok(fdtdec_get_int_array(fdt, 0, "test-phandle", val,
+ ARRAY_SIZE(val)));
+ ut_asserteq(test_phandle, val[0]);
+ ut_asserteq(local_phandle, val[1]);
return CMD_RET_SUCCESS;
}
-OVERLAY_TEST(fdt_overlay_stacked, 0);
+FDT_OVERLAY_TEST(fdt_overlay_test_local_phandles, 0);
-int do_ut_overlay(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+static int fdt_overlay_test_stacked(struct unit_test_state *uts)
{
- struct unit_test *tests = UNIT_TEST_SUITE_START(overlay_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(overlay_test);
- struct unit_test_state *uts;
- void *fdt_base = &__dtb_test_fdt_base_begin;
- void *fdt_overlay = &__dtb_test_fdt_overlay_begin;
- void *fdt_overlay_stacked = &__dtb_test_fdt_overlay_stacked_begin;
- void *fdt_overlay_copy, *fdt_overlay_stacked_copy;
- int ret = -ENOMEM;
-
- uts = calloc(1, sizeof(*uts));
- if (!uts)
- return -ENOMEM;
-
- ut_assertok(fdt_check_header(fdt_base));
- ut_assertok(fdt_check_header(fdt_overlay));
-
- fdt = malloc(FDT_COPY_SIZE);
- if (!fdt)
- goto err1;
-
- fdt_overlay_copy = malloc(FDT_COPY_SIZE);
- if (!fdt_overlay_copy)
- goto err2;
-
- fdt_overlay_stacked_copy = malloc(FDT_COPY_SIZE);
- if (!fdt_overlay_stacked_copy)
- goto err3;
-
- /*
- * Resize the FDT to 4k so that we have room to operate on
- *
- * (and relocate it since the memory might be mapped
- * read-only)
- */
- ut_assertok(fdt_open_into(fdt_base, fdt, FDT_COPY_SIZE));
-
- /*
- * Resize the overlay to 4k so that we have room to operate on
- *
- * (and relocate it since the memory might be mapped
- * read-only)
- */
- ut_assertok(fdt_open_into(fdt_overlay, fdt_overlay_copy,
- FDT_COPY_SIZE));
-
- /*
- * Resize the stacked overlay to 4k so that we have room to operate on
- *
- * (and relocate it since the memory might be mapped
- * read-only)
- */
- ut_assertok(fdt_open_into(fdt_overlay_stacked, fdt_overlay_stacked_copy,
- FDT_COPY_SIZE));
-
- /* Apply the overlay */
- ut_assertok(fdt_overlay_apply(fdt, fdt_overlay_copy));
+ int off;
- /* Apply the stacked overlay */
- ut_assertok(fdt_overlay_apply(fdt, fdt_overlay_stacked_copy));
+ off = fdt_path_offset(fdt, "/new-local-node");
+ ut_assert(off > 0);
- ret = cmd_ut_category("overlay", "", tests, n_ents, argc, argv);
+ ut_asserteq(43,
+ fdtdec_get_uint(fdt, off, "stacked-test-int-property", 0));
- free(fdt_overlay_stacked_copy);
-err3:
- free(fdt_overlay_copy);
-err2:
- free(fdt);
-err1:
- return ret;
+ return CMD_RET_SUCCESS;
}
+FDT_OVERLAY_TEST(fdt_overlay_test_stacked, 0);
diff --git a/test/overlay/test-fdt-base.dts b/test/fdt_overlay/test-fdt-base.dts
index 38278334e4d..38278334e4d 100644
--- a/test/overlay/test-fdt-base.dts
+++ b/test/fdt_overlay/test-fdt-base.dts
diff --git a/test/overlay/test-fdt-overlay-stacked.dts b/test/fdt_overlay/test-fdt-overlay-stacked.dtso
index 6411adec539..6411adec539 100644
--- a/test/overlay/test-fdt-overlay-stacked.dts
+++ b/test/fdt_overlay/test-fdt-overlay-stacked.dtso
diff --git a/test/overlay/test-fdt-overlay.dts b/test/fdt_overlay/test-fdt-overlay.dtso
index 5a21b346d07..5a21b346d07 100644
--- a/test/overlay/test-fdt-overlay.dts
+++ b/test/fdt_overlay/test-fdt-overlay.dtso
diff --git a/test/fuzz/Makefile b/test/fuzz/Makefile
index 663b79ce80b..0a8f3d12239 100644
--- a/test/fuzz/Makefile
+++ b/test/fuzz/Makefile
@@ -4,5 +4,5 @@
# Written by Andrew Scull <ascull@google.com>
#
-obj-$(CONFIG_$(SPL_)CMDLINE) += cmd_fuzz.o
+obj-$(CONFIG_$(PHASE_)CMDLINE) += cmd_fuzz.o
obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o
diff --git a/test/fuzz/cmd_fuzz.c b/test/fuzz/cmd_fuzz.c
index d0bc7b8d7b7..faa140433ff 100644
--- a/test/fuzz/cmd_fuzz.c
+++ b/test/fuzz/cmd_fuzz.c
@@ -5,7 +5,6 @@
*/
#include <command.h>
-#include <common.h>
#include <dm.h>
#include <fuzzing_engine.h>
#include <test/fuzz.h>
diff --git a/test/fuzz/virtio.c b/test/fuzz/virtio.c
index 8a47667e778..836eb9a2f66 100644
--- a/test/fuzz/virtio.c
+++ b/test/fuzz/virtio.c
@@ -4,7 +4,6 @@
* Written by Andrew Scull <ascull@google.com>
*/
-#include <common.h>
#include <dm.h>
#include <virtio.h>
#include <virtio_ring.h>
diff --git a/test/hush/Makefile b/test/hush/Makefile
index a2d98815e50..febdc82e8aa 100644
--- a/test/hush/Makefile
+++ b/test/hush/Makefile
@@ -3,8 +3,9 @@
# (C) Copyright 2021
# Francis Laniel, Amarula Solutions, francis.laniel@amarulasolutions.com
-obj-y += cmd_ut_hush.o
obj-y += if.o
+ifdef CONFIG_CONSOLE_RECORD
obj-y += dollar.o
+endif
obj-y += list.o
obj-y += loop.o
diff --git a/test/hush/cmd_ut_hush.c b/test/hush/cmd_ut_hush.c
deleted file mode 100644
index abad44f3216..00000000000
--- a/test/hush/cmd_ut_hush.c
+++ /dev/null
@@ -1,19 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * (C) Copyright 2021
- * Francis Laniel, Amarula Solutions, francis.laniel@amarulasolutions.com
- */
-
-#include <command.h>
-#include <test/hush.h>
-#include <test/suites.h>
-#include <test/ut.h>
-
-int do_ut_hush(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(hush_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(hush_test);
-
- return cmd_ut_category("hush", "hush_test_",
- tests, n_ents, argc, argv);
-}
diff --git a/test/hush/dollar.c b/test/hush/dollar.c
index 4caa07c192a..820110799a2 100644
--- a/test/hush/dollar.c
+++ b/test/hush/dollar.c
@@ -14,7 +14,6 @@ DECLARE_GLOBAL_DATA_PTR;
static int hush_test_simple_dollar(struct unit_test_state *uts)
{
- console_record_reset_enable();
ut_assertok(run_command("echo $dollar_foo", 0));
ut_assert_nextline_empty();
ut_assert_console_end();
@@ -53,29 +52,22 @@ static int hush_test_simple_dollar(struct unit_test_state *uts)
ut_asserteq(1, run_command("dollar_foo='bar quux", 0));
/* Next line contains error message */
ut_assert_skipline();
-
- if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
- /*
- * For some strange reasons, the console is not empty after
- * running above command.
- * So, we reset it to not have side effects for other tests.
- */
- console_record_reset_enable();
- } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
- ut_assert_console_end();
- }
+ ut_assert_console_end();
ut_asserteq(1, run_command("dollar_foo=bar quux\"", 0));
- /* Two next lines contain error message */
- ut_assert_skipline();
+ /* Next line contains error message */
ut_assert_skipline();
-
- if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
- /* See above comments. */
- console_record_reset_enable();
- } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
- ut_assert_console_end();
+ /*
+ * Old parser prints the error message on two lines:
+ * Unknown command 'quux
+ * ' - try 'help'
+ * While the new only prints it on one:
+ * syntax error: unterminated \"
+ */
+ if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
+ ut_assert_skipline();
}
+ ut_assert_console_end();
ut_assertok(run_command("dollar_foo='bar \"quux'", 0));
@@ -116,17 +108,16 @@ static int hush_test_simple_dollar(struct unit_test_state *uts)
/* Reset local variable. */
ut_assertok(run_command("dollar_foo=", 0));
} else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
- puts("Beware: this test set local variable dollar_foo and it cannot be unset!");
+ puts("Beware: this test set local variable dollar_foo and it cannot be unset!\n");
}
return 0;
}
-HUSH_TEST(hush_test_simple_dollar, 0);
+HUSH_TEST(hush_test_simple_dollar, UTF_CONSOLE);
static int hush_test_env_dollar(struct unit_test_state *uts)
{
env_set("env_foo", "bar");
- console_record_reset_enable();
ut_assertok(run_command("echo $env_foo", 0));
ut_assert_nextline("bar");
@@ -149,17 +140,15 @@ static int hush_test_env_dollar(struct unit_test_state *uts)
/* Reset local variable. */
ut_assertok(run_command("env_foo=", 0));
} else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
- puts("Beware: this test set local variable env_foo and it cannot be unset!");
+ puts("Beware: this test set local variable env_foo and it cannot be unset!\n");
}
return 0;
}
-HUSH_TEST(hush_test_env_dollar, 0);
+HUSH_TEST(hush_test_env_dollar, UTF_CONSOLE);
static int hush_test_command_dollar(struct unit_test_state *uts)
{
- console_record_reset_enable();
-
ut_assertok(run_command("dollar_bar=\"echo bar\"", 0));
ut_assertok(run_command("$dollar_bar", 0));
@@ -217,9 +206,10 @@ static int hush_test_command_dollar(struct unit_test_state *uts)
ut_assertok(run_command("dollar_bar=", 0));
ut_assertok(run_command("dollar_quux=", 0));
} else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
- puts("Beware: this test sets local variable dollar_bar and dollar_quux and they cannot be unset!");
+ puts("Beware: this test sets local variable dollar_bar and "
+ "dollar_quux and they cannot be unset!\n");
}
return 0;
}
-HUSH_TEST(hush_test_command_dollar, 0);
+HUSH_TEST(hush_test_command_dollar, UTF_CONSOLE);
diff --git a/test/hush/loop.c b/test/hush/loop.c
index d734abf136d..7154b9bc0ae 100644
--- a/test/hush/loop.c
+++ b/test/hush/loop.c
@@ -14,8 +14,6 @@ DECLARE_GLOBAL_DATA_PTR;
static int hush_test_for(struct unit_test_state *uts)
{
- console_record_reset_enable();
-
ut_assertok(run_command("for loop_i in foo bar quux quux; do echo $loop_i; done", 0));
ut_assert_nextline("foo");
ut_assert_nextline("bar");
@@ -27,17 +25,15 @@ static int hush_test_for(struct unit_test_state *uts)
/* Reset local variable. */
ut_assertok(run_command("loop_i=", 0));
} else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
- puts("Beware: this test set local variable loop_i and it cannot be unset!");
+ puts("Beware: this test set local variable loop_i and it cannot be unset!\n");
}
return 0;
}
-HUSH_TEST(hush_test_for, 0);
+HUSH_TEST(hush_test_for, UTF_CONSOLE);
static int hush_test_while(struct unit_test_state *uts)
{
- console_record_reset_enable();
-
if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
/*
* Hush 2021 always returns 0 from while loop...
@@ -60,16 +56,15 @@ static int hush_test_while(struct unit_test_state *uts)
/* Reset local variable. */
ut_assertok(run_command("loop_foo=", 0));
} else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
- puts("Beware: this test set local variable loop_foo and it cannot be unset!");
+ puts("Beware: this test set local variable loop_foo and it cannot be unset!\n");
}
return 0;
}
-HUSH_TEST(hush_test_while, 0);
+HUSH_TEST(hush_test_while, UTF_CONSOLE);
static int hush_test_until(struct unit_test_state *uts)
{
- console_record_reset_enable();
env_set("loop_bar", "bar");
/*
@@ -87,4 +82,4 @@ static int hush_test_until(struct unit_test_state *uts)
env_set("loop_bar", NULL);
return 0;
}
-HUSH_TEST(hush_test_until, 0);
+HUSH_TEST(hush_test_until, UTF_CONSOLE);
diff --git a/test/image/spl_load.c b/test/image/spl_load.c
index e1036eff28c..3b6206955d3 100644
--- a/test/image/spl_load.c
+++ b/test/image/spl_load.c
@@ -3,7 +3,6 @@
* Copyright (C) 2023 Sean Anderson <seanga2@gmail.com>
*/
-#include <common.h>
#include <image.h>
#include <imx_container.h>
#include <mapmem.h>
@@ -344,9 +343,7 @@ static int spl_test_image(struct unit_test_state *uts, const char *test_name,
} else {
struct spl_load_info load;
- spl_set_bl_len(&load, 1);
- load.priv = img;
- load.read = spl_test_read;
+ spl_load_init(&load, spl_test_read, img, 1);
if (type == IMX8)
ut_assertok(spl_load_imx_container(&info_read, &load,
0));
diff --git a/test/image/spl_load_fs.c b/test/image/spl_load_fs.c
index a89189e1124..935078bf67b 100644
--- a/test/image/spl_load_fs.c
+++ b/test/image/spl_load_fs.c
@@ -3,7 +3,6 @@
* Copyright (C) 2023 Sean Anderson <seanga2@gmail.com>
*/
-#include <common.h>
#include <blk.h>
#include <ext_common.h>
#include <ext4fs.h>
diff --git a/test/image/spl_load_net.c b/test/image/spl_load_net.c
index 9d067a7a592..4af6e21b8b9 100644
--- a/test/image/spl_load_net.c
+++ b/test/image/spl_load_net.c
@@ -3,7 +3,6 @@
* Copyright (C) 2023 Sean Anderson <seanga2@gmail.com>
*/
-#include <common.h>
#include <dm.h>
#include <spl.h>
#include <test/spl.h>
diff --git a/test/image/spl_load_nor.c b/test/image/spl_load_nor.c
index de5686343b9..f53a6724e27 100644
--- a/test/image/spl_load_nor.c
+++ b/test/image/spl_load_nor.c
@@ -3,7 +3,6 @@
* Copyright (C) 2023 Sean Anderson <seanga2@gmail.com>
*/
-#include <common.h>
#include <dm.h>
#include <spl.h>
#include <asm/io.h>
diff --git a/test/image/spl_load_os.c b/test/image/spl_load_os.c
index 26228a8a4a9..d17cf116a0e 100644
--- a/test/image/spl_load_os.c
+++ b/test/image/spl_load_os.c
@@ -4,71 +4,20 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <image.h>
#include <os.h>
#include <spl.h>
#include <test/spl.h>
#include <test/ut.h>
-/* Context used for this test */
-struct text_ctx {
- int fd;
-};
-
-static ulong read_fit_image(struct spl_load_info *load, ulong offset,
- ulong size, void *buf)
-{
- struct text_ctx *text_ctx = load->priv;
- off_t ret;
- ssize_t res;
-
- ret = os_lseek(text_ctx->fd, offset, OS_SEEK_SET);
- if (ret != offset) {
- printf("Failed to seek to %zx, got %zx (errno=%d)\n", offset,
- ret, errno);
- return 0;
- }
-
- res = os_read(text_ctx->fd, buf, size);
- if (res == -1) {
- printf("Failed to read %lx bytes, got %ld (errno=%d)\n",
- size, res, errno);
- return 0;
- }
-
- return size;
-}
-
static int spl_test_load(struct unit_test_state *uts)
{
struct spl_image_info image;
- struct legacy_img_hdr *header;
- struct text_ctx text_ctx;
- struct spl_load_info load;
char fname[256];
- int ret;
- int fd;
- memset(&load, '\0', sizeof(load));
- spl_set_bl_len(&load, 512);
- load.read = read_fit_image;
-
- ret = sandbox_find_next_phase(fname, sizeof(fname), true);
- if (ret)
- ut_assertf(0, "%s not found, error %d\n", fname, ret);
-
- header = spl_get_load_buffer(-sizeof(*header), sizeof(*header));
-
- fd = os_open(fname, OS_O_RDONLY);
- ut_assert(fd >= 0);
- ut_asserteq(512, os_read(fd, header, 512));
- text_ctx.fd = fd;
-
- load.priv = &text_ctx;
-
- ut_assertok(spl_load_simple_fit(&image, &load, 0, header));
+ ut_assertok(sandbox_spl_load_fit(fname, sizeof(fname), &image));
return 0;
}
SPL_TEST(spl_test_load, 0);
+
diff --git a/test/image/spl_load_spi.c b/test/image/spl_load_spi.c
index 54a95465e23..80836dc0dff 100644
--- a/test/image/spl_load_spi.c
+++ b/test/image/spl_load_spi.c
@@ -3,7 +3,6 @@
* Copyright (C) 2023 Sean Anderson <seanga2@gmail.com>
*/
-#include <common.h>
#include <dm.h>
#include <spi_flash.h>
#include <spl.h>
diff --git a/test/lib/Makefile b/test/lib/Makefile
index e75a263e6a4..d620510f998 100644
--- a/test/lib/Makefile
+++ b/test/lib/Makefile
@@ -2,26 +2,37 @@
#
# (C) Copyright 2018
# Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
-ifeq ($(CONFIG_SPL_BUILD),)
-obj-y += cmd_ut_lib.o
+
+obj-$(CONFIG_$(PHASE_)UT_COMPRESSION) += compression.o
+
+ifeq ($(CONFIG_XPL_BUILD),)
obj-y += abuf.o
+obj-y += alist.o
obj-$(CONFIG_EFI_LOADER) += efi_device_path.o
obj-$(CONFIG_EFI_SECURE_BOOT) += efi_image_region.o
obj-y += hexdump.o
obj-$(CONFIG_SANDBOX) += kconfig.o
obj-y += lmb.o
-obj-y += longjmp.o
+obj-$(CONFIG_HAVE_SETJMP) += longjmp.o
+obj-$(CONFIG_SANDBOX) += membuf.o
+obj-$(CONFIG_HAVE_INITJMP) += initjmp.o
obj-$(CONFIG_CONSOLE_RECORD) += test_print.o
obj-$(CONFIG_SSCANF) += sscanf.o
+obj-$(CONFIG_$(PHASE_)STRTO) += str.o
obj-y += string.o
obj-y += strlcat.o
obj-$(CONFIG_ERRNO_STR) += test_errno_str.o
obj-$(CONFIG_UT_LIB_ASN1) += asn1.o
obj-$(CONFIG_UT_LIB_RSA) += rsa.o
obj-$(CONFIG_AES) += test_aes.o
+obj-$(CONFIG_SHA256) += test_sha256_hmac.o
+obj-$(CONFIG_HKDF_MBEDTLS) += test_sha256_hkdf.o
obj-$(CONFIG_GETOPT) += getopt.o
obj-$(CONFIG_CRC8) += test_crc8.o
obj-$(CONFIG_UT_LIB_CRYPT) += test_crypt.o
+obj-$(CONFIG_UT_TIME) += time.o
+obj-$(CONFIG_$(PHASE_)UT_UNICODE) += unicode.o
+obj-$(CONFIG_UTHREAD) += uthread.o
obj-$(CONFIG_LIB_UUID) += uuid.o
else
obj-$(CONFIG_SANDBOX) += kconfig_spl.o
diff --git a/test/lib/abuf.c b/test/lib/abuf.c
index 42803b20e2a..b38690fe1a9 100644
--- a/test/lib/abuf.c
+++ b/test/lib/abuf.c
@@ -4,7 +4,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <abuf.h>
#include <mapmem.h>
#include <test/lib.h>
@@ -47,7 +46,29 @@ static int lib_test_abuf_set(struct unit_test_state *uts)
}
LIB_TEST(lib_test_abuf_set, 0);
-/* Test abuf_map_sysmem() */
+/* Test abuf_init_const() */
+static int lib_test_abuf_init_const(struct unit_test_state *uts)
+{
+ struct abuf buf;
+ ulong start;
+ void *ptr;
+
+ start = ut_check_free();
+
+ ptr = map_sysmem(0x100, 0);
+
+ abuf_init_const(&buf, ptr, 10);
+ ut_asserteq_ptr(ptr, buf.data);
+ ut_asserteq(10, buf.size);
+
+ /* No memory should have been allocated */
+ ut_assertok(ut_check_delta(start));
+
+ return 0;
+}
+LIB_TEST(lib_test_abuf_init_const, 0);
+
+/* Test abuf_map_sysmem() and abuf_addr() */
static int lib_test_abuf_map_sysmem(struct unit_test_state *uts)
{
struct abuf buf;
@@ -61,6 +82,8 @@ static int lib_test_abuf_map_sysmem(struct unit_test_state *uts)
ut_asserteq(TEST_DATA_LEN, buf.size);
ut_asserteq(false, buf.alloced);
+ ut_asserteq(addr, abuf_addr(&buf));
+
return 0;
}
LIB_TEST(lib_test_abuf_map_sysmem, 0);
diff --git a/test/lib/alist.c b/test/lib/alist.c
new file mode 100644
index 00000000000..0bf24578d2e
--- /dev/null
+++ b/test/lib/alist.c
@@ -0,0 +1,495 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2023 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <alist.h>
+#include <string.h>
+#include <test/lib.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+struct my_struct {
+ uint val;
+ uint other_val;
+};
+
+enum {
+ obj_size = sizeof(struct my_struct),
+};
+
+/* Test alist_init() */
+static int lib_test_alist_init(struct unit_test_state *uts)
+{
+ struct alist lst;
+ ulong start;
+
+ start = ut_check_free();
+
+ /* with a size of 0, the fields should be inited, with no memory used */
+ memset(&lst, '\xff', sizeof(lst));
+ ut_assert(alist_init_struct(&lst, struct my_struct));
+ ut_asserteq_ptr(NULL, lst.data);
+ ut_asserteq(0, lst.count);
+ ut_asserteq(0, lst.alloc);
+ ut_assertok(ut_check_delta(start));
+ alist_uninit(&lst);
+ ut_asserteq_ptr(NULL, lst.data);
+ ut_asserteq(0, lst.count);
+ ut_asserteq(0, lst.alloc);
+
+ /* use an impossible size */
+ ut_asserteq(false, alist_init(&lst, obj_size,
+ CONFIG_SYS_MALLOC_LEN));
+ ut_assertnull(lst.data);
+ ut_asserteq(0, lst.count);
+ ut_asserteq(0, lst.alloc);
+
+ /* use a small size */
+ ut_assert(alist_init(&lst, obj_size, 4));
+ ut_assertnonnull(lst.data);
+ ut_asserteq(0, lst.count);
+ ut_asserteq(4, lst.alloc);
+
+ /* free it */
+ alist_uninit(&lst);
+ ut_asserteq_ptr(NULL, lst.data);
+ ut_asserteq(0, lst.count);
+ ut_asserteq(0, lst.alloc);
+ ut_assertok(ut_check_delta(start));
+
+ /* Check for memory leaks */
+ ut_assertok(ut_check_delta(start));
+
+ return 0;
+}
+LIB_TEST(lib_test_alist_init, 0);
+
+/* Test alist_get() and alist_getd() */
+static int lib_test_alist_get(struct unit_test_state *uts)
+{
+ struct alist lst;
+ ulong start;
+ void *ptr;
+
+ start = ut_check_free();
+
+ ut_assert(alist_init(&lst, obj_size, 3));
+ ut_asserteq(0, lst.count);
+ ut_asserteq(3, lst.alloc);
+
+ ut_assertnull(alist_get_ptr(&lst, 2));
+ ut_assertnull(alist_get_ptr(&lst, 3));
+
+ ptr = alist_ensure_ptr(&lst, 1);
+ ut_assertnonnull(ptr);
+ ut_asserteq(2, lst.count);
+ ptr = alist_ensure_ptr(&lst, 2);
+ ut_asserteq(3, lst.count);
+ ut_assertnonnull(ptr);
+
+ ptr = alist_ensure_ptr(&lst, 3);
+ ut_assertnonnull(ptr);
+ ut_asserteq(4, lst.count);
+ ut_asserteq(6, lst.alloc);
+
+ ut_assertnull(alist_get_ptr(&lst, 4));
+
+ alist_uninit(&lst);
+
+ /* Check for memory leaks */
+ ut_assertok(ut_check_delta(start));
+
+ return 0;
+}
+LIB_TEST(lib_test_alist_get, 0);
+
+/* Test alist_has() */
+static int lib_test_alist_has(struct unit_test_state *uts)
+{
+ struct alist lst;
+ ulong start;
+ void *ptr;
+
+ start = ut_check_free();
+
+ ut_assert(alist_init(&lst, obj_size, 3));
+
+ ut_assert(!alist_has(&lst, 0));
+ ut_assert(!alist_has(&lst, 1));
+ ut_assert(!alist_has(&lst, 2));
+ ut_assert(!alist_has(&lst, 3));
+
+ /* create a new one to force expansion */
+ ptr = alist_ensure_ptr(&lst, 4);
+ ut_assertnonnull(ptr);
+
+ ut_assert(alist_has(&lst, 0));
+ ut_assert(alist_has(&lst, 1));
+ ut_assert(alist_has(&lst, 2));
+ ut_assert(alist_has(&lst, 3));
+ ut_assert(alist_has(&lst, 4));
+ ut_assert(!alist_has(&lst, 5));
+
+ alist_uninit(&lst);
+
+ /* Check for memory leaks */
+ ut_assertok(ut_check_delta(start));
+
+ return 0;
+}
+LIB_TEST(lib_test_alist_has, 0);
+
+/* Test alist_ensure() */
+static int lib_test_alist_ensure(struct unit_test_state *uts)
+{
+ struct my_struct *ptr3, *ptr4;
+ struct alist lst;
+ ulong start;
+
+ start = ut_check_free();
+
+ ut_assert(alist_init_struct(&lst, struct my_struct));
+ ut_asserteq(obj_size, lst.obj_size);
+ ut_asserteq(0, lst.count);
+ ut_asserteq(0, lst.alloc);
+ ptr3 = alist_ensure_ptr(&lst, 3);
+ ut_asserteq(4, lst.count);
+ ut_asserteq(4, lst.alloc);
+ ut_assertnonnull(ptr3);
+ ptr3->val = 3;
+
+ ptr4 = alist_ensure_ptr(&lst, 4);
+ ut_asserteq(8, lst.alloc);
+ ut_asserteq(5, lst.count);
+ ut_assertnonnull(ptr4);
+ ptr4->val = 4;
+ ut_asserteq(4, alist_get(&lst, 4, struct my_struct)->val);
+
+ ut_asserteq_ptr(ptr4, alist_ensure(&lst, 4, struct my_struct));
+
+ alist_ensure(&lst, 4, struct my_struct)->val = 44;
+ ut_asserteq(44, alist_get(&lst, 4, struct my_struct)->val);
+ ut_asserteq(3, alist_get(&lst, 3, struct my_struct)->val);
+ ut_assertnull(alist_get(&lst, 7, struct my_struct));
+ ut_asserteq(8, lst.alloc);
+ ut_asserteq(5, lst.count);
+
+ /* add some more, checking handling of malloc() failure */
+ malloc_enable_testing(0);
+ ut_assertnonnull(alist_ensure(&lst, 7, struct my_struct));
+ ut_assertnull(alist_ensure(&lst, 8, struct my_struct));
+ malloc_disable_testing();
+
+ lst.flags &= ~ALISTF_FAIL;
+ ut_assertnonnull(alist_ensure(&lst, 8, struct my_struct));
+ ut_asserteq(16, lst.alloc);
+ ut_asserteq(9, lst.count);
+
+ alist_uninit(&lst);
+
+ /* Check for memory leaks */
+ ut_assertok(ut_check_delta(start));
+
+ return 0;
+}
+LIB_TEST(lib_test_alist_ensure, 0);
+
+/* Test alist_add() bits not tested by lib_test_alist_ensure() */
+static int lib_test_alist_add(struct unit_test_state *uts)
+{
+ struct my_struct data, *ptr, *ptr2;
+ const struct my_struct *chk;
+ struct alist lst;
+ ulong start;
+
+ start = ut_check_free();
+
+ ut_assert(alist_init_struct(&lst, struct my_struct));
+
+ data.val = 123;
+ data.other_val = 456;
+ ptr = alist_add(&lst, data);
+ ut_assertnonnull(ptr);
+ ut_asserteq(4, lst.alloc);
+ ut_asserteq(1, lst.count);
+
+ ut_asserteq(123, ptr->val);
+ ut_asserteq(456, ptr->other_val);
+
+ ptr2 = alist_add_placeholder(&lst);
+ ut_assertnonnull(ptr2);
+
+ ptr2->val = 321;
+ ptr2->other_val = 654;
+
+ chk = alist_get(&lst, 1, struct my_struct);
+ ut_asserteq(321, chk->val);
+ ut_asserteq(654, chk->other_val);
+
+ ptr2 = alist_getw(&lst, 1, struct my_struct);
+ ut_asserteq(321, ptr2->val);
+ ut_asserteq(654, ptr2->other_val);
+
+ alist_uninit(&lst);
+
+ /* Check for memory leaks */
+ ut_assertok(ut_check_delta(start));
+
+ return 0;
+}
+LIB_TEST(lib_test_alist_add, 0);
+
+/* Test alist_next() */
+static int lib_test_alist_next(struct unit_test_state *uts)
+{
+ const struct my_struct *ptr;
+ struct my_struct data, *ptr2;
+ struct alist lst;
+ ulong start;
+
+ start = ut_check_free();
+
+ ut_assert(alist_init_struct(&lst, struct my_struct));
+ data.val = 123;
+ data.other_val = 0;
+ alist_add(&lst, data);
+
+ data.val = 321;
+ alist_add(&lst, data);
+
+ data.val = 789;
+ alist_add(&lst, data);
+
+ ptr = alist_get(&lst, 0, struct my_struct);
+ ut_assertnonnull(ptr);
+ ut_asserteq(123, ptr->val);
+
+ ptr = alist_next(&lst, ptr);
+ ut_assertnonnull(ptr);
+ ut_asserteq(321, ptr->val);
+
+ ptr2 = (struct my_struct *)ptr;
+ ptr2 = alist_nextw(&lst, ptr2);
+ ut_assertnonnull(ptr2);
+
+ ptr = alist_next(&lst, ptr);
+ ut_assertnonnull(ptr);
+ ut_asserteq(789, ptr->val);
+ ut_asserteq_ptr(ptr, ptr2);
+ ptr2->val = 89;
+ ut_asserteq(89, ptr->val);
+
+ ptr = alist_next(&lst, ptr);
+ ut_assertnull(ptr);
+
+ alist_uninit(&lst);
+
+ /* Check for memory leaks */
+ ut_assertok(ut_check_delta(start));
+
+ return 0;
+}
+LIB_TEST(lib_test_alist_next, 0);
+
+/* Test alist_for_each() */
+static int lib_test_alist_for_each(struct unit_test_state *uts)
+{
+ const struct my_struct *ptr;
+ struct my_struct data, *ptr2;
+ struct alist lst;
+ ulong start;
+ int sum;
+
+ start = ut_check_free();
+
+ ut_assert(alist_init_struct(&lst, struct my_struct));
+ ut_asserteq_ptr(NULL, alist_end(&lst, struct my_struct));
+
+ sum = 0;
+ alist_for_each(ptr, &lst)
+ sum++;
+ ut_asserteq(0, sum);
+
+ alist_for_each(ptr, &lst)
+ sum++;
+ ut_asserteq(0, sum);
+
+ /* add three items */
+ data.val = 1;
+ data.other_val = 0;
+ alist_add(&lst, data);
+
+ ptr = lst.data;
+ ut_asserteq_ptr(ptr + 1, alist_end(&lst, struct my_struct));
+
+ data.val = 2;
+ alist_add(&lst, data);
+ ut_asserteq_ptr(ptr + 2, alist_end(&lst, struct my_struct));
+
+ data.val = 3;
+ alist_add(&lst, data);
+ ut_asserteq_ptr(ptr + 3, alist_end(&lst, struct my_struct));
+
+ /* check alist_chk_ptr() */
+ ut_asserteq(true, alist_chk_ptr(&lst, ptr + 2));
+ ut_asserteq(false, alist_chk_ptr(&lst, ptr + 3));
+ ut_asserteq(false, alist_chk_ptr(&lst, ptr + 4));
+ ut_asserteq(true, alist_chk_ptr(&lst, ptr));
+ ut_asserteq(false, alist_chk_ptr(&lst, ptr - 1));
+
+ /* sum all items */
+ sum = 0;
+ alist_for_each(ptr, &lst)
+ sum += ptr->val;
+ ut_asserteq(6, sum);
+
+ /* increment all items */
+ alist_for_each(ptr2, &lst)
+ ptr2->val += 1;
+
+ /* sum all items again */
+ sum = 0;
+ alist_for_each(ptr, &lst)
+ sum += ptr->val;
+ ut_asserteq(9, sum);
+
+ ptr = lst.data;
+ ut_asserteq_ptr(ptr + 3, alist_end(&lst, struct my_struct));
+
+ /* empty the list and try again */
+ alist_empty(&lst);
+ ut_asserteq_ptr(ptr, alist_end(&lst, struct my_struct));
+ ut_assertnull(alist_get(&lst, 0, struct my_struct));
+
+ sum = 0;
+ alist_for_each(ptr, &lst)
+ sum += ptr->val;
+ ut_asserteq(0, sum);
+
+ alist_uninit(&lst);
+
+ /* Check for memory leaks */
+ ut_assertok(ut_check_delta(start));
+
+ return 0;
+}
+LIB_TEST(lib_test_alist_for_each, 0);
+
+/* Test alist_empty() */
+static int lib_test_alist_empty(struct unit_test_state *uts)
+{
+ struct my_struct data;
+ struct alist lst;
+ ulong start;
+
+ start = ut_check_free();
+
+ ut_assert(alist_init_struct(&lst, struct my_struct));
+ ut_asserteq(0, lst.count);
+ data.val = 1;
+ data.other_val = 0;
+ alist_add(&lst, data);
+ ut_asserteq(1, lst.count);
+ ut_asserteq(4, lst.alloc);
+
+ alist_empty(&lst);
+ ut_asserteq(0, lst.count);
+ ut_asserteq(4, lst.alloc);
+ ut_assertnonnull(lst.data);
+ ut_asserteq(sizeof(data), lst.obj_size);
+
+ alist_uninit(&lst);
+
+ /* Check for memory leaks */
+ ut_assertok(ut_check_delta(start));
+
+ return 0;
+}
+LIB_TEST(lib_test_alist_empty, 0);
+
+static int lib_test_alist_filter(struct unit_test_state *uts)
+{
+ struct my_struct *from, *to, *ptr;
+ struct my_struct data;
+ struct alist lst;
+ ulong start;
+ int count;
+
+ start = ut_check_free();
+
+ ut_assert(alist_init_struct(&lst, struct my_struct));
+ data.val = 1;
+ data.other_val = 0;
+ alist_add(&lst, data);
+
+ data.val = 2;
+ alist_add(&lst, data);
+
+ data.val = 3;
+ alist_add(&lst, data);
+ ptr = lst.data;
+
+ /* filter out all values except 2 */
+ alist_for_each_filter(from, to, &lst) {
+ if (from->val != 2)
+ *to++ = *from;
+ }
+ alist_update_end(&lst, to);
+
+ ut_asserteq(2, lst.count);
+ ut_assertnonnull(lst.data);
+
+ ut_asserteq(1, alist_get(&lst, 0, struct my_struct)->val);
+ ut_asserteq(3, alist_get(&lst, 1, struct my_struct)->val);
+ ut_asserteq_ptr(ptr + 3, from);
+ ut_asserteq_ptr(ptr + 2, to);
+
+ /* filter out nothing */
+ alist_for_each_filter(from, to, &lst) {
+ if (from->val != 2)
+ *to++ = *from;
+ }
+ alist_update_end(&lst, to);
+ ut_asserteq_ptr(ptr + 2, from);
+ ut_asserteq_ptr(ptr + 2, to);
+
+ ut_asserteq(2, lst.count);
+ ut_assertnonnull(lst.data);
+
+ ut_asserteq(1, alist_get(&lst, 0, struct my_struct)->val);
+ ut_asserteq(3, alist_get(&lst, 1, struct my_struct)->val);
+
+ /* filter out everything */
+ alist_for_each_filter(from, to, &lst) {
+ if (from->val == 2)
+ *to++ = *from;
+ }
+ alist_update_end(&lst, to);
+ ut_asserteq_ptr(ptr + 2, from);
+ ut_asserteq_ptr(ptr, to);
+
+ /* filter out everything (nop) */
+ count = 0;
+ alist_for_each_filter(from, to, &lst) {
+ if (from->val == 2)
+ *to++ = *from;
+ count++;
+ }
+ alist_update_end(&lst, to);
+ ut_asserteq_ptr(ptr, from);
+ ut_asserteq_ptr(ptr, to);
+ ut_asserteq(0, count);
+
+ ut_asserteq(0, lst.count);
+ ut_assertnonnull(lst.data);
+
+ alist_uninit(&lst);
+
+ /* Check for memory leaks */
+ ut_assertok(ut_check_delta(start));
+
+ return 0;
+}
+LIB_TEST(lib_test_alist_filter, 0);
diff --git a/test/lib/asn1.c b/test/lib/asn1.c
index a66cdd77df0..f0c7819e408 100644
--- a/test/lib/asn1.c
+++ b/test/lib/asn1.c
@@ -6,7 +6,6 @@
* Unit test for asn1 compiler and asn1 decoder function via various parsers
*/
-#include <common.h>
#include <command.h>
#include <test/lib.h>
#include <test/test.h>
@@ -136,7 +135,6 @@ static int lib_asn1_x509(struct unit_test_state *uts)
return CMD_RET_SUCCESS;
}
-
LIB_TEST(lib_asn1_x509, 0);
#endif /* CONFIG_X509_CERTIFICATE_PARSER */
@@ -325,7 +323,6 @@ static int lib_asn1_pkcs7(struct unit_test_state *uts)
return CMD_RET_SUCCESS;
}
-
LIB_TEST(lib_asn1_pkcs7, 0);
#endif /* CONFIG_PKCS7_MESSAGE_PARSER */
@@ -387,6 +384,5 @@ static int lib_asn1_pkey(struct unit_test_state *uts)
return CMD_RET_SUCCESS;
}
-
LIB_TEST(lib_asn1_pkey, 0);
#endif /* CONFIG_RSA_PUBLIC_KEY_PARSER */
diff --git a/test/lib/cmd_ut_lib.c b/test/lib/cmd_ut_lib.c
deleted file mode 100644
index f1ac015b2c8..00000000000
--- a/test/lib/cmd_ut_lib.c
+++ /dev/null
@@ -1,20 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * Copyright (c) 2019 Heinrich Schuchardt <xypron.glpk@gmx.de>
- *
- * Unit tests for library functions
- */
-
-#include <common.h>
-#include <command.h>
-#include <test/lib.h>
-#include <test/suites.h>
-#include <test/ut.h>
-
-int do_ut_lib(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(lib_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(lib_test);
-
- return cmd_ut_category("lib", "lib_test_", tests, n_ents, argc, argv);
-}
diff --git a/test/compression.c b/test/lib/compression.c
index 3df90819a1f..31b6e5b1eb4 100644
--- a/test/compression.c
+++ b/test/lib/compression.c
@@ -3,7 +3,6 @@
* Copyright (c) 2013, The Chromium Authors
*/
-#include <common.h>
#include <abuf.h>
#include <bootm.h>
#include <command.h>
@@ -24,8 +23,7 @@
#include <linux/lzo.h>
#include <linux/zstd.h>
-#include <test/compression.h>
-#include <test/suites.h>
+#include <test/lib.h>
#include <test/ut.h>
static const char plain[] =
@@ -140,7 +138,6 @@ static const char zstd_compressed[] =
"\x01\xe4\xf4\x6e\xfa";
static const unsigned long zstd_compressed_size = sizeof(zstd_compressed) - 1;
-
#define TEST_BUFFER_SIZE 512
typedef int (*mutate_func)(struct unit_test_state *uts, void *, unsigned long,
@@ -473,40 +470,40 @@ static int compression_test_gzip(struct unit_test_state *uts)
return run_test(uts, "gzip", compress_using_gzip,
uncompress_using_gzip);
}
-COMPRESSION_TEST(compression_test_gzip, 0);
+LIB_TEST(compression_test_gzip, 0);
static int compression_test_bzip2(struct unit_test_state *uts)
{
return run_test(uts, "bzip2", compress_using_bzip2,
uncompress_using_bzip2);
}
-COMPRESSION_TEST(compression_test_bzip2, 0);
+LIB_TEST(compression_test_bzip2, 0);
static int compression_test_lzma(struct unit_test_state *uts)
{
return run_test(uts, "lzma", compress_using_lzma,
uncompress_using_lzma);
}
-COMPRESSION_TEST(compression_test_lzma, 0);
+LIB_TEST(compression_test_lzma, 0);
static int compression_test_lzo(struct unit_test_state *uts)
{
return run_test(uts, "lzo", compress_using_lzo, uncompress_using_lzo);
}
-COMPRESSION_TEST(compression_test_lzo, 0);
+LIB_TEST(compression_test_lzo, 0);
static int compression_test_lz4(struct unit_test_state *uts)
{
return run_test(uts, "lz4", compress_using_lz4, uncompress_using_lz4);
}
-COMPRESSION_TEST(compression_test_lz4, 0);
+LIB_TEST(compression_test_lz4, 0);
static int compression_test_zstd(struct unit_test_state *uts)
{
return run_test(uts, "zstd", compress_using_zstd,
uncompress_using_zstd);
}
-COMPRESSION_TEST(compression_test_zstd, 0);
+LIB_TEST(compression_test_zstd, 0);
static int compress_using_none(struct unit_test_state *uts,
void *in, unsigned long in_size,
@@ -572,50 +569,40 @@ static int compression_test_bootm_gzip(struct unit_test_state *uts)
{
return run_bootm_test(uts, IH_COMP_GZIP, compress_using_gzip);
}
-COMPRESSION_TEST(compression_test_bootm_gzip, 0);
+LIB_TEST(compression_test_bootm_gzip, 0);
static int compression_test_bootm_bzip2(struct unit_test_state *uts)
{
return run_bootm_test(uts, IH_COMP_BZIP2, compress_using_bzip2);
}
-COMPRESSION_TEST(compression_test_bootm_bzip2, 0);
+LIB_TEST(compression_test_bootm_bzip2, 0);
static int compression_test_bootm_lzma(struct unit_test_state *uts)
{
return run_bootm_test(uts, IH_COMP_LZMA, compress_using_lzma);
}
-COMPRESSION_TEST(compression_test_bootm_lzma, 0);
+LIB_TEST(compression_test_bootm_lzma, 0);
static int compression_test_bootm_lzo(struct unit_test_state *uts)
{
return run_bootm_test(uts, IH_COMP_LZO, compress_using_lzo);
}
-COMPRESSION_TEST(compression_test_bootm_lzo, 0);
+LIB_TEST(compression_test_bootm_lzo, 0);
static int compression_test_bootm_lz4(struct unit_test_state *uts)
{
return run_bootm_test(uts, IH_COMP_LZ4, compress_using_lz4);
}
-COMPRESSION_TEST(compression_test_bootm_lz4, 0);
+LIB_TEST(compression_test_bootm_lz4, 0);
static int compression_test_bootm_zstd(struct unit_test_state *uts)
{
return run_bootm_test(uts, IH_COMP_ZSTD, compress_using_zstd);
}
-COMPRESSION_TEST(compression_test_bootm_zstd, 0);
+LIB_TEST(compression_test_bootm_zstd, 0);
static int compression_test_bootm_none(struct unit_test_state *uts)
{
return run_bootm_test(uts, IH_COMP_NONE, compress_using_none);
}
-COMPRESSION_TEST(compression_test_bootm_none, 0);
-
-int do_ut_compression(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(compression_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(compression_test);
-
- return cmd_ut_category("compression", "compression_test_",
- tests, n_ents, argc, argv);
-}
+LIB_TEST(compression_test_bootm_none, 0);
diff --git a/test/lib/efi_device_path.c b/test/lib/efi_device_path.c
index 24e2f23c5af..5cc001e209e 100644
--- a/test/lib/efi_device_path.c
+++ b/test/lib/efi_device_path.c
@@ -5,7 +5,6 @@
* Copyright (c) 2020 Heinrich Schuchardt <xypron.glpk@gmx.de>
*/
-#include <common.h>
#include <efi_loader.h>
#include <test/lib.h>
#include <test/test.h>
@@ -46,5 +45,4 @@ static int lib_test_efi_dp_check_length(struct unit_test_state *uts)
return 0;
}
-
LIB_TEST(lib_test_efi_dp_check_length, 0);
diff --git a/test/lib/efi_image_region.c b/test/lib/efi_image_region.c
index 0b888f84337..2102539ea70 100644
--- a/test/lib/efi_image_region.c
+++ b/test/lib/efi_image_region.c
@@ -3,7 +3,6 @@
* (C) Copyright 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
*/
-#include <common.h>
#include <efi_loader.h>
#include <test/lib.h>
#include <test/test.h>
@@ -66,7 +65,6 @@ static int lib_test_efi_image_region_add(struct unit_test_state *uts)
return 0;
}
-
LIB_TEST(lib_test_efi_image_region_add, 0);
static int lib_test_efi_image_region_sort(struct unit_test_state *uts)
@@ -159,5 +157,4 @@ static int lib_test_efi_image_region_sort(struct unit_test_state *uts)
return 0;
}
-
LIB_TEST(lib_test_efi_image_region_sort, 0);
diff --git a/test/lib/getopt.c b/test/lib/getopt.c
index 3c68b93c8a5..388a076200b 100644
--- a/test/lib/getopt.c
+++ b/test/lib/getopt.c
@@ -6,7 +6,6 @@
* posix/tst-getopt-cancel.c
*/
-#include <common.h>
#include <getopt.h>
#include <test/lib.h>
#include <test/test.h>
diff --git a/test/lib/hexdump.c b/test/lib/hexdump.c
index 5dccf438866..7b4592d175f 100644
--- a/test/lib/hexdump.c
+++ b/test/lib/hexdump.c
@@ -4,7 +4,6 @@
* Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
*/
-#include <common.h>
#include <hexdump.h>
#include <test/lib.h>
#include <test/test.h>
@@ -32,7 +31,6 @@ static int lib_test_hex_to_bin(struct unit_test_state *uts)
return 0;
}
-
LIB_TEST(lib_test_hex_to_bin, 0);
static int lib_test_hex2bin(struct unit_test_state *uts)
@@ -62,7 +60,6 @@ static int lib_test_hex2bin(struct unit_test_state *uts)
return 0;
}
-
LIB_TEST(lib_test_hex2bin, 0);
static int lib_test_bin2hex(struct unit_test_state *uts)
@@ -92,5 +89,4 @@ static int lib_test_bin2hex(struct unit_test_state *uts)
return 0;
}
-
LIB_TEST(lib_test_bin2hex, 0);
diff --git a/test/lib/initjmp.c b/test/lib/initjmp.c
new file mode 100644
index 00000000000..5b4b50b3f0f
--- /dev/null
+++ b/test/lib/initjmp.c
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2025 Linaro Limited
+ *
+ * Unit test for initjmp()
+ */
+
+#include <compiler.h>
+#include <setjmp.h>
+#include <stdbool.h>
+#include <test/lib.h>
+#include <test/ut.h>
+#include <vsprintf.h>
+
+static bool ep_entered;
+static jmp_buf return_buf;
+
+static void __noreturn entrypoint(void)
+{
+ ep_entered = true;
+
+ /* Jump back to the main routine */
+ longjmp(return_buf, 1);
+
+ /* Not reached */
+ panic("longjmp failed\n");
+}
+
+static int lib_initjmp(struct unit_test_state *uts)
+{
+ int ret;
+ void *stack;
+ jmp_buf buf;
+ /* Arbitrary but smaller values (< page size?) fail on SANDBOX */
+ size_t stack_sz = 8192;
+
+ (void)entrypoint;
+
+ ep_entered = false;
+
+ stack = malloc(stack_sz);
+ ut_assertnonnull(stack);
+
+ /*
+ * Prepare return_buf so that entrypoint may jump back just after the
+ * if()
+ */
+ if (!setjmp(return_buf)) {
+ /* return_buf initialized, entrypoint not yet called */
+
+ /*
+ * Prepare another jump buffer to jump into entrypoint with the
+ * given stack
+ */
+ ret = initjmp(buf, entrypoint, stack, stack_sz);
+ ut_assertok(ret);
+
+ /* Jump into entrypoint */
+ longjmp(buf, 1);
+ /*
+ * Not reached since entrypoint is expected to branch after
+ * the if()
+ */
+ ut_assert(false);
+ }
+
+ ut_assert(ep_entered);
+
+ free(stack);
+
+ return 0;
+}
+LIB_TEST(lib_initjmp, 0);
diff --git a/test/lib/kconfig.c b/test/lib/kconfig.c
index 3914f699659..2f47af9acf1 100644
--- a/test/lib/kconfig.c
+++ b/test/lib/kconfig.c
@@ -6,7 +6,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <test/lib.h>
#include <test/test.h>
#include <test/ut.h>
@@ -22,10 +21,12 @@ static int lib_test_is_enabled(struct unit_test_state *uts)
ut_asserteq(0, CONFIG_IS_ENABLED(OF_PLATDATA));
ut_asserteq(0, CONFIG_IS_ENABLED(_UNDEFINED));
- ut_asserteq(0xb000,
- IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED, CONFIG_BLOBLIST_ADDR));
- ut_asserteq(0xb000,
- CONFIG_IF_ENABLED_INT(BLOBLIST_FIXED, BLOBLIST_ADDR));
+ if (IS_ENABLED(CONFIG_BLOBLIST)) {
+ ut_asserteq(0x100, IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED,
+ CONFIG_BLOBLIST_ADDR));
+ ut_asserteq(0x100, CONFIG_IF_ENABLED_INT(BLOBLIST_FIXED,
+ BLOBLIST_ADDR));
+ }
/*
* This fails if CONFIG_TEST_KCONFIG_ENABLE is not enabled, since the
diff --git a/test/lib/kconfig_spl.c b/test/lib/kconfig_spl.c
index 8f8a3411b14..3bd8abdf4b8 100644
--- a/test/lib/kconfig_spl.c
+++ b/test/lib/kconfig_spl.c
@@ -6,7 +6,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <test/lib.h>
#include <test/test.h>
#include <test/ut.h>
diff --git a/test/lib/lmb.c b/test/lib/lmb.c
index 7e4368de22e..3bf558f7f4f 100644
--- a/test/lib/lmb.c
+++ b/test/lib/lmb.c
@@ -3,7 +3,7 @@
* (C) Copyright 2018 Simon Goldschmidt
*/
-#include <common.h>
+#include <alist.h>
#include <dm.h>
#include <lmb.h>
#include <log.h>
@@ -13,50 +13,64 @@
#include <test/test.h>
#include <test/ut.h>
-static inline bool lmb_is_nomap(struct lmb_property *m)
+static inline bool lmb_is_nomap(struct lmb_region *m)
{
return m->flags & LMB_NOMAP;
}
-static int check_lmb(struct unit_test_state *uts, struct lmb *lmb,
- phys_addr_t ram_base, phys_size_t ram_size,
- unsigned long num_reserved,
+static int check_lmb(struct unit_test_state *uts, struct alist *mem_lst,
+ struct alist *used_lst, phys_addr_t ram_base,
+ phys_size_t ram_size, unsigned long num_reserved,
phys_addr_t base1, phys_size_t size1,
phys_addr_t base2, phys_size_t size2,
phys_addr_t base3, phys_size_t size3)
{
+ struct lmb_region *mem, *used;
+
+ mem = mem_lst->data;
+ used = used_lst->data;
+
if (ram_size) {
- ut_asserteq(lmb->memory.cnt, 1);
- ut_asserteq(lmb->memory.region[0].base, ram_base);
- ut_asserteq(lmb->memory.region[0].size, ram_size);
+ ut_asserteq(mem_lst->count, 1);
+ ut_asserteq(mem[0].base, ram_base);
+ ut_asserteq(mem[0].size, ram_size);
}
- ut_asserteq(lmb->reserved.cnt, num_reserved);
+ ut_asserteq(used_lst->count, num_reserved);
if (num_reserved > 0) {
- ut_asserteq(lmb->reserved.region[0].base, base1);
- ut_asserteq(lmb->reserved.region[0].size, size1);
+ ut_asserteq(used[0].base, base1);
+ ut_asserteq(used[0].size, size1);
}
if (num_reserved > 1) {
- ut_asserteq(lmb->reserved.region[1].base, base2);
- ut_asserteq(lmb->reserved.region[1].size, size2);
+ ut_asserteq(used[1].base, base2);
+ ut_asserteq(used[1].size, size2);
}
if (num_reserved > 2) {
- ut_asserteq(lmb->reserved.region[2].base, base3);
- ut_asserteq(lmb->reserved.region[2].size, size3);
+ ut_asserteq(used[2].base, base3);
+ ut_asserteq(used[2].size, size3);
}
return 0;
}
-#define ASSERT_LMB(lmb, ram_base, ram_size, num_reserved, base1, size1, \
+#define ASSERT_LMB(mem_lst, used_lst, ram_base, ram_size, num_reserved, base1, size1, \
base2, size2, base3, size3) \
- ut_assert(!check_lmb(uts, lmb, ram_base, ram_size, \
+ ut_assert(!check_lmb(uts, mem_lst, used_lst, ram_base, ram_size, \
num_reserved, base1, size1, base2, size2, base3, \
size3))
-/*
- * Test helper function that reserves 64 KiB somewhere in the simulated RAM and
- * then does some alloc + free tests.
- */
+static int setup_lmb_test(struct unit_test_state *uts, struct lmb *store,
+ struct alist **mem_lstp, struct alist **used_lstp)
+{
+ struct lmb *lmb;
+
+ ut_assertok(lmb_push(store));
+ lmb = lmb_get();
+ *mem_lstp = &lmb->available_mem;
+ *used_lstp = &lmb->used_mem;
+
+ return 0;
+}
+
static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram,
const phys_size_t ram_size, const phys_addr_t ram0,
const phys_size_t ram0_size,
@@ -65,9 +79,11 @@ static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram,
const phys_addr_t ram_end = ram + ram_size;
const phys_addr_t alloc_64k_end = alloc_64k_addr + 0x10000;
- struct lmb lmb;
long ret;
+ struct alist *mem_lst, *used_lst;
+ struct lmb_region *mem, *used;
phys_addr_t a, a2, b, b2, c, d;
+ struct lmb store;
/* check for overflow */
ut_assert(ram_end == 0 || ram_end > ram);
@@ -76,106 +92,110 @@ static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram,
ut_assert(alloc_64k_addr >= ram + 8);
ut_assert(alloc_64k_end <= ram_end - 8);
- lmb_init(&lmb);
+ ut_assertok(setup_lmb_test(uts, &store, &mem_lst, &used_lst));
+ mem = mem_lst->data;
+ used = used_lst->data;
if (ram0_size) {
- ret = lmb_add(&lmb, ram0, ram0_size);
+ ret = lmb_add(ram0, ram0_size);
ut_asserteq(ret, 0);
}
- ret = lmb_add(&lmb, ram, ram_size);
+ ret = lmb_add(ram, ram_size);
ut_asserteq(ret, 0);
if (ram0_size) {
- ut_asserteq(lmb.memory.cnt, 2);
- ut_asserteq(lmb.memory.region[0].base, ram0);
- ut_asserteq(lmb.memory.region[0].size, ram0_size);
- ut_asserteq(lmb.memory.region[1].base, ram);
- ut_asserteq(lmb.memory.region[1].size, ram_size);
+ ut_asserteq(mem_lst->count, 2);
+ ut_asserteq(mem[0].base, ram0);
+ ut_asserteq(mem[0].size, ram0_size);
+ ut_asserteq(mem[1].base, ram);
+ ut_asserteq(mem[1].size, ram_size);
} else {
- ut_asserteq(lmb.memory.cnt, 1);
- ut_asserteq(lmb.memory.region[0].base, ram);
- ut_asserteq(lmb.memory.region[0].size, ram_size);
+ ut_asserteq(mem_lst->count, 1);
+ ut_asserteq(mem[0].base, ram);
+ ut_asserteq(mem[0].size, ram_size);
}
/* reserve 64KiB somewhere */
- ret = lmb_reserve(&lmb, alloc_64k_addr, 0x10000);
+ ret = lmb_reserve(alloc_64k_addr, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, 0, 0, 1, alloc_64k_addr, 0x10000,
+ ASSERT_LMB(mem_lst, used_lst, 0, 0, 1, alloc_64k_addr, 0x10000,
0, 0, 0, 0);
/* allocate somewhere, should be at the end of RAM */
- a = lmb_alloc(&lmb, 4, 1);
+ a = lmb_alloc(4, 1);
ut_asserteq(a, ram_end - 4);
- ASSERT_LMB(&lmb, 0, 0, 2, alloc_64k_addr, 0x10000,
+ ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, alloc_64k_addr, 0x10000,
ram_end - 4, 4, 0, 0);
/* alloc below end of reserved region -> below reserved region */
- b = lmb_alloc_base(&lmb, 4, 1, alloc_64k_end);
+ b = lmb_alloc_base(4, 1, alloc_64k_end, LMB_NONE);
ut_asserteq(b, alloc_64k_addr - 4);
- ASSERT_LMB(&lmb, 0, 0, 2,
+ ASSERT_LMB(mem_lst, used_lst, 0, 0, 2,
alloc_64k_addr - 4, 0x10000 + 4, ram_end - 4, 4, 0, 0);
/* 2nd time */
- c = lmb_alloc(&lmb, 4, 1);
+ c = lmb_alloc(4, 1);
ut_asserteq(c, ram_end - 8);
- ASSERT_LMB(&lmb, 0, 0, 2,
+ ASSERT_LMB(mem_lst, used_lst, 0, 0, 2,
alloc_64k_addr - 4, 0x10000 + 4, ram_end - 8, 8, 0, 0);
- d = lmb_alloc_base(&lmb, 4, 1, alloc_64k_end);
+ d = lmb_alloc_base(4, 1, alloc_64k_end, LMB_NONE);
ut_asserteq(d, alloc_64k_addr - 8);
- ASSERT_LMB(&lmb, 0, 0, 2,
+ ASSERT_LMB(mem_lst, used_lst, 0, 0, 2,
alloc_64k_addr - 8, 0x10000 + 8, ram_end - 8, 8, 0, 0);
- ret = lmb_free(&lmb, a, 4);
+ ret = lmb_free(a, 4);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, 0, 0, 2,
+ ASSERT_LMB(mem_lst, used_lst, 0, 0, 2,
alloc_64k_addr - 8, 0x10000 + 8, ram_end - 8, 4, 0, 0);
/* allocate again to ensure we get the same address */
- a2 = lmb_alloc(&lmb, 4, 1);
+ a2 = lmb_alloc(4, 1);
ut_asserteq(a, a2);
- ASSERT_LMB(&lmb, 0, 0, 2,
+ ASSERT_LMB(mem_lst, used_lst, 0, 0, 2,
alloc_64k_addr - 8, 0x10000 + 8, ram_end - 8, 8, 0, 0);
- ret = lmb_free(&lmb, a2, 4);
+ ret = lmb_free(a2, 4);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, 0, 0, 2,
+ ASSERT_LMB(mem_lst, used_lst, 0, 0, 2,
alloc_64k_addr - 8, 0x10000 + 8, ram_end - 8, 4, 0, 0);
- ret = lmb_free(&lmb, b, 4);
+ ret = lmb_free(b, 4);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, 0, 0, 3,
+ ASSERT_LMB(mem_lst, used_lst, 0, 0, 3,
alloc_64k_addr - 8, 4, alloc_64k_addr, 0x10000,
ram_end - 8, 4);
/* allocate again to ensure we get the same address */
- b2 = lmb_alloc_base(&lmb, 4, 1, alloc_64k_end);
+ b2 = lmb_alloc_base(4, 1, alloc_64k_end, LMB_NONE);
ut_asserteq(b, b2);
- ASSERT_LMB(&lmb, 0, 0, 2,
+ ASSERT_LMB(mem_lst, used_lst, 0, 0, 2,
alloc_64k_addr - 8, 0x10000 + 8, ram_end - 8, 4, 0, 0);
- ret = lmb_free(&lmb, b2, 4);
+ ret = lmb_free(b2, 4);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, 0, 0, 3,
+ ASSERT_LMB(mem_lst, used_lst, 0, 0, 3,
alloc_64k_addr - 8, 4, alloc_64k_addr, 0x10000,
ram_end - 8, 4);
- ret = lmb_free(&lmb, c, 4);
+ ret = lmb_free(c, 4);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, 0, 0, 2,
+ ASSERT_LMB(mem_lst, used_lst, 0, 0, 2,
alloc_64k_addr - 8, 4, alloc_64k_addr, 0x10000, 0, 0);
- ret = lmb_free(&lmb, d, 4);
+ ret = lmb_free(d, 4);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, 0, 0, 1, alloc_64k_addr, 0x10000,
+ ASSERT_LMB(mem_lst, used_lst, 0, 0, 1, alloc_64k_addr, 0x10000,
0, 0, 0, 0);
if (ram0_size) {
- ut_asserteq(lmb.memory.cnt, 2);
- ut_asserteq(lmb.memory.region[0].base, ram0);
- ut_asserteq(lmb.memory.region[0].size, ram0_size);
- ut_asserteq(lmb.memory.region[1].base, ram);
- ut_asserteq(lmb.memory.region[1].size, ram_size);
+ ut_asserteq(mem_lst->count, 2);
+ ut_asserteq(mem[0].base, ram0);
+ ut_asserteq(mem[0].size, ram0_size);
+ ut_asserteq(mem[1].base, ram);
+ ut_asserteq(mem[1].size, ram_size);
} else {
- ut_asserteq(lmb.memory.cnt, 1);
- ut_asserteq(lmb.memory.region[0].base, ram);
- ut_asserteq(lmb.memory.region[0].size, ram_size);
+ ut_asserteq(mem_lst->count, 1);
+ ut_asserteq(mem[0].base, ram);
+ ut_asserteq(mem[0].size, ram_size);
}
+ lmb_pop(&store);
+
return 0;
}
@@ -230,48 +250,51 @@ static int test_bigblock(struct unit_test_state *uts, const phys_addr_t ram)
const phys_size_t big_block_size = 0x10000000;
const phys_addr_t ram_end = ram + ram_size;
const phys_addr_t alloc_64k_addr = ram + 0x10000000;
- struct lmb lmb;
+ struct alist *mem_lst, *used_lst;
long ret;
phys_addr_t a, b;
+ struct lmb store;
/* check for overflow */
ut_assert(ram_end == 0 || ram_end > ram);
- lmb_init(&lmb);
+ ut_assertok(setup_lmb_test(uts, &store, &mem_lst, &used_lst));
- ret = lmb_add(&lmb, ram, ram_size);
+ ret = lmb_add(ram, ram_size);
ut_asserteq(ret, 0);
/* reserve 64KiB in the middle of RAM */
- ret = lmb_reserve(&lmb, alloc_64k_addr, 0x10000);
+ ret = lmb_reserve(alloc_64k_addr, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 1, alloc_64k_addr, 0x10000,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, alloc_64k_addr, 0x10000,
0, 0, 0, 0);
/* allocate a big block, should be below reserved */
- a = lmb_alloc(&lmb, big_block_size, 1);
+ a = lmb_alloc(big_block_size, 1);
ut_asserteq(a, ram);
- ASSERT_LMB(&lmb, ram, ram_size, 1, a,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, a,
big_block_size + 0x10000, 0, 0, 0, 0);
/* allocate 2nd big block */
/* This should fail, printing an error */
- b = lmb_alloc(&lmb, big_block_size, 1);
+ b = lmb_alloc(big_block_size, 1);
ut_asserteq(b, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 1, a,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, a,
big_block_size + 0x10000, 0, 0, 0, 0);
- ret = lmb_free(&lmb, a, big_block_size);
+ ret = lmb_free(a, big_block_size);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 1, alloc_64k_addr, 0x10000,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, alloc_64k_addr, 0x10000,
0, 0, 0, 0);
/* allocate too big block */
/* This should fail, printing an error */
- a = lmb_alloc(&lmb, ram_size, 1);
+ a = lmb_alloc(ram_size, 1);
ut_asserteq(a, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 1, alloc_64k_addr, 0x10000,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, alloc_64k_addr, 0x10000,
0, 0, 0, 0);
+ lmb_pop(&store);
+
return 0;
}
@@ -295,56 +318,62 @@ static int test_noreserved(struct unit_test_state *uts, const phys_addr_t ram,
{
const phys_size_t ram_size = 0x20000000;
const phys_addr_t ram_end = ram + ram_size;
- struct lmb lmb;
long ret;
phys_addr_t a, b;
+ struct lmb store;
+ struct alist *mem_lst, *used_lst;
const phys_addr_t alloc_size_aligned = (alloc_size + align - 1) &
~(align - 1);
/* check for overflow */
ut_assert(ram_end == 0 || ram_end > ram);
- lmb_init(&lmb);
+ ut_assertok(setup_lmb_test(uts, &store, &mem_lst, &used_lst));
- ret = lmb_add(&lmb, ram, ram_size);
+ ret = lmb_add(ram, ram_size);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 0, 0, 0, 0, 0, 0, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 0, 0, 0, 0, 0, 0, 0);
/* allocate a block */
- a = lmb_alloc(&lmb, alloc_size, align);
+ a = lmb_alloc(alloc_size, align);
ut_assert(a != 0);
- ASSERT_LMB(&lmb, ram, ram_size, 1, ram + ram_size - alloc_size_aligned,
- alloc_size, 0, 0, 0, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1,
+ ram + ram_size - alloc_size_aligned, alloc_size, 0, 0, 0, 0);
+
/* allocate another block */
- b = lmb_alloc(&lmb, alloc_size, align);
+ b = lmb_alloc(alloc_size, align);
ut_assert(b != 0);
if (alloc_size == alloc_size_aligned) {
- ASSERT_LMB(&lmb, ram, ram_size, 1, ram + ram_size -
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram + ram_size -
(alloc_size_aligned * 2), alloc_size * 2, 0, 0, 0,
0);
} else {
- ASSERT_LMB(&lmb, ram, ram_size, 2, ram + ram_size -
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram + ram_size -
(alloc_size_aligned * 2), alloc_size, ram + ram_size
- alloc_size_aligned, alloc_size, 0, 0);
}
/* and free them */
- ret = lmb_free(&lmb, b, alloc_size);
+ ret = lmb_free(b, alloc_size);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 1, ram + ram_size - alloc_size_aligned,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1,
+ ram + ram_size - alloc_size_aligned,
alloc_size, 0, 0, 0, 0);
- ret = lmb_free(&lmb, a, alloc_size);
+ ret = lmb_free(a, alloc_size);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 0, 0, 0, 0, 0, 0, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 0, 0, 0, 0, 0, 0, 0);
/* allocate a block with base*/
- b = lmb_alloc_base(&lmb, alloc_size, align, ram_end);
+ b = lmb_alloc_base(alloc_size, align, ram_end, LMB_NONE);
ut_assert(a == b);
- ASSERT_LMB(&lmb, ram, ram_size, 1, ram + ram_size - alloc_size_aligned,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1,
+ ram + ram_size - alloc_size_aligned,
alloc_size, 0, 0, 0, 0);
/* and free it */
- ret = lmb_free(&lmb, b, alloc_size);
+ ret = lmb_free(b, alloc_size);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 0, 0, 0, 0, 0, 0, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 0, 0, 0, 0, 0, 0, 0);
+
+ lmb_pop(&store);
return 0;
}
@@ -361,7 +390,6 @@ static int lib_test_lmb_noreserved(struct unit_test_state *uts)
/* simulate 512 MiB RAM beginning at 1.5GiB */
return test_noreserved(uts, 0xE0000000, 4, 1);
}
-
LIB_TEST(lib_test_lmb_noreserved, 0);
static int lib_test_lmb_unaligned_size(struct unit_test_state *uts)
@@ -386,36 +414,39 @@ static int lib_test_lmb_at_0(struct unit_test_state *uts)
{
const phys_addr_t ram = 0;
const phys_size_t ram_size = 0x20000000;
- struct lmb lmb;
+ struct lmb store;
+ struct alist *mem_lst, *used_lst;
long ret;
phys_addr_t a, b;
- lmb_init(&lmb);
+ ut_assertok(setup_lmb_test(uts, &store, &mem_lst, &used_lst));
- ret = lmb_add(&lmb, ram, ram_size);
+ ret = lmb_add(ram, ram_size);
ut_asserteq(ret, 0);
/* allocate nearly everything */
- a = lmb_alloc(&lmb, ram_size - 4, 1);
+ a = lmb_alloc(ram_size - 4, 1);
ut_asserteq(a, ram + 4);
- ASSERT_LMB(&lmb, ram, ram_size, 1, a, ram_size - 4,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, a, ram_size - 4,
0, 0, 0, 0);
/* allocate the rest */
/* This should fail as the allocated address would be 0 */
- b = lmb_alloc(&lmb, 4, 1);
+ b = lmb_alloc(4, 1);
ut_asserteq(b, 0);
/* check that this was an error by checking lmb */
- ASSERT_LMB(&lmb, ram, ram_size, 1, a, ram_size - 4,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, a, ram_size - 4,
0, 0, 0, 0);
/* check that this was an error by freeing b */
- ret = lmb_free(&lmb, b, 4);
+ ret = lmb_free(b, 4);
ut_asserteq(ret, -1);
- ASSERT_LMB(&lmb, ram, ram_size, 1, a, ram_size - 4,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, a, ram_size - 4,
0, 0, 0, 0);
- ret = lmb_free(&lmb, a, ram_size - 4);
+ ret = lmb_free(a, ram_size - 4);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 0, 0, 0, 0, 0, 0, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 0, 0, 0, 0, 0, 0, 0);
+
+ lmb_pop(&store);
return 0;
}
@@ -426,45 +457,85 @@ static int lib_test_lmb_overlapping_reserve(struct unit_test_state *uts)
{
const phys_addr_t ram = 0x40000000;
const phys_size_t ram_size = 0x20000000;
- struct lmb lmb;
+ struct lmb store;
+ struct alist *mem_lst, *used_lst;
long ret;
- lmb_init(&lmb);
+ ut_assertok(setup_lmb_test(uts, &store, &mem_lst, &used_lst));
- ret = lmb_add(&lmb, ram, ram_size);
+ ret = lmb_add(ram, ram_size);
ut_asserteq(ret, 0);
- ret = lmb_reserve(&lmb, 0x40010000, 0x10000);
+ ret = lmb_reserve(0x40010000, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x10000,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x10000,
0, 0, 0, 0);
- /* allocate overlapping region should fail */
- ret = lmb_reserve(&lmb, 0x40011000, 0x10000);
- ut_asserteq(ret, -1);
- ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x10000,
+
+ /* allocate overlapping region */
+ ret = lmb_reserve(0x40011000, 0x10000, LMB_NONE);
+ ut_asserteq(ret, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x11000,
0, 0, 0, 0);
- /* allocate 3nd region */
- ret = lmb_reserve(&lmb, 0x40030000, 0x10000);
+ /* allocate 2nd region */
+ ret = lmb_reserve(0x40030000, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 2, 0x40010000, 0x10000,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40010000, 0x11000,
0x40030000, 0x10000, 0, 0);
- /* allocate 2nd region , This should coalesced all region into one */
- ret = lmb_reserve(&lmb, 0x40020000, 0x10000);
+ /* allocate 3rd region , This should coalesce all regions into one */
+ ret = lmb_reserve(0x40020000, 0x10000, LMB_NONE);
ut_assert(ret >= 0);
- ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x30000,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x30000,
0, 0, 0, 0);
/* allocate 2nd region, which should be added as first region */
- ret = lmb_reserve(&lmb, 0x40000000, 0x8000);
+ ret = lmb_reserve(0x40000000, 0x8000, LMB_NONE);
ut_assert(ret >= 0);
- ASSERT_LMB(&lmb, ram, ram_size, 2, 0x40000000, 0x8000,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x8000,
0x40010000, 0x30000, 0, 0);
/* allocate 3rd region, coalesce with first and overlap with second */
- ret = lmb_reserve(&lmb, 0x40008000, 0x10000);
+ ret = lmb_reserve(0x40008000, 0x10000, LMB_NONE);
ut_assert(ret >= 0);
- ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40000000, 0x40000,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40000000, 0x40000,
0, 0, 0, 0);
+
+ /* try to allocate overlapping region with a different flag, should fail */
+ ret = lmb_reserve(0x40008000, 0x1000, LMB_NOOVERWRITE);
+ ut_asserteq(ret, -EEXIST);
+
+ /* allocate another region at 0x40050000 with a different flag */
+ ret = lmb_reserve(0x40050000, 0x10000, LMB_NOOVERWRITE);
+ ut_asserteq(ret, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x40000,
+ 0x40050000, 0x10000, 0, 0);
+
+ /*
+ * try to reserve a region adjacent to region 1 overlapping the 2nd region,
+ * should fail
+ */
+ ret = lmb_reserve(0x40040000, 0x20000, LMB_NONE);
+ ut_asserteq(ret, -EEXIST);
+
+ /*
+ * try to reserve a region between the two regions, but without an overlap,
+ * should succeed. this added region coalesces with the region 1
+ */
+ ret = lmb_reserve(0x40040000, 0x10000, LMB_NONE);
+ ut_asserteq(ret, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x50000,
+ 0x40050000, 0x10000, 0, 0);
+
+ /*
+ * try to reserve a region which overlaps with both the regions,
+ * should fail as the flags do not match
+ */
+ ret = lmb_reserve(0x40020000, 0x80000, LMB_NONE);
+ ut_asserteq(ret, -EEXIST);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x50000,
+ 0x40050000, 0x10000, 0, 0);
+
+ lmb_pop(&store);
+
return 0;
}
LIB_TEST(lib_test_lmb_overlapping_reserve, 0);
@@ -475,112 +546,208 @@ LIB_TEST(lib_test_lmb_overlapping_reserve, 0);
*/
static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram)
{
+ struct lmb store;
+ struct alist *mem_lst, *used_lst;
const phys_size_t ram_size = 0x20000000;
const phys_addr_t ram_end = ram + ram_size;
const phys_size_t alloc_addr_a = ram + 0x8000000;
const phys_size_t alloc_addr_b = ram + 0x8000000 * 2;
const phys_size_t alloc_addr_c = ram + 0x8000000 * 3;
- struct lmb lmb;
long ret;
phys_addr_t a, b, c, d, e;
/* check for overflow */
ut_assert(ram_end == 0 || ram_end > ram);
- lmb_init(&lmb);
+ ut_assertok(setup_lmb_test(uts, &store, &mem_lst, &used_lst));
+
+ ret = lmb_add(ram, ram_size);
+ ut_asserteq(ret, 0);
+
+ /* Try to allocate a page twice */
+ b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE);
+ ut_asserteq(b, 0);
+ b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NOOVERWRITE);
+ ut_asserteq(b, -1);
+ b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE);
+ ut_asserteq(b, 0);
+ b = lmb_alloc_addr(alloc_addr_a, 0x2000, LMB_NONE);
+ ut_asserteq(b, 0);
+ ret = lmb_free(alloc_addr_a, 0x2000);
+ ut_asserteq(ret, 0);
+ b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NOOVERWRITE);
+ ut_asserteq(b, 0);
+ b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE);
+ ut_asserteq(b, -1);
+ b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NOOVERWRITE);
+ ut_asserteq(b, -1);
+ ret = lmb_free(alloc_addr_a, 0x1000);
+ ut_asserteq(ret, 0);
+
+ /*
+ * Add two regions with different flags, region1 and region2 with
+ * a gap between them.
+ * Try adding another region, adjacent to region 1 and overlapping
+ * region 2. Should fail.
+ */
+ a = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE);
+ ut_asserteq(a, 0);
+
+ b = lmb_alloc_addr(alloc_addr_a + 0x4000, 0x1000, LMB_NOOVERWRITE);
+ ut_asserteq(b, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, alloc_addr_a, 0x1000,
+ alloc_addr_a + 0x4000, 0x1000, 0, 0);
+
+ c = lmb_alloc_addr(alloc_addr_a + 0x1000, 0x5000, LMB_NONE);
+ ut_asserteq(c, -1);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, alloc_addr_a, 0x1000,
+ alloc_addr_a + 0x4000, 0x1000, 0, 0);
- ret = lmb_add(&lmb, ram, ram_size);
+ ret = lmb_free(alloc_addr_a, 0x1000);
+ ut_asserteq(ret, 0);
+ ret = lmb_free(alloc_addr_a + 0x4000, 0x1000);
+ ut_asserteq(ret, 0);
+
+ /*
+ * Add two regions with same flags(LMB_NONE), region1 and region2
+ * with a gap between them.
+ * Try adding another region, adjacent to region 1 and overlapping
+ * region 2. Should succeed. All regions should coalesce into a
+ * single region.
+ */
+ a = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE);
+ ut_asserteq(a, 0);
+
+ b = lmb_alloc_addr(alloc_addr_a + 0x4000, 0x1000, LMB_NONE);
+ ut_asserteq(b, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, alloc_addr_a, 0x1000,
+ alloc_addr_a + 0x4000, 0x1000, 0, 0);
+
+ c = lmb_alloc_addr(alloc_addr_a + 0x1000, 0x5000, LMB_NONE);
+ ut_asserteq(c, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, alloc_addr_a, 0x6000,
+ 0, 0, 0, 0);
+
+ ret = lmb_free(alloc_addr_a, 0x6000);
+ ut_asserteq(ret, 0);
+
+ /*
+ * Add two regions with same flags(LMB_NOOVERWRITE), region1 and
+ * region2 with a gap between them.
+ * Try adding another region, adjacent to region 1 and overlapping
+ * region 2. Should fail.
+ */
+ a = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NOOVERWRITE);
+ ut_asserteq(a, 0);
+
+ b = lmb_alloc_addr(alloc_addr_a + 0x4000, 0x1000, LMB_NOOVERWRITE);
+ ut_asserteq(b, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, alloc_addr_a, 0x1000,
+ alloc_addr_a + 0x4000, 0x1000, 0, 0);
+
+ c = lmb_alloc_addr(alloc_addr_a + 0x1000, 0x5000, LMB_NOOVERWRITE);
+ ut_asserteq(c, -1);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, alloc_addr_a, 0x1000,
+ alloc_addr_a + 0x4000, 0x1000, 0, 0);
+
+ ret = lmb_free(alloc_addr_a, 0x1000);
+ ut_asserteq(ret, 0);
+ ret = lmb_free(alloc_addr_a + 0x4000, 0x1000);
ut_asserteq(ret, 0);
/* reserve 3 blocks */
- ret = lmb_reserve(&lmb, alloc_addr_a, 0x10000);
+ ret = lmb_reserve(alloc_addr_a, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
- ret = lmb_reserve(&lmb, alloc_addr_b, 0x10000);
+ ret = lmb_reserve(alloc_addr_b, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
- ret = lmb_reserve(&lmb, alloc_addr_c, 0x10000);
+ ret = lmb_reserve(alloc_addr_c, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 3, alloc_addr_a, 0x10000,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, alloc_addr_a, 0x10000,
alloc_addr_b, 0x10000, alloc_addr_c, 0x10000);
/* allocate blocks */
- a = lmb_alloc_addr(&lmb, ram, alloc_addr_a - ram);
- ut_asserteq(a, ram);
- ASSERT_LMB(&lmb, ram, ram_size, 3, ram, 0x8010000,
+ a = lmb_alloc_addr(ram, alloc_addr_a - ram, LMB_NONE);
+ ut_asserteq(a, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, ram, 0x8010000,
alloc_addr_b, 0x10000, alloc_addr_c, 0x10000);
- b = lmb_alloc_addr(&lmb, alloc_addr_a + 0x10000,
- alloc_addr_b - alloc_addr_a - 0x10000);
- ut_asserteq(b, alloc_addr_a + 0x10000);
- ASSERT_LMB(&lmb, ram, ram_size, 2, ram, 0x10010000,
+ b = lmb_alloc_addr(alloc_addr_a + 0x10000,
+ alloc_addr_b - alloc_addr_a - 0x10000, LMB_NONE);
+ ut_asserteq(b, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram, 0x10010000,
alloc_addr_c, 0x10000, 0, 0);
- c = lmb_alloc_addr(&lmb, alloc_addr_b + 0x10000,
- alloc_addr_c - alloc_addr_b - 0x10000);
- ut_asserteq(c, alloc_addr_b + 0x10000);
- ASSERT_LMB(&lmb, ram, ram_size, 1, ram, 0x18010000,
+ c = lmb_alloc_addr(alloc_addr_b + 0x10000,
+ alloc_addr_c - alloc_addr_b - 0x10000, LMB_NONE);
+ ut_asserteq(c, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000,
0, 0, 0, 0);
- d = lmb_alloc_addr(&lmb, alloc_addr_c + 0x10000,
- ram_end - alloc_addr_c - 0x10000);
- ut_asserteq(d, alloc_addr_c + 0x10000);
- ASSERT_LMB(&lmb, ram, ram_size, 1, ram, ram_size,
+ d = lmb_alloc_addr(alloc_addr_c + 0x10000,
+ ram_end - alloc_addr_c - 0x10000, LMB_NONE);
+ ut_asserteq(d, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, ram_size,
0, 0, 0, 0);
/* allocating anything else should fail */
- e = lmb_alloc(&lmb, 1, 1);
+ e = lmb_alloc(1, 1);
ut_asserteq(e, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 1, ram, ram_size,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, ram_size,
0, 0, 0, 0);
- ret = lmb_free(&lmb, d, ram_end - alloc_addr_c - 0x10000);
+ /* free thge allocation from d */
+ ret = lmb_free(alloc_addr_c + 0x10000, ram_end - alloc_addr_c - 0x10000);
ut_asserteq(ret, 0);
/* allocate at 3 points in free range */
- d = lmb_alloc_addr(&lmb, ram_end - 4, 4);
- ut_asserteq(d, ram_end - 4);
- ASSERT_LMB(&lmb, ram, ram_size, 2, ram, 0x18010000,
- d, 4, 0, 0);
- ret = lmb_free(&lmb, d, 4);
+ d = lmb_alloc_addr(ram_end - 4, 4, LMB_NONE);
+ ut_asserteq(d, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram, 0x18010000,
+ ram_end - 4, 4, 0, 0);
+ ret = lmb_free(ram_end - 4, 4);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 1, ram, 0x18010000,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000,
0, 0, 0, 0);
- d = lmb_alloc_addr(&lmb, ram_end - 128, 4);
- ut_asserteq(d, ram_end - 128);
- ASSERT_LMB(&lmb, ram, ram_size, 2, ram, 0x18010000,
- d, 4, 0, 0);
- ret = lmb_free(&lmb, d, 4);
+ d = lmb_alloc_addr(ram_end - 128, 4, LMB_NONE);
+ ut_asserteq(d, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram, 0x18010000,
+ ram_end - 128, 4, 0, 0);
+ ret = lmb_free(ram_end - 128, 4);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 1, ram, 0x18010000,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000,
0, 0, 0, 0);
- d = lmb_alloc_addr(&lmb, alloc_addr_c + 0x10000, 4);
- ut_asserteq(d, alloc_addr_c + 0x10000);
- ASSERT_LMB(&lmb, ram, ram_size, 1, ram, 0x18010004,
+ d = lmb_alloc_addr(alloc_addr_c + 0x10000, 4, LMB_NONE);
+ ut_asserteq(d, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010004,
0, 0, 0, 0);
- ret = lmb_free(&lmb, d, 4);
+ ret = lmb_free(alloc_addr_c + 0x10000, 4);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 1, ram, 0x18010000,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000,
0, 0, 0, 0);
- /* allocate at the bottom */
- ret = lmb_free(&lmb, a, alloc_addr_a - ram);
+ /* allocate at the bottom a was assigned to ram at the top */
+ ret = lmb_free(ram, alloc_addr_a - ram);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 1, ram + 0x8000000, 0x10010000,
- 0, 0, 0, 0);
- d = lmb_alloc_addr(&lmb, ram, 4);
- ut_asserteq(d, ram);
- ASSERT_LMB(&lmb, ram, ram_size, 2, d, 4,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram + 0x8000000,
+ 0x10010000, 0, 0, 0, 0);
+
+ d = lmb_alloc_addr(ram, 4, LMB_NONE);
+ ut_asserteq(d, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram, 4,
ram + 0x8000000, 0x10010000, 0, 0);
/* check that allocating outside memory fails */
if (ram_end != 0) {
- ret = lmb_alloc_addr(&lmb, ram_end, 1);
- ut_asserteq(ret, 0);
+ ret = lmb_alloc_addr(ram_end, 1, LMB_NONE);
+ ut_asserteq(ret, -1);
}
if (ram != 0) {
- ret = lmb_alloc_addr(&lmb, ram - 1, 1);
- ut_asserteq(ret, 0);
+ ret = lmb_alloc_addr(ram - 1, 1, LMB_NONE);
+ ut_asserteq(ret, -1);
}
+ lmb_pop(&store);
+
return 0;
}
@@ -602,55 +769,57 @@ LIB_TEST(lib_test_lmb_alloc_addr, 0);
static int test_get_unreserved_size(struct unit_test_state *uts,
const phys_addr_t ram)
{
+ struct lmb store;
+ struct alist *mem_lst, *used_lst;
const phys_size_t ram_size = 0x20000000;
const phys_addr_t ram_end = ram + ram_size;
const phys_size_t alloc_addr_a = ram + 0x8000000;
const phys_size_t alloc_addr_b = ram + 0x8000000 * 2;
const phys_size_t alloc_addr_c = ram + 0x8000000 * 3;
- struct lmb lmb;
long ret;
phys_size_t s;
/* check for overflow */
ut_assert(ram_end == 0 || ram_end > ram);
+ ut_assertok(setup_lmb_test(uts, &store, &mem_lst, &used_lst));
- lmb_init(&lmb);
-
- ret = lmb_add(&lmb, ram, ram_size);
+ ret = lmb_add(ram, ram_size);
ut_asserteq(ret, 0);
/* reserve 3 blocks */
- ret = lmb_reserve(&lmb, alloc_addr_a, 0x10000);
+ ret = lmb_reserve(alloc_addr_a, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
- ret = lmb_reserve(&lmb, alloc_addr_b, 0x10000);
+ ret = lmb_reserve(alloc_addr_b, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
- ret = lmb_reserve(&lmb, alloc_addr_c, 0x10000);
+ ret = lmb_reserve(alloc_addr_c, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 3, alloc_addr_a, 0x10000,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, alloc_addr_a, 0x10000,
alloc_addr_b, 0x10000, alloc_addr_c, 0x10000);
/* check addresses in between blocks */
- s = lmb_get_free_size(&lmb, ram);
+ s = lmb_get_free_size(ram);
ut_asserteq(s, alloc_addr_a - ram);
- s = lmb_get_free_size(&lmb, ram + 0x10000);
+ s = lmb_get_free_size(ram + 0x10000);
ut_asserteq(s, alloc_addr_a - ram - 0x10000);
- s = lmb_get_free_size(&lmb, alloc_addr_a - 4);
+ s = lmb_get_free_size(alloc_addr_a - 4);
ut_asserteq(s, 4);
- s = lmb_get_free_size(&lmb, alloc_addr_a + 0x10000);
+ s = lmb_get_free_size(alloc_addr_a + 0x10000);
ut_asserteq(s, alloc_addr_b - alloc_addr_a - 0x10000);
- s = lmb_get_free_size(&lmb, alloc_addr_a + 0x20000);
+ s = lmb_get_free_size(alloc_addr_a + 0x20000);
ut_asserteq(s, alloc_addr_b - alloc_addr_a - 0x20000);
- s = lmb_get_free_size(&lmb, alloc_addr_b - 4);
+ s = lmb_get_free_size(alloc_addr_b - 4);
ut_asserteq(s, 4);
- s = lmb_get_free_size(&lmb, alloc_addr_c + 0x10000);
+ s = lmb_get_free_size(alloc_addr_c + 0x10000);
ut_asserteq(s, ram_end - alloc_addr_c - 0x10000);
- s = lmb_get_free_size(&lmb, alloc_addr_c + 0x20000);
+ s = lmb_get_free_size(alloc_addr_c + 0x20000);
ut_asserteq(s, ram_end - alloc_addr_c - 0x20000);
- s = lmb_get_free_size(&lmb, ram_end - 4);
+ s = lmb_get_free_size(ram_end - 4);
ut_asserteq(s, 4);
+ lmb_pop(&store);
+
return 0;
}
@@ -668,158 +837,94 @@ static int lib_test_lmb_get_free_size(struct unit_test_state *uts)
}
LIB_TEST(lib_test_lmb_get_free_size, 0);
-#ifdef CONFIG_LMB_USE_MAX_REGIONS
-static int lib_test_lmb_max_regions(struct unit_test_state *uts)
-{
- const phys_addr_t ram = 0x00000000;
- /*
- * All of 32bit memory space will contain regions for this test, so
- * we need to scale ram_size (which in this case is the size of the lmb
- * region) to match.
- */
- const phys_size_t ram_size = ((0xFFFFFFFF >> CONFIG_LMB_MAX_REGIONS)
- + 1) * CONFIG_LMB_MAX_REGIONS;
- const phys_size_t blk_size = 0x10000;
- phys_addr_t offset;
- struct lmb lmb;
- int ret, i;
-
- lmb_init(&lmb);
-
- ut_asserteq(lmb.memory.cnt, 0);
- ut_asserteq(lmb.memory.max, CONFIG_LMB_MAX_REGIONS);
- ut_asserteq(lmb.reserved.cnt, 0);
- ut_asserteq(lmb.reserved.max, CONFIG_LMB_MAX_REGIONS);
-
- /* Add CONFIG_LMB_MAX_REGIONS memory regions */
- for (i = 0; i < CONFIG_LMB_MAX_REGIONS; i++) {
- offset = ram + 2 * i * ram_size;
- ret = lmb_add(&lmb, offset, ram_size);
- ut_asserteq(ret, 0);
- }
- ut_asserteq(lmb.memory.cnt, CONFIG_LMB_MAX_REGIONS);
- ut_asserteq(lmb.reserved.cnt, 0);
-
- /* error for the (CONFIG_LMB_MAX_REGIONS + 1) memory regions */
- offset = ram + 2 * (CONFIG_LMB_MAX_REGIONS + 1) * ram_size;
- ret = lmb_add(&lmb, offset, ram_size);
- ut_asserteq(ret, -1);
-
- ut_asserteq(lmb.memory.cnt, CONFIG_LMB_MAX_REGIONS);
- ut_asserteq(lmb.reserved.cnt, 0);
-
- /* reserve CONFIG_LMB_MAX_REGIONS regions */
- for (i = 0; i < CONFIG_LMB_MAX_REGIONS; i++) {
- offset = ram + 2 * i * blk_size;
- ret = lmb_reserve(&lmb, offset, blk_size);
- ut_asserteq(ret, 0);
- }
-
- ut_asserteq(lmb.memory.cnt, CONFIG_LMB_MAX_REGIONS);
- ut_asserteq(lmb.reserved.cnt, CONFIG_LMB_MAX_REGIONS);
-
- /* error for the 9th reserved blocks */
- offset = ram + 2 * (CONFIG_LMB_MAX_REGIONS + 1) * blk_size;
- ret = lmb_reserve(&lmb, offset, blk_size);
- ut_asserteq(ret, -1);
-
- ut_asserteq(lmb.memory.cnt, CONFIG_LMB_MAX_REGIONS);
- ut_asserteq(lmb.reserved.cnt, CONFIG_LMB_MAX_REGIONS);
-
- /* check each regions */
- for (i = 0; i < CONFIG_LMB_MAX_REGIONS; i++)
- ut_asserteq(lmb.memory.region[i].base, ram + 2 * i * ram_size);
-
- for (i = 0; i < CONFIG_LMB_MAX_REGIONS; i++)
- ut_asserteq(lmb.reserved.region[i].base, ram + 2 * i * blk_size);
-
- return 0;
-}
-LIB_TEST(lib_test_lmb_max_regions, 0);
-#endif
-
static int lib_test_lmb_flags(struct unit_test_state *uts)
{
+ struct lmb store;
+ struct lmb_region *mem, *used;
+ struct alist *mem_lst, *used_lst;
const phys_addr_t ram = 0x40000000;
const phys_size_t ram_size = 0x20000000;
- struct lmb lmb;
long ret;
- lmb_init(&lmb);
+ ut_assertok(setup_lmb_test(uts, &store, &mem_lst, &used_lst));
+ mem = mem_lst->data;
+ used = used_lst->data;
- ret = lmb_add(&lmb, ram, ram_size);
+ ret = lmb_add(ram, ram_size);
ut_asserteq(ret, 0);
/* reserve, same flag */
- ret = lmb_reserve_flags(&lmb, 0x40010000, 0x10000, LMB_NOMAP);
+ ret = lmb_reserve(0x40010000, 0x10000, LMB_NOMAP);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x10000,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x10000,
0, 0, 0, 0);
/* reserve again, same flag */
- ret = lmb_reserve_flags(&lmb, 0x40010000, 0x10000, LMB_NOMAP);
- ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x10000,
+ ret = lmb_reserve(0x40010000, 0x10000, LMB_NOMAP);
+ ut_asserteq(ret, -EEXIST);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x10000,
0, 0, 0, 0);
/* reserve again, new flag */
- ret = lmb_reserve_flags(&lmb, 0x40010000, 0x10000, LMB_NONE);
- ut_asserteq(ret, -1);
- ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x10000,
+ ret = lmb_reserve(0x40010000, 0x10000, LMB_NONE);
+ ut_asserteq(ret, -EEXIST);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x10000,
0, 0, 0, 0);
- ut_asserteq(lmb_is_nomap(&lmb.reserved.region[0]), 1);
+ ut_asserteq(lmb_is_nomap(&used[0]), 1);
/* merge after */
- ret = lmb_reserve_flags(&lmb, 0x40020000, 0x10000, LMB_NOMAP);
- ut_asserteq(ret, 1);
- ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x20000,
+ ret = lmb_reserve(0x40020000, 0x10000, LMB_NOMAP);
+ ut_asserteq(ret, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x20000,
0, 0, 0, 0);
/* merge before */
- ret = lmb_reserve_flags(&lmb, 0x40000000, 0x10000, LMB_NOMAP);
- ut_asserteq(ret, 1);
- ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40000000, 0x30000,
+ ret = lmb_reserve(0x40000000, 0x10000, LMB_NOMAP);
+ ut_asserteq(ret, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40000000, 0x30000,
0, 0, 0, 0);
- ut_asserteq(lmb_is_nomap(&lmb.reserved.region[0]), 1);
+ ut_asserteq(lmb_is_nomap(&used[0]), 1);
- ret = lmb_reserve_flags(&lmb, 0x40030000, 0x10000, LMB_NONE);
+ ret = lmb_reserve(0x40030000, 0x10000, LMB_NONE);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 2, 0x40000000, 0x30000,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x30000,
0x40030000, 0x10000, 0, 0);
- ut_asserteq(lmb_is_nomap(&lmb.reserved.region[0]), 1);
- ut_asserteq(lmb_is_nomap(&lmb.reserved.region[1]), 0);
+ ut_asserteq(lmb_is_nomap(&used[0]), 1);
+ ut_asserteq(lmb_is_nomap(&used[1]), 0);
/* test that old API use LMB_NONE */
- ret = lmb_reserve(&lmb, 0x40040000, 0x10000);
- ut_asserteq(ret, 1);
- ASSERT_LMB(&lmb, ram, ram_size, 2, 0x40000000, 0x30000,
+ ret = lmb_reserve(0x40040000, 0x10000, LMB_NONE);
+ ut_asserteq(ret, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x30000,
0x40030000, 0x20000, 0, 0);
- ut_asserteq(lmb_is_nomap(&lmb.reserved.region[0]), 1);
- ut_asserteq(lmb_is_nomap(&lmb.reserved.region[1]), 0);
+ ut_asserteq(lmb_is_nomap(&used[0]), 1);
+ ut_asserteq(lmb_is_nomap(&used[1]), 0);
- ret = lmb_reserve_flags(&lmb, 0x40070000, 0x10000, LMB_NOMAP);
+ ret = lmb_reserve(0x40070000, 0x10000, LMB_NOMAP);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 3, 0x40000000, 0x30000,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, 0x40000000, 0x30000,
0x40030000, 0x20000, 0x40070000, 0x10000);
- ret = lmb_reserve_flags(&lmb, 0x40050000, 0x10000, LMB_NOMAP);
+ ret = lmb_reserve(0x40050000, 0x10000, LMB_NOMAP);
ut_asserteq(ret, 0);
- ASSERT_LMB(&lmb, ram, ram_size, 4, 0x40000000, 0x30000,
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 4, 0x40000000, 0x30000,
0x40030000, 0x20000, 0x40050000, 0x10000);
/* merge with 2 adjacent regions */
- ret = lmb_reserve_flags(&lmb, 0x40060000, 0x10000, LMB_NOMAP);
- ut_asserteq(ret, 2);
- ASSERT_LMB(&lmb, ram, ram_size, 3, 0x40000000, 0x30000,
+ ret = lmb_reserve(0x40060000, 0x10000, LMB_NOMAP);
+ ut_asserteq(ret, 0);
+ ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, 0x40000000, 0x30000,
0x40030000, 0x20000, 0x40050000, 0x30000);
- ut_asserteq(lmb_is_nomap(&lmb.reserved.region[0]), 1);
- ut_asserteq(lmb_is_nomap(&lmb.reserved.region[1]), 0);
- ut_asserteq(lmb_is_nomap(&lmb.reserved.region[2]), 1);
+ ut_asserteq(lmb_is_nomap(&used[0]), 1);
+ ut_asserteq(lmb_is_nomap(&used[1]), 0);
+ ut_asserteq(lmb_is_nomap(&used[2]), 1);
+
+ lmb_pop(&store);
return 0;
}
diff --git a/test/lib/longjmp.c b/test/lib/longjmp.c
index 201367a5a3a..74c3465b8c2 100644
--- a/test/lib/longjmp.c
+++ b/test/lib/longjmp.c
@@ -5,11 +5,10 @@
* Copyright (c) 2021, Heinrich Schuchardt <xypron.glpk@gmx.de>
*/
-#include <common.h>
+#include <setjmp.h>
#include <test/lib.h>
#include <test/test.h>
#include <test/ut.h>
-#include <asm/setjmp.h>
struct test_jmp_buf {
jmp_buf env;
diff --git a/test/lib/membuf.c b/test/lib/membuf.c
new file mode 100644
index 00000000000..3f268a422d5
--- /dev/null
+++ b/test/lib/membuf.c
@@ -0,0 +1,239 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2024 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <membuf.h>
+#include <os.h>
+#include <rand.h>
+#include <string.h>
+#include <test/lib.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+#define TEST_SIZE 16
+#define TEST_COUNT 10000
+
+static void membuf_zero(struct membuf *mb)
+{
+ memset(mb->start, '\0', mb->end - mb->start);
+}
+
+static int membuf_check(struct unit_test_state *uts, struct membuf *mb,
+ int value)
+{
+ /* head is out of range */
+ ut_assert(!(mb->head < mb->start || mb->head >= mb->end));
+
+ /* tail is out of range */
+ ut_assert(!(mb->tail < mb->start || mb->tail >= mb->end));
+
+ return 0;
+}
+
+/* write from 1 to test_size bytes, and check they come back OK */
+static int lib_test_membuf_one(struct unit_test_state *uts)
+{
+ char in[TEST_SIZE * 2], out[TEST_SIZE * 2];
+ struct membuf mb;
+ int size, ret, test_size, i;
+
+ ut_assertok(membuf_new(&mb, TEST_SIZE));
+
+ /* setup in test */
+ for (i = 0; i < TEST_SIZE; i++) {
+ in[i] = (i & 63) + '0';
+ in[i + TEST_SIZE] = in[i];
+ }
+
+ test_size = TEST_SIZE;
+
+ for (i = 1; i < TEST_COUNT; i++) {
+ membuf_zero(&mb);
+ size = rand() % test_size;
+
+ // now write patterns and check they come back OK
+ ret = membuf_put(&mb, in, 0);
+ ret = membuf_put(&mb, in, size);
+ ut_asserteq(size, ret);
+
+ ret = membuf_put(&mb, in, 0);
+ ut_assertok(membuf_check(uts, &mb, i));
+
+ ret = membuf_get(&mb, out, 0);
+ ret = membuf_get(&mb, out, size);
+ ut_asserteq(size, ret);
+
+ ret = membuf_get(&mb, out, 0);
+ ut_assertok(membuf_check(uts, &mb, i));
+
+ ut_asserteq_mem(in, out, size);
+ }
+
+ return 0;
+}
+LIB_TEST(lib_test_membuf_one, 0);
+
+/* write random number of bytes, and check they come back OK */
+static int lib_test_membuf_random(struct unit_test_state *uts)
+{
+ char in[TEST_SIZE * 2];
+ char buf[TEST_SIZE * 2];
+ struct membuf mb;
+ int size, ret, test_size, i;
+ char *inptr, *outptr;
+ int max_avail, min_free;
+
+ ut_assertok(membuf_new(&mb, TEST_SIZE));
+
+ for (i = 0; i < TEST_SIZE; i++) {
+ in[i] = (i & 63) + '0';
+ in[i + TEST_SIZE] = in[i];
+ }
+
+ test_size = TEST_SIZE;
+
+ inptr = in;
+ outptr = in;
+ min_free = TEST_COUNT;
+ max_avail = 0;
+ membuf_zero(&mb);
+ for (i = 0; i < TEST_COUNT; i++) {
+ size = rand() % test_size;
+
+ if (membuf_free(&mb) < min_free)
+ min_free = membuf_free(&mb);
+
+ ret = membuf_put(&mb, inptr, size);
+ ut_assertok(membuf_check(uts, &mb, i));
+ inptr += ret;
+ if (inptr >= in + TEST_SIZE)
+ inptr -= TEST_SIZE;
+
+ size = rand() % (test_size - 1);
+
+ if (membuf_avail(&mb) > max_avail)
+ max_avail = membuf_avail(&mb);
+
+ ret = membuf_get(&mb, buf, size);
+ ut_assertok(membuf_check(uts, &mb, i));
+ ut_asserteq_mem(buf, outptr, ret);
+
+ outptr += ret;
+ if (outptr >= in + TEST_SIZE)
+ outptr -= TEST_SIZE;
+ }
+
+ return 0;
+}
+LIB_TEST(lib_test_membuf_random, 0);
+
+/* test membuf_extend() with split segments */
+static int lib_test_membuf_extend(struct unit_test_state *uts)
+{
+ char in[TEST_SIZE * 2];
+ char buf[TEST_SIZE * 2];
+ struct membuf mb;
+ int ret, test_size, i, cur;
+ char *data;
+
+ ut_assertok(membuf_new(&mb, TEST_SIZE));
+
+ for (i = 0; i < TEST_SIZE; i++) {
+ in[i] = (i & 63) + '0';
+ in[i + TEST_SIZE] = in[i];
+ }
+
+ test_size = TEST_SIZE - 1;
+
+ for (cur = 0; cur <= test_size; cur++) {
+ ut_assertok(membuf_new(&mb, TEST_SIZE));
+
+ membuf_zero(&mb);
+
+ /*
+ * add some bytes, then remove them - this will force the membuf
+ * to have data split into two segments when we fill it
+ */
+ ret = membuf_putraw(&mb, TEST_SIZE / 2, true, &data);
+ membuf_getraw(&mb, ret, true, &data);
+ ut_asserteq(TEST_SIZE / 2, ret);
+
+ /* fill it */
+ ret = membuf_put(&mb, in, cur);
+ ut_assertok(membuf_check(uts, &mb, cur));
+ ut_asserteq(cur, ret);
+
+ /* extend the buffer */
+ ut_assertok(membuf_extend_by(&mb, TEST_SIZE, -1));
+ ut_assertok(membuf_check(uts, &mb, cur));
+
+ /* check our data is still there */
+ ret = membuf_get(&mb, buf, TEST_SIZE * 2);
+ ut_assertok(membuf_check(uts, &mb, cur));
+ ut_asserteq(cur, ret);
+ ut_asserteq_mem(in, buf, cur);
+ membuf_uninit(&mb);
+ }
+
+ return 0;
+}
+LIB_TEST(lib_test_membuf_extend, 0);
+
+/* test membuf_readline() with generated data */
+static int lib_test_membuf_readline(struct unit_test_state *uts)
+{
+ char *buf;
+ int size, cur, i, ret, readptr, cmpptr;
+ struct membuf mb;
+ char *data;
+ char str[256];
+ char *s;
+
+ ut_assertok(membuf_new(&mb, 1024));
+ membuf_zero(&mb);
+
+ /* Use the README as test data */
+ ut_assertok(os_read_file("README", (void **)&buf, &size));
+
+ cur = 0;
+ readptr = 0;
+ cmpptr = 0;
+ for (i = 0; i < 100000; i++, cur += 1) {
+ /* fill the buffer with up to 'cur' bytes */
+ ret = membuf_putraw(&mb, cur, false, &data);
+
+ if (ret > 0) {
+ int can_read = min(ret, size - readptr);
+
+ memcpy(data, &buf[readptr], can_read);
+ readptr += can_read;
+
+ membuf_putraw(&mb, can_read, true, &data);
+ ut_assertok(membuf_check(uts, &mb, i));
+ }
+
+ /* read a line and compare */
+ ret = membuf_readline(&mb, str, 256, 0, true);
+ ut_assertok(membuf_check(uts, &mb, i));
+ if (ret) {
+ char *ptr;
+
+ s = &buf[cmpptr];
+ ptr = strchr(s, '\n');
+ *ptr = '\0';
+
+ ut_asserteq_str(s, str);
+ cmpptr += strlen(s) + 1;
+ *ptr = '\n';
+ } else {
+ ut_assert(membuf_free(&mb));
+ }
+ }
+ membuf_dispose(&mb);
+ os_free(buf);
+
+ return 0;
+}
+LIB_TEST(lib_test_membuf_readline, 0);
diff --git a/test/lib/rsa.c b/test/lib/rsa.c
index 44f8ade226f..129d03ab7dd 100644
--- a/test/lib/rsa.c
+++ b/test/lib/rsa.c
@@ -6,7 +6,6 @@
* Unit test for rsa_verify() function
*/
-#include <common.h>
#include <command.h>
#include <image.h>
#include <test/lib.h>
@@ -159,7 +158,6 @@ static int lib_rsa_verify_valid(struct unit_test_state *uts)
return CMD_RET_SUCCESS;
}
-
LIB_TEST(lib_rsa_verify_valid, 0);
/**
@@ -201,6 +199,5 @@ static int lib_rsa_verify_invalid(struct unit_test_state *uts)
return CMD_RET_SUCCESS;
}
-
LIB_TEST(lib_rsa_verify_invalid, 0);
#endif /* RSA_VERIFY_WITH_PKEY */
diff --git a/test/lib/sscanf.c b/test/lib/sscanf.c
index 772e4b92042..3a2ec8ffa5f 100644
--- a/test/lib/sscanf.c
+++ b/test/lib/sscanf.c
@@ -9,7 +9,6 @@
* Unit tests for sscanf() function
*/
-#include <common.h>
#include <command.h>
#include <log.h>
#include <test/lib.h>
@@ -170,5 +169,4 @@ static int lib_sscanf(struct unit_test_state *uts)
return 0;
}
-
LIB_TEST(lib_sscanf, 0);
diff --git a/test/str_ut.c b/test/lib/str.c
index fa9328ede50..48351abc756 100644
--- a/test/str_ut.c
+++ b/test/lib/str.c
@@ -3,9 +3,8 @@
* Copyright 2020 Google LLC
*/
-#include <common.h>
#include <vsprintf.h>
-#include <test/suites.h>
+#include <test/lib.h>
#include <test/test.h>
#include <test/ut.h>
@@ -19,9 +18,8 @@ static const char str4[] = "1234567890123 I lost closer friends";
static const char str5[] = "0x9876543210the last time I was deloused";
static const char str6[] = "0778octal is seldom used";
static const char str7[] = "707it is a piece of computing history";
-
-/* Declare a new str test */
-#define STR_TEST(_name, _flags) UNIT_TEST(_name, _flags, str_test)
+static const char str8[] = "0x887e2561352d80fa";
+static const char str9[] = "614FF7EAA63009DA";
static int str_upper(struct unit_test_state *uts)
{
@@ -59,7 +57,7 @@ static int str_upper(struct unit_test_state *uts)
return 0;
}
-STR_TEST(str_upper, 0);
+LIB_TEST(str_upper, 0);
static int run_strtoul(struct unit_test_state *uts, const char *str, int base,
ulong expect_val, int expect_endp_offset, bool upper)
@@ -113,7 +111,7 @@ static int str_simple_strtoul(struct unit_test_state *uts)
return 0;
}
-STR_TEST(str_simple_strtoul, 0);
+LIB_TEST(str_simple_strtoul, 0);
static int run_strtoull(struct unit_test_state *uts, const char *str, int base,
unsigned long long expect_val, int expect_endp_offset,
@@ -176,7 +174,7 @@ static int str_simple_strtoull(struct unit_test_state *uts)
return 0;
}
-STR_TEST(str_simple_strtoull, 0);
+LIB_TEST(str_simple_strtoull, 0);
static int str_hextoul(struct unit_test_state *uts)
{
@@ -188,7 +186,23 @@ static int str_hextoul(struct unit_test_state *uts)
return 0;
}
-STR_TEST(str_hextoul, 0);
+LIB_TEST(str_hextoul, 0);
+
+static int str_hextoull(struct unit_test_state *uts)
+{
+ char *endp;
+
+ /* Just a simple test, since we know this uses simple_strtoull() */
+ ut_asserteq_64(0x887e2561352d80faULL, hextoull(str8, &endp));
+ ut_asserteq_64(0x12, endp - str8);
+ ut_asserteq_64(0x614ff7eaa63009daULL, hextoull(str9, &endp));
+ ut_asserteq_64(0x10, endp - str9);
+ ut_asserteq_64(0x887e2561352d80faULL, hextoull(str8, NULL));
+ ut_asserteq_64(0x614ff7eaa63009daULL, hextoull(str9, NULL));
+
+ return 0;
+}
+LIB_TEST(str_hextoull, 0);
static int str_dectoul(struct unit_test_state *uts)
{
@@ -200,7 +214,7 @@ static int str_dectoul(struct unit_test_state *uts)
return 0;
}
-STR_TEST(str_dectoul, 0);
+LIB_TEST(str_dectoul, 0);
static int str_itoa(struct unit_test_state *uts)
{
@@ -210,17 +224,17 @@ static int str_itoa(struct unit_test_state *uts)
ut_asserteq_str("4294967295", simple_itoa(0xffffffff));
/* Use #ifdef here to avoid a compiler warning on 32-bit machines */
-#ifdef CONFIG_PHYS_64BIT
+#ifdef CONFIG_64BIT
if (sizeof(ulong) == 8) {
ut_asserteq_str("9223372036854775807",
simple_itoa((1UL << 63) - 1));
ut_asserteq_str("18446744073709551615", simple_itoa(-1));
}
-#endif /* CONFIG_PHYS_64BIT */
+#endif /* CONFIG_64BIT */
return 0;
}
-STR_TEST(str_itoa, 0);
+LIB_TEST(str_itoa, 0);
static int str_xtoa(struct unit_test_state *uts)
{
@@ -230,17 +244,17 @@ static int str_xtoa(struct unit_test_state *uts)
ut_asserteq_str("ffffffff", simple_xtoa(0xffffffff));
/* Use #ifdef here to avoid a compiler warning on 32-bit machines */
-#ifdef CONFIG_PHYS_64BIT
+#ifdef CONFIG_64BIT
if (sizeof(ulong) == 8) {
ut_asserteq_str("7fffffffffffffff",
simple_xtoa((1UL << 63) - 1));
ut_asserteq_str("ffffffffffffffff", simple_xtoa(-1));
}
-#endif /* CONFIG_PHYS_64BIT */
+#endif /* CONFIG_64BIT */
return 0;
}
-STR_TEST(str_xtoa, 0);
+LIB_TEST(str_xtoa, 0);
static int str_trailing(struct unit_test_state *uts)
{
@@ -272,7 +286,7 @@ static int str_trailing(struct unit_test_state *uts)
return 0;
}
-STR_TEST(str_trailing, 0);
+LIB_TEST(str_trailing, 0);
static int test_str_to_list(struct unit_test_state *uts)
{
@@ -343,9 +357,7 @@ static int test_str_to_list(struct unit_test_state *uts)
ut_asserteq_str("space", ptr[3]);
ut_assertnonnull(ptr[4]);
ut_asserteq_str("", ptr[4]);
- ut_assertnonnull(ptr[5]);
- ut_asserteq_str("", ptr[5]);
- ut_assertnull(ptr[6]);
+ ut_assertnull(ptr[5]);
str_free_list(ptr);
ut_assertok(ut_check_delta(start));
@@ -354,12 +366,4 @@ static int test_str_to_list(struct unit_test_state *uts)
return 0;
}
-STR_TEST(test_str_to_list, 0);
-
-int do_ut_str(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(str_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(str_test);
-
- return cmd_ut_category("str", "str_", tests, n_ents, argc, argv);
-}
+LIB_TEST(test_str_to_list, 0);
diff --git a/test/lib/string.c b/test/lib/string.c
index 5dcf4d6db00..f56c2e4c946 100644
--- a/test/lib/string.c
+++ b/test/lib/string.c
@@ -9,9 +9,9 @@
* This has to be considered in testing.
*/
-#include <common.h>
#include <command.h>
#include <log.h>
+#include <string.h>
#include <test/lib.h>
#include <test/test.h>
#include <test/ut.h>
@@ -94,7 +94,6 @@ static int lib_memset(struct unit_test_state *uts)
}
return 0;
}
-
LIB_TEST(lib_memset, 0);
/**
@@ -158,7 +157,6 @@ static int lib_memcpy(struct unit_test_state *uts)
}
return 0;
}
-
LIB_TEST(lib_memcpy, 0);
/**
@@ -193,7 +191,6 @@ static int lib_memmove(struct unit_test_state *uts)
}
return 0;
}
-
LIB_TEST(lib_memmove, 0);
/** lib_memdup() - unit test for memdup() */
@@ -225,3 +222,79 @@ static int lib_memdup(struct unit_test_state *uts)
return 0;
}
LIB_TEST(lib_memdup, 0);
+
+/** lib_strnstr() - unit test for strnstr() */
+static int lib_strnstr(struct unit_test_state *uts)
+{
+ const char *s1 = "Itsy Bitsy Teenie Weenie";
+ const char *s2 = "eenie";
+ const char *s3 = "eery";
+
+ ut_asserteq_ptr(&s1[12], strnstr(s1, s2, SIZE_MAX));
+ ut_asserteq_ptr(&s1[12], strnstr(s1, s2, 17));
+ ut_assertnull(strnstr(s1, s2, 16));
+ ut_assertnull(strnstr(s1, s2, 0));
+ ut_asserteq_ptr(&s1[13], strnstr(&s1[3], &s2[1], SIZE_MAX));
+ ut_asserteq_ptr(&s1[13], strnstr(&s1[3], &s2[1], 14));
+ ut_assertnull(strnstr(&s1[3], &s2[1], 13));
+ ut_assertnull(strnstr(&s1[3], &s2[1], 0));
+ ut_assertnull(strnstr(s1, s3, SIZE_MAX));
+ ut_assertnull(strnstr(s1, s3, 0));
+
+ return 0;
+}
+LIB_TEST(lib_strnstr, 0);
+
+/** lib_strstr() - unit test for strstr() */
+static int lib_strstr(struct unit_test_state *uts)
+{
+ const char *s1 = "Itsy Bitsy Teenie Weenie";
+ const char *s2 = "eenie";
+ const char *s3 = "easy";
+
+ ut_asserteq_ptr(&s1[12], strstr(s1, s2));
+ ut_asserteq_ptr(&s1[13], strstr(&s1[3], &s2[1]));
+ ut_assertnull(strstr(s1, s3));
+ ut_asserteq_ptr(&s1[2], strstr(s1, &s3[2]));
+ ut_asserteq_ptr(&s1[8], strstr(&s1[5], &s3[2]));
+
+ return 0;
+}
+LIB_TEST(lib_strstr, 0);
+
+static int lib_strim(struct unit_test_state *uts)
+{
+ char buf[BUFLEN], *p;
+
+ strcpy(buf, "abc");
+ ut_asserteq_str("abc", strim(buf));
+
+ /* leading space */
+ strcpy(buf, " abc");
+ ut_asserteq_str("abc", strim(buf));
+
+ /* multiple leading spaces */
+ strcpy(buf, " abc");
+ ut_asserteq_str("abc", strim(buf));
+
+ /* multiple internal spaces */
+ strcpy(buf, " a bc");
+ ut_asserteq_str("a bc", strim(buf));
+
+ /* with trailing space */
+ strcpy(buf, " a bc ");
+ ut_asserteq_str("a bc", strim(buf));
+
+ /* with multiple trailing spaces */
+ strcpy(buf, " a bc ");
+ ut_asserteq_str("a bc", strim(buf));
+
+ /* with only spaces */
+ strcpy(buf, " ");
+ p = strim(buf);
+ ut_asserteq_ptr(p, buf);
+ ut_asserteq_str("", p);
+
+ return 0;
+}
+LIB_TEST(lib_strim, 0);
diff --git a/test/lib/strlcat.c b/test/lib/strlcat.c
index d8453fe78e2..d1a0293271b 100644
--- a/test/lib/strlcat.c
+++ b/test/lib/strlcat.c
@@ -6,7 +6,6 @@
* These tests adapted from glibc's string/test-strncat.c
*/
-#include <common.h>
#include <test/lib.h>
#include <test/test.h>
#include <test/ut.h>
diff --git a/test/lib/test_aes.c b/test/lib/test_aes.c
index cbc712f7eda..6d9068c4f79 100644
--- a/test/lib/test_aes.c
+++ b/test/lib/test_aes.c
@@ -5,7 +5,6 @@
* Unit tests for aes functions
*/
-#include <common.h>
#include <command.h>
#include <hexdump.h>
#include <rand.h>
@@ -164,5 +163,4 @@ static int lib_test_aes(struct unit_test_state *uts)
return ret;
}
-
LIB_TEST(lib_test_aes, 0);
diff --git a/test/lib/test_crc8.c b/test/lib/test_crc8.c
index 0dac97bc5bf..52be2dc06c4 100644
--- a/test/lib/test_crc8.c
+++ b/test/lib/test_crc8.c
@@ -25,5 +25,4 @@ static int lib_crc8(struct unit_test_state *uts) {
return 0;
}
-
LIB_TEST(lib_crc8, 0);
diff --git a/test/lib/test_crypt.c b/test/lib/test_crypt.c
index fb21edf9748..b6dd5f07b86 100644
--- a/test/lib/test_crypt.c
+++ b/test/lib/test_crypt.c
@@ -5,7 +5,6 @@
* Unit test for crypt-style password hashing
*/
-#include <common.h>
#include <test/lib.h>
#include <test/test.h>
#include <test/ut.h>
@@ -60,5 +59,4 @@ static int lib_crypt(struct unit_test_state *uts)
return CMD_RET_SUCCESS;
}
-
LIB_TEST(lib_crypt, 0);
diff --git a/test/lib/test_errno_str.c b/test/lib/test_errno_str.c
index 8a9f1fd9805..967ecfd56f1 100644
--- a/test/lib/test_errno_str.c
+++ b/test/lib/test_errno_str.c
@@ -9,7 +9,6 @@
* This has to be considered in testing.
*/
-#include <common.h>
#include <command.h>
#include <errno.h>
#include <test/lib.h>
@@ -42,5 +41,4 @@ static int lib_errno_str(struct unit_test_state *uts)
return 0;
}
-
LIB_TEST(lib_errno_str, 0);
diff --git a/test/lib/test_print.c b/test/lib/test_print.c
index 79b67c77932..cd7f3f85769 100644
--- a/test/lib/test_print.c
+++ b/test/lib/test_print.c
@@ -5,7 +5,6 @@
* Copyright 2020, Heinrich Schuchadt <xypron.glpk@gmx.de>
*/
-#include <common.h>
#include <command.h>
#include <display_options.h>
#include <asm/global_data.h>
@@ -18,13 +17,10 @@ DECLARE_GLOBAL_DATA_PTR;
static int test_print_freq(struct unit_test_state *uts,
uint64_t freq, char *expected)
{
- ut_silence_console(uts);
- console_record_reset_enable();
print_freq(freq, ";\n");
- ut_unsilence_console(uts);
console_record_readline(uts->actual_str, sizeof(uts->actual_str));
ut_asserteq_str(expected, uts->actual_str);
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
@@ -42,19 +38,15 @@ static int lib_test_print_freq(struct unit_test_state *uts)
ut_assertok(test_print_freq(uts, 54321987654321, "54321.99 GHz;"));
return 0;
}
-
-LIB_TEST(lib_test_print_freq, 0);
+LIB_TEST(lib_test_print_freq, UTF_CONSOLE);
static int test_print_size(struct unit_test_state *uts,
uint64_t freq, char *expected)
{
- ut_silence_console(uts);
- console_record_reset_enable();
print_size(freq, ";\n");
- ut_unsilence_console(uts);
console_record_readline(uts->actual_str, sizeof(uts->actual_str));
ut_asserteq_str(expected, uts->actual_str);
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
@@ -75,5 +67,4 @@ static int lib_test_print_size(struct unit_test_state *uts)
ut_assertok(test_print_size(uts, 54321987654321, "49.4 TiB;"));
return 0;
}
-
-LIB_TEST(lib_test_print_size, 0);
+LIB_TEST(lib_test_print_size, UTF_CONSOLE);
diff --git a/test/lib/test_sha256_hkdf.c b/test/lib/test_sha256_hkdf.c
new file mode 100644
index 00000000000..5277b44eba5
--- /dev/null
+++ b/test/lib/test_sha256_hkdf.c
@@ -0,0 +1,198 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2024 Philippe Reynes <philippe.reynes@softathome.com>
+ *
+ * Unit tests for sha256_hkdf functions
+ */
+
+#include <command.h>
+#include <test/lib.h>
+#include <test/test.h>
+#include <test/ut.h>
+#include <u-boot/sha256.h>
+
+struct test_sha256_hkdf_s {
+ const unsigned char *salt;
+ int saltlen;
+ const unsigned char *ikm;
+ int ikmlen;
+ const unsigned char *info;
+ int infolen;
+ const unsigned char *expected;
+ int expectedlen;
+};
+
+/*
+ * data comes from:
+ * https://www.rfc-editor.org/rfc/rfc5869
+ */
+static unsigned char salt_test1[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
+ 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c };
+
+static unsigned char ikm_test1[] = {
+ 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+ 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b
+};
+
+static unsigned char info_test1[] = {
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9
+};
+
+static unsigned char expected_test1[] = {
+ 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a,
+ 0x90, 0x43, 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a,
+ 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c,
+ 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf,
+ 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18,
+ 0x58, 0x65
+};
+
+static unsigned char salt_test2[] = {
+ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
+ 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
+ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
+ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+ 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
+};
+
+static unsigned char ikm_test2[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+};
+
+static unsigned char info_test2[] = {
+ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
+ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
+ 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
+ 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
+ 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
+ 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
+ 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
+};
+
+static unsigned char expected_test2[] = {
+ 0xb1, 0x1e, 0x39, 0x8d, 0xc8, 0x03, 0x27, 0xa1,
+ 0xc8, 0xe7, 0xf7, 0x8c, 0x59, 0x6a, 0x49, 0x34,
+ 0x4f, 0x01, 0x2e, 0xda, 0x2d, 0x4e, 0xfa, 0xd8,
+ 0xa0, 0x50, 0xcc, 0x4c, 0x19, 0xaf, 0xa9, 0x7c,
+ 0x59, 0x04, 0x5a, 0x99, 0xca, 0xc7, 0x82, 0x72,
+ 0x71, 0xcb, 0x41, 0xc6, 0x5e, 0x59, 0x0e, 0x09,
+ 0xda, 0x32, 0x75, 0x60, 0x0c, 0x2f, 0x09, 0xb8,
+ 0x36, 0x77, 0x93, 0xa9, 0xac, 0xa3, 0xdb, 0x71,
+ 0xcc, 0x30, 0xc5, 0x81, 0x79, 0xec, 0x3e, 0x87,
+ 0xc1, 0x4c, 0x01, 0xd5, 0xc1, 0xf3, 0x43, 0x4f,
+ 0x1d, 0x87,
+};
+
+static unsigned char salt_test3[] = {
+};
+
+static unsigned char ikm_test3[] = {
+ 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+ 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+ 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+};
+
+static unsigned char info_test3[] = {
+};
+
+static unsigned char expected_test3[] = {
+ 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f,
+ 0x71, 0x5f, 0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31,
+ 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1, 0x87, 0x9e,
+ 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d,
+ 0x9d, 0x20, 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a,
+ 0x96, 0xc8,
+};
+
+static struct test_sha256_hkdf_s test_sha256_hkdf[] = {
+ {
+ .salt = salt_test1,
+ .saltlen = sizeof(salt_test1),
+ .ikm = ikm_test1,
+ .ikmlen = sizeof(ikm_test1),
+ .info = info_test1,
+ .infolen = sizeof(info_test1),
+ .expected = expected_test1,
+ .expectedlen = sizeof(expected_test1),
+ },
+ {
+ .salt = salt_test2,
+ .saltlen = sizeof(salt_test2),
+ .ikm = ikm_test2,
+ .ikmlen = sizeof(ikm_test2),
+ .info = info_test2,
+ .infolen = sizeof(info_test2),
+ .expected = expected_test2,
+ .expectedlen = sizeof(expected_test2),
+ },
+ {
+ .salt = salt_test3,
+ .saltlen = sizeof(salt_test3),
+ .ikm = ikm_test3,
+ .ikmlen = sizeof(ikm_test3),
+ .info = info_test3,
+ .infolen = sizeof(info_test3),
+ .expected = expected_test3,
+ .expectedlen = sizeof(expected_test3),
+ },
+};
+
+static int _lib_test_sha256_hkdf_run(struct unit_test_state *uts,
+ const unsigned char *salt, int saltlen,
+ const unsigned char *ikm, int ikmlen,
+ const unsigned char *info, int infolen,
+ const unsigned char *expected,
+ int expectedlen)
+{
+ unsigned char output[256];
+ int ret;
+
+ ut_assert(expectedlen <= sizeof(output));
+ ret = sha256_hkdf(salt, saltlen, ikm, ikmlen, info, infolen, output, expectedlen);
+ ut_assert(!ret);
+ ut_asserteq_mem(expected, output, expectedlen);
+
+ return 0;
+}
+
+static int lib_test_sha256_hkdf_run(struct unit_test_state *uts,
+ struct test_sha256_hkdf_s *test)
+{
+ return _lib_test_sha256_hkdf_run(uts, test->salt, test->saltlen,
+ test->ikm, test->ikmlen,
+ test->info, test->infolen,
+ test->expected, test->expectedlen);
+}
+
+static int lib_test_sha256_hkdf(struct unit_test_state *uts)
+{
+ int i, ret = 0;
+
+ for (i = 0; i < ARRAY_SIZE(test_sha256_hkdf); i++) {
+ ret = lib_test_sha256_hkdf_run(uts, &test_sha256_hkdf[i]);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+LIB_TEST(lib_test_sha256_hkdf, 0);
diff --git a/test/lib/test_sha256_hmac.c b/test/lib/test_sha256_hmac.c
new file mode 100644
index 00000000000..5279dd78e0f
--- /dev/null
+++ b/test/lib/test_sha256_hmac.c
@@ -0,0 +1,294 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2024 Philippe Reynes <philippe.reynes@softathome.com>
+ *
+ * Unit tests for sha256_hmac functions
+ */
+
+#include <command.h>
+#include <test/lib.h>
+#include <test/test.h>
+#include <test/ut.h>
+#include <u-boot/sha256.h>
+
+struct test_sha256_hmac_s {
+ const unsigned char *key;
+ int keylen;
+ const unsigned char *input;
+ int ilen;
+ const unsigned char *expected;
+ int elen;
+};
+
+/*
+ * data comes from:
+ * https://datatracker.ietf.org/doc/html/rfc4231
+ */
+static unsigned char key_test1[] = {
+ 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+ 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
+
+static unsigned char input_test1[] = {
+ 0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65 };
+
+static unsigned char expected_test1[] = {
+ 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
+ 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
+ 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
+ 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7 };
+
+static unsigned char key_test2[] = { 0x4a, 0x65, 0x66, 0x65 };
+
+static unsigned char input_test2[] = {
+ 0x77, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20,
+ 0x79, 0x61, 0x20, 0x77, 0x61, 0x6e, 0x74, 0x20,
+ 0x66, 0x6f, 0x72, 0x20, 0x6e, 0x6f, 0x74, 0x68,
+ 0x69, 0x6e, 0x67, 0x3f };
+
+static unsigned char expected_test2[] = {
+ 0x5b, 0xdc, 0xc1, 0x46, 0xbf, 0x60, 0x75, 0x4e,
+ 0x6a, 0x04, 0x24, 0x26, 0x08, 0x95, 0x75, 0xc7,
+ 0x5a, 0x00, 0x3f, 0x08, 0x9d, 0x27, 0x39, 0x83,
+ 0x9d, 0xec, 0x58, 0xb9, 0x64, 0xec, 0x38, 0x43 };
+
+static unsigned char key_test3[] = {
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa };
+
+static unsigned char input_test3[] = {
+ 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
+ 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
+ 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
+ 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
+ 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
+ 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
+ 0xdd, 0xdd };
+
+static unsigned char expected_test3[] = {
+ 0x77, 0x3e, 0xa9, 0x1e, 0x36, 0x80, 0x0e, 0x46,
+ 0x85, 0x4d, 0xb8, 0xeb, 0xd0, 0x91, 0x81, 0xa7,
+ 0x29, 0x59, 0x09, 0x8b, 0x3e, 0xf8, 0xc1, 0x22,
+ 0xd9, 0x63, 0x55, 0x14, 0xce, 0xd5, 0x65, 0xfe };
+
+static unsigned char key_test4[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
+ 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
+ 0x19,
+};
+
+static unsigned char input_test4[] = {
+ 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
+ 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
+ 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
+ 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
+ 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
+ 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
+ 0xcd, 0xcd,
+};
+
+static unsigned char expected_test4[] = {
+ 0x82, 0x55, 0x8a, 0x38, 0x9a, 0x44, 0x3c, 0x0e,
+ 0xa4, 0xcc, 0x81, 0x98, 0x99, 0xf2, 0x08, 0x3a,
+ 0x85, 0xf0, 0xfa, 0xa3, 0xe5, 0x78, 0xf8, 0x07,
+ 0x7a, 0x2e, 0x3f, 0xf4, 0x67, 0x29, 0x66, 0x5b,
+};
+
+static unsigned char key_test5[] = {
+ 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
+ 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
+ 0x0c, 0x0c, 0x0c, 0x0c,
+};
+
+static unsigned char input_test5[] = {
+ 0x54, 0x65, 0x73, 0x74, 0x20, 0x57, 0x69, 0x74,
+ 0x68, 0x20, 0x54, 0x72, 0x75, 0x6e, 0x63, 0x61,
+ 0x74, 0x69, 0x6f, 0x6e,
+};
+
+static unsigned char expected_test5[] = {
+ 0xa3, 0xb6, 0x16, 0x74, 0x73, 0x10, 0x0e, 0xe0,
+ 0x6e, 0x0c, 0x79, 0x6c, 0x29, 0x55, 0x55, 0x2b,
+};
+
+static unsigned char key_test6[] = {
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa };
+
+static unsigned char input_test6[] = {
+ 0x54, 0x65, 0x73, 0x74, 0x20, 0x55, 0x73, 0x69,
+ 0x6e, 0x67, 0x20, 0x4c, 0x61, 0x72, 0x67, 0x65,
+ 0x72, 0x20, 0x54, 0x68, 0x61, 0x6e, 0x20, 0x42,
+ 0x6c, 0x6f, 0x63, 0x6b, 0x2d, 0x53, 0x69, 0x7a,
+ 0x65, 0x20, 0x4b, 0x65, 0x79, 0x20, 0x2d, 0x20,
+ 0x48, 0x61, 0x73, 0x68, 0x20, 0x4b, 0x65, 0x79,
+ 0x20, 0x46, 0x69, 0x72, 0x73, 0x74 };
+
+static unsigned char expected_test6[] = {
+ 0x60, 0xe4, 0x31, 0x59, 0x1e, 0xe0, 0xb6, 0x7f,
+ 0x0d, 0x8a, 0x26, 0xaa, 0xcb, 0xf5, 0xb7, 0x7f,
+ 0x8e, 0x0b, 0xc6, 0x21, 0x37, 0x28, 0xc5, 0x14,
+ 0x05, 0x46, 0x04, 0x0f, 0x0e, 0xe3, 0x7f, 0x54 };
+
+static unsigned char key_test7[] = {
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+ 0xaa, 0xaa, 0xaa,
+};
+
+static unsigned char input_test7[] = {
+ 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
+ 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x75,
+ 0x73, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x6c,
+ 0x61, 0x72, 0x67, 0x65, 0x72, 0x20, 0x74, 0x68,
+ 0x61, 0x6e, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b,
+ 0x2d, 0x73, 0x69, 0x7a, 0x65, 0x20, 0x6b, 0x65,
+ 0x79, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x61, 0x20,
+ 0x6c, 0x61, 0x72, 0x67, 0x65, 0x72, 0x20, 0x74,
+ 0x68, 0x61, 0x6e, 0x20, 0x62, 0x6c, 0x6f, 0x63,
+ 0x6b, 0x2d, 0x73, 0x69, 0x7a, 0x65, 0x20, 0x64,
+ 0x61, 0x74, 0x61, 0x2e, 0x20, 0x54, 0x68, 0x65,
+ 0x20, 0x6b, 0x65, 0x79, 0x20, 0x6e, 0x65, 0x65,
+ 0x64, 0x73, 0x20, 0x74, 0x6f, 0x20, 0x62, 0x65,
+ 0x20, 0x68, 0x61, 0x73, 0x68, 0x65, 0x64, 0x20,
+ 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x20, 0x62,
+ 0x65, 0x69, 0x6e, 0x67, 0x20, 0x75, 0x73, 0x65,
+ 0x64, 0x20, 0x62, 0x79, 0x20, 0x74, 0x68, 0x65,
+ 0x20, 0x48, 0x4d, 0x41, 0x43, 0x20, 0x61, 0x6c,
+ 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x2e,
+};
+
+static unsigned char expected_test7[] = {
+ 0x9b, 0x09, 0xff, 0xa7, 0x1b, 0x94, 0x2f, 0xcb,
+ 0x27, 0x63, 0x5f, 0xbc, 0xd5, 0xb0, 0xe9, 0x44,
+ 0xbf, 0xdc, 0x63, 0x64, 0x4f, 0x07, 0x13, 0x93,
+ 0x8a, 0x7f, 0x51, 0x53, 0x5c, 0x3a, 0x35, 0xe2,
+};
+
+static struct test_sha256_hmac_s test_sha256_hmac[] = {
+ {
+ .key = key_test1,
+ .keylen = sizeof(key_test1),
+ .input = input_test1,
+ .ilen = sizeof(input_test1),
+ .expected = expected_test1,
+ .elen = sizeof(expected_test1),
+ },
+ {
+ .key = key_test2,
+ .keylen = sizeof(key_test2),
+ .input = input_test2,
+ .ilen = sizeof(input_test2),
+ .expected = expected_test2,
+ .elen = sizeof(expected_test2),
+ },
+ {
+ .key = key_test3,
+ .keylen = sizeof(key_test3),
+ .input = input_test3,
+ .ilen = sizeof(input_test3),
+ .expected = expected_test3,
+ .elen = sizeof(expected_test3),
+ },
+ {
+ .key = key_test4,
+ .keylen = sizeof(key_test4),
+ .input = input_test4,
+ .ilen = sizeof(input_test4),
+ .expected = expected_test4,
+ .elen = sizeof(expected_test4),
+ },
+ {
+ .key = key_test5,
+ .keylen = sizeof(key_test5),
+ .input = input_test5,
+ .ilen = sizeof(input_test5),
+ .expected = expected_test5,
+ .elen = sizeof(expected_test5),
+ },
+ {
+ .key = key_test6,
+ .keylen = sizeof(key_test6),
+ .input = input_test6,
+ .ilen = sizeof(input_test6),
+ .expected = expected_test6,
+ .elen = sizeof(expected_test6),
+ },
+ {
+ .key = key_test7,
+ .keylen = sizeof(key_test7),
+ .input = input_test7,
+ .ilen = sizeof(input_test7),
+ .expected = expected_test7,
+ .elen = sizeof(expected_test7),
+ },
+};
+
+static int _lib_test_sha256_hmac_run(struct unit_test_state *uts,
+ const unsigned char *key, int keylen,
+ const unsigned char *input, int ilen,
+ const unsigned char *expected, int elen)
+{
+ unsigned char output[SHA256_SUM_LEN];
+ int ret;
+
+ ut_assert(elen <= sizeof(output));
+ ret = sha256_hmac(key, keylen, input, ilen, output);
+ ut_assert(!ret);
+ ut_asserteq_mem(expected, output, elen);
+
+ return 0;
+}
+
+static int lib_test_sha256_hmac_run(struct unit_test_state *uts,
+ struct test_sha256_hmac_s *test)
+{
+ return _lib_test_sha256_hmac_run(uts, test->key, test->keylen,
+ test->input, test->ilen,
+ test->expected, test->elen);
+}
+
+static int lib_test_sha256_hmac(struct unit_test_state *uts)
+{
+ int i, ret = 0;
+
+ for (i = 0; i < ARRAY_SIZE(test_sha256_hmac); i++) {
+ ret = lib_test_sha256_hmac_run(uts, &test_sha256_hmac[i]);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+LIB_TEST(lib_test_sha256_hmac, 0);
diff --git a/test/time_ut.c b/test/lib/time.c
index 80b82dbfd83..2095bef7589 100644
--- a/test/time_ut.c
+++ b/test/lib/time.c
@@ -4,13 +4,13 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
-#include <command.h>
#include <errno.h>
#include <time.h>
#include <linux/delay.h>
+#include <test/lib.h>
+#include <test/ut.h>
-static int test_get_timer(void)
+static int test_get_timer(struct unit_test_state *uts)
{
ulong base, start, next, diff;
int iter;
@@ -43,8 +43,9 @@ static int test_get_timer(void)
return 0;
}
+LIB_TEST(test_get_timer, 0);
-static int test_timer_get_us(void)
+static int test_timer_get_us(struct unit_test_state *uts)
{
ulong prev, next, min = 1000000;
long delta;
@@ -77,8 +78,9 @@ static int test_timer_get_us(void)
return 0;
}
+LIB_TEST(test_timer_get_us, 0);
-static int test_time_comparison(void)
+static int test_time_comparison(struct unit_test_state *uts)
{
ulong start_us, end_us, delta_us;
long error;
@@ -98,8 +100,9 @@ static int test_time_comparison(void)
return 0;
}
+LIB_TEST(test_time_comparison, 0);
-static int test_udelay(void)
+static int test_udelay(struct unit_test_state *uts)
{
long error;
ulong start, delta;
@@ -117,17 +120,4 @@ static int test_udelay(void)
return 0;
}
-
-int do_ut_time(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- int ret = 0;
-
- ret |= test_get_timer();
- ret |= test_timer_get_us();
- ret |= test_time_comparison();
- ret |= test_udelay();
-
- printf("Test %s\n", ret ? "failed" : "passed");
-
- return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
-}
+LIB_TEST(test_udelay, 0);
diff --git a/test/unicode_ut.c b/test/lib/unicode.c
index 47c3f52774c..673470c8d2c 100644
--- a/test/unicode_ut.c
+++ b/test/lib/unicode.c
@@ -5,20 +5,16 @@
* Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de>
*/
-#include <common.h>
#include <charset.h>
#include <command.h>
#include <efi_loader.h>
#include <errno.h>
#include <log.h>
#include <malloc.h>
+#include <test/lib.h>
#include <test/test.h>
-#include <test/suites.h>
#include <test/ut.h>
-/* Linker list entry for a Unicode test */
-#define UNICODE_TEST(_name) UNIT_TEST(_name, 0, unicode_test)
-
/* Constants c1-c4 and d1-d4 encode the same letters */
/* Six characters translating to one utf-8 byte each. */
@@ -65,7 +61,7 @@ static int unicode_test_u16_strlen(struct unit_test_state *uts)
ut_asserteq(6, u16_strlen(c4));
return 0;
}
-UNICODE_TEST(unicode_test_u16_strlen);
+LIB_TEST(unicode_test_u16_strlen, 0);
static int unicode_test_u16_strnlen(struct unit_test_state *uts)
{
@@ -76,7 +72,7 @@ static int unicode_test_u16_strnlen(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_u16_strnlen);
+LIB_TEST(unicode_test_u16_strnlen, 0);
static int unicode_test_u16_strdup(struct unit_test_state *uts)
{
@@ -88,7 +84,7 @@ static int unicode_test_u16_strdup(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_u16_strdup);
+LIB_TEST(unicode_test_u16_strdup, 0);
static int unicode_test_u16_strcpy(struct unit_test_state *uts)
{
@@ -101,7 +97,7 @@ static int unicode_test_u16_strcpy(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_u16_strcpy);
+LIB_TEST(unicode_test_u16_strcpy, 0);
/* U-Boot uses UTF-16 strings in the EFI context only. */
#if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD)
@@ -174,7 +170,7 @@ static int unicode_test_string16(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_string16);
+LIB_TEST(unicode_test_string16, 0);
#endif
static int unicode_test_utf8_get(struct unit_test_state *uts)
@@ -219,7 +215,7 @@ static int unicode_test_utf8_get(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_utf8_get);
+LIB_TEST(unicode_test_utf8_get, 0);
static int unicode_test_utf8_put(struct unit_test_state *uts)
{
@@ -257,7 +253,7 @@ static int unicode_test_utf8_put(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_utf8_put);
+LIB_TEST(unicode_test_utf8_put, 0);
static int unicode_test_utf8_utf16_strlen(struct unit_test_state *uts)
{
@@ -273,7 +269,7 @@ static int unicode_test_utf8_utf16_strlen(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_utf8_utf16_strlen);
+LIB_TEST(unicode_test_utf8_utf16_strlen, 0);
static int unicode_test_utf8_utf16_strnlen(struct unit_test_state *uts)
{
@@ -291,7 +287,7 @@ static int unicode_test_utf8_utf16_strnlen(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_utf8_utf16_strnlen);
+LIB_TEST(unicode_test_utf8_utf16_strnlen, 0);
/**
* ut_u16_strcmp() - Compare to u16 strings.
@@ -355,7 +351,7 @@ static int unicode_test_utf8_utf16_strcpy(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_utf8_utf16_strcpy);
+LIB_TEST(unicode_test_utf8_utf16_strcpy, 0);
static int unicode_test_utf8_utf16_strncpy(struct unit_test_state *uts)
{
@@ -399,7 +395,7 @@ static int unicode_test_utf8_utf16_strncpy(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_utf8_utf16_strncpy);
+LIB_TEST(unicode_test_utf8_utf16_strncpy, 0);
static int unicode_test_utf16_get(struct unit_test_state *uts)
{
@@ -425,7 +421,7 @@ static int unicode_test_utf16_get(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_utf16_get);
+LIB_TEST(unicode_test_utf16_get, 0);
static int unicode_test_utf16_put(struct unit_test_state *uts)
{
@@ -453,7 +449,7 @@ static int unicode_test_utf16_put(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_utf16_put);
+LIB_TEST(unicode_test_utf16_put, 0);
static int unicode_test_utf16_strnlen(struct unit_test_state *uts)
{
@@ -471,7 +467,7 @@ static int unicode_test_utf16_strnlen(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_utf16_strnlen);
+LIB_TEST(unicode_test_utf16_strnlen, 0);
static int unicode_test_utf16_utf8_strlen(struct unit_test_state *uts)
{
@@ -487,7 +483,7 @@ static int unicode_test_utf16_utf8_strlen(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_utf16_utf8_strlen);
+LIB_TEST(unicode_test_utf16_utf8_strlen, 0);
static int unicode_test_utf16_utf8_strnlen(struct unit_test_state *uts)
{
@@ -499,7 +495,7 @@ static int unicode_test_utf16_utf8_strnlen(struct unit_test_state *uts)
ut_asserteq(12, utf16_utf8_strnlen(c4, 3));
return 0;
}
-UNICODE_TEST(unicode_test_utf16_utf8_strnlen);
+LIB_TEST(unicode_test_utf16_utf8_strnlen, 0);
static int unicode_test_utf16_utf8_strcpy(struct unit_test_state *uts)
{
@@ -544,7 +540,7 @@ static int unicode_test_utf16_utf8_strcpy(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_utf16_utf8_strcpy);
+LIB_TEST(unicode_test_utf16_utf8_strcpy, 0);
static int unicode_test_utf16_utf8_strncpy(struct unit_test_state *uts)
{
@@ -588,7 +584,7 @@ static int unicode_test_utf16_utf8_strncpy(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_utf16_utf8_strncpy);
+LIB_TEST(unicode_test_utf16_utf8_strncpy, 0);
static int unicode_test_utf_to_lower(struct unit_test_state *uts)
{
@@ -605,7 +601,7 @@ static int unicode_test_utf_to_lower(struct unit_test_state *uts)
#endif
return 0;
}
-UNICODE_TEST(unicode_test_utf_to_lower);
+LIB_TEST(unicode_test_utf_to_lower, 0);
static int unicode_test_utf_to_upper(struct unit_test_state *uts)
{
@@ -622,7 +618,7 @@ static int unicode_test_utf_to_upper(struct unit_test_state *uts)
#endif
return 0;
}
-UNICODE_TEST(unicode_test_utf_to_upper);
+LIB_TEST(unicode_test_utf_to_upper, 0);
static int unicode_test_u16_strcasecmp(struct unit_test_state *uts)
{
@@ -647,7 +643,7 @@ static int unicode_test_u16_strcasecmp(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_u16_strcasecmp);
+LIB_TEST(unicode_test_u16_strcasecmp, 0);
static int unicode_test_u16_strncmp(struct unit_test_state *uts)
{
@@ -660,7 +656,7 @@ static int unicode_test_u16_strncmp(struct unit_test_state *uts)
ut_assert(u16_strcmp(u"deghi", u"abcdef") > 0);
return 0;
}
-UNICODE_TEST(unicode_test_u16_strncmp);
+LIB_TEST(unicode_test_u16_strncmp, 0);
static int unicode_test_u16_strsize(struct unit_test_state *uts)
{
@@ -670,7 +666,7 @@ static int unicode_test_u16_strsize(struct unit_test_state *uts)
ut_asserteq_64(u16_strsize(c4), 14);
return 0;
}
-UNICODE_TEST(unicode_test_u16_strsize);
+LIB_TEST(unicode_test_u16_strsize, 0);
static int unicode_test_utf_to_cp(struct unit_test_state *uts)
{
@@ -699,7 +695,7 @@ static int unicode_test_utf_to_cp(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_utf_to_cp);
+LIB_TEST(unicode_test_utf_to_cp, 0);
static void utf8_to_cp437_stream_helper(const char *in, char *out)
{
@@ -730,7 +726,7 @@ static int unicode_test_utf8_to_cp437_stream(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_utf8_to_cp437_stream);
+LIB_TEST(unicode_test_utf8_to_cp437_stream, 0);
static void utf8_to_utf32_stream_helper(const char *in, s32 *out)
{
@@ -779,7 +775,7 @@ static int unicode_test_utf8_to_utf32_stream(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_utf8_to_utf32_stream);
+LIB_TEST(unicode_test_utf8_to_utf32_stream, 0);
#ifdef CONFIG_EFI_LOADER
static int unicode_test_efi_create_indexed_name(struct unit_test_state *uts)
@@ -796,7 +792,7 @@ static int unicode_test_efi_create_indexed_name(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_efi_create_indexed_name);
+LIB_TEST(unicode_test_efi_create_indexed_name, 0);
#endif
static int unicode_test_u16_strlcat(struct unit_test_state *uts)
@@ -847,13 +843,4 @@ static int unicode_test_u16_strlcat(struct unit_test_state *uts)
return 0;
}
-UNICODE_TEST(unicode_test_u16_strlcat);
-
-int do_ut_unicode(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(unicode_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(unicode_test);
-
- return cmd_ut_category("Unicode", "unicode_test_",
- tests, n_ents, argc, argv);
-}
+LIB_TEST(unicode_test_u16_strlcat, 0);
diff --git a/test/lib/uthread.c b/test/lib/uthread.c
new file mode 100644
index 00000000000..10a94d1c560
--- /dev/null
+++ b/test/lib/uthread.c
@@ -0,0 +1,146 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2025 Linaro Limited
+ *
+ * Unit test for uthread
+ */
+
+#include <stdbool.h>
+#include <test/lib.h>
+#include <test/ut.h>
+#include <uthread.h>
+
+static int count;
+
+/* A thread entry point */
+static void worker(void *arg)
+{
+ int loops = (int)(unsigned long)arg;
+ int i;
+
+ for (i = 0; i < loops; i++) {
+ count++;
+ uthread_schedule();
+ }
+}
+
+/*
+ * uthread() - testing the uthread API
+ *
+ * This function creates two threads with the same entry point. The first one
+ * receives 5 as an argument, the second one receives 10. The number indicates
+ * the number of time the worker thread should loop on uthread_schedule()
+ * before returning. The workers increment a global counter each time they loop.
+ * As a result the main thread knows how many times it should call
+ * uthread_schedule() to let the two threads proceed, and it also knows which
+ * value the counter should have at any moment.
+ */
+static int uthread(struct unit_test_state *uts)
+{
+ int i;
+ int id1, id2;
+
+ count = 0;
+ id1 = uthread_grp_new_id();
+ ut_assert(id1 != 0);
+ id2 = uthread_grp_new_id();
+ ut_assert(id2 != 0);
+ ut_assert(id1 != id2);
+ ut_assertok(uthread_create(NULL, worker, (void *)5, 0, id1));
+ ut_assertok(uthread_create(NULL, worker, (void *)10, 0, 0));
+ /*
+ * The first call is expected to schedule the first worker, which will
+ * schedule the second one, which will schedule back to the main thread
+ * (here). Therefore count should be 2.
+ */
+ ut_assert(uthread_schedule());
+ ut_asserteq(2, count);
+ ut_assert(!uthread_grp_done(id1));
+ /* Four more calls should bring the count to 10 */
+ for (i = 0; i < 4; i++) {
+ ut_assert(!uthread_grp_done(id1));
+ ut_assert(uthread_schedule());
+ }
+ ut_asserteq(10, count);
+ /* This one allows the first worker to exit */
+ ut_assert(uthread_schedule());
+ /* At this point there should be no runnable thread in group 'id1' */
+ ut_assert(uthread_grp_done(id1));
+ /* Five more calls for the second worker to finish incrementing */
+ for (i = 0; i < 5; i++)
+ ut_assert(uthread_schedule());
+ ut_asserteq(15, count);
+ /* Plus one call to let the second worker return from its entry point */
+ ut_assert(uthread_schedule());
+ /* Now both tasks should be done, schedule should return false */
+ ut_assert(!uthread_schedule());
+
+ return 0;
+}
+LIB_TEST(uthread, 0);
+
+struct mw_args {
+ struct unit_test_state *uts;
+ struct uthread_mutex *m;
+ int flag;
+};
+
+static int mutex_worker_ret;
+
+static int _mutex_worker(struct mw_args *args)
+{
+ struct unit_test_state *uts = args->uts;
+
+ ut_asserteq(-EBUSY, uthread_mutex_trylock(args->m));
+ ut_assertok(uthread_mutex_lock(args->m));
+ args->flag = 1;
+ ut_assertok(uthread_mutex_unlock(args->m));
+
+ return 0;
+}
+
+static void mutex_worker(void *arg)
+{
+ mutex_worker_ret = _mutex_worker((struct mw_args *)arg);
+}
+
+/*
+ * thread_mutex() - testing uthread mutex operations
+ *
+ */
+static int uthread_mutex(struct unit_test_state *uts)
+{
+ struct uthread_mutex m = UTHREAD_MUTEX_INITIALIZER;
+ struct mw_args args = { .uts = uts, .m = &m, .flag = 0 };
+ int id;
+ int i;
+
+ id = uthread_grp_new_id();
+ ut_assert(id != 0);
+ /* Take the mutex */
+ ut_assertok(uthread_mutex_lock(&m));
+ /* Start a thread */
+ ut_assertok(uthread_create(NULL, mutex_worker, (void *)&args, 0,
+ id));
+ /* Let the thread run for a bit */
+ for (i = 0; i < 100; i++)
+ ut_assert(uthread_schedule());
+ /* Thread should not have set the flag due to the mutex */
+ ut_asserteq(0, args.flag);
+ /* Release the mutex */
+ ut_assertok(uthread_mutex_unlock(&m));
+ /* Schedule the thread until it is done */
+ while (uthread_schedule())
+ ;
+ /* Now the flag should be set */
+ ut_asserteq(1, args.flag);
+ /* And the mutex should be available */
+ ut_assertok(uthread_mutex_trylock(&m));
+ ut_assertok(uthread_mutex_unlock(&m));
+
+ /* Of course no error are expected from the thread routine */
+ ut_assertok(mutex_worker_ret);
+
+ return 0;
+}
+LIB_TEST(uthread_mutex, 0);
diff --git a/test/lib/uuid.c b/test/lib/uuid.c
index e24331a1366..d00e9563a47 100644
--- a/test/lib/uuid.c
+++ b/test/lib/uuid.c
@@ -8,14 +8,18 @@
* Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
*/
-#include <common.h>
-#include <uuid.h>
+#include <charset.h>
+#include <u-boot/uuid.h>
#include <test/lib.h>
#include <test/test.h>
#include <test/ut.h>
+#include <efi.h>
+
/* test UUID */
#define TEST_SVC_UUID "ed32d533-4209-99e6-2d72-cdd998a79cc0"
+/* U-Boot default fw image namespace */
+#define DEFAULT_FW_IMAGE_NAMESPACE "8c9f137e-91dc-427b-b2d6-b420faebaf2a"
#define UUID_SIZE 16
@@ -37,5 +41,121 @@ static int lib_test_uuid_to_le(struct unit_test_state *uts)
return 0;
}
-
LIB_TEST(lib_test_uuid_to_le, 0);
+
+#if defined(CONFIG_RANDOM_UUID) || defined(CONFIG_CMD_UUID)
+/* Test UUID attribute bits (version, variant) */
+static int lib_test_uuid_bits(struct unit_test_state *uts)
+{
+ unsigned char uuid[16];
+ efi_guid_t guid;
+ int i;
+
+ /*
+ * Reduce the chance of a randomly generated UUID disguising
+ * a regression by testing multiple times.
+ */
+ for (i = 0; i < 5; i++) {
+ /* Test UUID v4 */
+ gen_rand_uuid((unsigned char *)&uuid);
+
+ printf("v4 UUID: %pUb\n", (efi_guid_t *)uuid);
+
+ /* version 4 */
+ ut_assert((uuid[6] & 0xf0) == 0x40);
+ /* variant 1 */
+ ut_assert((uuid[8] & UUID_VARIANT_MASK) == (UUID_VARIANT << UUID_VARIANT_SHIFT));
+
+ /* Test v5, use the v4 UUID as the namespace */
+ gen_v5_guid((struct uuid *)uuid,
+ &guid, "test", 4, NULL);
+
+ printf("v5 GUID: %pUl\n", (efi_guid_t *)uuid);
+
+ /* This is a GUID so bits 6 and 7 are swapped (little endian). Version 5 */
+ ut_assert((guid.b[7] & 0xf0) == 0x50);
+ /* variant 1 */
+ ut_assert((guid.b[8] & UUID_VARIANT_MASK) == (UUID_VARIANT << UUID_VARIANT_SHIFT));
+ }
+
+ return 0;
+}
+
+LIB_TEST(lib_test_uuid_bits, 0);
+#endif
+
+struct dynamic_uuid_test_data {
+ const char *compatible;
+ const u16 *images[4];
+ const char *expected_uuids[4];
+};
+
+static int lib_test_dynamic_uuid_case(struct unit_test_state *uts,
+ const struct dynamic_uuid_test_data *data)
+{
+ struct uuid namespace;
+ int j;
+
+ ut_assertok(uuid_str_to_bin(DEFAULT_FW_IMAGE_NAMESPACE, (unsigned char *)&namespace,
+ UUID_STR_FORMAT_GUID));
+
+ for (j = 0; data->images[j]; j++) {
+ const char *expected_uuid = data->expected_uuids[j];
+ const u16 *image = data->images[j];
+ efi_guid_t uuid;
+ char uuid_str[37];
+
+ gen_v5_guid(&namespace, &uuid,
+ data->compatible, strlen(data->compatible),
+ image, u16_strlen(image) * sizeof(uint16_t),
+ NULL);
+ uuid_bin_to_str((unsigned char *)&uuid, uuid_str, UUID_STR_FORMAT_GUID);
+
+ ut_asserteq_str(expected_uuid, uuid_str);
+ }
+
+ return 0;
+}
+
+static int lib_test_dynamic_uuid(struct unit_test_state *uts)
+{
+ int ret, i;
+ const struct dynamic_uuid_test_data test_data[] = {
+ {
+ .compatible = "sandbox",
+ .images = {
+ u"SANDBOX-UBOOT",
+ u"SANDBOX-UBOOT-ENV",
+ u"SANDBOX-FIT",
+ NULL,
+ },
+ .expected_uuids = {
+ "985f2937-7c2e-5e9a-8a5e-8e063312964b",
+ "9e339473-c2eb-530a-a69b-0cd6bbbed40e",
+ "46610520-469e-59dc-a8dd-c11832b877ea",
+ NULL,
+ }
+ },
+ {
+ .compatible = "qcom,qrb4210-rb2",
+ .images = {
+ u"QUALCOMM-UBOOT",
+ NULL,
+ },
+ .expected_uuids = {
+ "d5021fac-8dd0-5ed7-90c2-763c304aaf86",
+ NULL,
+ }
+ },
+ };
+
+ for (i = 0; i < ARRAY_SIZE(test_data); i++) {
+ ret = lib_test_dynamic_uuid_case(uts, &test_data[i]);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+LIB_TEST(lib_test_dynamic_uuid, 0);
diff --git a/test/log/Makefile b/test/log/Makefile
index 08eea70e344..24b7c46786d 100644
--- a/test/log/Makefile
+++ b/test/log/Makefile
@@ -7,8 +7,6 @@ obj-$(CONFIG_CMD_LOG) += log_filter.o
ifdef CONFIG_UT_LOG
-obj-y += log_ut.o
-
ifdef CONFIG_SANDBOX
obj-$(CONFIG_LOG_SYSLOG) += syslog_test.o
obj-$(CONFIG_LOG_SYSLOG) += syslog_test_ndebug.o
diff --git a/test/log/cont_test.c b/test/log/cont_test.c
index de7b7f064cd..3b3b791f025 100644
--- a/test/log/cont_test.c
+++ b/test/log/cont_test.c
@@ -5,12 +5,10 @@
* Test continuation of log messages.
*/
-#include <common.h>
#include <console.h>
#include <asm/global_data.h>
#include <test/log.h>
#include <test/test.h>
-#include <test/suites.h>
#include <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -26,7 +24,6 @@ static int log_test_cont(struct unit_test_state *uts)
/* Write two messages, the second continuing the first */
gd->log_fmt = (1 << LOGF_CAT) | (1 << LOGF_LEVEL) | (1 << LOGF_MSG);
gd->default_log_level = LOGL_INFO;
- console_record_reset_enable();
log(LOGC_ARCH, LOGL_ERR, "ea%d\n", 1);
log(LOGC_CONT, LOGL_CONT, "cc%d\n", 2);
gd->default_log_level = log_level;
@@ -34,7 +31,7 @@ static int log_test_cont(struct unit_test_state *uts)
gd->flags &= ~GD_FLG_RECORD;
ut_assertok(ut_check_console_line(uts, "ERR.arch, ea1"));
ut_assertok(ut_check_console_line(uts, "ERR.arch, cc2"));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Write a third message which is not a continuation */
gd->log_fmt = (1 << LOGF_CAT) | (1 << LOGF_LEVEL) | (1 << LOGF_MSG);
@@ -45,7 +42,7 @@ static int log_test_cont(struct unit_test_state *uts)
gd->log_fmt = log_fmt;
gd->flags &= ~GD_FLG_RECORD;
ut_assertok(ut_check_console_line(uts, "INFO.efi, ie3"));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
/* Write two messages without a newline between them */
gd->log_fmt = (1 << LOGF_CAT) | (1 << LOGF_LEVEL) | (1 << LOGF_MSG);
@@ -57,7 +54,7 @@ static int log_test_cont(struct unit_test_state *uts)
gd->log_fmt = log_fmt;
gd->flags &= ~GD_FLG_RECORD;
ut_assertok(ut_check_console_line(uts, "ERR.arch, ea1 cc2"));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
diff --git a/test/log/log_filter.c b/test/log/log_filter.c
index b644b40a850..8622dcf2913 100644
--- a/test/log/log_filter.c
+++ b/test/log/log_filter.c
@@ -3,7 +3,6 @@
* Copyright (C) 2020 Sean Anderson <seanga2@gmail.com>
*/
-#include <common.h>
#include <console.h>
#include <log.h>
#include <asm/global_data.h>
@@ -25,7 +24,7 @@ static int log_test_filter_invalid(struct unit_test_state *uts)
return 0;
}
-LOG_TEST_FLAGS(log_test_filter_invalid, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_filter_invalid, UTF_CONSOLE);
/* Test adding and removing filters */
static int log_test_filter(struct unit_test_state *uts)
@@ -39,9 +38,7 @@ static int log_test_filter(struct unit_test_state *uts)
ulong filt1, filt2;
#define create_filter(args, filter_num) do {\
- ut_assertok(console_record_reset_enable()); \
ut_assertok(run_command("log filter-add -p " args, 0)); \
- ut_assert_skipline(); \
ut_assertok(strict_strtoul(uts->actual_str, 10, &(filter_num))); \
ut_assert_console_end(); \
} while (0)
@@ -73,7 +70,6 @@ static int log_test_filter(struct unit_test_state *uts)
ut_asserteq(true, filt2_found);
#define remove_filter(filter_num) do { \
- ut_assertok(console_record_reset_enable()); \
snprintf(cmd, sizeof(cmd), "log filter-remove %lu", filter_num); \
ut_assertok(run_command(cmd, 0)); \
ut_assert_console_end(); \
@@ -96,7 +92,6 @@ static int log_test_filter(struct unit_test_state *uts)
create_filter("", filt1);
create_filter("", filt2);
- ut_assertok(console_record_reset_enable());
ut_assertok(run_command("log filter-remove -a", 0));
ut_assert_console_end();
@@ -106,4 +101,4 @@ static int log_test_filter(struct unit_test_state *uts)
return 0;
}
-LOG_TEST_FLAGS(log_test_filter, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_filter, UTF_CONSOLE);
diff --git a/test/log/log_test.c b/test/log/log_test.c
index c5abff80d11..00b442252f0 100644
--- a/test/log/log_test.c
+++ b/test/log/log_test.c
@@ -6,7 +6,6 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
#include <command.h>
#include <log.h>
#include <asm/global_data.h>
@@ -16,7 +15,8 @@
DECLARE_GLOBAL_DATA_PTR;
/* emit some sample log records in different ways, for testing */
-static int do_log_run(struct unit_test_state *uts, int cat, const char *file)
+static int do_log_run(struct unit_test_state *uts, int cat, const char *file,
+ const char *func)
{
int i;
int ret, expected_ret;
@@ -31,13 +31,13 @@ static int do_log_run(struct unit_test_state *uts, int cat, const char *file)
for (i = LOGL_FIRST; i < LOGL_COUNT; i++) {
log(cat, i, "log %d\n", i);
ret = _log(log_uc_cat(cat), i, file, 100 + i,
- "func", "_log %d\n", i);
+ func, "_log %d\n", i);
ut_asserteq(ret, expected_ret);
}
/* test with LOGL_COUNT flag */
for (i = LOGL_FIRST; i < LOGL_COUNT; i++) {
ret = _log(log_uc_cat(cat), i | LOGL_FORCE_DEBUG, file, 100 + i,
- "func", "_log force %d\n", i);
+ func, "_log force %d\n", i);
ut_asserteq(ret, expected_ret);
}
@@ -45,9 +45,10 @@ static int do_log_run(struct unit_test_state *uts, int cat, const char *file)
return 0;
}
-#define log_run_cat(cat) do_log_run(uts, cat, "file")
-#define log_run_file(file) do_log_run(uts, UCLASS_SPI, file)
-#define log_run() do_log_run(uts, UCLASS_SPI, "file")
+#define log_run_cat(cat) do_log_run(uts, cat, "file", "func")
+#define log_run_file(file) do_log_run(uts, UCLASS_SPI, file, "func")
+#define log_run_func(func) do_log_run(uts, UCLASS_SPI, "file", func)
+#define log_run() do_log_run(uts, UCLASS_SPI, "file", "func")
#define EXPECT_LOG BIT(0)
#define EXPECT_DIRECT BIT(1)
@@ -56,7 +57,7 @@ static int do_log_run(struct unit_test_state *uts, int cat, const char *file)
#define EXPECT_DEBUG BIT(4)
static int do_check_log_entries(struct unit_test_state *uts, int flags, int min,
- int max)
+ int max, const char *func)
{
int i;
@@ -64,7 +65,8 @@ static int do_check_log_entries(struct unit_test_state *uts, int flags, int min,
if (flags & EXPECT_LOG)
ut_assert_nextline(" do_log_run() log %d", i);
if (flags & EXPECT_DIRECT)
- ut_assert_nextline(" func() _log %d", i);
+ ut_assert_nextline(" %s() _log %d", func,
+ i);
if (flags & EXPECT_DEBUG) {
ut_assert_nextline("log %d", i);
ut_assert_nextline("_log %d", i);
@@ -72,12 +74,13 @@ static int do_check_log_entries(struct unit_test_state *uts, int flags, int min,
}
if (flags & EXPECT_EXTRA)
for (; i <= LOGL_MAX ; i++)
- ut_assert_nextline(" func() _log %d", i);
+ ut_assert_nextline(" %s() _log %d", func,
+ i);
for (i = LOGL_FIRST; i < LOGL_COUNT; i++) {
if (flags & EXPECT_FORCE)
- ut_assert_nextline(" func() _log force %d",
- i);
+ ut_assert_nextline(" %s() _log force %d",
+ func, i);
if (flags & EXPECT_DEBUG)
ut_assert_nextline("_log force %d", i);
}
@@ -87,7 +90,7 @@ static int do_check_log_entries(struct unit_test_state *uts, int flags, int min,
}
#define check_log_entries_flags_levels(flags, min, max) do {\
- int ret = do_check_log_entries(uts, flags, min, max); \
+ int ret = do_check_log_entries(uts, flags, min, max, "func"); \
if (ret) \
return ret; \
} while (0)
@@ -111,18 +114,16 @@ int log_test_cat_allow(struct unit_test_state *uts)
filt = log_add_filter("console", cat_list, LOGL_MAX, NULL);
ut_assert(filt >= 0);
- ut_assertok(console_record_reset_enable());
log_run_cat(UCLASS_MMC);
check_log_entries_extra();
- ut_assertok(console_record_reset_enable());
log_run_cat(UCLASS_SPI);
check_log_entries_extra();
ut_assertok(log_remove_filter("console", filt));
return 0;
}
-LOG_TEST_FLAGS(log_test_cat_allow, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_cat_allow, UTF_CONSOLE);
/* Check a category filter that should block log entries */
int log_test_cat_deny_implicit(struct unit_test_state *uts)
@@ -135,14 +136,13 @@ int log_test_cat_deny_implicit(struct unit_test_state *uts)
filt = log_add_filter("console", cat_list, LOGL_MAX, NULL);
ut_assert(filt >= 0);
- ut_assertok(console_record_reset_enable());
log_run_cat(UCLASS_SPI);
check_log_entries_none();
ut_assertok(log_remove_filter("console", filt));
return 0;
}
-LOG_TEST_FLAGS(log_test_cat_deny_implicit, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_cat_deny_implicit, UTF_CONSOLE);
/* Check passing and failing file filters */
int log_test_file(struct unit_test_state *uts)
@@ -152,18 +152,16 @@ int log_test_file(struct unit_test_state *uts)
filt = log_add_filter("console", NULL, LOGL_MAX, "file");
ut_assert(filt >= 0);
- ut_assertok(console_record_reset_enable());
log_run_file("file");
check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE);
- ut_assertok(console_record_reset_enable());
log_run_file("file2");
check_log_entries_none();
ut_assertok(log_remove_filter("console", filt));
return 0;
}
-LOG_TEST_FLAGS(log_test_file, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_file, UTF_CONSOLE);
/* Check a passing file filter (second in list) */
int log_test_file_second(struct unit_test_state *uts)
@@ -173,14 +171,13 @@ int log_test_file_second(struct unit_test_state *uts)
filt = log_add_filter("console", NULL, LOGL_MAX, "file,file2");
ut_assert(filt >= 0);
- ut_assertok(console_record_reset_enable());
log_run_file("file2");
check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE);
ut_assertok(log_remove_filter("console", filt));
return 0;
}
-LOG_TEST_FLAGS(log_test_file_second, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_file_second, UTF_CONSOLE);
/* Check a passing file filter (middle of list) */
int log_test_file_mid(struct unit_test_state *uts)
@@ -191,14 +188,53 @@ int log_test_file_mid(struct unit_test_state *uts)
"file,file2,log/log_test.c");
ut_assert(filt >= 0);
- ut_assertok(console_record_reset_enable());
log_run_file("file2");
check_log_entries_extra();
ut_assertok(log_remove_filter("console", filt));
return 0;
}
-LOG_TEST_FLAGS(log_test_file_mid, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_file_mid, UTF_CONSOLE);
+
+/* Check passing and failing function filters */
+int log_test_func(struct unit_test_state *uts)
+{
+ int filt;
+
+ filt = log_add_filter_flags("console", NULL, LOGL_MAX, "file", "func",
+ 0);
+ ut_assert(filt >= 0);
+
+ log_run_func("func");
+ check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE);
+
+ log_run_func("fnc2");
+ do_check_log_entries(uts, EXPECT_FORCE, LOGL_FIRST, _LOG_MAX_LEVEL,
+ "fnc2");
+
+ ut_assertok(log_remove_filter("console", filt));
+
+ return 0;
+}
+LOG_TEST_FLAGS(log_test_func, UTF_CONSOLE);
+
+/* Check a passing function filter (middle of list) */
+int log_test_func_mid(struct unit_test_state *uts)
+{
+ int filt;
+
+ filt = log_add_filter_flags("console", NULL, LOGL_MAX, "file",
+ "bad1,func,bad2", 0);
+ ut_assert(filt >= 0);
+
+ log_run_func("func");
+ check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE);
+
+ ut_assertok(log_remove_filter("console", filt));
+
+ return 0;
+}
+LOG_TEST_FLAGS(log_test_func_mid, UTF_CONSOLE);
/* Check a log level filter */
int log_test_level(struct unit_test_state *uts)
@@ -208,7 +244,6 @@ int log_test_level(struct unit_test_state *uts)
filt = log_add_filter("console", NULL, LOGL_WARNING, NULL);
ut_assert(filt >= 0);
- ut_assertok(console_record_reset_enable());
log_run();
check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE,
LOGL_FIRST, LOGL_WARNING);
@@ -216,7 +251,7 @@ int log_test_level(struct unit_test_state *uts)
ut_assertok(log_remove_filter("console", filt));
return 0;
}
-LOG_TEST_FLAGS(log_test_level, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_level, UTF_CONSOLE);
/* Check two filters, one of which passes everything */
int log_test_double(struct unit_test_state *uts)
@@ -228,7 +263,6 @@ int log_test_double(struct unit_test_state *uts)
filt2 = log_add_filter("console", NULL, LOGL_MAX, NULL);
ut_assert(filt2 >= 0);
- ut_assertok(console_record_reset_enable());
log_run();
check_log_entries_extra();
@@ -236,7 +270,7 @@ int log_test_double(struct unit_test_state *uts)
ut_assertok(log_remove_filter("console", filt2));
return 0;
}
-LOG_TEST_FLAGS(log_test_double, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_double, UTF_CONSOLE);
/* Check three filters, which together pass everything */
int log_test_triple(struct unit_test_state *uts)
@@ -250,7 +284,6 @@ int log_test_triple(struct unit_test_state *uts)
filt3 = log_add_filter("console", NULL, LOGL_MAX, "log/log_test.c");
ut_assert(filt3 >= 0);
- ut_assertok(console_record_reset_enable());
log_run_file("file2");
check_log_entries_extra();
@@ -259,13 +292,12 @@ int log_test_triple(struct unit_test_state *uts)
ut_assertok(log_remove_filter("console", filt3));
return 0;
}
-LOG_TEST_FLAGS(log_test_triple, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_triple, UTF_CONSOLE);
int do_log_test_helpers(struct unit_test_state *uts)
{
int i;
- ut_assertok(console_record_reset_enable());
log_err("level %d\n", LOGL_EMERG);
log_err("level %d\n", LOGL_ALERT);
log_err("level %d\n", LOGL_CRIT);
@@ -293,11 +325,10 @@ int log_test_helpers(struct unit_test_state *uts)
gd->log_fmt = log_get_default_format();
return ret;
}
-LOG_TEST_FLAGS(log_test_helpers, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_helpers, UTF_CONSOLE);
int do_log_test_disable(struct unit_test_state *uts)
{
- ut_assertok(console_record_reset_enable());
log_err("default\n");
ut_assert_nextline("%*s() default", CONFIG_LOGF_FUNC_PAD, __func__);
@@ -320,7 +351,7 @@ int log_test_disable(struct unit_test_state *uts)
gd->log_fmt = log_get_default_format();
return ret;
}
-LOG_TEST_FLAGS(log_test_disable, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_disable, UTF_CONSOLE);
/* Check denying based on category */
int log_test_cat_deny(struct unit_test_state *uts)
@@ -333,10 +364,9 @@ int log_test_cat_deny(struct unit_test_state *uts)
filt1 = log_add_filter("console", cat_list, LOGL_MAX, NULL);
ut_assert(filt1 >= 0);
filt2 = log_add_filter_flags("console", cat_list, LOGL_MAX, NULL,
- LOGFF_DENY);
+ NULL, LOGFF_DENY);
ut_assert(filt2 >= 0);
- ut_assertok(console_record_reset_enable());
log_run_cat(UCLASS_SPI);
check_log_entries_none();
@@ -344,7 +374,7 @@ int log_test_cat_deny(struct unit_test_state *uts)
ut_assertok(log_remove_filter("console", filt2));
return 0;
}
-LOG_TEST_FLAGS(log_test_cat_deny, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_cat_deny, UTF_CONSOLE);
/* Check denying based on file */
int log_test_file_deny(struct unit_test_state *uts)
@@ -354,10 +384,9 @@ int log_test_file_deny(struct unit_test_state *uts)
filt1 = log_add_filter("console", NULL, LOGL_MAX, "file");
ut_assert(filt1 >= 0);
filt2 = log_add_filter_flags("console", NULL, LOGL_MAX, "file",
- LOGFF_DENY);
+ NULL, LOGFF_DENY);
ut_assert(filt2 >= 0);
- ut_assertok(console_record_reset_enable());
log_run_file("file");
check_log_entries_none();
@@ -365,7 +394,7 @@ int log_test_file_deny(struct unit_test_state *uts)
ut_assertok(log_remove_filter("console", filt2));
return 0;
}
-LOG_TEST_FLAGS(log_test_file_deny, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_file_deny, UTF_CONSOLE);
/* Check denying based on level */
int log_test_level_deny(struct unit_test_state *uts)
@@ -375,20 +404,19 @@ int log_test_level_deny(struct unit_test_state *uts)
filt1 = log_add_filter("console", NULL, LOGL_INFO, NULL);
ut_assert(filt1 >= 0);
filt2 = log_add_filter_flags("console", NULL, LOGL_WARNING, NULL,
- LOGFF_DENY);
+ NULL, LOGFF_DENY);
ut_assert(filt2 >= 0);
- ut_assertok(console_record_reset_enable());
log_run();
- check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE,
- LOGL_WARNING + 1,
- min(gd->default_log_level, LOGL_INFO));
+ check_log_entries_flags_levels(
+ EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE,
+ LOGL_WARNING + 1, min((int)gd->default_log_level, LOGL_INFO));
ut_assertok(log_remove_filter("console", filt1));
ut_assertok(log_remove_filter("console", filt2));
return 0;
}
-LOG_TEST_FLAGS(log_test_level_deny, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_level_deny, UTF_CONSOLE);
/* Check matching based on minimum level */
int log_test_min(struct unit_test_state *uts)
@@ -396,13 +424,12 @@ int log_test_min(struct unit_test_state *uts)
int filt1, filt2;
filt1 = log_add_filter_flags("console", NULL, LOGL_WARNING, NULL,
- LOGFF_LEVEL_MIN);
+ NULL, LOGFF_LEVEL_MIN);
ut_assert(filt1 >= 0);
filt2 = log_add_filter_flags("console", NULL, LOGL_INFO, NULL,
- LOGFF_DENY | LOGFF_LEVEL_MIN);
+ NULL, LOGFF_DENY | LOGFF_LEVEL_MIN);
ut_assert(filt2 >= 0);
- ut_assertok(console_record_reset_enable());
log_run();
check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE,
LOGL_WARNING, LOGL_INFO - 1);
@@ -411,7 +438,7 @@ int log_test_min(struct unit_test_state *uts)
ut_assertok(log_remove_filter("console", filt2));
return 0;
}
-LOG_TEST_FLAGS(log_test_min, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_min, UTF_CONSOLE);
/* Check dropped traces */
int log_test_dropped(struct unit_test_state *uts)
@@ -420,8 +447,6 @@ int log_test_dropped(struct unit_test_state *uts)
gd->flags &= ~(GD_FLG_LOG_READY);
gd->log_drop_count = 0;
- ut_assertok(console_record_reset_enable());
-
log_run();
ut_asserteq(2 * (LOGL_COUNT - LOGL_FIRST) +
_LOG_MAX_LEVEL - LOGL_FIRST + 1,
@@ -433,7 +458,7 @@ int log_test_dropped(struct unit_test_state *uts)
return 0;
}
-LOG_TEST_FLAGS(log_test_dropped, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_dropped, UTF_CONSOLE);
/* Check log_buffer() */
int log_test_buffer(struct unit_test_state *uts)
@@ -447,17 +472,18 @@ int log_test_buffer(struct unit_test_state *uts)
for (i = 0; i < 0x11; i++)
buf[i] = i * 0x11;
- ut_assertok(console_record_reset_enable());
log_buffer(LOGC_BOOT, LOGL_INFO, 0, buf, 1, 0x12, 0);
/* This one should product no output due to the debug level */
log_buffer(LOGC_BOOT, LOGL_DEBUG, 0, buf, 1, 0x12, 0);
- ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........");
- ut_assert_nextline("00000010: 10 00 ..");
+ ut_assert_nextline(
+ " log_test_buffer() 00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........");
+ ut_assert_nextline(
+ " log_test_buffer() 00000010: 10 00 ..");
ut_assert_console_end();
free(buf);
return 0;
}
-LOG_TEST_FLAGS(log_test_buffer, UT_TESTF_CONSOLE_REC);
+LOG_TEST_FLAGS(log_test_buffer, UTF_CONSOLE);
diff --git a/test/log/log_ut.c b/test/log/log_ut.c
deleted file mode 100644
index 5aa3a184004..00000000000
--- a/test/log/log_ut.c
+++ /dev/null
@@ -1,21 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
- *
- * Logging function tests.
- */
-
-#include <common.h>
-#include <console.h>
-#include <log.h>
-#include <test/log.h>
-#include <test/suites.h>
-
-int do_ut_log(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(log_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(log_test);
-
- return cmd_ut_category("log", "log_test_",
- tests, n_ents, argc, argv);
-}
diff --git a/test/log/nolog_ndebug.c b/test/log/nolog_ndebug.c
index bd9a4f408e7..4dc0f2d3a33 100644
--- a/test/log/nolog_ndebug.c
+++ b/test/log/nolog_ndebug.c
@@ -5,7 +5,6 @@
* Logging function tests for CONFIG_LOG=n without #define DEBUG
*/
-#include <common.h>
#include <console.h>
#include <log.h>
#include <asm/global_data.h>
@@ -22,7 +21,6 @@ static int log_test_log_disabled_ndebug(struct unit_test_state *uts)
int i;
memset(buf, 0, BUFFSIZE);
- console_record_reset_enable();
/* Output a log record at every level */
for (i = LOGL_EMERG; i < LOGL_COUNT; i++)
@@ -32,7 +30,7 @@ static int log_test_log_disabled_ndebug(struct unit_test_state *uts)
/* Since DEBUG is not defined, we expect to not get debug output */
for (i = LOGL_EMERG; i < LOGL_DEBUG; i++)
ut_assertok(ut_check_console_line(uts, "testing level %d", i));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
diff --git a/test/log/nolog_test.c b/test/log/nolog_test.c
index 4e52e5bed82..1913e6817a7 100644
--- a/test/log/nolog_test.c
+++ b/test/log/nolog_test.c
@@ -8,13 +8,11 @@
/* Needed for testing log_debug() */
#define DEBUG 1
-#include <common.h>
#include <console.h>
#include <log.h>
#include <asm/global_data.h>
#include <test/log.h>
#include <test/test.h>
-#include <test/suites.h>
#include <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -26,11 +24,10 @@ static int log_test_nolog_err(struct unit_test_state *uts)
char buf[BUFFSIZE];
memset(buf, 0, BUFFSIZE);
- console_record_reset_enable();
log_err("testing %s\n", "log_err");
gd->flags &= ~GD_FLG_RECORD;
ut_assertok(ut_check_console_line(uts, "testing log_err"));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
LOG_TEST(log_test_nolog_err);
@@ -40,11 +37,10 @@ static int log_test_nolog_warning(struct unit_test_state *uts)
char buf[BUFFSIZE];
memset(buf, 0, BUFFSIZE);
- console_record_reset_enable();
log_warning("testing %s\n", "log_warning");
gd->flags &= ~GD_FLG_RECORD;
ut_assertok(ut_check_console_line(uts, "testing log_warning"));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
LOG_TEST(log_test_nolog_warning);
@@ -54,11 +50,10 @@ static int log_test_nolog_notice(struct unit_test_state *uts)
char buf[BUFFSIZE];
memset(buf, 0, BUFFSIZE);
- console_record_reset_enable();
log_notice("testing %s\n", "log_notice");
gd->flags &= ~GD_FLG_RECORD;
ut_assertok(ut_check_console_line(uts, "testing log_notice"));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
LOG_TEST(log_test_nolog_notice);
@@ -68,11 +63,10 @@ static int log_test_nolog_info(struct unit_test_state *uts)
char buf[BUFFSIZE];
memset(buf, 0, BUFFSIZE);
- console_record_reset_enable();
log_err("testing %s\n", "log_info");
gd->flags &= ~GD_FLG_RECORD;
ut_assertok(ut_check_console_line(uts, "testing log_info"));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
LOG_TEST(log_test_nolog_info);
@@ -84,10 +78,9 @@ static int nolog_test_nodebug(struct unit_test_state *uts)
char buf[BUFFSIZE];
memset(buf, 0, BUFFSIZE);
- console_record_reset_enable();
debug("testing %s\n", "debug");
gd->flags &= ~GD_FLG_RECORD;
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
LOG_TEST(nolog_test_nodebug);
@@ -97,11 +90,10 @@ static int log_test_nolog_nodebug(struct unit_test_state *uts)
char buf[BUFFSIZE];
memset(buf, 0, BUFFSIZE);
- console_record_reset_enable();
log_debug("testing %s\n", "log_debug");
gd->flags &= ~GD_FLG_RECORD;
ut_assert(!strcmp(buf, ""));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
LOG_TEST(log_test_nolog_nodebug);
@@ -113,11 +105,10 @@ static int nolog_test_debug(struct unit_test_state *uts)
char buf[BUFFSIZE];
memset(buf, 0, BUFFSIZE);
- console_record_reset_enable();
debug("testing %s\n", "debug");
gd->flags &= ~GD_FLG_RECORD;
ut_assertok(ut_check_console_line(uts, "testing debug"));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
LOG_TEST(nolog_test_debug);
@@ -127,13 +118,12 @@ static int log_test_nolog_debug(struct unit_test_state *uts)
char buf[BUFFSIZE];
memset(buf, 0, BUFFSIZE);
- console_record_reset_enable();
log_debug("testing %s\n", "log_debug");
log(LOGC_NONE, LOGL_DEBUG, "more %s\n", "log_debug");
gd->flags &= ~GD_FLG_RECORD;
ut_assertok(ut_check_console_line(uts, "testing log_debug"));
ut_assertok(ut_check_console_line(uts, "more log_debug"));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
LOG_TEST(log_test_nolog_debug);
diff --git a/test/log/pr_cont_test.c b/test/log/pr_cont_test.c
index df4520d2807..67d8ac59db9 100644
--- a/test/log/pr_cont_test.c
+++ b/test/log/pr_cont_test.c
@@ -5,11 +5,9 @@
* Test continuation of log messages using pr_cont().
*/
-#include <common.h>
#include <console.h>
#include <test/log.h>
#include <test/test.h>
-#include <test/suites.h>
#include <test/ut.h>
#include <asm/global_data.h>
#include <linux/printk.h>
@@ -29,14 +27,13 @@ static int log_test_pr_cont(struct unit_test_state *uts)
/* Write two messages, the second continuing the first */
gd->log_fmt = BIT(LOGF_MSG);
gd->default_log_level = LOGL_INFO;
- console_record_reset_enable();
pr_err("ea%d ", 1);
pr_cont("cc%d\n", 2);
gd->default_log_level = log_level;
gd->log_fmt = log_fmt;
gd->flags &= ~GD_FLG_RECORD;
ut_assertok(ut_check_console_line(uts, "ea1 cc2"));
- ut_assertok(ut_check_console_end(uts));
+ ut_assert_console_end();
return 0;
}
diff --git a/test/log/syslog_test.c b/test/log/syslog_test.c
index 4db649db822..98b91436580 100644
--- a/test/log/syslog_test.c
+++ b/test/log/syslog_test.c
@@ -10,13 +10,11 @@
/* Override CONFIG_LOG_MAX_LEVEL */
#define LOG_DEBUG
-#include <common.h>
#include <asm/global_data.h>
#include <dm/device.h>
#include <hexdump.h>
#include <test/log.h>
#include <test/test.h>
-#include <test/suites.h>
#include <test/ut.h>
#include <asm/eth.h>
#include "syslog_test.h"
diff --git a/test/log/syslog_test_ndebug.c b/test/log/syslog_test_ndebug.c
index 4438791044d..dfd0217c1e4 100644
--- a/test/log/syslog_test_ndebug.c
+++ b/test/log/syslog_test_ndebug.c
@@ -7,13 +7,11 @@
* Invoke the test with: ./u-boot -d arch/sandbox/dts/test.dtb
*/
-#include <common.h>
#include <asm/global_data.h>
#include <dm/device.h>
#include <hexdump.h>
#include <test/log.h>
#include <test/test.h>
-#include <test/suites.h>
#include <test/ut.h>
#include <asm/eth.h>
#include "syslog_test.h"
diff --git a/test/optee/Kconfig b/test/optee/Kconfig
index 2f6834aa3b4..63e2cbf79c7 100644
--- a/test/optee/Kconfig
+++ b/test/optee/Kconfig
@@ -1,6 +1,6 @@
config UT_OPTEE
bool "Enable OP-TEE Unit Tests"
- depends on UNIT_TEST && OF_CONTROL && OPTEE
+ depends on OF_CONTROL && OPTEE
default y
help
This enables the 'ut optee' command which runs a series of unit
diff --git a/test/optee/Makefile b/test/optee/Makefile
index 8793fd7ad61..ec56750fa80 100644
--- a/test/optee/Makefile
+++ b/test/optee/Makefile
@@ -3,7 +3,7 @@
# Copyright (C) 2019, Theobroma Systems Design und Consulting GmbH
# Test files
-obj-y += cmd_ut_optee.o
+obj-y += optee.o
DTC_FLAGS += -@
diff --git a/test/optee/cmd_ut_optee.c b/test/optee/optee.c
index c3887ab11d9..658621fa2fa 100644
--- a/test/optee/cmd_ut_optee.c
+++ b/test/optee/optee.c
@@ -3,7 +3,6 @@
* Copyright (C) 2019, Theobroma Systems Design und Consulting GmbH
*/
-#include <common.h>
#include <command.h>
#include <errno.h>
#include <fdt_support.h>
@@ -15,7 +14,6 @@
#include <test/ut.h>
#include <test/optee.h>
-#include <test/suites.h>
/* 4k ought to be enough for anybody */
#define FDT_COPY_SIZE (4 * SZ_1K)
@@ -27,6 +25,41 @@ extern u32 __dtb_test_optee_no_optee_begin;
static void *fdt;
static bool expect_success;
+static int optee_test_init(struct unit_test_state *uts)
+{
+ void *fdt_optee = &__dtb_test_optee_optee_begin;
+ void *fdt_no_optee = &__dtb_test_optee_no_optee_begin;
+ void *fdt_base = &__dtb_test_optee_base_begin;
+ int ret = -ENOMEM;
+
+ ut_assertok(fdt_check_header(fdt_base));
+ ut_assertok(fdt_check_header(fdt_optee));
+ ut_assertok(fdt_check_header(fdt_no_optee));
+
+ fdt = malloc(FDT_COPY_SIZE);
+ if (!fdt)
+ return ret;
+
+ /*
+ * Resize the FDT to 4k so that we have room to operate on
+ *
+ * (and relocate it since the memory might be mapped
+ * read-only)
+ */
+ ut_assertok(fdt_open_into(fdt_base, fdt, FDT_COPY_SIZE));
+
+ return 0;
+}
+OPTEE_TEST_INIT(optee_test_init, 0);
+
+static int optee_test_uninit(struct unit_test_state *uts)
+{
+ free(fdt);
+
+ return 0;
+}
+OPTEE_TEST_UNINIT(optee_test_uninit, 0);
+
static int optee_fdt_firmware(struct unit_test_state *uts)
{
const void *prop;
@@ -47,7 +80,6 @@ static int optee_fdt_firmware(struct unit_test_state *uts)
return CMD_RET_SUCCESS;
}
-OPTEE_TEST(optee_fdt_firmware, 0);
static int optee_fdt_protected_memory(struct unit_test_state *uts)
{
@@ -90,60 +122,50 @@ static int optee_fdt_protected_memory(struct unit_test_state *uts)
return CMD_RET_SUCCESS;
}
-OPTEE_TEST(optee_fdt_protected_memory, 0);
-int do_ut_optee(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+/* (1) Try to copy optee nodes from empty dt */
+static int optee_fdt_copy_empty(struct unit_test_state *uts)
{
- struct unit_test *tests = UNIT_TEST_SUITE_START(optee_test);
- const int n_ents = UNIT_TEST_SUITE_COUNT(optee_test);
- struct unit_test_state *uts;
- void *fdt_optee = &__dtb_test_optee_optee_begin;
void *fdt_no_optee = &__dtb_test_optee_no_optee_begin;
- void *fdt_base = &__dtb_test_optee_base_begin;
- int ret = -ENOMEM;
-
- uts = calloc(1, sizeof(*uts));
- if (!uts)
- return -ENOMEM;
-
- ut_assertok(fdt_check_header(fdt_base));
- ut_assertok(fdt_check_header(fdt_optee));
- ut_assertok(fdt_check_header(fdt_no_optee));
-
- fdt = malloc(FDT_COPY_SIZE);
- if (!fdt)
- return ret;
- /*
- * Resize the FDT to 4k so that we have room to operate on
- *
- * (and relocate it since the memory might be mapped
- * read-only)
- */
- ut_assertok(fdt_open_into(fdt_base, fdt, FDT_COPY_SIZE));
-
- /*
- * (1) Try to copy optee nodes from empty dt.
- * This should still run successfully.
- */
+ /* This should still run successfully */
ut_assertok(optee_copy_fdt_nodes(fdt_no_optee, fdt));
expect_success = false;
- ret = cmd_ut_category("optee", "", tests, n_ents, argc, argv);
+ ut_assertok(optee_fdt_firmware(uts));
+ ut_assertok(optee_fdt_protected_memory(uts));
+
+ return 0;
+}
+OPTEE_TEST(optee_fdt_copy_empty, 0);
+
+/* (2) Try to copy optee nodes from prefilled dt */
+static int optee_fdt_copy_prefilled(struct unit_test_state *uts)
+{
+ void *fdt_optee = &__dtb_test_optee_optee_begin;
- /* (2) Try to copy optee nodes from prefilled dt */
ut_assertok(optee_copy_fdt_nodes(fdt_optee, fdt));
expect_success = true;
- ret = cmd_ut_category("optee", "", tests, n_ents, argc, argv);
+ ut_assertok(optee_fdt_firmware(uts));
+ ut_assertok(optee_fdt_protected_memory(uts));
+
+ return 0;
+}
+OPTEE_TEST(optee_fdt_copy_prefilled, 0);
+
+/* (3) Try to copy OP-TEE nodes into a already filled DT */
+static int optee_fdt_copy_already_filled(struct unit_test_state *uts)
+{
+ void *fdt_optee = &__dtb_test_optee_optee_begin;
- /* (3) Try to copy OP-TEE nodes into a already filled DT */
ut_assertok(fdt_open_into(fdt_optee, fdt, FDT_COPY_SIZE));
ut_assertok(optee_copy_fdt_nodes(fdt_optee, fdt));
expect_success = true;
- ret = cmd_ut_category("optee", "", tests, n_ents, argc, argv);
+ ut_assertok(optee_fdt_firmware(uts));
+ ut_assertok(optee_fdt_protected_memory(uts));
- free(fdt);
- return ret;
+ return 0;
}
+OPTEE_TEST(optee_fdt_copy_already_filled, 0);
diff --git a/test/py/conftest.py b/test/py/conftest.py
index fc9dd3a83f8..5aea85647af 100644
--- a/test/py/conftest.py
+++ b/test/py/conftest.py
@@ -7,7 +7,7 @@
# test, at shutdown etc. These hooks perform functions such as:
# - Parsing custom command-line options.
# - Pullilng in user-specified board configuration.
-# - Creating the U-Boot console test fixture.
+# - Creating the ubman test fixture.
# - Creating the HTML log file.
# - Monitoring each test's results.
# - Implementing custom pytest markers.
@@ -23,14 +23,20 @@ from pathlib import Path
import pytest
import re
from _pytest.runner import runtestprotocol
+import subprocess
import sys
+from spawn import BootFail, Timeout, Unexpected, handle_exception
+import time
-# Globals: The HTML log file, and the connection to the U-Boot console.
+# Globals: The HTML log file, and the top-level fixture
log = None
-console = None
+ubman_fix = None
TEST_PY_DIR = os.path.dirname(os.path.abspath(__file__))
+# Regex for test-function symbols
+RE_UT_TEST_LIST = re.compile(r'[^a-zA-Z0-9_]_u_boot_list_2_ut_(.*)_2_(.*)\s*$')
+
def mkdir_p(path):
"""Create a directory path.
@@ -64,12 +70,16 @@ def pytest_addoption(parser):
parser.addoption('--build-dir', default=None,
help='U-Boot build directory (O=)')
+ parser.addoption('--build-dir-extra', default=None,
+ help='U-Boot build directory for extra build (O=)')
parser.addoption('--result-dir', default=None,
help='U-Boot test result/tmp directory')
parser.addoption('--persistent-data-dir', default=None,
help='U-Boot test persistent generated data directory')
parser.addoption('--board-type', '--bd', '-B', default='sandbox',
help='U-Boot board type')
+ parser.addoption('--board-type-extra', '--bde', default='sandbox',
+ help='U-Boot extra board type')
parser.addoption('--board-identity', '--id', default='na',
help='U-Boot board identity/instance')
parser.addoption('--build', default=False, action='store_true',
@@ -79,6 +89,12 @@ def pytest_addoption(parser):
parser.addoption('--gdbserver', default=None,
help='Run sandbox under gdbserver. The argument is the channel '+
'over which gdbserver should communicate, e.g. localhost:1234')
+ parser.addoption('--role', help='U-Boot board role (for Labgrid-sjg)')
+ parser.addoption('--use-running-system', default=False, action='store_true',
+ help="Assume that U-Boot is ready and don't wait for a prompt")
+ parser.addoption('--timing', default=False, action='store_true',
+ help='Show info on test timing')
+
def run_build(config, source_dir, build_dir, board_type, log):
"""run_build: Build U-Boot
@@ -115,14 +131,87 @@ def run_build(config, source_dir, build_dir, board_type, log):
runner.close()
log.status_pass('OK')
-def pytest_xdist_setupnodes(config, specs):
- """Clear out any 'done' file from a previous build"""
- global build_done_file
+def get_details(config):
+ """Obtain salient details about the board and directories to use
+
+ Args:
+ config (pytest.Config): pytest configuration
+
+ Returns:
+ tuple:
+ str: Board type (U-Boot build name)
+ str: Extra board type (where two U-Boot builds are needed)
+ str: Identity for the lab board
+ str: Build directory
+ str: Extra build directory (where two U-Boot builds are needed)
+ str: Source directory
+ """
+ role = config.getoption('role')
+
+ # Get a few provided parameters
build_dir = config.getoption('build_dir')
- board_type = config.getoption('board_type')
+ build_dir_extra = config.getoption('build_dir_extra')
+
+ # The source tree must be the current directory
source_dir = os.path.dirname(os.path.dirname(TEST_PY_DIR))
+ if role:
+ # When using a role, build_dir and build_dir_extra are normally not set,
+ # since they are picked up from Labgrid-sjg via the u-boot-test-getrole
+ # script
+ board_identity = role
+ cmd = ['u-boot-test-getrole', role, '--configure']
+ env = os.environ.copy()
+ if build_dir:
+ env['U_BOOT_BUILD_DIR'] = build_dir
+ if build_dir_extra:
+ env['U_BOOT_BUILD_DIR_EXTRA'] = build_dir_extra
+
+ # Make sure the script sees that it is being run from pytest
+ env['U_BOOT_SOURCE_DIR'] = source_dir
+
+ proc = subprocess.run(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT, encoding='utf-8',
+ env=env)
+ if proc.returncode:
+ raise ValueError(f"Error {proc.returncode} running {cmd}: '{proc.stderr} '{proc.stdout}'")
+ # For debugging
+ # print('conftest: lab:', proc.stdout)
+ vals = {}
+ for line in proc.stdout.splitlines():
+ item, value = line.split(' ', maxsplit=1)
+ k = item.split(':')[-1]
+ vals[k] = value
+ # For debugging
+ # print('conftest: lab info:', vals)
+
+ # Read the build directories here, in case none were provided in the
+ # command-line arguments
+ (board_type, board_type_extra, default_build_dir,
+ default_build_dir_extra) = (vals['board'],
+ vals['board_extra'], vals['build_dir'], vals['build_dir_extra'])
+ else:
+ board_type = config.getoption('board_type')
+ board_type_extra = config.getoption('board_type_extra')
+ board_identity = config.getoption('board_identity')
+
+ default_build_dir = source_dir + '/build-' + board_type
+ default_build_dir_extra = source_dir + '/build-' + board_type_extra
+
+ # Use the provided command-line arguments if present, else fall back to
if not build_dir:
- build_dir = source_dir + '/build-' + board_type
+ build_dir = default_build_dir
+ if not build_dir_extra:
+ build_dir_extra = default_build_dir_extra
+
+ return (board_type, board_type_extra, board_identity, build_dir,
+ build_dir_extra, source_dir)
+
+def pytest_xdist_setupnodes(config, specs):
+ """Clear out any 'done' file from a previous build"""
+ global build_done_file
+
+ build_dir = get_details(config)[3]
+
build_done_file = Path(build_dir) / 'build.done'
if build_done_file.exists():
os.remove(build_done_file)
@@ -158,20 +247,14 @@ def pytest_configure(config):
ubconfig.buildconfig.update(parser.items('root'))
global log
- global console
+ global ubman_fix
global ubconfig
- source_dir = os.path.dirname(os.path.dirname(TEST_PY_DIR))
+ (board_type, board_type_extra, board_identity, build_dir, build_dir_extra,
+ source_dir) = get_details(config)
- board_type = config.getoption('board_type')
board_type_filename = board_type.replace('-', '_')
-
- board_identity = config.getoption('board_identity')
board_identity_filename = board_identity.replace('-', '_')
-
- build_dir = config.getoption('build_dir')
- if not build_dir:
- build_dir = source_dir + '/build-' + board_type
mkdir_p(build_dir)
result_dir = config.getoption('result_dir')
@@ -206,19 +289,26 @@ def pytest_configure(config):
ubconfig = ArbitraryAttributeContainer()
ubconfig.brd = dict()
ubconfig.env = dict()
-
- modules = [
- (ubconfig.brd, 'u_boot_board_' + board_type_filename),
- (ubconfig.env, 'u_boot_boardenv_' + board_type_filename),
- (ubconfig.env, 'u_boot_boardenv_' + board_type_filename + '_' +
- board_identity_filename),
- ]
- for (dict_to_fill, module_name) in modules:
- try:
- module = __import__(module_name)
- except ImportError:
- continue
- dict_to_fill.update(module.__dict__)
+ not_found = []
+
+ with log.section('Loading lab modules', 'load_modules'):
+ modules = [
+ (ubconfig.brd, 'u_boot_board_' + board_type_filename),
+ (ubconfig.env, 'u_boot_boardenv_' + board_type_filename),
+ (ubconfig.env, 'u_boot_boardenv_' + board_type_filename + '_' +
+ board_identity_filename),
+ ]
+ for (dict_to_fill, module_name) in modules:
+ try:
+ module = __import__(module_name)
+ except ImportError:
+ not_found.append(module_name)
+ continue
+ dict_to_fill.update(module.__dict__)
+ log.info(f"Loaded {module}")
+
+ if not_found:
+ log.warning(f"Failed to find modules: {' '.join(not_found)}")
ubconfig.buildconfig = dict()
@@ -233,19 +323,27 @@ def pytest_configure(config):
ubconfig.test_py_dir = TEST_PY_DIR
ubconfig.source_dir = source_dir
ubconfig.build_dir = build_dir
+ ubconfig.build_dir_extra = build_dir_extra
ubconfig.result_dir = result_dir
ubconfig.persistent_data_dir = persistent_data_dir
ubconfig.board_type = board_type
+ ubconfig.board_type_extra = board_type_extra
ubconfig.board_identity = board_identity
ubconfig.gdbserver = gdbserver
+ ubconfig.use_running_system = config.getoption('use_running_system')
ubconfig.dtb = build_dir + '/arch/sandbox/dts/test.dtb'
+ ubconfig.connection_ok = True
+ ubconfig.timing = config.getoption('timing')
+ ubconfig.role = config.getoption('role')
env_vars = (
'board_type',
+ 'board_type_extra',
'board_identity',
'source_dir',
'test_py_dir',
'build_dir',
+ 'build_dir_extra',
'result_dir',
'persistent_data_dir',
)
@@ -253,13 +351,13 @@ def pytest_configure(config):
os.environ['U_BOOT_' + v.upper()] = getattr(ubconfig, v)
if board_type.startswith('sandbox'):
- import u_boot_console_sandbox
- console = u_boot_console_sandbox.ConsoleSandbox(log, ubconfig)
+ import console_sandbox
+ ubman_fix = console_sandbox.ConsoleSandbox(log, ubconfig)
else:
- import u_boot_console_exec_attach
- console = u_boot_console_exec_attach.ConsoleExecAttach(log, ubconfig)
+ import console_board
+ ubman_fix = console_board.ConsoleExecAttach(log, ubconfig)
+
-re_ut_test_list = re.compile(r'[^a-zA-Z0-9_]_u_boot_list_2_ut_(.*)_test_2_(.*)\s*$')
def generate_ut_subtest(metafunc, fixture_name, sym_path):
"""Provide parametrization for a ut_subtest fixture.
@@ -276,7 +374,7 @@ def generate_ut_subtest(metafunc, fixture_name, sym_path):
Returns:
Nothing.
"""
- fn = console.config.build_dir + sym_path
+ fn = ubman_fix.config.build_dir + sym_path
try:
with open(fn, 'rt') as f:
lines = f.readlines()
@@ -286,7 +384,7 @@ def generate_ut_subtest(metafunc, fixture_name, sym_path):
vals = []
for l in lines:
- m = re_ut_test_list.search(l)
+ m = RE_UT_TEST_LIST.search(l)
if not m:
continue
suite, name = m.groups()
@@ -317,8 +415,8 @@ def generate_config(metafunc, fixture_name):
"""
subconfigs = {
- 'brd': console.config.brd,
- 'env': console.config.env,
+ 'brd': ubman_fix.config.brd,
+ 'env': ubman_fix.config.env,
}
parts = fixture_name.split('__')
if len(parts) < 2:
@@ -380,7 +478,7 @@ def u_boot_log(request):
The fixture value.
"""
- return console.log
+ return ubman_fix.log
@pytest.fixture(scope='session')
def u_boot_config(request):
@@ -393,11 +491,11 @@ def u_boot_config(request):
The fixture value.
"""
- return console.config
+ return ubman_fix.config
@pytest.fixture(scope='function')
-def u_boot_console(request):
- """Generate the value of a test's u_boot_console fixture.
+def ubman(request):
+ """Generate the value of a test's ubman fixture.
Args:
request: The pytest request.
@@ -405,9 +503,22 @@ def u_boot_console(request):
Returns:
The fixture value.
"""
-
- console.ensure_spawned()
- return console
+ if not ubconfig.connection_ok:
+ pytest.skip('Cannot get target connection')
+ return None
+ try:
+ ubman_fix.ensure_spawned()
+ except OSError as err:
+ handle_exception(ubconfig, ubman_fix, log, err, 'Lab failure', True)
+ except Timeout as err:
+ handle_exception(ubconfig, ubman_fix, log, err, 'Lab timeout', True)
+ except BootFail as err:
+ handle_exception(ubconfig, ubman_fix, log, err, 'Boot fail', True,
+ ubman.get_spawn_output())
+ except Unexpected:
+ handle_exception(ubconfig, ubman_fix, log, err, 'Unexpected test output',
+ False)
+ return ubman_fix
anchors = {}
tests_not_run = []
@@ -418,6 +529,12 @@ tests_skipped = []
tests_warning = []
tests_passed = []
+# Duration of each test:
+# key (string): test name
+# value (float): duration in ms
+test_durations = {}
+
+
def pytest_itemcollected(item):
"""pytest hook: Called once for each test found during collection.
@@ -433,6 +550,73 @@ def pytest_itemcollected(item):
tests_not_run.append(item.name)
+
+def show_timings():
+ """Write timings for each test, along with a histogram"""
+
+ def get_time_delta(msecs):
+ """Convert milliseconds into a user-friendly string"""
+ if msecs >= 1000:
+ return f'{msecs / 1000:.1f}s'
+ else:
+ return f'{msecs:.0f}ms'
+
+ def show_bar(key, msecs, value):
+ """Show a single bar (line) of the histogram
+
+ Args:
+ key (str): Key to write on the left
+ value (int): Value to display, i.e. the relative length of the bar
+ """
+ if value:
+ bar_length = int((value / max_count) * max_bar_length)
+ print(f"{key:>8} : {get_time_delta(msecs):>7} |{'#' * bar_length} {value}", file=buf)
+
+ # Create the buckets we will use, each has a count and a total time
+ bucket = {}
+ for power in range(5):
+ for i in [1, 2, 3, 4, 5, 7.5]:
+ bucket[i * 10 ** power] = {'count': 0, 'msecs': 0.0}
+ max_dur = max(bucket.keys())
+
+ # Collect counts for each bucket; if outside the range, add to too_long
+ # Also show a sorted list of test timings from longest to shortest
+ too_long = 0
+ too_long_msecs = 0.0
+ max_count = 0
+ with log.section('Timing Report', 'timing_report'):
+ for name, dur in sorted(test_durations.items(), key=lambda kv: kv[1],
+ reverse=True):
+ log.info(f'{get_time_delta(dur):>8} {name}')
+ greater = [k for k in bucket.keys() if dur <= k]
+ if greater:
+ buck = bucket[min(greater)]
+ buck['count'] += 1
+ max_count = max(max_count, buck['count'])
+ buck['msecs'] += dur
+ else:
+ too_long += 1
+ too_long_msecs += dur
+
+ # Set the maximum length of a histogram bar, in characters
+ max_bar_length = 40
+
+ # Show a a summary with histogram
+ buf = io.StringIO()
+ with log.section('Timing Summary', 'timing_summary'):
+ print('Duration : Total | Number of tests', file=buf)
+ print(f'{"=" * 8} : {"=" * 7} |{"=" * max_bar_length}', file=buf)
+ for dur, buck in bucket.items():
+ if buck['count']:
+ label = get_time_delta(dur)
+ show_bar(f'<{label}', buck['msecs'], buck['count'])
+ if too_long:
+ show_bar(f'>{get_time_delta(max_dur)}', too_long_msecs, too_long)
+ log.info(buf.getvalue())
+ if ubconfig.timing:
+ print(buf.getvalue(), end='')
+
+
def cleanup():
"""Clean up all global state.
@@ -447,8 +631,8 @@ def cleanup():
Nothing.
"""
- if console:
- console.close()
+ if ubman_fix:
+ ubman_fix.close()
if log:
with log.section('Status Report', 'status_report'):
log.status_pass('%d passed' % len(tests_passed))
@@ -482,6 +666,7 @@ def cleanup():
for test in tests_not_run:
anchor = anchors.get(test, None)
log.status_fail('... ' + test, anchor)
+ show_timings()
log.close()
atexit.register(cleanup)
@@ -576,6 +761,26 @@ def setup_singlethread(item):
if worker_id and worker_id != 'master':
pytest.skip('must run single-threaded')
+def setup_role(item):
+ """Process any 'role' marker for a test.
+
+ Skip this test if the role does not match.
+
+ Args:
+ item (pytest.Item): The pytest test item
+ """
+ required_roles = []
+ for roles in item.iter_markers('role'):
+ role = roles.args[0]
+ if role.startswith('!'):
+ if ubconfig.role == role[1:]:
+ pytest.skip(f'role "{ubconfig.role}" not supported')
+ return
+ else:
+ required_roles.append(role)
+ if required_roles and ubconfig.role not in required_roles:
+ pytest.skip(f'board "{ubconfig.role}" not supported')
+
def start_test_section(item):
anchors[item.name] = log.start_section(item.name)
@@ -597,6 +802,7 @@ def pytest_runtest_setup(item):
setup_buildconfigspec(item)
setup_requiredtool(item)
setup_singlethread(item)
+ setup_role(item)
def pytest_runtest_protocol(item, nextitem):
"""pytest hook: Called to execute a test.
@@ -615,7 +821,9 @@ def pytest_runtest_protocol(item, nextitem):
log.get_and_reset_warning()
ihook = item.ihook
ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location)
+ start = time.monotonic()
reports = runtestprotocol(item, nextitem=nextitem)
+ duration = round((time.monotonic() - start) * 1000, 1)
ihook.pytest_runtest_logfinish(nodeid=item.nodeid, location=item.location)
was_warning = log.get_and_reset_warning()
@@ -628,6 +836,7 @@ def pytest_runtest_protocol(item, nextitem):
start_test_section(item)
failure_cleanup = False
+ record_duration = True
if not was_warning:
test_list = tests_passed
msg = 'OK'
@@ -658,9 +867,14 @@ def pytest_runtest_protocol(item, nextitem):
test_list = tests_skipped
msg = 'SKIPPED:\n' + str(report.longrepr)
msg_log = log.status_skipped
+ record_duration = False
+
+ msg += f' {duration} ms'
+ if record_duration:
+ test_durations[item.name] = duration
if failure_cleanup:
- console.drain_console()
+ ubman_fix.drain_console()
test_list.append(item.name)
tests_not_run.remove(item.name)
@@ -670,7 +884,7 @@ def pytest_runtest_protocol(item, nextitem):
except:
# If something went wrong with logging, it's better to let the test
# process continue, which may report other exceptions that triggered
- # the logging issue (e.g. console.log wasn't created). Hence, just
+ # the logging issue (e.g. ubman_fix.log wasn't created). Hence, just
# squash the exception. If the test setup failed due to e.g. syntax
# error somewhere else, this won't be seen. However, once that issue
# is fixed, if this exception still exists, it will then be logged as
@@ -683,6 +897,6 @@ def pytest_runtest_protocol(item, nextitem):
log.end_section(item.name)
if failure_cleanup:
- console.cleanup_spawn()
+ ubman_fix.cleanup_spawn()
return True
diff --git a/test/py/u_boot_console_base.py b/test/py/console_base.py
index 26b6de07f88..88d444b44b8 100644
--- a/test/py/u_boot_console_base.py
+++ b/test/py/console_base.py
@@ -13,23 +13,35 @@ import os
import pytest
import re
import sys
-import u_boot_spawn
+import spawn
+from spawn import BootFail, Timeout, Unexpected, handle_exception
# Regexes for text we expect U-Boot to send to the console.
pattern_u_boot_spl_signon = re.compile('(U-Boot SPL \\d{4}\\.\\d{2}[^\r\n]*\\))')
-pattern_u_boot_spl2_signon = re.compile('(U-Boot SPL \\d{4}\\.\\d{2}[^\r\n]*\\))')
pattern_u_boot_main_signon = re.compile('(U-Boot \\d{4}\\.\\d{2}[^\r\n]*\\))')
pattern_stop_autoboot_prompt = re.compile('Hit any key to stop autoboot: ')
pattern_unknown_command = re.compile('Unknown command \'.*\' - try \'help\'')
pattern_error_notification = re.compile('## Error: ')
pattern_error_please_reset = re.compile('### ERROR ### Please RESET the board ###')
+pattern_ready_prompt = re.compile('{lab ready in (.*)s: (.*)}')
+pattern_lab_mode = re.compile('{lab mode.*}')
PAT_ID = 0
PAT_RE = 1
+# Timeout before expecting the console to be ready (in milliseconds)
+TIMEOUT_MS = 30000 # Standard timeout
+TIMEOUT_CMD_MS = 10000 # Command-echo timeout
+
+# Timeout for board preparation in lab mode. This needs to be enough to build
+# U-Boot, write it to the board and then boot the board. Since this process is
+# under the control of another program (e.g. Labgrid), it will failure sooner
+# if something goes way. So use a very long timeout here to cover all possible
+# situations.
+TIMEOUT_PREPARE_MS = 3 * 60 * 1000
+
bad_pattern_defs = (
('spl_signon', pattern_u_boot_spl_signon),
- ('spl2_signon', pattern_u_boot_spl2_signon),
('main_signon', pattern_u_boot_main_signon),
('stop_autoboot_prompt', pattern_stop_autoboot_prompt),
('unknown_command', pattern_unknown_command),
@@ -57,6 +69,32 @@ class ConsoleDisableCheck(object):
self.console.disable_check_count[self.check_type] -= 1
self.console.eval_bad_patterns()
+class ConsoleEnableCheck(object):
+ """Context manager (for Python's with statement) that temporarily enables
+ the specified console output error check. This is useful when executing a
+ command that might raise an extra bad pattern, beyond the default bad
+ patterns, in order to validate that the extra bad pattern is actually
+ detected. This class is used internally by ConsoleBase::enable_check(); it
+ is not intended for direct usage."""
+
+ def __init__(self, console, check_type, check_pattern):
+ self.console = console
+ self.check_type = check_type
+ self.check_pattern = check_pattern
+
+ def __enter__(self):
+ global bad_pattern_defs
+ self.default_bad_patterns = bad_pattern_defs
+ bad_pattern_defs += ((self.check_type, self.check_pattern),)
+ self.console.disable_check_count = {pat[PAT_ID]: 0 for pat in bad_pattern_defs}
+ self.console.eval_bad_patterns()
+
+ def __exit__(self, extype, value, traceback):
+ global bad_pattern_defs
+ bad_pattern_defs = self.default_bad_patterns
+ self.console.disable_check_count = {pat[PAT_ID]: 0 for pat in bad_pattern_defs}
+ self.console.eval_bad_patterns()
+
class ConsoleSetupTimeout(object):
"""Context manager (for Python's with statement) that temporarily sets up
timeout for specific command. This is useful when execution time is greater
@@ -85,7 +123,7 @@ class ConsoleBase(object):
Can only usefully be called by sub-classes.
Args:
- log: A mulptiplex_log.Logfile object, to which the U-Boot output
+ log: A multiplexed_log.Logfile object, to which the U-Boot output
will be logged.
config: A configuration data structure, as built by conftest.py.
max_fifo_fill: The maximum number of characters to send to U-Boot
@@ -114,13 +152,14 @@ class ConsoleBase(object):
self.at_prompt = False
self.at_prompt_logevt = None
+ self.lab_mode = False
def get_spawn(self):
# This is not called, ssubclass must define this.
# Return a value to avoid:
- # u_boot_console_base.py:348:12: E1128: Assigning result of a function
+ # console_base.py:348:12: E1128: Assigning result of a function
# call, where the function returns None (assignment-from-none)
- return u_boot_spawn.Spawn([])
+ return spawn.Spawn([])
def eval_bad_patterns(self):
@@ -144,53 +183,76 @@ class ConsoleBase(object):
"""
if self.p:
- self.p.close()
+ self.log.start_section('Stopping U-Boot')
+ close_type = self.p.close()
+ self.log.info(f'Close type: {close_type}')
+ self.log.end_section('Stopping U-Boot')
self.logstream.close()
+ def set_lab_mode(self):
+ """Select lab mode
+
+ This tells us that we will get a 'lab ready' message when the board is
+ ready for use. We don't need to look for signon messages.
+ """
+ self.log.info(f'test.py: Lab mode is active')
+ self.p.timeout = TIMEOUT_PREPARE_MS
+ self.lab_mode = True
+
def wait_for_boot_prompt(self, loop_num = 1):
"""Wait for the boot up until command prompt. This is for internal use only.
"""
try:
+ self.log.info('Waiting for U-Boot to be ready')
bcfg = self.config.buildconfig
- config_spl = bcfg.get('config_spl', 'n') == 'y'
config_spl_serial = bcfg.get('config_spl_serial', 'n') == 'y'
env_spl_skipped = self.config.env.get('env__spl_skipped', False)
- env_spl2_skipped = self.config.env.get('env__spl2_skipped', True)
+ env_spl_banner_times = self.config.env.get('env__spl_banner_times', 1)
- while loop_num > 0:
+ while not self.lab_mode and loop_num > 0:
loop_num -= 1
- if config_spl and config_spl_serial and not env_spl_skipped:
- m = self.p.expect([pattern_u_boot_spl_signon] +
- self.bad_patterns)
- if m != 0:
- raise Exception('Bad pattern found on SPL console: ' +
- self.bad_pattern_ids[m - 1])
- if not env_spl2_skipped:
- m = self.p.expect([pattern_u_boot_spl2_signon] +
- self.bad_patterns)
- if m != 0:
- raise Exception('Bad pattern found on SPL2 console: ' +
- self.bad_pattern_ids[m - 1])
- m = self.p.expect([pattern_u_boot_main_signon] + self.bad_patterns)
- if m != 0:
- raise Exception('Bad pattern found on console: ' +
- self.bad_pattern_ids[m - 1])
- self.u_boot_version_string = self.p.after
+ while config_spl_serial and not env_spl_skipped and env_spl_banner_times > 0:
+ m = self.p.expect([pattern_u_boot_spl_signon,
+ pattern_lab_mode] + self.bad_patterns)
+ if m == 1:
+ self.set_lab_mode()
+ break
+ elif m != 0:
+ raise BootFail('Bad pattern found on SPL console: ' +
+ self.bad_pattern_ids[m - 1])
+ env_spl_banner_times -= 1
+
+ if not self.lab_mode:
+ m = self.p.expect([pattern_u_boot_main_signon,
+ pattern_lab_mode] + self.bad_patterns)
+ if m == 1:
+ self.set_lab_mode()
+ elif m != 0:
+ raise BootFail('Bad pattern found on console: ' +
+ self.bad_pattern_ids[m - 1])
+ if not self.lab_mode:
+ self.u_boot_version_string = self.p.after
while True:
- m = self.p.expect([self.prompt_compiled,
+ m = self.p.expect([self.prompt_compiled, pattern_ready_prompt,
pattern_stop_autoboot_prompt] + self.bad_patterns)
if m == 0:
+ self.log.info(f'Found ready prompt {m}')
break
- if m == 1:
+ elif m == 1:
+ m = pattern_ready_prompt.search(self.p.after)
+ self.u_boot_version_string = m.group(2)
+ self.log.info(f'Lab: Board is ready')
+ self.p.timeout = TIMEOUT_MS
+ break
+ if m == 2:
+ self.log.info(f'Found autoboot prompt {m}')
self.p.send(' ')
continue
- raise Exception('Bad pattern found on console: ' +
- self.bad_pattern_ids[m - 2])
+ if not self.lab_mode:
+ raise BootFail('Missing prompt / ready message on console: ' +
+ self.bad_pattern_ids[m - 3])
+ self.log.info(f'U-Boot is ready')
- except Exception as ex:
- self.log.error(str(ex))
- self.cleanup_spawn()
- raise
finally:
self.log.timestamp()
@@ -242,22 +304,28 @@ class ConsoleBase(object):
try:
self.at_prompt = False
+ if not self.p:
+ raise BootFail(
+ f"Lab failure: Connection lost when sending command '{cmd}'")
+
if send_nl:
cmd += '\n'
- while cmd:
- # Limit max outstanding data, so UART FIFOs don't overflow
- chunk = cmd[:self.max_fifo_fill]
- cmd = cmd[self.max_fifo_fill:]
- self.p.send(chunk)
- if not wait_for_echo:
- continue
- chunk = re.escape(chunk)
- chunk = chunk.replace('\\\n', '[\r\n]')
- m = self.p.expect([chunk] + self.bad_patterns)
- if m != 0:
- self.at_prompt = False
- raise Exception('Bad pattern found on console: ' +
- self.bad_pattern_ids[m - 1])
+ rem = cmd # Remaining to be sent
+ with self.temporary_timeout(TIMEOUT_CMD_MS):
+ while rem:
+ # Limit max outstanding data, so UART FIFOs don't overflow
+ chunk = rem[:self.max_fifo_fill]
+ rem = rem[self.max_fifo_fill:]
+ self.p.send(chunk)
+ if not wait_for_echo:
+ continue
+ chunk = re.escape(chunk)
+ chunk = chunk.replace('\\\n', '[\r\n]')
+ m = self.p.expect([chunk] + self.bad_patterns)
+ if m != 0:
+ self.at_prompt = False
+ raise BootFail(f"Failed to get echo on console (cmd '{cmd}':rem '{rem}'): " +
+ self.bad_pattern_ids[m - 1])
if not wait_for_prompt:
return
if wait_for_reboot:
@@ -266,16 +334,21 @@ class ConsoleBase(object):
m = self.p.expect([self.prompt_compiled] + self.bad_patterns)
if m != 0:
self.at_prompt = False
- raise Exception('Bad pattern found on console: ' +
+ raise BootFail('Missing prompt on console: ' +
self.bad_pattern_ids[m - 1])
self.at_prompt = True
self.at_prompt_logevt = self.logstream.logfile.cur_evt
# Only strip \r\n; space/TAB might be significant if testing
# indentation.
return self.p.before.strip('\r\n')
- except Exception as ex:
- self.log.error(str(ex))
- self.cleanup_spawn()
+ except Timeout as exc:
+ handle_exception(self.config, self, self.log, exc,
+ f"Lab failure: Timeout executing '{cmd}'", True)
+ raise
+ except BootFail as exc:
+ handle_exception(self.config, self, self.log, exc,
+ f"'Boot fail '{cmd}'",
+ True, self.get_spawn_output())
raise
finally:
self.log.timestamp()
@@ -297,21 +370,30 @@ class ConsoleBase(object):
output.append(self.run_command(cmd))
return output
- def ctrlc(self):
- """Send a CTRL-C character to U-Boot.
+ def send(self, msg):
+ """Send characters without waiting for echo, etc."""
+ self.run_command(msg, wait_for_prompt=False, wait_for_echo=False,
+ send_nl=False)
+
+ def ctrl(self, char):
+ """Send a CTRL- character to U-Boot.
This is useful in order to stop execution of long-running synchronous
commands such as "ums".
Args:
- None.
-
- Returns:
- Nothing.
+ char (str): Character to send, e.g. 'C' to send Ctrl-C
"""
+ self.log.action(f'Sending Ctrl-{char}')
+ self.send(chr(ord(char) - ord('@')))
+
+ def ctrlc(self):
+ """Send a CTRL-C character to U-Boot.
- self.log.action('Sending Ctrl-C')
- self.run_command(chr(3), wait_for_echo=False, send_nl=False)
+ This is useful in order to stop execution of long-running synchronous
+ commands such as "ums".
+ """
+ self.ctrl('C')
def wait_for(self, text):
"""Wait for a pattern to be emitted by U-Boot.
@@ -332,8 +414,9 @@ class ConsoleBase(object):
text = re.escape(text)
m = self.p.expect([text] + self.bad_patterns)
if m != 0:
- raise Exception('Bad pattern found on console: ' +
- self.bad_pattern_ids[m - 1])
+ raise Unexpected(
+ "Unexpected pattern found on console (exp '{text}': " +
+ self.bad_pattern_ids[m - 1])
def drain_console(self):
"""Read from and log the U-Boot console for a short time.
@@ -403,7 +486,7 @@ class ConsoleBase(object):
# Reset the console timeout value as some tests may change
# its default value during the execution
if not self.config.gdbserver:
- self.p.timeout = 30000
+ self.p.timeout = TIMEOUT_MS
return
try:
self.log.start_section('Starting U-Boot')
@@ -414,13 +497,19 @@ class ConsoleBase(object):
# future, possibly per-test to be optimal. This works for 'help'
# on board 'seaboard'.
if not self.config.gdbserver:
- self.p.timeout = 30000
+ self.p.timeout = TIMEOUT_MS
self.p.logfile_read = self.logstream
- if expect_reset:
- loop_num = 2
+ if self.config.use_running_system:
+ # Send an empty command to set up the 'expect' logic. This has
+ # the side effect of ensuring that there was no partial command
+ # line entered
+ self.run_command(' ')
else:
- loop_num = 1
- self.wait_for_boot_prompt(loop_num = loop_num)
+ if expect_reset:
+ loop_num = 2
+ else:
+ loop_num = 1
+ self.wait_for_boot_prompt(loop_num = loop_num)
self.at_prompt = True
self.at_prompt_logevt = self.logstream.logfile.cur_evt
except Exception as ex:
@@ -499,6 +588,24 @@ class ConsoleBase(object):
return ConsoleDisableCheck(self, check_type)
+ def enable_check(self, check_type, check_pattern):
+ """Temporarily enable an error check of U-Boot's output.
+
+ Create a new context manager (for use with the "with" statement) which
+ temporarily enables a particular console output error check. The
+ arguments form a new element of bad_pattern_defs defined above.
+
+ Args:
+ check_type: The type of error-check or bad pattern to enable.
+ check_pattern: The regexes for text error pattern or bad pattern
+ to be checked.
+
+ Returns:
+ A context manager object.
+ """
+
+ return ConsoleEnableCheck(self, check_type, check_pattern)
+
def temporary_timeout(self, timeout):
"""Temporarily set up different timeout for commands.
diff --git a/test/py/u_boot_console_exec_attach.py b/test/py/console_board.py
index 8dd8cc1230c..bacb1e2526c 100644
--- a/test/py/u_boot_console_exec_attach.py
+++ b/test/py/console_board.py
@@ -8,8 +8,8 @@ physical serial port.
"""
import sys
-from u_boot_spawn import Spawn
-from u_boot_console_base import ConsoleBase
+from spawn import Spawn
+from console_base import ConsoleBase
class ConsoleExecAttach(ConsoleBase):
"""Represents a physical connection to a U-Boot console, typically via a
@@ -53,20 +53,33 @@ class ConsoleExecAttach(ConsoleBase):
None.
Returns:
- A u_boot_spawn.Spawn object that is attached to U-Boot.
+ A spawn.Spawn object that is attached to U-Boot.
"""
args = [self.config.board_type, self.config.board_identity]
s = Spawn(['u-boot-test-console'] + args)
- try:
- self.log.action('Resetting board')
- cmd = ['u-boot-test-reset'] + args
- runner = self.log.get_runner(cmd[0], sys.stdout)
- runner.run(cmd)
- runner.close()
- except:
- s.close()
- raise
+ if self.config.use_running_system:
+ self.log.action('Connecting to board without reset')
+ else:
+ try:
+ self.log.action('Resetting board')
+ cmd = ['u-boot-test-reset'] + args
+ runner = self.log.get_runner(cmd[0], sys.stdout)
+ runner.run(cmd)
+ runner.close()
+ except:
+ s.close()
+ raise
return s
+
+ def close(self):
+ super().close()
+
+ self.log.action('Releasing board')
+ args = [self.config.board_type, self.config.board_identity]
+ cmd = ['u-boot-test-release'] + args
+ runner = self.log.get_runner(cmd[0], sys.stdout)
+ runner.run(cmd)
+ runner.close()
diff --git a/test/py/u_boot_console_sandbox.py b/test/py/console_sandbox.py
index 27c6db8d719..da55d2fcc1f 100644
--- a/test/py/u_boot_console_sandbox.py
+++ b/test/py/console_sandbox.py
@@ -7,8 +7,8 @@ Logic to interact with the sandbox port of U-Boot, running as a sub-process.
"""
import time
-from u_boot_spawn import Spawn
-from u_boot_console_base import ConsoleBase
+from spawn import Spawn
+from console_base import ConsoleBase
class ConsoleSandbox(ConsoleBase):
"""Represents a connection to a sandbox U-Boot console, executed as a sub-
@@ -39,7 +39,7 @@ class ConsoleSandbox(ConsoleBase):
None.
Returns:
- A u_boot_spawn.Spawn object that is attached to U-Boot.
+ A spawn.Spawn object that is attached to U-Boot.
"""
bcfg = self.config.buildconfig
@@ -58,7 +58,7 @@ class ConsoleSandbox(ConsoleBase):
if self.use_dtb:
cmd += ['-d', self.config.dtb]
cmd += self.sandbox_flags
- return Spawn(cmd, cwd=self.config.source_dir)
+ return Spawn(cmd, cwd=self.config.source_dir, decode_signal=True)
def restart_uboot_with_flags(self, flags, expect_reset=False, use_dtb=True):
"""Run U-Boot with the given command-line flags
@@ -71,7 +71,7 @@ class ConsoleSandbox(ConsoleBase):
use_dtb: True to use a device tree file, False to run without one
Returns:
- A u_boot_spawn.Spawn object that is attached to U-Boot.
+ A spawn.Spawn object that is attached to U-Boot.
"""
try:
diff --git a/test/py/pytest.ini b/test/py/pytest.ini
index 26d83f83e00..361be0178ee 100644
--- a/test/py/pytest.ini
+++ b/test/py/pytest.ini
@@ -12,3 +12,4 @@ markers =
requiredtool: U-Boot: Required host tools for a test.
slow: U-Boot: Specific test will run slowly.
singlethread: Cannot run in parallel
+ role: U-Boot: Indicates the lab 'role' which can execute this test
diff --git a/test/py/requirements.txt b/test/py/requirements.txt
index 0f67c3c6194..804a427b351 100644
--- a/test/py/requirements.txt
+++ b/test/py/requirements.txt
@@ -1,30 +1,5 @@
-atomicwrites==1.4.1
-attrs==19.3.0
-concurrencytest==0.1.2
-coverage==4.5.4
-extras==1.0.0
filelock==3.0.12
-fixtures==3.0.0
-importlib-metadata==0.23
-linecache2==1.0.0
-more-itertools==7.2.0
-packaging==23.2
-pbr==5.4.3
-pluggy==0.13.0
-py==1.11.0
-pycryptodomex==3.19.1
-pyelftools==0.27
-pygit2==1.13.3
-pyparsing==3.0.7
+pycryptodomex==3.21.0
pytest==6.2.5
pytest-xdist==2.5.0
-python-mimeparse==1.6.0
-python-subunit==1.3.0
-requests==2.31.0
-setuptools==65.5.1
-six==1.16.0
-testtools==2.3.0
-traceback2==1.4.0
-unittest2==1.1.0
-wcwidth==0.1.7
-zipp==0.6.0
+FATtools==1.0.42
diff --git a/test/py/u_boot_spawn.py b/test/py/spawn.py
index 7c48d96210e..c703454389d 100644
--- a/test/py/u_boot_spawn.py
+++ b/test/py/spawn.py
@@ -5,17 +5,72 @@
Logic to spawn a sub-process and interact with its stdio.
"""
+import io
import os
import re
import pty
+import pytest
import signal
import select
+import sys
+import termios
import time
import traceback
+# Character to send (twice) to exit the terminal
+EXIT_CHAR = 0x1d # FS (Ctrl + ])
+
class Timeout(Exception):
"""An exception sub-class that indicates that a timeout occurred."""
+class BootFail(Exception):
+ """An exception sub-class that indicates that a boot failure occurred.
+
+ This is used when a bad pattern is seen when waiting for the boot prompt.
+ It is regarded as fatal, to avoid trying to boot the again and again to no
+ avail.
+ """
+
+class Unexpected(Exception):
+ """An exception sub-class that indicates that unexpected test was seen."""
+
+
+def handle_exception(ubconfig, console, log, err, name, fatal, output=''):
+ """Handle an exception from the console
+
+ Exceptions can occur when there is unexpected output or due to the board
+ crashing or hanging. Some exceptions are likely fatal, where retrying will
+ just chew up time to no available. In those cases it is best to cause
+ further tests be skipped.
+
+ Args:
+ ubconfig (ArbitraryAttributeContainer): ubconfig object
+ log (Logfile): Place to log errors
+ console (ConsoleBase): Console to clean up, if fatal
+ err (Exception): Exception which was thrown
+ name (str): Name of problem, to log
+ fatal (bool): True to abort all tests
+ output (str): Extra output to report on boot failure. This can show the
+ target's console output as it tried to boot
+ """
+ msg = f'{name}: '
+ if fatal:
+ msg += 'Marking connection bad - no other tests will run'
+ else:
+ msg += 'Assuming that lab is healthy'
+ print(msg)
+ log.error(msg)
+ log.error(f'Error: {err}')
+
+ if output:
+ msg += f'; output {output}'
+
+ if fatal:
+ ubconfig.connection_ok = False
+ console.cleanup_spawn()
+ pytest.exit(msg)
+
+
class Spawn:
"""Represents the stdio of a freshly created sub-process. Commands may be
sent to the process, and responses waited for.
@@ -24,18 +79,20 @@ class Spawn:
output: accumulated output from expect()
"""
- def __init__(self, args, cwd=None):
+ def __init__(self, args, cwd=None, decode_signal=False):
"""Spawn (fork/exec) the sub-process.
Args:
args: array of processs arguments. argv[0] is the command to
execute.
cwd: the directory to run the process in, or None for no change.
+ decode_signal (bool): True to indicate the exception number when
+ something goes wrong
Returns:
Nothing.
"""
-
+ self.decode_signal = decode_signal
self.waited = False
self.exit_code = 0
self.exit_info = ''
@@ -64,11 +121,30 @@ class Spawn:
finally:
os._exit(255)
+ old = None
try:
+ isatty = False
+ try:
+ isatty = os.isatty(sys.stdout.fileno())
+
+ # with --capture=tee-sys we cannot call fileno()
+ except io.UnsupportedOperation as exc:
+ pass
+ if isatty:
+ new = termios.tcgetattr(self.fd)
+ old = new
+ new[3] = new[3] & ~(termios.ICANON | termios.ISIG)
+ new[3] = new[3] & ~termios.ECHO
+ new[6][termios.VMIN] = 0
+ new[6][termios.VTIME] = 0
+ termios.tcsetattr(self.fd, termios.TCSANOW, new)
+
self.poll = select.poll()
self.poll.register(self.fd, select.POLLIN | select.POLLPRI | select.POLLERR |
select.POLLHUP | select.POLLNVAL)
except:
+ if old:
+ termios.tcsetattr(self.fd, termios.TCSANOW, old)
self.close()
raise
@@ -135,6 +211,32 @@ class Spawn:
os.write(self.fd, data.encode(errors='replace'))
+ def receive(self, num_bytes):
+ """Receive data from the sub-process's stdin.
+
+ Args:
+ num_bytes (int): Maximum number of bytes to read
+
+ Returns:
+ str: The data received
+
+ Raises:
+ ValueError if U-Boot died
+ """
+ try:
+ c = os.read(self.fd, num_bytes).decode(errors='replace')
+ except OSError as err:
+ # With sandbox, try to detect when U-Boot exits when it
+ # shouldn't and explain why. This is much more friendly than
+ # just dying with an I/O error
+ if self.decode_signal and err.errno == 5: # I/O error
+ alive, _, info = self.checkalive()
+ if alive:
+ raise err
+ raise ValueError('U-Boot exited with %s' % info)
+ raise
+ return c
+
def expect(self, patterns):
"""Wait for the sub-process to emit specific data.
@@ -191,18 +293,7 @@ class Spawn:
events = self.poll.poll(poll_maxwait)
if not events:
raise Timeout()
- try:
- c = os.read(self.fd, 1024).decode(errors='replace')
- except OSError as err:
- # With sandbox, try to detect when U-Boot exits when it
- # shouldn't and explain why. This is much more friendly than
- # just dying with an I/O error
- if err.errno == 5: # Input/output error
- alive, _, info = self.checkalive()
- if alive:
- raise err
- raise ValueError('U-Boot exited with %s' % info)
- raise err
+ c = self.receive(1024)
if self.logfile_read:
self.logfile_read.write(c)
self.buf += c
@@ -223,15 +314,28 @@ class Spawn:
None.
Returns:
- Nothing.
+ str: Type of closure completed
"""
-
+ # For Labgrid-sjg, ask it is exit gracefully, so it can transition the
+ # board to the final state (like 'off') before exiting.
+ if os.environ.get('USE_LABGRID_SJG'):
+ self.send(chr(EXIT_CHAR) * 2)
+
+ # Wait about 10 seconds for Labgrid to close and power off the board
+ for _ in range(100):
+ if not self.isalive():
+ return 'normal'
+ time.sleep(0.1)
+
+ # That didn't work, so try closing the PTY
os.close(self.fd)
for _ in range(100):
if not self.isalive():
- break
+ return 'break'
time.sleep(0.1)
+ return 'timeout'
+
def get_expect_output(self):
"""Return the output read by expect()
diff --git a/test/py/tests/bootstd/mmc1.img.xz b/test/py/tests/bootstd/mmc1.img.xz
deleted file mode 100644
index cebf7b9c53b..00000000000
--- a/test/py/tests/bootstd/mmc1.img.xz
+++ /dev/null
Binary files differ
diff --git a/test/py/tests/bootstd/mmc4.img.xz b/test/py/tests/bootstd/mmc4.img.xz
deleted file mode 100644
index f4db011969f..00000000000
--- a/test/py/tests/bootstd/mmc4.img.xz
+++ /dev/null
Binary files differ
diff --git a/test/py/tests/fit_util.py b/test/py/tests/fit_util.py
index 79718d431a0..f322b50a319 100644
--- a/test/py/tests/fit_util.py
+++ b/test/py/tests/fit_util.py
@@ -5,25 +5,25 @@
import os
-import u_boot_utils as util
+import utils
-def make_fname(cons, basename):
+def make_fname(ubman, basename):
"""Make a temporary filename
Args:
- cons (ConsoleBase): u_boot_console to use
+ ubman (ConsoleBase): ubman 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)
+ return os.path.join(ubman.config.build_dir, basename)
-def make_its(cons, base_its, params, basename='test.its'):
+def make_its(ubman, base_its, params, basename='test.its'):
"""Make a sample .its file with parameters embedded
Args:
- cons (ConsoleBase): u_boot_console to use
+ ubman (ConsoleBase): ubman to use
base_its (str): Template text for the .its file, typically containing
%() references
params (dict of str): Parameters to embed in the %() strings
@@ -31,19 +31,19 @@ def make_its(cons, base_its, params, basename='test.its'):
Returns:
str: Filename of .its file created
"""
- its = make_fname(cons, basename)
+ its = make_fname(ubman, 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):
+def make_fit(ubman, 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
+ ubman (ConsoleBase): ubman to use
mkimage (str): Filename of 'mkimage' utility
base_its (str): Template text for the .its file, typically containing
%() references
@@ -52,25 +52,25 @@ def make_fit(cons, mkimage, base_its, params, basename='test.fit', base_fdt=None
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])
+ fit = make_fname(ubman, basename)
+ its = make_its(ubman, base_its, params)
+ utils.run_and_log(ubman, [mkimage, '-f', its, fit])
if base_fdt:
- with open(make_fname(cons, 'u-boot.dts'), 'w') as fd:
+ with open(make_fname(ubman, 'u-boot.dts'), 'w') as fd:
fd.write(base_fdt)
return fit
-def make_kernel(cons, basename, text):
+def make_kernel(ubman, basename, text):
"""Make a sample kernel with test data
Args:
- cons (ConsoleBase): u_boot_console to use
+ ubman (ConsoleBase): ubman 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)
+ fname = make_fname(ubman, basename)
data = ''
for i in range(100):
data += f'this {text} {i} is unlikely to boot\n'
@@ -78,16 +78,16 @@ def make_kernel(cons, basename, text):
print(data, file=outf)
return fname
-def make_dtb(cons, base_fdt, basename):
+def make_dtb(ubman, base_fdt, basename):
"""Make a sample .dts file and compile it to a .dtb
Returns:
- cons (ConsoleBase): u_boot_console to use
+ ubman (ConsoleBase): ubman to use
Filename of .dtb file created
"""
- src = make_fname(cons, f'{basename}.dts')
- dtb = make_fname(cons, f'{basename}.dtb')
+ src = make_fname(ubman, f'{basename}.dts')
+ dtb = make_fname(ubman, 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])
+ utils.run_and_log(ubman, ['dtc', src, '-O', 'dtb', '-o', dtb])
return dtb
diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py
index 380f4c4dca3..b8a22b22806 100644
--- a/test/py/tests/fs_helper.py
+++ b/test/py/tests/fs_helper.py
@@ -9,7 +9,7 @@ import re
import os
from subprocess import call, check_call, check_output, CalledProcessError
-def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000):
+def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000):
"""Create a file system volume
Args:
@@ -17,6 +17,7 @@ def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000):
fs_type (str): File system type, e.g. 'ext4'
size (int): Size of file system in bytes
prefix (str): Prefix string of volume's file name
+ src_dir (str): Root directory to use, or None for none
size_gran (int): Size granularity of file system image in bytes
Raises:
@@ -34,11 +35,19 @@ def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000):
else:
mkfs_opt = ''
- if re.match('fat', fs_type):
+ if fs_type == 'exfat':
+ fs_lnxtype = 'exfat'
+ elif re.match('fat', fs_type) or fs_type == 'fs_generic':
fs_lnxtype = 'vfat'
else:
fs_lnxtype = fs_type
+ if src_dir:
+ if fs_lnxtype == 'ext4':
+ mkfs_opt = mkfs_opt + ' -d ' + src_dir
+ elif fs_lnxtype != 'vfat' and fs_lnxtype != 'exfat':
+ raise ValueError(f'src_dir not implemented for fs {fs_lnxtype}')
+
count = (size + size_gran - 1) // size_gran
# Some distributions do not add /sbin to the default PATH, where mkfs lives
@@ -47,7 +56,7 @@ def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000):
try:
check_call(f'rm -f {fs_img}', shell=True)
- check_call(f'dd if=/dev/zero of={fs_img} bs={size_gran} count={count}',
+ check_call(f'truncate -s $(( {size_gran} * {count} )) {fs_img}',
shell=True)
check_call(f'mkfs.{fs_lnxtype} {mkfs_opt} {fs_img}', shell=True)
if fs_type == 'ext4':
@@ -55,11 +64,49 @@ def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000):
shell=True).decode()
if 'metadata_csum' in sb_content:
check_call(f'tune2fs -O ^metadata_csum {fs_img}', shell=True)
+ elif fs_lnxtype == 'vfat' and src_dir:
+ check_call(f'mcopy -i {fs_img} -vsmpQ {src_dir}/* ::/', shell=True)
+ elif fs_lnxtype == 'exfat' and src_dir:
+ check_call(f'fattools cp {src_dir}/* {fs_img}', shell=True)
return fs_img
except CalledProcessError:
call(f'rm -f {fs_img}', shell=True)
raise
+def setup_image(ubman, devnum, part_type, img_size=20, second_part=False,
+ basename='mmc'):
+ """Create a disk image with a single partition
+
+ Args:
+ ubman (ConsoleBase): Console to use
+ devnum (int): Device number to use, e.g. 1
+ part_type (int): Partition type, e.g. 0xc for FAT32
+ img_size (int): Image size in MiB
+ second_part (bool): True to contain a small second partition
+ basename (str): Base name to use in the filename, e.g. 'mmc'
+
+ Returns:
+ tuple:
+ str: Filename of MMC image
+ str: Directory name of scratch directory
+ """
+ fname = os.path.join(ubman.config.source_dir, f'{basename}{devnum}.img')
+ mnt = os.path.join(ubman.config.persistent_data_dir, 'scratch')
+
+ spec = f'type={part_type:x}, size={img_size - 2}M, start=1M, bootable'
+ if second_part:
+ spec += '\ntype=c'
+
+ try:
+ check_call(f'mkdir -p {mnt}', shell=True)
+ check_call(f'qemu-img create {fname} {img_size}M', shell=True)
+ check_call(f'printf "{spec}" | sfdisk {fname}', shell=True)
+ except CalledProcessError:
+ call(f'rm -f {fname}', shell=True)
+ raise
+
+ return fname, mnt
+
# Just for trying out
if __name__ == "__main__":
import collections
diff --git a/test/py/tests/test_000_version.py b/test/py/tests/test_000_version.py
index bd089ab5439..63d392e956e 100644
--- a/test/py/tests/test_000_version.py
+++ b/test/py/tests/test_000_version.py
@@ -2,18 +2,20 @@
# Copyright (c) 2015 Stephen Warren
# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
-# pytest runs tests the order of their module path, which is related to the
-# filename containing the test. This file is named such that it is sorted
-# first, simply as a very basic sanity check of the functionality of the U-Boot
-# command prompt.
+"""
+pytest runs tests the order of their module path, which is related to the
+filename containing the test. This file is named such that it is sorted
+first, simply as a very basic sanity check of the functionality of the U-Boot
+command prompt.
+"""
-def test_version(u_boot_console):
+def test_version(ubman):
"""Test that the "version" command prints the U-Boot version."""
# "version" prints the U-Boot sign-on message. This is usually considered
# an error, so that any unexpected reboot causes an error. Here, this
# error detection is disabled since the sign-on message is expected.
- with u_boot_console.disable_check('main_signon'):
- response = u_boot_console.run_command('version')
+ with ubman.disable_check('main_signon'):
+ response = ubman.run_command('version')
# Ensure "version" printed what we expected.
- u_boot_console.validate_version_string_in_text(response)
+ ubman.validate_version_string_in_text(response)
diff --git a/test/py/tests/test_android/test_ab.py b/test/py/tests/test_android/test_ab.py
index c79cb07fda3..5876a137463 100644
--- a/test/py/tests/test_android/test_ab.py
+++ b/test/py/tests/test_android/test_ab.py
@@ -5,16 +5,16 @@
import os
import pytest
-import u_boot_utils
+import utils
class ABTestDiskImage(object):
"""Disk Image used by the A/B tests."""
- def __init__(self, u_boot_console):
+ def __init__(self, ubman):
"""Initialize a new ABTestDiskImage object.
Args:
- u_boot_console: A U-Boot console.
+ ubman: A U-Boot console.
Returns:
Nothing.
@@ -22,54 +22,77 @@ class ABTestDiskImage(object):
filename = 'test_ab_disk_image.bin'
- persistent = u_boot_console.config.persistent_data_dir + '/' + filename
- self.path = u_boot_console.config.result_dir + '/' + filename
+ persistent = ubman.config.persistent_data_dir + '/' + filename
+ self.path = ubman.config.result_dir + '/' + filename
- with u_boot_utils.persistent_file_helper(u_boot_console.log, persistent):
+ with utils.persistent_file_helper(ubman.log, persistent):
if os.path.exists(persistent):
- u_boot_console.log.action('Disk image file ' + persistent +
+ ubman.log.action('Disk image file ' + persistent +
' already exists')
else:
- u_boot_console.log.action('Generating ' + persistent)
+ ubman.log.action('Generating ' + persistent)
fd = os.open(persistent, os.O_RDWR | os.O_CREAT)
os.ftruncate(fd, 524288)
os.close(fd)
cmd = ('sgdisk', persistent)
- u_boot_utils.run_and_log(u_boot_console, cmd)
+ utils.run_and_log(ubman, cmd)
cmd = ('sgdisk', '--new=1:64:512', '--change-name=1:misc',
persistent)
- u_boot_utils.run_and_log(u_boot_console, cmd)
+ utils.run_and_log(ubman, cmd)
cmd = ('sgdisk', '--load-backup=' + persistent)
- u_boot_utils.run_and_log(u_boot_console, cmd)
+ utils.run_and_log(ubman, cmd)
cmd = ('cp', persistent, self.path)
- u_boot_utils.run_and_log(u_boot_console, cmd)
+ utils.run_and_log(ubman, cmd)
di = None
@pytest.fixture(scope='function')
-def ab_disk_image(u_boot_console):
+def ab_disk_image(ubman):
global di
if not di:
- di = ABTestDiskImage(u_boot_console)
+ di = ABTestDiskImage(ubman)
return di
+def ab_dump(ubman, slot_num, crc):
+ output = ubman.run_command('bcb ab_dump host 0#misc')
+ header, slot0, slot1 = output.split('\r\r\n\r\r\n')
+ slots = [slot0, slot1]
+ slot_suffixes = ['_a', '_b']
+
+ header = dict(map(lambda x: map(str.strip, x.split(':')), header.split('\r\r\n')))
+ assert header['Bootloader Control'] == '[misc]'
+ assert header['Active Slot'] == slot_suffixes[slot_num]
+ assert header['Magic Number'] == '0x42414342'
+ assert header['Version'] == '1'
+ assert header['Number of Slots'] == '2'
+ assert header['Recovery Tries Remaining'] == '0'
+ assert header['CRC'] == '{} (Valid)'.format(crc)
+
+ slot = dict(map(lambda x: map(str.strip, x.split(':')), slots[slot_num].split('\r\r\n\t- ')[1:]))
+ assert slot['Priority'] == '15'
+ assert slot['Tries Remaining'] == '6'
+ assert slot['Successful Boot'] == '0'
+ assert slot['Verity Corrupted'] == '0'
+
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('android_ab')
-@pytest.mark.buildconfigspec('cmd_ab_select')
+@pytest.mark.buildconfigspec('cmd_bcb')
@pytest.mark.requiredtool('sgdisk')
-def test_ab(ab_disk_image, u_boot_console):
- """Test the 'ab_select' command."""
+def test_ab(ab_disk_image, ubman):
+ """Test the 'bcb ab_select' command."""
- u_boot_console.run_command('host bind 0 ' + ab_disk_image.path)
+ ubman.run_command('host bind 0 ' + ab_disk_image.path)
- output = u_boot_console.run_command('ab_select slot_name host 0#misc')
+ output = ubman.run_command('bcb ab_select slot_name host 0#misc')
assert 're-initializing A/B metadata' in output
assert 'Attempting slot a, tries remaining 7' in output
- output = u_boot_console.run_command('printenv slot_name')
+ output = ubman.run_command('printenv slot_name')
assert 'slot_name=a' in output
+ ab_dump(ubman, 0, '0xd438d1b9')
- output = u_boot_console.run_command('ab_select slot_name host 0:1')
+ output = ubman.run_command('bcb ab_select slot_name host 0:1')
assert 'Attempting slot b, tries remaining 7' in output
- output = u_boot_console.run_command('printenv slot_name')
+ output = ubman.run_command('printenv slot_name')
assert 'slot_name=b' in output
+ ab_dump(ubman, 1, '0x011ec016')
diff --git a/test/py/tests/test_android/test_abootimg.py b/test/py/tests/test_android/test_abootimg.py
index 6a8ff34538b..2aadb692b30 100644
--- a/test/py/tests/test_android/test_abootimg.py
+++ b/test/py/tests/test_android/test_abootimg.py
@@ -6,7 +6,7 @@
import os
import pytest
-import u_boot_utils
+import utils
"""
These tests rely on disk image (boot.img), which is automatically created by
@@ -105,78 +105,78 @@ dtb2_addr = vloadaddr + dtb2_offset
class AbootimgTestDiskImage(object):
"""Disk image used by abootimg tests."""
- def __init__(self, u_boot_console, image_name, hex_img):
+ def __init__(self, ubman, image_name, hex_img):
"""Initialize a new AbootimgDiskImage object.
Args:
- u_boot_console: A U-Boot console.
+ ubman: A U-Boot console.
Returns:
Nothing.
"""
- gz_hex = u_boot_console.config.persistent_data_dir + '/' + image_name + '.gz.hex'
- gz = u_boot_console.config.persistent_data_dir + '/' + image_name + '.gz'
+ gz_hex = ubman.config.persistent_data_dir + '/' + image_name + '.gz.hex'
+ gz = ubman.config.persistent_data_dir + '/' + image_name + '.gz'
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):
+ persistent = ubman.config.persistent_data_dir + '/' + filename
+ self.path = ubman.config.result_dir + '/' + filename
+ ubman.log.action('persistent is ' + persistent)
+ with utils.persistent_file_helper(ubman.log, persistent):
if os.path.exists(persistent):
- u_boot_console.log.action('Disk image file ' + persistent +
+ ubman.log.action('Disk image file ' + persistent +
' already exists')
else:
- u_boot_console.log.action('Generating ' + persistent)
+ ubman.log.action('Generating ' + persistent)
f = open(gz_hex, "w")
f.write(hex_img)
f.close()
cmd = ('xxd', '-r', '-p', gz_hex, gz)
- u_boot_utils.run_and_log(u_boot_console, cmd)
+ utils.run_and_log(ubman, cmd)
cmd = ('gunzip', '-9', gz)
- u_boot_utils.run_and_log(u_boot_console, cmd)
+ utils.run_and_log(ubman, cmd)
cmd = ('cp', persistent, self.path)
- u_boot_utils.run_and_log(u_boot_console, cmd)
+ utils.run_and_log(ubman, cmd)
gtdi1 = None
@pytest.fixture(scope='function')
-def abootimg_disk_image(u_boot_console):
+def abootimg_disk_image(ubman):
"""pytest fixture to provide a AbootimgTestDiskImage object to tests.
- This is function-scoped because it uses u_boot_console, which is also
+ This is function-scoped because it uses ubman, 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 gtdi1
if not gtdi1:
- gtdi1 = AbootimgTestDiskImage(u_boot_console, 'boot.img', img_hex)
+ gtdi1 = AbootimgTestDiskImage(ubman, 'boot.img', img_hex)
return gtdi1
gtdi2 = None
@pytest.fixture(scope='function')
-def abootimgv4_disk_image_vboot(u_boot_console):
+def abootimgv4_disk_image_vboot(ubman):
"""pytest fixture to provide a AbootimgTestDiskImage object to tests.
- This is function-scoped because it uses u_boot_console, which is also
+ This is function-scoped because it uses ubman, 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)
+ gtdi2 = AbootimgTestDiskImage(ubman, 'vendor_boot.img', vboot_img_hex)
return gtdi2
gtdi3 = None
@pytest.fixture(scope='function')
-def abootimgv4_disk_image_boot(u_boot_console):
+def abootimgv4_disk_image_boot(ubman):
"""pytest fixture to provide a AbootimgTestDiskImage object to tests.
- This is function-scoped because it uses u_boot_console, which is also
+ This is function-scoped because it uses ubman, 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)
+ gtdi3 = AbootimgTestDiskImage(ubman, 'bootv4.img', boot_img_hex)
return gtdi3
@pytest.mark.boardspec('sandbox')
@@ -185,42 +185,42 @@ def abootimgv4_disk_image_boot(u_boot_console):
@pytest.mark.buildconfigspec('cmd_fdt')
@pytest.mark.requiredtool('xxd')
@pytest.mark.requiredtool('gunzip')
-def test_abootimg(abootimg_disk_image, u_boot_console):
+def test_abootimg(abootimg_disk_image, ubman):
"""Test the 'abootimg' command."""
- u_boot_console.log.action('Loading disk image to RAM...')
- u_boot_console.run_command('setenv loadaddr 0x%x' % (loadaddr))
- u_boot_console.run_command('host load hostfs - 0x%x %s' % (loadaddr,
+ ubman.log.action('Loading disk image to RAM...')
+ ubman.run_command('setenv loadaddr 0x%x' % (loadaddr))
+ ubman.run_command('host load hostfs - 0x%x %s' % (loadaddr,
abootimg_disk_image.path))
- u_boot_console.log.action('Testing \'abootimg get ver\'...')
- response = u_boot_console.run_command('abootimg get ver')
+ ubman.log.action('Testing \'abootimg get ver\'...')
+ response = ubman.run_command('abootimg get ver')
assert response == "2"
- u_boot_console.run_command('abootimg get ver v')
- response = u_boot_console.run_command('env print v')
+ ubman.run_command('abootimg get ver v')
+ response = ubman.run_command('env print v')
assert response == 'v=2'
- u_boot_console.log.action('Testing \'abootimg get recovery_dtbo\'...')
- response = u_boot_console.run_command('abootimg get recovery_dtbo a')
+ ubman.log.action('Testing \'abootimg get recovery_dtbo\'...')
+ response = ubman.run_command('abootimg get recovery_dtbo a')
assert response == 'Error: recovery_dtbo_size is 0'
- u_boot_console.log.action('Testing \'abootimg dump dtb\'...')
- response = u_boot_console.run_command('abootimg dump dtb').replace('\r', '')
+ ubman.log.action('Testing \'abootimg dump dtb\'...')
+ response = ubman.run_command('abootimg dump dtb').replace('\r', '')
assert response == dtb_dump_resp
- u_boot_console.log.action('Testing \'abootimg get dtb_load_addr\'...')
- u_boot_console.run_command('abootimg get dtb_load_addr a')
- response = u_boot_console.run_command('env print a')
+ ubman.log.action('Testing \'abootimg get dtb_load_addr\'...')
+ ubman.run_command('abootimg get dtb_load_addr a')
+ response = ubman.run_command('env print a')
assert response == 'a=11f00000'
- u_boot_console.log.action('Testing \'abootimg get dtb --index\'...')
- u_boot_console.run_command('abootimg get dtb --index=1 dtb1_start')
- response = u_boot_console.run_command('env print dtb1_start')
+ ubman.log.action('Testing \'abootimg get dtb --index\'...')
+ ubman.run_command('abootimg get dtb --index=1 dtb1_start')
+ response = ubman.run_command('env print dtb1_start')
correct_str = "dtb1_start=%x" % (dtb1_addr)
assert response == correct_str
- u_boot_console.run_command('fdt addr $dtb1_start')
- u_boot_console.run_command('fdt get value v / model')
- response = u_boot_console.run_command('env print v')
+ ubman.run_command('fdt addr $dtb1_start')
+ ubman.run_command('fdt get value v / model')
+ response = ubman.run_command('env print v')
assert response == 'v=x2'
@pytest.mark.boardspec('sandbox')
@@ -229,41 +229,40 @@ def test_abootimg(abootimg_disk_image, u_boot_console):
@pytest.mark.buildconfigspec('cmd_fdt')
@pytest.mark.requiredtool('xxd')
@pytest.mark.requiredtool('gunzip')
-def test_abootimgv4(abootimgv4_disk_image_vboot, abootimgv4_disk_image_boot, u_boot_console):
+def test_abootimgv4(abootimgv4_disk_image_vboot, abootimgv4_disk_image_boot, ubman):
"""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,
+ ubman.log.action('Loading disk image to RAM...')
+ ubman.run_command('setenv loadaddr 0x%x' % (loadaddr))
+ ubman.run_command('setenv vloadaddr 0x%x' % (vloadaddr))
+ ubman.run_command('host load hostfs - 0x%x %s' % (vloadaddr,
abootimgv4_disk_image_vboot.path))
- cons.run_command('host load hostfs - 0x%x %s' % (loadaddr,
+ ubman.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')
+ ubman.run_command('abootimg addr 0x%x 0x%x' % (loadaddr, vloadaddr))
+ ubman.log.action('Testing \'abootimg get ver\'...')
+ response = ubman.run_command('abootimg get ver')
assert response == "4"
- cons.run_command('abootimg get ver v')
- response = cons.run_command('env print v')
+ ubman.run_command('abootimg get ver v')
+ response = ubman.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')
+ ubman.log.action('Testing \'abootimg get recovery_dtbo\'...')
+ response = ubman.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')
+ ubman.log.action('Testing \'abootimg get dtb_load_addr\'...')
+ ubman.run_command('abootimg get dtb_load_addr a')
+ response = ubman.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')
+ ubman.log.action('Testing \'abootimg get dtb --index\'...')
+ ubman.run_command('abootimg get dtb --index=1 dtb2_start')
+ response = ubman.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')
+ ubman.run_command('fdt addr $dtb2_start')
+ ubman.run_command('fdt get value v / model')
+ response = ubman.run_command('env print v')
assert response == 'v=x2'
diff --git a/test/py/tests/test_android/test_avb.py b/test/py/tests/test_android/test_avb.py
index 865efbca4de..137d83e1dea 100644
--- a/test/py/tests/test_android/test_avb.py
+++ b/test/py/tests/test_android/test_avb.py
@@ -15,7 +15,6 @@ For configuration verification:
"""
import pytest
-import u_boot_utils as util
# defauld mmc id
mmc_dev = 1
@@ -24,34 +23,34 @@ temp_addr2 = 0x90002000
@pytest.mark.buildconfigspec('cmd_avb')
@pytest.mark.buildconfigspec('cmd_mmc')
-def test_avb_verify(u_boot_console):
+def test_avb_verify(ubman):
"""Run AVB 2.0 boot verification chain with avb subset of commands
"""
success_str = "Verification passed successfully"
- response = u_boot_console.run_command('avb init %s' %str(mmc_dev))
+ response = ubman.run_command('avb init %s' %str(mmc_dev))
assert response == ''
- response = u_boot_console.run_command('avb verify')
+ response = ubman.run_command('avb verify')
assert response.find(success_str)
@pytest.mark.buildconfigspec('cmd_avb')
@pytest.mark.buildconfigspec('cmd_mmc')
@pytest.mark.notbuildconfigspec('sandbox')
-def test_avb_mmc_uuid(u_boot_console):
+def test_avb_mmc_uuid(ubman):
"""Check if 'avb get_uuid' works, compare results with
'part list mmc 1' output
"""
- response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
+ response = ubman.run_command('avb init %s' % str(mmc_dev))
assert response == ''
- response = u_boot_console.run_command('mmc rescan; mmc dev %s' %
+ response = ubman.run_command('mmc rescan; mmc dev %s' %
str(mmc_dev))
assert response.find('is current device')
- part_lines = u_boot_console.run_command('mmc part').splitlines()
+ part_lines = ubman.run_command('mmc part').splitlines()
part_list = {}
cur_partname = ''
@@ -67,72 +66,72 @@ def test_avb_mmc_uuid(u_boot_console):
# lets check all guids with avb get_guid
for part, guid in part_list.items():
- avb_guid_resp = u_boot_console.run_command('avb get_uuid %s' % part)
+ avb_guid_resp = ubman.run_command('avb get_uuid %s' % part)
assert guid == avb_guid_resp.split('UUID: ')[1]
@pytest.mark.buildconfigspec('cmd_avb')
-def test_avb_read_rb(u_boot_console):
+def test_avb_read_rb(ubman):
"""Test reading rollback indexes
"""
- response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
+ response = ubman.run_command('avb init %s' % str(mmc_dev))
assert response == ''
- response = u_boot_console.run_command('avb read_rb 1')
+ response = ubman.run_command('avb read_rb 1')
assert response == 'Rollback index: 0'
@pytest.mark.buildconfigspec('cmd_avb')
-def test_avb_is_unlocked(u_boot_console):
+def test_avb_is_unlocked(ubman):
"""Test if device is in the unlocked state
"""
- response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
+ response = ubman.run_command('avb init %s' % str(mmc_dev))
assert response == ''
- response = u_boot_console.run_command('avb is_unlocked')
+ response = ubman.run_command('avb is_unlocked')
assert response == 'Unlocked = 1'
@pytest.mark.buildconfigspec('cmd_avb')
@pytest.mark.buildconfigspec('cmd_mmc')
@pytest.mark.notbuildconfigspec('sandbox')
-def test_avb_mmc_read(u_boot_console):
+def test_avb_mmc_read(ubman):
"""Test mmc read operation
"""
- response = u_boot_console.run_command('mmc rescan; mmc dev %s 0' %
+ response = ubman.run_command('mmc rescan; mmc dev %s 0' %
str(mmc_dev))
assert response.find('is current device')
- response = u_boot_console.run_command('mmc read 0x%x 0x100 0x1' % temp_addr)
+ response = ubman.run_command('mmc read 0x%x 0x100 0x1' % temp_addr)
assert response.find('read: OK')
- response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
+ response = ubman.run_command('avb init %s' % str(mmc_dev))
assert response == ''
- response = u_boot_console.run_command('avb read_part xloader 0 100 0x%x' %
+ response = ubman.run_command('avb read_part xloader 0 100 0x%x' %
temp_addr2)
assert response.find('Read 512 bytes')
# Now lets compare two buffers
- response = u_boot_console.run_command('cmp 0x%x 0x%x 40' %
+ response = ubman.run_command('cmp 0x%x 0x%x 40' %
(temp_addr, temp_addr2))
assert response.find('64 word')
@pytest.mark.buildconfigspec('cmd_avb')
@pytest.mark.buildconfigspec('optee_ta_avb')
-def test_avb_persistent_values(u_boot_console):
+def test_avb_persistent_values(ubman):
"""Test reading/writing persistent storage to avb
"""
- response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
+ response = ubman.run_command('avb init %s' % str(mmc_dev))
assert response == ''
- response = u_boot_console.run_command('avb write_pvalue test value_value')
+ response = ubman.run_command('avb write_pvalue test value_value')
assert response == 'Wrote 12 bytes'
- response = u_boot_console.run_command('avb read_pvalue test 12')
+ response = ubman.run_command('avb read_pvalue test 12')
assert response == 'Read 12 bytes, value = value_value'
diff --git a/test/py/tests/test_bind.py b/test/py/tests/test_bind.py
index 1376ab5ed28..850fe113fe2 100644
--- a/test/py/tests/test_bind.py
+++ b/test/py/tests/test_bind.py
@@ -7,6 +7,7 @@ import re
import pytest
def in_tree(response, name, uclass, drv, depth, last_child):
+ """A helper function to confirm contents of the device tree """
lines = [x.strip() for x in response.splitlines()]
leaf = ''
if depth != 0:
@@ -27,85 +28,91 @@ def in_tree(response, name, uclass, drv, depth, last_child):
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_bind')
-def test_bind_unbind_with_node(u_boot_console):
-
- tree = u_boot_console.run_command('dm tree')
+def test_bind_unbind_with_node(ubman):
+ """Test the bind and unbind commands of a node
+
+ Verify that the dm tree output contains some expected nodes, and then bind
+ and unbind a USB via node device while verifying that the dm tree output
+ matches the expected values at each step.
+ """
+ tree = ubman.run_command('dm tree')
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, False)
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
#bind usb_ether driver (which has no compatible) to usb@1 node.
##New entry usb_ether should appear in the dm tree
- response = u_boot_console.run_command('bind /usb@1 usb_ether')
+ response = ubman.run_command('bind /usb@1 usb_ether')
assert response == ''
- tree = u_boot_console.run_command('dm tree')
+ tree = ubman.run_command('dm tree')
assert in_tree(tree, 'usb@1', 'ethernet', 'usb_ether', 1, True)
#Unbind child #1. No error expected and all devices should be there except for bind-test-child1
- response = u_boot_console.run_command('unbind /bind-test/bind-test-child1')
+ response = ubman.run_command('unbind /bind-test/bind-test-child1')
assert response == ''
- tree = u_boot_console.run_command('dm tree')
+ tree = ubman.run_command('dm tree')
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
assert 'bind-test-child1' not in tree
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
#bind child #1. No error expected and all devices should be there
- response = u_boot_console.run_command('bind /bind-test/bind-test-child1 phy_sandbox')
+ response = ubman.run_command('bind /bind-test/bind-test-child1 phy_sandbox')
assert response == ''
- tree = u_boot_console.run_command('dm tree')
+ tree = ubman.run_command('dm tree')
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, True)
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, False)
#Unbind child #2. No error expected and all devices should be there except for bind-test-child2
- response = u_boot_console.run_command('unbind /bind-test/bind-test-child2')
+ response = ubman.run_command('unbind /bind-test/bind-test-child2')
assert response == ''
- tree = u_boot_console.run_command('dm tree')
+ tree = ubman.run_command('dm tree')
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, True)
assert 'bind-test-child2' not in tree
#Bind child #2. No error expected and all devices should be there
- response = u_boot_console.run_command('bind /bind-test/bind-test-child2 simple_bus')
+ response = ubman.run_command('bind /bind-test/bind-test-child2 simple_bus')
assert response == ''
- tree = u_boot_console.run_command('dm tree')
+ tree = ubman.run_command('dm tree')
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, False)
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
#Unbind parent. No error expected. All devices should be removed and unbound
- response = u_boot_console.run_command('unbind /bind-test')
+ response = ubman.run_command('unbind /bind-test')
assert response == ''
- tree = u_boot_console.run_command('dm tree')
+ tree = ubman.run_command('dm tree')
assert 'bind-test' not in tree
assert 'bind-test-child1' not in tree
assert 'bind-test-child2' not in tree
#try binding invalid node with valid driver
- response = u_boot_console.run_command('bind /not-a-valid-node simple_bus')
+ response = ubman.run_command('bind /not-a-valid-node simple_bus')
assert response != ''
- tree = u_boot_console.run_command('dm tree')
+ tree = ubman.run_command('dm tree')
assert 'not-a-valid-node' not in tree
#try binding valid node with invalid driver
- response = u_boot_console.run_command('bind /bind-test not_a_driver')
+ response = ubman.run_command('bind /bind-test not_a_driver')
assert response != ''
- tree = u_boot_console.run_command('dm tree')
+ tree = ubman.run_command('dm tree')
assert 'bind-test' not in tree
#bind /bind-test. Device should come up as well as its children
- response = u_boot_console.run_command('bind /bind-test simple_bus')
+ response = ubman.run_command('bind /bind-test simple_bus')
assert response == ''
- tree = u_boot_console.run_command('dm tree')
+ tree = ubman.run_command('dm tree')
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, False)
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
- response = u_boot_console.run_command('unbind /bind-test')
+ response = ubman.run_command('unbind /bind-test')
assert response == ''
def get_next_line(tree, name):
+ """A helper function to strip content out of dm tree output"""
treelines = [x.strip() for x in tree.splitlines() if x.strip()]
child_line = ''
for idx, line in enumerate(treelines):
@@ -120,13 +127,18 @@ def get_next_line(tree, name):
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_bind')
@pytest.mark.singlethread
-def test_bind_unbind_with_uclass(u_boot_console):
+def test_bind_unbind_with_uclass(ubman):
+ """Test the bind and unbind commands of a class
+
+ Bind and unbind the simple_bus class while verifying that the dm tree
+ output matches the expected values at each step.
+ """
#bind /bind-test
- response = u_boot_console.run_command('bind /bind-test simple_bus')
+ response = ubman.run_command('bind /bind-test simple_bus')
assert response == ''
#make sure bind-test-child2 is there and get its uclass/index pair
- tree = u_boot_console.run_command('dm tree')
+ tree = ubman.run_command('dm tree')
child2_line = [x.strip() for x in tree.splitlines() if '-- bind-test-child2' in x]
assert len(child2_line) == 1
@@ -134,11 +146,11 @@ def test_bind_unbind_with_uclass(u_boot_console):
child2_index = int(child2_line[0].split()[1])
#bind simple_bus as a child of bind-test-child2
- response = u_boot_console.run_command(
+ response = ubman.run_command(
'bind {} {} simple_bus'.format(child2_uclass, child2_index))
#check that the child is there and its uclass/index pair is right
- tree = u_boot_console.run_command('dm tree')
+ tree = ubman.run_command('dm tree')
child_of_child2_line = get_next_line(tree, 'bind-test-child2')
assert child_of_child2_line
@@ -147,20 +159,20 @@ def test_bind_unbind_with_uclass(u_boot_console):
assert child_of_child2_index == child2_index + 1
#unbind the child and check it has been removed
- response = u_boot_console.run_command('unbind simple_bus {}'.format(child_of_child2_index))
+ response = ubman.run_command('unbind simple_bus {}'.format(child_of_child2_index))
assert response == ''
- tree = u_boot_console.run_command('dm tree')
+ tree = ubman.run_command('dm tree')
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
assert not in_tree(tree, 'simple_bus', 'simple_bus', 'simple_bus', 2, True)
child_of_child2_line = get_next_line(tree, 'bind-test-child2')
assert child_of_child2_line == ''
#bind simple_bus as a child of bind-test-child2
- response = u_boot_console.run_command(
+ response = ubman.run_command(
'bind {} {} simple_bus'.format(child2_uclass, child2_index))
#check that the child is there and its uclass/index pair is right
- tree = u_boot_console.run_command('dm tree')
+ tree = ubman.run_command('dm tree')
treelines = [x.strip() for x in tree.splitlines() if x.strip()]
child_of_child2_line = get_next_line(tree, 'bind-test-child2')
@@ -170,24 +182,24 @@ def test_bind_unbind_with_uclass(u_boot_console):
assert child_of_child2_index == child2_index + 1
#unbind the child and check it has been removed
- response = u_boot_console.run_command(
+ response = ubman.run_command(
'unbind {} {} simple_bus'.format(child2_uclass, child2_index))
assert response == ''
- tree = u_boot_console.run_command('dm tree')
+ tree = ubman.run_command('dm tree')
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
child_of_child2_line = get_next_line(tree, 'bind-test-child2')
assert child_of_child2_line == ''
#unbind the child again and check it doesn't change the tree
- tree_old = u_boot_console.run_command('dm tree')
- response = u_boot_console.run_command(
+ tree_old = ubman.run_command('dm tree')
+ response = ubman.run_command(
'unbind {} {} simple_bus'.format(child2_uclass, child2_index))
- tree_new = u_boot_console.run_command('dm tree')
+ tree_new = ubman.run_command('dm tree')
assert response == ''
assert tree_old == tree_new
- response = u_boot_console.run_command('unbind /bind-test')
+ response = ubman.run_command('unbind /bind-test')
assert response == ''
diff --git a/test/py/tests/test_bootmenu.py b/test/py/tests/test_bootmenu.py
index 70f51de699f..be8257fe3e8 100644
--- a/test/py/tests/test_bootmenu.py
+++ b/test/py/tests/test_bootmenu.py
@@ -5,42 +5,42 @@
import pytest
@pytest.mark.buildconfigspec('cmd_bootmenu')
-def test_bootmenu(u_boot_console):
+def test_bootmenu(ubman):
"""Test bootmenu
- u_boot_console -- U-Boot console
+ Args:
+ ubman: U-Boot console
"""
-
- with u_boot_console.temporary_timeout(500):
- u_boot_console.run_command('setenv bootmenu_default 1')
- u_boot_console.run_command('setenv bootmenu_0 test 1=echo ok 1')
- u_boot_console.run_command('setenv bootmenu_1 test 2=echo ok 2')
- u_boot_console.run_command('setenv bootmenu_2 test 3=echo ok 3')
- u_boot_console.run_command('bootmenu 2', wait_for_prompt=False)
+ with ubman.temporary_timeout(500):
+ ubman.run_command('setenv bootmenu_default 1')
+ ubman.run_command('setenv bootmenu_0 test 1=echo ok 1')
+ ubman.run_command('setenv bootmenu_1 test 2=echo ok 2')
+ ubman.run_command('setenv bootmenu_2 test 3=echo ok 3')
+ ubman.run_command('bootmenu 2', wait_for_prompt=False)
for i in ('U-Boot Boot Menu', 'test 1', 'test 2', 'test 3', 'autoboot'):
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
# Press enter key to execute default entry
- response = u_boot_console.run_command(cmd='\x0d', wait_for_echo=False, send_nl=False)
+ response = ubman.run_command(cmd='\x0d', wait_for_echo=False, send_nl=False)
assert 'ok 2' in response
- u_boot_console.run_command('bootmenu 2', wait_for_prompt=False)
- u_boot_console.p.expect(['autoboot'])
+ ubman.run_command('bootmenu 2', wait_for_prompt=False)
+ ubman.p.expect(['autoboot'])
# Press up key to select prior entry followed by the enter key
- response = u_boot_console.run_command(cmd='\x1b\x5b\x41\x0d', wait_for_echo=False,
+ response = ubman.run_command(cmd='\x1b\x5b\x41\x0d', wait_for_echo=False,
send_nl=False)
assert 'ok 1' in response
- u_boot_console.run_command('bootmenu 2', wait_for_prompt=False)
- u_boot_console.p.expect(['autoboot'])
+ ubman.run_command('bootmenu 2', wait_for_prompt=False)
+ ubman.p.expect(['autoboot'])
# Press down key to select next entry followed by the enter key
- response = u_boot_console.run_command(cmd='\x1b\x5b\x42\x0d', wait_for_echo=False,
+ response = ubman.run_command(cmd='\x1b\x5b\x42\x0d', wait_for_echo=False,
send_nl=False)
assert 'ok 3' in response
- u_boot_console.run_command('bootmenu 2; echo rc:$?', wait_for_prompt=False)
- u_boot_console.p.expect(['autoboot'])
+ ubman.run_command('bootmenu 2; echo rc:$?', wait_for_prompt=False)
+ ubman.p.expect(['autoboot'])
# Press the escape key
- response = u_boot_console.run_command(cmd='\x1b', wait_for_echo=False, send_nl=False)
+ response = ubman.run_command(cmd='\x1b', wait_for_echo=False, send_nl=False)
assert 'ok' not in response
assert 'rc:0' in response
- u_boot_console.run_command('setenv bootmenu_default')
- u_boot_console.run_command('setenv bootmenu_0')
- u_boot_console.run_command('setenv bootmenu_1')
- u_boot_console.run_command('setenv bootmenu_2')
+ ubman.run_command('setenv bootmenu_default')
+ ubman.run_command('setenv bootmenu_0')
+ ubman.run_command('setenv bootmenu_1')
+ ubman.run_command('setenv bootmenu_2')
diff --git a/test/py/tests/test_bootstage.py b/test/py/tests/test_bootstage.py
index a9eb9f0b4a1..2505862c5a4 100644
--- a/test/py/tests/test_bootstage.py
+++ b/test/py/tests/test_bootstage.py
@@ -1,8 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
# (C) Copyright 2023, Advanced Micro Devices, Inc.
-import pytest
-
"""
Test the bootstage command.
@@ -15,17 +13,33 @@ common/bootstage.c). Without this, bootstage stash and unstash tests will be
automatically skipped.
For example:
-env__bootstage_cmd_file = {
- 'addr': 0x200000,
- 'size': 0x1000,
- 'bootstage_magic_addr': 0xb00757a3,
-}
+
+.. code-block:: python
+
+ env__bootstage_cmd_file = {
+ 'addr': 0x200000,
+ 'size': 0x1000,
+ 'bootstage_magic_addr': 0xb00757a3,
+ }
"""
+import pytest
+
@pytest.mark.buildconfigspec('bootstage')
@pytest.mark.buildconfigspec('cmd_bootstage')
-def test_bootstage_report(u_boot_console):
- output = u_boot_console.run_command('bootstage report')
+def test_bootstage_report(ubman):
+ """Test the bootstage report subcommand
+
+ This will run the 'bootstage report' subcommand and ensure that we are
+ reporting:
+
+ - A timer summary in microseconds
+ - The accumulated time
+ - That at least the phrase 'dm_r' is in the output
+
+ Note that the time values are not checked.
+ """
+ output = ubman.run_command('bootstage report')
assert 'Timer summary in microseconds' in output
assert 'Accumulated time:' in output
assert 'dm_r' in output
@@ -33,8 +47,15 @@ def test_bootstage_report(u_boot_console):
@pytest.mark.buildconfigspec('bootstage')
@pytest.mark.buildconfigspec('cmd_bootstage')
@pytest.mark.buildconfigspec('bootstage_stash')
-def test_bootstage_stash(u_boot_console):
- f = u_boot_console.config.env.get('env__bootstage_cmd_file', None)
+def test_bootstage_stash_and_unstash(ubman):
+ """Test the bootstage stash and unstash subcommands
+
+ After checking that we have configured an environment file to use, we will
+ use the stash subcommand to save information. Then we will use the md
+ command to verify the contents in memory. Finally we confirm the unstash
+ subcommand runs successfully.
+ """
+ f = ubman.config.env.get('env__bootstage_cmd_file', None)
if not f:
pytest.skip('No bootstage environment file is defined')
@@ -43,11 +64,11 @@ def test_bootstage_stash(u_boot_console):
bootstage_magic = f.get('bootstage_magic_addr')
expected_text = 'dm_r'
- u_boot_console.run_command('bootstage stash %x %x' % (addr, size))
- output = u_boot_console.run_command('echo $?')
+ ubman.run_command('bootstage stash %x %x' % (addr, size))
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
- output = u_boot_console.run_command('md %x 100' % addr)
+ output = ubman.run_command('md %x 100' % addr)
# Check BOOTSTAGE_MAGIC address at 4th byte address
assert '0x' + output.split('\n')[0].split()[4] == hex(bootstage_magic)
@@ -55,13 +76,8 @@ def test_bootstage_stash(u_boot_console):
# Check expected string in last column of output
output_last_col = ''.join([i.split()[-1] for i in output.split('\n')])
assert expected_text in output_last_col
- return addr, size
-@pytest.mark.buildconfigspec('bootstage')
-@pytest.mark.buildconfigspec('cmd_bootstage')
-@pytest.mark.buildconfigspec('bootstage_stash')
-def test_bootstage_unstash(u_boot_console):
- addr, size = test_bootstage_stash(u_boot_console)
- u_boot_console.run_command('bootstage unstash %x %x' % (addr, size))
- output = u_boot_console.run_command('echo $?')
+ # Check that unstash works as expected
+ ubman.run_command('bootstage unstash %x %x' % (addr, size))
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
diff --git a/test/py/tests/test_button.py b/test/py/tests/test_button.py
index 3b7f148c8fc..f3f68169e14 100644
--- a/test/py/tests/test_button.py
+++ b/test/py/tests/test_button.py
@@ -1,13 +1,15 @@
# SPDX-License-Identifier: GPL-2.0+
+"""Tests for the button command"""
+
import pytest
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_button')
-def test_button_list(u_boot_console):
+def test_button_list(ubman):
"""Test listing buttons"""
- response = u_boot_console.run_command('button list; echo rc:$?')
+ response = ubman.run_command('button list; echo rc:$?')
assert('button1' in response)
assert('button2' in response)
assert('rc:0' in response)
@@ -15,23 +17,23 @@ def test_button_list(u_boot_console):
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_button')
@pytest.mark.buildconfigspec('cmd_gpio')
-def test_button_return_code(u_boot_console):
+def test_button_return_code(ubman):
"""Test correct reporting of the button status
The sandbox gpio driver reports the last output value as input value.
We can use this in our test to emulate different input statuses.
"""
- u_boot_console.run_command('gpio set a3; gpio input a3');
- response = u_boot_console.run_command('button button1; echo rc:$?')
+ ubman.run_command('gpio set a3; gpio input a3');
+ response = ubman.run_command('button button1; echo rc:$?')
assert('on' in response)
assert('rc:0' in response)
- u_boot_console.run_command('gpio clear a3; gpio input a3');
- response = u_boot_console.run_command('button button1; echo rc:$?')
+ ubman.run_command('gpio clear a3; gpio input a3');
+ response = ubman.run_command('button button1; echo rc:$?')
assert('off' in response)
assert('rc:1' in response)
- response = u_boot_console.run_command('button nonexistent-button; echo rc:$?')
+ response = ubman.run_command('button nonexistent-button; echo rc:$?')
assert('not found' in response)
assert('rc:1' in response)
diff --git a/test/py/tests/test_cat.py b/test/py/tests/test_cat.py
new file mode 100644
index 00000000000..252c3d50a02
--- /dev/null
+++ b/test/py/tests/test_cat.py
@@ -0,0 +1,37 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+""" Unit test for cat command
+"""
+
+import pytest
+from subprocess import call, check_call, CalledProcessError
+from tests import fs_helper
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_cat')
+def test_cat(ubman):
+ """ Unit test for cat
+
+ Args:
+ ubman -- U-Boot console
+ """
+ try:
+ scratch_dir = ubman.config.persistent_data_dir + '/scratch'
+
+ check_call('mkdir -p %s' % scratch_dir, shell=True)
+
+ with open(scratch_dir + '/hello', 'w', encoding = 'ascii') as file:
+ file.write('hello world\n')
+
+ cat_data = fs_helper.mk_fs(ubman.config, 'vfat', 0x100000,
+ 'test_cat', scratch_dir)
+ response = ubman.run_command_list([ f'host bind 0 {cat_data}',
+ 'cat host 0 hello'])
+ assert 'hello world' in response
+ except CalledProcessError as err:
+ pytest.skip('Preparing test_cat image failed')
+ call('rm -f %s' % cat_data, shell=True)
+ return
+ finally:
+ call('rm -rf %s' % scratch_dir, shell=True)
+ call('rm -f %s' % cat_data, shell=True)
diff --git a/test/py/tests/test_cat/conftest.py b/test/py/tests/test_cat/conftest.py
deleted file mode 100644
index 320e7ebd295..00000000000
--- a/test/py/tests/test_cat/conftest.py
+++ /dev/null
@@ -1,36 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0+
-
-"""Fixture for cat command test
-"""
-
-import os
-import shutil
-from subprocess import check_call, CalledProcessError
-import pytest
-
-@pytest.fixture(scope='session')
-def cat_data(u_boot_config):
- """Set up a file system to be used in cat tests
-
- Args:
- u_boot_config -- U-Boot configuration.
- """
- mnt_point = u_boot_config.persistent_data_dir + '/test_cat'
- image_path = u_boot_config.persistent_data_dir + '/cat.img'
-
- try:
- os.mkdir(mnt_point, mode = 0o755)
-
- with open(mnt_point + '/hello', 'w', encoding = 'ascii') as file:
- file.write('hello world\n')
-
- check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}',
- shell=True)
-
- yield image_path
- except CalledProcessError:
- pytest.skip('Setup failed')
- finally:
- shutil.rmtree(mnt_point)
- if os.path.exists(image_path):
- os.remove(image_path)
diff --git a/test/py/tests/test_cat/test_cat.py b/test/py/tests/test_cat/test_cat.py
deleted file mode 100644
index 132527bd4c2..00000000000
--- a/test/py/tests/test_cat/test_cat.py
+++ /dev/null
@@ -1,20 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0+
-
-""" Unit test for cat command
-"""
-
-import pytest
-
-@pytest.mark.boardspec('sandbox')
-@pytest.mark.buildconfigspec('cmd_cat')
-def test_cat(u_boot_console, cat_data):
- """ Unit test for cat
-
- Args:
- u_boot_console -- U-Boot console
- cat_data -- Path to the disk image used for testing.
- """
- response = u_boot_console.run_command_list([
- f'host bind 0 {cat_data}',
- 'cat host 0 hello'])
- assert 'hello world' in response
diff --git a/test/py/tests/test_dfu.py b/test/py/tests/test_dfu.py
index 5d87eb349bf..7d6f41db7fb 100644
--- a/test/py/tests/test_dfu.py
+++ b/test/py/tests/test_dfu.py
@@ -9,7 +9,7 @@
import os
import os.path
import pytest
-import u_boot_utils
+import utils
"""
Note: This test relies on:
@@ -113,13 +113,13 @@ first_usb_dev_port = None
@pytest.mark.buildconfigspec('cmd_dfu')
@pytest.mark.requiredtool('dfu-util')
-def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
+def test_dfu(ubman, env__usb_dev_port, env__dfu_config):
"""Test the "dfu" command; the host system must be able to enumerate a USB
device when "dfu" is running, various DFU transfers are tested, and the
USB device must disappear when "dfu" is aborted.
Args:
- u_boot_console: A U-Boot console connection.
+ ubman: A U-Boot console connection.
env__usb_dev_port: The single USB device-mode port specification on
which to run the test. See the file-level comment above for
details of the format.
@@ -143,15 +143,15 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
Nothing.
"""
- u_boot_utils.wait_until_file_open_fails(
+ utils.wait_until_file_open_fails(
env__usb_dev_port['host_usb_dev_node'], True)
- fh = u_boot_utils.attempt_to_open_file(
+ fh = utils.attempt_to_open_file(
env__usb_dev_port['host_usb_dev_node'])
if fh:
fh.close()
raise Exception('USB device present before dfu command invoked')
- u_boot_console.log.action(
+ ubman.log.action(
'Starting long-running U-Boot dfu shell command')
dfu_alt_info_env = env__dfu_config.get('alt_info_env_name', \
@@ -159,12 +159,12 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
cmd = 'setenv "%s" "%s"' % (dfu_alt_info_env,
env__dfu_config['alt_info'])
- u_boot_console.run_command(cmd)
+ ubman.run_command(cmd)
cmd = 'dfu 0 ' + env__dfu_config['cmd_params']
- u_boot_console.run_command(cmd, wait_for_prompt=False)
- u_boot_console.log.action('Waiting for DFU USB device to appear')
- fh = u_boot_utils.wait_until_open_succeeds(
+ ubman.run_command(cmd, wait_for_prompt=False)
+ ubman.log.action('Waiting for DFU USB device to appear')
+ fh = utils.wait_until_open_succeeds(
env__usb_dev_port['host_usb_dev_node'])
fh.close()
@@ -185,12 +185,12 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
"""
try:
- u_boot_console.log.action(
+ ubman.log.action(
'Stopping long-running U-Boot dfu shell command')
- u_boot_console.ctrlc()
- u_boot_console.log.action(
+ ubman.ctrlc()
+ ubman.log.action(
'Waiting for DFU USB device to disappear')
- u_boot_utils.wait_until_file_open_fails(
+ utils.wait_until_file_open_fails(
env__usb_dev_port['host_usb_dev_node'], ignore_errors)
except:
if not ignore_errors:
@@ -213,8 +213,8 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
cmd = ['dfu-util', '-a', alt_setting, up_dn_load_arg, fn]
if 'host_usb_port_path' in env__usb_dev_port:
cmd += ['-p', env__usb_dev_port['host_usb_port_path']]
- u_boot_utils.run_and_log(u_boot_console, cmd)
- u_boot_console.wait_for('Ctrl+C to exit ...')
+ utils.run_and_log(ubman, cmd)
+ ubman.wait_for('Ctrl+C to exit ...')
def dfu_write(alt_setting, fn):
"""Write a file to the target board using DFU.
@@ -261,25 +261,25 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
Nothing.
"""
- test_f = u_boot_utils.PersistentRandomFile(u_boot_console,
+ test_f = utils.PersistentRandomFile(ubman,
'dfu_%d.bin' % size, size)
- readback_fn = u_boot_console.config.result_dir + '/dfu_readback.bin'
+ readback_fn = ubman.config.result_dir + '/dfu_readback.bin'
- u_boot_console.log.action('Writing test data to DFU primary ' +
+ ubman.log.action('Writing test data to DFU primary ' +
'altsetting')
dfu_write(alt_setting_test_file, test_f.abs_fn)
- u_boot_console.log.action('Writing dummy data to DFU secondary ' +
+ ubman.log.action('Writing dummy data to DFU secondary ' +
'altsetting to clear DFU buffers')
dfu_write(alt_setting_dummy_file, dummy_f.abs_fn)
- u_boot_console.log.action('Reading DFU primary altsetting for ' +
+ ubman.log.action('Reading DFU primary altsetting for ' +
'comparison')
dfu_read(alt_setting_test_file, readback_fn)
- u_boot_console.log.action('Comparing written and read data')
+ ubman.log.action('Comparing written and read data')
written_hash = test_f.content_hash
- read_back_hash = u_boot_utils.md5sum_file(readback_fn, size)
+ read_back_hash = utils.md5sum_file(readback_fn, size)
assert(written_hash == read_back_hash)
# This test may be executed against multiple USB ports. The test takes a
@@ -295,7 +295,7 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
else:
sizes = []
- dummy_f = u_boot_utils.PersistentRandomFile(u_boot_console,
+ dummy_f = utils.PersistentRandomFile(ubman,
'dfu_dummy.bin', 1024)
alt_setting_test_file = env__dfu_config.get('alt_id_test_file', '0')
@@ -305,16 +305,16 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config):
try:
start_dfu()
- u_boot_console.log.action(
+ ubman.log.action(
'Overwriting DFU primary altsetting with dummy data')
dfu_write(alt_setting_test_file, dummy_f.abs_fn)
for size in sizes:
- with u_boot_console.log.section('Data size %d' % size):
+ with ubman.log.section('Data size %d' % size):
dfu_write_read_check(size)
# Make the status of each sub-test obvious. If the test didn't
# pass, an exception was thrown so this code isn't executed.
- u_boot_console.log.status_pass('OK')
+ ubman.log.status_pass('OK')
ignore_cleanup_errors = False
finally:
stop_dfu(ignore_cleanup_errors)
diff --git a/test/py/tests/test_distro.py b/test/py/tests/test_distro.py
new file mode 100644
index 00000000000..bdf4ab657d1
--- /dev/null
+++ b/test/py/tests/test_distro.py
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2025 Canonical Ltd.
+# Written by Simon Glass <simon.glass@canonical.com>
+
+import pytest
+
+# Enable early console so that the test can see if something goes wrong
+CONSOLE = 'earlycon=uart8250,io,0x3f8 console=uart8250,io,0x3f8'
+
+@pytest.mark.boardspec('qemu-x86_64')
+@pytest.mark.role('qemu-x86_64')
+def test_distro(ubman):
+ """Test that of-platdata can be generated and used in sandbox"""
+ with ubman.log.section('boot'):
+ ubman.run_command('boot', wait_for_prompt=False)
+
+ with ubman.log.section('Grub'):
+ # Wait for grub to come up and offset a menu
+ ubman.p.expect(['Try or Install Ubuntu'])
+
+ # Press 'e' to edit the command line
+ ubman.log.info("Pressing 'e'")
+ ubman.run_command('e', wait_for_prompt=False, send_nl=False)
+
+ # Wait until we see the editor appear
+ ubman.p.expect(['/casper/initrd'])
+
+ # Go down to the 'linux' line. Avoid using down-arrow as that includes
+ # an Escape character, which may be parsed by Grub as such, causing it
+ # to return to the top menu
+ ubman.log.info("Going DOWN")
+ ubman.ctrl('N')
+ ubman.ctrl('N')
+ ubman.ctrl('N')
+
+ # Go to end of line
+ ubman.log.info("Going to EOL")
+ ubman.ctrl('E')
+
+ # Backspace to remove 'quiet splash'
+ ubman.log.info("Erasing quiet and splash")
+ ubman.send('\b' * len('quiet splash'))
+
+ # Send our noisy console
+ ubman.log.info("Noisy console")
+ ubman.send(CONSOLE)
+
+ # Tell grub to boot
+ ubman.log.info("boot")
+ ubman.ctrl('X')
+ ubman.p.expect(['Booting a command list'])
+
+ with ubman.log.section('Linux'):
+ # Linux should start immediately
+ ubman.p.expect(['Linux version'])
+
+ with ubman.log.section('Ubuntu'):
+ # Shortly later, we should see this banner
+ ubman.p.expect(['Welcome to .*Ubuntu 24.04.1 LTS.*!'])
+
+ ubman.restart_uboot()
diff --git a/test/py/tests/test_dm.py b/test/py/tests/test_dm.py
index 68d4ea12235..f4c2ccd1101 100644
--- a/test/py/tests/test_dm.py
+++ b/test/py/tests/test_dm.py
@@ -4,17 +4,20 @@
import pytest
@pytest.mark.buildconfigspec('cmd_dm')
-def test_dm_compat(u_boot_console):
+def test_dm_compat(ubman):
"""Test that each driver in `dm tree` is also listed in `dm compat`."""
- response = u_boot_console.run_command('dm tree')
+ response = ubman.run_command('dm tree')
driver_index = response.find('Driver')
assert driver_index != -1
drivers = (line[driver_index:].split()[0]
for line in response[:-1].split('\n')[2:])
- response = u_boot_console.run_command('dm compat')
+ response = ubman.run_command('dm compat')
+ bad_drivers = set()
for driver in drivers:
- assert driver in response
+ if not driver in response:
+ bad_drivers.add(driver)
+ assert not bad_drivers
# check sorting - output looks something like this:
# testacpi 0 [ ] testacpi_drv |-- acpi-test
@@ -26,7 +29,7 @@ def test_dm_compat(u_boot_console):
# checking sorting only after UCLASS_AXI_EMUL after which the names should
# be sorted.
- response = u_boot_console.run_command('dm tree -s')
+ response = ubman.run_command('dm tree -s')
lines = response.split('\n')[2:]
stack = [] # holds where we were up to at the previous indent level
prev = '' # uclass name of previous line
@@ -55,27 +58,27 @@ def test_dm_compat(u_boot_console):
@pytest.mark.buildconfigspec('cmd_dm')
-def test_dm_drivers(u_boot_console):
+def test_dm_drivers(ubman):
"""Test that each driver in `dm compat` is also listed in `dm drivers`."""
- response = u_boot_console.run_command('dm compat')
+ response = ubman.run_command('dm compat')
drivers = (line[:20].rstrip() for line in response[:-1].split('\n')[2:])
- response = u_boot_console.run_command('dm drivers')
+ response = ubman.run_command('dm drivers')
for driver in drivers:
assert driver in response
@pytest.mark.buildconfigspec('cmd_dm')
-def test_dm_static(u_boot_console):
+def test_dm_static(ubman):
"""Test that each driver in `dm static` is also listed in `dm drivers`."""
- response = u_boot_console.run_command('dm static')
+ response = ubman.run_command('dm static')
drivers = (line[:25].rstrip() for line in response[:-1].split('\n')[2:])
- response = u_boot_console.run_command('dm drivers')
+ response = ubman.run_command('dm drivers')
for driver in drivers:
assert driver in response
@pytest.mark.buildconfigspec("cmd_dm")
-def test_dm_uclass(u_boot_console):
- response = u_boot_console.run_command("dm uclass")
+def test_dm_uclass(ubman):
+ response = ubman.run_command("dm uclass")
@pytest.mark.buildconfigspec("cmd_dm")
-def test_dm_devres(u_boot_console):
- response = u_boot_console.run_command("dm devres")
+def test_dm_devres(ubman):
+ response = ubman.run_command("dm devres")
diff --git a/test/py/tests/test_efi_bootmgr.py b/test/py/tests/test_efi_bootmgr.py
new file mode 100644
index 00000000000..4c10cbdf17d
--- /dev/null
+++ b/test/py/tests/test_efi_bootmgr.py
@@ -0,0 +1,70 @@
+# SPDX-License-Identifier: GPL-2.0+
+""" Unit test for UEFI bootmanager
+"""
+
+import shutil
+import pytest
+from subprocess import call, check_call, CalledProcessError
+from tests import fs_helper
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_efidebug')
+@pytest.mark.buildconfigspec('cmd_bootefi_bootmgr')
+@pytest.mark.singlethread
+def test_efi_bootmgr(ubman):
+ """ Unit test for UEFI bootmanager
+ The efidebug command is used to set up UEFI load options.
+ The bootefi bootmgr loads initrddump.efi as a payload.
+ The crc32 of the loaded initrd.img is checked
+
+ Args:
+ ubman -- U-Boot console
+ """
+ try:
+ efi_bootmgr_data, mnt = fs_helper.setup_image(ubman, 0, 0xc,
+ basename='test_efi_bootmgr')
+
+ with open(mnt + '/initrd-1.img', 'w', encoding = 'ascii') as file:
+ file.write("initrd 1")
+
+ with open(mnt + '/initrd-2.img', 'w', encoding = 'ascii') as file:
+ file.write("initrd 2")
+
+ shutil.copyfile(ubman.config.build_dir + '/lib/efi_loader/initrddump.efi',
+ mnt + '/initrddump.efi')
+
+ fsfile = fs_helper.mk_fs(ubman.config, 'vfat', 0x100000,
+ 'test_efi_bootmgr', mnt)
+ check_call(f'dd if={fsfile} of={efi_bootmgr_data} bs=1M seek=1', shell=True)
+
+ ubman.run_command(cmd = f'host bind 0 {efi_bootmgr_data}')
+
+ ubman.run_command(cmd = 'efidebug boot add ' \
+ '-b 0001 label-1 host 0:1 initrddump.efi ' \
+ '-i host 0:1 initrd-1.img -s nocolor')
+ ubman.run_command(cmd = 'efidebug boot dump')
+ ubman.run_command(cmd = 'efidebug boot order 0001')
+ ubman.run_command(cmd = 'bootefi bootmgr')
+ response = ubman.run_command(cmd = 'load', wait_for_echo=False)
+ assert 'crc32: 0x181464af' in response
+ ubman.run_command(cmd = 'exit', wait_for_echo=False)
+
+ ubman.run_command(cmd = 'efidebug boot add ' \
+ '-B 0002 label-2 host 0:1 initrddump.efi ' \
+ '-I host 0:1 initrd-2.img -s nocolor')
+ ubman.run_command(cmd = 'efidebug boot dump')
+ ubman.run_command(cmd = 'efidebug boot order 0002')
+ ubman.run_command(cmd = 'bootefi bootmgr')
+ response = ubman.run_command(cmd = 'load', wait_for_echo=False)
+ assert 'crc32: 0x811d3515' in response
+ ubman.run_command(cmd = 'exit', wait_for_echo=False)
+
+ ubman.run_command(cmd = 'efidebug boot rm 0001')
+ ubman.run_command(cmd = 'efidebug boot rm 0002')
+ except CalledProcessError as err:
+ pytest.skip('Preparing test_efi_bootmgr image failed')
+ call('rm -f %s' % efi_bootmgr_data, shell=True)
+ return
+ finally:
+ call('rm -rf %s' % mnt, shell=True)
+ call('rm -f %s' % efi_bootmgr_data, shell=True)
diff --git a/test/py/tests/test_efi_bootmgr/conftest.py b/test/py/tests/test_efi_bootmgr/conftest.py
deleted file mode 100644
index 0eca025058e..00000000000
--- a/test/py/tests/test_efi_bootmgr/conftest.py
+++ /dev/null
@@ -1,38 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0+
-
-"""Fixture for UEFI bootmanager test."""
-
-import os
-import shutil
-from subprocess import check_call
-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.
-
- Args:
- u_boot_config -- U-Boot configuration.
-
- Return:
- A path to disk image to be used for testing
- """
- mnt_point = u_boot_config.persistent_data_dir + '/test_efi_bootmgr'
- image_path = u_boot_config.persistent_data_dir + '/efi_bootmgr.img'
-
- shutil.rmtree(mnt_point, ignore_errors=True)
- os.mkdir(mnt_point, mode = 0o755)
-
- with open(mnt_point + '/initrd-1.img', 'w', encoding = 'ascii') as file:
- file.write("initrd 1")
-
- with open(mnt_point + '/initrd-2.img', 'w', encoding = 'ascii') as file:
- file.write("initrd 2")
-
- shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/initrddump.efi',
- mnt_point + '/initrddump.efi')
-
- check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}',
- shell=True)
-
- return image_path
diff --git a/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py b/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
deleted file mode 100644
index 1bb59d8fcf8..00000000000
--- a/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
+++ /dev/null
@@ -1,44 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0+
-""" Unit test for UEFI bootmanager
-"""
-
-import pytest
-
-@pytest.mark.boardspec('sandbox')
-@pytest.mark.buildconfigspec('cmd_efidebug')
-@pytest.mark.buildconfigspec('cmd_bootefi_bootmgr')
-@pytest.mark.singlethread
-def test_efi_bootmgr(u_boot_console, efi_bootmgr_data):
- """ Unit test for UEFI bootmanager
- The efidebug command is used to set up UEFI load options.
- The bootefi bootmgr loads initrddump.efi as a payload.
- The crc32 of the loaded initrd.img is checked
-
- Args:
- u_boot_console -- U-Boot console
- efi_bootmgr_data -- Path to the disk image used for testing.
- """
- u_boot_console.run_command(cmd = f'host bind 0 {efi_bootmgr_data}')
-
- u_boot_console.run_command(cmd = 'efidebug boot add ' \
- '-b 0001 label-1 host 0:1 initrddump.efi ' \
- '-i host 0:1 initrd-1.img -s nocolor')
- u_boot_console.run_command(cmd = 'efidebug boot dump')
- u_boot_console.run_command(cmd = 'efidebug boot order 0001')
- u_boot_console.run_command(cmd = 'bootefi bootmgr')
- response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
- assert 'crc32: 0x181464af' in response
- u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
-
- u_boot_console.run_command(cmd = 'efidebug boot add ' \
- '-B 0002 label-2 host 0:1 initrddump.efi ' \
- '-I host 0:1 initrd-2.img -s nocolor')
- u_boot_console.run_command(cmd = 'efidebug boot dump')
- u_boot_console.run_command(cmd = 'efidebug boot order 0002')
- u_boot_console.run_command(cmd = 'bootefi bootmgr')
- response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
- assert 'crc32: 0x811d3515' in response
- u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
-
- u_boot_console.run_command(cmd = 'efidebug boot rm 0001')
- u_boot_console.run_command(cmd = 'efidebug boot rm 0002')
diff --git a/test/py/tests/test_efi_capsule/capsule_common.py b/test/py/tests/test_efi_capsule/capsule_common.py
index fc0d851c619..04dabc176c4 100644
--- a/test/py/tests/test_efi_capsule/capsule_common.py
+++ b/test/py/tests/test_efi_capsule/capsule_common.py
@@ -6,15 +6,15 @@
from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR
-def capsule_setup(u_boot_console, disk_img, osindications):
+def capsule_setup(ubman, disk_img, osindications):
"""setup the test
Args:
- u_boot_console -- A console connection to U-Boot.
+ ubman -- A console connection to U-Boot.
disk_img -- A path to disk image to be used for testing.
osindications -- String of osindications value.
"""
- u_boot_console.run_command_list([
+ ubman.run_command_list([
f'host bind 0 {disk_img}',
'printenv -e PlatformLangCodes', # workaround for terminal size determination
'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi',
@@ -23,22 +23,22 @@ def capsule_setup(u_boot_console, disk_img, osindications):
'u-boot-env raw 0x150000 0x200000"'])
if osindications is None:
- u_boot_console.run_command('env set -e OsIndications')
+ ubman.run_command('env set -e OsIndications')
else:
- u_boot_console.run_command(f'env set -e -nv -bs -rt OsIndications ={osindications}')
+ ubman.run_command(f'env set -e -nv -bs -rt OsIndications ={osindications}')
- u_boot_console.run_command('env save')
+ ubman.run_command('env save')
-def init_content(u_boot_console, target, filename, expected):
+def init_content(ubman, target, filename, expected):
"""initialize test content
Args:
- u_boot_console -- A console connection to U-Boot.
+ ubman -- A console connection to U-Boot.
target -- Target address to place the content.
filename -- File name of the content.
expected -- Expected string of the content.
"""
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'sf probe 0:0',
f'fatload host 0:1 4000000 {CAPSULE_DATA_DIR}/{filename}',
f'sf write 4000000 {target} 10',
@@ -46,34 +46,34 @@ def init_content(u_boot_console, target, filename, expected):
'md.b 5000000 10'])
assert expected in ''.join(output)
-def place_capsule_file(u_boot_console, filenames):
+def place_capsule_file(ubman, filenames):
"""place the capsule file
Args:
- u_boot_console -- A console connection to U-Boot.
+ ubman -- A console connection to U-Boot.
filenames -- File name array of the target capsule files.
"""
for name in filenames:
- u_boot_console.run_command_list([
+ ubman.run_command_list([
f'fatload host 0:1 4000000 {CAPSULE_DATA_DIR}/{name}',
f'fatwrite host 0:1 4000000 {CAPSULE_INSTALL_DIR}/{name} $filesize'])
- output = u_boot_console.run_command(f'fatls host 0:1 {CAPSULE_INSTALL_DIR}')
+ output = ubman.run_command(f'fatls host 0:1 {CAPSULE_INSTALL_DIR}')
for name in filenames:
assert name in ''.join(output)
-def exec_manual_update(u_boot_console, disk_img, filenames, need_reboot = True):
+def exec_manual_update(ubman, disk_img, filenames, need_reboot = True):
"""execute capsule update manually
Args:
- u_boot_console -- A console connection to U-Boot.
+ ubman -- A console connection to U-Boot.
disk_img -- A path to disk image to be used for testing.
filenames -- File name array of the target capsule files.
need_reboot -- Flag indicates whether system reboot is required.
"""
# make sure that dfu_alt_info exists even persistent variables
# are not available.
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'env set dfu_alt_info '
'"sf 0:0=u-boot-bin raw 0x100000 0x50000;'
'u-boot-env raw 0x150000 0x200000"',
@@ -83,60 +83,60 @@ def exec_manual_update(u_boot_console, disk_img, filenames, need_reboot = True):
assert name in ''.join(output)
# need to run uefi command to initiate capsule handling
- u_boot_console.run_command(
+ ubman.run_command(
'env print -e Capsule0000', wait_for_reboot = need_reboot)
-def check_file_removed(u_boot_console, disk_img, filenames):
+def check_file_removed(ubman, disk_img, filenames):
"""check files are removed
Args:
- u_boot_console -- A console connection to U-Boot.
+ ubman -- A console connection to U-Boot.
disk_img -- A path to disk image to be used for testing.
filenames -- File name array of the target capsule files.
"""
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
f'host bind 0 {disk_img}',
f'fatls host 0:1 {CAPSULE_INSTALL_DIR}'])
for name in filenames:
assert name not in ''.join(output)
-def check_file_exist(u_boot_console, disk_img, filenames):
+def check_file_exist(ubman, disk_img, filenames):
"""check files exist
Args:
- u_boot_console -- A console connection to U-Boot.
+ ubman -- A console connection to U-Boot.
disk_img -- A path to disk image to be used for testing.
filenames -- File name array of the target capsule files.
"""
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
f'host bind 0 {disk_img}',
f'fatls host 0:1 {CAPSULE_INSTALL_DIR}'])
for name in filenames:
assert name in ''.join(output)
-def verify_content(u_boot_console, target, expected):
+def verify_content(ubman, target, expected):
"""verify the content
Args:
- u_boot_console -- A console connection to U-Boot.
+ ubman -- A console connection to U-Boot.
target -- Target address to verify.
expected -- Expected string of the content.
"""
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'sf probe 0:0',
f'sf read 4000000 {target} 10',
'md.b 4000000 10'])
assert expected in ''.join(output)
-def do_reboot_dtb_specified(u_boot_config, u_boot_console, dtb_filename):
+def do_reboot_dtb_specified(u_boot_config, ubman, dtb_filename):
"""do reboot with specified DTB
Args:
u_boot_config -- U-boot configuration.
- u_boot_console -- A console connection to U-Boot.
+ ubman -- A console connection to U-Boot.
dtb_filename -- DTB file name.
"""
- mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule'
- u_boot_console.config.dtb = mnt_point + CAPSULE_DATA_DIR \
+ mnt_point = u_boot_config.persistent_data_dir + '/scratch'
+ ubman.config.dtb = mnt_point + CAPSULE_DATA_DIR \
+ f'/{dtb_filename}'
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
diff --git a/test/py/tests/test_efi_capsule/conftest.py b/test/py/tests/test_efi_capsule/conftest.py
index 80b12977d6f..961d2e0b3c1 100644
--- a/test/py/tests/test_efi_capsule/conftest.py
+++ b/test/py/tests/test_efi_capsule/conftest.py
@@ -7,11 +7,12 @@
import os
from subprocess import call, check_call, CalledProcessError
+from tests import fs_helper
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):
+@pytest.fixture(scope='function')
+def efi_capsule_data(request, ubman):
"""Set up a file system and return path to image.
The function sets up a file system to be used in UEFI capsule and
@@ -19,14 +20,14 @@ def efi_capsule_data(request, u_boot_config):
for testing.
request -- Pytest request object.
- u_boot_config -- U-Boot configuration.
+ ubman -- U-Boot configuration.
"""
- 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
- image_path = u_boot_config.persistent_data_dir + '/test_efi_capsule.img'
-
try:
+ image_path, mnt_point = fs_helper.setup_image(ubman, 0, 0xc,
+ basename='test_efi_capsule')
+ data_dir = mnt_point + CAPSULE_DATA_DIR
+ install_dir = mnt_point + CAPSULE_INSTALL_DIR
+
# Create a target device
check_call('dd if=/dev/zero of=./spi.bin bs=1MiB count=16', shell=True)
@@ -34,9 +35,9 @@ def efi_capsule_data(request, u_boot_config):
check_call('mkdir -p %s' % data_dir, shell=True)
check_call('mkdir -p %s' % install_dir, shell=True)
- capsule_auth_enabled = u_boot_config.buildconfig.get(
+ capsule_auth_enabled = ubman.config.buildconfig.get(
'config_efi_capsule_authenticate')
- key_dir = u_boot_config.source_dir + '/board/sandbox'
+ key_dir = ubman.config.source_dir + '/board/sandbox'
if capsule_auth_enabled:
# Get the keys from the board directory
check_call('cp %s/capsule_priv_key_good.key %s/SIGNER.key'
@@ -53,46 +54,50 @@ def efi_capsule_data(request, u_boot_config):
# Update dtb to add the version information
check_call('cd %s; '
- 'cp %s/test/py/tests/test_efi_capsule/version.dts .'
- % (data_dir, u_boot_config.source_dir), shell=True)
+ 'cp %s/test/py/tests/test_efi_capsule/version.dtso .'
+ % (data_dir, ubman.config.source_dir), shell=True)
if capsule_auth_enabled:
check_call('cd %s; '
'cp %s/arch/sandbox/dts/test.dtb test_sig.dtb'
- % (data_dir, u_boot_config.build_dir), shell=True)
+ % (data_dir, ubman.config.build_dir), shell=True)
check_call('cd %s; '
- 'dtc -@ -I dts -O dtb -o version.dtbo version.dts; '
+ 'dtc -@ -I dts -O dtb -o version.dtbo version.dtso; '
'fdtoverlay -i test_sig.dtb '
'-o test_ver.dtb version.dtbo'
% (data_dir), shell=True)
else:
check_call('cd %s; '
- 'dtc -@ -I dts -O dtb -o version.dtbo version.dts; '
+ 'dtc -@ -I dts -O dtb -o version.dtbo version.dtso; '
'fdtoverlay -i %s/arch/sandbox/dts/test.dtb '
'-o test_ver.dtb version.dtbo'
- % (data_dir, u_boot_config.build_dir), shell=True)
+ % (data_dir, ubman.config.build_dir), shell=True)
# two regions: one for u-boot.bin and the other for u-boot.env
check_call('cd %s; echo -n u-boot:Old > u-boot.bin.old; echo -n u-boot:New > u-boot.bin.new; echo -n u-boot-env:Old > u-boot.env.old; echo -n u-boot-env:New > u-boot.env.new' % data_dir,
shell=True)
pythonpath = os.environ.get('PYTHONPATH', '')
- os.environ['PYTHONPATH'] = pythonpath + ':' + '%s/scripts/dtc/pylibfdt' % u_boot_config.build_dir
+ os.environ['PYTHONPATH'] = pythonpath + ':' + '%s/scripts/dtc/pylibfdt' % ubman.config.build_dir
check_call('cd %s; '
'cc -E -I %s/include -x assembler-with-cpp -o capsule_gen_tmp.dts %s/test/py/tests/test_efi_capsule/capsule_gen_binman.dts; '
'dtc -I dts -O dtb capsule_gen_tmp.dts -o capsule_binman.dtb;'
- % (data_dir, u_boot_config.source_dir, u_boot_config.source_dir), shell=True)
+ % (data_dir, ubman.config.source_dir, ubman.config.source_dir), shell=True)
check_call('cd %s; '
'./tools/binman/binman --toolpath %s/tools build -u -d %s/capsule_binman.dtb -O %s -m --allow-missing -I %s -I ./board/sandbox -I ./arch/sandbox/dts'
- % (u_boot_config.source_dir, u_boot_config.build_dir, data_dir, data_dir, data_dir), shell=True)
- check_call('cp %s/Test* %s' % (u_boot_config.build_dir, data_dir), shell=True)
+ % (ubman.config.source_dir, ubman.config.build_dir, data_dir, data_dir, data_dir), shell=True)
+ check_call('cp %s/Test* %s' % (ubman.config.build_dir, data_dir), shell=True)
os.environ['PYTHONPATH'] = pythonpath
- # Create a disk image with EFI system partition
- check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat %s %s' %
- (mnt_point, image_path), shell=True)
+ # Create a 16MiB partition as the EFI system partition in the disk
+ # image
+ fsfile = fs_helper.mk_fs(ubman.config, 'vfat', 0x1000000,
+ 'test_efi_capsule', mnt_point)
+ check_call(f'dd conv=notrunc if={fsfile} of={image_path} bs=1M seek=1', shell=True)
+ check_call('sgdisk --mbrtogpt %s' % image_path, shell=True)
check_call('sgdisk %s -A 1:set:0 -t 1:C12A7328-F81F-11D2-BA4B-00A0C93EC93B' %
image_path, shell=True)
+ call('rm -f %s' % fsfile, shell=True)
except CalledProcessError as exception:
pytest.skip('Setup failed: %s' % exception.cmd)
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 11bcdc2bb29..016274533cd 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
@@ -33,7 +33,7 @@ class TestEfiCapsuleFirmwareFit():
"""
def test_efi_capsule_fw1(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, 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
@@ -44,34 +44,34 @@ class TestEfiCapsuleFirmwareFit():
# other tests might have run and the
# system might not be in a clean state.
# Restart before starting the tests.
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_capsule_data
capsule_files = ['Test05']
- with u_boot_console.log.section('Test Case 1-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 1-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ init_content(ubman, '150000', 'u-boot.env.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
# reboot
- u_boot_console.restart_uboot(expect_reset = capsule_early)
+ ubman.restart_uboot(expect_reset = capsule_early)
- with u_boot_console.log.section('Test Case 1-b, after reboot'):
+ with ubman.log.section('Test Case 1-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
# deleted anyway
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
- verify_content(u_boot_console, '100000', 'u-boot:Old')
- verify_content(u_boot_console, '150000', 'u-boot-env:Old')
+ verify_content(ubman, '100000', 'u-boot:Old')
+ verify_content(ubman, '150000', 'u-boot-env:Old')
def test_efi_capsule_fw2(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, efi_capsule_data):
"""Test Case 2
Update U-Boot and U-Boot environment on SPI Flash
0x100000-0x150000: U-Boot binary (but dummy)
@@ -80,11 +80,11 @@ class TestEfiCapsuleFirmwareFit():
disk_img = efi_capsule_data
capsule_files = ['Test04']
- with u_boot_console.log.section('Test Case 2-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 2-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ init_content(ubman, '150000', 'u-boot.env.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
@@ -92,22 +92,22 @@ class TestEfiCapsuleFirmwareFit():
'config_efi_capsule_authenticate')
# reboot
- u_boot_console.restart_uboot(expect_reset = capsule_early)
+ ubman.restart_uboot(expect_reset = capsule_early)
- with u_boot_console.log.section('Test Case 2-b, after reboot'):
+ with ubman.log.section('Test Case 2-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
expected = 'u-boot:Old' if capsule_auth else 'u-boot:New'
- verify_content(u_boot_console, '100000', expected)
+ verify_content(ubman, '100000', expected)
expected = 'u-boot-env:Old' if capsule_auth else 'u-boot-env:New'
- verify_content(u_boot_console, '150000', expected)
+ verify_content(ubman, '150000', expected)
def test_efi_capsule_fw3(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, efi_capsule_data):
""" Test Case 3
Update U-Boot on SPI Flash, raw image format with fw_version and lowest_supported_version
0x100000-0x150000: U-Boot binary (but dummy)
@@ -115,47 +115,47 @@ class TestEfiCapsuleFirmwareFit():
"""
disk_img = efi_capsule_data
capsule_files = ['Test104']
- with u_boot_console.log.section('Test Case 3-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 3-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ init_content(ubman, '150000', 'u-boot.env.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
# reboot
- do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
+ do_reboot_dtb_specified(u_boot_config, ubman, 'test_ver.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
capsule_auth = u_boot_config.buildconfig.get(
'config_efi_capsule_authenticate')
- with u_boot_console.log.section('Test Case 3-b, after reboot'):
+ with ubman.log.section('Test Case 3-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
# deleted anyway
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
# make sure the dfu_alt_info exists because it is required for making ESRT.
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;'
'u-boot-env raw 0x150000 0x200000"',
'efidebug capsule esrt'])
if capsule_auth:
# capsule authentication failed
- verify_content(u_boot_console, '100000', 'u-boot:Old')
- verify_content(u_boot_console, '150000', 'u-boot-env:Old')
+ verify_content(ubman, '100000', 'u-boot:Old')
+ verify_content(ubman, '150000', 'u-boot-env:Old')
else:
# ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT.
- assert '3673B45D-6A7C-46F3-9E60-ADABB03F7937' in ''.join(output)
+ assert '985F2937-7C2E-5E9A-8A5E-8E063312964B' in ''.join(output)
assert 'ESRT: fw_version=5' in ''.join(output)
assert 'ESRT: lowest_supported_fw_version=3' in ''.join(output)
- verify_content(u_boot_console, '100000', 'u-boot:New')
- verify_content(u_boot_console, '150000', 'u-boot-env:New')
+ verify_content(ubman, '100000', 'u-boot:New')
+ verify_content(ubman, '150000', 'u-boot-env:New')
def test_efi_capsule_fw4(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, efi_capsule_data):
""" Test Case 4
Update U-Boot on SPI Flash, raw image format with fw_version and lowest_supported_version
but fw_version is lower than lowest_supported_version
@@ -164,20 +164,20 @@ class TestEfiCapsuleFirmwareFit():
"""
disk_img = efi_capsule_data
capsule_files = ['Test105']
- with u_boot_console.log.section('Test Case 4-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 4-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
# reboot
- do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
+ do_reboot_dtb_specified(u_boot_config, ubman, 'test_ver.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
- with u_boot_console.log.section('Test Case 4-b, after reboot'):
+ with ubman.log.section('Test Case 4-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
- verify_content(u_boot_console, '100000', 'u-boot:Old')
+ verify_content(ubman, '100000', 'u-boot:Old')
diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py
index a5b5c8a3853..b8cb483b380 100644
--- a/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py
+++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py
@@ -34,7 +34,7 @@ class TestEfiCapsuleFirmwareRaw:
"""
def test_efi_capsule_fw1(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, 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
@@ -46,75 +46,86 @@ class TestEfiCapsuleFirmwareRaw:
# other tests might have run and the
# system might not be in a clean state.
# Restart before starting the tests.
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_capsule_data
capsule_files = ['Test03']
- with u_boot_console.log.section('Test Case 1-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 1-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ init_content(ubman, '150000', 'u-boot.env.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
# reboot
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
- with u_boot_console.log.section('Test Case 1-b, after reboot'):
+ with ubman.log.section('Test Case 1-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
# deleted anyway
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
- verify_content(u_boot_console, '100000', 'u-boot:Old')
- verify_content(u_boot_console, '150000', 'u-boot-env:Old')
+ verify_content(ubman, '100000', 'u-boot:Old')
+ verify_content(ubman, '150000', 'u-boot-env:Old')
def test_efi_capsule_fw2(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, efi_capsule_data):
""" Test Case 2
Update U-Boot and U-Boot environment on SPI Flash but with OsIndications unset
- No update should happen
+ No update should happen unless CONFIG_EFI_IGNORE_OSINDICATIONS is set
0x100000-0x150000: U-Boot binary (but dummy)
0x150000-0x200000: U-Boot environment (but dummy)
"""
disk_img = efi_capsule_data
capsule_files = ['Test01', 'Test02']
- with u_boot_console.log.section('Test Case 2-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, None)
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 2-a, before reboot'):
+ capsule_setup(ubman, disk_img, None)
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ init_content(ubman, '150000', 'u-boot.env.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
# reboot
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
+
+ ignore_os_indications = u_boot_config.buildconfig.get(
+ 'config_efi_ignore_osindications')
+ need_reboot = True if ignore_os_indications else False
+
+ capsule_auth = u_boot_config.buildconfig.get(
+ 'config_efi_capsule_authenticate')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
- with u_boot_console.log.section('Test Case 2-b, after reboot'):
+ with ubman.log.section('Test Case 2-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files, False)
+ exec_manual_update(ubman, disk_img, capsule_files, need_reboot)
+
+ if not ignore_os_indications:
+ check_file_exist(ubman, disk_img, capsule_files)
- check_file_exist(u_boot_console, disk_img, capsule_files)
+ expected = 'u-boot:New' if (ignore_os_indications and not capsule_auth) else 'u-boot:Old'
+ verify_content(ubman, '100000', expected)
- verify_content(u_boot_console, '100000', 'u-boot:Old')
- verify_content(u_boot_console, '150000', 'u-boot-env:Old')
+ expected = 'u-boot-env:New' if (ignore_os_indications and not capsule_auth) else 'u-boot-env:Old'
+ verify_content(ubman, '150000', expected)
def test_efi_capsule_fw3(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, efi_capsule_data):
""" Test Case 3
Update U-Boot on SPI Flash, raw image format
0x100000-0x150000: U-Boot binary (but dummy)
"""
disk_img = efi_capsule_data
capsule_files = ['Test01', 'Test02']
- with u_boot_console.log.section('Test Case 3-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 3-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ init_content(ubman, '150000', 'u-boot.env.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
@@ -122,33 +133,33 @@ class TestEfiCapsuleFirmwareRaw:
'config_efi_capsule_authenticate')
# reboot
- u_boot_console.restart_uboot(expect_reset = capsule_early)
+ ubman.restart_uboot(expect_reset = capsule_early)
- with u_boot_console.log.section('Test Case 3-b, after reboot'):
+ with ubman.log.section('Test Case 3-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
# make sure the dfu_alt_info exists because it is required for making ESRT.
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
'efidebug capsule esrt'])
# ensure that SANDBOX_UBOOT_ENV_IMAGE_GUID is in the ESRT.
- assert '5A7021F5-FEF2-48B4-AABA-832E777418C0' in ''.join(output)
+ assert '9E339473-C2EB-530A-A69B-0CD6BBBED40E' in ''.join(output)
# ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT.
- assert '09D7CF52-0720-4710-91D1-08469B7FE9C8' in ''.join(output)
+ assert '985F2937-7C2E-5E9A-8A5E-8E063312964B' in ''.join(output)
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
expected = 'u-boot:Old' if capsule_auth else 'u-boot:New'
- verify_content(u_boot_console, '100000', expected)
+ verify_content(ubman, '100000', expected)
expected = 'u-boot-env:Old' if capsule_auth else 'u-boot-env:New'
- verify_content(u_boot_console, '150000', expected)
+ verify_content(ubman, '150000', expected)
def test_efi_capsule_fw4(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, efi_capsule_data):
""" Test Case 4
Update U-Boot on SPI Flash, raw image format with fw_version and lowest_supported_version
0x100000-0x150000: U-Boot binary (but dummy)
@@ -156,52 +167,52 @@ class TestEfiCapsuleFirmwareRaw:
"""
disk_img = efi_capsule_data
capsule_files = ['Test101', 'Test102']
- with u_boot_console.log.section('Test Case 4-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 4-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ init_content(ubman, '150000', 'u-boot.env.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
# reboot
- do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
+ do_reboot_dtb_specified(u_boot_config, ubman, 'test_ver.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
capsule_auth = u_boot_config.buildconfig.get(
'config_efi_capsule_authenticate')
- with u_boot_console.log.section('Test Case 4-b, after reboot'):
+ with ubman.log.section('Test Case 4-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
# deleted anyway
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
# make sure the dfu_alt_info exists because it is required for making ESRT.
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000'
'u-boot-env raw 0x150000 0x200000"',
'efidebug capsule esrt'])
if capsule_auth:
# capsule authentication failed
- verify_content(u_boot_console, '100000', 'u-boot:Old')
- verify_content(u_boot_console, '150000', 'u-boot-env:Old')
+ verify_content(ubman, '100000', 'u-boot:Old')
+ verify_content(ubman, '150000', 'u-boot-env:Old')
else:
# ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT.
- assert '09D7CF52-0720-4710-91D1-08469B7FE9C8' in ''.join(output)
+ assert '985F2937-7C2E-5E9A-8A5E-8E063312964B' in ''.join(output)
assert 'ESRT: fw_version=5' in ''.join(output)
assert 'ESRT: lowest_supported_fw_version=3' in ''.join(output)
# ensure that SANDBOX_UBOOT_ENV_IMAGE_GUID is in the ESRT.
- assert '5A7021F5-FEF2-48B4-AABA-832E777418C0' in ''.join(output)
+ assert '9E339473-C2EB-530A-A69B-0CD6BBBED40E' in ''.join(output)
assert 'ESRT: fw_version=10' in ''.join(output)
assert 'ESRT: lowest_supported_fw_version=7' in ''.join(output)
- verify_content(u_boot_console, '100000', 'u-boot:New')
- verify_content(u_boot_console, '150000', 'u-boot-env:New')
+ verify_content(ubman, '100000', 'u-boot:New')
+ verify_content(ubman, '150000', 'u-boot-env:New')
def test_efi_capsule_fw5(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, efi_capsule_data):
""" Test Case 5
Update U-Boot on SPI Flash, raw image format with fw_version and lowest_supported_version
but fw_version is lower than lowest_supported_version
@@ -210,20 +221,20 @@ class TestEfiCapsuleFirmwareRaw:
"""
disk_img = efi_capsule_data
capsule_files = ['Test103']
- with u_boot_console.log.section('Test Case 5-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 5-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
# reboot
- do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
+ do_reboot_dtb_specified(u_boot_config, ubman, 'test_ver.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
- with u_boot_console.log.section('Test Case 5-b, after reboot'):
+ with ubman.log.section('Test Case 5-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
- verify_content(u_boot_console, '100000', 'u-boot:Old')
+ verify_content(ubman, '100000', 'u-boot:Old')
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 44a58baa310..29545c5080a 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
@@ -36,7 +36,7 @@ class TestEfiCapsuleFirmwareSignedFit():
"""
def test_efi_capsule_auth1(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, efi_capsule_data):
"""Test Case 1
Update U-Boot on SPI Flash, FIT image format
x150000: U-Boot binary (but dummy)
@@ -46,25 +46,25 @@ class TestEfiCapsuleFirmwareSignedFit():
"""
disk_img = efi_capsule_data
capsule_files = ['Test13']
- with u_boot_console.log.section('Test Case 1-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 1-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
- do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_sig.dtb')
+ do_reboot_dtb_specified(u_boot_config, ubman, 'test_sig.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
- with u_boot_console.log.section('Test Case 1-b, after reboot'):
+ with ubman.log.section('Test Case 1-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
- verify_content(u_boot_console, '100000', 'u-boot:New')
+ verify_content(ubman, '100000', 'u-boot:New')
def test_efi_capsule_auth2(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, efi_capsule_data):
"""Test Case 2
Update U-Boot on SPI Flash, FIT image format
0x100000-0x150000: U-Boot binary (but dummy)
@@ -75,28 +75,28 @@ class TestEfiCapsuleFirmwareSignedFit():
"""
disk_img = efi_capsule_data
capsule_files = ['Test14']
- with u_boot_console.log.section('Test Case 2-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 2-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
- do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_sig.dtb')
+ do_reboot_dtb_specified(u_boot_config, ubman, 'test_sig.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
- with u_boot_console.log.section('Test Case 2-b, after reboot'):
+ with ubman.log.section('Test Case 2-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
# deleted any way
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
# TODO: check CapsuleStatus in CapsuleXXXX
- verify_content(u_boot_console, '100000', 'u-boot:Old')
+ verify_content(ubman, '100000', 'u-boot:Old')
def test_efi_capsule_auth3(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, efi_capsule_data):
"""Test Case 3
Update U-Boot on SPI Flash, FIT image format
0x100000-0x150000: U-Boot binary (but dummy)
@@ -106,28 +106,28 @@ class TestEfiCapsuleFirmwareSignedFit():
"""
disk_img = efi_capsule_data
capsule_files = ['Test02']
- with u_boot_console.log.section('Test Case 3-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 3-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
- do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_sig.dtb')
+ do_reboot_dtb_specified(u_boot_config, ubman, 'test_sig.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
- with u_boot_console.log.section('Test Case 3-b, after reboot'):
+ with ubman.log.section('Test Case 3-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
# deleted any way
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
# TODO: check CapsuleStatus in CapsuleXXXX
- verify_content(u_boot_console, '100000', 'u-boot:Old')
+ verify_content(ubman, '100000', 'u-boot:Old')
def test_efi_capsule_auth4(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, efi_capsule_data):
"""Test Case 4 - Update U-Boot on SPI Flash, raw image format with version information
0x100000-0x150000: U-Boot binary (but dummy)
@@ -136,36 +136,36 @@ class TestEfiCapsuleFirmwareSignedFit():
"""
disk_img = efi_capsule_data
capsule_files = ['Test114']
- with u_boot_console.log.section('Test Case 4-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 4-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
- do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
+ do_reboot_dtb_specified(u_boot_config, ubman, 'test_ver.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
- with u_boot_console.log.section('Test Case 4-b, after reboot'):
+ with ubman.log.section('Test Case 4-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;'
'u-boot-env raw 0x150000 0x200000"',
'efidebug capsule esrt'])
# ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT.
- assert '3673B45D-6A7C-46F3-9E60-ADABB03F7937' in ''.join(output)
+ assert '46610520-469E-59DC-A8DD-C11832B877EA' in ''.join(output)
assert 'ESRT: fw_version=5' in ''.join(output)
assert 'ESRT: lowest_supported_fw_version=3' in ''.join(output)
- verify_content(u_boot_console, '100000', 'u-boot:New')
- verify_content(u_boot_console, '150000', 'u-boot-env:New')
+ verify_content(ubman, '100000', 'u-boot:New')
+ verify_content(ubman, '150000', 'u-boot-env:New')
def test_efi_capsule_auth5(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, efi_capsule_data):
"""Test Case 5 - Update U-Boot on SPI Flash, raw image format with version information
0x100000-0x150000: U-Boot binary (but dummy)
@@ -175,19 +175,19 @@ class TestEfiCapsuleFirmwareSignedFit():
"""
disk_img = efi_capsule_data
capsule_files = ['Test115']
- with u_boot_console.log.section('Test Case 5-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 5-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
- do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
+ do_reboot_dtb_specified(u_boot_config, ubman, 'test_ver.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
- with u_boot_console.log.section('Test Case 5-b, after reboot'):
+ with ubman.log.section('Test Case 5-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
- verify_content(u_boot_console, '100000', 'u-boot:Old')
+ verify_content(ubman, '100000', 'u-boot:Old')
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 83a10e160b8..a500c499bb9 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
@@ -34,7 +34,7 @@ class TestEfiCapsuleFirmwareSignedRaw():
"""
def test_efi_capsule_auth1(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, efi_capsule_data):
"""Test Case 1 - Update U-Boot on SPI Flash, raw image format
0x100000-0x150000: U-Boot binary (but dummy)
@@ -43,25 +43,25 @@ class TestEfiCapsuleFirmwareSignedRaw():
"""
disk_img = efi_capsule_data
capsule_files = ['Test11']
- with u_boot_console.log.section('Test Case 1-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 1-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
- do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_sig.dtb')
+ do_reboot_dtb_specified(u_boot_config, ubman, 'test_sig.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
- with u_boot_console.log.section('Test Case 1-b, after reboot'):
+ with ubman.log.section('Test Case 1-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
- verify_content(u_boot_console, '100000', 'u-boot:New')
+ verify_content(ubman, '100000', 'u-boot:New')
def test_efi_capsule_auth2(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, efi_capsule_data):
"""Test Case 2 - Update U-Boot on SPI Flash, raw image format
0x100000-0x150000: U-Boot binary (but dummy)
@@ -71,27 +71,27 @@ class TestEfiCapsuleFirmwareSignedRaw():
"""
disk_img = efi_capsule_data
capsule_files = ['Test12']
- with u_boot_console.log.section('Test Case 2-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 2-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
- do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_sig.dtb')
+ do_reboot_dtb_specified(u_boot_config, ubman, 'test_sig.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
- with u_boot_console.log.section('Test Case 2-b, after reboot'):
+ with ubman.log.section('Test Case 2-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
# TODO: check CapsuleStatus in CapsuleXXXX
- verify_content(u_boot_console, '100000', 'u-boot:Old')
+ verify_content(ubman, '100000', 'u-boot:Old')
def test_efi_capsule_auth3(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, efi_capsule_data):
"""Test Case 3 - Update U-Boot on SPI Flash, raw image format
0x100000-0x150000: U-Boot binary (but dummy)
@@ -100,28 +100,28 @@ class TestEfiCapsuleFirmwareSignedRaw():
"""
disk_img = efi_capsule_data
capsule_files = ['Test02']
- with u_boot_console.log.section('Test Case 3-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 3-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
- do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_sig.dtb')
+ do_reboot_dtb_specified(u_boot_config, ubman, 'test_sig.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
- with u_boot_console.log.section('Test Case 3-b, after reboot'):
+ with ubman.log.section('Test Case 3-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
# deleted anyway
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
# TODO: check CapsuleStatus in CapsuleXXXX
- verify_content(u_boot_console, '100000', 'u-boot:Old')
+ verify_content(ubman, '100000', 'u-boot:Old')
def test_efi_capsule_auth4(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, efi_capsule_data):
"""Test Case 4 - Update U-Boot on SPI Flash, raw image format with version information
0x100000-0x150000: U-Boot binary (but dummy)
@@ -130,41 +130,41 @@ class TestEfiCapsuleFirmwareSignedRaw():
"""
disk_img = efi_capsule_data
capsule_files = ['Test111', 'Test112']
- with u_boot_console.log.section('Test Case 4-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 4-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
- do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
+ do_reboot_dtb_specified(u_boot_config, ubman, 'test_ver.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
- with u_boot_console.log.section('Test Case 4-b, after reboot'):
+ with ubman.log.section('Test Case 4-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;'
'u-boot-env raw 0x150000 0x200000"',
'efidebug capsule esrt'])
# ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT.
- assert '09D7CF52-0720-4710-91D1-08469B7FE9C8' in ''.join(output)
+ assert '985F2937-7C2E-5E9A-8A5E-8E063312964B' in ''.join(output)
assert 'ESRT: fw_version=5' in ''.join(output)
assert 'ESRT: lowest_supported_fw_version=3' in ''.join(output)
# ensure that SANDBOX_UBOOT_ENV_IMAGE_GUID is in the ESRT.
- assert '5A7021F5-FEF2-48B4-AABA-832E777418C0' in ''.join(output)
+ assert '9E339473-C2EB-530A-A69B-0CD6BBBED40E' in ''.join(output)
assert 'ESRT: fw_version=10' in ''.join(output)
assert 'ESRT: lowest_supported_fw_version=7' in ''.join(output)
- verify_content(u_boot_console, '100000', 'u-boot:New')
- verify_content(u_boot_console, '150000', 'u-boot-env:New')
+ verify_content(ubman, '100000', 'u-boot:New')
+ verify_content(ubman, '150000', 'u-boot-env:New')
def test_efi_capsule_auth5(
- self, u_boot_config, u_boot_console, efi_capsule_data):
+ self, u_boot_config, ubman, efi_capsule_data):
"""Test Case 5 - Update U-Boot on SPI Flash, raw image format with version information
0x100000-0x150000: U-Boot binary (but dummy)
@@ -174,19 +174,19 @@ class TestEfiCapsuleFirmwareSignedRaw():
"""
disk_img = efi_capsule_data
capsule_files = ['Test113']
- with u_boot_console.log.section('Test Case 5-a, before reboot'):
- capsule_setup(u_boot_console, disk_img, '0x0000000000000004')
- init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
- place_capsule_file(u_boot_console, capsule_files)
+ with ubman.log.section('Test Case 5-a, before reboot'):
+ capsule_setup(ubman, disk_img, '0x0000000000000004')
+ init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(ubman, capsule_files)
- do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
+ do_reboot_dtb_specified(u_boot_config, ubman, 'test_ver.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
- with u_boot_console.log.section('Test Case 5-b, after reboot'):
+ with ubman.log.section('Test Case 5-b, after reboot'):
if not capsule_early:
- exec_manual_update(u_boot_console, disk_img, capsule_files)
+ exec_manual_update(ubman, disk_img, capsule_files)
- check_file_removed(u_boot_console, disk_img, capsule_files)
+ check_file_removed(ubman, disk_img, capsule_files)
- verify_content(u_boot_console, '100000', 'u-boot:Old')
+ verify_content(ubman, '100000', 'u-boot:Old')
diff --git a/test/py/tests/test_efi_capsule/version.dts b/test/py/tests/test_efi_capsule/version.dtso
index 07850cc6064..3aebb5b64fb 100644
--- a/test/py/tests/test_efi_capsule/version.dts
+++ b/test/py/tests/test_efi_capsule/version.dtso
@@ -8,17 +8,17 @@
image1 {
lowest-supported-version = <3>;
image-index = <1>;
- image-type-id = "09D7CF52-0720-4710-91D1-08469B7FE9C8";
+ image-type-id = "985F2937-7C2E-5E9A-8A5E-8E063312964B";
};
image2 {
lowest-supported-version = <7>;
image-index = <2>;
- image-type-id = "5A7021F5-FEF2-48B4-AABA-832E777418C0";
+ image-type-id = "9E339473-C2EB-530A-A69B-0CD6BBBED40E";
};
image3 {
lowest-supported-version = <3>;
image-index = <1>;
- image-type-id = "3673B45D-6A7C-46F3-9E60-ADABB03F7937";
+ image-type-id = "46610520-469E-59DC-A8DD-C11832B877EA";
};
};
};
diff --git a/test/py/tests/test_efi_fit.py b/test/py/tests/test_efi_fit.py
index 0ad483500f8..63ee8e6cef2 100644
--- a/test/py/tests/test_efi_fit.py
+++ b/test/py/tests/test_efi_fit.py
@@ -55,7 +55,7 @@ env__efi_fit_tftp_file = {
import os.path
import pytest
-import u_boot_utils as util
+import utils
# Define the parametrized ITS data to be used for FIT images generation.
ITS_DATA = '''
@@ -66,9 +66,29 @@ ITS_DATA = '''
#address-cells = <1>;
images {
- efi {
+ helloworld {
description = "Test EFI";
- data = /incbin/("%(efi-bin)s");
+ data = /incbin/("%(hello-bin)s");
+ type = "%(kernel-type)s";
+ arch = "%(sys-arch)s";
+ os = "efi";
+ compression = "%(efi-comp)s";
+ load = <0x0>;
+ entry = <0x0>;
+ };
+ dtbdump {
+ description = "Test EFI fdtdump";
+ data = /incbin/("%(dtbdump-bin)s");
+ type = "%(kernel-type)s";
+ arch = "%(sys-arch)s";
+ os = "efi";
+ compression = "%(efi-comp)s";
+ load = <0x0>;
+ entry = <0x0>;
+ };
+ initrddump {
+ description = "Test EFI initrddump";
+ data = /incbin/("%(initrddump-bin)s");
type = "%(kernel-type)s";
arch = "%(sys-arch)s";
os = "efi";
@@ -83,18 +103,33 @@ ITS_DATA = '''
arch = "%(sys-arch)s";
compression = "%(fdt-comp)s";
};
+ initrd {
+ description = "Initial RAM Disk";
+ data = /incbin/("%(initrd-fs)s");
+ type = "ramdisk";
+ compression = "%(initrd-comp)s";
+ os = "efi";
+ };
};
configurations {
default = "config-efi-fdt";
+
+ config-efi {
+ description = "EFI FIT w/o FDT";
+ kernel = "helloworld";
+ };
+
config-efi-fdt {
description = "EFI FIT w/ FDT";
- kernel = "efi";
+ kernel = "dtbdump";
fdt = "fdt";
};
- config-efi-nofdt {
- description = "EFI FIT w/o FDT";
- kernel = "efi";
+
+ config-efi-initrd {
+ description = "EFI FIT w/ initrd";
+ kernel = "initrddump";
+ ramdisk = "initrd";
};
};
};
@@ -108,7 +143,7 @@ FDT_DATA = '''
#address-cells = <1>;
#size-cells = <1>;
- model = "%(sys-arch)s %(fdt_type)s EFI FIT Boot Test";
+ model = "%(sys-arch)s %(fdt_type)s EFI FIT FDT Boot Test";
compatible = "%(sys-arch)s";
reset@0 {
@@ -119,11 +154,12 @@ FDT_DATA = '''
'''
@pytest.mark.buildconfigspec('bootm_efi')
-@pytest.mark.buildconfigspec('cmd_bootefi_hello_compile')
+@pytest.mark.buildconfigspec('BOOTEFI_HELLO_COMPILE')
+@pytest.mark.buildconfigspec('EFI_LOAD_FILE2_INITRD')
@pytest.mark.buildconfigspec('fit')
@pytest.mark.notbuildconfigspec('generate_acpi_table')
@pytest.mark.requiredtool('dtc')
-def test_efi_fit_launch(u_boot_console):
+def test_efi_fit_launch(ubman):
"""Test handling of UEFI binaries inside FIT images.
The tests are trying to launch U-Boot's helloworld.efi embedded into
@@ -137,8 +173,10 @@ def test_efi_fit_launch(u_boot_console):
The following test cases are currently defined and enabled:
- Launch uncompressed FIT EFI & internal FDT
- Launch uncompressed FIT EFI & FIT FDT
+ - Launch uncompressed FIT EFI & internal FDT & FIT initrd
- Launch compressed FIT EFI & internal FDT
- Launch compressed FIT EFI & FIT FDT
+ - Launch compressed FIT EFI & internal FDT & FIT initrd
"""
def net_pre_commands():
@@ -148,13 +186,13 @@ def test_efi_fit_launch(u_boot_console):
at the beginning of this file.
"""
- init_usb = cons.config.env.get('env__net_uses_usb', False)
+ init_usb = ubman.config.env.get('env__net_uses_usb', False)
if init_usb:
- cons.run_command('usb start')
+ ubman.run_command('usb start')
- init_pci = cons.config.env.get('env__net_uses_pci', False)
+ init_pci = ubman.config.env.get('env__net_uses_pci', False)
if init_pci:
- cons.run_command('pci enum')
+ ubman.run_command('pci enum')
def net_dhcp():
"""Execute the dhcp command.
@@ -163,18 +201,18 @@ def test_efi_fit_launch(u_boot_console):
comment at the beginning of this file.
"""
- has_dhcp = cons.config.buildconfig.get('config_cmd_dhcp', 'n') == 'y'
+ has_dhcp = ubman.config.buildconfig.get('config_cmd_dhcp', 'n') == 'y'
if not has_dhcp:
- cons.log.warning('CONFIG_CMD_DHCP != y: Skipping DHCP network setup')
+ ubman.log.warning('CONFIG_CMD_DHCP != y: Skipping DHCP network setup')
return False
- test_dhcp = cons.config.env.get('env__net_dhcp_server', False)
+ test_dhcp = ubman.config.env.get('env__net_dhcp_server', False)
if not test_dhcp:
- cons.log.info('No DHCP server available')
+ ubman.log.info('No DHCP server available')
return False
- cons.run_command('setenv autoload no')
- output = cons.run_command('dhcp')
+ ubman.run_command('setenv autoload no')
+ output = ubman.run_command('dhcp')
assert 'DHCP client bound to address ' in output
return True
@@ -185,18 +223,18 @@ def test_efi_fit_launch(u_boot_console):
the beginning of this file.
"""
- has_dhcp = cons.config.buildconfig.get('config_cmd_dhcp', 'n') == 'y'
+ has_dhcp = ubman.config.buildconfig.get('config_cmd_dhcp', 'n') == 'y'
if not has_dhcp:
- cons.log.warning('CONFIG_NET != y: Skipping static network setup')
+ ubman.log.warning('CONFIG_NET != y: Skipping static network setup')
return False
- env_vars = cons.config.env.get('env__net_static_env_vars', None)
+ env_vars = ubman.config.env.get('env__net_static_env_vars', None)
if not env_vars:
- cons.log.info('No static network configuration is defined')
+ ubman.log.info('No static network configuration is defined')
return False
for (var, val) in env_vars:
- cons.run_command('setenv %s %s' % (var, val))
+ ubman.run_command('setenv %s %s' % (var, val))
return True
def make_fpath(file_name):
@@ -208,9 +246,9 @@ def test_efi_fit_launch(u_boot_console):
The computed file path.
"""
- return os.path.join(cons.config.build_dir, file_name)
+ return os.path.join(ubman.config.build_dir, file_name)
- def make_efi(fname, comp):
+ def make_efi(fname, efi_file, comp):
"""Create an UEFI binary.
This simply copies lib/efi_loader/helloworld.efi into U-Boot
@@ -218,17 +256,18 @@ def test_efi_fit_launch(u_boot_console):
Args:
fname -- The target file name within U-Boot build dir.
+ efi_file -- The source .efi application
comp -- Flag to enable gzip compression.
Return:
The path of the created file.
"""
bin_path = make_fpath(fname)
- util.run_and_log(cons,
- ['cp', make_fpath('lib/efi_loader/helloworld.efi'),
- bin_path])
+ utils.run_and_log(ubman,
+ ['cp', make_fpath(f'lib/efi_loader/{efi_file}'),
+ bin_path])
if comp:
- util.run_and_log(cons, ['gzip', '-f', bin_path])
+ utils.run_and_log(ubman, ['gzip', '-f', bin_path])
bin_path += '.gz'
return bin_path
@@ -257,12 +296,34 @@ def test_efi_fit_launch(u_boot_console):
# Build the test FDT.
dtb = make_fpath('test-efi-fit-%s.dtb' % fdt_type)
- util.run_and_log(cons, ['dtc', '-I', 'dts', '-O', 'dtb', '-o', dtb, dts])
+ utils.run_and_log(ubman,
+ ['dtc', '-I', 'dts', '-O', 'dtb', '-o', dtb, dts])
if comp:
- util.run_and_log(cons, ['gzip', '-f', dtb])
+ utils.run_and_log(ubman, ['gzip', '-f', dtb])
dtb += '.gz'
return dtb
+ def make_initrd(comp):
+ """Create a sample initrd.
+
+ Creates an initrd.
+
+ Args:
+ comp -- Flag to enable gzip compression.
+ Return:
+ The path of the created file.
+ """
+
+ # Generate a test initrd file.
+ initrd = make_fpath('test-efi-initrd')
+ with open(initrd, 'w', encoding='ascii') as file:
+ file.write('test-efi-initrd')
+
+ if comp:
+ utils.run_and_log(ubman, ['gzip', '-f', initrd])
+ initrd += '.gz'
+ return initrd
+
def make_fit(comp):
"""Create a sample FIT image.
@@ -274,24 +335,37 @@ def test_efi_fit_launch(u_boot_console):
"""
# Generate resources referenced by ITS.
+ hello_bin = os.path.basename(make_efi('test-efi-helloworld.efi', 'helloworld.efi', comp))
+ dtbdump_bin = os.path.basename(make_efi('test-efi-dtbdump.efi', 'dtbdump.efi', comp))
+ initrddump_bin = os.path.basename(make_efi('test-efi-initrddump.efi', 'initrddump.efi', comp))
+ fdt_bin = os.path.basename(make_dtb('user', comp))
+ initrd_fs = make_initrd(comp)
+ initrd_fs = os.path.basename(initrd_fs)
+ compression = 'gzip' if comp else 'none'
+ kernel_type = 'kernel' if comp else 'kernel_noload'
+
its_params = {
'sys-arch': sys_arch,
- 'efi-bin': os.path.basename(make_efi('test-efi-fit-helloworld.efi', comp)),
- 'kernel-type': 'kernel' if comp else 'kernel_noload',
- 'efi-comp': 'gzip' if comp else 'none',
- 'fdt-bin': os.path.basename(make_dtb('user', comp)),
- 'fdt-comp': 'gzip' if comp else 'none',
+ 'hello-bin': hello_bin,
+ 'dtbdump-bin': dtbdump_bin,
+ 'initrddump-bin': initrddump_bin,
+ 'kernel-type': kernel_type,
+ 'efi-comp': compression,
+ 'fdt-bin': fdt_bin,
+ 'fdt-comp': compression,
+ 'initrd-fs': initrd_fs,
+ 'initrd-comp': compression,
}
# Generate a test ITS file.
- its_path = make_fpath('test-efi-fit-helloworld.its')
+ its_path = make_fpath('test-efi-fit.its')
with open(its_path, 'w', encoding='ascii') as file:
file.write(ITS_DATA % its_params)
# Build the test ITS.
- fit_path = make_fpath('test-efi-fit-helloworld.fit')
- util.run_and_log(
- cons, [make_fpath('tools/mkimage'), '-f', its_path, fit_path])
+ fit_path = make_fpath('test-efi-fit.fit')
+ utils.run_and_log(
+ ubman, [make_fpath('tools/mkimage'), '-f', its_path, fit_path])
return fit_path
def load_fit_from_host(fit):
@@ -307,9 +381,9 @@ def test_efi_fit_launch(u_boot_console):
addr = fit.get('addr', None)
if not addr:
- addr = util.find_ram_base(cons)
+ addr = utils.find_ram_base(ubman)
- output = cons.run_command(
+ output = ubman.run_command(
'host load hostfs - %x %s/%s' % (addr, fit['dn'], fit['fn']))
expected_text = ' bytes read'
size = fit.get('size', None)
@@ -334,10 +408,10 @@ def test_efi_fit_launch(u_boot_console):
addr = fit.get('addr', None)
if not addr:
- addr = util.find_ram_base(cons)
+ addr = utils.find_ram_base(ubman)
file_name = fit['fn']
- output = cons.run_command('tftpboot %x %s' % (addr, file_name))
+ output = ubman.run_command('tftpboot %x %s' % (addr, file_name))
expected_text = 'Bytes transferred = '
size = fit.get('size', None)
if size:
@@ -348,15 +422,15 @@ def test_efi_fit_launch(u_boot_console):
if not expected_crc:
return addr
- if cons.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
+ if ubman.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
return addr
- output = cons.run_command('crc32 $fileaddr $filesize')
+ output = ubman.run_command('crc32 $fileaddr $filesize')
assert expected_crc in output
return addr
- def launch_efi(enable_fdt, enable_comp):
+ def launch_efi(enable_fdt, enable_initrd, enable_comp):
"""Launch U-Boot's helloworld.efi binary from a FIT image.
An external image file can be downloaded from TFTP, when related
@@ -371,22 +445,23 @@ def test_efi_fit_launch(u_boot_console):
from the host filesystem.
Once the load address is available on U-Boot console, the 'bootm'
- command is executed for either 'config-efi-fdt' or 'config-efi-nofdt'
- FIT configuration, depending on the value of the 'enable_fdt' function
- argument.
+ command is executed for either 'config-efi', 'config-efi-fdt' or
+ 'config-efi-initrd' FIT configuration, depending on the value of the
+ 'enable_fdt' and 'enable_initrd' function arguments.
Eventually the 'Hello, world' message is expected in the U-Boot console.
Args:
enable_fdt -- Flag to enable using the FDT blob inside FIT image.
+ enable_initrd -- Flag to enable using an initrd inside FIT image.
enable_comp -- Flag to enable GZIP compression on EFI and FDT
generated content.
"""
- with cons.log.section('FDT=%s;COMP=%s' % (enable_fdt, enable_comp)):
+ with ubman.log.section('FDT=%s;INITRD=%s;COMP=%s' % (enable_fdt, enable_initrd, enable_comp)):
if is_sandbox:
fit = {
- 'dn': cons.config.build_dir,
+ 'dn': ubman.config.build_dir,
}
else:
# Init networking.
@@ -396,7 +471,7 @@ def test_efi_fit_launch(u_boot_console):
if not net_set_up:
pytest.skip('Network not initialized')
- fit = cons.config.env.get('env__efi_fit_tftp_file', None)
+ fit = ubman.config.env.get('env__efi_fit_tftp_file', None)
if not fit:
pytest.skip('No env__efi_fit_tftp_file binary specified in environment')
@@ -411,56 +486,74 @@ def test_efi_fit_launch(u_boot_console):
fit['size'] = os.path.getsize(fit_path)
# Copy image to TFTP root directory.
- if fit['dn'] != cons.config.build_dir:
- util.run_and_log(cons, ['mv', '-f', fit_path, '%s/' % fit['dn']])
+ if fit['dn'] != ubman.config.build_dir:
+ utils.run_and_log(ubman,
+ ['mv', '-f', fit_path, '%s/' % fit['dn']])
# Load FIT image.
addr = load_fit_from_host(fit) if is_sandbox else load_fit_from_tftp(fit)
# Select boot configuration.
- fit_config = 'config-efi-fdt' if enable_fdt else 'config-efi-nofdt'
+ fit_config = 'config-efi'
+ fit_config = fit_config + '-fdt' if enable_fdt else fit_config
+ fit_config = fit_config + '-initrd' if enable_initrd else fit_config
# Try booting.
- output = cons.run_command('bootm %x#%s' % (addr, fit_config))
+ ubman.run_command('setenv bootargs nocolor')
+ output = ubman.run_command('bootm %x#%s' % (addr, fit_config))
+ assert '## Application failed' not in output
if enable_fdt:
assert 'Booting using the fdt blob' in output
- assert 'Hello, world' in output
- assert '## Application failed' not in output
- cons.restart_uboot()
+ assert 'DTB Dump' in output
+ if enable_initrd:
+ assert 'Loading ramdisk' in output
+ assert 'INITRD Dump' in output
+ if enable_fdt:
+ response = ubman.run_command(cmd = 'dump', wait_for_echo=False)
+ assert 'EFI FIT FDT Boot Test' in response
+ if enable_initrd:
+ response = ubman.run_command('load', wait_for_echo=False)
+ assert f"crc32: 0x0c77b025" in response
+ if not enable_fdt and not enable_initrd:
+ assert 'Hello, world' in output
+ ubman.restart_uboot()
- cons = u_boot_console
# Array slice removes leading/trailing quotes.
- sys_arch = cons.config.buildconfig.get('config_sys_arch', '"sandbox"')[1:-1]
+ sys_arch = ubman.config.buildconfig.get('config_sys_arch', '"sandbox"')[1:-1]
if sys_arch == 'arm':
- arm64 = cons.config.buildconfig.get('config_arm64')
+ arm64 = ubman.config.buildconfig.get('config_arm64')
if arm64:
sys_arch = 'arm64'
is_sandbox = sys_arch == 'sandbox'
if is_sandbox:
- old_dtb = cons.config.dtb
+ old_dtb = ubman.config.dtb
try:
if is_sandbox:
# Use our own device tree file, will be restored afterwards.
control_dtb = make_dtb('internal', False)
- cons.config.dtb = control_dtb
+ ubman.config.dtb = control_dtb
# Run tests
- # - fdt OFF, gzip OFF
- launch_efi(False, False)
- # - fdt ON, gzip OFF
- launch_efi(True, False)
+ # - fdt OFF, initrd OFF, gzip OFF
+ launch_efi(False, False, False)
+ # - fdt ON, initrd OFF, gzip OFF
+ launch_efi(True, False, False)
+ # - fdt OFF, initrd ON, gzip OFF
+ launch_efi(False, True, False)
if is_sandbox:
- # - fdt OFF, gzip ON
- launch_efi(False, True)
- # - fdt ON, gzip ON
- launch_efi(True, True)
+ # - fdt OFF, initrd OFF, gzip ON
+ launch_efi(False, False, True)
+ # - fdt ON, initrd OFF, gzip ON
+ launch_efi(True, False, True)
+ # - fdt OFF, initrd ON, gzip ON
+ launch_efi(False, True, True)
finally:
if is_sandbox:
# Go back to the original U-Boot with the correct dtb.
- cons.config.dtb = old_dtb
- cons.restart_uboot()
+ ubman.config.dtb = old_dtb
+ ubman.restart_uboot()
diff --git a/test/py/tests/test_efi_loader.py b/test/py/tests/test_efi_loader.py
index 85473a9049b..91f151d09cd 100644
--- a/test/py/tests/test_efi_loader.py
+++ b/test/py/tests/test_efi_loader.py
@@ -13,122 +13,137 @@ that rely on network will be automatically skipped.
For example:
-# Boolean indicating whether the Ethernet device is attached to USB, and hence
-# USB enumeration needs to be performed prior to network tests.
-# This variable may be omitted if its value is False.
-env__net_uses_usb = False
-
-# Boolean indicating whether the Ethernet device is attached to PCI, and hence
-# PCI enumeration needs to be performed prior to network tests.
-# This variable may be omitted if its value is False.
-env__net_uses_pci = True
-
-# True if a DHCP server is attached to the network, and should be tested.
-# If DHCP testing is not possible or desired, this variable may be omitted or
-# set to False.
-env__net_dhcp_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.
-env__net_static_env_vars = [
- ('ipaddr', '10.0.0.100'),
- ('netmask', '255.255.255.0'),
- ('serverip', '10.0.0.1'),
-]
-
-# Details regarding a file that may be read from a TFTP server. This variable
-# may be omitted or set to None if TFTP testing is not possible or desired.
-env__efi_loader_helloworld_file = {
- 'fn': 'lib/efi_loader/helloworld.efi', # file name
- 'size': 5058624, # file length in bytes
- 'crc32': 'c2244b26', # CRC32 check sum
- 'addr': 0x40400000, # load address
-}
+.. code-block:: python
+
+ # Boolean indicating whether the Ethernet device is attached to USB, and hence
+ # USB enumeration needs to be performed prior to network tests.
+ # This variable may be omitted if its value is False.
+ env__net_uses_usb = False
+
+ # Boolean indicating whether the Ethernet device is attached to PCI, and hence
+ # PCI enumeration needs to be performed prior to network tests.
+ # This variable may be omitted if its value is False.
+ env__net_uses_pci = True
+
+ # True if a DHCP server is attached to the network, and should be tested.
+ # If DHCP testing is not possible or desired, this variable may be omitted or
+ # set to False.
+ env__net_dhcp_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.
+ env__net_static_env_vars = [
+ ('ipaddr', '10.0.0.100'),
+ ('netmask', '255.255.255.0'),
+ ('serverip', '10.0.0.1'),
+ ]
+
+ # Details regarding a file that may be read from a TFTP server. This variable
+ # may be omitted or set to None if TFTP testing is not possible or desired.
+ env__efi_loader_helloworld_file = {
+ 'fn': 'lib/efi_loader/helloworld.efi', # file name
+ 'size': 5058624, # file length in bytes
+ 'crc32': 'c2244b26', # CRC32 check sum
+ 'addr': 0x40400000, # load address
+ }
+
+ # False if the helloworld EFI over HTTP boot test should be performed.
+ # If HTTP boot testing is not possible or desired, set this variable to True or
+ # ommit it.
+ env__efi_helloworld_net_http_test_skip = True
"""
import pytest
-import u_boot_utils
+import utils
+
+PROTO_TFTP, PROTO_HTTP = range(0, 2)
net_set_up = False
-def test_efi_pre_commands(u_boot_console):
+def test_efi_pre_commands(ubman):
"""Execute any commands required to enable network hardware.
These commands are provided by the boardenv_* file; see the comment at the
beginning of this file.
"""
- init_usb = u_boot_console.config.env.get('env__net_uses_usb', False)
+ init_usb = ubman.config.env.get('env__net_uses_usb', False)
if init_usb:
- u_boot_console.run_command('usb start')
+ ubman.run_command('usb start')
- init_pci = u_boot_console.config.env.get('env__net_uses_pci', False)
+ init_pci = ubman.config.env.get('env__net_uses_pci', False)
if init_pci:
- u_boot_console.run_command('pci enum')
+ ubman.run_command('pci enum')
@pytest.mark.buildconfigspec('cmd_dhcp')
-def test_efi_setup_dhcp(u_boot_console):
+def test_efi_setup_dhcp(ubman):
"""Set up the network using DHCP.
The boardenv_* file may be used to enable/disable this test; see the
comment at the beginning of this file.
"""
- test_dhcp = u_boot_console.config.env.get('env__net_dhcp_server', False)
+ test_dhcp = ubman.config.env.get('env__net_dhcp_server', False)
if not test_dhcp:
- env_vars = u_boot_console.config.env.get('env__net_static_env_vars', None)
+ env_vars = ubman.config.env.get('env__net_static_env_vars', None)
if not env_vars:
pytest.skip('No DHCP server available')
return
- u_boot_console.run_command('setenv autoload no')
- output = u_boot_console.run_command('dhcp')
+ ubman.run_command('setenv autoload no')
+ output = ubman.run_command('dhcp')
assert 'DHCP client bound to address ' in output
global net_set_up
net_set_up = True
@pytest.mark.buildconfigspec('net')
-def test_efi_setup_static(u_boot_console):
+def test_efi_setup_static(ubman):
"""Set up the network using a static IP configuration.
The configuration is provided by the boardenv_* file; see the comment at
the beginning of this file.
"""
- env_vars = u_boot_console.config.env.get('env__net_static_env_vars', None)
+ env_vars = ubman.config.env.get('env__net_static_env_vars', None)
if not env_vars:
- test_dhcp = u_boot_console.config.env.get('env__net_dhcp_server', False)
+ test_dhcp = ubman.config.env.get('env__net_dhcp_server', False)
if not test_dhcp:
pytest.skip('No static network configuration is defined')
return None
for (var, val) in env_vars:
- u_boot_console.run_command('setenv %s %s' % (var, val))
+ ubman.run_command('setenv %s %s' % (var, val))
global net_set_up
net_set_up = True
-def fetch_tftp_file(u_boot_console, env_conf):
- """Grab an env described file via TFTP and return its address
+def fetch_file(ubman, env_conf, proto):
+ """Grab an env described file via TFTP or HTTP and return its address
- A file as described by an env config <env_conf> is downloaded from the TFTP
+ A file as described by an env config <env_conf> is downloaded from the
server. The address to that file is returned.
"""
if not net_set_up:
pytest.skip('Network not initialized')
- f = u_boot_console.config.env.get(env_conf, None)
+ f = ubman.config.env.get(env_conf, None)
if not f:
pytest.skip('No %s binary specified in environment' % env_conf)
addr = f.get('addr', None)
if not addr:
- addr = u_boot_utils.find_ram_base(u_boot_console)
+ addr = utils.find_ram_base(ubman)
fn = f['fn']
- output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn))
+ if proto == PROTO_TFTP:
+ cmd = 'tftpboot'
+ elif proto == PROTO_HTTP:
+ cmd = 'wget'
+ else:
+ assert False
+ output = ubman.run_command('%s %x %s' % (cmd, addr, fn))
expected_text = 'Bytes transferred = '
sz = f.get('size', None)
if sz:
@@ -139,66 +154,88 @@ def fetch_tftp_file(u_boot_console, env_conf):
if not expected_crc:
return addr
- if u_boot_console.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
+ if ubman.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
return addr
- output = u_boot_console.run_command('crc32 %x $filesize' % addr)
+ output = ubman.run_command('crc32 %x $filesize' % addr)
assert expected_crc in output
return addr
-@pytest.mark.buildconfigspec('of_control')
-@pytest.mark.buildconfigspec('cmd_bootefi_hello_compile')
-def test_efi_helloworld_net(u_boot_console):
- """Run the helloworld.efi binary via TFTP.
+def do_test_efi_helloworld_net(ubman, proto):
+ """Download and execute the helloworld appliation
- The helloworld.efi file is downloaded from the TFTP server and is executed
- using the fallback device tree at $fdtcontroladdr.
+ The helloworld.efi file is downloaded based on the value passed to us as a
+ protocol and is executed using the fallback device tree at $fdtcontroladdr.
"""
+ addr = fetch_file(ubman, 'env__efi_loader_helloworld_file', proto)
- addr = fetch_tftp_file(u_boot_console, 'env__efi_loader_helloworld_file')
-
- output = u_boot_console.run_command('bootefi %x' % addr)
+ output = ubman.run_command('bootefi %x' % addr)
expected_text = 'Hello, world'
assert expected_text in output
expected_text = '## Application failed'
assert expected_text not in output
+@pytest.mark.buildconfigspec('of_control')
+@pytest.mark.buildconfigspec('bootefi_hello_compile')
+@pytest.mark.buildconfigspec('cmd_tftpboot')
+def test_efi_helloworld_net_tftp(ubman):
+ """Run the helloworld.efi binary via TFTP.
+
+ Call the do_test_efi_helloworld_net function to execute the test via TFTP.
+ """
+
+ do_test_efi_helloworld_net(ubman, PROTO_TFTP);
+
+@pytest.mark.buildconfigspec('of_control')
+@pytest.mark.buildconfigspec('bootefi_hello_compile')
+@pytest.mark.buildconfigspec('cmd_wget')
+def test_efi_helloworld_net_http(ubman):
+ """Run the helloworld.efi binary via HTTP.
+
+ Call the do_test_efi_helloworld_net function to execute the test via HTTP.
+ """
+ if ubman.config.env.get('env__efi_helloworld_net_http_test_skip', True):
+ pytest.skip('helloworld.efi HTTP test is not enabled!')
+
+ do_test_efi_helloworld_net(ubman, PROTO_HTTP);
+
@pytest.mark.buildconfigspec('cmd_bootefi_hello')
-def test_efi_helloworld_builtin(u_boot_console):
+def test_efi_helloworld_builtin(ubman):
"""Run the builtin helloworld.efi binary.
The helloworld.efi file is included in U-Boot, execute it using the
special "bootefi hello" command.
"""
- output = u_boot_console.run_command('bootefi hello')
+ output = ubman.run_command('bootefi hello')
expected_text = 'Hello, world'
assert expected_text in output
@pytest.mark.buildconfigspec('of_control')
@pytest.mark.buildconfigspec('cmd_bootefi')
-def test_efi_grub_net(u_boot_console):
+@pytest.mark.buildconfigspec('cmd_tftpboot')
+def test_efi_grub_net(ubman):
"""Run the grub.efi binary via TFTP.
The grub.efi file is downloaded from the TFTP server and gets
executed.
"""
- addr = fetch_tftp_file(u_boot_console, 'env__efi_loader_grub_file')
+ addr = fetch_file(ubman, 'env__efi_loader_grub_file', PROTO_TFTP)
- u_boot_console.run_command('bootefi %x' % addr, wait_for_prompt=False)
+ ubman.run_command('bootefi %x' % addr, wait_for_prompt=False)
# Verify that we have an SMBIOS table
- check_smbios = u_boot_console.config.env.get('env__efi_loader_check_smbios', False)
+ check_smbios = ubman.config.env.get('env__efi_loader_check_smbios', False)
if check_smbios:
- u_boot_console.wait_for('grub>')
- u_boot_console.run_command('lsefisystab', wait_for_prompt=False, wait_for_echo=False)
- u_boot_console.wait_for('SMBIOS')
+ ubman.wait_for('grub>')
+ ubman.run_command('lsefisystab', wait_for_prompt=False, wait_for_echo=False)
+ ubman.wait_for('SMBIOS')
# Then exit cleanly
- u_boot_console.wait_for('grub>')
- u_boot_console.run_command('exit', wait_for_prompt=False, wait_for_echo=False)
- u_boot_console.wait_for(u_boot_console.prompt)
+ ubman.wait_for('grub>')
+ ubman.run_command('exit', wait_for_prompt=False, wait_for_echo=False)
+ ubman.wait_for(ubman.prompt)
# And give us our U-Boot prompt back
- u_boot_console.run_command('')
+ ubman.run_command('')
diff --git a/test/py/tests/test_efi_secboot/conftest.py b/test/py/tests/test_efi_secboot/conftest.py
index ff7ac7c8101..aa9a3536296 100644
--- a/test/py/tests/test_efi_secboot/conftest.py
+++ b/test/py/tests/test_efi_secboot/conftest.py
@@ -5,27 +5,25 @@
"""Fixture for UEFI secure boot test."""
from subprocess import call, check_call, CalledProcessError
+from tests import fs_helper
import pytest
from defs import *
-@pytest.fixture(scope='session')
-def efi_boot_env(request, u_boot_config):
+@pytest.fixture(scope='function')
+def efi_boot_env(request, ubman):
"""Set up a file system to be used in UEFI secure boot test.
Args:
request: Pytest request object.
- u_boot_config: U-Boot configuration.
+ ubman: U-Boot configuration.
Return:
A path to disk image to be used for testing
"""
- image_path = u_boot_config.persistent_data_dir
- image_path = image_path + '/test_efi_secboot.img'
try:
- mnt_point = u_boot_config.build_dir + '/mnt_efisecure'
- check_call('rm -rf {}'.format(mnt_point), shell=True)
- check_call('mkdir -p {}'.format(mnt_point), shell=True)
+ image_path, mnt_point = fs_helper.setup_image(ubman, 0, 0xc,
+ basename='test_efi_secboot')
# suffix
# *.key: RSA private key in PEM
@@ -64,6 +62,12 @@ def efi_boot_env(request, u_boot_config):
check_call('cd %s; %scert-to-efi-sig-list -g %s db1.crt db1.esl; %ssign-efi-sig-list -t "2020-04-05" -c KEK.crt -k KEK.key db db1.esl db1.auth'
% (mnt_point, EFITOOLS_PATH, GUID, EFITOOLS_PATH),
shell=True)
+ # db2 (APPEND_WRITE)
+ check_call('cd %s; openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=TEST_db2/ -keyout db2.key -out db2.crt -nodes -days 365'
+ % mnt_point, shell=True)
+ check_call('cd %s; %scert-to-efi-sig-list -g %s db2.crt db2.esl; %ssign-efi-sig-list -a -c KEK.crt -k KEK.key db db2.esl db2.auth'
+ % (mnt_point, EFITOOLS_PATH, GUID, EFITOOLS_PATH),
+ shell=True)
# dbx (TEST_dbx certificate)
check_call('cd %s; openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=TEST_dbx/ -keyout dbx.key -out dbx.crt -nodes -days 365'
% mnt_point, shell=True)
@@ -84,6 +88,10 @@ def efi_boot_env(request, u_boot_config):
check_call('cd %s; %scert-to-efi-hash-list -g %s -s 256 db1.crt dbx_hash1.crl; %ssign-efi-sig-list -t "2020-04-06" -c KEK.crt -k KEK.key dbx dbx_hash1.crl dbx_hash1.auth'
% (mnt_point, EFITOOLS_PATH, GUID, EFITOOLS_PATH),
shell=True)
+ # dbx_hash2 (digest of TEST_db2 certificate, with APPEND_WRITE)
+ check_call('cd %s; %scert-to-efi-hash-list -g %s -s 256 db2.crt dbx_hash2.crl; %ssign-efi-sig-list -a -c KEK.crt -k KEK.key dbx dbx_hash2.crl dbx_hash2.auth'
+ % (mnt_point, EFITOOLS_PATH, GUID, EFITOOLS_PATH),
+ shell=True)
# dbx_db (with TEST_db certificate)
check_call('cd %s; %ssign-efi-sig-list -t "2020-04-05" -c KEK.crt -k KEK.key dbx db.esl dbx_db.auth'
% (mnt_point, EFITOOLS_PATH),
@@ -91,7 +99,7 @@ def efi_boot_env(request, u_boot_config):
# Copy image
check_call('cp %s/lib/efi_loader/helloworld.efi %s' %
- (u_boot_config.build_dir, mnt_point), shell=True)
+ (ubman.config.build_dir, mnt_point), shell=True)
# Sign image
check_call('cd %s; sbsign --key db.key --cert db.crt helloworld.efi'
@@ -101,7 +109,7 @@ def efi_boot_env(request, u_boot_config):
% mnt_point, shell=True)
# Create a corrupted signed image
check_call('cd %s; sh %s/test/py/tests/test_efi_secboot/forge_image.sh helloworld.efi.signed helloworld_forged.efi.signed'
- % (mnt_point, u_boot_config.source_dir), shell=True)
+ % (mnt_point, ubman.config.source_dir), shell=True)
# Digest image
check_call('cd %s; %shash-to-efi-sig-list helloworld.efi db_hello.hash; %ssign-efi-sig-list -t "2020-04-07" -c KEK.crt -k KEK.key db db_hello.hash db_hello.auth'
% (mnt_point, EFITOOLS_PATH, EFITOOLS_PATH),
@@ -113,9 +121,9 @@ def efi_boot_env(request, u_boot_config):
% (mnt_point, EFITOOLS_PATH),
shell=True)
- check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat {} {}'.format(
- mnt_point, image_path), shell=True)
- check_call('rm -rf {}'.format(mnt_point), shell=True)
+ fsfile = fs_helper.mk_fs(ubman.config, 'vfat', 0x1000000,
+ 'test_efi_secboot', mnt_point)
+ check_call(f'dd if={fsfile} of={image_path} bs=1M seek=1', shell=True)
except CalledProcessError as exception:
pytest.skip('Setup failed: %s' % exception.cmd)
@@ -123,15 +131,16 @@ def efi_boot_env(request, u_boot_config):
else:
yield image_path
finally:
- call('rm -f %s' % image_path, shell=True)
+ call('rm -rf %s' % mnt_point, shell=True)
+ call('rm -f %s %s' % (image_path, fsfile), shell=True)
#
# Fixture for UEFI secure boot test of intermediate certificates
#
-@pytest.fixture(scope='session')
-def efi_boot_env_intca(request, u_boot_config):
+@pytest.fixture(scope='function')
+def efi_boot_env_intca(request, ubman):
"""Set up file system for secure boot test.
Set up a file system to be used in UEFI secure boot test
@@ -139,18 +148,15 @@ def efi_boot_env_intca(request, u_boot_config):
Args:
request: Pytest request object.
- u_boot_config: U-Boot configuration.
+ ubman: U-Boot configuration.
Return:
A path to disk image to be used for testing
"""
- image_path = u_boot_config.persistent_data_dir
- image_path = image_path + '/test_efi_secboot_intca.img'
try:
- mnt_point = u_boot_config.persistent_data_dir + '/mnt_efi_secboot_intca'
- check_call('rm -rf {}'.format(mnt_point), shell=True)
- check_call('mkdir -p {}'.format(mnt_point), shell=True)
+ image_path, mnt_point = fs_helper.setup_image(ubman, 0, 0xc,
+ basename='test_efi_secboot_intca')
# Create signature database
# PK
@@ -180,7 +186,7 @@ def efi_boot_env_intca(request, u_boot_config):
# TestRoot
check_call('cp %s/test/py/tests/test_efi_secboot/openssl.cnf %s'
- % (u_boot_config.source_dir, mnt_point), shell=True)
+ % (ubman.config.source_dir, mnt_point), shell=True)
check_call('cd %s; export OPENSSL_CONF=./openssl.cnf; openssl genrsa -out TestRoot.key 2048; openssl req -extensions v3_ca -new -x509 -days 365 -key TestRoot.key -out TestRoot.crt -subj "/CN=TEST_root/"; touch index.txt; touch index.txt.attr'
% mnt_point, shell=True)
# TestSub
@@ -221,7 +227,7 @@ def efi_boot_env_intca(request, u_boot_config):
# in SignedData
check_call('cp %s/lib/efi_loader/helloworld.efi %s' %
- (u_boot_config.build_dir, mnt_point), shell=True)
+ (ubman.config.build_dir, mnt_point), shell=True)
# signed by TestCert
check_call('cd %s; %ssbsign --key TestCert.key --cert TestCert.crt --out helloworld.efi.signed_a helloworld.efi'
% (mnt_point, SBSIGN_PATH), shell=True)
@@ -232,8 +238,9 @@ def efi_boot_env_intca(request, u_boot_config):
check_call('cd %s; cat TestSub.crt TestRoot.crt > TestSubRoot.crt; %ssbsign --key TestCert.key --cert TestCert.crt --addcert TestSubRoot.crt --out helloworld.efi.signed_abc helloworld.efi'
% (mnt_point, SBSIGN_PATH), shell=True)
- check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat {} {}'.format(mnt_point, image_path), shell=True)
- check_call('rm -rf {}'.format(mnt_point), shell=True)
+ fsfile = fs_helper.mk_fs(ubman.config, 'vfat', 0x1000000,
+ 'test_efi_secboot_intca', mnt_point)
+ check_call(f'dd if={fsfile} of={image_path} bs=1M seek=1', shell=True)
except CalledProcessError as e:
pytest.skip('Setup failed: %s' % e.cmd)
@@ -241,4 +248,5 @@ def efi_boot_env_intca(request, u_boot_config):
else:
yield image_path
finally:
- call('rm -f %s' % image_path, shell=True)
+ call('rm -rf %s' % mnt_point, shell=True)
+ call('rm -f %s %s' % (image_path, fsfile), shell=True)
diff --git a/test/py/tests/test_efi_secboot/test_authvar.py b/test/py/tests/test_efi_secboot/test_authvar.py
index f99b8270a64..7b45f8fb814 100644
--- a/test/py/tests/test_efi_secboot/test_authvar.py
+++ b/test/py/tests/test_efi_secboot/test_authvar.py
@@ -17,119 +17,119 @@ import pytest
@pytest.mark.buildconfigspec('cmd_nvedit_efi')
@pytest.mark.slow
class TestEfiAuthVar(object):
- def test_efi_var_auth1(self, u_boot_console, efi_boot_env):
+ def test_efi_var_auth1(self, ubman, efi_boot_env):
"""
Test Case 1 - Install signature database
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env
- with u_boot_console.log.section('Test Case 1a'):
+ with ubman.log.section('Test Case 1a'):
# Test Case 1a, Initial secure state
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'printenv -e SecureBoot'])
assert '00000000: 00' in ''.join(output)
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'printenv -e SetupMode')
assert '00000000: 01' in output
- with u_boot_console.log.section('Test Case 1b'):
+ with ubman.log.section('Test Case 1b'):
# Test Case 1b, PK without AUTHENTICATED_WRITE_ACCESS
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 PK.auth',
'setenv -e -nv -bs -rt -i 4000000:$filesize PK'])
assert 'Failed to set EFI variable' in ''.join(output)
- with u_boot_console.log.section('Test Case 1c'):
+ with ubman.log.section('Test Case 1c'):
# Test Case 1c, install PK
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 PK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK',
'printenv -e -n PK'])
assert 'PK:' in ''.join(output)
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'printenv -e SecureBoot')
assert '00000000: 01' in output
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'printenv -e SetupMode')
assert '00000000: 00' in output
- with u_boot_console.log.section('Test Case 1d'):
+ with ubman.log.section('Test Case 1d'):
# Test Case 1d, db/dbx without KEK
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 db.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db'])
assert 'Failed to set EFI variable' in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 db.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx'])
assert 'Failed to set EFI variable' in ''.join(output)
- with u_boot_console.log.section('Test Case 1e'):
+ with ubman.log.section('Test Case 1e'):
# Test Case 1e, install KEK
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 KEK.auth',
'setenv -e -nv -bs -rt -i 4000000:$filesize KEK'])
assert 'Failed to set EFI variable' in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 KEK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK',
'printenv -e -n KEK'])
assert 'KEK:' in ''.join(output)
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'printenv -e SecureBoot')
assert '00000000: 01' in output
- with u_boot_console.log.section('Test Case 1f'):
+ with ubman.log.section('Test Case 1f'):
# Test Case 1f, install db
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 db.auth',
'setenv -e -nv -bs -rt -i 4000000:$filesize db'])
assert 'Failed to set EFI variable' in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 db.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db',
'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db'])
assert 'Failed to set EFI variable' not in ''.join(output)
assert 'db:' in ''.join(output)
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'printenv -e SecureBoot')
assert '00000000: 01' in output
- with u_boot_console.log.section('Test Case 1g'):
+ with ubman.log.section('Test Case 1g'):
# Test Case 1g, install dbx
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 dbx.auth',
'setenv -e -nv -bs -rt -i 4000000:$filesize dbx'])
assert 'Failed to set EFI variable' in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 dbx.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx',
'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f dbx'])
assert 'Failed to set EFI variable' not in ''.join(output)
assert 'dbx:' in ''.join(output)
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'printenv -e SecureBoot')
assert '00000000: 01' in output
- def test_efi_var_auth2(self, u_boot_console, efi_boot_env):
+ def test_efi_var_auth2(self, ubman, efi_boot_env):
"""
Test Case 2 - Update database by overwriting
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env
- with u_boot_console.log.section('Test Case 2a'):
+ with ubman.log.section('Test Case 2a'):
# Test Case 2a, update without AUTHENTICATED_WRITE_ACCESS
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 PK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK',
@@ -141,36 +141,36 @@ class TestEfiAuthVar(object):
assert 'Failed to set EFI variable' not in ''.join(output)
assert 'db:' in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 db1.auth',
'setenv -e -nv -bs -rt -i 4000000:$filesize db'])
assert 'Failed to set EFI variable' in ''.join(output)
- with u_boot_console.log.section('Test Case 2b'):
+ with ubman.log.section('Test Case 2b'):
# Test Case 2b, update without correct signature
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 db.esl',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db'])
assert 'Failed to set EFI variable' in ''.join(output)
- with u_boot_console.log.section('Test Case 2c'):
+ with ubman.log.section('Test Case 2c'):
# Test Case 2c, update with correct signature
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 db1.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db',
'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db'])
assert 'Failed to set EFI variable' not in ''.join(output)
assert 'db:' in ''.join(output)
- def test_efi_var_auth3(self, u_boot_console, efi_boot_env):
+ def test_efi_var_auth3(self, ubman, efi_boot_env):
"""
Test Case 3 - Append database
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env
- with u_boot_console.log.section('Test Case 3a'):
+ with ubman.log.section('Test Case 3a'):
# Test Case 3a, update without AUTHENTICATED_WRITE_ACCESS
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 PK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK',
@@ -182,36 +182,36 @@ class TestEfiAuthVar(object):
assert 'Failed to set EFI variable' not in ''.join(output)
assert 'db:' in ''.join(output)
- output = u_boot_console.run_command_list([
- 'fatload host 0:1 4000000 db1.auth',
+ output = ubman.run_command_list([
+ 'fatload host 0:1 4000000 db2.auth',
'setenv -e -nv -bs -rt -a -i 4000000:$filesize db'])
assert 'Failed to set EFI variable' in ''.join(output)
- with u_boot_console.log.section('Test Case 3b'):
+ with ubman.log.section('Test Case 3b'):
# Test Case 3b, update without correct signature
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 db.esl',
'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize db'])
assert 'Failed to set EFI variable' in ''.join(output)
- with u_boot_console.log.section('Test Case 3c'):
+ with ubman.log.section('Test Case 3c'):
# Test Case 3c, update with correct signature
- output = u_boot_console.run_command_list([
- 'fatload host 0:1 4000000 db1.auth',
+ output = ubman.run_command_list([
+ 'fatload host 0:1 4000000 db2.auth',
'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize db',
'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db'])
assert 'Failed to set EFI variable' not in ''.join(output)
assert 'db:' in ''.join(output)
- def test_efi_var_auth4(self, u_boot_console, efi_boot_env):
+ def test_efi_var_auth4(self, ubman, efi_boot_env):
"""
Test Case 4 - Delete database without authentication
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env
- with u_boot_console.log.section('Test Case 4a'):
+ with ubman.log.section('Test Case 4a'):
# Test Case 4a, update without AUTHENTICATED_WRITE_ACCESS
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 PK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK',
@@ -223,29 +223,29 @@ class TestEfiAuthVar(object):
assert 'Failed to set EFI variable' not in ''.join(output)
assert 'db:' in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'setenv -e -nv -bs -rt db',
'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db'])
assert 'Failed to set EFI variable' in ''.join(output)
assert 'db:' in ''.join(output)
- with u_boot_console.log.section('Test Case 4b'):
+ with ubman.log.section('Test Case 4b'):
# Test Case 4b, update without correct signature/data
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'setenv -e -nv -bs -rt -at db',
'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db'])
assert 'Failed to set EFI variable' in ''.join(output)
assert 'db:' in ''.join(output)
- def test_efi_var_auth5(self, u_boot_console, efi_boot_env):
+ def test_efi_var_auth5(self, ubman, efi_boot_env):
"""
Test Case 5 - Uninstall(delete) PK
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env
- with u_boot_console.log.section('Test Case 5a'):
+ with ubman.log.section('Test Case 5a'):
# Test Case 5a, Uninstall PK without correct signature
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 PK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK',
@@ -257,25 +257,25 @@ class TestEfiAuthVar(object):
assert 'Failed to set EFI variable' not in ''.join(output)
assert 'PK:' in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 PK_null.esl',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK',
'printenv -e -n PK'])
assert 'Failed to set EFI variable' in ''.join(output)
assert 'PK:' in ''.join(output)
- with u_boot_console.log.section('Test Case 5b'):
+ with ubman.log.section('Test Case 5b'):
# Test Case 5b, Uninstall PK with correct signature
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 PK_null.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK',
'printenv -e -n PK'])
assert 'Failed to set EFI variable' not in ''.join(output)
assert '\"PK\" not defined' in ''.join(output)
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'printenv -e SecureBoot')
assert '00000000: 00' in output
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'printenv -e SetupMode')
assert '00000000: 01' in output
diff --git a/test/py/tests/test_efi_secboot/test_signed.py b/test/py/tests/test_efi_secboot/test_signed.py
index 2f862a259ad..e8aaef7090c 100644
--- a/test/py/tests/test_efi_secboot/test_signed.py
+++ b/test/py/tests/test_efi_secboot/test_signed.py
@@ -18,83 +18,83 @@ import pytest
@pytest.mark.buildconfigspec('cmd_nvedit_efi')
@pytest.mark.slow
class TestEfiSignedImage(object):
- def test_efi_signed_image_auth1(self, u_boot_console, efi_boot_env):
+ def test_efi_signed_image_auth1(self, ubman, efi_boot_env):
"""
Test Case 1 - Secure boot is not in force
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env
- with u_boot_console.log.section('Test Case 1a'):
+ with ubman.log.section('Test Case 1a'):
# Test Case 1a, run signed image if no PK
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'efidebug boot add -b 1 HELLO1 host 0:1 /helloworld.efi.signed -s ""',
'efidebug boot order 1',
'bootefi bootmgr'])
assert 'Hello, world!' in ''.join(output)
- with u_boot_console.log.section('Test Case 1b'):
+ with ubman.log.section('Test Case 1b'):
# Test Case 1b, run unsigned image if no PK
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot add -b 2 HELLO2 host 0:1 /helloworld.efi -s ""',
'efidebug boot order 2',
'bootefi bootmgr'])
assert 'Hello, world!' in ''.join(output)
- def test_efi_signed_image_auth2(self, u_boot_console, efi_boot_env):
+ def test_efi_signed_image_auth2(self, ubman, efi_boot_env):
"""
Test Case 2 - Secure boot is in force,
authenticated by db (TEST_db certificate in db)
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env
- with u_boot_console.log.section('Test Case 2a'):
+ with ubman.log.section('Test Case 2a'):
# Test Case 2a, db is not yet installed
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 KEK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK',
'fatload host 0:1 4000000 PK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot add -b 1 HELLO1 host 0:1 /helloworld.efi.signed -s ""',
'efidebug boot order 1',
'efidebug test bootmgr'])
assert('\'HELLO1\' failed' in ''.join(output))
- assert('efi_start_image() returned: 26' in ''.join(output))
- output = u_boot_console.run_command_list([
+ assert('efi_bootmgr_load() returned: 26' in ''.join(output))
+ output = ubman.run_command_list([
'efidebug boot add -b 2 HELLO2 host 0:1 /helloworld.efi -s ""',
'efidebug boot order 2',
'efidebug test bootmgr'])
assert '\'HELLO2\' failed' in ''.join(output)
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
- with u_boot_console.log.section('Test Case 2b'):
+ with ubman.log.section('Test Case 2b'):
# Test Case 2b, authenticated by db
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 db.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot order 2',
'efidebug test bootmgr'])
assert '\'HELLO2\' failed' in ''.join(output)
- assert 'efi_start_image() returned: 26' in ''.join(output)
- output = u_boot_console.run_command_list([
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
+ output = ubman.run_command_list([
'efidebug boot order 1',
'bootefi bootmgr'])
assert 'Hello, world!' in ''.join(output)
- def test_efi_signed_image_auth3(self, u_boot_console, efi_boot_env):
+ def test_efi_signed_image_auth3(self, ubman, efi_boot_env):
"""
Test Case 3 - rejected by dbx (TEST_db certificate in dbx)
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env
- with u_boot_console.log.section('Test Case 3a'):
+ with ubman.log.section('Test Case 3a'):
# Test Case 3a, rejected by dbx
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 db.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx',
@@ -103,34 +103,34 @@ class TestEfiSignedImage(object):
'fatload host 0:1 4000000 PK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed -s ""',
'efidebug boot order 1',
'efidebug test bootmgr'])
assert '\'HELLO\' failed' in ''.join(output)
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
- with u_boot_console.log.section('Test Case 3b'):
+ with ubman.log.section('Test Case 3b'):
# Test Case 3b, rejected by dbx even if db allows
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 db.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot order 1',
'efidebug test bootmgr'])
assert '\'HELLO\' failed' in ''.join(output)
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
- def test_efi_signed_image_auth4(self, u_boot_console, efi_boot_env):
+ def test_efi_signed_image_auth4(self, ubman, efi_boot_env):
"""
Test Case 4 - revoked by dbx (digest of TEST_db certificate in dbx)
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env
- with u_boot_console.log.section('Test Case 4'):
+ with ubman.log.section('Test Case 4'):
# Test Case 4, rejected by dbx
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 dbx_hash.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx',
@@ -141,25 +141,25 @@ class TestEfiSignedImage(object):
'fatload host 0:1 4000000 PK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed -s ""',
'efidebug boot order 1',
'efidebug test bootmgr'])
assert '\'HELLO\' failed' in ''.join(output)
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
- def test_efi_signed_image_auth5(self, u_boot_console, efi_boot_env):
+ def test_efi_signed_image_auth5(self, ubman, efi_boot_env):
"""
Test Case 5 - multiple signatures
one signed with TEST_db, and
one signed with TEST_db1
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env
- with u_boot_console.log.section('Test Case 5a'):
+ with ubman.log.section('Test Case 5a'):
# Test Case 5a, authenticated even if only one of signatures
# is verified
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 db.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db',
@@ -168,54 +168,54 @@ class TestEfiSignedImage(object):
'fatload host 0:1 4000000 PK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""',
'efidebug boot order 1',
'efidebug test bootmgr'])
assert 'Hello, world!' in ''.join(output)
- with u_boot_console.log.section('Test Case 5b'):
+ with ubman.log.section('Test Case 5b'):
# Test Case 5b, authenticated if both signatures are verified
- output = u_boot_console.run_command_list([
- 'fatload host 0:1 4000000 db1.auth',
+ output = ubman.run_command_list([
+ 'fatload host 0:1 4000000 db2.auth',
'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize db'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot order 1',
'efidebug test bootmgr'])
assert 'Hello, world!' in ''.join(output)
- with u_boot_console.log.section('Test Case 5c'):
+ with ubman.log.section('Test Case 5c'):
# Test Case 5c, rejected if one of signatures (digest of
# certificate) is revoked
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 dbx_hash.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot order 1',
'efidebug test bootmgr'])
assert '\'HELLO\' failed' in ''.join(output)
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
- with u_boot_console.log.section('Test Case 5d'):
+ with ubman.log.section('Test Case 5d'):
# Test Case 5d, rejected if both of signatures are revoked
- output = u_boot_console.run_command_list([
- 'fatload host 0:1 4000000 dbx_hash1.auth',
+ output = ubman.run_command_list([
+ 'fatload host 0:1 4000000 dbx_hash2.auth',
'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize dbx'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot order 1',
'efidebug test bootmgr'])
assert '\'HELLO\' failed' in ''.join(output)
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
# Try rejection in reverse order.
- u_boot_console.restart_uboot()
- with u_boot_console.log.section('Test Case 5e'):
+ ubman.restart_uboot()
+ with ubman.log.section('Test Case 5e'):
# Test Case 5e, authenticated even if only one of signatures
# is verified. Same as before but reject dbx_hash1.auth only
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 db.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db',
@@ -223,27 +223,27 @@ class TestEfiSignedImage(object):
'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK',
'fatload host 0:1 4000000 PK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK',
- 'fatload host 0:1 4000000 db1.auth',
+ 'fatload host 0:1 4000000 db2.auth',
'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize db',
'fatload host 0:1 4000000 dbx_hash1.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""',
'efidebug boot order 1',
'efidebug test bootmgr'])
assert '\'HELLO\' failed' in ''.join(output)
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
- def test_efi_signed_image_auth6(self, u_boot_console, efi_boot_env):
+ def test_efi_signed_image_auth6(self, ubman, efi_boot_env):
"""
Test Case 6 - using digest of signed image in database
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env
- with u_boot_console.log.section('Test Case 6a'):
+ with ubman.log.section('Test Case 6a'):
# Test Case 6a, verified by image's digest in db
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 db_hello_signed.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db',
@@ -252,47 +252,47 @@ class TestEfiSignedImage(object):
'fatload host 0:1 4000000 PK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed -s ""',
'efidebug boot order 1',
'bootefi bootmgr'])
assert 'Hello, world!' in ''.join(output)
- with u_boot_console.log.section('Test Case 6b'):
+ with ubman.log.section('Test Case 6b'):
# Test Case 6b, rejected by TEST_db certificate in dbx
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 dbx_db.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot order 1',
'efidebug test bootmgr'])
assert '\'HELLO\' failed' in ''.join(output)
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
- with u_boot_console.log.section('Test Case 6c'):
+ with ubman.log.section('Test Case 6c'):
# Test Case 6c, rejected by image's digest in dbx
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 db.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db',
'fatload host 0:1 4000000 dbx_hello_signed.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot order 1',
'efidebug test bootmgr'])
assert '\'HELLO\' failed' in ''.join(output)
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
- def test_efi_signed_image_auth7(self, u_boot_console, efi_boot_env):
+ def test_efi_signed_image_auth7(self, ubman, efi_boot_env):
"""
Test Case 7 - Reject images based on the sha384/512 of their x509 cert
"""
# sha384 of an x509 cert in dbx
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env
- with u_boot_console.log.section('Test Case 7a'):
- output = u_boot_console.run_command_list([
+ with ubman.log.section('Test Case 7a'):
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 db.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db',
@@ -300,22 +300,22 @@ class TestEfiSignedImage(object):
'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK',
'fatload host 0:1 4000000 PK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK',
- 'fatload host 0:1 4000000 db1.auth',
+ 'fatload host 0:1 4000000 db2.auth',
'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize db',
'fatload host 0:1 4000000 dbx_hash384.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""',
'efidebug boot order 1',
'efidebug test bootmgr'])
assert '\'HELLO\' failed' in ''.join(output)
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
# sha512 of an x509 cert in dbx
- u_boot_console.restart_uboot()
- with u_boot_console.log.section('Test Case 7b'):
- output = u_boot_console.run_command_list([
+ ubman.restart_uboot()
+ with ubman.log.section('Test Case 7b'):
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 db.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db',
@@ -323,39 +323,39 @@ class TestEfiSignedImage(object):
'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK',
'fatload host 0:1 4000000 PK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK',
- 'fatload host 0:1 4000000 db1.auth',
+ 'fatload host 0:1 4000000 db2.auth',
'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize db',
'fatload host 0:1 4000000 dbx_hash512.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi.signed_2sigs -s ""',
'efidebug boot order 1',
'efidebug test bootmgr'])
assert '\'HELLO\' failed' in ''.join(output)
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
- def test_efi_signed_image_auth8(self, u_boot_console, efi_boot_env):
+ def test_efi_signed_image_auth8(self, ubman, efi_boot_env):
"""
Test Case 8 - Secure boot is in force,
Same as Test Case 2 but the image binary to be loaded
was willfully modified (forged)
Must be rejected.
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env
- with u_boot_console.log.section('Test Case 8a'):
+ with ubman.log.section('Test Case 8a'):
# Test Case 8a, Secure boot is not yet forced
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'efidebug boot add -b 1 HELLO1 host 0:1 /helloworld_forged.efi.signed -s ""',
'efidebug boot order 1',
'efidebug test bootmgr'])
assert('hELLO, world!' in ''.join(output))
- with u_boot_console.log.section('Test Case 8b'):
+ with ubman.log.section('Test Case 8b'):
# Test Case 8b, Install signature database and verify the image
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 db.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db',
'fatload host 0:1 4000000 KEK.auth',
@@ -363,9 +363,9 @@ class TestEfiSignedImage(object):
'fatload host 0:1 4000000 PK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot order 1',
'efidebug test bootmgr'])
assert(not 'hELLO, world!' in ''.join(output))
assert('\'HELLO1\' failed' in ''.join(output))
- assert('efi_start_image() returned: 26' in ''.join(output))
+ assert('efi_bootmgr_load() returned: 26' in ''.join(output))
diff --git a/test/py/tests/test_efi_secboot/test_signed_intca.py b/test/py/tests/test_efi_secboot/test_signed_intca.py
index 8d9a5f3e7fe..58f7be03b8b 100644
--- a/test/py/tests/test_efi_secboot/test_signed_intca.py
+++ b/test/py/tests/test_efi_secboot/test_signed_intca.py
@@ -20,15 +20,15 @@ import pytest
@pytest.mark.buildconfigspec('cmd_nvedit_efi')
@pytest.mark.slow
class TestEfiSignedImageIntca(object):
- def test_efi_signed_image_intca1(self, u_boot_console, efi_boot_env_intca):
+ def test_efi_signed_image_intca1(self, ubman, efi_boot_env_intca):
"""
Test Case 1 - authenticated by root CA in db
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env_intca
- with u_boot_console.log.section('Test Case 1a'):
+ with ubman.log.section('Test Case 1a'):
# Test Case 1a, with no Int CA and not authenticated by root CA
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 db_c.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db',
@@ -38,30 +38,30 @@ class TestEfiSignedImageIntca(object):
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot add -b 1 HELLO_a host 0:1 /helloworld.efi.signed_a -s ""',
'efidebug boot order 1',
'efidebug test bootmgr'])
assert '\'HELLO_a\' failed' in ''.join(output)
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
- with u_boot_console.log.section('Test Case 1b'):
+ with ubman.log.section('Test Case 1b'):
# Test Case 1b, signed and authenticated by root CA
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot add -b 2 HELLO_ab host 0:1 /helloworld.efi.signed_ab -s ""',
'efidebug boot order 2',
'bootefi bootmgr'])
assert 'Hello, world!' in ''.join(output)
- def test_efi_signed_image_intca2(self, u_boot_console, efi_boot_env_intca):
+ def test_efi_signed_image_intca2(self, ubman, efi_boot_env_intca):
"""
Test Case 2 - authenticated by root CA in db
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env_intca
- with u_boot_console.log.section('Test Case 2a'):
+ with ubman.log.section('Test Case 2a'):
# Test Case 2a, unsigned and not authenticated by root CA
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 KEK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK',
@@ -69,41 +69,41 @@ class TestEfiSignedImageIntca(object):
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot add -b 1 HELLO_abc host 0:1 /helloworld.efi.signed_abc -s ""',
'efidebug boot order 1',
'efidebug test bootmgr'])
assert '\'HELLO_abc\' failed' in ''.join(output)
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
- with u_boot_console.log.section('Test Case 2b'):
+ with ubman.log.section('Test Case 2b'):
# Test Case 2b, signed and authenticated by root CA
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 db_b.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db',
'efidebug boot order 1',
'efidebug test bootmgr'])
assert '\'HELLO_abc\' failed' in ''.join(output)
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
- with u_boot_console.log.section('Test Case 2c'):
+ with ubman.log.section('Test Case 2c'):
# Test Case 2c, signed and authenticated by root CA
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 db_c.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db',
'efidebug boot order 1',
'efidebug test bootmgr'])
assert 'Hello, world!' in ''.join(output)
- def test_efi_signed_image_intca3(self, u_boot_console, efi_boot_env_intca):
+ def test_efi_signed_image_intca3(self, ubman, efi_boot_env_intca):
"""
Test Case 3 - revoked by dbx
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env_intca
- with u_boot_console.log.section('Test Case 3a'):
+ with ubman.log.section('Test Case 3a'):
# Test Case 3a, revoked by int CA in dbx
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 dbx_b.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx',
@@ -115,21 +115,21 @@ class TestEfiSignedImageIntca(object):
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot add -b 1 HELLO_abc host 0:1 /helloworld.efi.signed_abc -s ""',
'efidebug boot order 1',
'efidebug test bootmgr'])
assert 'Hello, world!' in ''.join(output)
# Or,
# assert '\'HELLO_abc\' failed' in ''.join(output)
- # assert 'efi_start_image() returned: 26' in ''.join(output)
+ # assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
- with u_boot_console.log.section('Test Case 3b'):
+ with ubman.log.section('Test Case 3b'):
# Test Case 3b, revoked by root CA in dbx
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 dbx_c.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx',
'efidebug boot order 1',
'efidebug test bootmgr'])
assert '\'HELLO_abc\' failed' in ''.join(output)
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
diff --git a/test/py/tests/test_efi_secboot/test_unsigned.py b/test/py/tests/test_efi_secboot/test_unsigned.py
index 7c078f220d0..bd6e1b2dadd 100644
--- a/test/py/tests/test_efi_secboot/test_unsigned.py
+++ b/test/py/tests/test_efi_secboot/test_unsigned.py
@@ -18,15 +18,15 @@ import pytest
@pytest.mark.buildconfigspec('cmd_nvedit_efi')
@pytest.mark.slow
class TestEfiUnsignedImage(object):
- def test_efi_unsigned_image_auth1(self, u_boot_console, efi_boot_env):
+ def test_efi_unsigned_image_auth1(self, ubman, efi_boot_env):
"""
Test Case 1 - rejected when not digest in db or dbx
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env
- with u_boot_console.log.section('Test Case 1'):
+ with ubman.log.section('Test Case 1'):
# Test Case 1
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 KEK.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK',
@@ -34,26 +34,26 @@ class TestEfiUnsignedImage(object):
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""',
'efidebug boot order 1',
'bootefi bootmgr'])
assert '\'HELLO\' failed' in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot order 1',
'efidebug test bootmgr'])
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
assert 'Hello, world!' not in ''.join(output)
- def test_efi_unsigned_image_auth2(self, u_boot_console, efi_boot_env):
+ def test_efi_unsigned_image_auth2(self, ubman, efi_boot_env):
"""
Test Case 2 - authenticated by digest in db
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env
- with u_boot_console.log.section('Test Case 2'):
+ with ubman.log.section('Test Case 2'):
# Test Case 2
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 db_hello.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db',
@@ -63,21 +63,21 @@ class TestEfiUnsignedImage(object):
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""',
'efidebug boot order 1',
'bootefi bootmgr'])
assert 'Hello, world!' in ''.join(output)
- def test_efi_unsigned_image_auth3(self, u_boot_console, efi_boot_env):
+ def test_efi_unsigned_image_auth3(self, ubman, efi_boot_env):
"""
Test Case 3 - rejected by digest in dbx
"""
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
disk_img = efi_boot_env
- with u_boot_console.log.section('Test Case 3a'):
+ with ubman.log.section('Test Case 3a'):
# Test Case 3a, rejected by dbx
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % disk_img,
'fatload host 0:1 4000000 db_hello.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx',
@@ -87,31 +87,31 @@ class TestEfiUnsignedImage(object):
'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""',
'efidebug boot order 1',
'bootefi bootmgr'])
assert '\'HELLO\' failed' in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot order 1',
'efidebug test bootmgr'])
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
assert 'Hello, world!' not in ''.join(output)
- with u_boot_console.log.section('Test Case 3b'):
+ with ubman.log.section('Test Case 3b'):
# Test Case 3b, rejected by dbx even if db allows
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'fatload host 0:1 4000000 db_hello.auth',
'setenv -e -nv -bs -rt -at -i 4000000:$filesize db'])
assert 'Failed to set EFI variable' not in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot add -b 1 HELLO host 0:1 /helloworld.efi -s ""',
'efidebug boot order 1',
'bootefi bootmgr'])
assert '\'HELLO\' failed' in ''.join(output)
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'efidebug boot order 1',
'efidebug test bootmgr'])
- assert 'efi_start_image() returned: 26' in ''.join(output)
+ assert 'efi_bootmgr_load() returned: 26' in ''.join(output)
assert 'Hello, world!' not in ''.join(output)
diff --git a/test/py/tests/test_efi_selftest.py b/test/py/tests/test_efi_selftest.py
index 43f24245582..12cbe5caa9b 100644
--- a/test/py/tests/test_efi_selftest.py
+++ b/test/py/tests/test_efi_selftest.py
@@ -7,191 +7,191 @@
import pytest
@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
-def test_efi_selftest_base(u_boot_console):
+def test_efi_selftest_base(ubman):
"""Run UEFI unit tests
- u_boot_console -- U-Boot console
+ ubman -- U-Boot console
This function executes all selftests that are not marked as on request.
"""
- u_boot_console.run_command(cmd='setenv efi_selftest')
- u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
- if u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']):
+ ubman.run_command(cmd='setenv efi_selftest')
+ ubman.run_command(cmd='bootefi selftest', wait_for_prompt=False)
+ if ubman.p.expect(['Summary: 0 failures', 'Press any key']):
raise Exception('Failures occurred during the EFI selftest')
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
@pytest.mark.buildconfigspec('hush_parser')
@pytest.mark.buildconfigspec('of_control')
@pytest.mark.notbuildconfigspec('generate_acpi_table')
-def test_efi_selftest_device_tree(u_boot_console):
+def test_efi_selftest_device_tree(ubman):
"""Test the device tree support in the UEFI sub-system
- u_boot_console -- U-Boot console
+ ubman -- U-Boot console
This test executes the UEFI unit test by calling 'bootefi selftest'.
"""
- u_boot_console.run_command(cmd='setenv efi_selftest list')
- output = u_boot_console.run_command('bootefi selftest')
+ ubman.run_command(cmd='setenv efi_selftest list')
+ output = ubman.run_command('bootefi selftest')
assert '\'device tree\'' in output
- u_boot_console.run_command(cmd='setenv efi_selftest device tree')
+ ubman.run_command(cmd='setenv efi_selftest device tree')
# Set serial# if it is not already set.
- u_boot_console.run_command(cmd='setenv efi_test "${serial#}x"')
- u_boot_console.run_command(cmd='test "${efi_test}" = x && setenv serial# 0')
- u_boot_console.run_command(cmd='bootefi selftest ${fdtcontroladdr}', wait_for_prompt=False)
- if u_boot_console.p.expect(['serial-number:', 'U-Boot']):
+ ubman.run_command(cmd='setenv efi_test "${serial#}x"')
+ ubman.run_command(cmd='test "${efi_test}" = x && setenv serial# 0')
+ ubman.run_command(cmd='bootefi selftest ${fdtcontroladdr}', wait_for_prompt=False)
+ if ubman.p.expect(['serial-number:', 'U-Boot']):
raise Exception('serial-number missing in device tree')
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
-def test_efi_selftest_watchdog_reboot(u_boot_console):
+def test_efi_selftest_watchdog_reboot(ubman):
"""Test the watchdog timer
- u_boot_console -- U-Boot console
+ ubman -- U-Boot console
This function executes the 'watchdog reboot' unit test.
"""
- u_boot_console.run_command(cmd='setenv efi_selftest list')
- output = u_boot_console.run_command('bootefi selftest')
+ ubman.run_command(cmd='setenv efi_selftest list')
+ output = ubman.run_command('bootefi selftest')
assert '\'watchdog reboot\'' in output
- u_boot_console.run_command(cmd='setenv efi_selftest watchdog reboot')
- u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
- if u_boot_console.p.expect(['resetting', 'U-Boot']):
+ ubman.run_command(cmd='setenv efi_selftest watchdog reboot')
+ ubman.run_command(cmd='bootefi selftest', wait_for_prompt=False)
+ if ubman.p.expect(['resetting', 'U-Boot']):
raise Exception('Reset failed in \'watchdog reboot\' test')
- u_boot_console.restart_uboot()
+ ubman.run_command(cmd='', send_nl=False, wait_for_reboot=True)
@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
-def test_efi_selftest_text_input(u_boot_console):
+def test_efi_selftest_text_input(ubman):
"""Test the EFI_SIMPLE_TEXT_INPUT_PROTOCOL
- u_boot_console -- U-Boot console
+ ubman -- U-Boot console
This function calls the text input EFI selftest.
"""
- u_boot_console.run_command(cmd='setenv efi_selftest text input')
- u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
- if u_boot_console.p.expect([r'To terminate type \'x\'']):
+ ubman.run_command(cmd='setenv efi_selftest text input')
+ ubman.run_command(cmd='bootefi selftest', wait_for_prompt=False)
+ if ubman.p.expect([r'To terminate type \'x\'']):
raise Exception('No prompt for \'text input\' test')
- u_boot_console.drain_console()
+ ubman.drain_console()
# EOT
- u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
+ ubman.run_command(cmd=chr(4), wait_for_echo=False,
send_nl=False, wait_for_prompt=False)
- if u_boot_console.p.expect([r'Unicode char 4 \(unknown\), scan code 0 \(Null\)']):
+ if ubman.p.expect([r'Unicode char 4 \(unknown\), scan code 0 \(Null\)']):
raise Exception('EOT failed in \'text input\' test')
- u_boot_console.drain_console()
+ ubman.drain_console()
# BS
- u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
+ ubman.run_command(cmd=chr(8), wait_for_echo=False,
send_nl=False, wait_for_prompt=False)
- if u_boot_console.p.expect([r'Unicode char 8 \(BS\), scan code 0 \(Null\)']):
+ if ubman.p.expect([r'Unicode char 8 \(BS\), scan code 0 \(Null\)']):
raise Exception('BS failed in \'text input\' test')
- u_boot_console.drain_console()
+ ubman.drain_console()
# TAB
- u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
+ ubman.run_command(cmd=chr(9), wait_for_echo=False,
send_nl=False, wait_for_prompt=False)
- if u_boot_console.p.expect([r'Unicode char 9 \(TAB\), scan code 0 \(Null\)']):
+ if ubman.p.expect([r'Unicode char 9 \(TAB\), scan code 0 \(Null\)']):
raise Exception('BS failed in \'text input\' test')
- u_boot_console.drain_console()
+ ubman.drain_console()
# a
- u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
+ ubman.run_command(cmd='a', wait_for_echo=False, send_nl=False,
wait_for_prompt=False)
- if u_boot_console.p.expect([r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']):
+ if ubman.p.expect([r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']):
raise Exception('\'a\' failed in \'text input\' test')
- u_boot_console.drain_console()
+ ubman.drain_console()
# UP escape sequence
- u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
+ ubman.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
send_nl=False, wait_for_prompt=False)
- if u_boot_console.p.expect([r'Unicode char 0 \(Null\), scan code 1 \(Up\)']):
+ if ubman.p.expect([r'Unicode char 0 \(Null\), scan code 1 \(Up\)']):
raise Exception('UP failed in \'text input\' test')
- u_boot_console.drain_console()
+ ubman.drain_console()
# Euro sign
- u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
+ ubman.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
send_nl=False, wait_for_prompt=False)
- if u_boot_console.p.expect([r'Unicode char 8364 \(\'']):
+ if ubman.p.expect([r'Unicode char 8364 \(\'']):
raise Exception('Euro sign failed in \'text input\' test')
- u_boot_console.drain_console()
- u_boot_console.run_command(cmd='x', wait_for_echo=False, send_nl=False,
+ ubman.drain_console()
+ ubman.run_command(cmd='x', wait_for_echo=False, send_nl=False,
wait_for_prompt=False)
- if u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']):
+ if ubman.p.expect(['Summary: 0 failures', 'Press any key']):
raise Exception('Failures occurred during the EFI selftest')
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
-def test_efi_selftest_text_input_ex(u_boot_console):
+def test_efi_selftest_text_input_ex(ubman):
"""Test the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
- u_boot_console -- U-Boot console
+ ubman -- U-Boot console
This function calls the extended text input EFI selftest.
"""
- u_boot_console.run_command(cmd='setenv efi_selftest extended text input')
- u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
- if u_boot_console.p.expect([r'To terminate type \'CTRL\+x\'']):
+ ubman.run_command(cmd='setenv efi_selftest extended text input')
+ ubman.run_command(cmd='bootefi selftest', wait_for_prompt=False)
+ if ubman.p.expect([r'To terminate type \'CTRL\+x\'']):
raise Exception('No prompt for \'text input\' test')
- u_boot_console.drain_console()
+ ubman.drain_console()
# EOT
- u_boot_console.run_command(cmd=chr(4), wait_for_echo=False,
+ ubman.run_command(cmd=chr(4), wait_for_echo=False,
send_nl=False, wait_for_prompt=False)
- if u_boot_console.p.expect([r'Unicode char 100 \(\'d\'\), scan code 0 \(CTRL\+Null\)']):
+ if ubman.p.expect([r'Unicode char 100 \(\'d\'\), scan code 0 \(CTRL\+Null\)']):
raise Exception('EOT failed in \'text input\' test')
- u_boot_console.drain_console()
+ ubman.drain_console()
# BS
- u_boot_console.run_command(cmd=chr(8), wait_for_echo=False,
+ ubman.run_command(cmd=chr(8), wait_for_echo=False,
send_nl=False, wait_for_prompt=False)
- if u_boot_console.p.expect([r'Unicode char 8 \(BS\), scan code 0 \(\+Null\)']):
+ if ubman.p.expect([r'Unicode char 8 \(BS\), scan code 0 \(\+Null\)']):
raise Exception('BS failed in \'text input\' test')
- u_boot_console.drain_console()
+ ubman.drain_console()
# TAB
- u_boot_console.run_command(cmd=chr(9), wait_for_echo=False,
+ ubman.run_command(cmd=chr(9), wait_for_echo=False,
send_nl=False, wait_for_prompt=False)
- if u_boot_console.p.expect([r'Unicode char 9 \(TAB\), scan code 0 \(\+Null\)']):
+ if ubman.p.expect([r'Unicode char 9 \(TAB\), scan code 0 \(\+Null\)']):
raise Exception('TAB failed in \'text input\' test')
- u_boot_console.drain_console()
+ ubman.drain_console()
# a
- u_boot_console.run_command(cmd='a', wait_for_echo=False, send_nl=False,
+ ubman.run_command(cmd='a', wait_for_echo=False, send_nl=False,
wait_for_prompt=False)
- if u_boot_console.p.expect([r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']):
+ if ubman.p.expect([r'Unicode char 97 \(\'a\'\), scan code 0 \(Null\)']):
raise Exception('\'a\' failed in \'text input\' test')
- u_boot_console.drain_console()
+ ubman.drain_console()
# UP escape sequence
- u_boot_console.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
+ ubman.run_command(cmd=chr(27) + '[A', wait_for_echo=False,
send_nl=False, wait_for_prompt=False)
- if u_boot_console.p.expect([r'Unicode char 0 \(Null\), scan code 1 \(\+Up\)']):
+ if ubman.p.expect([r'Unicode char 0 \(Null\), scan code 1 \(\+Up\)']):
raise Exception('UP failed in \'text input\' test')
- u_boot_console.drain_console()
+ ubman.drain_console()
# Euro sign
- u_boot_console.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
+ ubman.run_command(cmd=b'\xe2\x82\xac'.decode(), wait_for_echo=False,
send_nl=False, wait_for_prompt=False)
- if u_boot_console.p.expect([r'Unicode char 8364 \(\'']):
+ if ubman.p.expect([r'Unicode char 8364 \(\'']):
raise Exception('Euro sign failed in \'text input\' test')
- u_boot_console.drain_console()
+ ubman.drain_console()
# SHIFT+ALT+FN 5
- u_boot_console.run_command(cmd=b'\x1b\x5b\x31\x35\x3b\x34\x7e'.decode(),
+ ubman.run_command(cmd=b'\x1b\x5b\x31\x35\x3b\x34\x7e'.decode(),
wait_for_echo=False, send_nl=False,
wait_for_prompt=False)
- if u_boot_console.p.expect([r'Unicode char 0 \(Null\), scan code 15 \(SHIFT\+ALT\+FN 5\)']):
+ if ubman.p.expect([r'Unicode char 0 \(Null\), scan code 15 \(SHIFT\+ALT\+FN 5\)']):
raise Exception('SHIFT+ALT+FN 5 failed in \'text input\' test')
- u_boot_console.drain_console()
- u_boot_console.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False,
+ ubman.drain_console()
+ ubman.run_command(cmd=chr(24), wait_for_echo=False, send_nl=False,
wait_for_prompt=False)
- if u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']):
+ if ubman.p.expect(['Summary: 0 failures', 'Press any key']):
raise Exception('Failures occurred during the EFI selftest')
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
@pytest.mark.buildconfigspec('efi_tcg2_protocol')
-def test_efi_selftest_tcg2(u_boot_console):
+def test_efi_selftest_tcg2(ubman):
"""Test the EFI_TCG2 PROTOCOL
- u_boot_console -- U-Boot console
+ ubman -- U-Boot console
This function executes the 'tcg2' unit test.
"""
- u_boot_console.restart_uboot()
- u_boot_console.run_command(cmd='setenv efi_selftest list')
- output = u_boot_console.run_command('bootefi selftest')
+ ubman.restart_uboot()
+ ubman.run_command(cmd='setenv efi_selftest list')
+ output = ubman.run_command('bootefi selftest')
assert '\'tcg2\'' in output
- u_boot_console.run_command(cmd='setenv efi_selftest tcg2')
- u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False)
- if u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']):
+ ubman.run_command(cmd='setenv efi_selftest tcg2')
+ ubman.run_command(cmd='bootefi selftest', wait_for_prompt=False)
+ if ubman.p.expect(['Summary: 0 failures', 'Press any key']):
raise Exception('Failures occurred during the EFI selftest')
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
diff --git a/test/py/tests/test_eficonfig/test_eficonfig.py b/test/py/tests/test_eficonfig.py
index 1d8e033f75d..ac1600ec252 100644
--- a/test/py/tests/test_eficonfig/test_eficonfig.py
+++ b/test/py/tests/test_eficonfig.py
@@ -3,52 +3,96 @@
"""
import pytest
+import shutil
+import pytest
import time
+from subprocess import call, check_call, CalledProcessError
+from tests import fs_helper
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_eficonfig')
@pytest.mark.buildconfigspec('cmd_bootefi_bootmgr')
-def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
+def test_efi_eficonfig(ubman):
+
+ def prepare_image(u_boot_config):
+ """Set up a file system to be used in UEFI "eficonfig" command
+ tests. This creates a disk image with the following files:
+ initrd-1.img
+ initrd-2.img
+ initrddump.efi
+
+ Args:
+ u_boot_config -- U-Boot configuration.
+
+ Return:
+ A path to disk image to be used for testing
+
+ """
+ try:
+ image_path, mnt_point = fs_helper.setup_image(u_boot_config, 0,
+ 0xc,
+ basename='test_eficonfig')
+
+ with open(mnt_point + '/initrd-1.img', 'w', encoding = 'ascii') as file:
+ file.write("initrd 1")
+
+ with open(mnt_point + '/initrd-2.img', 'w', encoding = 'ascii') as file:
+ file.write("initrd 2")
+
+ shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/initrddump.efi',
+ mnt_point + '/initrddump.efi')
+
+ fsfile = fs_helper.mk_fs(ubman.config, 'vfat', 0x100000,
+ 'test_eficonfig', mnt_point)
+ check_call(f'dd if={fsfile} of={image_path} bs=1M seek=1', shell=True)
+
+ yield image_path
+ except CalledProcessError as err:
+ pytest.skip('Preparing test_eficonfig image failed')
+ call('rm -f %s' % image_path, shell=True)
+ finally:
+ call('rm -rf %s' % mnt_point, shell=True)
+ call('rm -f %s' % image_path, shell=True)
def send_user_input_and_wait(user_str, expect_str):
time.sleep(0.1) # TODO: does not work correctly without sleep
- u_boot_console.run_command(cmd=user_str, wait_for_prompt=False,
+ ubman.run_command(cmd=user_str, wait_for_prompt=False,
wait_for_echo=True, send_nl=False)
- u_boot_console.run_command(cmd='\x0d', wait_for_prompt=False,
+ ubman.run_command(cmd='\x0d', wait_for_prompt=False,
wait_for_echo=False, send_nl=False)
if expect_str is not None:
for i in expect_str:
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
def press_up_down_enter_and_wait(up_count, down_count, enter, expect_str):
# press UP key
for i in range(up_count):
- u_boot_console.run_command(cmd='\x1b\x5b\x41', wait_for_prompt=False,
+ ubman.run_command(cmd='\x1b\x5b\x41', wait_for_prompt=False,
wait_for_echo=False, send_nl=False)
# press DOWN key
for i in range(down_count):
- u_boot_console.run_command(cmd='\x1b\x5b\x42', wait_for_prompt=False,
+ ubman.run_command(cmd='\x1b\x5b\x42', wait_for_prompt=False,
wait_for_echo=False, send_nl=False)
# press ENTER if requested
if enter:
- u_boot_console.run_command(cmd='\x0d', wait_for_prompt=False,
+ ubman.run_command(cmd='\x0d', wait_for_prompt=False,
wait_for_echo=False, send_nl=False)
# wait expected output
if expect_str is not None:
for i in expect_str:
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
def press_escape_key(wait_prompt):
- u_boot_console.run_command(cmd='\x1b', wait_for_prompt=wait_prompt, wait_for_echo=False, send_nl=False)
+ ubman.run_command(cmd='\x1b', wait_for_prompt=wait_prompt, wait_for_echo=False, send_nl=False)
def press_enter_key(wait_prompt):
- u_boot_console.run_command(cmd='\x0d', wait_for_prompt=wait_prompt,
+ ubman.run_command(cmd='\x0d', wait_for_prompt=wait_prompt,
wait_for_echo=False, send_nl=False)
def check_current_is_maintenance_menu():
for i in ('UEFI Maintenance Menu', 'Add Boot Option', 'Edit Boot Option',
'Change Boot Order', 'Delete Boot Option', 'Quit'):
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
""" Unit test for "eficonfig" command
The menu-driven interface is used to set up UEFI load options.
@@ -56,34 +100,29 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
The crc32 of the loaded initrd.img is checked
Args:
- u_boot_console -- U-Boot console
- efi__data -- Path to the disk image used for testing.
- Test disk image has following files.
- initrd-1.img
- initrd-2.img
- initrddump.efi
-
+ ubman -- U-Boot console
"""
# This test passes for unknown reasons in the bowels of U-Boot. It needs to
# be replaced with a unit test.
return
# Restart the system to clean the previous state
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
- with u_boot_console.temporary_timeout(500):
+ efi_eficonfig_data = prepare_image(ubman.config)
+ with ubman.temporary_timeout(500):
#
# Test Case 1: Check the menu is displayed
#
- u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+ ubman.run_command('eficonfig', wait_for_prompt=False)
for i in ('UEFI Maintenance Menu', 'Add Boot Option', 'Edit Boot Option',
'Change Boot Order', 'Delete Boot Option', 'Quit'):
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
# Select "Add Boot Option"
press_enter_key(False)
for i in ('Add Boot Option', 'Description:', 'File', 'Initrd File', 'Optional Data',
'Save', 'Quit'):
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
press_escape_key(False)
check_current_is_maintenance_menu()
# return to U-Boot console
@@ -94,16 +133,16 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
#
# bind the test disk image for succeeding tests
- u_boot_console.run_command(cmd = f'host bind 0 {efi_eficonfig_data}')
+ ubman.run_command(cmd = f'host bind 0 {efi_eficonfig_data}')
- u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+ ubman.run_command('eficonfig', wait_for_prompt=False)
# Change the Boot Order
press_up_down_enter_and_wait(0, 2, True, 'Quit')
for i in ('host 0:1', 'Save', 'Quit'):
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
# disable auto generated boot option for succeeding test
- u_boot_console.run_command(cmd=' ', wait_for_prompt=False,
+ ubman.run_command(cmd=' ', wait_for_prompt=False,
wait_for_echo=False, send_nl=False)
# Save the BootOrder
press_up_down_enter_and_wait(0, 1, True, None)
@@ -117,7 +156,7 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
press_up_down_enter_and_wait(0, 0, True, 'Quit')
# Press the enter key to select 'Description:' entry, then enter Description
- press_up_down_enter_and_wait(0, 0, True, 'enter description:')
+ press_up_down_enter_and_wait(0, 0, True, 'Enter description:')
# Send Description user input, press ENTER key to complete
send_user_input_and_wait('test 1', 'Quit')
@@ -143,7 +182,7 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
send_user_input_and_wait('nocolor', None)
for i in ('Description: test 1', 'File: host 0:1/initrddump.efi',
'Initrd File: host 0:1/initrd-1.img', 'Optional Data: nocolor', 'Save', 'Quit'):
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
# Save the Boot Option
press_up_down_enter_and_wait(0, 4, True, None)
@@ -152,21 +191,21 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
# Check the newly added Boot Option is handled correctly
# Return to U-Boot console
press_escape_key(True)
- u_boot_console.run_command(cmd = 'bootefi bootmgr')
- response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
+ ubman.run_command(cmd = 'bootefi bootmgr')
+ response = ubman.run_command(cmd = 'load', wait_for_echo=False)
assert 'crc32: 0x181464af' in response
- u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
+ ubman.run_command(cmd = 'exit', wait_for_echo=False)
#
# Test Case 4: Add second Boot Option and load it
#
- u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+ ubman.run_command('eficonfig', wait_for_prompt=False)
# Select 'Add Boot Option'
press_up_down_enter_and_wait(0, 0, True, 'Quit')
# Press the enter key to select 'Description:' entry, then enter Description
- press_up_down_enter_and_wait(0, 0, True, 'enter description:')
+ press_up_down_enter_and_wait(0, 0, True, 'Enter description:')
# Send Description user input, press ENTER key to complete
send_user_input_and_wait('test 2', 'Quit')
@@ -192,7 +231,7 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
send_user_input_and_wait('nocolor', None)
for i in ('Description: test 2', 'File: host 0:1/initrddump.efi',
'Initrd File: host 0:1/initrd-2.img', 'Optional Data: nocolor', 'Save', 'Quit'):
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
# Save the Boot Option
press_up_down_enter_and_wait(0, 4, True, 'Quit')
@@ -201,10 +240,10 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
press_up_down_enter_and_wait(0, 2, True, 'Quit')
press_up_down_enter_and_wait(0, 1, False, 'Quit')
# move 'test 1' to the second entry
- u_boot_console.run_command(cmd='+', wait_for_prompt=False,
+ ubman.run_command(cmd='+', wait_for_prompt=False,
wait_for_echo=False, send_nl=False)
for i in ('test 2', 'test 1', 'host 0:1', 'Save', 'Quit'):
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
# Save the BootOrder
press_up_down_enter_and_wait(0, 3, True, None)
check_current_is_maintenance_menu()
@@ -212,52 +251,52 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
# Check the newly added Boot Option is handled correctly
# Return to U-Boot console
press_escape_key(True)
- u_boot_console.run_command(cmd = 'bootefi bootmgr')
- response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
+ ubman.run_command(cmd = 'bootefi bootmgr')
+ response = ubman.run_command(cmd = 'load', wait_for_echo=False)
assert 'crc32: 0x811d3515' in response
- u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
+ ubman.run_command(cmd = 'exit', wait_for_echo=False)
#
# Test Case 5: Change BootOrder and load it
#
- u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+ ubman.run_command('eficonfig', wait_for_prompt=False)
# Change the Boot Order
press_up_down_enter_and_wait(0, 2, True, None)
# Check the current BootOrder
for i in ('test 2', 'test 1', 'host 0:1', 'Save', 'Quit'):
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
# move 'test 2' to the second entry
- u_boot_console.run_command(cmd='-', wait_for_prompt=False,
+ ubman.run_command(cmd='-', wait_for_prompt=False,
wait_for_echo=False, send_nl=False)
for i in ('test 1', 'test 2', 'host 0:1', 'Save', 'Quit'):
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
# Save the BootOrder
press_up_down_enter_and_wait(0, 2, True, None)
check_current_is_maintenance_menu()
# Return to U-Boot console
press_escape_key(True)
- u_boot_console.run_command(cmd = 'bootefi bootmgr')
- response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
+ ubman.run_command(cmd = 'bootefi bootmgr')
+ response = ubman.run_command(cmd = 'load', wait_for_echo=False)
assert 'crc32: 0x181464af' in response
- u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
+ ubman.run_command(cmd = 'exit', wait_for_echo=False)
#
# Test Case 6: Delete Boot Option(label:test 2)
#
- u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+ ubman.run_command('eficonfig', wait_for_prompt=False)
# Select 'Delete Boot Option'
press_up_down_enter_and_wait(0, 3, True, None)
# Check the current BootOrder
for i in ('test 1', 'test 2', 'Quit'):
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
# Delete 'test 2'
press_up_down_enter_and_wait(0, 1, True, None)
for i in ('test 1', 'Quit'):
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
press_escape_key(False)
check_current_is_maintenance_menu()
# Return to U-Boot console
@@ -266,19 +305,19 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
#
# Test Case 7: Edit Boot Option
#
- u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+ ubman.run_command('eficonfig', wait_for_prompt=False)
# Select 'Edit Boot Option'
press_up_down_enter_and_wait(0, 1, True, None)
# Check the current BootOrder
for i in ('test 1', 'Quit'):
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
press_up_down_enter_and_wait(0, 0, True, None)
for i in ('Description: test 1', 'File: host 0:1/initrddump.efi',
'Initrd File: host 0:1/initrd-1.img', 'Optional Data: nocolor', 'Save', 'Quit'):
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
# Press the enter key to select 'Description:' entry, then enter Description
- press_up_down_enter_and_wait(0, 0, True, 'enter description:')
+ press_up_down_enter_and_wait(0, 0, True, 'Enter description:')
# Send Description user input, press ENTER key to complete
send_user_input_and_wait('test 3', 'Quit')
@@ -304,7 +343,7 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
send_user_input_and_wait('', None)
for i in ('Description: test 3', 'File: host 0:1/initrddump.efi',
'Initrd File: host 0:1/initrd-2.img', 'Optional Data:', 'Save', 'Quit'):
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
# Save the Boot Option
press_up_down_enter_and_wait(0, 4, True, 'Quit')
@@ -314,21 +353,21 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
# Check the updated Boot Option is handled correctly
# Return to U-Boot console
press_escape_key(True)
- u_boot_console.run_command(cmd = 'bootefi bootmgr')
- response = u_boot_console.run_command(cmd = 'load', wait_for_echo=False)
+ ubman.run_command(cmd = 'bootefi bootmgr')
+ response = ubman.run_command(cmd = 'load', wait_for_echo=False)
assert 'crc32: 0x811d3515' in response
- u_boot_console.run_command(cmd = 'exit', wait_for_echo=False)
+ ubman.run_command(cmd = 'exit', wait_for_echo=False)
#
# Test Case 8: Delete Boot Option(label:test 3)
#
- u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+ ubman.run_command('eficonfig', wait_for_prompt=False)
# Select 'Delete Boot Option'
press_up_down_enter_and_wait(0, 3, True, None)
# Check the current BootOrder
for i in ('test 3', 'Quit'):
- u_boot_console.p.expect([i])
+ ubman.p.expect([i])
# Delete 'test 3'
press_up_down_enter_and_wait(0, 0, True, 'Quit')
@@ -338,12 +377,12 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
press_escape_key(True)
# remove the host device
- u_boot_console.run_command(cmd = f'host bind -r 0')
+ ubman.run_command(cmd = f'host bind -r 0')
#
# Test Case 9: No block device found
#
- u_boot_console.run_command('eficonfig', wait_for_prompt=False)
+ ubman.run_command('eficonfig', wait_for_prompt=False)
# Select 'Add Boot Option'
press_up_down_enter_and_wait(0, 0, True, 'Quit')
diff --git a/test/py/tests/test_eficonfig/conftest.py b/test/py/tests/test_eficonfig/conftest.py
deleted file mode 100644
index 0a82fbefd75..00000000000
--- a/test/py/tests/test_eficonfig/conftest.py
+++ /dev/null
@@ -1,40 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0+
-
-"""Fixture for UEFI eficonfig test
-"""
-
-import os
-import shutil
-from subprocess import check_call
-import pytest
-
-@pytest.fixture(scope='session')
-def efi_eficonfig_data(u_boot_config):
- """Set up a file system to be used in UEFI "eficonfig" command
- tests
-
- Args:
- u_boot_config -- U-Boot configuration.
-
- Return:
- A path to disk image to be used for testing
- """
- mnt_point = u_boot_config.persistent_data_dir + '/test_efi_eficonfig'
- image_path = u_boot_config.persistent_data_dir + '/efi_eficonfig.img'
-
- shutil.rmtree(mnt_point, ignore_errors=True)
- os.mkdir(mnt_point, mode = 0o755)
-
- with open(mnt_point + '/initrd-1.img', 'w', encoding = 'ascii') as file:
- file.write("initrd 1")
-
- with open(mnt_point + '/initrd-2.img', 'w', encoding = 'ascii') as file:
- file.write("initrd 2")
-
- shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/initrddump.efi',
- mnt_point + '/initrddump.efi')
-
- check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}',
- shell=True)
-
- return image_path
diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py
index 00bcccd65ff..383e26c03b0 100644
--- a/test/py/tests/test_env.py
+++ b/test/py/tests/test_env.py
@@ -13,7 +13,7 @@ from subprocess import call, CalledProcessError
import tempfile
import pytest
-import u_boot_utils
+import utils
# FIXME: This might be useful for other tests;
# perhaps refactor it into ConsoleBase or some other state object?
@@ -23,17 +23,17 @@ class StateTestEnv(object):
names.
"""
- def __init__(self, u_boot_console):
+ def __init__(self, ubman):
"""Initialize a new StateTestEnv object.
Args:
- u_boot_console: A U-Boot console.
+ ubman: A U-Boot console.
Returns:
Nothing.
"""
- self.u_boot_console = u_boot_console
+ self.ubman = ubman
self.get_env()
self.set_var = self.get_non_existent_var()
@@ -47,12 +47,12 @@ class StateTestEnv(object):
Nothing.
"""
- if self.u_boot_console.config.buildconfig.get(
+ if self.ubman.config.buildconfig.get(
'config_version_variable', 'n') == 'y':
- with self.u_boot_console.disable_check('main_signon'):
- response = self.u_boot_console.run_command('printenv')
+ with self.ubman.disable_check('main_signon'):
+ response = self.ubman.run_command('printenv')
else:
- response = self.u_boot_console.run_command('printenv')
+ response = self.ubman.run_command('printenv')
self.env = {}
for l in response.splitlines():
if not '=' in l:
@@ -92,12 +92,12 @@ class StateTestEnv(object):
ste = None
@pytest.fixture(scope='function')
-def state_test_env(u_boot_console):
+def state_test_env(ubman):
"""pytest fixture to provide a StateTestEnv object to tests."""
global ste
if not ste:
- ste = StateTestEnv(u_boot_console)
+ ste = StateTestEnv(ubman)
return ste
def unset_var(state_test_env, var):
@@ -114,7 +114,7 @@ def unset_var(state_test_env, var):
Nothing.
"""
- state_test_env.u_boot_console.run_command('setenv %s' % var)
+ state_test_env.ubman.run_command('setenv %s' % var)
if var in state_test_env.env:
del state_test_env.env[var]
@@ -133,7 +133,7 @@ def set_var(state_test_env, var, value):
Nothing.
"""
- bc = state_test_env.u_boot_console.config.buildconfig
+ bc = state_test_env.ubman.config.buildconfig
if bc.get('config_hush_parser', None):
quote = '"'
else:
@@ -141,7 +141,7 @@ def set_var(state_test_env, var, value):
if ' ' in value:
pytest.skip('Space in variable value on non-Hush shell')
- state_test_env.u_boot_console.run_command(
+ state_test_env.ubman.run_command(
'setenv %s %s%s%s' % (var, quote, value, quote))
state_test_env.env[var] = value
@@ -155,7 +155,7 @@ def validate_empty(state_test_env, var):
Nothing.
"""
- response = state_test_env.u_boot_console.run_command('echo ${%s}' % var)
+ response = state_test_env.ubman.run_command('echo ${%s}' % var)
assert response == ''
def validate_set(state_test_env, var, value):
@@ -171,15 +171,14 @@ def validate_set(state_test_env, var, value):
# echo does not preserve leading, internal, or trailing whitespace in the
# value. printenv does, and hence allows more complete testing.
- response = state_test_env.u_boot_console.run_command('printenv %s' % var)
+ response = state_test_env.ubman.run_command('printenv %s' % var)
assert response == ('%s=%s' % (var, value))
@pytest.mark.boardspec('sandbox')
-def test_env_initial_env_file(u_boot_console):
+def test_env_initial_env_file(ubman):
"""Test that the u-boot-initial-env make target works"""
- cons = u_boot_console
- builddir = 'O=' + cons.config.build_dir
- envfile = cons.config.build_dir + '/u-boot-initial-env'
+ builddir = 'O=' + ubman.config.build_dir
+ envfile = ubman.config.build_dir + '/u-boot-initial-env'
# remove if already exists from an older run
try:
@@ -187,7 +186,7 @@ def test_env_initial_env_file(u_boot_console):
except:
pass
- u_boot_utils.run_and_log(cons, ['make', builddir, 'u-boot-initial-env'])
+ utils.run_and_log(ubman, ['make', builddir, 'u-boot-initial-env'])
assert os.path.exists(envfile)
@@ -215,7 +214,7 @@ def test_env_printenv_non_existent(state_test_env):
"""Test printenv error message for non-existant variables."""
var = state_test_env.set_var
- c = state_test_env.u_boot_console
+ c = state_test_env.ubman
with c.disable_check('error_notification'):
response = c.run_command('printenv %s' % var)
assert response == '## Error: "%s" not defined' % var
@@ -277,8 +276,8 @@ def test_env_import_checksum_no_size(state_test_env):
"""Test that omitted ('-') size parameter with checksum validation fails the
env import function.
"""
- c = state_test_env.u_boot_console
- ram_base = u_boot_utils.find_ram_base(state_test_env.u_boot_console)
+ c = state_test_env.ubman
+ ram_base = utils.find_ram_base(state_test_env.ubman)
addr = '%08x' % ram_base
with c.disable_check('error_notification'):
@@ -290,8 +289,8 @@ def test_env_import_whitelist_checksum_no_size(state_test_env):
"""Test that omitted ('-') size parameter with checksum validation fails the
env import function when variables are passed as parameters.
"""
- c = state_test_env.u_boot_console
- ram_base = u_boot_utils.find_ram_base(state_test_env.u_boot_console)
+ c = state_test_env.ubman
+ ram_base = utils.find_ram_base(state_test_env.ubman)
addr = '%08x' % ram_base
with c.disable_check('error_notification'):
@@ -302,8 +301,8 @@ def test_env_import_whitelist_checksum_no_size(state_test_env):
@pytest.mark.buildconfigspec('cmd_importenv')
def test_env_import_whitelist(state_test_env):
"""Test importing only a handful of env variables from an environment."""
- c = state_test_env.u_boot_console
- ram_base = u_boot_utils.find_ram_base(state_test_env.u_boot_console)
+ c = state_test_env.ubman
+ ram_base = utils.find_ram_base(state_test_env.ubman)
addr = '%08x' % ram_base
set_var(state_test_env, 'foo1', 'bar1')
@@ -339,8 +338,8 @@ def test_env_import_whitelist_delete(state_test_env):
deletion if a var A that is passed to env import is not in the
environment to be imported.
"""
- c = state_test_env.u_boot_console
- ram_base = u_boot_utils.find_ram_base(state_test_env.u_boot_console)
+ c = state_test_env.ubman
+ ram_base = utils.find_ram_base(state_test_env.ubman)
addr = '%08x' % ram_base
set_var(state_test_env, 'foo1', 'bar1')
@@ -373,7 +372,7 @@ def test_env_info(state_test_env):
"""Test 'env info' command with all possible options.
"""
- c = state_test_env.u_boot_console
+ c = state_test_env.ubman
response = c.run_command('env info')
nb_line = 0
@@ -410,7 +409,7 @@ def test_env_info_sandbox(state_test_env):
"""Test 'env info' command result with several options on sandbox
with a known ENV configuration: ready & default & persistent
"""
- c = state_test_env.u_boot_console
+ c = state_test_env.ubman
response = c.run_command('env info')
assert 'env_ready = true' in response
@@ -435,7 +434,7 @@ def test_env_info_sandbox(state_test_env):
def mk_env_ext4(state_test_env):
"""Create a empty ext4 file system volume."""
- c = state_test_env.u_boot_console
+ c = state_test_env.ubman
filename = 'env.ext4.img'
persistent = c.config.persistent_data_dir + '/' + filename
fs_img = c.config.result_dir + '/' + filename
@@ -446,16 +445,16 @@ def mk_env_ext4(state_test_env):
# Some distributions do not add /sbin to the default PATH, where mkfs.ext4 lives
os.environ["PATH"] += os.pathsep + '/sbin'
try:
- u_boot_utils.run_and_log(c, 'dd if=/dev/zero of=%s bs=1M count=16' % persistent)
- u_boot_utils.run_and_log(c, 'mkfs.ext4 %s' % persistent)
- sb_content = u_boot_utils.run_and_log(c, 'tune2fs -l %s' % persistent)
+ utils.run_and_log(c, 'dd if=/dev/zero of=%s bs=1M count=16' % persistent)
+ utils.run_and_log(c, 'mkfs.ext4 %s' % persistent)
+ sb_content = utils.run_and_log(c, 'tune2fs -l %s' % persistent)
if 'metadata_csum' in sb_content:
- u_boot_utils.run_and_log(c, 'tune2fs -O ^metadata_csum %s' % persistent)
+ utils.run_and_log(c, 'tune2fs -O ^metadata_csum %s' % persistent)
except CalledProcessError:
call('rm -f %s' % persistent, shell=True)
raise
- u_boot_utils.run_and_log(c, ['cp', '-f', persistent, fs_img])
+ utils.run_and_log(c, ['cp', '-f', persistent, fs_img])
return fs_img
@pytest.mark.boardspec('sandbox')
@@ -467,7 +466,7 @@ def mk_env_ext4(state_test_env):
def test_env_ext4(state_test_env):
"""Test ENV in EXT4 on sandbox."""
- c = state_test_env.u_boot_console
+ c = state_test_env.ubman
fs_img = ''
try:
fs_img = mk_env_ext4(state_test_env)
@@ -488,7 +487,7 @@ def test_env_ext4(state_test_env):
assert 'Loading Environment from EXT4... OK' in response
response = c.run_command('ext4ls host 0:0')
- assert '8192 uboot.env' in response
+ assert '8192 uboot.env' in response
response = c.run_command('env info')
assert 'env_valid = valid' in response
@@ -545,7 +544,7 @@ def test_env_ext4(state_test_env):
if fs_img:
call('rm -f %s' % fs_img, shell=True)
-def test_env_text(u_boot_console):
+def test_env_text(ubman):
"""Test the script that converts the environment to a text file"""
def check_script(intext, expect_val):
@@ -560,15 +559,14 @@ def test_env_text(u_boot_console):
fname = os.path.join(path, 'infile')
with open(fname, 'w') as inf:
print(intext, file=inf)
- result = u_boot_utils.run_and_log(cons, ['awk', '-f', script, fname])
+ result = utils.run_and_log(ubman, ['awk', '-f', script, fname])
if expect_val is not None:
expect = '#define CONFIG_EXTRA_ENV_TEXT "%s"\n' % expect_val
assert result == expect
else:
assert result == ''
- cons = u_boot_console
- script = os.path.join(cons.config.source_dir, 'scripts', 'env2string.awk')
+ script = os.path.join(ubman.config.source_dir, 'scripts', 'env2string.awk')
# simple script with a single var
check_script('fred=123', 'fred=123\\0')
diff --git a/test/py/tests/test_event_dump.py b/test/py/tests/test_event_dump.py
index e282c67335c..b9d48f54dc2 100644
--- a/test/py/tests/test_event_dump.py
+++ b/test/py/tests/test_event_dump.py
@@ -4,20 +4,21 @@
import pytest
import re
-import u_boot_utils as util
+import utils
# This is only a partial test - coverting 64-bit sandbox. It does not test
# big-endian images, nor 32-bit images
@pytest.mark.boardspec('sandbox')
-def test_event_dump(u_boot_console):
+def test_event_dump(ubman):
"""Test that the "help" command can be executed."""
- cons = u_boot_console
- sandbox = cons.config.build_dir + '/u-boot'
- out = util.run_and_log(cons, ['scripts/event_dump.py', sandbox])
+ sandbox = ubman.config.build_dir + '/u-boot'
+ out = utils.run_and_log(ubman, ['scripts/event_dump.py', sandbox])
expect = '''.*Event type Id Source location
-------------------- ------------------------------ ------------------------------
EVT_FT_FIXUP bootmeth_vbe_ft_fixup .*boot/vbe_request.c:.*
EVT_FT_FIXUP bootmeth_vbe_simple_ft_fixup .*boot/vbe_simple_os.c:.*
+EVT_LAST_STAGE_INIT alloc_write_acpi_tables .*lib/acpi/acpi_table.c:.*
+EVT_LAST_STAGE_INIT efi_block_device_create .*lib/efi_driver/efi_block_device.c:.*
EVT_LAST_STAGE_INIT install_smbios_table .*lib/efi_loader/efi_smbios.c:.*
EVT_MISC_INIT_F sandbox_early_getopt_check .*arch/sandbox/cpu/start.c:.*
EVT_TEST h_adder_simple .*test/common/event.c:'''
diff --git a/test/py/tests/test_extension.py b/test/py/tests/test_extension.py
index 267cf2ff27c..61223496054 100644
--- a/test/py/tests/test_extension.py
+++ b/test/py/tests/test_extension.py
@@ -6,48 +6,50 @@
import os
import pytest
-import u_boot_utils
+import utils
overlay_addr = 0x1000
SANDBOX_DTB='arch/sandbox/dts/sandbox.dtb'
OVERLAY_DIR='arch/sandbox/dts/'
-def load_dtb(u_boot_console):
- u_boot_console.log.action('Loading devicetree to RAM...')
- u_boot_console.run_command('host load hostfs - $fdt_addr_r %s' % (os.path.join(u_boot_console.config.build_dir, SANDBOX_DTB)))
- u_boot_console.run_command('fdt addr $fdt_addr_r')
+def load_dtb(ubman):
+ ubman.log.action('Loading devicetree to RAM...')
+ ubman.run_command('host load hostfs - $fdt_addr_r %s' % (os.path.join(ubman.config.build_dir, SANDBOX_DTB)))
+ ubman.run_command('fdt addr $fdt_addr_r')
@pytest.mark.buildconfigspec('cmd_fdt')
@pytest.mark.boardspec('sandbox')
-def test_extension(u_boot_console):
+def test_extension(ubman):
"""Test the 'extension' command."""
- load_dtb(u_boot_console)
+ load_dtb(ubman)
- output = u_boot_console.run_command('extension list')
- assert('No extension' in output)
+ output = ubman.run_command('extension list')
+ # extension_bootdev_hunt may have already run.
+ # Without reboot we cannot make any assumption here.
+ # assert('No extension' in output)
- output = u_boot_console.run_command('extension scan')
+ output = ubman.run_command('extension scan')
assert output == 'Found 2 extension board(s).'
- output = u_boot_console.run_command('extension list')
+ output = ubman.run_command('extension list')
assert('overlay0.dtbo' in output)
assert('overlay1.dtbo' in output)
- u_boot_console.run_command_list([
+ ubman.run_command_list([
'setenv extension_overlay_addr %s' % (overlay_addr),
- 'setenv extension_overlay_cmd \'host load hostfs - ${extension_overlay_addr} %s${extension_overlay_name}\'' % (os.path.join(u_boot_console.config.build_dir, OVERLAY_DIR))])
+ 'setenv extension_overlay_cmd \'host load hostfs - ${extension_overlay_addr} %s${extension_overlay_name}\'' % (os.path.join(ubman.config.build_dir, OVERLAY_DIR))])
- output = u_boot_console.run_command('extension apply 0')
+ output = ubman.run_command('extension apply 0')
assert('bytes read' in output)
- output = u_boot_console.run_command('fdt print')
+ output = ubman.run_command('fdt print')
assert('button3' in output)
- output = u_boot_console.run_command('extension apply all')
+ output = ubman.run_command('extension apply all')
assert('bytes read' in output)
- output = u_boot_console.run_command('fdt print')
+ output = ubman.run_command('fdt print')
assert('button4' in output)
diff --git a/test/py/tests/test_fit.py b/test/py/tests/test_fit.py
index 8f9c4b26411..619f73153a0 100755
--- a/test/py/tests/test_fit.py
+++ b/test/py/tests/test_fit.py
@@ -6,7 +6,7 @@
import os
import pytest
import struct
-import u_boot_utils as util
+import utils
import fit_util
# Define a base ITS which we can adjust using % and a dictionary
@@ -118,7 +118,7 @@ host save hostfs 0 %(loadables2_addr)x %(loadables2_out)s %(loadables2_size)x
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('fit_signature')
@pytest.mark.requiredtool('dtc')
-def test_fit(u_boot_console):
+def test_fit(ubman):
def make_fname(leaf):
"""Make a temporary filename
@@ -127,7 +127,7 @@ def test_fit(u_boot_console):
Return:
Temporary filename
"""
- return os.path.join(cons.config.build_dir, leaf)
+ return os.path.join(ubman.config.build_dir, leaf)
def filesize(fname):
"""Get the size of a file
@@ -165,7 +165,7 @@ def test_fit(u_boot_console):
return fname
def make_compressed(filename):
- util.run_and_log(cons, ['gzip', '-f', '-k', filename])
+ utils.run_and_log(ubman, ['gzip', '-f', '-k', filename])
return filename + '.gz'
def find_matching(text, match):
@@ -260,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 = fit_util.make_dtb(cons, base_fdt, 'u-boot')
- kernel = fit_util.make_kernel(cons, 'test-kernel.bin', 'kernel')
+ control_dtb = fit_util.make_dtb(ubman, base_fdt, 'u-boot')
+ kernel = fit_util.make_kernel(ubman, 'test-kernel.bin', 'kernel')
ramdisk = make_ramdisk('test-ramdisk.bin', 'ramdisk')
- loadables1 = fit_util.make_kernel(cons, 'test-loadables1.bin', 'lenrek')
+ loadables1 = fit_util.make_kernel(ubman, 'test-loadables1.bin', 'lenrek')
loadables2 = make_ramdisk('test-loadables2.bin', 'ksidmar')
kernel_out = make_fname('kernel-out.bin')
fdt = make_fname('u-boot.dtb')
@@ -311,16 +311,16 @@ def test_fit(u_boot_console):
}
# Make a basic FIT and a script to load it
- fit = fit_util.make_fit(cons, mkimage, base_its, params)
+ fit = fit_util.make_fit(ubman, mkimage, base_its, params)
params['fit'] = fit
cmd = base_script % params
# First check that we can load a kernel
# We could perhaps reduce duplication with some loss of readability
- cons.config.dtb = control_dtb
- cons.restart_uboot()
- with cons.log.section('Kernel load'):
- output = cons.run_command_list(cmd.splitlines())
+ ubman.config.dtb = control_dtb
+ ubman.restart_uboot()
+ with ubman.log.section('Kernel load'):
+ output = ubman.run_command_list(cmd.splitlines())
check_equal(kernel, kernel_out, 'Kernel not loaded')
check_not_equal(control_dtb, fdt_out,
'FDT loaded but should be ignored')
@@ -340,7 +340,7 @@ def test_fit(u_boot_console):
(fit_offset, real_fit_offset))
# Check if bootargs strings substitution works
- output = cons.run_command_list([
+ output = ubman.run_command_list([
'env set bootargs \\\"\'my_boot_var=${foo}\'\\\"',
'env set foo bar',
'bootm prep',
@@ -348,63 +348,62 @@ def test_fit(u_boot_console):
assert 'bootargs="my_boot_var=bar"' in output, "Bootargs strings not substituted"
# Now a kernel and an FDT
- with cons.log.section('Kernel + FDT load'):
+ with ubman.log.section('Kernel + FDT load'):
params['fdt_load'] = 'load = <%#x>;' % params['fdt_addr']
- fit = fit_util.make_fit(cons, mkimage, base_its, params)
- cons.restart_uboot()
- output = cons.run_command_list(cmd.splitlines())
+ fit = fit_util.make_fit(ubman, mkimage, base_its, params)
+ ubman.restart_uboot()
+ output = ubman.run_command_list(cmd.splitlines())
check_equal(kernel, kernel_out, 'Kernel not loaded')
check_equal(control_dtb, fdt_out, 'FDT not loaded')
check_not_equal(ramdisk, ramdisk_out,
'Ramdisk loaded but should not be')
# Try a ramdisk
- with cons.log.section('Kernel + FDT + Ramdisk load'):
+ with ubman.log.section('Kernel + FDT + Ramdisk load'):
params['ramdisk_config'] = 'ramdisk = "ramdisk-1";'
params['ramdisk_load'] = 'load = <%#x>;' % params['ramdisk_addr']
- fit = fit_util.make_fit(cons, mkimage, base_its, params)
- cons.restart_uboot()
- output = cons.run_command_list(cmd.splitlines())
+ fit = fit_util.make_fit(ubman, mkimage, base_its, params)
+ ubman.restart_uboot()
+ output = ubman.run_command_list(cmd.splitlines())
check_equal(ramdisk, ramdisk_out, 'Ramdisk not loaded')
# Configuration with some Loadables
- with cons.log.section('Kernel + FDT + Ramdisk load + Loadables'):
+ with ubman.log.section('Kernel + FDT + Ramdisk load + Loadables'):
params['loadables_config'] = 'loadables = "kernel-2", "ramdisk-2";'
params['loadables1_load'] = ('load = <%#x>;' %
params['loadables1_addr'])
params['loadables2_load'] = ('load = <%#x>;' %
params['loadables2_addr'])
- fit = fit_util.make_fit(cons, mkimage, base_its, params)
- cons.restart_uboot()
- output = cons.run_command_list(cmd.splitlines())
+ fit = fit_util.make_fit(ubman, mkimage, base_its, params)
+ ubman.restart_uboot()
+ output = ubman.run_command_list(cmd.splitlines())
check_equal(loadables1, loadables1_out,
'Loadables1 (kernel) not loaded')
check_equal(loadables2, loadables2_out,
'Loadables2 (ramdisk) not loaded')
# Kernel, FDT and Ramdisk all compressed
- with cons.log.section('(Kernel + FDT + Ramdisk) compressed'):
+ with ubman.log.section('(Kernel + FDT + Ramdisk) compressed'):
params['compression'] = 'gzip'
params['kernel'] = make_compressed(kernel)
params['fdt'] = make_compressed(fdt)
params['ramdisk'] = make_compressed(ramdisk)
- fit = fit_util.make_fit(cons, mkimage, base_its, params)
- cons.restart_uboot()
- output = cons.run_command_list(cmd.splitlines())
+ fit = fit_util.make_fit(ubman, mkimage, base_its, params)
+ ubman.restart_uboot()
+ output = ubman.run_command_list(cmd.splitlines())
check_equal(kernel, kernel_out, 'Kernel not loaded')
check_equal(control_dtb, fdt_out, 'FDT not loaded')
check_not_equal(ramdisk, ramdisk_out, 'Ramdisk got decompressed?')
check_equal(ramdisk + '.gz', ramdisk_out, 'Ramdist not loaded')
- cons = u_boot_console
# We need to use our own device tree file. Remember to restore it
# afterwards.
- old_dtb = cons.config.dtb
+ old_dtb = ubman.config.dtb
try:
- mkimage = cons.config.build_dir + '/tools/mkimage'
+ mkimage = ubman.config.build_dir + '/tools/mkimage'
run_fit_test(mkimage)
finally:
# Go back to the original U-Boot with the correct dtb.
- cons.config.dtb = old_dtb
- cons.restart_uboot()
+ ubman.config.dtb = old_dtb
+ ubman.restart_uboot()
diff --git a/test/py/tests/test_fit_auto_signed.py b/test/py/tests/test_fit_auto_signed.py
index 9ea3351619f..cdfd341c6f5 100644
--- a/test/py/tests/test_fit_auto_signed.py
+++ b/test/py/tests/test_fit_auto_signed.py
@@ -17,7 +17,7 @@ The test does not run the sandbox. It only checks the host tool mkimage.
import os
import pytest
-import u_boot_utils as util
+import utils
import binascii
from Cryptodome.Hash import SHA1
from Cryptodome.Hash import SHA256
@@ -26,22 +26,22 @@ from Cryptodome.Signature import pkcs1_15
class SignedFitHelper(object):
"""Helper to manipulate a FIT with signed/hashed images/configs."""
- def __init__(self, cons, file_name):
+ def __init__(self, ubman, file_name):
self.fit = file_name
- self.cons = cons
+ self.ubman = ubman
self.images_nodes = set()
self.confgs_nodes = set()
def __fdt_list(self, path):
- return util.run_and_log(self.cons,
+ return utils.run_and_log(self.ubman,
f'fdtget -l {self.fit} {path}')
def __fdt_get_string(self, node, prop):
- return util.run_and_log(self.cons,
+ return utils.run_and_log(self.ubman,
f'fdtget -ts {self.fit} {node} {prop}')
def __fdt_get_binary(self, node, prop):
- numbers = util.run_and_log(self.cons,
+ numbers = utils.run_and_log(self.ubman,
f'fdtget -tbi {self.fit} {node} {prop}')
bignum = bytearray()
@@ -120,7 +120,7 @@ class SignedFitHelper(object):
@pytest.mark.buildconfigspec('fit_signature')
@pytest.mark.requiredtool('fdtget')
-def test_fit_auto_signed(u_boot_console):
+def test_fit_auto_signed(ubman):
"""Test that mkimage generates auto-FIT with signatures/hashes as expected.
The mkimage tool can create auto generated (i.e. without an ITS file
@@ -133,9 +133,8 @@ def test_fit_auto_signed(u_boot_console):
The test does not run the sandbox. It only checks the host tool mkimage.
"""
- cons = u_boot_console
- mkimage = cons.config.build_dir + '/tools/mkimage'
- tempdir = os.path.join(cons.config.result_dir, 'auto_fit')
+ mkimage = ubman.config.build_dir + '/tools/mkimage'
+ tempdir = os.path.join(ubman.config.result_dir, 'auto_fit')
os.makedirs(tempdir, exist_ok=True)
kernel_file = f'{tempdir}/vmlinuz'
dt1_file = f'{tempdir}/dt-1.dtb'
@@ -166,29 +165,29 @@ def test_fit_auto_signed(u_boot_console):
s_args = " -k" + tempdir + " -g" + key_name + " -o" + sign_algo
# 1 - Create auto FIT with images crc32 checksum, and verify it
- util.run_and_log(cons, mkimage + ' -fauto' + b_args + " " + fit_file)
+ utils.run_and_log(ubman, mkimage + ' -fauto' + b_args + " " + fit_file)
- fit = SignedFitHelper(cons, fit_file)
+ fit = SignedFitHelper(ubman, fit_file)
if fit.build_nodes_sets() == 0:
raise ValueError('FIT-1 has no "/image" nor "/configuration" nodes')
fit.check_fit_crc32_images()
# 2 - Create auto FIT with signed images, and verify it
- util.run_and_log(cons, mkimage + ' -fauto' + b_args + s_args + " " +
- fit_file)
+ utils.run_and_log(ubman, mkimage + ' -fauto' + b_args + s_args + " " +
+ fit_file)
- fit = SignedFitHelper(cons, fit_file)
+ fit = SignedFitHelper(ubman, fit_file)
if fit.build_nodes_sets() == 0:
raise ValueError('FIT-2 has no "/image" nor "/configuration" nodes')
fit.check_fit_signed_images(key_name, sign_algo, verifier)
# 3 - Create auto FIT with signed configs and hashed images, and verify it
- util.run_and_log(cons, mkimage + ' -fauto-conf' + b_args + s_args + " " +
- fit_file)
+ utils.run_and_log(ubman, mkimage + ' -fauto-conf' + b_args + s_args + " " +
+ fit_file)
- fit = SignedFitHelper(cons, fit_file)
+ fit = SignedFitHelper(ubman, fit_file)
if fit.build_nodes_sets() == 0:
raise ValueError('FIT-3 has no "/image" nor "/configuration" nodes')
diff --git a/test/py/tests/test_fit_ecdsa.py b/test/py/tests/test_fit_ecdsa.py
index cc6c0c4dc42..3e816d68eb6 100644
--- a/test/py/tests/test_fit_ecdsa.py
+++ b/test/py/tests/test_fit_ecdsa.py
@@ -12,27 +12,29 @@ This test doesn't run the sandbox. It only checks the host tool 'mkimage'
import os
import pytest
-import u_boot_utils as util
+import utils
from Cryptodome.Hash import SHA256
from Cryptodome.PublicKey import ECC
from Cryptodome.Signature import DSS
class SignableFitImage(object):
""" Helper to manipulate a FIT image on disk """
- def __init__(self, cons, file_name):
+ def __init__(self, ubman, file_name):
self.fit = file_name
- self.cons = cons
+ self.ubman = ubman
self.signable_nodes = set()
def __fdt_list(self, path):
- return util.run_and_log(self.cons, f'fdtget -l {self.fit} {path}')
+ return utils.run_and_log(self.ubman, f'fdtget -l {self.fit} {path}')
def __fdt_set(self, node, **prop_value):
for prop, value in prop_value.items():
- util.run_and_log(self.cons, f'fdtput -ts {self.fit} {node} {prop} {value}')
+ utils.run_and_log(self.ubman,
+ f'fdtput -ts {self.fit} {node} {prop} {value}')
def __fdt_get_binary(self, node, prop):
- numbers = util.run_and_log(self.cons, f'fdtget -tbi {self.fit} {node} {prop}')
+ numbers = utils.run_and_log(self.ubman,
+ f'fdtget -tbi {self.fit} {node} {prop}')
bignum = bytearray()
for little_num in numbers.split():
@@ -53,7 +55,7 @@ class SignableFitImage(object):
self.__fdt_set(f'{image}/signature', algo='sha256,ecdsa256')
def sign(self, mkimage, key_file):
- util.run_and_log(self.cons, [mkimage, '-F', self.fit, f'-G{key_file}'])
+ utils.run_and_log(self.ubman, [mkimage, '-F', self.fit, f'-G{key_file}'])
def check_signatures(self, key):
for image in self.signable_nodes:
@@ -69,23 +71,22 @@ class SignableFitImage(object):
@pytest.mark.requiredtool('dtc')
@pytest.mark.requiredtool('fdtget')
@pytest.mark.requiredtool('fdtput')
-def test_fit_ecdsa(u_boot_console):
+def test_fit_ecdsa(ubman):
""" Test that signatures generated by mkimage are legible. """
def generate_ecdsa_key():
return ECC.generate(curve='prime256v1')
def assemble_fit_image(dest_fit, its, destdir):
dtc_args = f'-I dts -O dtb -i {destdir}'
- util.run_and_log(cons, [mkimage, '-D', dtc_args, '-f', its, dest_fit])
+ utils.run_and_log(ubman, [mkimage, '-D', dtc_args, '-f', its, dest_fit])
def dtc(dts):
dtb = dts.replace('.dts', '.dtb')
- util.run_and_log(cons, f'dtc {datadir}/{dts} -O dtb -o {tempdir}/{dtb}')
+ utils.run_and_log(ubman, f'dtc {datadir}/{dts} -O dtb -o {tempdir}/{dtb}')
- cons = u_boot_console
- mkimage = cons.config.build_dir + '/tools/mkimage'
- datadir = cons.config.source_dir + '/test/py/tests/vboot/'
- tempdir = os.path.join(cons.config.result_dir, 'ecdsa')
+ mkimage = ubman.config.build_dir + '/tools/mkimage'
+ datadir = ubman.config.source_dir + '/test/py/tests/vboot/'
+ tempdir = os.path.join(ubman.config.result_dir, 'ecdsa')
os.makedirs(tempdir, exist_ok=True)
key_file = f'{tempdir}/ecdsa-test-key.pem'
fit_file = f'{tempdir}/test.fit'
@@ -103,7 +104,7 @@ def test_fit_ecdsa(u_boot_console):
assemble_fit_image(fit_file, f'{datadir}/sign-images-sha256.its', tempdir)
- fit = SignableFitImage(cons, fit_file)
+ fit = SignableFitImage(ubman, fit_file)
nodes = fit.find_signable_image_nodes()
if len(nodes) == 0:
raise ValueError('FIT image has no "/image" nodes with "signature"')
diff --git a/test/py/tests/test_fit_hashes.py b/test/py/tests/test_fit_hashes.py
index 4891e77ca2d..07bf0fd5211 100644
--- a/test/py/tests/test_fit_hashes.py
+++ b/test/py/tests/test_fit_hashes.py
@@ -12,7 +12,7 @@ This test doesn't run the sandbox. It only checks the host tool 'mkimage'
import os
import pytest
-import u_boot_utils as util
+import utils
kernel_hashes = {
"sha512" : "f18c1486a2c29f56360301576cdfce4dfd8e8e932d0ed8e239a1f314b8ae1d77b2a58cd7fe32e4075e69448e623ce53b0b6aa6ce5626d2c189a5beae29a68d93",
@@ -26,20 +26,21 @@ kernel_hashes = {
class ReadonlyFitImage(object):
""" Helper to manipulate a FIT image on disk """
- def __init__(self, cons, file_name):
+ def __init__(self, ubman, file_name):
self.fit = file_name
- self.cons = cons
+ self.ubman = ubman
self.hashable_nodes = set()
def __fdt_list(self, path):
- return util.run_and_log(self.cons, f'fdtget -l {self.fit} {path}')
+ return utils.run_and_log(self.ubman, f'fdtget -l {self.fit} {path}')
def __fdt_get(self, node, prop):
- val = util.run_and_log(self.cons, f'fdtget {self.fit} {node} {prop}')
+ val = utils.run_and_log(self.ubman, f'fdtget {self.fit} {node} {prop}')
return val.rstrip('\n')
def __fdt_get_sexadecimal(self, node, prop):
- numbers = util.run_and_log(self.cons, f'fdtget -tbx {self.fit} {node} {prop}')
+ numbers = utils.run_and_log(self.ubman,
+ f'fdtget -tbx {self.fit} {node} {prop}')
sexadecimal = ''
for num in numbers.rstrip('\n').split(' '):
@@ -80,21 +81,21 @@ class ReadonlyFitImage(object):
@pytest.mark.requiredtool('dtc')
@pytest.mark.requiredtool('fdtget')
@pytest.mark.requiredtool('fdtput')
-def test_mkimage_hashes(u_boot_console):
+def test_mkimage_hashes(ubman):
""" Test that hashes generated by mkimage are correct. """
def assemble_fit_image(dest_fit, its, destdir):
dtc_args = f'-I dts -O dtb -i {destdir}'
- util.run_and_log(cons, [mkimage, '-D', dtc_args, '-f', its, dest_fit])
+ utils.run_and_log(ubman, [mkimage, '-D', dtc_args, '-f', its, dest_fit])
def dtc(dts):
dtb = dts.replace('.dts', '.dtb')
- util.run_and_log(cons, f'dtc {datadir}/{dts} -O dtb -o {tempdir}/{dtb}')
+ utils.run_and_log(ubman,
+ f'dtc {datadir}/{dts} -O dtb -o {tempdir}/{dtb}')
- cons = u_boot_console
- mkimage = cons.config.build_dir + '/tools/mkimage'
- datadir = cons.config.source_dir + '/test/py/tests/vboot/'
- tempdir = os.path.join(cons.config.result_dir, 'hashes')
+ mkimage = ubman.config.build_dir + '/tools/mkimage'
+ datadir = ubman.config.source_dir + '/test/py/tests/vboot/'
+ tempdir = os.path.join(ubman.config.result_dir, 'hashes')
os.makedirs(tempdir, exist_ok=True)
fit_file = f'{tempdir}/test.fit'
@@ -106,7 +107,7 @@ def test_mkimage_hashes(u_boot_console):
assemble_fit_image(fit_file, f'{datadir}/hash-images.its', tempdir)
- fit = ReadonlyFitImage(cons, fit_file)
+ fit = ReadonlyFitImage(ubman, fit_file)
nodes = fit.find_hashable_image_nodes()
if len(nodes) == 0:
raise ValueError('FIT image has no "/image" nodes with "hash-..."')
diff --git a/test/py/tests/test_fpga.py b/test/py/tests/test_fpga.py
index ca7ef8ea40d..74cd42b910e 100644
--- a/test/py/tests/test_fpga.py
+++ b/test/py/tests/test_fpga.py
@@ -8,7 +8,7 @@
import pytest
import re
import random
-import u_boot_utils
+import utils
"""
Note: This test relies on boardenv_* containing configuration values to define
@@ -63,8 +63,8 @@ env__fpga_under_test = {
import test_net
-def check_dev(u_boot_console):
- f = u_boot_console.config.env.get('env__fpga_under_test', None)
+def check_dev(ubman):
+ f = ubman.config.env.get('env__fpga_under_test', None)
if not f:
pytest.skip('No FPGA to test')
@@ -74,20 +74,20 @@ def check_dev(u_boot_console):
return dev, f
-def load_file_from_var(u_boot_console, name):
- dev, f = check_dev(u_boot_console)
+def load_file_from_var(ubman, name):
+ dev, f = check_dev(ubman)
addr = f.get('addr', -1)
if addr < 0:
pytest.fail('No address specified via env__fpga_under_test')
- test_net.test_net_dhcp(u_boot_console)
- test_net.test_net_setup_static(u_boot_console)
+ test_net.test_net_dhcp(ubman)
+ test_net.test_net_setup_static(ubman)
bit = f['%s' % (name)]
bit_size = f['%s_size' % (name)]
expected_tftp = 'Bytes transferred = %d' % bit_size
- output = u_boot_console.run_command('tftpboot %x %s' % (addr, bit))
+ output = ubman.run_command('tftpboot %x %s' % (addr, bit))
assert expected_tftp in output
return f, dev, addr, bit, bit_size
@@ -97,158 +97,158 @@ expected_usage = 'fpga - loadable FPGA image support'
@pytest.mark.xfail
@pytest.mark.buildconfigspec('cmd_fpga')
-def test_fpga_fail(u_boot_console):
+def test_fpga_fail(ubman):
# Test non valid fpga subcommand
expected = 'fpga: non existing command'
- output = u_boot_console.run_command('fpga broken 0')
+ output = ubman.run_command('fpga broken 0')
#assert expected in output
assert expected_usage in output
@pytest.mark.buildconfigspec('cmd_fpga')
-def test_fpga_help(u_boot_console):
+def test_fpga_help(ubman):
# Just show help
- output = u_boot_console.run_command('fpga')
+ output = ubman.run_command('fpga')
assert expected_usage in output
###### FPGA DUMP tests ######
@pytest.mark.buildconfigspec('cmd_fpga')
-def test_fpga_dump(u_boot_console):
+def test_fpga_dump(ubman):
pytest.skip('Not implemented now')
@pytest.mark.buildconfigspec('cmd_fpga')
-def test_fpga_dump_variable(u_boot_console):
+def test_fpga_dump_variable(ubman):
# Same as above but via "fpga" variable
pytest.skip('Not implemented now')
###### FPGA INFO tests ######
@pytest.mark.buildconfigspec('cmd_fpga')
-def test_fpga_info_fail(u_boot_console):
+def test_fpga_info_fail(ubman):
# Maybe this can be skipped completely
- dev, f = check_dev(u_boot_console)
+ dev, f = check_dev(ubman)
# Multiple parameters to fpga info should fail
expected = 'fpga: more parameters passed'
- output = u_boot_console.run_command('fpga info 0 0')
+ output = ubman.run_command('fpga info 0 0')
#assert expected in output
assert expected_usage in output
@pytest.mark.buildconfigspec('cmd_fpga')
-def test_fpga_info_list(u_boot_console):
+def test_fpga_info_list(ubman):
# Maybe this can be skipped completely
- dev, f = check_dev(u_boot_console)
+ dev, f = check_dev(ubman)
# Code is design in a way that if fpga dev is not passed it should
# return list of all fpga devices in the system
- u_boot_console.run_command('setenv fpga')
- output = u_boot_console.run_command('fpga info')
+ ubman.run_command('setenv fpga')
+ output = ubman.run_command('fpga info')
assert expected_usage not in output
@pytest.mark.buildconfigspec('cmd_fpga')
-def test_fpga_info(u_boot_console):
- dev, f = check_dev(u_boot_console)
+def test_fpga_info(ubman):
+ dev, f = check_dev(ubman)
- output = u_boot_console.run_command('fpga info %x' % (dev))
+ output = ubman.run_command('fpga info %x' % (dev))
assert expected_usage not in output
@pytest.mark.buildconfigspec('cmd_fpga')
-def test_fpga_info_variable(u_boot_console):
- dev, f = check_dev(u_boot_console)
+def test_fpga_info_variable(ubman):
+ dev, f = check_dev(ubman)
#
# fpga variable is storing device number which doesn't need to be passed
#
- u_boot_console.run_command('setenv fpga %x' % (dev))
+ ubman.run_command('setenv fpga %x' % (dev))
- output = u_boot_console.run_command('fpga info')
+ output = ubman.run_command('fpga info')
# Variable cleanup
- u_boot_console.run_command('setenv fpga')
+ ubman.run_command('setenv fpga')
assert expected_usage not in output
###### FPGA LOAD tests ######
@pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_echo')
-def test_fpga_load_fail(u_boot_console):
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'bitstream_load')
+def test_fpga_load_fail(ubman):
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'bitstream_load')
for cmd in ['dump', 'load', 'loadb']:
# missing dev parameter
expected = 'fpga: incorrect parameters passed'
- output = u_boot_console.run_command('fpga %s %x $filesize' % (cmd, addr))
+ output = ubman.run_command('fpga %s %x $filesize' % (cmd, addr))
#assert expected in output
assert expected_usage in output
# more parameters - 0 at the end
expected = 'fpga: more parameters passed'
- output = u_boot_console.run_command('fpga %s %x %x $filesize 0' % (cmd, dev, addr))
+ output = ubman.run_command('fpga %s %x %x $filesize 0' % (cmd, dev, addr))
#assert expected in output
assert expected_usage in output
# 0 address
expected = 'fpga: zero fpga_data address'
- output = u_boot_console.run_command('fpga %s %x 0 $filesize' % (cmd, dev))
+ output = ubman.run_command('fpga %s %x 0 $filesize' % (cmd, dev))
#assert expected in output
assert expected_usage in output
# 0 filesize
expected = 'fpga: zero size'
- output = u_boot_console.run_command('fpga %s %x %x 0' % (cmd, dev, addr))
+ output = ubman.run_command('fpga %s %x %x 0' % (cmd, dev, addr))
#assert expected in output
assert expected_usage in output
@pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_echo')
-def test_fpga_load(u_boot_console):
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'bitstream_load')
+def test_fpga_load(ubman):
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'bitstream_load')
expected_text = 'FPGA loaded successfully'
- output = u_boot_console.run_command('fpga load %x %x $filesize && echo %s' % (dev, addr, expected_text))
+ output = ubman.run_command('fpga load %x %x $filesize && echo %s' % (dev, addr, expected_text))
assert expected_text in output
@pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_fpga_loadp')
@pytest.mark.buildconfigspec('cmd_echo')
-def test_fpga_loadp(u_boot_console):
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'bitstream_load')
+def test_fpga_loadp(ubman):
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'bitstream_load')
expected_text = 'FPGA loaded successfully'
- output = u_boot_console.run_command('fpga load %x %x $filesize && echo %s' % (dev, addr, expected_text))
+ output = ubman.run_command('fpga load %x %x $filesize && echo %s' % (dev, addr, expected_text))
assert expected_text in output
# And load also partial bistream
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'bitstream_loadp')
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'bitstream_loadp')
expected_text = 'FPGA loaded successfully'
- output = u_boot_console.run_command('fpga loadp %x %x $filesize && echo %s' % (dev, addr, expected_text))
+ output = ubman.run_command('fpga loadp %x %x $filesize && echo %s' % (dev, addr, expected_text))
assert expected_text in output
@pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_echo')
-def test_fpga_loadb(u_boot_console):
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'bitstream_loadb')
+def test_fpga_loadb(ubman):
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'bitstream_loadb')
expected_text = 'FPGA loaded successfully'
- output = u_boot_console.run_command('fpga loadb %x %x $filesize && echo %s' % (dev, addr, expected_text))
+ output = ubman.run_command('fpga loadb %x %x $filesize && echo %s' % (dev, addr, expected_text))
assert expected_text in output
@pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_fpga_loadbp')
@pytest.mark.buildconfigspec('cmd_echo')
-def test_fpga_loadbp(u_boot_console):
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'bitstream_loadb')
+def test_fpga_loadbp(ubman):
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'bitstream_loadb')
expected_text = 'FPGA loaded successfully'
- output = u_boot_console.run_command('fpga loadb %x %x $filesize && echo %s' % (dev, addr, expected_text))
+ output = ubman.run_command('fpga loadb %x %x $filesize && echo %s' % (dev, addr, expected_text))
assert expected_text in output
# And load also partial bistream in bit format
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'bitstream_loadbp')
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'bitstream_loadbp')
expected_text = 'FPGA loaded successfully'
- output = u_boot_console.run_command('fpga loadbp %x %x $filesize && echo %s' % (dev, addr, expected_text))
+ output = ubman.run_command('fpga loadbp %x %x $filesize && echo %s' % (dev, addr, expected_text))
assert expected_text in output
###### FPGA LOADMK tests ######
@@ -256,184 +256,184 @@ def test_fpga_loadbp(u_boot_console):
@pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_fpga_loadmk')
@pytest.mark.buildconfigspec('cmd_echo')
-@pytest.mark.buildconfigspec('image_format_legacy')
-def test_fpga_loadmk_fail(u_boot_console):
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_legacy')
+@pytest.mark.buildconfigspec('legacy_image_format')
+def test_fpga_loadmk_fail(ubman):
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'mkimage_legacy')
- u_boot_console.run_command('imi %x' % (addr))
+ ubman.run_command('imi %x' % (addr))
# load image but pass incorrect address to show error message
expected = 'Unknown image type'
- output = u_boot_console.run_command('fpga loadmk %x %x' % (dev, addr + 0x10))
+ output = ubman.run_command('fpga loadmk %x %x' % (dev, addr + 0x10))
assert expected in output
# Pass more parameters then command expects - 0 at the end
- output = u_boot_console.run_command('fpga loadmk %x %x 0' % (dev, addr))
+ output = ubman.run_command('fpga loadmk %x %x 0' % (dev, addr))
#assert expected in output
assert expected_usage in output
@pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_fpga_loadmk')
@pytest.mark.buildconfigspec('cmd_echo')
-@pytest.mark.buildconfigspec('image_format_legacy')
-def test_fpga_loadmk_legacy(u_boot_console):
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_legacy')
+@pytest.mark.buildconfigspec('legacy_image_format')
+def test_fpga_loadmk_legacy(ubman):
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'mkimage_legacy')
- u_boot_console.run_command('imi %x' % (addr))
+ ubman.run_command('imi %x' % (addr))
expected_text = 'FPGA loaded successfully'
- output = u_boot_console.run_command('fpga loadmk %x %x && echo %s' % (dev, addr, expected_text))
+ output = ubman.run_command('fpga loadmk %x %x && echo %s' % (dev, addr, expected_text))
assert expected_text in output
@pytest.mark.xfail
@pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_fpga_loadmk')
@pytest.mark.buildconfigspec('cmd_echo')
-@pytest.mark.buildconfigspec('image_format_legacy')
-def test_fpga_loadmk_legacy_variable_fpga(u_boot_console):
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_legacy')
+@pytest.mark.buildconfigspec('legacy_image_format')
+def test_fpga_loadmk_legacy_variable_fpga(ubman):
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'mkimage_legacy')
- u_boot_console.run_command('imi %x' % (addr))
+ ubman.run_command('imi %x' % (addr))
- u_boot_console.run_command('setenv fpga %x' % (dev))
+ ubman.run_command('setenv fpga %x' % (dev))
# this testcase should cover case which looks like it is supported but dev pointer is broken by loading mkimage address
expected_text = 'FPGA loaded successfully'
- output = u_boot_console.run_command('fpga loadmk %x && echo %s' % (addr, expected_text))
- u_boot_console.run_command('setenv fpga')
+ output = ubman.run_command('fpga loadmk %x && echo %s' % (addr, expected_text))
+ ubman.run_command('setenv fpga')
assert expected_text in output
@pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_fpga_loadmk')
@pytest.mark.buildconfigspec('cmd_echo')
-@pytest.mark.buildconfigspec('image_format_legacy')
-def test_fpga_loadmk_legacy_variable_fpgadata(u_boot_console):
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_legacy')
+@pytest.mark.buildconfigspec('legacy_image_format')
+def test_fpga_loadmk_legacy_variable_fpgadata(ubman):
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'mkimage_legacy')
- u_boot_console.run_command('imi %x' % (addr))
+ ubman.run_command('imi %x' % (addr))
- u_boot_console.run_command('setenv fpgadata %x' % (addr))
+ ubman.run_command('setenv fpgadata %x' % (addr))
# this testcase should cover case which looks like it is supported but dev pointer is broken by loading mkimage address
expected_text = 'FPGA loaded successfully'
- output = u_boot_console.run_command('fpga loadmk %x && echo %s' % (dev, expected_text))
- u_boot_console.run_command('setenv fpgadata')
+ output = ubman.run_command('fpga loadmk %x && echo %s' % (dev, expected_text))
+ ubman.run_command('setenv fpgadata')
assert expected_text in output
@pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_fpga_loadmk')
@pytest.mark.buildconfigspec('cmd_echo')
-@pytest.mark.buildconfigspec('image_format_legacy')
-def test_fpga_loadmk_legacy_variable(u_boot_console):
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_legacy')
+@pytest.mark.buildconfigspec('legacy_image_format')
+def test_fpga_loadmk_legacy_variable(ubman):
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'mkimage_legacy')
- u_boot_console.run_command('imi %x' % (addr))
+ ubman.run_command('imi %x' % (addr))
- u_boot_console.run_command('setenv fpga %x' % (dev))
- u_boot_console.run_command('setenv fpgadata %x' % (addr))
+ ubman.run_command('setenv fpga %x' % (dev))
+ ubman.run_command('setenv fpgadata %x' % (addr))
# this testcase should cover case which looks like it is supported but dev pointer is broken by loading mkimage address
expected_text = 'FPGA loaded successfully'
- output = u_boot_console.run_command('fpga loadmk && echo %s' % (expected_text))
- u_boot_console.run_command('setenv fpga')
- u_boot_console.run_command('setenv fpgadata')
+ output = ubman.run_command('fpga loadmk && echo %s' % (expected_text))
+ ubman.run_command('setenv fpga')
+ ubman.run_command('setenv fpgadata')
assert expected_text in output
@pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_fpga_loadmk')
@pytest.mark.buildconfigspec('cmd_echo')
-@pytest.mark.buildconfigspec('image_format_legacy')
+@pytest.mark.buildconfigspec('legacy_image_format')
@pytest.mark.buildconfigspec('gzip')
-def test_fpga_loadmk_legacy_gz(u_boot_console):
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_legacy_gz')
+def test_fpga_loadmk_legacy_gz(ubman):
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'mkimage_legacy_gz')
- u_boot_console.run_command('imi %x' % (addr))
+ ubman.run_command('imi %x' % (addr))
expected_text = 'FPGA loaded successfully'
- output = u_boot_console.run_command('fpga loadmk %x %x && echo %s' % (dev, addr, expected_text))
+ output = ubman.run_command('fpga loadmk %x %x && echo %s' % (dev, addr, expected_text))
assert expected_text in output
@pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_fpga_loadmk')
@pytest.mark.buildconfigspec('fit')
@pytest.mark.buildconfigspec('cmd_echo')
-def test_fpga_loadmk_fit_external(u_boot_console):
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_fit_external')
+def test_fpga_loadmk_fit_external(ubman):
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'mkimage_fit_external')
- u_boot_console.run_command('imi %x' % (addr))
+ ubman.run_command('imi %x' % (addr))
expected_text = 'FPGA loaded successfully'
- output = u_boot_console.run_command('fpga loadmk %x %x:fpga && echo %s' % (dev, addr, expected_text))
+ output = ubman.run_command('fpga loadmk %x %x:fpga && echo %s' % (dev, addr, expected_text))
assert expected_text in output
@pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_fpga_loadmk')
@pytest.mark.buildconfigspec('fit')
@pytest.mark.buildconfigspec('cmd_echo')
-def test_fpga_loadmk_fit(u_boot_console):
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_fit')
+def test_fpga_loadmk_fit(ubman):
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'mkimage_fit')
- u_boot_console.run_command('imi %x' % (addr))
+ ubman.run_command('imi %x' % (addr))
expected_text = 'FPGA loaded successfully'
- output = u_boot_console.run_command('fpga loadmk %x %x:fpga && echo %s' % (dev, addr, expected_text))
+ output = ubman.run_command('fpga loadmk %x %x:fpga && echo %s' % (dev, addr, expected_text))
assert expected_text in output
@pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_fpga_loadmk')
@pytest.mark.buildconfigspec('fit')
@pytest.mark.buildconfigspec('cmd_echo')
-def test_fpga_loadmk_fit_variable_fpga(u_boot_console):
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_fit')
+def test_fpga_loadmk_fit_variable_fpga(ubman):
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'mkimage_fit')
- u_boot_console.run_command('imi %x' % (addr))
+ ubman.run_command('imi %x' % (addr))
# FIXME this should fail - broken support in past
- u_boot_console.run_command('setenv fpga %x' % (dev))
+ ubman.run_command('setenv fpga %x' % (dev))
expected_text = 'FPGA loaded successfully'
- output = u_boot_console.run_command('fpga loadmk %x:fpga && echo %s' % (addr, expected_text))
- u_boot_console.run_command('setenv fpga')
+ output = ubman.run_command('fpga loadmk %x:fpga && echo %s' % (addr, expected_text))
+ ubman.run_command('setenv fpga')
assert expected_text in output
@pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_fpga_loadmk')
@pytest.mark.buildconfigspec('fit')
@pytest.mark.buildconfigspec('cmd_echo')
-def test_fpga_loadmk_fit_variable_fpgadata(u_boot_console):
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_fit')
+def test_fpga_loadmk_fit_variable_fpgadata(ubman):
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'mkimage_fit')
- u_boot_console.run_command('imi %x' % (addr))
+ ubman.run_command('imi %x' % (addr))
# FIXME this should fail - broken support in past
- u_boot_console.run_command('setenv fpgadata %x:fpga' % (addr))
+ ubman.run_command('setenv fpgadata %x:fpga' % (addr))
expected_text = 'FPGA loaded successfully'
- output = u_boot_console.run_command('fpga loadmk %x && echo %s' % (dev, expected_text))
- u_boot_console.run_command('setenv fpgadata')
+ output = ubman.run_command('fpga loadmk %x && echo %s' % (dev, expected_text))
+ ubman.run_command('setenv fpgadata')
assert expected_text in output
@pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_fpga_loadmk')
@pytest.mark.buildconfigspec('fit')
@pytest.mark.buildconfigspec('cmd_echo')
-def test_fpga_loadmk_fit_variable(u_boot_console):
- f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_fit')
+def test_fpga_loadmk_fit_variable(ubman):
+ f, dev, addr, bit, bit_size = load_file_from_var(ubman, 'mkimage_fit')
- u_boot_console.run_command('imi %x' % (addr))
+ ubman.run_command('imi %x' % (addr))
- u_boot_console.run_command('setenv fpga %x' % (dev))
- u_boot_console.run_command('setenv fpgadata %x:fpga' % (addr))
+ ubman.run_command('setenv fpga %x' % (dev))
+ ubman.run_command('setenv fpgadata %x:fpga' % (addr))
expected_text = 'FPGA loaded successfully'
- output = u_boot_console.run_command('fpga loadmk && echo %s' % (expected_text))
- u_boot_console.run_command('setenv fpga')
- u_boot_console.run_command('setenv fpgadata')
+ output = ubman.run_command('fpga loadmk && echo %s' % (expected_text))
+ ubman.run_command('setenv fpga')
+ ubman.run_command('setenv fpgadata')
assert expected_text in output
###### FPGA LOAD tests ######
@pytest.mark.buildconfigspec('cmd_fpga')
-def test_fpga_loadfs_fail(u_boot_console):
- dev, f = check_dev(u_boot_console)
+def test_fpga_loadfs_fail(ubman):
+ dev, f = check_dev(ubman)
addr = f.get('addr', -1)
if addr < 0:
@@ -445,49 +445,49 @@ def test_fpga_loadfs_fail(u_boot_console):
# less params - dev number removed
expected = 'fpga: incorrect parameters passed'
- output = u_boot_console.run_command('fpga loadfs %x %x %x %s' % (addr, bit_size, block_size, bit))
+ output = ubman.run_command('fpga loadfs %x %x %x %s' % (addr, bit_size, block_size, bit))
#assert expected in output
assert expected_usage in output
# one more param - 0 at the end
# This is the longest command that's why there is no message from cmd/fpga.c
- output = u_boot_console.run_command('fpga loadfs %x %x %x %x %s 0' % (dev, addr, bit_size, block_size, bit))
+ output = ubman.run_command('fpga loadfs %x %x %x %x %s 0' % (dev, addr, bit_size, block_size, bit))
assert expected_usage in output
# zero address 0
expected = 'fpga: zero fpga_data address'
- output = u_boot_console.run_command('fpga loadfs %x %x %x %x %s' % (dev, 0, bit_size, block_size, bit))
+ output = ubman.run_command('fpga loadfs %x %x %x %x %s' % (dev, 0, bit_size, block_size, bit))
#assert expected in output
assert expected_usage in output
# bit_size 0
expected = 'fpga: zero size'
- output = u_boot_console.run_command('fpga loadfs %x %x %x %x %s' % (dev, addr, 0, block_size, bit))
+ output = ubman.run_command('fpga loadfs %x %x %x %x %s' % (dev, addr, 0, block_size, bit))
#assert expected in output
assert expected_usage in output
# block size 0
# FIXME this should pass but it failing too
- output = u_boot_console.run_command('fpga loadfs %x %x %x %x %s' % (dev, addr, bit_size, 0, bit))
+ output = ubman.run_command('fpga loadfs %x %x %x %x %s' % (dev, addr, bit_size, 0, bit))
assert expected_usage in output
# non existing bitstream name
expected = 'Unable to read file noname'
- output = u_boot_console.run_command('fpga loadfs %x %x %x %x mmc 0 noname' % (dev, addr, bit_size, block_size))
+ output = ubman.run_command('fpga loadfs %x %x %x %x mmc 0 noname' % (dev, addr, bit_size, block_size))
assert expected in output
assert expected_usage in output
# -1 dev number
expected = 'fpga_fsload: Invalid device number -1'
- output = u_boot_console.run_command('fpga loadfs %d %x %x %x mmc 0 noname' % (-1, addr, bit_size, block_size))
+ output = ubman.run_command('fpga loadfs %d %x %x %x mmc 0 noname' % (-1, addr, bit_size, block_size))
assert expected in output
assert expected_usage in output
@pytest.mark.buildconfigspec('cmd_fpga')
@pytest.mark.buildconfigspec('cmd_echo')
-def test_fpga_loadfs(u_boot_console):
- dev, f = check_dev(u_boot_console)
+def test_fpga_loadfs(ubman):
+ dev, f = check_dev(ubman)
addr = f.get('addr', -1)
if addr < 0:
@@ -499,7 +499,7 @@ def test_fpga_loadfs(u_boot_console):
# This should be done better
expected_text = 'FPGA loaded successfully'
- output = u_boot_console.run_command('fpga loadfs %x %x %x %x %s && echo %s' % (dev, addr, bit_size, block_size, bit, expected_text))
+ output = ubman.run_command('fpga loadfs %x %x %x %x %s && echo %s' % (dev, addr, bit_size, block_size, bit, expected_text))
assert expected_text in output
@pytest.mark.buildconfigspec('cmd_fpga')
@@ -507,26 +507,26 @@ def test_fpga_loadfs(u_boot_console):
@pytest.mark.buildconfigspec('cmd_net')
@pytest.mark.buildconfigspec('cmd_dhcp')
@pytest.mark.buildconfigspec('net')
-def test_fpga_secure_bit_auth(u_boot_console):
+def test_fpga_secure_bit_auth(ubman):
- test_net.test_net_dhcp(u_boot_console)
- test_net.test_net_setup_static(u_boot_console)
+ test_net.test_net_dhcp(ubman)
+ test_net.test_net_setup_static(ubman)
- f = u_boot_console.config.env.get('env__fpga_secure_readable_file', None)
+ f = ubman.config.env.get('env__fpga_secure_readable_file', None)
if not f:
pytest.skip('No TFTP readable file to read')
addr = f.get('addr', None)
if not addr:
- addr = u_boot_utils.find_ram_base(u_boot_console)
+ addr = utils.find_ram_base(ubman)
expected_tftp = 'Bytes transferred = '
fn = f['fn']
- output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn))
+ output = ubman.run_command('tftpboot %x %s' % (addr, fn))
assert expected_tftp in output
expected_zynqmpsecure = 'Bitstream successfully loaded'
- output = u_boot_console.run_command('fpga loads 0 %x $filesize 0 2' % (addr))
+ output = ubman.run_command('fpga loads 0 %x $filesize 0 2' % (addr))
assert expected_zynqmpsecure in output
@@ -535,31 +535,31 @@ def test_fpga_secure_bit_auth(u_boot_console):
@pytest.mark.buildconfigspec('cmd_net')
@pytest.mark.buildconfigspec('cmd_dhcp')
@pytest.mark.buildconfigspec('net')
-def test_fpga_secure_bit_img_auth_kup(u_boot_console):
+def test_fpga_secure_bit_img_auth_kup(ubman):
- test_net.test_net_dhcp(u_boot_console)
- test_net.test_net_setup_static(u_boot_console)
+ test_net.test_net_dhcp(ubman)
+ test_net.test_net_setup_static(ubman)
- f = u_boot_console.config.env.get('env__fpga_secure_readable_file', None)
+ f = ubman.config.env.get('env__fpga_secure_readable_file', None)
if not f:
pytest.skip('No TFTP readable file to read')
keyaddr = f.get('keyaddr', None)
if not keyaddr:
- addr = u_boot_utils.find_ram_base(u_boot_console)
+ addr = utils.find_ram_base(ubman)
expected_tftp = 'Bytes transferred = '
keyfn = f['keyfn']
- output = u_boot_console.run_command('tftpboot %x %s' % (keyaddr, keyfn))
+ output = ubman.run_command('tftpboot %x %s' % (keyaddr, keyfn))
assert expected_tftp in output
addr = f.get('addr', None)
if not addr:
- addr = u_boot_utils.find_ram_base(u_boot_console)
+ addr = utils.find_ram_base(ubman)
expected_tftp = 'Bytes transferred = '
fn = f['enckupfn']
- output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn))
+ output = ubman.run_command('tftpboot %x %s' % (addr, fn))
assert expected_tftp in output
expected_zynqmpsecure = 'Bitstream successfully loaded'
- output = u_boot_console.run_command('fpga loads 0 %x $filesize 0 1 %x' % (addr, keyaddr))
+ output = ubman.run_command('fpga loads 0 %x $filesize 0 1 %x' % (addr, keyaddr))
assert expected_zynqmpsecure in output
diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py
index fca54488374..0205048e73a 100644
--- a/test/py/tests/test_fs/conftest.py
+++ b/test/py/tests/test_fs/conftest.py
@@ -8,16 +8,16 @@ import pytest
import re
from subprocess import call, check_call, check_output, CalledProcessError
from fstest_defs import *
-import u_boot_utils as util
# pylint: disable=E0611
from tests import fs_helper
-supported_fs_basic = ['fat16', 'fat32', 'ext4']
-supported_fs_ext = ['fat12', 'fat16', 'fat32']
+supported_fs_basic = ['fat16', 'fat32', 'exfat', 'ext4', 'fs_generic']
+supported_fs_ext = ['fat12', 'fat16', 'fat32', 'exfat', 'fs_generic']
supported_fs_fat = ['fat12', 'fat16']
-supported_fs_mkdir = ['fat12', 'fat16', 'fat32']
-supported_fs_unlink = ['fat12', 'fat16', 'fat32']
+supported_fs_mkdir = ['fat12', 'fat16', 'fat32', 'exfat', 'fs_generic']
+supported_fs_unlink = ['fat12', 'fat16', 'fat32', 'exfat', 'fs_generic']
supported_fs_symlink = ['ext4']
+supported_fs_rename = ['fat12', 'fat16', 'fat32', 'exfat', 'fs_generic']
#
# Filesystem test specific setup
@@ -55,6 +55,7 @@ def pytest_configure(config):
global supported_fs_mkdir
global supported_fs_unlink
global supported_fs_symlink
+ global supported_fs_rename
def intersect(listA, listB):
return [x for x in listA if x in listB]
@@ -68,6 +69,7 @@ def pytest_configure(config):
supported_fs_mkdir = intersect(supported_fs, supported_fs_mkdir)
supported_fs_unlink = intersect(supported_fs, supported_fs_unlink)
supported_fs_symlink = intersect(supported_fs, supported_fs_symlink)
+ supported_fs_rename = intersect(supported_fs, supported_fs_rename)
def pytest_generate_tests(metafunc):
"""Parametrize fixtures, fs_obj_xxx
@@ -99,10 +101,29 @@ def pytest_generate_tests(metafunc):
if 'fs_obj_symlink' in metafunc.fixturenames:
metafunc.parametrize('fs_obj_symlink', supported_fs_symlink,
indirect=True, scope='module')
+ if 'fs_obj_rename' in metafunc.fixturenames:
+ metafunc.parametrize('fs_obj_rename', supported_fs_rename,
+ indirect=True, scope='module')
#
# Helper functions
#
+def fstype_to_prefix(fs_type):
+ """Convert a file system type to an U-Boot command prefix
+
+ Args:
+ fs_type: File system type.
+
+ Return:
+ A corresponding command prefix for file system type.
+ """
+ if fs_type == 'fs_generic' or fs_type == 'exfat':
+ return ''
+ elif re.match('fat', fs_type):
+ return 'fat'
+ else:
+ return fs_type
+
def fstype_to_ubname(fs_type):
"""Convert a file system type to an U-Boot specific string
@@ -134,8 +155,12 @@ def check_ubconfig(config, fs_type):
Return:
Nothing.
"""
- if not config.buildconfig.get('config_cmd_%s' % fs_type, None):
+ if fs_type == 'exfat' and not config.buildconfig.get('config_fs_%s' % fs_type, None):
+ pytest.skip('.config feature "FS_%s" not enabled' % fs_type.upper())
+ if fs_type != 'exfat' and not config.buildconfig.get('config_cmd_%s' % fs_type, None):
pytest.skip('.config feature "CMD_%s" not enabled' % fs_type.upper())
+ if fs_type == 'fs_generic' or fs_type == 'exfat':
+ return
if not config.buildconfig.get('config_%s_write' % fs_type, None):
pytest.skip('.config feature "%s_WRITE" not enabled'
% fs_type.upper())
@@ -156,64 +181,6 @@ def tool_is_in_path(tool):
return True
return False
-fuse_mounted = False
-
-def mount_fs(fs_type, device, mount_point):
- """Mount a volume.
-
- Args:
- fs_type: File system type.
- device: Volume's file name.
- mount_point: Mount point.
-
- Return:
- Nothing.
- """
- global fuse_mounted
-
- try:
- check_call('guestmount --pid-file guestmount.pid -a %s -m /dev/sda %s'
- % (device, mount_point), shell=True)
- fuse_mounted = True
- return
- except CalledProcessError:
- fuse_mounted = False
-
- mount_opt = 'loop,rw'
- if re.match('fat', fs_type):
- mount_opt += ',umask=0000'
-
- check_call('sudo mount -o %s %s %s'
- % (mount_opt, device, mount_point), shell=True)
-
- # may not be effective for some file systems
- check_call('sudo chmod a+rw %s' % mount_point, shell=True)
-
-def umount_fs(mount_point):
- """Unmount a volume.
-
- Args:
- mount_point: Mount point.
-
- Return:
- Nothing.
- """
- if fuse_mounted:
- call('sync')
- call('guestunmount %s' % mount_point, shell=True)
-
- try:
- with open("guestmount.pid", "r") as pidfile:
- pid = int(pidfile.read())
- util.waitpid(pid, kill=True)
- os.remove("guestmount.pid")
-
- except FileNotFoundError:
- pass
-
- else:
- call('sudo umount %s' % mount_point, shell=True)
-
#
# Fixture for basic fs test
# derived from test/fs/fs-test.sh
@@ -231,43 +198,28 @@ def fs_obj_basic(request, u_boot_config):
volume file name and a list of MD5 hashes.
"""
fs_type = request.param
+ fs_cmd_prefix = fstype_to_prefix(fs_type)
+ fs_cmd_write = 'save' if fs_type == 'fs_generic' or fs_type == 'exfat' else 'write'
fs_img = ''
fs_ubtype = fstype_to_ubname(fs_type)
check_ubconfig(u_boot_config, fs_ubtype)
- mount_dir = u_boot_config.persistent_data_dir + '/mnt'
+ scratch_dir = u_boot_config.persistent_data_dir + '/scratch'
- small_file = mount_dir + '/' + SMALL_FILE
- big_file = mount_dir + '/' + BIG_FILE
-
- try:
-
- # 3GiB volume
- fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB')
- except CalledProcessError as err:
- pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
- return
+ small_file = scratch_dir + '/' + SMALL_FILE
+ big_file = scratch_dir + '/' + BIG_FILE
try:
- check_call('mkdir -p %s' % mount_dir, shell=True)
+ check_call('mkdir -p %s' % scratch_dir, shell=True)
except CalledProcessError as err:
pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err))
call('rm -f %s' % fs_img, shell=True)
return
try:
- # Mount the image so we can populate it.
- mount_fs(fs_type, fs_img, mount_dir)
- except CalledProcessError as err:
- pytest.skip('Mounting to folder failed for filesystem: ' + fs_type + '. {}'.format(err))
- call('rmdir %s' % mount_dir, shell=True)
- call('rm -f %s' % fs_img, shell=True)
- return
-
- try:
# Create a subdirectory.
- check_call('mkdir %s/SUBDIR' % mount_dir, shell=True)
+ check_call('mkdir %s/SUBDIR' % scratch_dir, shell=True)
# Create big file in this image.
# Note that we work only on the start 1MB, couple MBs in the 2GB range
@@ -326,15 +278,20 @@ def fs_obj_basic(request, u_boot_config):
% big_file, shell=True).decode()
md5val.append(out.split()[0])
+ try:
+ # 3GiB volume
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB', scratch_dir)
+ except CalledProcessError as err:
+ pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
+ return
+
except CalledProcessError as err:
pytest.skip('Setup failed for filesystem: ' + fs_type + '. {}'.format(err))
- umount_fs(mount_dir)
return
else:
- umount_fs(mount_dir)
- yield [fs_ubtype, fs_img, md5val]
+ yield [fs_ubtype, fs_cmd_prefix, fs_cmd_write, fs_img, md5val]
finally:
- call('rmdir %s' % mount_dir, shell=True)
+ call('rm -rf %s' % scratch_dir, shell=True)
call('rm -f %s' % fs_img, shell=True)
#
@@ -353,43 +310,28 @@ def fs_obj_ext(request, u_boot_config):
volume file name and a list of MD5 hashes.
"""
fs_type = request.param
+ fs_cmd_prefix = fstype_to_prefix(fs_type)
+ fs_cmd_write = 'save' if fs_type == 'fs_generic' or fs_type == 'exfat' else 'write'
fs_img = ''
fs_ubtype = fstype_to_ubname(fs_type)
check_ubconfig(u_boot_config, fs_ubtype)
- mount_dir = u_boot_config.persistent_data_dir + '/mnt'
+ scratch_dir = u_boot_config.persistent_data_dir + '/scratch'
- min_file = mount_dir + '/' + MIN_FILE
- tmp_file = mount_dir + '/tmpfile'
+ min_file = scratch_dir + '/' + MIN_FILE
+ tmp_file = scratch_dir + '/tmpfile'
try:
-
- # 128MiB volume
- fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
- except CalledProcessError as err:
- pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
- return
-
- try:
- check_call('mkdir -p %s' % mount_dir, shell=True)
+ check_call('mkdir -p %s' % scratch_dir, shell=True)
except CalledProcessError as err:
pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err))
call('rm -f %s' % fs_img, shell=True)
return
try:
- # Mount the image so we can populate it.
- mount_fs(fs_type, fs_img, mount_dir)
- except CalledProcessError as err:
- pytest.skip('Mounting to folder failed for filesystem: ' + fs_type + '. {}'.format(err))
- call('rmdir %s' % mount_dir, shell=True)
- call('rm -f %s' % fs_img, shell=True)
- return
-
- try:
# Create a test directory
- check_call('mkdir %s/dir1' % mount_dir, shell=True)
+ check_call('mkdir %s/dir1' % scratch_dir, shell=True)
# Create a small file and calculate md5
check_call('dd if=/dev/urandom of=%s bs=1K count=20'
@@ -427,15 +369,21 @@ def fs_obj_ext(request, u_boot_config):
md5val.append(out.split()[0])
check_call('rm %s' % tmp_file, shell=True)
+
+ try:
+ # 128MiB volume
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', scratch_dir)
+ except CalledProcessError as err:
+ pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
+ return
+
except CalledProcessError:
pytest.skip('Setup failed for filesystem: ' + fs_type)
- umount_fs(mount_dir)
return
else:
- umount_fs(mount_dir)
- yield [fs_ubtype, fs_img, md5val]
+ yield [fs_ubtype, fs_cmd_prefix, fs_cmd_write, fs_img, md5val]
finally:
- call('rmdir %s' % mount_dir, shell=True)
+ call('rm -rf %s' % scratch_dir, shell=True)
call('rm -f %s' % fs_img, shell=True)
#
@@ -454,6 +402,7 @@ def fs_obj_mkdir(request, u_boot_config):
volume file name.
"""
fs_type = request.param
+ fs_cmd_prefix = fstype_to_prefix(fs_type)
fs_img = ''
fs_ubtype = fstype_to_ubname(fs_type)
@@ -461,12 +410,12 @@ def fs_obj_mkdir(request, u_boot_config):
try:
# 128MiB volume
- fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', None)
except:
pytest.skip('Setup failed for filesystem: ' + fs_type)
return
else:
- yield [fs_ubtype, fs_img]
+ yield [fs_ubtype, fs_cmd_prefix, fs_img]
call('rm -f %s' % fs_img, shell=True)
#
@@ -485,68 +434,57 @@ def fs_obj_unlink(request, u_boot_config):
volume file name.
"""
fs_type = request.param
+ fs_cmd_prefix = fstype_to_prefix(fs_type)
fs_img = ''
fs_ubtype = fstype_to_ubname(fs_type)
check_ubconfig(u_boot_config, fs_ubtype)
- mount_dir = u_boot_config.persistent_data_dir + '/mnt'
+ scratch_dir = u_boot_config.persistent_data_dir + '/scratch'
try:
-
- # 128MiB volume
- fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
- except CalledProcessError as err:
- pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
- return
-
- try:
- check_call('mkdir -p %s' % mount_dir, shell=True)
+ check_call('mkdir -p %s' % scratch_dir, shell=True)
except CalledProcessError as err:
pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err))
call('rm -f %s' % fs_img, shell=True)
return
try:
- # Mount the image so we can populate it.
- mount_fs(fs_type, fs_img, mount_dir)
- except CalledProcessError as err:
- pytest.skip('Mounting to folder failed for filesystem: ' + fs_type + '. {}'.format(err))
- call('rmdir %s' % mount_dir, shell=True)
- call('rm -f %s' % fs_img, shell=True)
- return
-
- try:
# Test Case 1 & 3
- check_call('mkdir %s/dir1' % mount_dir, shell=True)
+ check_call('mkdir %s/dir1' % scratch_dir, shell=True)
check_call('dd if=/dev/urandom of=%s/dir1/file1 bs=1K count=1'
- % mount_dir, shell=True)
+ % scratch_dir, shell=True)
check_call('dd if=/dev/urandom of=%s/dir1/file2 bs=1K count=1'
- % mount_dir, shell=True)
+ % scratch_dir, shell=True)
# Test Case 2
- check_call('mkdir %s/dir2' % mount_dir, shell=True)
+ check_call('mkdir %s/dir2' % scratch_dir, shell=True)
for i in range(0, 20):
check_call('mkdir %s/dir2/0123456789abcdef%02x'
- % (mount_dir, i), shell=True)
+ % (scratch_dir, i), shell=True)
# Test Case 4
- check_call('mkdir %s/dir4' % mount_dir, shell=True)
+ check_call('mkdir %s/dir4' % scratch_dir, shell=True)
# Test Case 5, 6 & 7
- check_call('mkdir %s/dir5' % mount_dir, shell=True)
+ check_call('mkdir %s/dir5' % scratch_dir, shell=True)
check_call('dd if=/dev/urandom of=%s/dir5/file1 bs=1K count=1'
- % mount_dir, shell=True)
+ % scratch_dir, shell=True)
+
+ try:
+ # 128MiB volume
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', scratch_dir)
+ except CalledProcessError as err:
+ pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
+ return
except CalledProcessError:
pytest.skip('Setup failed for filesystem: ' + fs_type)
- umount_fs(mount_dir)
return
else:
- umount_fs(mount_dir)
- yield [fs_ubtype, fs_img]
+ yield [fs_ubtype, fs_cmd_prefix, fs_img]
finally:
- call('rmdir %s' % mount_dir, shell=True)
+ call('rm -rf %s' % scratch_dir, shell=True)
call('rm -f %s' % fs_img, shell=True)
#
@@ -570,38 +508,21 @@ def fs_obj_symlink(request, u_boot_config):
fs_ubtype = fstype_to_ubname(fs_type)
check_ubconfig(u_boot_config, fs_ubtype)
- mount_dir = u_boot_config.persistent_data_dir + '/mnt'
-
- small_file = mount_dir + '/' + SMALL_FILE
- medium_file = mount_dir + '/' + MEDIUM_FILE
-
- try:
+ scratch_dir = u_boot_config.persistent_data_dir + '/scratch'
- # 1GiB volume
- fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x40000000, '1GB')
- except CalledProcessError as err:
- pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
- return
+ small_file = scratch_dir + '/' + SMALL_FILE
+ medium_file = scratch_dir + '/' + MEDIUM_FILE
try:
- check_call('mkdir -p %s' % mount_dir, shell=True)
+ check_call('mkdir -p %s' % scratch_dir, shell=True)
except CalledProcessError as err:
pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err))
call('rm -f %s' % fs_img, shell=True)
return
try:
- # Mount the image so we can populate it.
- mount_fs(fs_type, fs_img, mount_dir)
- except CalledProcessError as err:
- pytest.skip('Mounting to folder failed for filesystem: ' + fs_type + '. {}'.format(err))
- call('rmdir %s' % mount_dir, shell=True)
- call('rm -f %s' % fs_img, shell=True)
- return
-
- try:
# Create a subdirectory.
- check_call('mkdir %s/SUBDIR' % mount_dir, shell=True)
+ check_call('mkdir %s/SUBDIR' % scratch_dir, shell=True)
# Create a small file in this image.
check_call('dd if=/dev/urandom of=%s bs=1M count=1'
@@ -621,15 +542,135 @@ def fs_obj_symlink(request, u_boot_config):
% medium_file, shell=True).decode()
md5val.extend([out.split()[0]])
+ try:
+ # 1GiB volume
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x40000000, '1GB', scratch_dir)
+ except CalledProcessError as err:
+ pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
+ return
+
+ except CalledProcessError:
+ pytest.skip('Setup failed for filesystem: ' + fs_type)
+ return
+ else:
+ yield [fs_ubtype, fs_img, md5val]
+ finally:
+ call('rm -rf %s' % scratch_dir, shell=True)
+ call('rm -f %s' % fs_img, shell=True)
+
+#
+# Fixture for rename test
+#
+@pytest.fixture()
+def fs_obj_rename(request, u_boot_config):
+ """Set up a file system to be used in rename tests.
+
+ Args:
+ request: Pytest request object.
+ u_boot_config: U-Boot configuration.
+
+ Return:
+ A fixture for rename tests, i.e. a triplet of file system type,
+ volume file name, and dictionary of test identifier and md5val.
+ """
+ def new_rand_file(path):
+ check_call('dd if=/dev/urandom of=%s bs=1K count=1' % path, shell=True)
+
+ def file_hash(path):
+ out = check_output(
+ 'dd if=%s bs=1K skip=0 count=1 2> /dev/null | md5sum' % path,
+ shell=True
+ )
+ return out.decode().split()[0]
+
+ fs_type = request.param
+ fs_img = ''
+
+ fs_ubtype = fstype_to_ubname(fs_type)
+ check_ubconfig(u_boot_config, fs_ubtype)
+
+ mount_dir = u_boot_config.persistent_data_dir + '/scratch'
+
+ try:
+ check_call('mkdir -p %s' % mount_dir, shell=True)
+ except CalledProcessError as err:
+ pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err))
+ call('rm -f %s' % fs_img, shell=True)
+ return
+
+ try:
+ md5val = {}
+ # Test Case 1
+ check_call('mkdir %s/test1' % mount_dir, shell=True)
+ new_rand_file('%s/test1/file1' % mount_dir)
+ md5val['test1'] = file_hash('%s/test1/file1' % mount_dir)
+
+ # Test Case 2
+ check_call('mkdir %s/test2' % mount_dir, shell=True)
+ new_rand_file('%s/test2/file1' % mount_dir)
+ new_rand_file('%s/test2/file_exist' % mount_dir)
+ md5val['test2'] = file_hash('%s/test2/file1' % mount_dir)
+
+ # Test Case 3
+ check_call('mkdir -p %s/test3/dir1' % mount_dir, shell=True)
+ new_rand_file('%s/test3/dir1/file1' % mount_dir)
+ md5val['test3'] = file_hash('%s/test3/dir1/file1' % mount_dir)
+
+ # Test Case 4
+ check_call('mkdir -p %s/test4/dir1' % mount_dir, shell=True)
+ check_call('mkdir -p %s/test4/dir2/dir1' % mount_dir, shell=True)
+ new_rand_file('%s/test4/dir1/file1' % mount_dir)
+ md5val['test4'] = file_hash('%s/test4/dir1/file1' % mount_dir)
+
+ # Test Case 5
+ check_call('mkdir -p %s/test5/dir1' % mount_dir, shell=True)
+ new_rand_file('%s/test5/file2' % mount_dir)
+ md5val['test5'] = file_hash('%s/test5/file2' % mount_dir)
+
+ # Test Case 6
+ check_call('mkdir -p %s/test6/dir2/existing' % mount_dir, shell=True)
+ new_rand_file('%s/test6/existing' % mount_dir)
+ md5val['test6'] = file_hash('%s/test6/existing' % mount_dir)
+
+ # Test Case 7
+ check_call('mkdir -p %s/test7/dir1' % mount_dir, shell=True)
+ check_call('mkdir -p %s/test7/dir2/dir1' % mount_dir, shell=True)
+ new_rand_file('%s/test7/dir2/dir1/file1' % mount_dir)
+ md5val['test7'] = file_hash('%s/test7/dir2/dir1/file1' % mount_dir)
+
+ # Test Case 8
+ check_call('mkdir -p %s/test8/dir1' % mount_dir, shell=True)
+ new_rand_file('%s/test8/dir1/file1' % mount_dir)
+ md5val['test8'] = file_hash('%s/test8/dir1/file1' % mount_dir)
+
+ # Test Case 9
+ check_call('mkdir -p %s/test9/dir1/nested/inner' % mount_dir, shell=True)
+ new_rand_file('%s/test9/dir1/nested/inner/file1' % mount_dir)
+
+ # Test Case 10
+ check_call('mkdir -p %s/test10' % mount_dir, shell=True)
+ new_rand_file('%s/test10/file1' % mount_dir)
+ md5val['test10'] = file_hash('%s/test10/file1' % mount_dir)
+
+ # Test Case 11
+ check_call('mkdir -p %s/test11/dir1' % mount_dir, shell=True)
+ new_rand_file('%s/test11/dir1/file1' % mount_dir)
+ md5val['test11'] = file_hash('%s/test11/dir1/file1' % mount_dir)
+
+ try:
+ # 128MiB volume
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', mount_dir)
+ except CalledProcessError as err:
+ pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
+ return
+
except CalledProcessError:
pytest.skip('Setup failed for filesystem: ' + fs_type)
- umount_fs(mount_dir)
return
else:
- umount_fs(mount_dir)
yield [fs_ubtype, fs_img, md5val]
finally:
- call('rmdir %s' % mount_dir, shell=True)
+ call('rm -rf %s' % mount_dir, shell=True)
call('rm -f %s' % fs_img, shell=True)
#
@@ -665,7 +706,7 @@ def fs_obj_fat(request, u_boot_config):
try:
# the volume size depends on the filesystem
- fs_img = fs_helper.mk_fs(u_boot_config, fs_type, fs_size, f'{fs_size}', 1024)
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, fs_size, f'{fs_size}', None, 1024)
except:
pytest.skip('Setup failed for filesystem: ' + fs_type)
return
diff --git a/test/py/tests/test_fs/fstest_helpers.py b/test/py/tests/test_fs/fstest_helpers.py
index faec2982489..d25326ee993 100644
--- a/test/py/tests/test_fs/fstest_helpers.py
+++ b/test/py/tests/test_fs/fstest_helpers.py
@@ -9,5 +9,9 @@ def assert_fs_integrity(fs_type, fs_img):
try:
if fs_type == 'ext4':
check_call('fsck.ext4 -n -f %s' % fs_img, shell=True)
+ elif fs_type == 'exfat':
+ check_call('fsck.exfat -n %s' % fs_img, shell=True)
+ elif fs_type in ['fat12', 'fat16', 'fat32']:
+ check_call('fsck.fat -n %s' % fs_img, shell=True)
except CalledProcessError:
raise
diff --git a/test/py/tests/test_fs/test_basic.py b/test/py/tests/test_fs/test_basic.py
index 71f3e86fb18..88b163ce305 100644
--- a/test/py/tests/test_fs/test_basic.py
+++ b/test/py/tests/test_fs/test_basic.py
@@ -16,276 +16,287 @@ from fstest_helpers import assert_fs_integrity
@pytest.mark.boardspec('sandbox')
@pytest.mark.slow
class TestFsBasic(object):
- def test_fs1(self, u_boot_console, fs_obj_basic):
+ def test_fs1(self, ubman, fs_obj_basic):
"""
Test Case 1 - ls command, listing a root directory and invalid directory
"""
- fs_type,fs_img,md5val = fs_obj_basic
- with u_boot_console.log.section('Test Case 1a - ls'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic
+ with ubman.log.section('Test Case 1a - ls'):
# Test Case 1 - ls
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%sls host 0:0' % fs_type])
+ '%sls host 0:0' % fs_cmd_prefix])
assert(re.search('2621440000 *%s' % BIG_FILE, ''.join(output)))
assert(re.search('1048576 *%s' % SMALL_FILE, ''.join(output)))
- with u_boot_console.log.section('Test Case 1b - ls (invalid dir)'):
+ with ubman.log.section('Test Case 1b - ls (invalid dir)'):
# In addition, test with a nonexistent directory to see if we crash.
- output = u_boot_console.run_command(
- '%sls host 0:0 invalid_d' % fs_type)
- if fs_type == 'ext4':
- assert('Can not find directory' in output)
- else:
- assert('' == output)
+ output = ubman.run_command(
+ '%sls host 0:0 invalid_d' % fs_cmd_prefix)
+ assert('' == output)
- def test_fs2(self, u_boot_console, fs_obj_basic):
+ with ubman.log.section('Test Case 1c - test -e'):
+ # Test Case 1 - test -e
+ output = ubman.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'test -e host 0:0 1MB.file && echo PASS'])
+ assert('PASS' in ''.join(output))
+
+ with ubman.log.section('Test Case 1d - test -e (invalid file)'):
+ # In addition, test with a nonexistent file to see if we crash.
+ output = ubman.run_command(
+ 'test -e host 0:0 2MB.file || echo PASS')
+ assert('PASS' in ''.join(output))
+
+ def test_fs2(self, ubman, fs_obj_basic):
"""
Test Case 2 - size command for a small file
"""
- fs_type,fs_img,md5val = fs_obj_basic
- with u_boot_console.log.section('Test Case 2a - size (small)'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic
+ with ubman.log.section('Test Case 2a - size (small)'):
# 1MB is 0x0010 0000
# Test Case 2a - size of small file
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%ssize host 0:0 /%s' % (fs_type, SMALL_FILE),
+ '%ssize host 0:0 /%s' % (fs_cmd_prefix, SMALL_FILE),
'printenv filesize',
'setenv filesize'])
assert('filesize=100000' in ''.join(output))
- with u_boot_console.log.section('Test Case 2b - size (/../<file>)'):
+ with ubman.log.section('Test Case 2b - size (/../<file>)'):
# Test Case 2b - size of small file via a path using '..'
- output = u_boot_console.run_command_list([
- '%ssize host 0:0 /SUBDIR/../%s' % (fs_type, SMALL_FILE),
+ output = ubman.run_command_list([
+ '%ssize host 0:0 /SUBDIR/../%s' % (fs_cmd_prefix, SMALL_FILE),
'printenv filesize',
'setenv filesize'])
assert('filesize=100000' in ''.join(output))
- def test_fs3(self, u_boot_console, fs_obj_basic):
+ def test_fs3(self, ubman, fs_obj_basic):
"""
Test Case 3 - size command for a large file
"""
- fs_type,fs_img,md5val = fs_obj_basic
- with u_boot_console.log.section('Test Case 3 - size (large)'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic
+ with ubman.log.section('Test Case 3 - size (large)'):
# 2.5GB (1024*1024*2500) is 0x9C40 0000
# Test Case 3 - size of big file
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%ssize host 0:0 /%s' % (fs_type, BIG_FILE),
+ '%ssize host 0:0 /%s' % (fs_cmd_prefix, BIG_FILE),
'printenv filesize',
'setenv filesize'])
assert('filesize=9c400000' in ''.join(output))
- def test_fs4(self, u_boot_console, fs_obj_basic):
+ def test_fs4(self, ubman, fs_obj_basic):
"""
Test Case 4 - load a small file, 1MB
"""
- fs_type,fs_img,md5val = fs_obj_basic
- with u_boot_console.log.section('Test Case 4 - load (small)'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic
+ with ubman.log.section('Test Case 4 - load (small)'):
# Test Case 4a - Read full 1MB of small file
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE),
+ '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, SMALL_FILE),
'printenv filesize'])
assert('filesize=100000' in ''.join(output))
# Test Case 4b - Read full 1MB of small file
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[0] in ''.join(output))
- def test_fs5(self, u_boot_console, fs_obj_basic):
+ def test_fs5(self, ubman, fs_obj_basic):
"""
Test Case 5 - load, reading first 1MB of 3GB file
"""
- fs_type,fs_img,md5val = fs_obj_basic
- with u_boot_console.log.section('Test Case 5 - load (first 1MB)'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic
+ with ubman.log.section('Test Case 5 - load (first 1MB)'):
# Test Case 5a - First 1MB of big file
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%sload host 0:0 %x /%s %x 0x0' % (fs_type, ADDR, BIG_FILE, LENGTH),
+ '%sload host 0:0 %x /%s %x 0x0' % (fs_cmd_prefix, ADDR, BIG_FILE, LENGTH),
'printenv filesize'])
assert('filesize=100000' in ''.join(output))
# Test Case 5b - First 1MB of big file
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[1] in ''.join(output))
- def test_fs6(self, u_boot_console, fs_obj_basic):
+ def test_fs6(self, ubman, fs_obj_basic):
"""
Test Case 6 - load, reading last 1MB of 3GB file
"""
- fs_type,fs_img,md5val = fs_obj_basic
- with u_boot_console.log.section('Test Case 6 - load (last 1MB)'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic
+ with ubman.log.section('Test Case 6 - load (last 1MB)'):
# fails for ext as no offset support
# Test Case 6a - Last 1MB of big file
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s %x 0x9c300000'
- % (fs_type, ADDR, BIG_FILE, LENGTH),
+ % (fs_cmd_prefix, ADDR, BIG_FILE, LENGTH),
'printenv filesize'])
assert('filesize=100000' in ''.join(output))
# Test Case 6b - Last 1MB of big file
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[2] in ''.join(output))
- def test_fs7(self, u_boot_console, fs_obj_basic):
+ def test_fs7(self, ubman, fs_obj_basic):
"""
Test Case 7 - load, 1MB from the last 1MB in 2GB
"""
- fs_type,fs_img,md5val = fs_obj_basic
- with u_boot_console.log.section('Test Case 7 - load (last 1MB in 2GB)'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic
+ with ubman.log.section('Test Case 7 - load (last 1MB in 2GB)'):
# fails for ext as no offset support
# Test Case 7a - One from the last 1MB chunk of 2GB
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s %x 0x7ff00000'
- % (fs_type, ADDR, BIG_FILE, LENGTH),
+ % (fs_cmd_prefix, ADDR, BIG_FILE, LENGTH),
'printenv filesize'])
assert('filesize=100000' in ''.join(output))
# Test Case 7b - One from the last 1MB chunk of 2GB
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[3] in ''.join(output))
- def test_fs8(self, u_boot_console, fs_obj_basic):
+ def test_fs8(self, ubman, fs_obj_basic):
"""
Test Case 8 - load, reading first 1MB in 2GB
"""
- fs_type,fs_img,md5val = fs_obj_basic
- with u_boot_console.log.section('Test Case 8 - load (first 1MB in 2GB)'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic
+ with ubman.log.section('Test Case 8 - load (first 1MB in 2GB)'):
# fails for ext as no offset support
# Test Case 8a - One from the start 1MB chunk from 2GB
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s %x 0x80000000'
- % (fs_type, ADDR, BIG_FILE, LENGTH),
+ % (fs_cmd_prefix, ADDR, BIG_FILE, LENGTH),
'printenv filesize'])
assert('filesize=100000' in ''.join(output))
# Test Case 8b - One from the start 1MB chunk from 2GB
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[4] in ''.join(output))
- def test_fs9(self, u_boot_console, fs_obj_basic):
+ def test_fs9(self, ubman, fs_obj_basic):
"""
Test Case 9 - load, 1MB crossing 2GB boundary
"""
- fs_type,fs_img,md5val = fs_obj_basic
- with u_boot_console.log.section('Test Case 9 - load (crossing 2GB boundary)'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic
+ with ubman.log.section('Test Case 9 - load (crossing 2GB boundary)'):
# fails for ext as no offset support
# Test Case 9a - One 1MB chunk crossing the 2GB boundary
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s %x 0x7ff80000'
- % (fs_type, ADDR, BIG_FILE, LENGTH),
+ % (fs_cmd_prefix, ADDR, BIG_FILE, LENGTH),
'printenv filesize'])
assert('filesize=100000' in ''.join(output))
# Test Case 9b - One 1MB chunk crossing the 2GB boundary
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[5] in ''.join(output))
- def test_fs10(self, u_boot_console, fs_obj_basic):
+ def test_fs10(self, ubman, fs_obj_basic):
"""
Test Case 10 - load, reading beyond file end'):
"""
- fs_type,fs_img,md5val = fs_obj_basic
- with u_boot_console.log.section('Test Case 10 - load (beyond file end)'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic
+ with ubman.log.section('Test Case 10 - load (beyond file end)'):
# Generic failure case
# Test Case 10 - 2MB chunk from the last 1MB of big file
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
'%sload host 0:0 %x /%s 0x00200000 0x9c300000'
- % (fs_type, ADDR, BIG_FILE),
+ % (fs_cmd_prefix, ADDR, BIG_FILE),
'printenv filesize',
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert('filesize=100000' in ''.join(output))
- def test_fs11(self, u_boot_console, fs_obj_basic):
+ def test_fs11(self, ubman, fs_obj_basic):
"""
Test Case 11 - write'
"""
- fs_type,fs_img,md5val = fs_obj_basic
- with u_boot_console.log.section('Test Case 11 - write'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic
+ with ubman.log.section('Test Case 11 - write'):
# Read 1MB from small file
# Write it back to test the writes
# Test Case 11a - Check that the write succeeded
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE),
- '%swrite host 0:0 %x /%s.w $filesize'
- % (fs_type, ADDR, SMALL_FILE)])
+ '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, SMALL_FILE),
+ '%s%s host 0:0 %x /%s.w $filesize'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, SMALL_FILE)])
assert('1048576 bytes written' in ''.join(output))
# Test Case 11b - Check md5 of written to is same
# as the one read from
- output = u_boot_console.run_command_list([
- '%sload host 0:0 %x /%s.w' % (fs_type, ADDR, SMALL_FILE),
+ output = ubman.run_command_list([
+ '%sload host 0:0 %x /%s.w' % (fs_cmd_prefix, ADDR, SMALL_FILE),
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[0] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_fs12(self, u_boot_console, fs_obj_basic):
+ def test_fs12(self, ubman, fs_obj_basic):
"""
Test Case 12 - write to "." directory
"""
- fs_type,fs_img,md5val = fs_obj_basic
- with u_boot_console.log.section('Test Case 12 - write (".")'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic
+ with ubman.log.section('Test Case 12 - write (".")'):
# Next test case checks writing a file whose dirent
# is the first in the block, which is always true for "."
# The write should fail, but the lookup should work
# Test Case 12 - Check directory traversal
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%swrite host 0:0 %x /. 0x10' % (fs_type, ADDR)])
+ '%s%s host 0:0 %x /. 0x10'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR)])
assert('Unable to write' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_fs13(self, u_boot_console, fs_obj_basic):
+ def test_fs13(self, ubman, fs_obj_basic):
"""
Test Case 13 - write to a file with "/./<filename>"
"""
- fs_type,fs_img,md5val = fs_obj_basic
- with u_boot_console.log.section('Test Case 13 - write ("./<file>")'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic
+ with ubman.log.section('Test Case 13 - write ("./<file>")'):
# Read 1MB from small file
# Write it via "same directory", i.e. "." dirent
# Test Case 13a - Check directory traversal
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE),
- '%swrite host 0:0 %x /./%s2 $filesize'
- % (fs_type, ADDR, SMALL_FILE)])
+ '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, SMALL_FILE),
+ '%s%s host 0:0 %x /./%s2 $filesize'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, SMALL_FILE)])
assert('1048576 bytes written' in ''.join(output))
# Test Case 13b - Check md5 of written to is same
# as the one read from
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'mw.b %x 00 100' % ADDR,
- '%sload host 0:0 %x /./%s2' % (fs_type, ADDR, SMALL_FILE),
+ '%sload host 0:0 %x /./%s2' % (fs_cmd_prefix, ADDR, SMALL_FILE),
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[0] in ''.join(output))
# Test Case 13c - Check md5 of written to is same
# as the one read from
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'mw.b %x 00 100' % ADDR,
- '%sload host 0:0 %x /%s2' % (fs_type, ADDR, SMALL_FILE),
+ '%sload host 0:0 %x /%s2' % (fs_cmd_prefix, ADDR, SMALL_FILE),
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[0] in ''.join(output))
diff --git a/test/py/tests/test_fs/test_erofs.py b/test/py/tests/test_fs/test_erofs.py
index 87ad8f2d5fd..a2bb6b505f2 100644
--- a/test/py/tests/test_fs/test_erofs.py
+++ b/test/py/tests/test_fs/test_erofs.py
@@ -65,64 +65,64 @@ def clean_erofs_image(build_dir):
image_path = os.path.join(build_dir, EROFS_IMAGE_NAME)
os.remove(image_path)
-def erofs_ls_at_root(u_boot_console):
+def erofs_ls_at_root(ubman):
"""
Test if all the present files and directories were listed.
"""
- no_slash = u_boot_console.run_command('erofsls host 0')
- slash = u_boot_console.run_command('erofsls host 0 /')
+ no_slash = ubman.run_command('erofsls host 0')
+ slash = ubman.run_command('erofsls host 0 /')
assert no_slash == slash
expected_lines = ['./', '../', '4096 f4096', '7812 f7812', 'subdir/',
'<SYM> symdir', '<SYM> symfile', '4 file(s), 3 dir(s)']
- output = u_boot_console.run_command('erofsls host 0')
+ output = ubman.run_command('erofsls host 0')
for line in expected_lines:
assert line in output
-def erofs_ls_at_subdir(u_boot_console):
+def erofs_ls_at_subdir(ubman):
"""
Test if the path resolution works.
"""
expected_lines = ['./', '../', '100 subdir-file', '1 file(s), 2 dir(s)']
- output = u_boot_console.run_command('erofsls host 0 subdir')
+ output = ubman.run_command('erofsls host 0 subdir')
for line in expected_lines:
assert line in output
-def erofs_ls_at_symlink(u_boot_console):
+def erofs_ls_at_symlink(ubman):
"""
Test if the symbolic link's target resolution works.
"""
- output = u_boot_console.run_command('erofsls host 0 symdir')
- output_subdir = u_boot_console.run_command('erofsls host 0 subdir')
+ output = ubman.run_command('erofsls host 0 symdir')
+ output_subdir = ubman.run_command('erofsls host 0 subdir')
assert output == output_subdir
expected_lines = ['./', '../', '100 subdir-file', '1 file(s), 2 dir(s)']
for line in expected_lines:
assert line in output
-def erofs_ls_at_non_existent_dir(u_boot_console):
+def erofs_ls_at_non_existent_dir(ubman):
"""
Test if the EROFS support will crash when get a nonexistent directory.
"""
- out_non_existent = u_boot_console.run_command('erofsls host 0 fff')
- out_not_dir = u_boot_console.run_command('erofsls host 0 f1000')
+ out_non_existent = ubman.run_command('erofsls host 0 fff')
+ out_not_dir = ubman.run_command('erofsls host 0 f1000')
assert out_non_existent == out_not_dir
assert '' in out_non_existent
-def erofs_load_files(u_boot_console, files, sizes, address):
+def erofs_load_files(ubman, files, sizes, address):
"""
Loads files and asserts their checksums.
"""
- build_dir = u_boot_console.config.build_dir
+ build_dir = ubman.config.build_dir
for (file, size) in zip(files, sizes):
- out = u_boot_console.run_command('erofsload host 0 {} {}'.format(address, file))
+ out = ubman.run_command('erofsload host 0 {} {}'.format(address, file))
# check if the right amount of bytes was read
assert size in out
# calculate u-boot file's checksum
- out = u_boot_console.run_command('md5sum {} {}'.format(address, hex(int(size))))
+ out = ubman.run_command('md5sum {} {}'.format(address, hex(int(size))))
u_boot_checksum = out.split()[-1]
# calculate original file's checksum
@@ -134,54 +134,54 @@ def erofs_load_files(u_boot_console, files, sizes, address):
# compare checksum
assert u_boot_checksum == original_checksum
-def erofs_load_files_at_root(u_boot_console):
+def erofs_load_files_at_root(ubman):
"""
Test load file from the root directory.
"""
files = ['f4096', 'f7812']
sizes = ['4096', '7812']
address = '$kernel_addr_r'
- erofs_load_files(u_boot_console, files, sizes, address)
+ erofs_load_files(ubman, files, sizes, address)
-def erofs_load_files_at_subdir(u_boot_console):
+def erofs_load_files_at_subdir(ubman):
"""
Test load file from the subdirectory.
"""
files = ['subdir/subdir-file']
sizes = ['100']
address = '$kernel_addr_r'
- erofs_load_files(u_boot_console, files, sizes, address)
+ erofs_load_files(ubman, files, sizes, address)
-def erofs_load_files_at_symlink(u_boot_console):
+def erofs_load_files_at_symlink(ubman):
"""
Test load file from the symlink.
"""
files = ['symfile']
sizes = ['7812']
address = '$kernel_addr_r'
- erofs_load_files(u_boot_console, files, sizes, address)
+ erofs_load_files(ubman, files, sizes, address)
-def erofs_load_non_existent_file(u_boot_console):
+def erofs_load_non_existent_file(ubman):
"""
Test if the EROFS support will crash when load a nonexistent file.
"""
address = '$kernel_addr_r'
file = 'non-existent'
- out = u_boot_console.run_command('erofsload host 0 {} {}'.format(address, file))
+ out = ubman.run_command('erofsload host 0 {} {}'.format(address, file))
assert 'Failed to load' in out
-def erofs_run_all_tests(u_boot_console):
+def erofs_run_all_tests(ubman):
"""
Runs all test cases.
"""
- erofs_ls_at_root(u_boot_console)
- erofs_ls_at_subdir(u_boot_console)
- erofs_ls_at_symlink(u_boot_console)
- erofs_ls_at_non_existent_dir(u_boot_console)
- erofs_load_files_at_root(u_boot_console)
- erofs_load_files_at_subdir(u_boot_console)
- erofs_load_files_at_symlink(u_boot_console)
- erofs_load_non_existent_file(u_boot_console)
+ erofs_ls_at_root(ubman)
+ erofs_ls_at_subdir(ubman)
+ erofs_ls_at_symlink(ubman)
+ erofs_ls_at_non_existent_dir(ubman)
+ erofs_load_files_at_root(ubman)
+ erofs_load_files_at_subdir(ubman)
+ erofs_load_files_at_symlink(ubman)
+ erofs_load_non_existent_file(ubman)
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_fs_generic')
@@ -190,11 +190,11 @@ def erofs_run_all_tests(u_boot_console):
@pytest.mark.requiredtool('mkfs.erofs')
@pytest.mark.requiredtool('md5sum')
-def test_erofs(u_boot_console):
+def test_erofs(ubman):
"""
Executes the erofs test suite.
"""
- build_dir = u_boot_console.config.build_dir
+ build_dir = ubman.config.build_dir
# If the EFI subsystem is enabled and initialized, EFI subsystem tries to
# add EFI boot option when the new disk is detected. If there is no EFI
@@ -203,15 +203,15 @@ def test_erofs(u_boot_console):
# Restart U-Boot to clear the previous state.
# TODO: Ideally EFI test cases need to be fixed, but it will
# increase the number of system reset.
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
try:
# setup test environment
make_erofs_image(build_dir)
image_path = os.path.join(build_dir, EROFS_IMAGE_NAME)
- u_boot_console.run_command('host bind 0 {}'.format(image_path))
+ ubman.run_command('host bind 0 {}'.format(image_path))
# run all tests
- erofs_run_all_tests(u_boot_console)
+ erofs_run_all_tests(ubman)
except:
clean_erofs_image(build_dir)
raise AssertionError
diff --git a/test/py/tests/test_fs/test_ext.py b/test/py/tests/test_fs/test_ext.py
index 05fefa53a0e..41f126e7876 100644
--- a/test/py/tests/test_fs/test_ext.py
+++ b/test/py/tests/test_fs/test_ext.py
@@ -29,327 +29,335 @@ def str2fat(long_filename):
@pytest.mark.boardspec('sandbox')
@pytest.mark.slow
class TestFsExt(object):
- def test_fs_ext1(self, u_boot_console, fs_obj_ext):
+ def test_fs_ext1(self, ubman, fs_obj_ext):
"""
Test Case 1 - write a file with absolute path
"""
- fs_type,fs_img,md5val = fs_obj_ext
- with u_boot_console.log.section('Test Case 1 - write with abs path'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext
+ with ubman.log.section('Test Case 1 - write with abs path'):
# Test Case 1a - Check if command successfully returned
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
- '%swrite host 0:0 %x /dir1/%s.w1 $filesize'
- % (fs_type, ADDR, MIN_FILE)])
+ '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE),
+ '%s%s host 0:0 %x /dir1/%s.w1 $filesize'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)])
assert('20480 bytes written' in ''.join(output))
# Test Case 1b - Check md5 of file content
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'mw.b %x 00 100' % ADDR,
- '%sload host 0:0 %x /dir1/%s.w1' % (fs_type, ADDR, MIN_FILE),
+ '%sload host 0:0 %x /dir1/%s.w1' % (fs_cmd_prefix, ADDR, MIN_FILE),
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[0] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_fs_ext2(self, u_boot_console, fs_obj_ext):
+ def test_fs_ext2(self, ubman, fs_obj_ext):
"""
Test Case 2 - write to a file with relative path
"""
- fs_type,fs_img,md5val = fs_obj_ext
- with u_boot_console.log.section('Test Case 2 - write with rel path'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext
+ with ubman.log.section('Test Case 2 - write with rel path'):
# Test Case 2a - Check if command successfully returned
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
- '%swrite host 0:0 %x dir1/%s.w2 $filesize'
- % (fs_type, ADDR, MIN_FILE)])
+ '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE),
+ '%s%s host 0:0 %x dir1/%s.w2 $filesize'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)])
assert('20480 bytes written' in ''.join(output))
# Test Case 2b - Check md5 of file content
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'mw.b %x 00 100' % ADDR,
- '%sload host 0:0 %x dir1/%s.w2' % (fs_type, ADDR, MIN_FILE),
+ '%sload host 0:0 %x dir1/%s.w2' % (fs_cmd_prefix, ADDR, MIN_FILE),
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[0] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_fs_ext3(self, u_boot_console, fs_obj_ext):
+ def test_fs_ext3(self, ubman, fs_obj_ext):
"""
Test Case 3 - write to a file with invalid path
"""
- fs_type,fs_img,md5val = fs_obj_ext
- with u_boot_console.log.section('Test Case 3 - write with invalid path'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext
+ with ubman.log.section('Test Case 3 - write with invalid path'):
# Test Case 3 - Check if command expectedly failed
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
- '%swrite host 0:0 %x /dir1/none/%s.w3 $filesize'
- % (fs_type, ADDR, MIN_FILE)])
+ '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE),
+ '%s%s host 0:0 %x /dir1/none/%s.w3 $filesize'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)])
assert('Unable to write file /dir1/none/' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_fs_ext4(self, u_boot_console, fs_obj_ext):
+ def test_fs_ext4(self, ubman, fs_obj_ext):
"""
Test Case 4 - write at non-zero offset, enlarging file size
"""
- fs_type,fs_img,md5val = fs_obj_ext
- with u_boot_console.log.section('Test Case 4 - write at non-zero offset, enlarging file size'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext
+ with ubman.log.section('Test Case 4 - write at non-zero offset, enlarging file size'):
# Test Case 4a - Check if command successfully returned
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
- '%swrite host 0:0 %x /dir1/%s.w4 $filesize'
- % (fs_type, ADDR, MIN_FILE)])
- output = u_boot_console.run_command(
- '%swrite host 0:0 %x /dir1/%s.w4 $filesize 0x1400'
- % (fs_type, ADDR, MIN_FILE))
+ '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE),
+ '%s%s host 0:0 %x /dir1/%s.w4 $filesize'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)])
+ output = ubman.run_command(
+ '%s%s host 0:0 %x /dir1/%s.w4 $filesize 0x1400'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE))
assert('20480 bytes written' in output)
# Test Case 4b - Check size of written file
- output = u_boot_console.run_command_list([
- '%ssize host 0:0 /dir1/%s.w4' % (fs_type, MIN_FILE),
+ output = ubman.run_command_list([
+ '%ssize host 0:0 /dir1/%s.w4' % (fs_cmd_prefix, MIN_FILE),
'printenv filesize',
'setenv filesize'])
assert('filesize=6400' in ''.join(output))
# Test Case 4c - Check md5 of file content
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'mw.b %x 00 100' % ADDR,
- '%sload host 0:0 %x /dir1/%s.w4' % (fs_type, ADDR, MIN_FILE),
+ '%sload host 0:0 %x /dir1/%s.w4' % (fs_cmd_prefix, ADDR, MIN_FILE),
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[1] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_fs_ext5(self, u_boot_console, fs_obj_ext):
+ def test_fs_ext5(self, ubman, fs_obj_ext):
"""
Test Case 5 - write at non-zero offset, shrinking file size
"""
- fs_type,fs_img,md5val = fs_obj_ext
- with u_boot_console.log.section('Test Case 5 - write at non-zero offset, shrinking file size'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext
+ with ubman.log.section('Test Case 5 - write at non-zero offset, shrinking file size'):
# Test Case 5a - Check if command successfully returned
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
- '%swrite host 0:0 %x /dir1/%s.w5 $filesize'
- % (fs_type, ADDR, MIN_FILE)])
- output = u_boot_console.run_command(
- '%swrite host 0:0 %x /dir1/%s.w5 0x1400 0x1400'
- % (fs_type, ADDR, MIN_FILE))
+ '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE),
+ '%s%s host 0:0 %x /dir1/%s.w5 $filesize'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)])
+ output = ubman.run_command(
+ '%s%s host 0:0 %x /dir1/%s.w5 0x1400 0x1400'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE))
assert('5120 bytes written' in output)
# Test Case 5b - Check size of written file
- output = u_boot_console.run_command_list([
- '%ssize host 0:0 /dir1/%s.w5' % (fs_type, MIN_FILE),
+ output = ubman.run_command_list([
+ '%ssize host 0:0 /dir1/%s.w5' % (fs_cmd_prefix, MIN_FILE),
'printenv filesize',
'setenv filesize'])
assert('filesize=2800' in ''.join(output))
# Test Case 5c - Check md5 of file content
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'mw.b %x 00 100' % ADDR,
- '%sload host 0:0 %x /dir1/%s.w5' % (fs_type, ADDR, MIN_FILE),
+ '%sload host 0:0 %x /dir1/%s.w5' % (fs_cmd_prefix, ADDR, MIN_FILE),
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[2] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_fs_ext6(self, u_boot_console, fs_obj_ext):
+ def test_fs_ext6(self, ubman, fs_obj_ext):
"""
Test Case 6 - write nothing at the start, truncating to zero
"""
- fs_type,fs_img,md5val = fs_obj_ext
- with u_boot_console.log.section('Test Case 6 - write nothing at the start, truncating to zero'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext
+ with ubman.log.section('Test Case 6 - write nothing at the start, truncating to zero'):
# Test Case 6a - Check if command successfully returned
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
- '%swrite host 0:0 %x /dir1/%s.w6 $filesize'
- % (fs_type, ADDR, MIN_FILE)])
- output = u_boot_console.run_command(
- '%swrite host 0:0 %x /dir1/%s.w6 0 0'
- % (fs_type, ADDR, MIN_FILE))
+ '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE),
+ '%s%s host 0:0 %x /dir1/%s.w6 $filesize'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)])
+ output = ubman.run_command(
+ '%s%s host 0:0 %x /dir1/%s.w6 0 0'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE))
assert('0 bytes written' in output)
# Test Case 6b - Check size of written file
- output = u_boot_console.run_command_list([
- '%ssize host 0:0 /dir1/%s.w6' % (fs_type, MIN_FILE),
+ output = ubman.run_command_list([
+ '%ssize host 0:0 /dir1/%s.w6' % (fs_cmd_prefix, MIN_FILE),
'printenv filesize',
'setenv filesize'])
assert('filesize=0' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_fs_ext7(self, u_boot_console, fs_obj_ext):
+ def test_fs_ext7(self, ubman, fs_obj_ext):
"""
Test Case 7 - write at the end (append)
"""
- fs_type,fs_img,md5val = fs_obj_ext
- with u_boot_console.log.section('Test Case 7 - write at the end (append)'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext
+ with ubman.log.section('Test Case 7 - write at the end (append)'):
# Test Case 7a - Check if command successfully returned
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
- '%swrite host 0:0 %x /dir1/%s.w7 $filesize'
- % (fs_type, ADDR, MIN_FILE)])
- output = u_boot_console.run_command(
- '%swrite host 0:0 %x /dir1/%s.w7 $filesize $filesize'
- % (fs_type, ADDR, MIN_FILE))
+ '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE),
+ '%s%s host 0:0 %x /dir1/%s.w7 $filesize'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)])
+ output = ubman.run_command(
+ '%s%s host 0:0 %x /dir1/%s.w7 $filesize $filesize'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE))
assert('20480 bytes written' in output)
# Test Case 7b - Check size of written file
- output = u_boot_console.run_command_list([
- '%ssize host 0:0 /dir1/%s.w7' % (fs_type, MIN_FILE),
+ output = ubman.run_command_list([
+ '%ssize host 0:0 /dir1/%s.w7' % (fs_cmd_prefix, MIN_FILE),
'printenv filesize',
'setenv filesize'])
assert('filesize=a000' in ''.join(output))
# Test Case 7c - Check md5 of file content
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'mw.b %x 00 100' % ADDR,
- '%sload host 0:0 %x /dir1/%s.w7' % (fs_type, ADDR, MIN_FILE),
+ '%sload host 0:0 %x /dir1/%s.w7' % (fs_cmd_prefix, ADDR, MIN_FILE),
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[3] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_fs_ext8(self, u_boot_console, fs_obj_ext):
+ def test_fs_ext8(self, ubman, fs_obj_ext):
"""
Test Case 8 - write at offset beyond the end of file
"""
- fs_type,fs_img,md5val = fs_obj_ext
- with u_boot_console.log.section('Test Case 8 - write beyond the end'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext
+ with ubman.log.section('Test Case 8 - write beyond the end'):
# Test Case 8a - Check if command expectedly failed
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
- '%swrite host 0:0 %x /dir1/%s.w8 $filesize'
- % (fs_type, ADDR, MIN_FILE)])
- output = u_boot_console.run_command(
- '%swrite host 0:0 %x /dir1/%s.w8 0x1400 %x'
- % (fs_type, ADDR, MIN_FILE, 0x100000 + 0x1400))
+ '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE),
+ '%s%s host 0:0 %x /dir1/%s.w8 $filesize'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)])
+ output = ubman.run_command(
+ '%s%s host 0:0 %x /dir1/%s.w8 0x1400 %x'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE, 0x100000 + 0x1400))
assert('Unable to write file /dir1' in output)
assert_fs_integrity(fs_type, fs_img)
- def test_fs_ext9(self, u_boot_console, fs_obj_ext):
+ def test_fs_ext9(self, ubman, fs_obj_ext):
"""
Test Case 9 - write to a non-existing file at non-zero offset
"""
- fs_type,fs_img,md5val = fs_obj_ext
- with u_boot_console.log.section('Test Case 9 - write to non-existing file with non-zero offset'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext
+ with ubman.log.section('Test Case 9 - write to non-existing file with non-zero offset'):
# Test Case 9a - Check if command expectedly failed
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
- '%swrite host 0:0 %x /dir1/%s.w9 0x1400 0x1400'
- % (fs_type, ADDR, MIN_FILE)])
+ '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE),
+ '%s%s host 0:0 %x /dir1/%s.w9 0x1400 0x1400'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)])
assert('Unable to write file /dir1' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_fs_ext10(self, u_boot_console, fs_obj_ext):
+ def test_fs_ext10(self, ubman, fs_obj_ext):
"""
'Test Case 10 - create/delete as many directories under root directory
as amount of directory entries goes beyond one cluster size)'
"""
- fs_type,fs_img,md5val = fs_obj_ext
- with u_boot_console.log.section('Test Case 10 - create/delete (many)'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext
+ with ubman.log.section('Test Case 10 - create/delete (many)'):
# Test Case 10a - Create many files
# Please note that the size of directory entry is 32 bytes.
# So one typical cluster may holds 64 (2048/32) entries.
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'host bind 0 %s' % fs_img)
for i in range(0, 66):
- output = u_boot_console.run_command(
- '%swrite host 0:0 %x /FILE0123456789_%02x 100'
- % (fs_type, ADDR, i))
- output = u_boot_console.run_command('%sls host 0:0 /' % fs_type)
+ output = ubman.run_command(
+ '%s%s host 0:0 %x /FILE0123456789_%02x 100'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, i))
+ output = ubman.run_command('%sls host 0:0 /' % fs_cmd_prefix)
assert('FILE0123456789_00' in output)
assert('FILE0123456789_41' in output)
# Test Case 10b - Delete many files
for i in range(0, 66):
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'%srm host 0:0 /FILE0123456789_%02x'
- % (fs_type, i))
- output = u_boot_console.run_command('%sls host 0:0 /' % fs_type)
+ % (fs_cmd_prefix, i))
+ output = ubman.run_command('%sls host 0:0 /' % fs_cmd_prefix)
assert(not 'FILE0123456789_00' in output)
assert(not 'FILE0123456789_41' in output)
# Test Case 10c - Create many files again
# Please note no.64 and 65 are intentionally re-created
for i in range(64, 128):
- output = u_boot_console.run_command(
- '%swrite host 0:0 %x /FILE0123456789_%02x 100'
- % (fs_type, ADDR, i))
- output = u_boot_console.run_command('%sls host 0:0 /' % fs_type)
+ output = ubman.run_command(
+ '%s%s host 0:0 %x /FILE0123456789_%02x 100'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, i))
+ output = ubman.run_command('%sls host 0:0 /' % fs_cmd_prefix)
assert('FILE0123456789_40' in output)
assert('FILE0123456789_79' in output)
assert_fs_integrity(fs_type, fs_img)
- def test_fs_ext11(self, u_boot_console, fs_obj_ext):
+ def test_fs_ext11(self, ubman, fs_obj_ext):
"""
'Test Case 11 - create/delete as many directories under non-root
directory as amount of directory entries goes beyond one cluster size)'
"""
- fs_type,fs_img,md5val = fs_obj_ext
- with u_boot_console.log.section('Test Case 11 - create/delete (many)'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext
+ with ubman.log.section('Test Case 11 - create/delete (many)'):
# Test Case 11a - Create many files
# Please note that the size of directory entry is 32 bytes.
# So one typical cluster may holds 64 (2048/32) entries.
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'host bind 0 %s' % fs_img)
for i in range(0, 66):
- output = u_boot_console.run_command(
- '%swrite host 0:0 %x /dir1/FILE0123456789_%02x 100'
- % (fs_type, ADDR, i))
- output = u_boot_console.run_command('%sls host 0:0 /dir1' % fs_type)
+ output = ubman.run_command(
+ '%s%s host 0:0 %x /dir1/FILE0123456789_%02x 100'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, i))
+ output = ubman.run_command('%sls host 0:0 /dir1' % fs_cmd_prefix)
assert('FILE0123456789_00' in output)
assert('FILE0123456789_41' in output)
# Test Case 11b - Delete many files
for i in range(0, 66):
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'%srm host 0:0 /dir1/FILE0123456789_%02x'
- % (fs_type, i))
- output = u_boot_console.run_command('%sls host 0:0 /dir1' % fs_type)
+ % (fs_cmd_prefix, i))
+ output = ubman.run_command('%sls host 0:0 /dir1' % fs_cmd_prefix)
assert(not 'FILE0123456789_00' in output)
assert(not 'FILE0123456789_41' in output)
# Test Case 11c - Create many files again
# Please note no.64 and 65 are intentionally re-created
for i in range(64, 128):
- output = u_boot_console.run_command(
- '%swrite host 0:0 %x /dir1/FILE0123456789_%02x 100'
- % (fs_type, ADDR, i))
- output = u_boot_console.run_command('%sls host 0:0 /dir1' % fs_type)
+ output = ubman.run_command(
+ '%s%s host 0:0 %x /dir1/FILE0123456789_%02x 100'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, i))
+ output = ubman.run_command('%sls host 0:0 /dir1' % fs_cmd_prefix)
assert('FILE0123456789_40' in output)
assert('FILE0123456789_79' in output)
assert_fs_integrity(fs_type, fs_img)
- def test_fs_ext12(self, u_boot_console, fs_obj_ext):
+ def test_fs_ext12(self, ubman, fs_obj_ext):
"""
Test Case 12 - write plain and mangle file
"""
- fs_type,fs_img,md5val = fs_obj_ext
- with u_boot_console.log.section('Test Case 12 - write plain and mangle file'):
+ fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext
+ with ubman.log.section('Test Case 12 - write plain and mangle file'):
# Test Case 12a - Check if command successfully returned
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%swrite host 0:0 %x /%s 0'
- % (fs_type, ADDR, PLAIN_FILE),
- '%swrite host 0:0 %x /%s 0'
- % (fs_type, ADDR, MANGLE_FILE)])
+ '%s%s host 0:0 %x /%s 0'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, PLAIN_FILE),
+ '%s%s host 0:0 %x /%s 0'
+ % (fs_cmd_prefix, fs_cmd_write, ADDR, MANGLE_FILE)])
assert('0 bytes written' in ''.join(output))
- # Test Case 12b - Read file system content
- output = check_output('mdir -i %s' % fs_img, shell=True).decode()
- # Test Case 12c - Check if short filename is not mangled
- assert(str2fat(PLAIN_FILE) in ''.join(output))
- # Test Case 12d - Check if long filename is mangled
- assert(str2fat(MANGLE_FILE) in ''.join(output))
+ if fs_type == 'exfat':
+ # Test Case 12b - Read file system content
+ output = check_output('fattools ls %s' % fs_img, shell=True).decode()
+ # Test Case 12c - Check if short filename is not mangled
+ assert(PLAIN_FILE in ''.join(output))
+ # Test Case 12d - Check if long filename is mangled
+ assert(MANGLE_FILE in ''.join(output))
+ else:
+ # Test Case 12b - Read file system content
+ output = check_output('mdir -i %s' % fs_img, shell=True).decode()
+ # Test Case 12c - Check if short filename is not mangled
+ assert(str2fat(PLAIN_FILE) in ''.join(output))
+ # Test Case 12d - Check if long filename is mangled
+ assert(str2fat(MANGLE_FILE) in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
diff --git a/test/py/tests/test_fs/test_fs_cmd.py b/test/py/tests/test_fs/test_fs_cmd.py
index 700cf3591de..c925547c7bc 100644
--- a/test/py/tests/test_fs/test_fs_cmd.py
+++ b/test/py/tests/test_fs/test_fs_cmd.py
@@ -6,8 +6,8 @@ import pytest
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_fs_generic')
-def test_fstypes(u_boot_console):
+def test_fstypes(ubman):
"""Test that `fstypes` prints a result which includes `sandbox`."""
- output = u_boot_console.run_command('fstypes')
+ output = ubman.run_command('fstypes')
assert "Supported filesystems:" in output
assert "sandbox" in output
diff --git a/test/py/tests/test_fs/test_fs_fat.py b/test/py/tests/test_fs/test_fs_fat.py
index 4009d0b63a3..b61d8ab9eac 100644
--- a/test/py/tests/test_fs/test_fs_fat.py
+++ b/test/py/tests/test_fs/test_fs_fat.py
@@ -14,12 +14,12 @@ import re
@pytest.mark.boardspec('sandbox')
@pytest.mark.slow
class TestFsFat(object):
- def test_fs_fat1(self, u_boot_console, fs_obj_fat):
+ def test_fs_fat1(self, ubman, fs_obj_fat):
"""Test that `fstypes` prints a result which includes `sandbox`."""
fs_type,fs_img = fs_obj_fat
- with u_boot_console.log.section('Test Case 1 - fatinfo'):
+ with ubman.log.section('Test Case 1 - fatinfo'):
# Test Case 1 - ls
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
'fatinfo host 0:0'])
assert(re.search('Filesystem: %s' % fs_type.upper(), ''.join(output)))
diff --git a/test/py/tests/test_fs/test_mkdir.py b/test/py/tests/test_fs/test_mkdir.py
index fa9561ec359..1578c3cba3a 100644
--- a/test/py/tests/test_fs/test_mkdir.py
+++ b/test/py/tests/test_fs/test_mkdir.py
@@ -14,108 +14,108 @@ from fstest_helpers import assert_fs_integrity
@pytest.mark.boardspec('sandbox')
@pytest.mark.slow
class TestMkdir(object):
- def test_mkdir1(self, u_boot_console, fs_obj_mkdir):
+ def test_mkdir1(self, ubman, fs_obj_mkdir):
"""
Test Case 1 - create a directory under a root
"""
- fs_type,fs_img = fs_obj_mkdir
- with u_boot_console.log.section('Test Case 1 - mkdir'):
- output = u_boot_console.run_command_list([
+ fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir
+ with ubman.log.section('Test Case 1 - mkdir'):
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%smkdir host 0:0 dir1' % fs_type,
- '%sls host 0:0 /' % fs_type])
+ '%smkdir host 0:0 dir1' % fs_cmd_prefix,
+ '%sls host 0:0 /' % fs_cmd_prefix])
assert('dir1/' in ''.join(output))
- output = u_boot_console.run_command(
- '%sls host 0:0 dir1' % fs_type)
+ output = ubman.run_command(
+ '%sls host 0:0 dir1' % fs_cmd_prefix)
assert('./' in output)
assert('../' in output)
assert_fs_integrity(fs_type, fs_img)
- def test_mkdir2(self, u_boot_console, fs_obj_mkdir):
+ def test_mkdir2(self, ubman, fs_obj_mkdir):
"""
Test Case 2 - create a directory under a sub-directory
"""
- fs_type,fs_img = fs_obj_mkdir
- with u_boot_console.log.section('Test Case 2 - mkdir (sub-sub directory)'):
- output = u_boot_console.run_command_list([
+ fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir
+ with ubman.log.section('Test Case 2 - mkdir (sub-sub directory)'):
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%smkdir host 0:0 dir1/dir2' % fs_type,
- '%sls host 0:0 dir1' % fs_type])
+ '%smkdir host 0:0 dir1/dir2' % fs_cmd_prefix,
+ '%sls host 0:0 dir1' % fs_cmd_prefix])
assert('dir2/' in ''.join(output))
- output = u_boot_console.run_command(
- '%sls host 0:0 dir1/dir2' % fs_type)
+ output = ubman.run_command(
+ '%sls host 0:0 dir1/dir2' % fs_cmd_prefix)
assert('./' in output)
assert('../' in output)
assert_fs_integrity(fs_type, fs_img)
- def test_mkdir3(self, u_boot_console, fs_obj_mkdir):
+ def test_mkdir3(self, ubman, fs_obj_mkdir):
"""
Test Case 3 - trying to create a directory with a non-existing
path should fail
"""
- fs_type,fs_img = fs_obj_mkdir
- with u_boot_console.log.section('Test Case 3 - mkdir (non-existing path)'):
- output = u_boot_console.run_command_list([
+ fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir
+ with ubman.log.section('Test Case 3 - mkdir (non-existing path)'):
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%smkdir host 0:0 none/dir3' % fs_type])
+ '%smkdir host 0:0 none/dir3' % fs_cmd_prefix])
assert('Unable to create a directory' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_mkdir4(self, u_boot_console, fs_obj_mkdir):
+ def test_mkdir4(self, ubman, fs_obj_mkdir):
"""
Test Case 4 - trying to create "." should fail
"""
- fs_type,fs_img = fs_obj_mkdir
- with u_boot_console.log.section('Test Case 4 - mkdir (".")'):
- output = u_boot_console.run_command_list([
+ fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir
+ with ubman.log.section('Test Case 4 - mkdir (".")'):
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%smkdir host 0:0 .' % fs_type])
+ '%smkdir host 0:0 .' % fs_cmd_prefix])
assert('Unable to create a directory' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_mkdir5(self, u_boot_console, fs_obj_mkdir):
+ def test_mkdir5(self, ubman, fs_obj_mkdir):
"""
Test Case 5 - trying to create ".." should fail
"""
- fs_type,fs_img = fs_obj_mkdir
- with u_boot_console.log.section('Test Case 5 - mkdir ("..")'):
- output = u_boot_console.run_command_list([
+ fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir
+ with ubman.log.section('Test Case 5 - mkdir ("..")'):
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%smkdir host 0:0 ..' % fs_type])
+ '%smkdir host 0:0 ..' % fs_cmd_prefix])
assert('Unable to create a directory' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_mkdir6(self, u_boot_console, fs_obj_mkdir):
+ def test_mkdir6(self, ubman, fs_obj_mkdir):
"""
'Test Case 6 - create as many directories as amount of directory
entries goes beyond a cluster size)'
"""
- fs_type,fs_img = fs_obj_mkdir
- with u_boot_console.log.section('Test Case 6 - mkdir (create many)'):
- output = u_boot_console.run_command_list([
+ fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir
+ with ubman.log.section('Test Case 6 - mkdir (create many)'):
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%smkdir host 0:0 dir6' % fs_type,
- '%sls host 0:0 /' % fs_type])
+ '%smkdir host 0:0 dir6' % fs_cmd_prefix,
+ '%sls host 0:0 /' % fs_cmd_prefix])
assert('dir6/' in ''.join(output))
for i in range(0, 20):
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'%smkdir host 0:0 dir6/0123456789abcdef%02x'
- % (fs_type, i))
- output = u_boot_console.run_command('%sls host 0:0 dir6' % fs_type)
+ % (fs_cmd_prefix, i))
+ output = ubman.run_command('%sls host 0:0 dir6' % fs_cmd_prefix)
assert('0123456789abcdef00/' in output)
assert('0123456789abcdef13/' in output)
- output = u_boot_console.run_command(
- '%sls host 0:0 dir6/0123456789abcdef13/.' % fs_type)
+ output = ubman.run_command(
+ '%sls host 0:0 dir6/0123456789abcdef13/.' % fs_cmd_prefix)
assert('./' in output)
assert('../' in output)
- output = u_boot_console.run_command(
- '%sls host 0:0 dir6/0123456789abcdef13/..' % fs_type)
+ output = ubman.run_command(
+ '%sls host 0:0 dir6/0123456789abcdef13/..' % fs_cmd_prefix)
assert('0123456789abcdef00/' in output)
assert('0123456789abcdef13/' in output)
assert_fs_integrity(fs_type, fs_img)
diff --git a/test/py/tests/test_fs/test_rename.py b/test/py/tests/test_fs/test_rename.py
new file mode 100644
index 00000000000..e36cff99bb7
--- /dev/null
+++ b/test/py/tests/test_fs/test_rename.py
@@ -0,0 +1,372 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2025 Gabriel Dalimonte <gabriel.dalimonte@gmail.com>
+#
+# U-Boot File System:rename Test
+
+
+import pytest
+
+from fstest_defs import *
+from fstest_helpers import assert_fs_integrity
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.slow
+class TestRename(object):
+ def test_rename1(self, ubman, fs_obj_rename):
+ """
+ Test Case 1 - rename a file (successful mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with ubman.log.section('Test Case 1 - rename a file'):
+ d = 'test1'
+ src = '%s/file1' % d
+ dst = '%s/file2' % d
+ output = ubman.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = ubman.run_command_list([
+ 'load host 0:0 %x /%s' % (ADDR, dst),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = ubman.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('file1' not in ''.join(output))
+
+ output = ubman.run_command_list([
+ 'md5sum %x $filesize' % ADDR,
+ 'setenv filesize'])
+ assert(md5val['test1'] in ''.join(output))
+ assert_fs_integrity(fs_type, fs_img)
+
+ def test_rename2(self, ubman, fs_obj_rename):
+ """
+ Test Case 2 - rename a file to an existing file (successful mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with ubman.log.section('Test Case 2 - rename a file to an existing file'):
+ d = 'test2'
+ src = '%s/file1' % d
+ dst = '%s/file_exist' % d
+ output = ubman.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = ubman.run_command_list([
+ 'load host 0:0 %x /%s' % (ADDR, dst),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = ubman.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('file1' not in ''.join(output))
+
+ output = ubman.run_command_list([
+ 'md5sum %x $filesize' % ADDR,
+ 'setenv filesize'])
+ assert(md5val['test2'] in ''.join(output))
+ assert_fs_integrity(fs_type, fs_img)
+
+ def test_rename3(self, ubman, fs_obj_rename):
+ """
+ Test Case 3 - rename a directory (successful mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with ubman.log.section('Test Case 3 - rename a directory'):
+ d = 'test3'
+ src = '%s/dir1' % d
+ dst = '%s/dir2' % d
+ output = ubman.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = ubman.run_command_list([
+ 'load host 0:0 %x /%s/file1' % (ADDR, dst),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = ubman.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('dir1' not in ''.join(output))
+
+ output = ubman.run_command_list([
+ 'md5sum %x $filesize' % ADDR,
+ 'setenv filesize'])
+ assert(md5val['test3'] in ''.join(output))
+ assert_fs_integrity(fs_type, fs_img)
+
+ def test_rename4(self, ubman, fs_obj_rename):
+ """
+ Test Case 4 - rename a directory to an existing directory (successful
+ mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with ubman.log.section('Test Case 4 - rename a directory to an existing directory'):
+ d = 'test4'
+ src = '%s/dir1' % d
+ dst = '%s/dir2' % d
+ output = ubman.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = ubman.run_command_list([
+ 'load host 0:0 %x /%s/dir1/file1' % (ADDR, dst),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = ubman.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('dir1' not in ''.join(output))
+
+ output = ubman.run_command_list([
+ 'md5sum %x $filesize' % ADDR,
+ 'setenv filesize'])
+ assert(md5val['test4'] in ''.join(output))
+ assert_fs_integrity(fs_type, fs_img)
+
+ def test_rename5(self, ubman, fs_obj_rename):
+ """
+ Test Case 5 - rename a directory to an existing file (failed mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with ubman.log.section('Test Case 5 - rename a directory to an existing file'):
+ d = 'test5'
+ src = '%s/dir1' % d
+ dst = '%s/file2' % d
+ output = ubman.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = ubman.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('dir1' in ''.join(output))
+ assert('file2' in ''.join(output))
+
+ output = ubman.run_command_list([
+ 'load host 0:0 %x /%s' % (ADDR, dst),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = ubman.run_command_list([
+ 'md5sum %x $filesize' % ADDR,
+ 'setenv filesize'])
+ assert(md5val['test5'] in ''.join(output))
+ assert_fs_integrity(fs_type, fs_img)
+
+ def test_rename6(self, ubman, fs_obj_rename):
+ """
+ Test Case 6 - rename a file to an existing empty directory (failed mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with ubman.log.section('Test Case 6 - rename a file to an existing empty directory'):
+ d = 'test6'
+ src = '%s/existing' % d
+ dst = '%s/dir2' % d
+ output = ubman.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = ubman.run_command_list([
+ 'load host 0:0 %x /%s' % (ADDR, src),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = ubman.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('dir2' in ''.join(output))
+ assert('existing' in ''.join(output))
+
+ output = ubman.run_command_list([
+ 'md5sum %x $filesize' % ADDR,
+ 'setenv filesize'])
+ assert(md5val['test6'] in ''.join(output))
+ assert_fs_integrity(fs_type, fs_img)
+
+ def test_rename7(self, ubman, fs_obj_rename):
+ """
+ Test Case 7 - rename a directory to a non-empty directory (failed mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with ubman.log.section('Test Case 7 - rename a directory to a non-empty directory'):
+ d = 'test7'
+ src = '%s/dir1' % d
+ dst = '%s/dir2' % d
+ output = ubman.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = ubman.run_command_list([
+ 'load host 0:0 %x /%s/dir1/file1' % (ADDR, dst),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = ubman.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('dir1' in ''.join(output))
+ assert('dir2' in ''.join(output))
+
+ output = ubman.run_command_list([
+ 'md5sum %x $filesize' % ADDR,
+ 'setenv filesize'])
+ assert(md5val['test7'] in ''.join(output))
+ assert_fs_integrity(fs_type, fs_img)
+
+ def test_rename8(self, ubman, fs_obj_rename):
+ """
+ Test Case 8 - rename a directory inside itself (failed mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with ubman.log.section('Test Case 8 - rename a directory inside itself'):
+ d = 'test8'
+ src = '%s/dir1' % d
+ dst = '%s/dir1/dir1' % d
+ output = ubman.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = ubman.run_command_list([
+ 'load host 0:0 %x /%s/file1' % (ADDR, src),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = ubman.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('dir1' in ''.join(output))
+
+ output = ubman.run_command_list([
+ 'ls host 0:0 %s' % (src),
+ ])
+ assert('file1' in ''.join(output))
+ assert('dir1' not in ''.join(output))
+
+ output = ubman.run_command_list([
+ 'md5sum %x $filesize' % ADDR,
+ 'setenv filesize'])
+ assert(md5val['test8'] in ''.join(output))
+ assert_fs_integrity(fs_type, fs_img)
+
+ def test_rename9(self, ubman, fs_obj_rename):
+ """
+ Test Case 9 - rename a directory inside itself with backtracks (failed
+ mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with ubman.log.section('Test Case 9 - rename a directory inside itself with backtracks'):
+ d = 'test9'
+ src = '%s/dir1/nested' % d
+ dst = '%s/dir1/nested/inner/./../../../dir1/nested/inner/another' % d
+ output = ubman.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = ubman.run_command_list([
+ 'ls host 0:0 %s/dir1' % (d),
+ ])
+ assert('nested' in ''.join(output))
+
+ output = ubman.run_command_list([
+ 'ls host 0:0 %s' % (src),
+ ])
+ assert('inner' in ''.join(output))
+ assert('nested' not in ''.join(output))
+ assert_fs_integrity(fs_type, fs_img)
+
+ def test_rename10(self, ubman, fs_obj_rename):
+ """
+ Test Case 10 - rename a file to itself (successful mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with ubman.log.section('Test Case 10 - rename a file to itself'):
+ d = 'test10'
+ src = '%s/file1' % d
+ output = ubman.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, src),
+ ])
+ assert('' == ''.join(output))
+
+ output = ubman.run_command_list([
+ 'load host 0:0 %x /%s' % (ADDR, src),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = ubman.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('file1' in ''.join(output))
+
+ output = ubman.run_command_list([
+ 'md5sum %x $filesize' % ADDR,
+ 'setenv filesize'])
+ assert(md5val['test10'] in ''.join(output))
+ assert_fs_integrity(fs_type, fs_img)
+
+ def test_rename11(self, ubman, fs_obj_rename):
+ """
+ Test Case 11 - rename a directory to itself (successful mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with ubman.log.section('Test Case 11 - rename a directory to itself'):
+ # / at the end here is intentional. Ensures trailing / doesn't
+ # affect mv producing an updated dst path for fs_rename
+ d = 'test11/'
+ src = '%sdir1' % d
+ output = ubman.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, d),
+ ])
+ assert('' == ''.join(output))
+
+ output = ubman.run_command_list([
+ 'load host 0:0 %x /%s/file1' % (ADDR, src),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = ubman.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('dir1' in ''.join(output))
+
+ output = ubman.run_command_list([
+ 'md5sum %x $filesize' % ADDR,
+ 'setenv filesize'])
+ assert(md5val['test11'] in ''.join(output))
+ assert_fs_integrity(fs_type, fs_img)
diff --git a/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py b/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py
index 6ec6ccec6c9..33093f61ac3 100644
--- a/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py
+++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py
@@ -27,11 +27,11 @@ def original_md5sum(path):
return checksum
-def uboot_md5sum(u_boot_console, address, count):
+def uboot_md5sum(ubman, address, count):
""" Runs U-Boot's md5sum command.
Args:
- u_boot_console: provides the means to interact with U-Boot's console.
+ ubman: provides the means to interact with U-Boot's console.
address: address where the file was loaded (e.g.: $kernel_addr_r).
count: file's size. It was named 'count' to match md5sum's respective
argument name.
@@ -39,89 +39,89 @@ def uboot_md5sum(u_boot_console, address, count):
The checksum of the file loaded with sqfsload as a string.
"""
- out = u_boot_console.run_command('md5sum {} {}'.format(address, count))
+ out = ubman.run_command('md5sum {} {}'.format(address, count))
checksum = out.split()[-1]
return checksum
-def sqfs_load_files(u_boot_console, files, sizes, address):
+def sqfs_load_files(ubman, files, sizes, address):
""" Loads files and asserts their checksums.
Args:
- u_boot_console: provides the means to interact with U-Boot's console.
+ ubman: provides the means to interact with U-Boot's console.
files: list of files to be loaded.
sizes: the sizes of each file.
address: the address where the files should be loaded.
"""
- build_dir = u_boot_console.config.build_dir
+ build_dir = ubman.config.build_dir
for (file, size) in zip(files, sizes):
- out = u_boot_console.run_command('sqfsload host 0 {} {}'.format(address, file))
+ out = ubman.run_command('sqfsload host 0 {} {}'.format(address, file))
# check if the right amount of bytes was read
assert size in out
# compare original file's checksum against u-boot's
- u_boot_checksum = uboot_md5sum(u_boot_console, address, hex(int(size)))
+ u_boot_checksum = uboot_md5sum(ubman, address, hex(int(size)))
original_file_path = os.path.join(build_dir, SQFS_SRC_DIR + '/' + file)
original_checksum = original_md5sum(original_file_path)
assert u_boot_checksum == original_checksum
-def sqfs_load_files_at_root(u_boot_console):
+def sqfs_load_files_at_root(ubman):
""" Calls sqfs_load_files passing the files at the SquashFS image's root.
Args:
- u_boot_console: provides the means to interact with U-Boot's console.
+ ubman: provides the means to interact with U-Boot's console.
"""
files = ['f4096', 'f5096', 'f1000']
sizes = ['4096', '5096', '1000']
address = '$kernel_addr_r'
- sqfs_load_files(u_boot_console, files, sizes, address)
+ sqfs_load_files(ubman, files, sizes, address)
-def sqfs_load_files_at_subdir(u_boot_console):
+def sqfs_load_files_at_subdir(ubman):
""" Calls sqfs_load_files passing the files at the SquashFS image's subdir.
This test checks if the path resolution works, since the file is not at the
root directory.
Args:
- u_boot_console: provides the means to interact with U-Boot's console.
+ ubman: provides the means to interact with U-Boot's console.
"""
files = ['subdir/subdir-file']
sizes = ['100']
address = '$kernel_addr_r'
- sqfs_load_files(u_boot_console, files, sizes, address)
+ sqfs_load_files(ubman, files, sizes, address)
-def sqfs_load_non_existent_file(u_boot_console):
+def sqfs_load_non_existent_file(ubman):
""" Calls sqfs_load_files passing an non-existent file to raise an error.
This test checks if the SquashFS support won't crash if it doesn't find the
specified file.
Args:
- u_boot_console: provides the means to interact with U-Boot's console.
+ ubman: provides the means to interact with U-Boot's console.
"""
address = '$kernel_addr_r'
file = 'non-existent'
- out = u_boot_console.run_command('sqfsload host 0 {} {}'.format(address, file))
+ out = ubman.run_command('sqfsload host 0 {} {}'.format(address, file))
assert 'Failed to load' in out
-def sqfs_run_all_load_tests(u_boot_console):
+def sqfs_run_all_load_tests(ubman):
""" Runs all the previously defined test cases.
Args:
- u_boot_console: provides the means to interact with U-Boot's console.
+ ubman: provides the means to interact with U-Boot's console.
"""
- sqfs_load_files_at_root(u_boot_console)
- sqfs_load_files_at_subdir(u_boot_console)
- sqfs_load_non_existent_file(u_boot_console)
+ sqfs_load_files_at_root(ubman)
+ sqfs_load_files_at_subdir(ubman)
+ sqfs_load_non_existent_file(ubman)
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_fs_generic')
@pytest.mark.buildconfigspec('cmd_squashfs')
@pytest.mark.buildconfigspec('fs_squashfs')
@pytest.mark.requiredtool('mksquashfs')
-def test_sqfs_load(u_boot_console):
+def test_sqfs_load(ubman):
""" Executes the sqfsload test suite.
First, it generates the SquashFS images, then it runs the test cases and
@@ -129,9 +129,9 @@ def test_sqfs_load(u_boot_console):
cleaned before exiting.
Args:
- u_boot_console: provides the means to interact with U-Boot's console.
+ ubman: provides the means to interact with U-Boot's console.
"""
- build_dir = u_boot_console.config.build_dir
+ build_dir = ubman.config.build_dir
# setup test environment
check_mksquashfs_version()
@@ -142,8 +142,8 @@ def test_sqfs_load(u_boot_console):
for image in STANDARD_TABLE:
try:
image_path = os.path.join(build_dir, image)
- u_boot_console.run_command('host bind 0 {}'.format(image_path))
- sqfs_run_all_load_tests(u_boot_console)
+ ubman.run_command('host bind 0 {}'.format(image_path))
+ sqfs_run_all_load_tests(ubman)
except:
clean_all_images(build_dir)
clean_sqfs_src_dir(build_dir)
diff --git a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py
index a20a7d1a663..adda3b98cda 100644
--- a/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py
+++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_ls.py
@@ -10,70 +10,70 @@ from sqfs_common import generate_sqfs_src_dir, make_all_images
from sqfs_common import clean_sqfs_src_dir, clean_all_images
from sqfs_common import check_mksquashfs_version
-def sqfs_ls_at_root(u_boot_console):
+def sqfs_ls_at_root(ubman):
""" Runs sqfsls at image's root.
This test checks if all the present files and directories were listed. Also,
it checks if passing the slash or not changes the output, which it shouldn't.
Args:
- u_boot_console: provides the means to interact with U-Boot's console.
+ ubman: provides the means to interact with U-Boot's console.
"""
- no_slash = u_boot_console.run_command('sqfsls host 0')
- slash = u_boot_console.run_command('sqfsls host 0 /')
+ no_slash = ubman.run_command('sqfsls host 0')
+ slash = ubman.run_command('sqfsls host 0 /')
assert no_slash == slash
expected_lines = ['empty-dir/', '1000 f1000', '4096 f4096', '5096 f5096',
'subdir/', '<SYM> sym', '4 file(s), 2 dir(s)']
- output = u_boot_console.run_command('sqfsls host 0')
+ output = ubman.run_command('sqfsls host 0')
for line in expected_lines:
assert line in output
-def sqfs_ls_at_empty_dir(u_boot_console):
+def sqfs_ls_at_empty_dir(ubman):
""" Runs sqfsls at an empty directory.
This tests checks if sqfsls will print anything other than the 'Empty directory'
message.
Args:
- u_boot_console: provides the means to interact with U-Boot's console.
+ ubman: provides the means to interact with U-Boot's console.
"""
- assert u_boot_console.run_command('sqfsls host 0 empty-dir') == 'Empty directory.'
+ assert ubman.run_command('sqfsls host 0 empty-dir') == 'Empty directory.'
-def sqfs_ls_at_subdir(u_boot_console):
+def sqfs_ls_at_subdir(ubman):
""" Runs sqfsls at the SquashFS image's subdir.
This test checks if the path resolution works, since the directory is not the
root.
Args:
- u_boot_console: provides the means to interact with U-Boot's console.
+ ubman: provides the means to interact with U-Boot's console.
"""
expected_lines = ['100 subdir-file', '1 file(s), 0 dir(s)']
- output = u_boot_console.run_command('sqfsls host 0 subdir')
+ output = ubman.run_command('sqfsls host 0 subdir')
for line in expected_lines:
assert line in output
-def sqfs_ls_at_symlink(u_boot_console):
+def sqfs_ls_at_symlink(ubman):
""" Runs sqfsls at a SquashFS image's symbolic link.
This test checks if the symbolic link's target resolution works.
Args:
- u_boot_console: provides the means to interact with U-Boot's console.
+ ubman: provides the means to interact with U-Boot's console.
"""
# since sym -> subdir, the following outputs must be equal
- output = u_boot_console.run_command('sqfsls host 0 sym')
- output_subdir = u_boot_console.run_command('sqfsls host 0 subdir')
+ output = ubman.run_command('sqfsls host 0 sym')
+ output_subdir = ubman.run_command('sqfsls host 0 subdir')
assert output == output_subdir
expected_lines = ['100 subdir-file', '1 file(s), 0 dir(s)']
for line in expected_lines:
assert line in output
-def sqfs_ls_at_non_existent_dir(u_boot_console):
+def sqfs_ls_at_non_existent_dir(ubman):
""" Runs sqfsls at a file and at a non-existent directory.
This test checks if the SquashFS support won't crash if it doesn't find the
@@ -81,24 +81,24 @@ def sqfs_ls_at_non_existent_dir(u_boot_console):
directory. In both cases, the output should be the same.
Args:
- u_boot_console: provides the means to interact with U-Boot's console.
+ ubman: provides the means to interact with U-Boot's console.
"""
- out_non_existent = u_boot_console.run_command('sqfsls host 0 fff')
- out_not_dir = u_boot_console.run_command('sqfsls host 0 f1000')
+ out_non_existent = ubman.run_command('sqfsls host 0 fff')
+ out_not_dir = ubman.run_command('sqfsls host 0 f1000')
assert out_non_existent == out_not_dir
assert '** Cannot find directory. **' in out_non_existent
-def sqfs_run_all_ls_tests(u_boot_console):
+def sqfs_run_all_ls_tests(ubman):
""" Runs all the previously defined test cases.
Args:
- u_boot_console: provides the means to interact with U-Boot's console.
+ ubman: provides the means to interact with U-Boot's console.
"""
- sqfs_ls_at_root(u_boot_console)
- sqfs_ls_at_empty_dir(u_boot_console)
- sqfs_ls_at_subdir(u_boot_console)
- sqfs_ls_at_symlink(u_boot_console)
- sqfs_ls_at_non_existent_dir(u_boot_console)
+ sqfs_ls_at_root(ubman)
+ sqfs_ls_at_empty_dir(ubman)
+ sqfs_ls_at_subdir(ubman)
+ sqfs_ls_at_symlink(ubman)
+ sqfs_ls_at_non_existent_dir(ubman)
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_fs_generic')
@@ -106,7 +106,7 @@ def sqfs_run_all_ls_tests(u_boot_console):
@pytest.mark.buildconfigspec('fs_squashfs')
@pytest.mark.requiredtool('mksquashfs')
@pytest.mark.singlethread
-def test_sqfs_ls(u_boot_console):
+def test_sqfs_ls(ubman):
""" Executes the sqfsls test suite.
First, it generates the SquashFS images, then it runs the test cases and
@@ -114,9 +114,9 @@ def test_sqfs_ls(u_boot_console):
cleaned before exiting.
Args:
- u_boot_console: provides the means to interact with U-Boot's console.
+ ubman: provides the means to interact with U-Boot's console.
"""
- build_dir = u_boot_console.config.build_dir
+ build_dir = ubman.config.build_dir
# If the EFI subsystem is enabled and initialized, EFI subsystem tries to
# add EFI boot option when the new disk is detected. If there is no EFI
@@ -125,7 +125,7 @@ def test_sqfs_ls(u_boot_console):
# Restart U-Boot to clear the previous state.
# TODO: Ideally EFI test cases need to be fixed, but it will
# increase the number of system reset.
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
# setup test environment
check_mksquashfs_version()
@@ -136,8 +136,8 @@ def test_sqfs_ls(u_boot_console):
for image in STANDARD_TABLE:
try:
image_path = os.path.join(build_dir, image)
- u_boot_console.run_command('host bind 0 {}'.format(image_path))
- sqfs_run_all_ls_tests(u_boot_console)
+ ubman.run_command('host bind 0 {}'.format(image_path))
+ sqfs_run_all_ls_tests(ubman)
except:
clean_all_images(build_dir)
clean_sqfs_src_dir(build_dir)
diff --git a/test/py/tests/test_fs/test_symlink.py b/test/py/tests/test_fs/test_symlink.py
index 9ced101a294..9ffd7e6e54d 100644
--- a/test/py/tests/test_fs/test_symlink.py
+++ b/test/py/tests/test_fs/test_symlink.py
@@ -18,38 +18,38 @@ from fstest_helpers import assert_fs_integrity
@pytest.mark.boardspec('sandbox')
@pytest.mark.slow
class TestSymlink(object):
- def test_symlink1(self, u_boot_console, fs_obj_symlink):
+ def test_symlink1(self, ubman, fs_obj_symlink):
"""
Test Case 1 - create a link. and follow it when reading
"""
fs_type, fs_img, md5val = fs_obj_symlink
- with u_boot_console.log.section('Test Case 1 - create link and read'):
- output = u_boot_console.run_command_list([
+ with ubman.log.section('Test Case 1 - create link and read'):
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
'setenv filesize',
'ln host 0:0 %s /%s.link ' % (SMALL_FILE, SMALL_FILE),
])
assert('' in ''.join(output))
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'%sload host 0:0 %x /%s.link' % (fs_type, ADDR, SMALL_FILE),
'printenv filesize'])
assert('filesize=100000' in ''.join(output))
# Test Case 4b - Read full 1MB of small file
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[0] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_symlink2(self, u_boot_console, fs_obj_symlink):
+ def test_symlink2(self, ubman, fs_obj_symlink):
"""
Test Case 2 - create chained links
"""
fs_type, fs_img, md5val = fs_obj_symlink
- with u_boot_console.log.section('Test Case 2 - create chained links'):
- output = u_boot_console.run_command_list([
+ with ubman.log.section('Test Case 2 - create chained links'):
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
'setenv filesize',
'ln host 0:0 %s /%s.link1 ' % (SMALL_FILE, SMALL_FILE),
@@ -60,25 +60,25 @@ class TestSymlink(object):
])
assert('' in ''.join(output))
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'%sload host 0:0 %x /%s.link3' % (fs_type, ADDR, SMALL_FILE),
'printenv filesize'])
assert('filesize=100000' in ''.join(output))
# Test Case 4b - Read full 1MB of small file
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[0] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_symlink3(self, u_boot_console, fs_obj_symlink):
+ def test_symlink3(self, ubman, fs_obj_symlink):
"""
Test Case 3 - replace file/link with link
"""
fs_type, fs_img, md5val = fs_obj_symlink
- with u_boot_console.log.section('Test Case 1 - create link and read'):
- output = u_boot_console.run_command_list([
+ with ubman.log.section('Test Case 1 - create link and read'):
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
'setenv filesize',
'ln host 0:0 %s /%s ' % (MEDIUM_FILE, SMALL_FILE),
@@ -86,45 +86,45 @@ class TestSymlink(object):
])
assert('' in ''.join(output))
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE),
'printenv filesize'])
assert('filesize=a00000' in ''.join(output))
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[1] in ''.join(output))
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'ln host 0:0 %s.link /%s ' % (MEDIUM_FILE, SMALL_FILE),
'%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE),
'printenv filesize'])
assert('filesize=a00000' in ''.join(output))
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(md5val[1] in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_symlink4(self, u_boot_console, fs_obj_symlink):
+ def test_symlink4(self, ubman, fs_obj_symlink):
"""
Test Case 4 - create a broken link
"""
fs_type, fs_img, md5val = fs_obj_symlink
- with u_boot_console.log.section('Test Case 1 - create link and read'):
+ with ubman.log.section('Test Case 1 - create link and read'):
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'setenv filesize',
'ln host 0:0 nowhere /link ',
])
assert('' in ''.join(output))
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'%sload host 0:0 %x /link' %
(fs_type, ADDR))
- with u_boot_console.disable_check('error_notification'):
- output = u_boot_console.run_command('printenv filesize')
+ with ubman.disable_check('error_notification'):
+ output = ubman.run_command('printenv filesize')
assert('"filesize" not defined' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
diff --git a/test/py/tests/test_fs/test_unlink.py b/test/py/tests/test_fs/test_unlink.py
index 97aafc63bb5..1e2df3dbfd8 100644
--- a/test/py/tests/test_fs/test_unlink.py
+++ b/test/py/tests/test_fs/test_unlink.py
@@ -15,104 +15,104 @@ from fstest_helpers import assert_fs_integrity
@pytest.mark.boardspec('sandbox')
@pytest.mark.slow
class TestUnlink(object):
- def test_unlink1(self, u_boot_console, fs_obj_unlink):
+ def test_unlink1(self, ubman, fs_obj_unlink):
"""
Test Case 1 - delete a file
"""
- fs_type,fs_img = fs_obj_unlink
- with u_boot_console.log.section('Test Case 1 - unlink (file)'):
- output = u_boot_console.run_command_list([
+ fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink
+ with ubman.log.section('Test Case 1 - unlink (file)'):
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%srm host 0:0 dir1/file1' % fs_type,
- '%sls host 0:0 dir1/file1' % fs_type])
+ '%srm host 0:0 dir1/file1' % fs_cmd_prefix,
+ '%sls host 0:0 dir1/file1' % fs_cmd_prefix])
assert('' == ''.join(output))
- output = u_boot_console.run_command(
- '%sls host 0:0 dir1/' % fs_type)
+ output = ubman.run_command(
+ '%sls host 0:0 dir1/' % fs_cmd_prefix)
assert(not 'file1' in output)
assert('file2' in output)
assert_fs_integrity(fs_type, fs_img)
- def test_unlink2(self, u_boot_console, fs_obj_unlink):
+ def test_unlink2(self, ubman, fs_obj_unlink):
"""
Test Case 2 - delete many files
"""
- fs_type,fs_img = fs_obj_unlink
- with u_boot_console.log.section('Test Case 2 - unlink (many)'):
- output = u_boot_console.run_command('host bind 0 %s' % fs_img)
+ fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink
+ with ubman.log.section('Test Case 2 - unlink (many)'):
+ output = ubman.run_command('host bind 0 %s' % fs_img)
for i in range(0, 20):
- output = u_boot_console.run_command_list([
- '%srm host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i),
- '%sls host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i)])
+ output = ubman.run_command_list([
+ '%srm host 0:0 dir2/0123456789abcdef%02x' % (fs_cmd_prefix, i),
+ '%sls host 0:0 dir2/0123456789abcdef%02x' % (fs_cmd_prefix, i)])
assert('' == ''.join(output))
- output = u_boot_console.run_command(
- '%sls host 0:0 dir2' % fs_type)
+ output = ubman.run_command(
+ '%sls host 0:0 dir2' % fs_cmd_prefix)
assert('0 file(s), 2 dir(s)' in output)
assert_fs_integrity(fs_type, fs_img)
- def test_unlink3(self, u_boot_console, fs_obj_unlink):
+ def test_unlink3(self, ubman, fs_obj_unlink):
"""
Test Case 3 - trying to delete a non-existing file should fail
"""
- fs_type,fs_img = fs_obj_unlink
- with u_boot_console.log.section('Test Case 3 - unlink (non-existing)'):
- output = u_boot_console.run_command_list([
+ fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink
+ with ubman.log.section('Test Case 3 - unlink (non-existing)'):
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%srm host 0:0 dir1/nofile' % fs_type])
+ '%srm host 0:0 dir1/nofile' % fs_cmd_prefix])
assert('nofile: doesn\'t exist' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_unlink4(self, u_boot_console, fs_obj_unlink):
+ def test_unlink4(self, ubman, fs_obj_unlink):
"""
Test Case 4 - delete an empty directory
"""
- fs_type,fs_img = fs_obj_unlink
- with u_boot_console.log.section('Test Case 4 - unlink (directory)'):
- output = u_boot_console.run_command_list([
+ fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink
+ with ubman.log.section('Test Case 4 - unlink (directory)'):
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%srm host 0:0 dir4' % fs_type])
+ '%srm host 0:0 dir4' % fs_cmd_prefix])
assert('' == ''.join(output))
- output = u_boot_console.run_command(
- '%sls host 0:0 /' % fs_type)
+ output = ubman.run_command(
+ '%sls host 0:0 /' % fs_cmd_prefix)
assert(not 'dir4' in output)
assert_fs_integrity(fs_type, fs_img)
- def test_unlink5(self, u_boot_console, fs_obj_unlink):
+ def test_unlink5(self, ubman, fs_obj_unlink):
"""
Test Case 5 - trying to deleting a non-empty directory ".."
should fail
"""
- fs_type,fs_img = fs_obj_unlink
- with u_boot_console.log.section('Test Case 5 - unlink ("non-empty directory")'):
- output = u_boot_console.run_command_list([
+ fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink
+ with ubman.log.section('Test Case 5 - unlink ("non-empty directory")'):
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%srm host 0:0 dir5' % fs_type])
+ '%srm host 0:0 dir5' % fs_cmd_prefix])
assert('directory is not empty' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_unlink6(self, u_boot_console, fs_obj_unlink):
+ def test_unlink6(self, ubman, fs_obj_unlink):
"""
Test Case 6 - trying to deleting a "." should fail
"""
- fs_type,fs_img = fs_obj_unlink
- with u_boot_console.log.section('Test Case 6 - unlink (".")'):
- output = u_boot_console.run_command_list([
+ fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink
+ with ubman.log.section('Test Case 6 - unlink (".")'):
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%srm host 0:0 dir5/.' % fs_type])
+ '%srm host 0:0 dir5/.' % fs_cmd_prefix])
assert('directory is not empty' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
- def test_unlink7(self, u_boot_console, fs_obj_unlink):
+ def test_unlink7(self, ubman, fs_obj_unlink):
"""
Test Case 7 - trying to deleting a ".." should fail
"""
- fs_type,fs_img = fs_obj_unlink
- with u_boot_console.log.section('Test Case 7 - unlink ("..")'):
- output = u_boot_console.run_command_list([
+ fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink
+ with ubman.log.section('Test Case 7 - unlink ("..")'):
+ output = ubman.run_command_list([
'host bind 0 %s' % fs_img,
- '%srm host 0:0 dir5/..' % fs_type])
+ '%srm host 0:0 dir5/..' % fs_cmd_prefix])
assert('directory is not empty' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
diff --git a/test/py/tests/test_gpio.py b/test/py/tests/test_gpio.py
index 3e16e636574..46b674b7653 100644
--- a/test/py/tests/test_gpio.py
+++ b/test/py/tests/test_gpio.py
@@ -5,7 +5,7 @@
import pytest
import time
-import u_boot_utils
+import utils
"""
test_gpio_input is intended to test the fix 4dbc107f4683.
@@ -14,51 +14,51 @@ import u_boot_utils
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_gpio')
-def test_gpio_input(u_boot_console):
+def test_gpio_input(ubman):
"""Test that gpio input correctly returns the value of a gpio pin."""
- response = u_boot_console.run_command('gpio input 0; echo rc:$?')
+ response = ubman.run_command('gpio input 0; echo rc:$?')
expected_response = 'rc:0'
assert(expected_response in response)
- response = u_boot_console.run_command('gpio toggle 0; gpio input 0; echo rc:$?')
+ response = ubman.run_command('gpio toggle 0; gpio input 0; echo rc:$?')
expected_response = 'rc:1'
assert(expected_response in response)
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_gpio')
-def test_gpio_exit_statuses(u_boot_console):
+def test_gpio_exit_statuses(ubman):
"""Test that non-input gpio commands correctly return the command
success/failure status."""
expected_response = 'rc:0'
- response = u_boot_console.run_command('gpio clear 0; echo rc:$?')
+ response = ubman.run_command('gpio clear 0; echo rc:$?')
assert(expected_response in response)
- response = u_boot_console.run_command('gpio set 0; echo rc:$?')
+ response = ubman.run_command('gpio set 0; echo rc:$?')
assert(expected_response in response)
- response = u_boot_console.run_command('gpio toggle 0; echo rc:$?')
+ response = ubman.run_command('gpio toggle 0; echo rc:$?')
assert(expected_response in response)
- response = u_boot_console.run_command('gpio status -a; echo rc:$?')
+ response = ubman.run_command('gpio status -a; echo rc:$?')
assert(expected_response in response)
expected_response = 'rc:1'
- response = u_boot_console.run_command('gpio nonexistent-command; echo rc:$?')
+ response = ubman.run_command('gpio nonexistent-command; echo rc:$?')
assert(expected_response in response)
- response = u_boot_console.run_command('gpio input 200; echo rc:$?')
+ response = ubman.run_command('gpio input 200; echo rc:$?')
assert(expected_response in response)
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_gpio')
-def test_gpio_read(u_boot_console):
+def test_gpio_read(ubman):
"""Test that gpio read correctly sets the variable to the value of a gpio pin."""
- u_boot_console.run_command('gpio clear 0')
- response = u_boot_console.run_command('gpio read var 0; echo val:$var,rc:$?')
+ ubman.run_command('gpio clear 0')
+ response = ubman.run_command('gpio read var 0; echo val:$var,rc:$?')
expected_response = 'val:0,rc:0'
assert(expected_response in response)
- response = u_boot_console.run_command('gpio toggle 0; gpio read var 0; echo val:$var,rc:$?')
+ response = ubman.run_command('gpio toggle 0; gpio read var 0; echo val:$var,rc:$?')
expected_response = 'val:1,rc:0'
assert(expected_response in response)
- response = u_boot_console.run_command('setenv var; gpio read var nonexistent-gpio; echo val:$var,rc:$?')
+ response = ubman.run_command('setenv var; gpio read var nonexistent-gpio; echo val:$var,rc:$?')
expected_response = 'val:,rc:1'
assert(expected_response in response)
@@ -97,7 +97,7 @@ env__gpio_dev_config = {
@pytest.mark.buildconfigspec('cmd_gpio')
-def test_gpio_status_all_generic(u_boot_console):
+def test_gpio_status_all_generic(ubman):
"""Test the 'gpio status' command.
Displays all gpio pins available on the Board.
@@ -108,7 +108,7 @@ def test_gpio_status_all_generic(u_boot_console):
number of such pins and mention that count in 'gpio_str_count'.
"""
- f = u_boot_console.config.env.get('env__gpio_dev_config',False)
+ f = ubman.config.env.get('env__gpio_dev_config',False)
if not f:
pytest.skip("gpio not configured")
@@ -116,14 +116,14 @@ def test_gpio_status_all_generic(u_boot_console):
#Display all the GPIO ports
cmd = 'gpio status -a'
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
for str_value in range(1,gpio_str_count + 1):
assert f["gpio_str_%d" %(str_value)] in response
@pytest.mark.buildconfigspec('cmd_gpio')
-def test_gpio_set_generic(u_boot_console):
+def test_gpio_set_generic(ubman):
"""Test the 'gpio set' command.
A specific gpio pin configured by user as output
@@ -132,7 +132,7 @@ def test_gpio_set_generic(u_boot_console):
"""
- f = u_boot_console.config.env.get('env__gpio_dev_config',False)
+ f = ubman.config.env.get('env__gpio_dev_config',False)
if not f:
pytest.skip("gpio not configured")
@@ -141,14 +141,14 @@ def test_gpio_set_generic(u_boot_console):
cmd = 'gpio set ' + gpio_pin_adr
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
good_response = gpio_set_value
assert good_response in response
@pytest.mark.buildconfigspec('cmd_gpio')
-def test_gpio_clear_generic(u_boot_console):
+def test_gpio_clear_generic(ubman):
"""Test the 'gpio clear' command.
A specific gpio pin configured by user as output
@@ -156,7 +156,7 @@ def test_gpio_clear_generic(u_boot_console):
'clear' option
"""
- f = u_boot_console.config.env.get('env__gpio_dev_config',False)
+ f = ubman.config.env.get('env__gpio_dev_config',False)
if not f:
pytest.skip("gpio not configured")
@@ -165,13 +165,13 @@ def test_gpio_clear_generic(u_boot_console):
cmd = 'gpio clear ' + gpio_pin_adr
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
good_response = gpio_clear_value
assert good_response in response
@pytest.mark.buildconfigspec('cmd_gpio')
-def test_gpio_toggle_generic(u_boot_console):
+def test_gpio_toggle_generic(ubman):
"""Test the 'gpio toggle' command.
A specific gpio pin configured by user as output
@@ -180,7 +180,7 @@ def test_gpio_toggle_generic(u_boot_console):
"""
- f = u_boot_console.config.env.get('env__gpio_dev_config',False)
+ f = ubman.config.env.get('env__gpio_dev_config',False)
if not f:
pytest.skip("gpio not configured")
@@ -189,18 +189,18 @@ def test_gpio_toggle_generic(u_boot_console):
gpio_clear_value = f['gpio_clear_value'];
cmd = 'gpio set ' + gpio_pin_adr
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
good_response = gpio_set_value
assert good_response in response
cmd = 'gpio toggle ' + gpio_pin_adr
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
good_response = gpio_clear_value
assert good_response in response
@pytest.mark.buildconfigspec('cmd_gpio')
-def test_gpio_input_generic(u_boot_console):
+def test_gpio_input_generic(ubman):
"""Test the 'gpio input' command.
Specific gpio pins configured by user as input
@@ -208,7 +208,7 @@ def test_gpio_input_generic(u_boot_console):
is verified for logic '1' and logic '0' states
"""
- f = u_boot_console.config.env.get('env__gpio_dev_config',False)
+ f = ubman.config.env.get('env__gpio_dev_config',False)
if not f:
pytest.skip("gpio not configured")
@@ -217,7 +217,7 @@ def test_gpio_input_generic(u_boot_console):
cmd = 'gpio input ' + gpio_pin_adr
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
good_response = gpio_clear_value
assert good_response in response
@@ -227,12 +227,12 @@ def test_gpio_input_generic(u_boot_console):
cmd = 'gpio input ' + gpio_pin_adr
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
good_response = gpio_set_value
assert good_response in response
@pytest.mark.buildconfigspec('cmd_gpio')
-def test_gpio_pins_generic(u_boot_console):
+def test_gpio_pins_generic(ubman):
"""Test various gpio related functionality, such as the input, set, clear,
and toggle for the set of gpio pin list.
@@ -241,7 +241,7 @@ def test_gpio_pins_generic(u_boot_console):
commands.
"""
- f = u_boot_console.config.env.get('env__gpio_dev_config', False)
+ f = ubman.config.env.get('env__gpio_dev_config', False)
if not f:
pytest.skip('gpio not configured')
@@ -251,31 +251,31 @@ def test_gpio_pins_generic(u_boot_console):
for gpin in gpio_pins:
# gpio input
- u_boot_console.run_command(f'gpio input {gpin}')
+ ubman.run_command(f'gpio input {gpin}')
expected_response = f'{gpin}: input:'
- response = u_boot_console.run_command(f'gpio status -a {gpin}')
+ response = ubman.run_command(f'gpio status -a {gpin}')
assert expected_response in response
# gpio set
- u_boot_console.run_command(f'gpio set {gpin}')
+ ubman.run_command(f'gpio set {gpin}')
expected_response = f'{gpin}: output: 1'
- response = u_boot_console.run_command(f'gpio status -a {gpin}')
+ response = ubman.run_command(f'gpio status -a {gpin}')
assert expected_response in response
# gpio clear
- u_boot_console.run_command(f'gpio clear {gpin}')
+ ubman.run_command(f'gpio clear {gpin}')
expected_response = f'{gpin}: output: 0'
- response = u_boot_console.run_command(f'gpio status -a {gpin}')
+ response = ubman.run_command(f'gpio status -a {gpin}')
assert expected_response in response
# gpio toggle
- u_boot_console.run_command(f'gpio toggle {gpin}')
+ ubman.run_command(f'gpio toggle {gpin}')
expected_response = f'{gpin}: output: 1'
- response = u_boot_console.run_command(f'gpio status -a {gpin}')
+ response = ubman.run_command(f'gpio status -a {gpin}')
assert expected_response in response
@pytest.mark.buildconfigspec('cmd_gpio')
-def test_gpio_pins_input_output_generic(u_boot_console):
+def test_gpio_pins_input_output_generic(ubman):
"""Test gpio related functionality such as input and output for the list of
shorted gpio pins provided as a pair of input and output pins. This test
will fail, if the gpio pins are not shorted properly.
@@ -285,7 +285,7 @@ def test_gpio_pins_input_output_generic(u_boot_console):
pair to be tested for gpio input output case.
"""
- f = u_boot_console.config.env.get('env__gpio_dev_config', False)
+ f = ubman.config.env.get('env__gpio_dev_config', False)
if not f:
pytest.skip('gpio not configured')
@@ -294,22 +294,22 @@ def test_gpio_pins_input_output_generic(u_boot_console):
pytest.skip('gpio pin list for input and output are not configured')
for gpins in gpio_pins:
- u_boot_console.run_command(f'gpio input {gpins[0]}')
+ ubman.run_command(f'gpio input {gpins[0]}')
expected_response = f'{gpins[0]}: input:'
- response = u_boot_console.run_command(f'gpio status -a {gpins[0]}')
+ response = ubman.run_command(f'gpio status -a {gpins[0]}')
assert expected_response in response
- u_boot_console.run_command(f'gpio set {gpins[1]}')
+ ubman.run_command(f'gpio set {gpins[1]}')
expected_response = f'{gpins[1]}: output:'
- response = u_boot_console.run_command(f'gpio status -a {gpins[1]}')
+ response = ubman.run_command(f'gpio status -a {gpins[1]}')
assert expected_response in response
- u_boot_console.run_command(f'gpio clear {gpins[1]}')
+ ubman.run_command(f'gpio clear {gpins[1]}')
expected_response = f'{gpins[0]}: input: 0'
- response = u_boot_console.run_command(f'gpio status -a {gpins[0]}')
+ response = ubman.run_command(f'gpio status -a {gpins[0]}')
assert expected_response in response
- u_boot_console.run_command(f'gpio set {gpins[1]}')
+ ubman.run_command(f'gpio set {gpins[1]}')
expected_response = f'{gpins[0]}: input: 1'
- response = u_boot_console.run_command(f'gpio status -a {gpins[0]}')
+ response = ubman.run_command(f'gpio status -a {gpins[0]}')
assert expected_response in response
diff --git a/test/py/tests/test_gpt.py b/test/py/tests/test_gpt.py
index 6e135b663e8..cfc8f1319a9 100644
--- a/test/py/tests/test_gpt.py
+++ b/test/py/tests/test_gpt.py
@@ -6,7 +6,7 @@
import os
import pytest
-import u_boot_utils
+import utils
"""
These tests rely on a 4 MB disk image, which is automatically created by
@@ -48,11 +48,11 @@ def parse_gpt_parts(disk_str):
class GptTestDiskImage(object):
"""Disk Image used by the GPT tests."""
- def __init__(self, u_boot_console):
+ def __init__(self, ubman):
"""Initialize a new GptTestDiskImage object.
Args:
- u_boot_console: A U-Boot console.
+ ubman: A U-Boot console.
Returns:
Nothing.
@@ -60,62 +60,62 @@ class GptTestDiskImage(object):
filename = 'test_gpt_disk_image.bin'
- persistent = u_boot_console.config.persistent_data_dir + '/' + filename
- self.path = u_boot_console.config.result_dir + '/' + filename
+ persistent = ubman.config.persistent_data_dir + '/' + filename
+ self.path = ubman.config.result_dir + '/' + filename
- with u_boot_utils.persistent_file_helper(u_boot_console.log, persistent):
+ with utils.persistent_file_helper(ubman.log, persistent):
if os.path.exists(persistent):
- u_boot_console.log.action('Disk image file ' + persistent +
+ ubman.log.action('Disk image file ' + persistent +
' already exists')
else:
- u_boot_console.log.action('Generating ' + persistent)
+ ubman.log.action('Generating ' + persistent)
fd = os.open(persistent, os.O_RDWR | os.O_CREAT)
os.ftruncate(fd, 4194304)
os.close(fd)
cmd = ('sgdisk',
'--disk-guid=375a56f7-d6c9-4e81-b5f0-09d41ca89efe',
persistent)
- u_boot_utils.run_and_log(u_boot_console, cmd)
+ utils.run_and_log(ubman, cmd)
# part1 offset 1MB size 1MB
cmd = ('sgdisk', '--new=1:2048:4095', '--change-name=1:part1',
'--partition-guid=1:33194895-67f6-4561-8457-6fdeed4f50a3',
'-A 1:set:2',
persistent)
# part2 offset 2MB size 1.5MB
- u_boot_utils.run_and_log(u_boot_console, cmd)
+ utils.run_and_log(ubman, cmd)
cmd = ('sgdisk', '--new=2:4096:7167', '--change-name=2:part2',
'--partition-guid=2:cc9c6e4a-6551-4cb5-87be-3210f96c86fb',
persistent)
- u_boot_utils.run_and_log(u_boot_console, cmd)
+ utils.run_and_log(ubman, cmd)
cmd = ('sgdisk', '--load-backup=' + persistent)
- u_boot_utils.run_and_log(u_boot_console, cmd)
+ utils.run_and_log(ubman, cmd)
cmd = ('cp', persistent, self.path)
- u_boot_utils.run_and_log(u_boot_console, cmd)
+ utils.run_and_log(ubman, cmd)
@pytest.fixture(scope='function')
-def state_disk_image(u_boot_console):
+def state_disk_image(ubman):
"""pytest fixture to provide a GptTestDiskImage object to tests.
- This is function-scoped because it uses u_boot_console, which is also
+ This is function-scoped because it uses ubman, which is also
function-scoped. A new disk is returned each time to prevent tests from
interfering with each other."""
- return GptTestDiskImage(u_boot_console)
+ return GptTestDiskImage(ubman)
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_gpt')
@pytest.mark.buildconfigspec('cmd_part')
@pytest.mark.requiredtool('sgdisk')
-def test_gpt_read(state_disk_image, u_boot_console):
+def test_gpt_read(state_disk_image, ubman):
"""Test the gpt read command."""
- u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
- output = u_boot_console.run_command('gpt read host 0')
+ ubman.run_command('host bind 0 ' + state_disk_image.path)
+ output = ubman.run_command('gpt read host 0')
assert 'Start 1MiB, size 1MiB' in output
assert 'Block size 512, name part1' in output
assert 'Start 2MiB, size 1MiB' in output
assert 'Block size 512, name part2' in output
- output = u_boot_console.run_command('part list host 0')
+ output = ubman.run_command('part list host 0')
assert '0x00000800 0x00000fff "part1"' in output
assert '0x00001000 0x00001bff "part2"' in output
@@ -123,14 +123,14 @@ def test_gpt_read(state_disk_image, u_boot_console):
@pytest.mark.buildconfigspec('cmd_gpt')
@pytest.mark.buildconfigspec('partition_type_guid')
@pytest.mark.requiredtool('sgdisk')
-def test_gpt_read_var(state_disk_image, u_boot_console):
+def test_gpt_read_var(state_disk_image, ubman):
"""Test the gpt read command."""
- u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
- output = u_boot_console.run_command('gpt read host 0 gpt_parts')
+ ubman.run_command('host bind 0 ' + state_disk_image.path)
+ output = ubman.run_command('gpt read host 0 gpt_parts')
assert 'success!' in output
- output = u_boot_console.run_command('echo ${gpt_parts}')
+ output = ubman.run_command('echo ${gpt_parts}')
parts = parse_gpt_parts(output.rstrip())
assert parts == [
@@ -157,99 +157,99 @@ def test_gpt_read_var(state_disk_image, u_boot_console):
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_gpt')
@pytest.mark.requiredtool('sgdisk')
-def test_gpt_verify(state_disk_image, u_boot_console):
+def test_gpt_verify(state_disk_image, ubman):
"""Test the gpt verify command."""
- u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
- output = u_boot_console.run_command('gpt verify host 0')
+ ubman.run_command('host bind 0 ' + state_disk_image.path)
+ output = ubman.run_command('gpt verify host 0')
assert 'Verify GPT: success!' in output
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_gpt')
@pytest.mark.requiredtool('sgdisk')
-def test_gpt_repair(state_disk_image, u_boot_console):
+def test_gpt_repair(state_disk_image, ubman):
"""Test the gpt repair command."""
- u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
- output = u_boot_console.run_command('gpt repair host 0')
+ ubman.run_command('host bind 0 ' + state_disk_image.path)
+ output = ubman.run_command('gpt repair host 0')
assert 'Repairing GPT: success!' in output
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_gpt')
@pytest.mark.requiredtool('sgdisk')
-def test_gpt_guid(state_disk_image, u_boot_console):
+def test_gpt_guid(state_disk_image, ubman):
"""Test the gpt guid command."""
- u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
- output = u_boot_console.run_command('gpt guid host 0')
+ ubman.run_command('host bind 0 ' + state_disk_image.path)
+ output = ubman.run_command('gpt guid host 0')
assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_gpt')
@pytest.mark.requiredtool('sgdisk')
-def test_gpt_setenv(state_disk_image, u_boot_console):
+def test_gpt_setenv(state_disk_image, ubman):
"""Test the gpt setenv command."""
- u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
- output = u_boot_console.run_command('gpt setenv host 0 part1')
+ ubman.run_command('host bind 0 ' + state_disk_image.path)
+ output = ubman.run_command('gpt setenv host 0 part1')
assert 'success!' in output
- output = u_boot_console.run_command('echo ${gpt_partition_addr}')
+ output = ubman.run_command('echo ${gpt_partition_addr}')
assert output.rstrip() == '800'
- output = u_boot_console.run_command('echo ${gpt_partition_size}')
+ output = ubman.run_command('echo ${gpt_partition_size}')
assert output.rstrip() == '800'
- output = u_boot_console.run_command('echo ${gpt_partition_name}')
+ output = ubman.run_command('echo ${gpt_partition_name}')
assert output.rstrip() == 'part1'
- output = u_boot_console.run_command('echo ${gpt_partition_entry}')
+ output = ubman.run_command('echo ${gpt_partition_entry}')
assert output.rstrip() == '1'
- output = u_boot_console.run_command('echo ${gpt_partition_bootable}')
+ output = ubman.run_command('echo ${gpt_partition_bootable}')
assert output.rstrip() == '1'
- output = u_boot_console.run_command('gpt setenv host 0 part2')
+ output = ubman.run_command('gpt setenv host 0 part2')
assert 'success!' in output
- output = u_boot_console.run_command('echo ${gpt_partition_addr}')
+ output = ubman.run_command('echo ${gpt_partition_addr}')
assert output.rstrip() == '1000'
- output = u_boot_console.run_command('echo ${gpt_partition_size}')
+ output = ubman.run_command('echo ${gpt_partition_size}')
assert output.rstrip() == 'c00'
- output = u_boot_console.run_command('echo ${gpt_partition_name}')
+ output = ubman.run_command('echo ${gpt_partition_name}')
assert output.rstrip() == 'part2'
- output = u_boot_console.run_command('echo ${gpt_partition_entry}')
+ output = ubman.run_command('echo ${gpt_partition_entry}')
assert output.rstrip() == '2'
- output = u_boot_console.run_command('echo ${gpt_partition_bootable}')
+ output = ubman.run_command('echo ${gpt_partition_bootable}')
assert output.rstrip() == '0'
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_gpt')
@pytest.mark.requiredtool('sgdisk')
-def test_gpt_save_guid(state_disk_image, u_boot_console):
+def test_gpt_save_guid(state_disk_image, ubman):
"""Test the gpt guid command to save GUID into a string."""
- if u_boot_console.config.buildconfig.get('config_cmd_gpt', 'n') != 'y':
+ if ubman.config.buildconfig.get('config_cmd_gpt', 'n') != 'y':
pytest.skip('gpt command not supported')
- u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
- output = u_boot_console.run_command('gpt guid host 0 newguid')
- output = u_boot_console.run_command('printenv newguid')
+ ubman.run_command('host bind 0 ' + state_disk_image.path)
+ output = ubman.run_command('gpt guid host 0 newguid')
+ output = ubman.run_command('printenv newguid')
assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_gpt')
@pytest.mark.requiredtool('sgdisk')
-def test_gpt_part_type_uuid(state_disk_image, u_boot_console):
+def test_gpt_part_type_uuid(state_disk_image, ubman):
"""Test the gpt partittion type UUID command."""
- u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
- output = u_boot_console.run_command('part type host 0:1')
+ ubman.run_command('host bind 0 ' + state_disk_image.path)
+ output = ubman.run_command('part type host 0:1')
assert '0fc63daf-8483-4772-8e79-3d69d8477de4' in output
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_gpt')
@pytest.mark.requiredtool('sgdisk')
-def test_gpt_part_type_save_uuid(state_disk_image, u_boot_console):
+def test_gpt_part_type_save_uuid(state_disk_image, ubman):
"""Test the gpt partittion type to save UUID into a string."""
- if u_boot_console.config.buildconfig.get('config_cmd_gpt', 'n') != 'y':
+ if ubman.config.buildconfig.get('config_cmd_gpt', 'n') != 'y':
pytest.skip('gpt command not supported')
- u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
- output = u_boot_console.run_command('part type host 0:1 newguid')
- output = u_boot_console.run_command('printenv newguid')
+ ubman.run_command('host bind 0 ' + state_disk_image.path)
+ output = ubman.run_command('part type host 0:1 newguid')
+ output = ubman.run_command('printenv newguid')
assert '0fc63daf-8483-4772-8e79-3d69d8477de4' in output
@pytest.mark.boardspec('sandbox')
@@ -257,17 +257,17 @@ def test_gpt_part_type_save_uuid(state_disk_image, u_boot_console):
@pytest.mark.buildconfigspec('cmd_gpt_rename')
@pytest.mark.buildconfigspec('cmd_part')
@pytest.mark.requiredtool('sgdisk')
-def test_gpt_rename_partition(state_disk_image, u_boot_console):
+def test_gpt_rename_partition(state_disk_image, ubman):
"""Test the gpt rename command to write partition names."""
- u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
- u_boot_console.run_command('gpt rename host 0 1 first')
- output = u_boot_console.run_command('gpt read host 0')
+ ubman.run_command('host bind 0 ' + state_disk_image.path)
+ ubman.run_command('gpt rename host 0 1 first')
+ output = ubman.run_command('gpt read host 0')
assert 'name first' in output
- u_boot_console.run_command('gpt rename host 0 2 second')
- output = u_boot_console.run_command('gpt read host 0')
+ ubman.run_command('gpt rename host 0 2 second')
+ output = ubman.run_command('gpt read host 0')
assert 'name second' in output
- output = u_boot_console.run_command('part list host 0')
+ output = ubman.run_command('part list host 0')
assert '0x00000800 0x00000fff "first"' in output
assert '0x00001000 0x00001bff "second"' in output
@@ -276,15 +276,15 @@ def test_gpt_rename_partition(state_disk_image, u_boot_console):
@pytest.mark.buildconfigspec('cmd_gpt_rename')
@pytest.mark.buildconfigspec('cmd_part')
@pytest.mark.requiredtool('sgdisk')
-def test_gpt_swap_partitions(state_disk_image, u_boot_console):
+def test_gpt_swap_partitions(state_disk_image, ubman):
"""Test the gpt swap command to exchange two partition names."""
- u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
- output = u_boot_console.run_command('part list host 0')
+ ubman.run_command('host bind 0 ' + state_disk_image.path)
+ output = ubman.run_command('part list host 0')
assert '0x00000800 0x00000fff "part1"' in output
assert '0x00001000 0x00001bff "part2"' in output
- u_boot_console.run_command('gpt swap host 0 part1 part2')
- output = u_boot_console.run_command('part list host 0')
+ ubman.run_command('gpt swap host 0 part1 part2')
+ output = ubman.run_command('part list host 0')
assert '0x00000800 0x00000fff "part2"' in output
assert '0x00001000 0x00001bff "part1"' in output
@@ -292,19 +292,19 @@ def test_gpt_swap_partitions(state_disk_image, u_boot_console):
@pytest.mark.buildconfigspec('cmd_gpt_rename')
@pytest.mark.buildconfigspec('cmd_part')
@pytest.mark.requiredtool('sgdisk')
-def test_gpt_set_bootable(state_disk_image, u_boot_console):
+def test_gpt_set_bootable(state_disk_image, ubman):
"""Test the gpt set-bootable command."""
- u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
+ ubman.run_command('host bind 0 ' + state_disk_image.path)
parts = ('part2', 'part1')
for bootable in parts:
- output = u_boot_console.run_command(f'gpt set-bootable host 0 {bootable}')
+ output = ubman.run_command(f'gpt set-bootable host 0 {bootable}')
assert 'success!' in output
for p in parts:
- output = u_boot_console.run_command(f'gpt setenv host 0 {p}')
+ output = ubman.run_command(f'gpt setenv host 0 {p}')
assert 'success!' in output
- output = u_boot_console.run_command('echo ${gpt_partition_bootable}')
+ output = ubman.run_command('echo ${gpt_partition_bootable}')
if p == bootable:
assert output.rstrip() == '1'
else:
@@ -314,37 +314,37 @@ def test_gpt_set_bootable(state_disk_image, u_boot_console):
@pytest.mark.buildconfigspec('cmd_gpt')
@pytest.mark.buildconfigspec('cmd_part')
@pytest.mark.requiredtool('sgdisk')
-def test_gpt_write(state_disk_image, u_boot_console):
+def test_gpt_write(state_disk_image, ubman):
"""Test the gpt write command."""
- u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
- output = u_boot_console.run_command('gpt write host 0 "name=all,size=0"')
+ ubman.run_command('host bind 0 ' + state_disk_image.path)
+ output = ubman.run_command('gpt write host 0 "name=all,size=0"')
assert 'Writing GPT: success!' in output
- output = u_boot_console.run_command('part list host 0')
+ output = ubman.run_command('part list host 0')
assert '0x00000022 0x00001fde "all"' in output
- output = u_boot_console.run_command('gpt write host 0 "uuid_disk=375a56f7-d6c9-4e81-b5f0-09d41ca89efe;name=first,start=1M,size=1M;name=second,start=0x200000,size=0x180000;"')
+ output = ubman.run_command('gpt write host 0 "uuid_disk=375a56f7-d6c9-4e81-b5f0-09d41ca89efe;name=first,start=1M,size=1M;name=second,start=0x200000,size=0x180000;"')
assert 'Writing GPT: success!' in output
- output = u_boot_console.run_command('part list host 0')
+ output = ubman.run_command('part list host 0')
assert '0x00000800 0x00000fff "first"' in output
assert '0x00001000 0x00001bff "second"' in output
- output = u_boot_console.run_command('gpt guid host 0')
+ output = ubman.run_command('gpt guid host 0')
assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output
@pytest.mark.buildconfigspec('cmd_gpt')
@pytest.mark.buildconfigspec('cmd_gpt_rename')
@pytest.mark.buildconfigspec('cmd_part')
@pytest.mark.requiredtool('sgdisk')
-def test_gpt_transpose(state_disk_image, u_boot_console):
+def test_gpt_transpose(state_disk_image, ubman):
"""Test the gpt transpose command."""
- u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
- output = u_boot_console.run_command('part list host 0')
+ ubman.run_command('host bind 0 ' + state_disk_image.path)
+ output = ubman.run_command('part list host 0')
assert '1\t0x00000800\t0x00000fff\t"part1"' in output
assert '2\t0x00001000\t0x00001bff\t"part2"' in output
- output = u_boot_console.run_command('gpt transpose host 0 1 2')
+ output = ubman.run_command('gpt transpose host 0 1 2')
assert 'success!' in output
- output = u_boot_console.run_command('part list host 0')
+ output = ubman.run_command('part list host 0')
assert '2\t0x00000800\t0x00000fff\t"part1"' in output
assert '1\t0x00001000\t0x00001bff\t"part2"' in output
diff --git a/test/py/tests/test_handoff.py b/test/py/tests/test_handoff.py
index 038f03064a6..becd7d75cf7 100644
--- a/test/py/tests/test_handoff.py
+++ b/test/py/tests/test_handoff.py
@@ -8,8 +8,7 @@ TEST_HANDOFF_MAGIC = 0x14f93c7b
@pytest.mark.boardspec('sandbox_spl')
@pytest.mark.buildconfigspec('spl')
-def test_handoff(u_boot_console):
+def test_handoff(ubman):
"""Test that of-platdata can be generated and used in sandbox"""
- cons = u_boot_console
- response = cons.run_command('sb handoff')
+ response = ubman.run_command('sb handoff')
assert ('SPL handoff magic %x' % TEST_HANDOFF_MAGIC) in response
diff --git a/test/py/tests/test_help.py b/test/py/tests/test_help.py
index 153133cf28f..12cb36b7b98 100644
--- a/test/py/tests/test_help.py
+++ b/test/py/tests/test_help.py
@@ -4,31 +4,33 @@
import pytest
-def test_help(u_boot_console):
+def test_help(ubman):
"""Test that the "help" command can be executed."""
- u_boot_console.run_command('help')
+ lines = ubman.run_command('help')
+ if ubman.config.buildconfig.get('config_cmd_2048', 'n') == 'y':
+ assert lines.splitlines()[0] == "2048 - The 2048 game"
+ else:
+ assert lines.splitlines()[0] == "? - alias for 'help'"
@pytest.mark.boardspec('sandbox')
-def test_help_no_devicetree(u_boot_console):
+def test_help_no_devicetree(ubman):
try:
- cons = u_boot_console
- cons.restart_uboot_with_flags([], use_dtb=False)
- cons.run_command('help')
- output = cons.get_spawn_output().replace('\r', '')
+ ubman.restart_uboot_with_flags([], use_dtb=False)
+ ubman.run_command('help')
+ output = ubman.get_spawn_output().replace('\r', '')
assert 'print command description/usage' in output
finally:
# Restart afterward to get the normal device tree back
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
@pytest.mark.boardspec('sandbox_vpl')
-def test_vpl_help(u_boot_console):
+def test_vpl_help(ubman):
try:
- cons = u_boot_console
- cons.restart_uboot()
- cons.run_command('help')
- output = cons.get_spawn_output().replace('\r', '')
+ ubman.restart_uboot()
+ ubman.run_command('help')
+ output = ubman.get_spawn_output().replace('\r', '')
assert 'print command description/usage' in output
finally:
# Restart afterward to get the normal device tree back
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
diff --git a/test/py/tests/test_i2c.py b/test/py/tests/test_i2c.py
index 825d0c2e6eb..69b11930ce7 100644
--- a/test/py/tests/test_i2c.py
+++ b/test/py/tests/test_i2c.py
@@ -31,8 +31,8 @@ env__i2c_eeprom_device_test = {
}
"""
-def get_i2c_test_env(u_boot_console):
- f = u_boot_console.config.env.get("env__i2c_device_test", None)
+def get_i2c_test_env(ubman):
+ f = ubman.config.env.get("env__i2c_device_test", None)
if not f:
pytest.skip("No I2C device to test!")
else:
@@ -43,34 +43,34 @@ def get_i2c_test_env(u_boot_console):
return bus_list, probe_all
@pytest.mark.buildconfigspec("cmd_i2c")
-def test_i2c_bus(u_boot_console):
- bus_list, probe = get_i2c_test_env(u_boot_console)
+def test_i2c_bus(ubman):
+ bus_list, probe = get_i2c_test_env(ubman)
bus = random.choice(bus_list)
expected_response = f"Bus {bus}:"
- response = u_boot_console.run_command("i2c bus")
+ response = ubman.run_command("i2c bus")
assert expected_response in response
@pytest.mark.buildconfigspec("cmd_i2c")
-def test_i2c_dev(u_boot_console):
- bus_list, probe = get_i2c_test_env(u_boot_console)
+def test_i2c_dev(ubman):
+ bus_list, probe = get_i2c_test_env(ubman)
expected_response = "Current bus is"
- response = u_boot_console.run_command("i2c dev")
+ response = ubman.run_command("i2c dev")
assert expected_response in response
@pytest.mark.buildconfigspec("cmd_i2c")
-def test_i2c_probe(u_boot_console):
- bus_list, probe = get_i2c_test_env(u_boot_console)
+def test_i2c_probe(ubman):
+ bus_list, probe = get_i2c_test_env(ubman)
bus = random.choice(bus_list)
expected_response = f"Setting bus to {bus}"
- response = u_boot_console.run_command(f"i2c dev {bus}")
+ response = ubman.run_command(f"i2c dev {bus}")
assert expected_response in response
expected_response = "Valid chip addresses:"
- response = u_boot_console.run_command("i2c probe")
+ response = ubman.run_command("i2c probe")
assert expected_response in response
@pytest.mark.buildconfigspec("cmd_i2c")
-def test_i2c_eeprom(u_boot_console):
- f = u_boot_console.config.env.get("env__i2c_eeprom_device_test", None)
+def test_i2c_eeprom(ubman):
+ f = ubman.config.env.get("env__i2c_eeprom_device_test", None)
if not f:
pytest.skip("No I2C eeprom to test!")
@@ -89,17 +89,17 @@ def test_i2c_eeprom(u_boot_console):
)
# Enable i2c mux bridge
- u_boot_console.run_command("i2c dev %x" % bus)
- u_boot_console.run_command("i2c probe")
- output = u_boot_console.run_command("i2c md %x 0 5" % addr)
+ ubman.run_command("i2c dev %x" % bus)
+ ubman.run_command("i2c probe")
+ output = ubman.run_command("i2c md %x 0 5" % addr)
assert value in output
@pytest.mark.buildconfigspec("cmd_i2c")
-def test_i2c_probe_all_buses(u_boot_console):
- bus_list, probe = get_i2c_test_env(u_boot_console)
+def test_i2c_probe_all_buses(ubman):
+ bus_list, probe = get_i2c_test_env(ubman)
bus = random.choice(bus_list)
expected_response = f"Bus {bus}:"
- response = u_boot_console.run_command("i2c bus")
+ response = ubman.run_command("i2c bus")
assert expected_response in response
# Get all the bus list
@@ -109,8 +109,8 @@ def test_i2c_probe_all_buses(u_boot_console):
for dev in bus_list:
expected_response = f"Setting bus to {dev}"
- response = u_boot_console.run_command(f"i2c dev {dev}")
+ response = ubman.run_command(f"i2c dev {dev}")
assert expected_response in response
expected_response = "Valid chip addresses:"
- response = u_boot_console.run_command("i2c probe")
+ response = ubman.run_command("i2c probe")
assert expected_response in response
diff --git a/test/py/tests/test_kconfig.py b/test/py/tests/test_kconfig.py
index 0b9e6bc3bd1..0c261d47975 100644
--- a/test/py/tests/test_kconfig.py
+++ b/test/py/tests/test_kconfig.py
@@ -4,33 +4,31 @@
import pytest
-import u_boot_utils as util
+import utils
# This is needed for Azure, since the default '..' directory is not writeable
TMPDIR = '/tmp/test_kconfig'
@pytest.mark.slow
@pytest.mark.boardspec('sandbox')
-def test_kconfig(u_boot_console):
+def test_kconfig(ubman):
"""Test build failures when IF_ENABLED_INT() option is not enabled"""
- cons = u_boot_console
# This detects build errors in test/lib/kconfig.c
- out = util.run_and_log(
- cons, ['./tools/buildman/buildman', '-m', '--board', 'sandbox',
+ out = utils.run_and_log(
+ ubman, ['./tools/buildman/buildman', '-m', '--board', 'sandbox',
'-a', 'TEST_KCONFIG', '-o', TMPDIR], ignore_errors=True)
assert 'invalid_use_of_IF_ENABLED_INT' in out
assert 'invalid_use_of_CONFIG_IF_ENABLED_INT' in out
@pytest.mark.slow
@pytest.mark.boardspec('sandbox_spl')
-def test_kconfig_spl(u_boot_console):
+def test_kconfig_spl(ubman):
"""Test build failures when IF_ENABLED_INT() option is not enabled"""
- cons = u_boot_console
# This detects build errors in test/lib/kconfig_spl.c
- out = util.run_and_log(
- cons, ['./tools/buildman/buildman', '-m', '--board', 'sandbox_spl',
+ out = utils.run_and_log(
+ ubman, ['./tools/buildman/buildman', '-m', '--board', 'sandbox_spl',
'-a', 'TEST_KCONFIG', '-o', TMPDIR], ignore_errors=True)
assert 'invalid_use_of_IF_ENABLED_INT' in out
diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py
index 140dcb9aa2b..4558b037e2a 100644
--- a/test/py/tests/test_log.py
+++ b/test/py/tests/test_log.py
@@ -11,7 +11,7 @@ and checks that the output is correct.
import pytest
@pytest.mark.buildconfigspec('cmd_log')
-def test_log_format(u_boot_console):
+def test_log_format(ubman):
"""Test the 'log format' and 'log rec' commands"""
def run_with_format(fmt, expected_output):
"""Set up the log format and then write a log record
@@ -20,29 +20,30 @@ def test_log_format(u_boot_console):
fmt: Format to use for 'log format'
expected_output: Expected output from the 'log rec' command
"""
- output = cons.run_command('log format %s' % fmt)
+ output = ubman.run_command('log format %s' % fmt)
assert output == ''
- output = cons.run_command('log rec arch notice file.c 123 func msg')
+ output = ubman.run_command('log rec arch notice file.c 123 func msg')
assert output == expected_output
- cons = u_boot_console
- with cons.log.section('format'):
- run_with_format('all', 'NOTICE.arch,file.c:123-func() msg')
- output = cons.run_command('log format')
+ with ubman.log.section('format'):
+ pad = int(ubman.config.buildconfig.get('config_logf_func_pad'))
+ padding = ' ' * (pad - len('func'))
+
+ run_with_format('all', f'NOTICE.arch,file.c:123-{padding}func() msg')
+ output = ubman.run_command('log format')
assert output == 'Log format: clFLfm'
- run_with_format('fm', 'func() msg')
- run_with_format('clfm', 'NOTICE.arch,func() msg')
- run_with_format('FLfm', 'file.c:123-func() msg')
+ run_with_format('fm', f'{padding}func() msg')
+ run_with_format('clfm', f'NOTICE.arch,{padding}func() msg')
+ run_with_format('FLfm', f'file.c:123-{padding}func() msg')
run_with_format('lm', 'NOTICE. msg')
run_with_format('m', 'msg')
@pytest.mark.buildconfigspec('debug_uart')
@pytest.mark.boardspec('sandbox')
-def test_log_dropped(u_boot_console):
+def test_log_dropped(ubman):
"""Test dropped 'log' message when debug_uart is activated"""
- cons = u_boot_console
- cons.restart_uboot()
- output = cons.get_spawn_output().replace('\r', '')
+ ubman.restart_uboot()
+ output = ubman.get_spawn_output().replace('\r', '')
assert (not 'debug: main' in output)
diff --git a/test/py/tests/test_lsblk.py b/test/py/tests/test_lsblk.py
index a719a48e6ee..babd4f9528b 100644
--- a/test/py/tests/test_lsblk.py
+++ b/test/py/tests/test_lsblk.py
@@ -7,8 +7,8 @@ import pytest
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('blk')
@pytest.mark.buildconfigspec('cmd_lsblk')
-def test_lsblk(u_boot_console):
+def test_lsblk(ubman):
"""Test that `lsblk` prints a result which includes `host`."""
- output = u_boot_console.run_command('lsblk')
+ output = ubman.run_command('lsblk')
assert "Block Driver" in output
assert "sandbox_host_blk" in output
diff --git a/test/py/tests/test_md.py b/test/py/tests/test_md.py
index 83e3c546f4a..5c7bcbd420b 100644
--- a/test/py/tests/test_md.py
+++ b/test/py/tests/test_md.py
@@ -3,34 +3,34 @@
# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
import pytest
-import u_boot_utils
+import utils
@pytest.mark.buildconfigspec('cmd_memory')
-def test_md(u_boot_console):
+def test_md(ubman):
"""Test that md reads memory as expected, and that memory can be modified
using the mw command."""
- ram_base = u_boot_utils.find_ram_base(u_boot_console)
+ ram_base = utils.find_ram_base(ubman)
addr = '%08x' % ram_base
val = 'a5f09876'
expected_response = addr + ': ' + val
- u_boot_console.run_command('mw ' + addr + ' 0 10')
- response = u_boot_console.run_command('md ' + addr + ' 10')
+ ubman.run_command('mw ' + addr + ' 0 10')
+ response = ubman.run_command('md ' + addr + ' 10')
assert(not (expected_response in response))
- u_boot_console.run_command('mw ' + addr + ' ' + val)
- response = u_boot_console.run_command('md ' + addr + ' 10')
+ ubman.run_command('mw ' + addr + ' ' + val)
+ response = ubman.run_command('md ' + addr + ' 10')
assert(expected_response in response)
@pytest.mark.buildconfigspec('cmd_memory')
-def test_md_repeat(u_boot_console):
+def test_md_repeat(ubman):
"""Test command repeat (via executing an empty command) operates correctly
for "md"; the command must repeat and dump an incrementing address."""
- ram_base = u_boot_utils.find_ram_base(u_boot_console)
+ ram_base = utils.find_ram_base(ubman)
addr_base = '%08x' % ram_base
words = 0x10
addr_repeat = '%08x' % (ram_base + (words * 4))
- u_boot_console.run_command('md %s %x' % (addr_base, words))
- response = u_boot_console.run_command('')
+ ubman.run_command('md %s %x' % (addr_base, words))
+ response = ubman.run_command('')
expected_response = addr_repeat + ': '
assert(expected_response in response)
diff --git a/test/py/tests/test_mdio.py b/test/py/tests/test_mdio.py
index 89711e70b55..5345f1f4c40 100644
--- a/test/py/tests/test_mdio.py
+++ b/test/py/tests/test_mdio.py
@@ -22,8 +22,8 @@ env__mdio_util_test = {
}
"""
-def get_mdio_test_env(u_boot_console):
- f = u_boot_console.config.env.get("env__mdio_util_test", None)
+def get_mdio_test_env(ubman):
+ f = ubman.config.env.get("env__mdio_util_test", None)
if not f or len(f) == 0:
pytest.skip("No PHY device to test!")
else:
@@ -31,9 +31,9 @@ def get_mdio_test_env(u_boot_console):
@pytest.mark.buildconfigspec("cmd_mii")
@pytest.mark.buildconfigspec("phylib")
-def test_mdio_list(u_boot_console):
- f = get_mdio_test_env(u_boot_console)
- output = u_boot_console.run_command("mdio list")
+def test_mdio_list(ubman):
+ f = get_mdio_test_env(ubman)
+ output = ubman.run_command("mdio list")
for dev, val in f.items():
phy_addr = val.get("phy_addr")
dev_name = val.get("device_name")
@@ -43,24 +43,24 @@ def test_mdio_list(u_boot_console):
@pytest.mark.buildconfigspec("cmd_mii")
@pytest.mark.buildconfigspec("phylib")
-def test_mdio_read(u_boot_console):
- f = get_mdio_test_env(u_boot_console)
- output = u_boot_console.run_command("mdio list")
+def test_mdio_read(ubman):
+ f = get_mdio_test_env(ubman)
+ output = ubman.run_command("mdio list")
for dev, val in f.items():
phy_addr = hex(val.get("phy_addr"))
dev_name = val.get("device_name")
reg = hex(val.get("reg"))
reg_val = hex(val.get("reg_val"))
- output = u_boot_console.run_command(f"mdio read {phy_addr} {reg}")
+ output = ubman.run_command(f"mdio read {phy_addr} {reg}")
assert f"PHY at address {int(phy_addr, 16):x}:" in output
assert f"{int(reg, 16):x} - {reg_val}" in output
@pytest.mark.buildconfigspec("cmd_mii")
@pytest.mark.buildconfigspec("phylib")
-def test_mdio_write(u_boot_console):
- f = get_mdio_test_env(u_boot_console)
- output = u_boot_console.run_command("mdio list")
+def test_mdio_write(ubman):
+ f = get_mdio_test_env(ubman)
+ output = ubman.run_command("mdio list")
for dev, val in f.items():
phy_addr = hex(val.get("phy_addr"))
dev_name = val.get("device_name")
@@ -68,12 +68,12 @@ def test_mdio_write(u_boot_console):
reg_val = hex(val.get("reg_val"))
wr_val = hex(val.get("write_val"))
- u_boot_console.run_command(f"mdio write {phy_addr} {reg} {wr_val}")
- output = u_boot_console.run_command(f"mdio read {phy_addr} {reg}")
+ ubman.run_command(f"mdio write {phy_addr} {reg} {wr_val}")
+ output = ubman.run_command(f"mdio read {phy_addr} {reg}")
assert f"PHY at address {int(phy_addr, 16):x}:" in output
assert f"{int(reg, 16):x} - {wr_val}" in output
- u_boot_console.run_command(f"mdio write {phy_addr} {reg} {reg_val}")
- output = u_boot_console.run_command(f"mdio read {phy_addr} {reg}")
+ ubman.run_command(f"mdio write {phy_addr} {reg} {reg_val}")
+ output = ubman.run_command(f"mdio read {phy_addr} {reg}")
assert f"PHY at address {int(phy_addr, 16):x}:" in output
assert f"{int(reg, 16):x} - {reg_val}" in output
diff --git a/test/py/tests/test_memtest.py b/test/py/tests/test_memtest.py
index 0618d96f1be..f24f9f0d67d 100644
--- a/test/py/tests/test_memtest.py
+++ b/test/py/tests/test_memtest.py
@@ -24,45 +24,45 @@ env__memtest = {
}
"""
-def get_memtest_env(u_boot_console):
- f = u_boot_console.config.env.get("env__memtest", None)
+def get_memtest_env(ubman):
+ f = ubman.config.env.get("env__memtest", None)
if not f:
pytest.skip("memtest is not enabled!")
else:
- start = f.get("start_addr", 0x0)
- size = f.get("size", 0x1000)
- pattern = f.get("pattern", 0x0)
+ start = hex(f.get("start_addr", 0x0))
+ size = hex(f.get("size", 0x1000))
+ pattern = hex(f.get("pattern", 0x0))
iteration = f.get("iteration", 2)
timeout = f.get("timeout", 50000)
- end = hex(int(start) + int(size))
+ end = hex(int(start, 16) + int(size, 16))
return start, end, pattern, iteration, timeout
@pytest.mark.buildconfigspec("cmd_memtest")
-def test_memtest_negative(u_boot_console):
+def test_memtest_negative(ubman):
"""Negative testcase where end address is smaller than starting address and
pattern is invalid."""
- start, end, pattern, iteration, timeout = get_memtest_env(u_boot_console)
+ start, end, pattern, iteration, timeout = get_memtest_env(ubman)
expected_response = "Refusing to do empty test"
- response = u_boot_console.run_command(
+ response = ubman.run_command(
f"mtest 2000 1000 {pattern} {hex(iteration)}"
)
assert expected_response in response
- output = u_boot_console.run_command("echo $?")
+ output = ubman.run_command("echo $?")
assert not output.endswith("0")
- u_boot_console.run_command(f"mtest {start} {end} 'xyz' {hex(iteration)}")
- output = u_boot_console.run_command("echo $?")
+ ubman.run_command(f"mtest {start} {end} 'xyz' {hex(iteration)}")
+ output = ubman.run_command("echo $?")
assert not output.endswith("0")
@pytest.mark.buildconfigspec("cmd_memtest")
-def test_memtest_ddr(u_boot_console):
+def test_memtest_ddr(ubman):
"""Test that md reads memory as expected, and that memory can be modified
using the mw command."""
- start, end, pattern, iteration, timeout = get_memtest_env(u_boot_console)
+ start, end, pattern, iteration, timeout = get_memtest_env(ubman)
expected_response = f"Tested {str(iteration)} iteration(s) with 0 errors."
- with u_boot_console.temporary_timeout(timeout):
- response = u_boot_console.run_command(
+ with ubman.temporary_timeout(timeout):
+ response = ubman.run_command(
f"mtest {start} {end} {pattern} {hex(iteration)}"
)
assert expected_response in response
- output = u_boot_console.run_command("echo $?")
+ output = ubman.run_command("echo $?")
assert output.endswith("0")
diff --git a/test/py/tests/test_mii.py b/test/py/tests/test_mii.py
index 7b6816d1089..e282add5ee8 100644
--- a/test/py/tests/test_mii.py
+++ b/test/py/tests/test_mii.py
@@ -22,21 +22,21 @@ env__mii_device_test = {
"""
@pytest.mark.buildconfigspec("cmd_mii")
-def test_mii_info(u_boot_console):
- if u_boot_console.config.env.get("env__mii_device_test_skip", False):
+def test_mii_info(ubman):
+ if ubman.config.env.get("env__mii_device_test_skip", False):
pytest.skip("MII device test is not enabled!")
expected_output = "PHY"
- output = u_boot_console.run_command("mii info")
+ output = ubman.run_command("mii info")
if not re.search(r"PHY (.+?):", output):
pytest.skip("PHY device does not exist!")
assert expected_output in output
@pytest.mark.buildconfigspec("cmd_mii")
-def test_mii_list(u_boot_console):
- if u_boot_console.config.env.get("env__mii_device_test_skip", False):
+def test_mii_list(ubman):
+ if ubman.config.env.get("env__mii_device_test_skip", False):
pytest.skip("MII device test is not enabled!")
- f = u_boot_console.config.env.get("env__mii_device_test", None)
+ f = ubman.config.env.get("env__mii_device_test", None)
if not f:
pytest.skip("No MII device to test!")
@@ -45,7 +45,7 @@ def test_mii_list(u_boot_console):
pytest.fail("No MII device list provided via env__mii_device_test!")
expected_output = "Current device"
- output = u_boot_console.run_command("mii device")
+ output = ubman.run_command("mii device")
mii_devices = (
re.search(r"MII devices: '(.+)'", output).groups()[0].replace("'", "").split()
)
@@ -54,39 +54,39 @@ def test_mii_list(u_boot_console):
assert expected_output in output
@pytest.mark.buildconfigspec("cmd_mii")
-def test_mii_set_device(u_boot_console):
- test_mii_list(u_boot_console)
- f = u_boot_console.config.env.get("env__mii_device_test", None)
+def test_mii_set_device(ubman):
+ test_mii_list(ubman)
+ f = ubman.config.env.get("env__mii_device_test", None)
dev_list = f.get("device_list")
- output = u_boot_console.run_command("mii device")
+ output = ubman.run_command("mii device")
current_dev = re.search(r"Current device: '(.+?)'", output).groups()[0]
for dev in dev_list:
- u_boot_console.run_command(f"mii device {dev}")
- output = u_boot_console.run_command("echo $?")
+ ubman.run_command(f"mii device {dev}")
+ output = ubman.run_command("echo $?")
assert output.endswith("0")
- u_boot_console.run_command(f"mii device {current_dev}")
- output = u_boot_console.run_command("mii device")
+ ubman.run_command(f"mii device {current_dev}")
+ output = ubman.run_command("mii device")
dev = re.search(r"Current device: '(.+?)'", output).groups()[0]
assert current_dev == dev
@pytest.mark.buildconfigspec("cmd_mii")
-def test_mii_read(u_boot_console):
- test_mii_list(u_boot_console)
- output = u_boot_console.run_command("mii info")
+def test_mii_read(ubman):
+ test_mii_list(ubman)
+ output = ubman.run_command("mii info")
eth_addr = hex(int(re.search(r"PHY (.+?):", output).groups()[0], 16))
- u_boot_console.run_command(f"mii read {eth_addr} 0")
- output = u_boot_console.run_command("echo $?")
+ ubman.run_command(f"mii read {eth_addr} 0")
+ output = ubman.run_command("echo $?")
assert output.endswith("0")
@pytest.mark.buildconfigspec("cmd_mii")
-def test_mii_dump(u_boot_console):
- test_mii_list(u_boot_console)
+def test_mii_dump(ubman):
+ test_mii_list(ubman)
expected_response = "PHY control register"
- output = u_boot_console.run_command("mii info")
+ output = ubman.run_command("mii info")
eth_addr = hex(int(re.search(r"PHY (.+?):", output).groups()[0], 16))
- response = u_boot_console.run_command(f"mii dump {eth_addr} 0")
+ response = ubman.run_command(f"mii dump {eth_addr} 0")
assert expected_response in response
- output = u_boot_console.run_command("echo $?")
+ output = ubman.run_command("echo $?")
assert output.endswith("0")
diff --git a/test/py/tests/test_mmc.py b/test/py/tests/test_mmc.py
index a96c4e8fd89..e751a3bd36a 100644
--- a/test/py/tests/test_mmc.py
+++ b/test/py/tests/test_mmc.py
@@ -4,7 +4,7 @@
import pytest
import random
import re
-import u_boot_utils
+import utils
"""
Note: This test doesn't rely on boardenv_* configuration values but it can
@@ -18,20 +18,59 @@ For example:
# Setup env__mmc_device_test_skip to not skipping the test. By default, its
# value is set to True. Set it to False to run all tests for MMC device.
env__mmc_device_test_skip = False
+
+# Setup env__mmc_device to set the supported mmc modes to be tested
+env__mmc_device {
+ 'mmc_modes': ['MMC_LEGACY', 'SD_HS'],
+}
+
"""
mmc_set_up = False
controllers = 0
devices = {}
-
-def setup_mmc(u_boot_console):
- if u_boot_console.config.env.get('env__mmc_device_test_skip', True):
+mmc_modes_name = []
+mmc_modes = []
+
+def setup_mmc_modes(ubman):
+ global mmc_modes, mmc_modes_name
+ f = ubman.config.env.get('env__mmc_device', None)
+ if f:
+ mmc_modes_name = f.get('mmc_modes', None)
+
+ # Set mmc mode to default mode (legacy), if speed mode config isn't enabled
+ if ubman.config.buildconfig.get('config_mmc_speed_mode_set', 'n') != 'y':
+ mmc_modes = [0]
+ return
+
+ if mmc_modes_name:
+ mmc_help = ubman.run_command('mmc -help')
+ m = re.search(r"\[MMC_LEGACY(.*\n.+])", mmc_help)
+ modes = [
+ x.strip()
+ for x in m.group()
+ .replace('\n', '')
+ .replace('[', '')
+ .replace(']', '')
+ .split(',')
+ ]
+
+ for mode in mmc_modes_name:
+ mmc_modes += [modes.index(mode)]
+ else:
+ # Set mmc mode to default mode (legacy), if it is not defined in env
+ mmc_modes = [0]
+
+def setup_mmc(ubman):
+ if ubman.config.env.get('env__mmc_device_test_skip', True):
pytest.skip('MMC device test is not enabled')
+ setup_mmc_modes(ubman)
+
@pytest.mark.buildconfigspec('cmd_mmc')
-def test_mmc_list(u_boot_console):
- setup_mmc(u_boot_console)
- output = u_boot_console.run_command('mmc list')
+def test_mmc_list(ubman):
+ setup_mmc(ubman)
+ output = ubman.run_command('mmc list')
if 'No MMC device available' in output:
pytest.skip('No SD/MMC/eMMC controller available')
@@ -51,73 +90,79 @@ def test_mmc_list(u_boot_console):
mmc_set_up = True
@pytest.mark.buildconfigspec('cmd_mmc')
-def test_mmc_dev(u_boot_console):
+def test_mmc_dev(ubman):
if not mmc_set_up:
pytest.skip('No SD/MMC/eMMC controller available')
fail = 0
for x in range(0, controllers):
devices[x]['detected'] = 'yes'
- output = u_boot_console.run_command('mmc dev %d' % x)
- # Some sort of switch here
- if 'Card did not respond to voltage select' in output:
- fail = 1
- devices[x]['detected'] = 'no'
+ for y in mmc_modes:
+ output = ubman.run_command('mmc dev %d 0 %d' % x, y)
- if 'no mmc device at slot' in output:
- devices[x]['detected'] = 'no'
+ if 'Card did not respond to voltage select' in output:
+ fail = 1
+ devices[x]['detected'] = 'no'
- if 'MMC: no card present' in output:
- devices[x]['detected'] = 'no'
+ if 'no mmc device at slot' in output:
+ devices[x]['detected'] = 'no'
- if fail:
- pytest.fail('Card not present')
+ if 'MMC: no card present' in output:
+ devices[x]['detected'] = 'no'
+
+ if fail:
+ pytest.fail('Card not present')
@pytest.mark.buildconfigspec('cmd_mmc')
-def test_mmcinfo(u_boot_console):
+def test_mmcinfo(ubman):
if not mmc_set_up:
pytest.skip('No SD/MMC/eMMC controller available')
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
- output = u_boot_console.run_command('mmcinfo')
- if 'busy timeout' in output:
- pytest.skip('No SD/MMC/eMMC device present')
+ for y in mmc_modes:
+ ubman.run_command('mmc dev %d 0 %d' % x, y)
+ output = ubman.run_command('mmcinfo')
+ if 'busy timeout' in output:
+ pytest.skip('No SD/MMC/eMMC device present')
- obj = re.search(r'Capacity: (\d+|\d+[\.]?\d)', output)
- try:
- capacity = float(obj.groups()[0])
- print(capacity)
- devices[x]['capacity'] = capacity
- print('Capacity of dev %d is: %g GiB' % (x, capacity))
- except ValueError:
- pytest.fail('MMC capacity not recognized')
+ assert mmc_modes_name[mmc_modes.index(y)] in output
+
+ obj = re.search(r'Capacity: (\d+|\d+[\.]?\d)', output)
+ try:
+ capacity = float(obj.groups()[0])
+ print(capacity)
+ devices[x]['capacity'] = capacity
+ print('Capacity of dev %d is: %g GiB' % (x, capacity))
+ except ValueError:
+ pytest.fail('MMC capacity not recognized')
@pytest.mark.buildconfigspec('cmd_mmc')
-def test_mmc_info(u_boot_console):
+def test_mmc_info(ubman):
if not mmc_set_up:
pytest.skip('No SD/MMC/eMMC controller available')
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
+ for y in mmc_modes:
+ ubman.run_command('mmc dev %d 0 %d' % x, y)
- output = u_boot_console.run_command('mmc info')
+ output = ubman.run_command('mmc info')
+ assert mmc_modes_name[mmc_modes.index(y)] in output
- obj = re.search(r'Capacity: (\d+|\d+[\.]?\d)', output)
- try:
- capacity = float(obj.groups()[0])
- print(capacity)
- if devices[x]['capacity'] != capacity:
- pytest.fail("MMC capacity doesn't match mmcinfo")
+ obj = re.search(r'Capacity: (\d+|\d+[\.]?\d)', output)
+ try:
+ capacity = float(obj.groups()[0])
+ print(capacity)
+ if devices[x]['capacity'] != capacity:
+ pytest.fail("MMC capacity doesn't match mmcinfo")
- except ValueError:
- pytest.fail('MMC capacity not recognized')
+ except ValueError:
+ pytest.fail('MMC capacity not recognized')
@pytest.mark.buildconfigspec('cmd_mmc')
-def test_mmc_rescan(u_boot_console):
+def test_mmc_rescan(ubman):
if not mmc_set_up:
pytest.skip('No SD/MMC/eMMC controller available')
@@ -126,15 +171,16 @@ def test_mmc_rescan(u_boot_console):
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
- output = u_boot_console.run_command('mmc rescan')
- if output:
- pytest.fail('mmc rescan has something to check')
- output = u_boot_console.run_command('echo $?')
- assert output.endswith('0')
+ for y in mmc_modes:
+ ubman.run_command('mmc dev %d 0 %d' % x, y)
+ output = ubman.run_command('mmc rescan')
+ if output:
+ pytest.fail('mmc rescan has something to check')
+ output = ubman.run_command('echo $?')
+ assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_mmc')
-def test_mmc_part(u_boot_console):
+def test_mmc_part(ubman):
if not mmc_set_up:
pytest.skip('No SD/MMC/eMMC controller available')
@@ -143,12 +189,13 @@ def test_mmc_part(u_boot_console):
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
- output = u_boot_console.run_command('mmc part')
+ ubman.run_command('mmc dev %d' % x)
+ output = ubman.run_command('mmc part')
lines = output.split('\n')
part_fat = []
- part_ext = []
+ part_ext2 = []
+ part_ext4 = []
for line in lines:
obj = re.search(
r'(\d)\s+\d+\s+\d+\s+\w+\d+\w+-\d+\s+(\d+\w+)', line)
@@ -161,20 +208,26 @@ def test_mmc_part(u_boot_console):
print('Fat detected')
part_fat.append(part_id)
elif part_type == '83':
- print('ext detected')
- part_ext.append(part_id)
+ print('ext(2/4) detected')
+ output = ubman.run_command(
+ 'fstype mmc %d:%d' % x, part_id
+ )
+ if 'ext2' in output:
+ part_ext2.append(part_id)
+ elif 'ext4' in output:
+ part_ext4.append(part_id)
else:
pytest.fail('Unsupported Filesystem on device %d' % x)
- devices[x]['ext4'] = part_ext
- devices[x]['ext2'] = part_ext
+ devices[x]['ext4'] = part_ext4
+ devices[x]['ext2'] = part_ext2
devices[x]['fat'] = part_fat
- if not part_ext and not part_fat:
+ if not part_ext2 and not part_ext4 and not part_fat:
pytest.fail('No partition detected on device %d' % x)
@pytest.mark.buildconfigspec('cmd_mmc')
@pytest.mark.buildconfigspec('cmd_fat')
-def test_mmc_fatls_fatinfo(u_boot_console):
+def test_mmc_fatls_fatinfo(ubman):
if not mmc_set_up:
pytest.skip('No SD/MMC/eMMC controller available')
@@ -185,7 +238,6 @@ def test_mmc_fatls_fatinfo(u_boot_console):
fs = 'fat'
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@@ -193,20 +245,22 @@ def test_mmc_fatls_fatinfo(u_boot_console):
continue
for part in partitions:
- output = u_boot_console.run_command(
- 'fatls mmc %d:%s' % (x, part))
- if 'Unrecognized filesystem type' in output:
- partitions.remove(part)
- pytest.fail('Unrecognized filesystem')
-
- if not re.search(r'\d file\(s\), \d dir\(s\)', output):
- pytest.fail('%s read failed on device %d' % (fs.upper, x))
- output = u_boot_console.run_command(
- 'fatinfo mmc %d:%s' % (x, part))
- string = 'Filesystem: %s' % fs.upper
- if re.search(string, output):
- pytest.fail('%s FS failed on device %d' % (fs.upper(), x))
- part_detect = 1
+ for y in mmc_modes:
+ ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ output = ubman.run_command(
+ 'fatls mmc %d:%s' % (x, part))
+ if 'Unrecognized filesystem type' in output:
+ partitions.remove(part)
+ pytest.fail('Unrecognized filesystem')
+
+ if not re.search(r'\d file\(s\), \d dir\(s\)', output):
+ pytest.fail('%s read failed on device %d' % (fs.upper, x))
+ output = ubman.run_command(
+ 'fatinfo mmc %d:%s' % (x, part))
+ string = 'Filesystem: %s' % fs.upper
+ if re.search(string, output):
+ pytest.fail('%s FS failed on device %d' % (fs.upper(), x))
+ part_detect = 1
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
@@ -215,7 +269,7 @@ def test_mmc_fatls_fatinfo(u_boot_console):
@pytest.mark.buildconfigspec('cmd_mmc')
@pytest.mark.buildconfigspec('cmd_fat')
@pytest.mark.buildconfigspec('cmd_memory')
-def test_mmc_fatload_fatwrite(u_boot_console):
+def test_mmc_fatload_fatwrite(ubman):
if not mmc_set_up:
pytest.skip('No SD/MMC/eMMC controller available')
@@ -226,7 +280,6 @@ def test_mmc_fatload_fatwrite(u_boot_console):
fs = 'fat'
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@@ -234,56 +287,58 @@ def test_mmc_fatload_fatwrite(u_boot_console):
continue
for part in partitions:
- part_detect = 1
- addr = u_boot_utils.find_ram_base(u_boot_console)
- devices[x]['addr_%d' % part] = addr
- size = random.randint(4, 1 * 1024 * 1024)
- devices[x]['size_%d' % part] = size
- # count CRC32
- output = u_boot_console.run_command('crc32 %x %x' % (addr, size))
- m = re.search('==> (.+?)', output)
- if not m:
- pytest.fail('CRC32 failed')
- expected_crc32 = m.group(1)
- devices[x]['expected_crc32_%d' % part] = expected_crc32
- # do write
- file = '%s_%d' % ('uboot_test', size)
- devices[x]['file_%d' % part] = file
- output = u_boot_console.run_command(
- '%swrite mmc %d:%s %x %s %x' % (fs, x, part, addr, file, size)
- )
- assert 'Unable to write' not in output
- assert 'Error' not in output
- assert 'overflow' not in output
- expected_text = '%d bytes written' % size
- assert expected_text in output
-
- alignment = int(
- u_boot_console.config.buildconfig.get(
- 'config_sys_cacheline_size', 128
+ for y in mmc_modes:
+ ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ part_detect = 1
+ addr = utils.find_ram_base(ubman)
+ devices[x]['addr_%d' % part] = addr
+ size = random.randint(4, 1 * 1024 * 1024)
+ devices[x]['size_%d' % part] = size
+ # count CRC32
+ output = ubman.run_command('crc32 %x %x' % (addr, size))
+ m = re.search('==> (.+?)', output)
+ if not m:
+ pytest.fail('CRC32 failed')
+ expected_crc32 = m.group(1)
+ devices[x]['expected_crc32_%d' % part] = expected_crc32
+ # do write
+ file = '%s_%d' % ('uboot_test', size)
+ devices[x]['file_%d' % part] = file
+ output = ubman.run_command(
+ '%swrite mmc %d:%s %x %s %x' % (fs, x, part, addr, file, size)
)
- )
- offset = random.randrange(alignment, 1024, alignment)
- output = u_boot_console.run_command(
- '%sload mmc %d:%s %x %s' % (fs, x, part, addr + offset, file)
- )
- assert 'Invalid FAT entry' not in output
- assert 'Unable to read file' not in output
- assert 'Misaligned buffer address' not in output
- expected_text = '%d bytes read' % size
- assert expected_text in output
-
- output = u_boot_console.run_command(
- 'crc32 %x $filesize' % (addr + offset)
- )
- assert expected_crc32 in output
+ assert 'Unable to write' not in output
+ assert 'Error' not in output
+ assert 'overflow' not in output
+ expected_text = '%d bytes written' % size
+ assert expected_text in output
+
+ alignment = int(
+ ubman.config.buildconfig.get(
+ 'config_sys_cacheline_size', 128
+ )
+ )
+ offset = random.randrange(alignment, 1024, alignment)
+ output = ubman.run_command(
+ '%sload mmc %d:%s %x %s' % (fs, x, part, addr + offset, file)
+ )
+ assert 'Invalid FAT entry' not in output
+ assert 'Unable to read file' not in output
+ assert 'Misaligned buffer address' not in output
+ expected_text = '%d bytes read' % size
+ assert expected_text in output
+
+ output = ubman.run_command(
+ 'crc32 %x $filesize' % (addr + offset)
+ )
+ assert expected_crc32 in output
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
@pytest.mark.buildconfigspec('cmd_mmc')
@pytest.mark.buildconfigspec('cmd_ext4')
-def test_mmc_ext4ls(u_boot_console):
+def test_mmc_ext4ls(ubman):
if not mmc_set_up:
pytest.skip('No SD/MMC/eMMC controller available')
@@ -300,13 +355,16 @@ def test_mmc_ext4ls(u_boot_console):
print('No %s table on this device' % fs.upper())
continue
- u_boot_console.run_command('mmc dev %d' % x)
for part in partitions:
- output = u_boot_console.run_command('%sls mmc %d:%s' % (fs, x, part))
- if 'Unrecognized filesystem type' in output:
- partitions.remove(part)
- pytest.fail('Unrecognized filesystem')
- part_detect = 1
+ for y in mmc_modes:
+ ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ output = ubman.run_command(
+ '%sls mmc %d:%s' % (fs, x, part)
+ )
+ if 'Unrecognized filesystem type' in output:
+ partitions.remove(part)
+ pytest.fail('Unrecognized filesystem')
+ part_detect = 1
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
@@ -315,7 +373,7 @@ def test_mmc_ext4ls(u_boot_console):
@pytest.mark.buildconfigspec('cmd_ext4')
@pytest.mark.buildconfigspec('ext4_write')
@pytest.mark.buildconfigspec('cmd_memory')
-def test_mmc_ext4load_ext4write(u_boot_console):
+def test_mmc_ext4load_ext4write(ubman):
if not mmc_set_up:
pytest.skip('No SD/MMC/eMMC controller available')
@@ -326,7 +384,6 @@ def test_mmc_ext4load_ext4write(u_boot_console):
fs = 'ext4'
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@@ -334,49 +391,51 @@ def test_mmc_ext4load_ext4write(u_boot_console):
continue
for part in partitions:
- part_detect = 1
- addr = u_boot_utils.find_ram_base(u_boot_console)
- devices[x]['addr_%d' % part] = addr
- size = random.randint(4, 1 * 1024 * 1024)
- devices[x]['size_%d' % part] = size
- # count CRC32
- output = u_boot_console.run_command('crc32 %x %x' % (addr, size))
- m = re.search('==> (.+?)', output)
- if not m:
- pytest.fail('CRC32 failed')
- expected_crc32 = m.group(1)
- devices[x]['expected_crc32_%d' % part] = expected_crc32
- # do write
-
- file = '%s_%d' % ('uboot_test', size)
- devices[x]['file_%d' % part] = file
- output = u_boot_console.run_command(
- '%swrite mmc %d:%s %x /%s %x' % (fs, x, part, addr, file, size)
- )
- assert 'Unable to write' not in output
- assert 'Error' not in output
- assert 'overflow' not in output
- expected_text = '%d bytes written' % size
- assert expected_text in output
-
- offset = random.randrange(128, 1024, 128)
- output = u_boot_console.run_command(
- '%sload mmc %d:%s %x /%s' % (fs, x, part, addr + offset, file)
- )
- expected_text = '%d bytes read' % size
- assert expected_text in output
-
- output = u_boot_console.run_command(
- 'crc32 %x $filesize' % (addr + offset)
- )
- assert expected_crc32 in output
+ for y in mmc_modes:
+ ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ part_detect = 1
+ addr = utils.find_ram_base(ubman)
+ devices[x]['addr_%d' % part] = addr
+ size = random.randint(4, 1 * 1024 * 1024)
+ devices[x]['size_%d' % part] = size
+ # count CRC32
+ output = ubman.run_command('crc32 %x %x' % (addr, size))
+ m = re.search('==> (.+?)', output)
+ if not m:
+ pytest.fail('CRC32 failed')
+ expected_crc32 = m.group(1)
+ devices[x]['expected_crc32_%d' % part] = expected_crc32
+
+ # do write
+ file = '%s_%d' % ('uboot_test', size)
+ devices[x]['file_%d' % part] = file
+ output = ubman.run_command(
+ '%swrite mmc %d:%s %x /%s %x' % (fs, x, part, addr, file, size)
+ )
+ assert 'Unable to write' not in output
+ assert 'Error' not in output
+ assert 'overflow' not in output
+ expected_text = '%d bytes written' % size
+ assert expected_text in output
+
+ offset = random.randrange(128, 1024, 128)
+ output = ubman.run_command(
+ '%sload mmc %d:%s %x /%s' % (fs, x, part, addr + offset, file)
+ )
+ expected_text = '%d bytes read' % size
+ assert expected_text in output
+
+ output = ubman.run_command(
+ 'crc32 %x $filesize' % (addr + offset)
+ )
+ assert expected_crc32 in output
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
@pytest.mark.buildconfigspec('cmd_mmc')
@pytest.mark.buildconfigspec('cmd_ext2')
-def test_mmc_ext2ls(u_boot_console):
+def test_mmc_ext2ls(ubman):
if not mmc_set_up:
pytest.skip('No SD/MMC/eMMC controller available')
@@ -387,7 +446,6 @@ def test_mmc_ext2ls(u_boot_console):
fs = 'ext2'
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@@ -395,12 +453,16 @@ def test_mmc_ext2ls(u_boot_console):
continue
for part in partitions:
- part_detect = 1
- output = u_boot_console.run_command('%sls mmc %d:%s' % (fs, x, part))
- if 'Unrecognized filesystem type' in output:
- partitions.remove(part)
- pytest.fail('Unrecognized filesystem')
- part_detect = 1
+ for y in mmc_modes:
+ ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ part_detect = 1
+ output = ubman.run_command(
+ '%sls mmc %d:%s' % (fs, x, part)
+ )
+ if 'Unrecognized filesystem type' in output:
+ partitions.remove(part)
+ pytest.fail('Unrecognized filesystem')
+ part_detect = 1
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
@@ -410,7 +472,7 @@ def test_mmc_ext2ls(u_boot_console):
@pytest.mark.buildconfigspec('cmd_ext4')
@pytest.mark.buildconfigspec('ext4_write')
@pytest.mark.buildconfigspec('cmd_memory')
-def test_mmc_ext2load(u_boot_console):
+def test_mmc_ext2load(ubman):
if not mmc_set_up:
pytest.skip('No SD/MMC/eMMC controller available')
@@ -421,7 +483,6 @@ def test_mmc_ext2load(u_boot_console):
fs = 'ext2'
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@@ -429,30 +490,32 @@ def test_mmc_ext2load(u_boot_console):
continue
for part in partitions:
- part_detect = 1
- addr = devices[x]['addr_%d' % part]
- size = devices[x]['size_%d' % part]
- expected_crc32 = devices[x]['expected_crc32_%d' % part]
- file = devices[x]['file_%d' % part]
-
- offset = random.randrange(128, 1024, 128)
- output = u_boot_console.run_command(
- '%sload mmc %d:%s %x /%s' % (fs, x, part, addr + offset, file)
- )
- expected_text = '%d bytes read' % size
- assert expected_text in output
-
- output = u_boot_console.run_command(
- 'crc32 %x $filesize' % (addr + offset)
- )
- assert expected_crc32 in output
+ for y in mmc_modes:
+ ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ part_detect = 1
+ addr = devices[x]['addr_%d' % part]
+ size = devices[x]['size_%d' % part]
+ expected_crc32 = devices[x]['expected_crc32_%d' % part]
+ file = devices[x]['file_%d' % part]
+
+ offset = random.randrange(128, 1024, 128)
+ output = ubman.run_command(
+ '%sload mmc %d:%s %x /%s' % (fs, x, part, addr + offset, file)
+ )
+ expected_text = '%d bytes read' % size
+ assert expected_text in output
+
+ output = ubman.run_command(
+ 'crc32 %x $filesize' % (addr + offset)
+ )
+ assert expected_crc32 in output
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
@pytest.mark.buildconfigspec('cmd_mmc')
@pytest.mark.buildconfigspec('cmd_fs_generic')
-def test_mmc_ls(u_boot_console):
+def test_mmc_ls(ubman):
if not mmc_set_up:
pytest.skip('No SD/MMC/eMMC controller available')
@@ -462,8 +525,7 @@ def test_mmc_ls(u_boot_console):
part_detect = 0
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
- for fs in ['fat', 'ext4']:
+ for fs in ['fat', 'ext4', 'ext2']:
try:
partitions = devices[x][fs]
except:
@@ -471,19 +533,21 @@ def test_mmc_ls(u_boot_console):
continue
for part in partitions:
- part_detect = 1
- output = u_boot_console.run_command('ls mmc %d:%s' % (x, part))
- if re.search(r'No \w+ table on this device', output):
- pytest.fail(
- '%s: Partition table not found %d' % (fs.upper(), x)
- )
+ for y in mmc_modes:
+ ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ part_detect = 1
+ output = ubman.run_command('ls mmc %d:%s' % (x, part))
+ if re.search(r'No \w+ table on this device', output):
+ pytest.fail(
+ '%s: Partition table not found %d' % (fs.upper(), x)
+ )
if not part_detect:
pytest.skip('No partition detected')
@pytest.mark.buildconfigspec('cmd_mmc')
@pytest.mark.buildconfigspec('cmd_fs_generic')
-def test_mmc_load(u_boot_console):
+def test_mmc_load(ubman):
if not mmc_set_up:
pytest.skip('No SD/MMC/eMMC controller available')
@@ -493,8 +557,7 @@ def test_mmc_load(u_boot_console):
part_detect = 0
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
- for fs in ['fat', 'ext4']:
+ for fs in ['fat', 'ext4', 'ext2']:
try:
partitions = devices[x][fs]
except:
@@ -502,30 +565,32 @@ def test_mmc_load(u_boot_console):
continue
for part in partitions:
- part_detect = 1
- addr = devices[x]['addr_%d' % part]
- size = devices[x]['size_%d' % part]
- expected_crc32 = devices[x]['expected_crc32_%d' % part]
- file = devices[x]['file_%d' % part]
-
- offset = random.randrange(128, 1024, 128)
- output = u_boot_console.run_command(
- 'load mmc %d:%s %x /%s' % (x, part, addr + offset, file)
- )
- expected_text = '%d bytes read' % size
- assert expected_text in output
+ for y in mmc_modes:
+ ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ part_detect = 1
+ addr = devices[x]['addr_%d' % part]
+ size = devices[x]['size_%d' % part]
+ expected_crc32 = devices[x]['expected_crc32_%d' % part]
+ file = devices[x]['file_%d' % part]
+
+ offset = random.randrange(128, 1024, 128)
+ output = ubman.run_command(
+ 'load mmc %d:%s %x /%s' % (x, part, addr + offset, file)
+ )
+ expected_text = '%d bytes read' % size
+ assert expected_text in output
- output = u_boot_console.run_command(
- 'crc32 %x $filesize' % (addr + offset)
- )
- assert expected_crc32 in output
+ output = ubman.run_command(
+ 'crc32 %x $filesize' % (addr + offset)
+ )
+ assert expected_crc32 in output
if not part_detect:
pytest.skip('No partition detected')
@pytest.mark.buildconfigspec('cmd_mmc')
@pytest.mark.buildconfigspec('cmd_fs_generic')
-def test_mmc_save(u_boot_console):
+def test_mmc_save(ubman):
if not mmc_set_up:
pytest.skip('No SD/MMC/eMMC controller available')
@@ -535,8 +600,7 @@ def test_mmc_save(u_boot_console):
part_detect = 0
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
- for fs in ['fat', 'ext4']:
+ for fs in ['fat', 'ext4', 'ext2']:
try:
partitions = devices[x][fs]
except:
@@ -544,18 +608,20 @@ def test_mmc_save(u_boot_console):
continue
for part in partitions:
- part_detect = 1
- addr = devices[x]['addr_%d' % part]
- size = 0
- file = devices[x]['file_%d' % part]
-
- offset = random.randrange(128, 1024, 128)
- output = u_boot_console.run_command(
- 'save mmc %d:%s %x /%s %d'
- % (x, part, addr + offset, file, size)
- )
- expected_text = '%d bytes written' % size
- assert expected_text in output
+ for y in mmc_modes:
+ ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ part_detect = 1
+ addr = devices[x]['addr_%d' % part]
+ size = 0
+ file = devices[x]['file_%d' % part]
+
+ offset = random.randrange(128, 1024, 128)
+ output = ubman.run_command(
+ 'save mmc %d:%s %x /%s %d'
+ % (x, part, addr + offset, file, size)
+ )
+ expected_text = '%d bytes written' % size
+ assert expected_text in output
if not part_detect:
pytest.skip('No partition detected')
@@ -563,11 +629,11 @@ def test_mmc_save(u_boot_console):
@pytest.mark.buildconfigspec('cmd_mmc')
@pytest.mark.buildconfigspec('cmd_fat')
@pytest.mark.buildconfigspec('cmd_memory')
-def test_mmc_fat_read_write_files(u_boot_console):
- test_mmc_list(u_boot_console)
- test_mmc_dev(u_boot_console)
- test_mmcinfo(u_boot_console)
- test_mmc_part(u_boot_console)
+def test_mmc_fat_read_write_files(ubman):
+ test_mmc_list(ubman)
+ test_mmc_dev(ubman)
+ test_mmcinfo(ubman)
+ test_mmc_part(ubman)
if not mmc_set_up:
pytest.skip('No SD/MMC/eMMC controller available')
@@ -582,7 +648,6 @@ def test_mmc_fat_read_write_files(u_boot_console):
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('mmc dev %d' % x)
try:
partitions = devices[x][fs]
except:
@@ -590,82 +655,86 @@ def test_mmc_fat_read_write_files(u_boot_console):
continue
for part in partitions:
- part_detect = 1
- addr = u_boot_utils.find_ram_base(u_boot_console)
- count_f = 0
- addr_l = []
- size_l = []
- file_l = []
- crc32_l = []
- offset_l = []
- addr_l.append(addr)
-
- while count_f < num_files:
- size_l.append(random.randint(4, 1 * 1024 * 1024))
-
- # CRC32 count
- output = u_boot_console.run_command(
- 'crc32 %x %x' % (addr_l[count_f], size_l[count_f])
- )
- m = re.search('==> (.+?)', output)
- if not m:
- pytest.fail('CRC32 failed')
- crc32_l.append(m.group(1))
-
- # Write operation
- file_l.append('%s_%d_%d' % ('uboot_test', count_f, size_l[count_f]))
- output = u_boot_console.run_command(
- '%swrite mmc %d:%s %x %s %x'
- % (
- fs,
- x,
- part,
- addr_l[count_f],
- file_l[count_f],
- size_l[count_f],
+ for y in mmc_modes:
+ ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ part_detect = 1
+ addr = utils.find_ram_base(ubman)
+ count_f = 0
+ addr_l = []
+ size_l = []
+ file_l = []
+ crc32_l = []
+ offset_l = []
+ addr_l.append(addr)
+
+ while count_f < num_files:
+ size_l.append(random.randint(4, 1 * 1024 * 1024))
+
+ # CRC32 count
+ output = ubman.run_command(
+ 'crc32 %x %x' % (addr_l[count_f], size_l[count_f])
)
- )
- assert 'Unable to write' not in output
- assert 'Error' not in output
- assert 'overflow' not in output
- expected_text = '%d bytes written' % size_l[count_f]
- assert expected_text in output
-
- addr_l.append(addr_l[count_f] + size_l[count_f] + 1048576)
- count_f += 1
-
- count_f = 0
- while count_f < num_files:
- alignment = int(
- u_boot_console.config.buildconfig.get(
- 'config_sys_cacheline_size', 128
+ m = re.search('==> (.+?)', output)
+ if not m:
+ pytest.fail('CRC32 failed')
+ crc32_l.append(m.group(1))
+
+ # Write operation
+ file_l.append(
+ '%s_%d_%d' % ('uboot_test', count_f, size_l[count_f])
)
- )
- offset_l.append(random.randrange(alignment, 1024, alignment))
-
- # Read operation
- output = u_boot_console.run_command(
- '%sload mmc %d:%s %x %s'
- % (
- fs,
- x,
- part,
- addr_l[count_f] + offset_l[count_f],
- file_l[count_f],
+ output = ubman.run_command(
+ '%swrite mmc %d:%s %x %s %x'
+ % (
+ fs,
+ x,
+ part,
+ addr_l[count_f],
+ file_l[count_f],
+ size_l[count_f],
+ )
)
- )
- assert 'Invalid FAT entry' not in output
- assert 'Unable to read file' not in output
- assert 'Misaligned buffer address' not in output
- expected_text = '%d bytes read' % size_l[count_f]
- assert expected_text in output
-
- output = u_boot_console.run_command(
- 'crc32 %x $filesize' % (addr_l[count_f] + offset_l[count_f])
- )
- assert crc32_l[count_f] in output
+ assert 'Unable to write' not in output
+ assert 'Error' not in output
+ assert 'overflow' not in output
+ expected_text = '%d bytes written' % size_l[count_f]
+ assert expected_text in output
+
+ addr_l.append(addr_l[count_f] + size_l[count_f] + 1048576)
+ count_f += 1
+
+ count_f = 0
+ while count_f < num_files:
+ alignment = int(
+ ubman.config.buildconfig.get(
+ 'config_sys_cacheline_size', 128
+ )
+ )
+ offset_l.append(random.randrange(alignment, 1024, alignment))
+
+ # Read operation
+ output = ubman.run_command(
+ '%sload mmc %d:%s %x %s'
+ % (
+ fs,
+ x,
+ part,
+ addr_l[count_f] + offset_l[count_f],
+ file_l[count_f],
+ )
+ )
+ assert 'Invalid FAT entry' not in output
+ assert 'Unable to read file' not in output
+ assert 'Misaligned buffer address' not in output
+ expected_text = '%d bytes read' % size_l[count_f]
+ assert expected_text in output
+
+ output = ubman.run_command(
+ 'crc32 %x $filesize' % (addr_l[count_f] + offset_l[count_f])
+ )
+ assert crc32_l[count_f] in output
- count_f += 1
+ count_f += 1
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
diff --git a/test/py/tests/test_mmc_rd.py b/test/py/tests/test_mmc_rd.py
index ea652f91361..cd1e299aa9d 100644
--- a/test/py/tests/test_mmc_rd.py
+++ b/test/py/tests/test_mmc_rd.py
@@ -7,7 +7,7 @@
import pytest
import time
-import u_boot_utils
+import utils
"""
This test relies on boardenv_* to containing configuration values to define
@@ -105,11 +105,11 @@ env__mmc_rd_configs = (
)
"""
-def mmc_dev(u_boot_console, is_emmc, devid, partid):
+def mmc_dev(ubman, is_emmc, devid, partid):
"""Run the "mmc dev" command.
Args:
- u_boot_console: A U-Boot console connection.
+ ubman: A U-Boot console connection.
is_emmc: Whether the device is eMMC
devid: Device ID
partid: Partition ID
@@ -122,7 +122,7 @@ def mmc_dev(u_boot_console, is_emmc, devid, partid):
cmd = 'mmc dev %d' % devid
if is_emmc:
cmd += ' %d' % partid
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
assert 'no card present' not in response
if is_emmc:
partid_response = '(part %d)' % partid
@@ -132,11 +132,11 @@ def mmc_dev(u_boot_console, is_emmc, devid, partid):
assert good_response in response
@pytest.mark.buildconfigspec('cmd_mmc')
-def test_mmc_dev(u_boot_console, env__mmc_dev_config):
+def test_mmc_dev(ubman, env__mmc_dev_config):
"""Test the "mmc dev" command.
Args:
- u_boot_console: A U-Boot console connection.
+ ubman: A U-Boot console connection.
env__mmc_dev_config: The single MMC configuration on which
to run the test. See the file-level comment above for details
of the format.
@@ -150,14 +150,14 @@ def test_mmc_dev(u_boot_console, env__mmc_dev_config):
partid = env__mmc_dev_config.get('partid', 0)
# Select MMC device
- mmc_dev(u_boot_console, is_emmc, devid, partid)
+ mmc_dev(ubman, is_emmc, devid, partid)
@pytest.mark.buildconfigspec('cmd_mmc')
-def test_mmc_rescan(u_boot_console, env__mmc_dev_config):
+def test_mmc_rescan(ubman, env__mmc_dev_config):
"""Test the "mmc rescan" command.
Args:
- u_boot_console: A U-Boot console connection.
+ ubman: A U-Boot console connection.
env__mmc_dev_config: The single MMC configuration on which
to run the test. See the file-level comment above for details
of the format.
@@ -171,19 +171,19 @@ def test_mmc_rescan(u_boot_console, env__mmc_dev_config):
partid = env__mmc_dev_config.get('partid', 0)
# Select MMC device
- mmc_dev(u_boot_console, is_emmc, devid, partid)
+ mmc_dev(ubman, is_emmc, devid, partid)
# Rescan MMC device
cmd = 'mmc rescan'
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
assert 'no card present' not in response
@pytest.mark.buildconfigspec('cmd_mmc')
-def test_mmc_info(u_boot_console, env__mmc_dev_config):
+def test_mmc_info(ubman, env__mmc_dev_config):
"""Test the "mmc info" command.
Args:
- u_boot_console: A U-Boot console connection.
+ ubman: A U-Boot console connection.
env__mmc_dev_config: The single MMC configuration on which
to run the test. See the file-level comment above for details
of the format.
@@ -201,11 +201,11 @@ def test_mmc_info(u_boot_console, env__mmc_dev_config):
info_buswidth = env__mmc_dev_config['info_buswidth']
# Select MMC device
- mmc_dev(u_boot_console, is_emmc, devid, partid)
+ mmc_dev(ubman, is_emmc, devid, partid)
# Read MMC device information
cmd = 'mmc info'
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
good_response = "Device: %s" % info_device
assert good_response in response
good_response = "Bus Speed: %s" % info_speed
@@ -216,11 +216,11 @@ def test_mmc_info(u_boot_console, env__mmc_dev_config):
assert good_response in response
@pytest.mark.buildconfigspec('cmd_mmc')
-def test_mmc_rd(u_boot_console, env__mmc_rd_config):
+def test_mmc_rd(ubman, env__mmc_rd_config):
"""Test the "mmc read" command.
Args:
- u_boot_console: A U-Boot console connection.
+ ubman: A U-Boot console connection.
env__mmc_rd_config: The single MMC configuration on which
to run the test. See the file-level comment above for details
of the format.
@@ -238,32 +238,32 @@ def test_mmc_rd(u_boot_console, env__mmc_rd_config):
read_duration_max = env__mmc_rd_config.get('read_duration_max', 0)
count_bytes = count_sectors * 512
- bcfg = u_boot_console.config.buildconfig
+ bcfg = ubman.config.buildconfig
has_cmd_memory = bcfg.get('config_cmd_memory', 'n') == 'y'
has_cmd_crc32 = bcfg.get('config_cmd_crc32', 'n') == 'y'
- ram_base = u_boot_utils.find_ram_base(u_boot_console)
+ ram_base = utils.find_ram_base(ubman)
addr = '0x%08x' % ram_base
# Select MMC device
- mmc_dev(u_boot_console, is_emmc, devid, partid)
+ mmc_dev(ubman, is_emmc, devid, partid)
# Clear target RAM
if expected_crc32:
if has_cmd_memory and has_cmd_crc32:
cmd = 'mw.b %s 0 0x%x' % (addr, count_bytes)
- u_boot_console.run_command(cmd)
+ ubman.run_command(cmd)
cmd = 'crc32 %s 0x%x' % (addr, count_bytes)
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
assert expected_crc32 not in response
else:
- u_boot_console.log.warning(
+ ubman.log.warning(
'CONFIG_CMD_MEMORY or CONFIG_CMD_CRC32 != y: Skipping RAM clear')
# Read data
cmd = 'mmc read %s %x %x' % (addr, sector, count_sectors)
tstart = time.time()
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
tend = time.time()
good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (
devid, sector, count_sectors, count_sectors)
@@ -273,14 +273,14 @@ def test_mmc_rd(u_boot_console, env__mmc_rd_config):
if expected_crc32:
if has_cmd_crc32:
cmd = 'crc32 %s 0x%x' % (addr, count_bytes)
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
assert expected_crc32 in response
else:
- u_boot_console.log.warning('CONFIG_CMD_CRC32 != y: Skipping check')
+ ubman.log.warning('CONFIG_CMD_CRC32 != y: Skipping check')
# Check if the command did not take too long
if read_duration_max:
elapsed = tend - tstart
- u_boot_console.log.info('Reading %d bytes took %f seconds' %
+ ubman.log.info('Reading %d bytes took %f seconds' %
(count_bytes, elapsed))
assert elapsed <= (read_duration_max - 0.01)
diff --git a/test/py/tests/test_mmc_wr.py b/test/py/tests/test_mmc_wr.py
index 05e5c1ee85d..41a75f885e1 100644
--- a/test/py/tests/test_mmc_wr.py
+++ b/test/py/tests/test_mmc_wr.py
@@ -6,7 +6,7 @@
# to the eMMC or SD card, then reads it back and performs a comparison.
import pytest
-import u_boot_utils
+import utils
"""
This test relies on boardenv_* to containing configuration values to define
@@ -38,11 +38,11 @@ env__mmc_wr_configs = (
@pytest.mark.buildconfigspec('cmd_mmc')
@pytest.mark.buildconfigspec('cmd_memory')
@pytest.mark.buildconfigspec('cmd_random')
-def test_mmc_wr(u_boot_console, env__mmc_wr_config):
+def test_mmc_wr(ubman, env__mmc_wr_config):
"""Test the "mmc write" command.
Args:
- u_boot_console: A U-Boot console connection.
+ ubman: A U-Boot console connection.
env__mmc_wr_config: The single MMC configuration on which
to run the test. See the file-level comment above for details
of the format.
@@ -60,8 +60,8 @@ def test_mmc_wr(u_boot_console, env__mmc_wr_config):
count_bytes = count_sectors * 512
- bcfg = u_boot_console.config.buildconfig
- ram_base = u_boot_utils.find_ram_base(u_boot_console)
+ bcfg = ubman.config.buildconfig
+ ram_base = utils.find_ram_base(ubman)
src_addr = '0x%08x' % ram_base
dst_addr = '0x%08x' % (ram_base + count_bytes)
@@ -69,7 +69,7 @@ def test_mmc_wr(u_boot_console, env__mmc_wr_config):
for i in range(test_iterations):
# Generate random data
cmd = 'random %s %x' % (src_addr, count_bytes)
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
good_response = '%d bytes filled with random data' % (count_bytes)
assert good_response in response
@@ -77,7 +77,7 @@ def test_mmc_wr(u_boot_console, env__mmc_wr_config):
cmd = 'mmc dev %d' % devid
if is_emmc:
cmd += ' %d' % partid
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
assert 'no card present' not in response
if is_emmc:
partid_response = "(part %d)" % partid
@@ -88,18 +88,18 @@ def test_mmc_wr(u_boot_console, env__mmc_wr_config):
# Write data
cmd = 'mmc write %s %x %x' % (src_addr, sector, count_sectors)
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
good_response = 'MMC write: dev # %d, block # %d, count %d ... %d blocks written: OK' % (devid, sector, count_sectors, count_sectors)
assert good_response in response
# Read data
cmd = 'mmc read %s %x %x' % (dst_addr, sector, count_sectors)
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (devid, sector, count_sectors, count_sectors)
assert good_response in response
# Compare src and dst data
cmd = 'cmp.b %s %s %x' % (src_addr, dst_addr, count_bytes)
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
good_response = 'Total of %d byte(s) were the same' % (count_bytes)
assert good_response in response
diff --git a/test/py/tests/test_net.py b/test/py/tests/test_net.py
index 038a473b239..27cdd73fd49 100644
--- a/test/py/tests/test_net.py
+++ b/test/py/tests/test_net.py
@@ -4,12 +4,6 @@
# Test various network-related functionality, such as the dhcp, ping, and
# tftpboot commands.
-import pytest
-import u_boot_utils
-import uuid
-import datetime
-import re
-
"""
Note: This test relies on boardenv_* containing configuration values to define
which network environment is available for testing. Without this, this test
@@ -17,111 +11,121 @@ will be automatically skipped.
For example:
-# Boolean indicating whether the Ethernet device is attached to USB, and hence
-# USB enumeration needs to be performed prior to network tests.
-# This variable may be omitted if its value is False.
-env__net_uses_usb = False
-
-# Boolean indicating whether the Ethernet device is attached to PCI, and hence
-# PCI enumeration needs to be performed prior to network tests.
-# This variable may be omitted if its value is False.
-env__net_uses_pci = True
-
-# True if a DHCP server is attached to the network, and should be tested.
-# If DHCP testing is not possible or desired, this variable may be omitted or
-# set to False.
-env__net_dhcp_server = True
-
-# False or omitted if a DHCP server is attached to the network, and dhcp abort
-# case should be tested.
-# If DHCP abort testing is not possible or desired, set this variable to True.
-# For example: On some setup, dhcp is too fast and this case may not work.
-env__dhcp_abort_test_skip = 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.
-env__net_static_env_vars = [
- ('ipaddr', '10.0.0.100'),
- ('netmask', '255.255.255.0'),
- ('serverip', '10.0.0.1'),
-]
-
-# Details regarding a file that may be read from a TFTP server. This variable
-# may be omitted or set to None if TFTP testing is not possible or desired.
-env__net_tftp_readable_file = {
- 'fn': 'ubtest-readable.bin',
- 'addr': 0x10000000,
- 'size': 5058624,
- 'crc32': 'c2244b26',
- 'timeout': 50000,
- 'fnu': 'ubtest-upload.bin',
-}
-
-# Details regarding a file that may be read from a NFS server. This variable
-# may be omitted or set to None if NFS testing is not possible or desired.
-env__net_nfs_readable_file = {
- 'fn': 'ubtest-readable.bin',
- 'addr': 0x10000000,
- 'size': 5058624,
- 'crc32': 'c2244b26',
-}
-
-# Details regarding a file that may be read from a TFTP server. This variable
-# may be omitted or set to None if PXE testing is not possible or desired.
-env__net_pxe_readable_file = {
- 'fn': 'default',
- 'addr': 0x2000000,
- 'size': 74,
- 'timeout': 50000,
- 'pattern': 'Linux',
-}
-
-# 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
+.. code-block:: python
+
+ # Boolean indicating whether the Ethernet device is attached to USB, and hence
+ # USB enumeration needs to be performed prior to network tests.
+ # This variable may be omitted if its value is False.
+ env__net_uses_usb = False
+
+ # Boolean indicating whether the Ethernet device is attached to PCI, and hence
+ # PCI enumeration needs to be performed prior to network tests.
+ # This variable may be omitted if its value is False.
+ env__net_uses_pci = True
+
+ # True if a DHCP server is attached to the network, and should be tested.
+ # If DHCP testing is not possible or desired, this variable may be omitted or
+ # set to False.
+ env__net_dhcp_server = True
+
+ # False or omitted if a DHCP server is attached to the network, and dhcp abort
+ # case should be tested.
+ # If DHCP abort testing is not possible or desired, set this variable to True.
+ # For example: On some setup, dhcp is too fast and this case may not work.
+ env__dhcp_abort_test_skip = 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.
+ env__net_static_env_vars = [
+ ('ipaddr', '10.0.0.100'),
+ ('netmask', '255.255.255.0'),
+ ('serverip', '10.0.0.1'),
+ ]
+
+ # Details regarding a file that may be read from a TFTP server. This variable
+ # may be omitted or set to None if TFTP testing is not possible or desired.
+ env__net_tftp_readable_file = {
+ 'fn': 'ubtest-readable.bin',
+ 'addr': 0x10000000,
+ 'size': 5058624,
+ 'crc32': 'c2244b26',
+ 'timeout': 50000,
+ 'fnu': 'ubtest-upload.bin',
+ }
+
+ # Details regarding a file that may be read from a NFS server. This variable
+ # may be omitted or set to None if NFS testing is not possible or desired.
+ env__net_nfs_readable_file = {
+ 'fn': 'ubtest-readable.bin',
+ 'addr': 0x10000000,
+ 'size': 5058624,
+ 'crc32': 'c2244b26',
+ }
+
+ # Details regarding a file that may be read from a TFTP server. This variable
+ # may be omitted or set to None if PXE testing is not possible or desired.
+ env__net_pxe_readable_file = {
+ 'fn': 'default',
+ 'addr': 0x2000000,
+ 'size': 74,
+ 'timeout': 50000,
+ 'pattern': 'Linux',
+ }
+
+ # 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
"""
+import pytest
+import utils
+import uuid
+import datetime
+import re
+
net_set_up = False
net6_set_up = False
-def test_net_pre_commands(u_boot_console):
+
+@pytest.mark.buildconfigspec('cmd_net')
+def test_net_pre_commands(ubman):
"""Execute any commands required to enable network hardware.
These commands are provided by the boardenv_* file; see the comment at the
beginning of this file.
"""
- init_usb = u_boot_console.config.env.get('env__net_uses_usb', False)
+ init_usb = ubman.config.env.get('env__net_uses_usb', False)
if init_usb:
- u_boot_console.run_command('usb start')
+ ubman.run_command('usb start')
- init_pci = u_boot_console.config.env.get('env__net_uses_pci', False)
+ init_pci = ubman.config.env.get('env__net_uses_pci', False)
if init_pci:
- u_boot_console.run_command('pci enum')
+ ubman.run_command('pci enum')
- u_boot_console.run_command('net list')
+ ubman.run_command('net list')
@pytest.mark.buildconfigspec('cmd_dhcp')
-def test_net_dhcp(u_boot_console):
+def test_net_dhcp(ubman):
"""Test the dhcp command.
The boardenv_* file may be used to enable/disable this test; see the
comment at the beginning of this file.
"""
- test_dhcp = u_boot_console.config.env.get('env__net_dhcp_server', False)
+ test_dhcp = ubman.config.env.get('env__net_dhcp_server', False)
if not test_dhcp:
pytest.skip('No DHCP server available')
- u_boot_console.run_command('setenv autoload no')
- output = u_boot_console.run_command('dhcp')
+ ubman.run_command('setenv autoload no')
+ output = ubman.run_command('dhcp')
assert 'DHCP client bound to address ' in output
global net_set_up
@@ -129,43 +133,43 @@ def test_net_dhcp(u_boot_console):
@pytest.mark.buildconfigspec('cmd_dhcp')
@pytest.mark.buildconfigspec('cmd_mii')
-def test_net_dhcp_abort(u_boot_console):
+def test_net_dhcp_abort(ubman):
"""Test the dhcp command by pressing ctrl+c in the middle of dhcp request
The boardenv_* file may be used to enable/disable this test; see the
comment at the beginning of this file.
"""
- test_dhcp = u_boot_console.config.env.get('env__net_dhcp_server', False)
+ test_dhcp = ubman.config.env.get('env__net_dhcp_server', False)
if not test_dhcp:
pytest.skip('No DHCP server available')
- if u_boot_console.config.env.get('env__dhcp_abort_test_skip', True):
+ if ubman.config.env.get('env__dhcp_abort_test_skip', True):
pytest.skip('DHCP abort test is not enabled!')
- u_boot_console.run_command('setenv autoload no')
+ ubman.run_command('setenv autoload no')
# Phy reset before running dhcp command
- output = u_boot_console.run_command('mii device')
+ output = ubman.run_command('mii device')
if not re.search(r"Current device: '(.+?)'", output):
pytest.skip('PHY device does not exist!')
eth_num = re.search(r"Current device: '(.+?)'", output).groups()[0]
- u_boot_console.run_command(f'mii device {eth_num}')
- output = u_boot_console.run_command('mii info')
+ ubman.run_command(f'mii device {eth_num}')
+ output = ubman.run_command('mii info')
eth_addr = hex(int(re.search(r'PHY (.+?):', output).groups()[0], 16))
- u_boot_console.run_command(f'mii modify {eth_addr} 0 0x8000 0x8000')
+ ubman.run_command(f'mii modify {eth_addr} 0 0x8000 0x8000')
- u_boot_console.run_command('dhcp', wait_for_prompt=False)
+ ubman.run_command('dhcp', wait_for_prompt=False)
try:
- u_boot_console.wait_for('Waiting for PHY auto negotiation to complete')
+ ubman.wait_for('Waiting for PHY auto negotiation to complete')
except:
pytest.skip('Timeout waiting for PHY auto negotiation to complete')
- u_boot_console.wait_for('done')
+ ubman.wait_for('done')
try:
# Sending Ctrl-C
- output = u_boot_console.run_command(
+ output = ubman.run_command(
chr(3), wait_for_echo=False, send_nl=False
)
assert 'TIMEOUT' not in output
@@ -174,49 +178,49 @@ def test_net_dhcp_abort(u_boot_console):
finally:
# Provide a time to recover from Abort - if it is not performed
# There is message like: ethernet@ff0e0000: No link.
- u_boot_console.run_command('sleep 1')
+ ubman.run_command('sleep 1')
# Run the dhcp test to setup the network configuration
- test_net_dhcp(u_boot_console)
+ test_net_dhcp(ubman)
@pytest.mark.buildconfigspec('cmd_dhcp6')
-def test_net_dhcp6(u_boot_console):
+def test_net_dhcp6(ubman):
"""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)
+ test_dhcp6 = ubman.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')
+ ubman.run_command('setenv autoload no')
+ output = ubman.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):
+def test_net_setup_static(ubman):
"""Set up a static IP configuration.
The configuration is provided by the boardenv_* file; see the comment at
the beginning of this file.
"""
- env_vars = u_boot_console.config.env.get('env__net_static_env_vars', None)
+ env_vars = ubman.config.env.get('env__net_static_env_vars', None)
if not env_vars:
pytest.skip('No static network configuration is defined')
for (var, val) in env_vars:
- u_boot_console.run_command('setenv %s %s' % (var, val))
+ ubman.run_command('setenv %s %s' % (var, val))
global net_set_up
net_set_up = True
@pytest.mark.buildconfigspec('cmd_ping')
-def test_net_ping(u_boot_console):
+def test_net_ping(ubman):
"""Test the ping command.
The $serverip (as set up by either test_net_dhcp or test_net_setup_static)
@@ -227,11 +231,11 @@ def test_net_ping(u_boot_console):
if not net_set_up:
pytest.skip('Network not initialized')
- output = u_boot_console.run_command('ping $serverip')
+ output = ubman.run_command('ping $serverip')
assert 'is alive' in output
@pytest.mark.buildconfigspec('IPV6_ROUTER_DISCOVERY')
-def test_net_network_discovery(u_boot_console):
+def test_net_network_discovery(ubman):
"""Test the network discovery feature of IPv6.
An IPv6 network command (ping6 in this case) is run to make U-Boot send a
@@ -244,18 +248,18 @@ def test_net_network_discovery(u_boot_console):
the beginning of this file.
"""
- router_on_net = u_boot_console.config.env.get('env__router_on_net', False)
+ router_on_net = ubman.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)
+ output = ubman.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):
+@pytest.mark.buildconfigspec('cmd_tftpboot')
+def test_net_tftpboot(ubman):
"""Test the tftpboot command.
A file is downloaded from the TFTP server, its size and optionally its
@@ -268,7 +272,7 @@ def test_net_tftpboot(u_boot_console):
if not net_set_up:
pytest.skip('Network not initialized')
- f = u_boot_console.config.env.get('env__net_tftp_readable_file', None)
+ f = ubman.config.env.get('env__net_tftp_readable_file', None)
if not f:
pytest.skip('No TFTP readable file to read')
@@ -276,9 +280,9 @@ def test_net_tftpboot(u_boot_console):
fn = f['fn']
if not addr:
- output = u_boot_console.run_command('tftpboot %s' % (fn))
+ output = ubman.run_command('tftpboot %s' % (fn))
else:
- output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn))
+ output = ubman.run_command('tftpboot %x %s' % (addr, fn))
expected_text = 'Bytes transferred = '
sz = f.get('size', None)
if sz:
@@ -289,14 +293,14 @@ def test_net_tftpboot(u_boot_console):
if not expected_crc:
return
- if u_boot_console.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
+ if ubman.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
return
- output = u_boot_console.run_command('crc32 $fileaddr $filesize')
+ output = ubman.run_command('crc32 $fileaddr $filesize')
assert expected_crc in output
@pytest.mark.buildconfigspec('cmd_nfs')
-def test_net_nfs(u_boot_console):
+def test_net_nfs(ubman):
"""Test the nfs command.
A file is downloaded from the NFS server, its size and optionally its
@@ -309,16 +313,16 @@ def test_net_nfs(u_boot_console):
if not net_set_up:
pytest.skip('Network not initialized')
- f = u_boot_console.config.env.get('env__net_nfs_readable_file', None)
+ f = ubman.config.env.get('env__net_nfs_readable_file', None)
if not f:
pytest.skip('No NFS readable file to read')
addr = f.get('addr', None)
if not addr:
- addr = u_boot_utils.find_ram_base(u_boot_console)
+ addr = utils.find_ram_base(ubman)
fn = f['fn']
- output = u_boot_console.run_command('nfs %x %s' % (addr, fn))
+ output = ubman.run_command('nfs %x %s' % (addr, fn))
expected_text = 'Bytes transferred = '
sz = f.get('size', None)
if sz:
@@ -329,15 +333,14 @@ def test_net_nfs(u_boot_console):
if not expected_crc:
return
- if u_boot_console.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
+ if ubman.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
return
- output = u_boot_console.run_command('crc32 %x $filesize' % addr)
+ output = ubman.run_command('crc32 %x $filesize' % addr)
assert expected_crc in output
-@pytest.mark.buildconfigspec("cmd_net")
@pytest.mark.buildconfigspec("cmd_pxe")
-def test_net_pxe_get(u_boot_console):
+def test_net_pxe_get(ubman):
"""Test the pxe get command.
A pxe configuration file is downloaded from the TFTP server and interpreted
@@ -350,31 +353,31 @@ def test_net_pxe_get(u_boot_console):
if not net_set_up:
pytest.skip("Network not initialized")
- test_net_setup_static(u_boot_console)
+ test_net_setup_static(ubman)
- f = u_boot_console.config.env.get("env__net_pxe_readable_file", None)
+ f = ubman.config.env.get("env__net_pxe_readable_file", None)
if not f:
pytest.skip("No PXE readable file to read")
addr = f.get("addr", None)
- timeout = f.get("timeout", u_boot_console.p.timeout)
+ timeout = f.get("timeout", ubman.p.timeout)
pxeuuid = uuid.uuid1()
- u_boot_console.run_command(f"setenv pxeuuid {pxeuuid}")
+ ubman.run_command(f"setenv pxeuuid {pxeuuid}")
expected_text_uuid = f"Retrieving file: pxelinux.cfg/{pxeuuid}"
- ethaddr = u_boot_console.run_command("echo $ethaddr")
+ ethaddr = ubman.run_command("echo $ethaddr")
ethaddr = ethaddr.replace(':', '-')
expected_text_ethaddr = f"Retrieving file: pxelinux.cfg/01-{ethaddr}"
- ip = u_boot_console.run_command("echo $ipaddr")
+ ip = ubman.run_command("echo $ipaddr")
ip = ip.split('.')
ipaddr_file = "".join(['%02x' % int(x) for x in ip]).upper()
expected_text_ipaddr = f"Retrieving file: pxelinux.cfg/{ipaddr_file}"
expected_text_default = f"Retrieving file: pxelinux.cfg/default"
- with u_boot_console.temporary_timeout(timeout):
- output = u_boot_console.run_command("pxe get")
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command("pxe get")
assert "TIMEOUT" not in output
assert expected_text_uuid in output
@@ -391,9 +394,9 @@ def test_net_pxe_get(u_boot_console):
assert "Config file 'default.boot' found" in output
@pytest.mark.buildconfigspec("cmd_crc32")
-@pytest.mark.buildconfigspec("cmd_net")
+@pytest.mark.buildconfigspec("cmd_tftpboot")
@pytest.mark.buildconfigspec("cmd_tftpput")
-def test_net_tftpput(u_boot_console):
+def test_net_tftpput(ubman):
"""Test the tftpput command.
A file is downloaded from the TFTP server and then uploaded to the TFTP
@@ -406,35 +409,35 @@ def test_net_tftpput(u_boot_console):
if not net_set_up:
pytest.skip("Network not initialized")
- f = u_boot_console.config.env.get("env__net_tftp_readable_file", None)
+ f = ubman.config.env.get("env__net_tftp_readable_file", None)
if not f:
pytest.skip("No TFTP readable file to read")
addr = f.get("addr", None)
if not addr:
- addr = u_boot_utils.find_ram_base(u_boot_console)
+ addr = utils.find_ram_base(ubman)
sz = f.get("size", None)
- timeout = f.get("timeout", u_boot_console.p.timeout)
+ timeout = f.get("timeout", ubman.p.timeout)
fn = f["fn"]
fnu = f.get("fnu", "_".join([datetime.datetime.now().strftime("%y%m%d%H%M%S"), fn]))
expected_text = "Bytes transferred = "
if sz:
expected_text += "%d" % sz
- with u_boot_console.temporary_timeout(timeout):
- output = u_boot_console.run_command("tftpboot %x %s" % (addr, fn))
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command("tftpboot %x %s" % (addr, fn))
assert "TIMEOUT" not in output
assert expected_text in output
expected_tftpb_crc = f.get("crc32", None)
- output = u_boot_console.run_command("crc32 $fileaddr $filesize")
+ output = ubman.run_command("crc32 $fileaddr $filesize")
assert expected_tftpb_crc in output
- with u_boot_console.temporary_timeout(timeout):
- output = u_boot_console.run_command(
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command(
"tftpput $fileaddr $filesize $serverip:%s" % (fnu)
)
@@ -446,8 +449,8 @@ def test_net_tftpput(u_boot_console):
assert "Access violation" not in output
assert expected_text in output
- with u_boot_console.temporary_timeout(timeout):
- output = u_boot_console.run_command("tftpboot %x %s" % (addr, fnu))
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command("tftpboot %x %s" % (addr, fnu))
expected_text = "Bytes transferred = "
if sz:
@@ -455,5 +458,5 @@ def test_net_tftpput(u_boot_console):
assert "TIMEOUT" not in output
assert expected_text in output
- output = u_boot_console.run_command("crc32 $fileaddr $filesize")
+ output = ubman.run_command("crc32 $fileaddr $filesize")
assert expected_tftpb_crc in output
diff --git a/test/py/tests/test_net_boot.py b/test/py/tests/test_net_boot.py
new file mode 100644
index 00000000000..72086a74637
--- /dev/null
+++ b/test/py/tests/test_net_boot.py
@@ -0,0 +1,429 @@
+# SPDX-License-Identifier: GPL-2.0
+# (C) Copyright 2023, Advanced Micro Devices, Inc.
+
+"""
+Note: This test relies on boardenv_* containing configuration values to define
+which the network environment available for testing. Without this, this test
+will be automatically skipped.
+
+For example:
+
+.. code-block:: python
+
+ # Details regarding a boot image file that may be read from a TFTP server. This
+ # variable may be omitted or set to None if TFTP boot testing is not possible
+ # or desired.
+ env__net_tftp_bootable_file = {
+ 'fn': 'image.ub',
+ 'addr': 0x10000000,
+ 'size': 5058624,
+ 'crc32': 'c2244b26',
+ 'pattern': 'Linux',
+ 'config': 'config@2',
+ 'timeout': 50000,
+ 'check_type': 'boot_error',
+ 'check_pattern': 'ERROR',
+ }
+
+ # False or omitted if a TFTP boot test should be tested.
+ # If TFTP boot testing is not possible or desired, set this variable to True.
+ # For example: If FIT image is not proper to boot
+ env__tftp_boot_test_skip = False
+
+
+Here is the example of FIT image configurations:
+
+.. code-block:: devicetree
+
+ configurations {
+ default = "config@1";
+ config@1 {
+ description = "Boot Linux kernel with config@1";
+ kernel = "kernel@0";
+ fdt = "fdt@0";
+ ramdisk = "ramdisk@0";
+ hash@1 {
+ algo = "sha1";
+ };
+ };
+ config@2 {
+ description = "Boot Linux kernel with config@2";
+ kernel = "kernel@1";
+ fdt = "fdt@1";
+ ramdisk = "ramdisk@1";
+ hash@1 {
+ algo = "sha1";
+ };
+ };
+ };
+
+.. code-block:: python
+
+ # Details regarding a file that may be read from a TFTP server. This variable
+ # may be omitted or set to None if PXE testing is not possible or desired.
+ env__net_pxe_bootable_file = {
+ 'fn': 'default',
+ 'addr': 0x10000000,
+ 'size': 74,
+ 'timeout': 50000,
+ 'pattern': 'Linux',
+ 'valid_label': '1',
+ 'invalid_label': '2',
+ 'exp_str_invalid': 'Skipping install for failure retrieving',
+ 'local_label': '3',
+ 'exp_str_local': 'missing environment variable: localcmd',
+ 'empty_label': '4',
+ 'exp_str_empty': 'No kernel given, skipping boot',
+ 'check_type': 'boot_error',
+ 'check_pattern': 'ERROR',
+ }
+
+ # False if a PXE boot test should be tested.
+ # If PXE boot testing is not possible or desired, set this variable to True.
+ # For example: If pxe configuration file is not proper to boot
+ env__pxe_boot_test_skip = False
+
+Here is the example of pxe configuration file ordered based on the execution
+flow:
+
+1) /tftpboot/pxelinux.cfg/default-arm-zynqmp
+
+.. code-block::
+
+ menu include pxelinux.cfg/default-arm
+ timeout 50
+
+ default Linux
+
+2) /tftpboot/pxelinux.cfg/default-arm
+
+.. code-block::
+
+ menu title Linux boot selections
+ menu include pxelinux.cfg/default
+
+ label install
+ menu label Invalid boot
+ kernel kernels/install.bin
+ append console=ttyAMA0,38400 debug earlyprintk
+ initrd initrds/uzInitrdDebInstall
+
+ label local
+ menu label Local boot
+ append root=/dev/sdb1
+ localboot 1
+
+ label boot
+ menu label Empty boot
+
+3) /tftpboot/pxelinux.cfg/default
+
+.. code-block::
+
+ label Linux
+ menu label Boot kernel
+ kernel Image
+ fdt system.dtb
+ initrd rootfs.cpio.gz.u-boot
+"""
+
+import pytest
+import utils
+import test_net
+import re
+
+def setup_networking(ubman):
+ """Setup networking
+
+ Making use of the test_net test, first try and configure networking via
+ DHCP. If this fails, fall back to static configuration.
+ """
+ test_net.test_net_dhcp(ubman)
+ if not test_net.net_set_up:
+ test_net.test_net_setup_static(ubman)
+
+def setup_tftpboot_boot(ubman):
+ """Setup for the tftpboot 'boot' test
+
+ We check that a file to use has been configured. If it has, we download it
+ and ensure it has the expected crc32 value.
+ """
+ f = ubman.config.env.get('env__net_tftp_bootable_file', None)
+ if not f:
+ pytest.skip('No TFTP bootable file to read')
+
+ setup_networking(ubman)
+ addr = f.get('addr', None)
+ if not addr:
+ addr = utils.find_ram_base(ubman)
+
+ fn = f['fn']
+ timeout = f.get('timeout', 50000)
+
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command('tftpboot %x %s' % (addr, fn))
+
+ expected_text = 'Bytes transferred = '
+ sz = f.get('size', None)
+ if sz:
+ expected_text += '%d' % sz
+ assert expected_text in output
+
+ expected_crc = f.get('crc32', None)
+ output = ubman.run_command('crc32 %x $filesize' % addr)
+ if expected_crc:
+ assert expected_crc in output
+
+ pattern = f.get('pattern')
+ chk_type = f.get('check_type', 'boot_error')
+ chk_pattern = re.compile(f.get('check_pattern', 'ERROR'))
+ config = f.get('config', None)
+
+ return addr, timeout, pattern, chk_type, chk_pattern, config
+
+@pytest.mark.buildconfigspec('cmd_tftpboot')
+def test_net_tftpboot_boot(ubman):
+ """Boot the loaded image
+
+ A boot file (fit image) is downloaded from the TFTP server and booted using
+ bootm command with the default fit configuration, its boot log pattern are
+ validated.
+
+ The details of the file to download are provided by the boardenv_* file;
+ see the comment at the beginning of this file.
+ """
+ if ubman.config.env.get('env__tftp_boot_test_skip', True):
+ pytest.skip('TFTP boot test is not enabled!')
+
+ addr, timeout, pattern, chk_type, chk_pattern, imcfg = setup_tftpboot_boot(
+ ubman
+ )
+
+ if imcfg:
+ bootcmd = 'bootm %x#%s' % (addr, imcfg)
+ else:
+ bootcmd = 'bootm %x' % addr
+
+ with ubman.enable_check(
+ chk_type, chk_pattern
+ ), ubman.temporary_timeout(timeout):
+ try:
+ # wait_for_prompt=False makes the core code not wait for the U-Boot
+ # prompt code to be seen, since it won't be on a successful kernel
+ # boot
+ ubman.run_command(bootcmd, wait_for_prompt=False)
+
+ # Wait for boot log pattern
+ ubman.wait_for(pattern)
+ finally:
+ # This forces the console object to be shutdown, so any subsequent
+ # test will reset the board back into U-Boot. We want to force this
+ # no matter whether the kernel boot passed or failed.
+ ubman.drain_console()
+ ubman.cleanup_spawn()
+
+def setup_pxe_boot(ubman):
+ """Setup for the PXE 'boot' test
+
+ Make sure that the file to load via PXE boot has been configured.
+ """
+ f = ubman.config.env.get('env__net_pxe_bootable_file', None)
+ if not f:
+ pytest.skip('No PXE bootable file to read')
+
+ setup_networking(ubman)
+ bootfile = ubman.run_command('echo $bootfile')
+ if not bootfile:
+ bootfile = '<NULL>'
+
+ return f, bootfile
+
+@pytest.mark.buildconfigspec('cmd_pxe')
+def test_net_pxe_boot(ubman):
+ """Test the pxe boot command.
+
+ A pxe configuration file is downloaded from the TFTP server and interpreted
+ to boot the images mentioned in pxe configuration file.
+
+ The details of the file to download are provided by the boardenv_* file;
+ see the comment at the beginning of this file.
+ """
+ if ubman.config.env.get('env__pxe_boot_test_skip', True):
+ pytest.skip('PXE boot test is not enabled!')
+
+ f, bootfile = setup_pxe_boot(ubman)
+ addr = f.get('addr', None)
+ timeout = f.get('timeout', ubman.p.timeout)
+ fn = f['fn']
+
+ if addr:
+ ubman.run_command('setenv pxefile_addr_r %x' % addr)
+
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command('pxe get')
+
+ expected_text = 'Bytes transferred = '
+ sz = f.get('size', None)
+ if sz:
+ expected_text += '%d' % sz
+ assert 'TIMEOUT' not in output
+ assert expected_text in output
+ assert f"Config file '{bootfile}' found" in output
+
+ pattern = f.get('pattern')
+ chk_type = f.get('check_type', 'boot_error')
+ chk_pattern = re.compile(f.get('check_pattern', 'ERROR'))
+
+ if not addr:
+ pxe_boot_cmd = 'pxe boot'
+ else:
+ pxe_boot_cmd = 'pxe boot %x' % addr
+
+ with ubman.enable_check(
+ chk_type, chk_pattern
+ ), ubman.temporary_timeout(timeout):
+ try:
+ ubman.run_command(pxe_boot_cmd, wait_for_prompt=False)
+ ubman.wait_for(pattern)
+ finally:
+ ubman.drain_console()
+ ubman.cleanup_spawn()
+
+@pytest.mark.buildconfigspec('cmd_pxe')
+def test_net_pxe_boot_config(ubman):
+ """Test the pxe boot command by selecting different combination of labels
+
+ A pxe configuration file is downloaded from the TFTP server and interpreted
+ to boot the images mentioned in pxe configuration file.
+
+ The details of the file to download are provided by the boardenv_* file;
+ see the comment at the beginning of this file.
+ """
+ if ubman.config.env.get('env__pxe_boot_test_skip', True):
+ pytest.skip('PXE boot test is not enabled!')
+
+ f, bootfile = setup_pxe_boot(ubman)
+ addr = f.get('addr', None)
+ timeout = f.get('timeout', ubman.p.timeout)
+ fn = f['fn']
+ local_label = f['local_label']
+ empty_label = f['empty_label']
+ exp_str_local = f['exp_str_local']
+ exp_str_empty = f['exp_str_empty']
+
+ if addr:
+ ubman.run_command('setenv pxefile_addr_r %x' % addr)
+
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command('pxe get')
+
+ expected_text = 'Bytes transferred = '
+ sz = f.get('size', None)
+ if sz:
+ expected_text += '%d' % sz
+ assert 'TIMEOUT' not in output
+ assert expected_text in output
+ assert f"Config file '{bootfile}' found" in output
+
+ pattern = f.get('pattern')
+ chk_type = f.get('check_type', 'boot_error')
+ chk_pattern = re.compile(f.get('check_pattern', 'ERROR'))
+
+ if not addr:
+ pxe_boot_cmd = 'pxe boot'
+ else:
+ pxe_boot_cmd = 'pxe boot %x' % addr
+
+ with ubman.enable_check(
+ chk_type, chk_pattern
+ ), ubman.temporary_timeout(timeout):
+ try:
+ ubman.run_command(pxe_boot_cmd, wait_for_prompt=False)
+
+ # pxe config is loaded where multiple labels are there and need to
+ # select particular label to boot and check for expected string
+ # In this case, local label is selected and it should look for
+ # localcmd env variable and if that variable is not defined it
+ # should not boot it and come out to u-boot prompt
+ ubman.wait_for('Enter choice:')
+ ubman.run_command(local_label, wait_for_prompt=False)
+ expected_str = ubman.p.expect([exp_str_local])
+ assert (
+ expected_str == 0
+ ), f'Expected string: {exp_str_local} did not match!'
+
+ # In this case, empty label is selected and it should look for
+ # kernel image path and if it is not set it should fail it and load
+ # default label to boot
+ ubman.run_command(pxe_boot_cmd, wait_for_prompt=False)
+ ubman.wait_for('Enter choice:')
+ ubman.run_command(empty_label, wait_for_prompt=False)
+ expected_str = ubman.p.expect([exp_str_empty])
+ assert (
+ expected_str == 0
+ ), f'Expected string: {exp_str_empty} did not match!'
+
+ ubman.wait_for(pattern)
+ finally:
+ ubman.drain_console()
+ ubman.cleanup_spawn()
+
+@pytest.mark.buildconfigspec('cmd_pxe')
+def test_net_pxe_boot_config_invalid(ubman):
+ """Test the pxe boot command by selecting invalid label
+
+ A pxe configuration file is downloaded from the TFTP server and interpreted
+ to boot the images mentioned in pxe configuration file.
+
+ The details of the file to download are provided by the boardenv_* file;
+ see the comment at the beginning of this file.
+ """
+ if ubman.config.env.get('env__pxe_boot_test_skip', True):
+ pytest.skip('PXE boot test is not enabled!')
+
+ f, bootfile = setup_pxe_boot(ubman)
+ addr = f.get('addr', None)
+ timeout = f.get('timeout', ubman.p.timeout)
+ fn = f['fn']
+ invalid_label = f['invalid_label']
+ exp_str_invalid = f['exp_str_invalid']
+
+ if addr:
+ ubman.run_command('setenv pxefile_addr_r %x' % addr)
+
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command('pxe get')
+
+ expected_text = 'Bytes transferred = '
+ sz = f.get('size', None)
+ if sz:
+ expected_text += '%d' % sz
+ assert 'TIMEOUT' not in output
+ assert expected_text in output
+ assert f"Config file '{bootfile}' found" in output
+
+ pattern = f.get('pattern')
+ if not addr:
+ pxe_boot_cmd = 'pxe boot'
+ else:
+ pxe_boot_cmd = 'pxe boot %x' % addr
+
+ with ubman.temporary_timeout(timeout):
+ try:
+ ubman.run_command(pxe_boot_cmd, wait_for_prompt=False)
+
+ # pxe config is loaded where multiple labels are there and need to
+ # select particular label to boot and check for expected string
+ # In this case invalid label is selected, it should load invalid
+ # label and if it fails it should load the default label to boot
+ ubman.wait_for('Enter choice:')
+ ubman.run_command(invalid_label, wait_for_prompt=False)
+ expected_str = ubman.p.expect([exp_str_invalid])
+ assert (
+ expected_str == 0
+ ), f'Expected string: {exp_str_invalid} did not match!'
+
+ ubman.wait_for(pattern)
+ finally:
+ ubman.drain_console()
+ ubman.cleanup_spawn()
diff --git a/test/py/tests/test_of_migrate.py b/test/py/tests/test_of_migrate.py
index 910f7c05510..ab89332331e 100644
--- a/test/py/tests/test_of_migrate.py
+++ b/test/py/tests/test_of_migrate.py
@@ -7,18 +7,18 @@
import os
import pytest
-import u_boot_utils as util
+import utils
# This is needed for Azure, since the default '..' directory is not writeable
TMPDIR1 = '/tmp/test_no_migrate'
TMPDIR2 = '/tmp/test_no_migrate_spl'
TMPDIR3 = '/tmp/test_migrate'
-def build_for_migrate(cons, replace_pair, board, tmpdir, disable_migrate=True):
+def build_for_migrate(ubman, replace_pair, board, tmpdir, disable_migrate=True):
"""Build an updated U-Boot with a slightly modified device tree
Args:
- cons (ConsoleBase): U-Boot console
+ ubman (ConsoleBase): U-Boot console
replace_pair (tuple):
String to find
String to replace it with
@@ -26,15 +26,15 @@ def build_for_migrate(cons, replace_pair, board, tmpdir, disable_migrate=True):
tmpdir (str): Temporary directory to use
disable_migrate (bool): True to disable CONFIG_OF_TAG_MIGRATE in build
"""
- srcdir = cons.config.source_dir
- build_dir = cons.config.build_dir
+ srcdir = ubman.config.source_dir
+ build_dir = ubman.config.build_dir
# Get the source for the existing dts
dt_dir = os.path.join(build_dir, 'arch', 'sandbox', 'dts')
orig_fname = os.path.join(dt_dir, 'sandbox.dtb')
out_dts = os.path.join(dt_dir, 'sandbox_out.dts')
- util.run_and_log(cons, ['dtc', orig_fname, '-I', 'dtb', '-O', 'dts',
- '-o', out_dts])
+ utils.run_and_log(ubman, ['dtc', orig_fname, '-I', 'dtb', '-O', 'dts',
+ '-o', out_dts])
# Update it to use an old tag
with open(out_dts) as inf:
@@ -45,7 +45,7 @@ def build_for_migrate(cons, replace_pair, board, tmpdir, disable_migrate=True):
with open(dts_fname, 'w') as outf:
print(data, file=outf)
dtb_fname = os.path.join(dt_dir, 'sandbox_oldtag.dtb')
- util.run_and_log(cons, ['dtc', dts_fname, '-o', dtb_fname])
+ utils.run_and_log(ubman, ['dtc', dts_fname, '-o', dtb_fname])
migrate = ['-a', '~CONFIG_OF_TAG_MIGRATE'] if disable_migrate else []
@@ -54,24 +54,23 @@ def build_for_migrate(cons, replace_pair, board, tmpdir, disable_migrate=True):
env['EXT_DTB'] = dtb_fname
env['DEVICE_TREE'] = 'sandbox_new'
env['NO_LTO'] = '1' # Speed up build
- out = util.run_and_log(
- cons, ['./tools/buildman/buildman', '-m', '--board', board,
+ out = utils.run_and_log(
+ ubman, ['./tools/buildman/buildman', '-m', '--board', board,
*migrate, '-w', '-o', tmpdir], ignore_errors=True, env=env)
return out
@pytest.mark.slow
@pytest.mark.boardspec('sandbox')
-def test_of_no_migrate(u_boot_console):
+def test_of_no_migrate(ubman):
"""Test sandbox with old boot phase tags like u-boot,dm-pre-proper"""
- cons = u_boot_console
- build_for_migrate(cons, ['bootph-some-ram', 'u-boot,dm-pre-proper'],
+ build_for_migrate(ubman, ['bootph-some-ram', 'u-boot,dm-pre-proper'],
'sandbox', TMPDIR1)
# It should fail to run, since the lcd device will not be bound before
# relocation. so won't get its frame-buffer memory
- out = util.run_and_log(
- cons, [os.path.join(TMPDIR1, 'u-boot'), '-D', '-c', 'help'],
+ out = utils.run_and_log(
+ ubman, [os.path.join(TMPDIR1, 'u-boot'), '-D', '-c', 'help'],
ignore_errors=True)
assert "Video device 'lcd' cannot allocate frame buffer memory" in out
@@ -80,11 +79,10 @@ def test_of_no_migrate(u_boot_console):
@pytest.mark.boardspec('sandbox_spl')
@pytest.mark.boardspec('spl_of_platdata_inst')
@pytest.mark.boardspec('!sandbox_tpl')
-def test_of_no_migrate_spl(u_boot_console):
+def test_of_no_migrate_spl(ubman):
"""Test sandbox with old boot phase tags like u-boot,dm-spl"""
- cons = u_boot_console
- out = build_for_migrate(cons, ['bootph-pre-ram', 'u-boot,dm-spl'],
+ out = build_for_migrate(ubman, ['bootph-pre-ram', 'u-boot,dm-spl'],
'sandbox_spl', TMPDIR2)
# It should fail to build, since the SPL DT will not include 'spl-test'
@@ -94,15 +92,14 @@ def test_of_no_migrate_spl(u_boot_console):
@pytest.mark.slow
@pytest.mark.boardspec('sandbox')
-def test_of_migrate(u_boot_console):
+def test_of_migrate(ubman):
"""Test sandbox shows a message when tags were migrated"""
- cons = u_boot_console
- build_for_migrate(cons, ['bootph-some-ram', 'u-boot,dm-pre-proper'],
+ build_for_migrate(ubman, ['bootph-some-ram', 'u-boot,dm-pre-proper'],
'sandbox', TMPDIR3, disable_migrate=False)
# It should show a migration message
- out = util.run_and_log(
- cons, [os.path.join(TMPDIR3, 'u-boot'), '-D', '-c', 'help'],
+ out = utils.run_and_log(
+ ubman, [os.path.join(TMPDIR3, 'u-boot'), '-D', '-c', 'help'],
ignore_errors=True)
assert "Warning: Device tree includes old 'u-boot,dm-' tags" in out
diff --git a/test/py/tests/test_ofplatdata.py b/test/py/tests/test_ofplatdata.py
index 51a188454f3..d31fa55f7c7 100644
--- a/test/py/tests/test_ofplatdata.py
+++ b/test/py/tests/test_ofplatdata.py
@@ -2,16 +2,15 @@
# Copyright (c) 2016 Google, Inc
import pytest
-import u_boot_utils as util
+import utils
@pytest.mark.boardspec('sandbox_spl')
@pytest.mark.buildconfigspec('spl_of_platdata')
-def test_spl_devicetree(u_boot_console):
+def test_spl_devicetree(ubman):
"""Test content of spl device-tree"""
- cons = u_boot_console
- dtb = cons.config.build_dir + '/spl/u-boot-spl.dtb'
- fdtgrep = cons.config.build_dir + '/tools/fdtgrep'
- output = util.run_and_log(cons, [fdtgrep, '-l', dtb])
+ dtb = ubman.config.build_dir + '/spl/u-boot-spl.dtb'
+ fdtgrep = ubman.config.build_dir + '/tools/fdtgrep'
+ output = utils.run_and_log(ubman, [fdtgrep, '-l', dtb])
assert "bootph-all" not in output
assert "bootph-some-ram" not in output
diff --git a/test/py/tests/test_optee_rpmb.py b/test/py/tests/test_optee_rpmb.py
index 8a081b5c494..04b3b5e41ef 100644
--- a/test/py/tests/test_optee_rpmb.py
+++ b/test/py/tests/test_optee_rpmb.py
@@ -7,14 +7,14 @@ This tests optee_rpmb cmd in U-Boot
"""
import pytest
-import u_boot_utils as util
+import utils
@pytest.mark.buildconfigspec('cmd_optee_rpmb')
-def test_optee_rpmb_read_write(u_boot_console):
+def test_optee_rpmb_read_write(ubman):
"""Test OP-TEE RPMB cmd read/write
"""
- response = u_boot_console.run_command('optee_rpmb write_pvalue test_variable test_value')
+ response = ubman.run_command('optee_rpmb write_pvalue test_variable test_value')
assert response == 'Wrote 11 bytes'
- response = u_boot_console.run_command('optee_rpmb read_pvalue test_variable 11')
- assert response == 'Read 11 bytes, value = test_value' \ No newline at end of file
+ response = ubman.run_command('optee_rpmb read_pvalue test_variable 11')
+ assert response == 'Read 11 bytes, value = test_value'
diff --git a/test/py/tests/test_part.py b/test/py/tests/test_part.py
index 2b5184654db..04c95a6d3cc 100644
--- a/test/py/tests/test_part.py
+++ b/test/py/tests/test_part.py
@@ -7,8 +7,8 @@ import pytest
@pytest.mark.buildconfigspec('cmd_part')
@pytest.mark.buildconfigspec('partitions')
@pytest.mark.buildconfigspec('efi_partition')
-def test_part_types(u_boot_console):
+def test_part_types(ubman):
"""Test that `part types` prints a result which includes `EFI`."""
- output = u_boot_console.run_command('part types')
+ output = ubman.run_command('part types')
assert "Supported partition tables:" in output
assert "EFI" in output
diff --git a/test/py/tests/test_pinmux.py b/test/py/tests/test_pinmux.py
index 794994e12d1..ee79e843341 100644
--- a/test/py/tests/test_pinmux.py
+++ b/test/py/tests/test_pinmux.py
@@ -1,27 +1,27 @@
# SPDX-License-Identifier: GPL-2.0
import pytest
-import u_boot_utils
+import utils
@pytest.mark.buildconfigspec('cmd_pinmux')
-def test_pinmux_usage_1(u_boot_console):
+def test_pinmux_usage_1(ubman):
"""Test that 'pinmux' command without parameters displays
pinmux usage."""
- output = u_boot_console.run_command('pinmux')
+ output = ubman.run_command('pinmux')
assert 'Usage:' in output
@pytest.mark.buildconfigspec('cmd_pinmux')
-def test_pinmux_usage_2(u_boot_console):
+def test_pinmux_usage_2(ubman):
"""Test that 'pinmux status' executed without previous "pinmux dev"
command displays error message."""
- output = u_boot_console.run_command('pinmux status')
+ output = ubman.run_command('pinmux status')
assert 'pin-controller device not selected' in output
@pytest.mark.buildconfigspec('cmd_pinmux')
@pytest.mark.boardspec('sandbox')
-def test_pinmux_status_all(u_boot_console):
+def test_pinmux_status_all(ubman):
"""Test that 'pinmux status -a' displays pin's muxing."""
- output = u_boot_console.run_command('pinmux status -a')
+ output = ubman.run_command('pinmux status -a')
assert ('pinctrl-gpio:' in output)
assert ('a5 : gpio output .' in output)
@@ -40,36 +40,36 @@ def test_pinmux_status_all(u_boot_console):
@pytest.mark.buildconfigspec('cmd_pinmux')
@pytest.mark.boardspec('sandbox')
-def test_pinmux_list(u_boot_console):
+def test_pinmux_list(ubman):
"""Test that 'pinmux list' returns the pin-controller list."""
- output = u_boot_console.run_command('pinmux list')
+ output = ubman.run_command('pinmux list')
assert 'sandbox_pinctrl' in output
@pytest.mark.buildconfigspec('cmd_pinmux')
-def test_pinmux_dev_bad(u_boot_console):
+def test_pinmux_dev_bad(ubman):
"""Test that 'pinmux dev' returns an error when trying to select a
wrong pin controller."""
pincontroller = 'bad_pin_controller_name'
- output = u_boot_console.run_command('pinmux dev ' + pincontroller)
+ output = ubman.run_command('pinmux dev ' + pincontroller)
expected_output = 'Can\'t get the pin-controller: ' + pincontroller + '!'
assert (expected_output in output)
@pytest.mark.buildconfigspec('cmd_pinmux')
@pytest.mark.boardspec('sandbox')
-def test_pinmux_dev(u_boot_console):
+def test_pinmux_dev(ubman):
"""Test that 'pinmux dev' select the wanted pin controller."""
pincontroller = 'pinctrl'
- output = u_boot_console.run_command('pinmux dev ' + pincontroller)
+ output = ubman.run_command('pinmux dev ' + pincontroller)
expected_output = 'dev: ' + pincontroller
assert (expected_output in output)
@pytest.mark.buildconfigspec('cmd_pinmux')
@pytest.mark.boardspec('sandbox')
-def test_pinmux_status(u_boot_console):
+def test_pinmux_status(ubman):
"""Test that 'pinmux status' displays selected pincontroller's pin
muxing descriptions."""
- u_boot_console.run_command('pinmux dev pinctrl')
- output = u_boot_console.run_command('pinmux status')
+ ubman.run_command('pinmux dev pinctrl')
+ output = ubman.run_command('pinmux status')
assert (not 'pinctrl-gpio:' in output)
assert (not 'pinctrl:' in output)
diff --git a/test/py/tests/test_pstore.py b/test/py/tests/test_pstore.py
index 5a35724f60a..70e07503ad3 100644
--- a/test/py/tests/test_pstore.py
+++ b/test/py/tests/test_pstore.py
@@ -3,7 +3,7 @@
# Author: Frédéric Danis <frederic.danis@collabora.com>
import pytest
-import u_boot_utils
+import utils
import os
import tempfile
import shutil
@@ -15,63 +15,63 @@ PSTORE_PANIC2='test/py/tests/test_pstore_data_panic2.hex'
PSTORE_CONSOLE='test/py/tests/test_pstore_data_console.hex'
ADDR=0x01000008
-def load_pstore(u_boot_console):
+def load_pstore(ubman):
"""Load PStore records from sample files"""
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'host load hostfs - 0x%x %s' % (PSTORE_ADDR,
- os.path.join(u_boot_console.config.source_dir, PSTORE_PANIC1)),
+ os.path.join(ubman.config.source_dir, PSTORE_PANIC1)),
'host load hostfs - 0x%x %s' % (PSTORE_ADDR + 4096,
- os.path.join(u_boot_console.config.source_dir, PSTORE_PANIC2)),
+ os.path.join(ubman.config.source_dir, PSTORE_PANIC2)),
'host load hostfs - 0x%x %s' % (PSTORE_ADDR + 253 * 4096,
- os.path.join(u_boot_console.config.source_dir, PSTORE_CONSOLE)),
+ os.path.join(ubman.config.source_dir, PSTORE_CONSOLE)),
'pstore set 0x%x 0x%x' % (PSTORE_ADDR, PSTORE_LENGTH)])
-def checkfile(u_boot_console, path, filesize, checksum):
+def checkfile(ubman, path, filesize, checksum):
"""Check file against MD5 checksum"""
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'load hostfs - %x %s' % (ADDR, path),
'printenv filesize'])
assert('filesize=%x' % (filesize) in ''.join(output))
- output = u_boot_console.run_command_list([
+ output = ubman.run_command_list([
'md5sum %x $filesize' % ADDR,
'setenv filesize'])
assert(checksum in ''.join(output))
@pytest.mark.buildconfigspec('cmd_pstore')
-def test_pstore_display_all_records(u_boot_console):
+def test_pstore_display_all_records(ubman):
"""Test that pstore displays all records."""
- u_boot_console.run_command('')
- load_pstore(u_boot_console)
- response = u_boot_console.run_command('pstore display')
+ ubman.run_command('')
+ load_pstore(ubman)
+ response = ubman.run_command('pstore display')
assert('**** Dump' in response)
assert('**** Console' in response)
@pytest.mark.buildconfigspec('cmd_pstore')
-def test_pstore_display_one_record(u_boot_console):
+def test_pstore_display_one_record(ubman):
"""Test that pstore displays only one record."""
- u_boot_console.run_command('')
- load_pstore(u_boot_console)
- response = u_boot_console.run_command('pstore display dump 1')
+ ubman.run_command('')
+ load_pstore(ubman)
+ response = ubman.run_command('pstore display dump 1')
assert('Panic#2 Part1' in response)
assert('**** Console' not in response)
@pytest.mark.buildconfigspec('cmd_pstore')
-def test_pstore_save_records(u_boot_console):
+def test_pstore_save_records(ubman):
"""Test that pstore saves all records."""
outdir = tempfile.mkdtemp()
- u_boot_console.run_command('')
- load_pstore(u_boot_console)
- u_boot_console.run_command('pstore save hostfs - %s' % (outdir))
+ ubman.run_command('')
+ load_pstore(ubman)
+ ubman.run_command('pstore save hostfs - %s' % (outdir))
- checkfile(u_boot_console, '%s/dmesg-ramoops-0' % (outdir), 3798, '8059335ab4cfa62c77324c491659c503')
- checkfile(u_boot_console, '%s/dmesg-ramoops-1' % (outdir), 4035, '3ff30df3429d81939c75d0070b5187b9')
- checkfile(u_boot_console, '%s/console-ramoops-0' % (outdir), 4084, 'bb44de4a9b8ebd9b17ae98003287325b')
+ checkfile(ubman, '%s/dmesg-ramoops-0' % (outdir), 3798, '8059335ab4cfa62c77324c491659c503')
+ checkfile(ubman, '%s/dmesg-ramoops-1' % (outdir), 4035, '3ff30df3429d81939c75d0070b5187b9')
+ checkfile(ubman, '%s/console-ramoops-0' % (outdir), 4084, 'bb44de4a9b8ebd9b17ae98003287325b')
shutil.rmtree(outdir)
diff --git a/test/py/tests/test_qfw.py b/test/py/tests/test_qfw.py
index 8b668c9721a..844cd3d9367 100644
--- a/test/py/tests/test_qfw.py
+++ b/test/py/tests/test_qfw.py
@@ -6,20 +6,20 @@
import pytest
@pytest.mark.buildconfigspec('cmd_qfw')
-def test_qfw_cpus(u_boot_console):
+def test_qfw_cpus(ubman):
"Test QEMU firmware config reports the CPU count."
- output = u_boot_console.run_command('qfw cpus')
+ output = ubman.run_command('qfw cpus')
# The actual number varies depending on the board under test, so only
# assert a non-zero output.
assert 'cpu(s) online' in output
assert '0 cpu(s) online' not in output
@pytest.mark.buildconfigspec('cmd_qfw')
-def test_qfw_list(u_boot_console):
+def test_qfw_list(ubman):
"Test QEMU firmware config lists devices."
- output = u_boot_console.run_command('qfw list')
+ output = ubman.run_command('qfw list')
# Assert either:
# 1) 'test-one', from the sandbox driver, or
# 2) 'bootorder', found in every real QEMU implementation.
diff --git a/test/py/tests/test_reset.py b/test/py/tests/test_reset.py
index 00fc31da57d..af079a70664 100644
--- a/test/py/tests/test_reset.py
+++ b/test/py/tests/test_reset.py
@@ -24,15 +24,15 @@ env__reset_test = {
import pytest
import test_000_version
-def setup_reset_env(u_boot_console):
- if u_boot_console.config.env.get('env__reset_test_skip', False):
+def setup_reset_env(ubman):
+ if ubman.config.env.get('env__reset_test_skip', False):
pytest.skip('reset test is not enabled')
- output = u_boot_console.run_command('echo $modeboot')
+ output = ubman.run_command('echo $modeboot')
if output:
bootmode = output
else:
- f = u_boot_console.config.env.get('env__reset_test', None)
+ f = ubman.config.env.get('env__reset_test', None)
if not f:
pytest.skip('bootmode cannot be determined')
bootmode = f.get('bootmode', 'jtagboot')
@@ -41,23 +41,23 @@ def setup_reset_env(u_boot_console):
pytest.skip('skipping reset test due to jtag bootmode')
@pytest.mark.buildconfigspec('hush_parser')
-def test_reset(u_boot_console):
+def test_reset(ubman):
"""Test the reset command in non-JTAG bootmode.
It does COLD reset, which resets CPU, DDR and peripherals
"""
- setup_reset_env(u_boot_console)
- u_boot_console.run_command('reset', wait_for_reboot=True)
+ setup_reset_env(ubman)
+ ubman.run_command('reset', wait_for_reboot=True)
# Checks the u-boot command prompt's functionality after reset
- test_000_version.test_version(u_boot_console)
+ test_000_version.test_version(ubman)
@pytest.mark.buildconfigspec('hush_parser')
-def test_reset_w(u_boot_console):
+def test_reset_w(ubman):
"""Test the reset -w command in non-JTAG bootmode.
It does WARM reset, which resets CPU but keep DDR/peripherals active.
"""
- setup_reset_env(u_boot_console)
- u_boot_console.run_command('reset -w', wait_for_reboot=True)
+ setup_reset_env(ubman)
+ ubman.run_command('reset -w', wait_for_reboot=True)
# Checks the u-boot command prompt's functionality after reset
- test_000_version.test_version(u_boot_console)
+ test_000_version.test_version(ubman)
diff --git a/test/py/tests/test_sandbox_exit.py b/test/py/tests/test_sandbox_exit.py
index 706f5fa3594..9610adf1fe7 100644
--- a/test/py/tests/test_sandbox_exit.py
+++ b/test/py/tests/test_sandbox_exit.py
@@ -7,39 +7,39 @@ import signal
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('sysreset_cmd_poweroff')
-def test_poweroff(u_boot_console):
+def test_poweroff(ubman):
"""Test that the "poweroff" command exits sandbox process."""
- u_boot_console.run_command('poweroff', wait_for_prompt=False)
- assert(u_boot_console.validate_exited())
+ ubman.run_command('poweroff', wait_for_prompt=False)
+ assert(ubman.validate_exited())
@pytest.mark.boardspec('sandbox')
-def test_ctrl_c(u_boot_console):
+def test_ctrl_c(ubman):
"""Test that sending SIGINT to sandbox causes it to exit."""
- u_boot_console.kill(signal.SIGINT)
- assert(u_boot_console.validate_exited())
+ ubman.kill(signal.SIGINT)
+ assert(ubman.validate_exited())
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_exception')
@pytest.mark.buildconfigspec('sandbox_crash_reset')
-def test_exception_reset(u_boot_console):
+def test_exception_reset(ubman):
"""Test that SIGILL causes a reset."""
- u_boot_console.run_command('exception undefined', wait_for_prompt=False)
- m = u_boot_console.p.expect(['resetting ...', 'U-Boot'])
+ ubman.run_command('exception undefined', wait_for_prompt=False)
+ m = ubman.p.expect(['resetting ...', 'U-Boot'])
if m != 0:
raise Exception('SIGILL did not lead to reset')
- m = u_boot_console.p.expect(['U-Boot', '=>'])
+ m = ubman.p.expect(['U-Boot', '=>'])
if m != 0:
raise Exception('SIGILL did not lead to reset')
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_exception')
@pytest.mark.notbuildconfigspec('sandbox_crash_reset')
-def test_exception_exit(u_boot_console):
+def test_exception_exit(ubman):
"""Test that SIGILL causes a reset."""
- u_boot_console.run_command('exception undefined', wait_for_prompt=False)
- assert(u_boot_console.validate_exited())
+ ubman.run_command('exception undefined', wait_for_prompt=False)
+ assert(ubman.validate_exited())
diff --git a/test/py/tests/test_sandbox_opts.py b/test/py/tests/test_sandbox_opts.py
index 422b43cb3bc..48f5b313870 100644
--- a/test/py/tests/test_sandbox_opts.py
+++ b/test/py/tests/test_sandbox_opts.py
@@ -4,27 +4,25 @@
import pytest
-import u_boot_utils as util
+import utils
# This is needed for Azure, since the default '..' directory is not writeable
TMPDIR = '/tmp/test_cmdline'
@pytest.mark.slow
@pytest.mark.boardspec('sandbox')
-def test_sandbox_cmdline(u_boot_console):
+def test_sandbox_cmdline(ubman):
"""Test building sandbox without CONFIG_CMDLINE"""
- cons = u_boot_console
- out = util.run_and_log(
- cons, ['./tools/buildman/buildman', '-m', '--board', 'sandbox',
+ utils.run_and_log(
+ ubman, ['./tools/buildman/buildman', '-m', '--board', 'sandbox',
'-a', '~CMDLINE', '-o', TMPDIR])
@pytest.mark.slow
@pytest.mark.boardspec('sandbox')
-def test_sandbox_lto(u_boot_console):
+def test_sandbox_lto(ubman):
"""Test building sandbox without CONFIG_LTO"""
- cons = u_boot_console
- out = util.run_and_log(
- cons, ['./tools/buildman/buildman', '-m', '--board', 'sandbox',
+ utils.run_and_log(
+ ubman, ['./tools/buildman/buildman', '-m', '--board', 'sandbox',
'-a', '~LTO', '-o', TMPDIR])
diff --git a/test/py/tests/test_saveenv.py b/test/py/tests/test_saveenv.py
index 7faa3bdf93d..019b229d30e 100644
--- a/test/py/tests/test_saveenv.py
+++ b/test/py/tests/test_saveenv.py
@@ -28,15 +28,15 @@ import string
import uuid
# Setup the env
-def setup_saveenv_env(u_boot_console):
- if u_boot_console.config.env.get('env__saveenv_test_skip', False):
+def setup_saveenv_env(ubman):
+ if ubman.config.env.get('env__saveenv_test_skip', False):
pytest.skip('saveenv test is not enabled')
- output = u_boot_console.run_command('echo $modeboot')
+ output = ubman.run_command('echo $modeboot')
if output:
bootmode = output
else:
- f = u_boot_console.config.env.get('env__saveenv_test', None)
+ f = ubman.config.env.get('env__saveenv_test', None)
if not f:
pytest.skip('bootmode cannot be determined')
bootmode = f.get('bootmode', 'jtagboot')
@@ -45,39 +45,39 @@ def setup_saveenv_env(u_boot_console):
pytest.skip('skipping saveenv test due to jtag bootmode')
# Check return code
-def ret_code(u_boot_console):
- return u_boot_console.run_command('echo $?')
+def ret_code(ubman):
+ return ubman.run_command('echo $?')
# Verify env variable
-def check_env(u_boot_console, var_name, var_value):
+def check_env(ubman, var_name, var_value):
if var_value:
- output = u_boot_console.run_command(f'printenv {var_name}')
+ output = ubman.run_command(f'printenv {var_name}')
var_value = str(var_value)
if (var_value.startswith("'") and var_value.endswith("'")) or (
var_value.startswith('"') and var_value.endswith('"')
):
var_value = var_value.split(var_value[-1])[1]
assert var_value in output
- assert ret_code(u_boot_console).endswith('0')
+ assert ret_code(ubman).endswith('0')
else:
- u_boot_console.p.send(f'printenv {var_name}\n')
- output = u_boot_console.p.expect(['not defined'])
+ ubman.p.send(f'printenv {var_name}\n')
+ output = ubman.p.expect(['not defined'])
assert output == 0
- assert ret_code(u_boot_console).endswith('1')
+ assert ret_code(ubman).endswith('1')
# Set env variable
-def set_env(u_boot_console, var_name, var_value):
- u_boot_console.run_command(f'setenv {var_name} {var_value}')
- assert ret_code(u_boot_console).endswith('0')
- check_env(u_boot_console, var_name, var_value)
+def set_env(ubman, var_name, var_value):
+ ubman.run_command(f'setenv {var_name} {var_value}')
+ assert ret_code(ubman).endswith('0')
+ check_env(ubman, var_name, var_value)
@pytest.mark.buildconfigspec('cmd_saveenv')
@pytest.mark.buildconfigspec('hush_parser')
-def test_saveenv(u_boot_console):
+def test_saveenv(ubman):
"""Test the saveenv command in non-JTAG bootmode.
It saves the U-Boot environment in persistent storage.
"""
- setup_saveenv_env(u_boot_console)
+ setup_saveenv_env(ubman)
# Set env for random mac address
rand_mac = '%02x:%02x:%02x:%02x:%02x:%02x' % (
@@ -88,50 +88,50 @@ def test_saveenv(u_boot_console):
random.randint(0, 255),
random.randint(0, 255),
)
- set_env(u_boot_console, 'mac_addr', rand_mac)
+ set_env(ubman, 'mac_addr', rand_mac)
# Set env for random IPv4 address
rand_ipv4 = ipaddress.IPv4Address._string_from_ip_int(
random.randint(0, ipaddress.IPv4Address._ALL_ONES)
)
- set_env(u_boot_console, 'ipv4_addr', rand_ipv4)
+ set_env(ubman, 'ipv4_addr', rand_ipv4)
# Set env for random IPv6 address
rand_ipv6 = ipaddress.IPv6Address._string_from_ip_int(
random.randint(0, ipaddress.IPv6Address._ALL_ONES)
)
- set_env(u_boot_console, 'ipv6_addr', rand_ipv6)
+ set_env(ubman, 'ipv6_addr', rand_ipv6)
# Set env for random number
rand_num = random.randrange(1, 10**9)
- set_env(u_boot_console, 'num_var', rand_num)
+ set_env(ubman, 'num_var', rand_num)
# Set env for uuid
uuid_str = uuid.uuid4().hex.lower()
- set_env(u_boot_console, 'uuid_var', uuid_str)
+ set_env(ubman, 'uuid_var', uuid_str)
# Set env for random string including special characters
sc = "!#%&()*+,-./:;<=>?@[\\]^_`{|}~"
rand_str = ''.join(
random.choices(' ' + string.ascii_letters + sc + string.digits, k=300)
)
- set_env(u_boot_console, 'str_var', f'"{rand_str}"')
+ set_env(ubman, 'str_var', f'"{rand_str}"')
# Set env for empty string
- set_env(u_boot_console, 'empty_var', '')
+ set_env(ubman, 'empty_var', '')
# Save the env variables
- u_boot_console.run_command('saveenv')
- assert ret_code(u_boot_console).endswith('0')
+ ubman.run_command('saveenv')
+ assert ret_code(ubman).endswith('0')
# Reboot
- u_boot_console.run_command('reset', wait_for_reboot=True)
+ ubman.run_command('reset', wait_for_reboot=True)
# Verify the saved env variables
- check_env(u_boot_console, 'mac_addr', rand_mac)
- check_env(u_boot_console, 'ipv4_addr', rand_ipv4)
- check_env(u_boot_console, 'ipv6_addr', rand_ipv6)
- check_env(u_boot_console, 'num_var', rand_num)
- check_env(u_boot_console, 'uuid_var', uuid_str)
- check_env(u_boot_console, 'str_var', rand_str)
- check_env(u_boot_console, 'empty_var', '')
+ check_env(ubman, 'mac_addr', rand_mac)
+ check_env(ubman, 'ipv4_addr', rand_ipv4)
+ check_env(ubman, 'ipv6_addr', rand_ipv6)
+ check_env(ubman, 'num_var', rand_num)
+ check_env(ubman, 'uuid_var', uuid_str)
+ check_env(ubman, 'str_var', rand_str)
+ check_env(ubman, 'empty_var', '')
diff --git a/test/py/tests/test_scp03.py b/test/py/tests/test_scp03.py
index 1a104b365f7..414b4251a69 100644
--- a/test/py/tests/test_scp03.py
+++ b/test/py/tests/test_scp03.py
@@ -11,17 +11,17 @@ For additional details check doc/usage/scp03.rst
"""
import pytest
-import u_boot_utils as util
+import utils
@pytest.mark.buildconfigspec('cmd_scp03')
-def test_scp03(u_boot_console):
+def test_scp03(ubman):
"""Enable and provision keys with SCP03
"""
success_str1 = "SCP03 is enabled"
success_str2 = "SCP03 is provisioned"
- response = u_boot_console.run_command('scp03 enable')
+ response = ubman.run_command('scp03 enable')
assert success_str1 in response
- response = u_boot_console.run_command('scp03 provision')
+ response = ubman.run_command('scp03 provision')
assert success_str2 in response
diff --git a/test/py/tests/test_scsi.py b/test/py/tests/test_scsi.py
index 445693cafd7..2a35e47e558 100644
--- a/test/py/tests/test_scsi.py
+++ b/test/py/tests/test_scsi.py
@@ -19,8 +19,8 @@ env__scsi_device_test = {
}
"""
-def scsi_setup(u_boot_console):
- f = u_boot_console.config.env.get('env__scsi_device_test', None)
+def scsi_setup(ubman):
+ f = ubman.config.env.get('env__scsi_device_test', None)
if not f:
pytest.skip('No SCSI device to test')
@@ -39,54 +39,54 @@ def scsi_setup(u_boot_console):
return dev_num, dev_type, dev_size
@pytest.mark.buildconfigspec('cmd_scsi')
-def test_scsi_reset(u_boot_console):
- dev_num, dev_type, dev_size = scsi_setup(u_boot_console)
- output = u_boot_console.run_command('scsi reset')
+def test_scsi_reset(ubman):
+ dev_num, dev_type, dev_size = scsi_setup(ubman)
+ output = ubman.run_command('scsi reset')
assert f'Device {dev_num}:' in output
assert f'Type: {dev_type}' in output
assert f'Capacity: {dev_size}' in output
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_scsi')
-def test_scsi_info(u_boot_console):
- dev_num, dev_type, dev_size = scsi_setup(u_boot_console)
- output = u_boot_console.run_command('scsi info')
+def test_scsi_info(ubman):
+ dev_num, dev_type, dev_size = scsi_setup(ubman)
+ output = ubman.run_command('scsi info')
assert f'Device {dev_num}:' in output
assert f'Type: {dev_type}' in output
assert f'Capacity: {dev_size}' in output
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_scsi')
-def test_scsi_scan(u_boot_console):
- dev_num, dev_type, dev_size = scsi_setup(u_boot_console)
- output = u_boot_console.run_command('scsi scan')
+def test_scsi_scan(ubman):
+ dev_num, dev_type, dev_size = scsi_setup(ubman)
+ output = ubman.run_command('scsi scan')
assert f'Device {dev_num}:' in output
assert f'Type: {dev_type}' in output
assert f'Capacity: {dev_size}' in output
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_scsi')
-def test_scsi_dev(u_boot_console):
- dev_num, dev_type, dev_size = scsi_setup(u_boot_console)
- output = u_boot_console.run_command('scsi device')
+def test_scsi_dev(ubman):
+ dev_num, dev_type, dev_size = scsi_setup(ubman)
+ output = ubman.run_command('scsi device')
assert 'no scsi devices available' not in output
assert f'device {dev_num}:' in output
assert f'Type: {dev_type}' in output
assert f'Capacity: {dev_size}' in output
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
- output = u_boot_console.run_command('scsi device %d' % dev_num)
+ output = ubman.run_command('scsi device %d' % dev_num)
assert 'is now current device' in output
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_scsi')
-def test_scsi_part(u_boot_console):
- test_scsi_dev(u_boot_console)
- output = u_boot_console.run_command('scsi part')
+def test_scsi_part(ubman):
+ test_scsi_dev(ubman)
+ output = ubman.run_command('scsi part')
assert 'Partition Map for scsi device' in output
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
diff --git a/test/py/tests/test_semihosting/test_hostfs.py b/test/py/tests/test_semihosting/test_hostfs.py
index 51f6fa7702c..1bead69b507 100644
--- a/test/py/tests/test_semihosting/test_hostfs.py
+++ b/test/py/tests/test_semihosting/test_hostfs.py
@@ -6,28 +6,28 @@
import pytest
@pytest.mark.buildconfigspec('semihosting')
-def test_semihosting_hostfs(u_boot_console, semihosting_data):
+def test_semihosting_hostfs(ubman, semihosting_data):
""" Unit test for semihosting
Args:
- u_boot_console -- U-Boot console
+ ubman -- U-Boot console
semihosting_data -- Path to the disk image used for testing.
"""
- response = u_boot_console.run_command(
+ response = ubman.run_command(
f'load hostfs - $loadaddr {semihosting_data}')
assert '11 bytes read' in response
- response = u_boot_console.run_command(
+ response = ubman.run_command(
'crc32 $loadaddr $filesize')
assert '==> 60cfccfc' in response
- u_boot_console.run_command(
+ ubman.run_command(
f'save hostfs - $loadaddr {semihosting_data} 11 11')
- response = u_boot_console.run_command(
+ response = ubman.run_command(
f'load hostfs - $loadaddr {semihosting_data} 4 13')
assert '4 bytes read' in response
- response = u_boot_console.run_command(
+ response = ubman.run_command(
'crc32 $loadaddr $filesize')
assert '==> e29063ea' in response
diff --git a/test/py/tests/test_sf.py b/test/py/tests/test_sf.py
index adf8b7dc893..5b4ba80f18b 100644
--- a/test/py/tests/test_sf.py
+++ b/test/py/tests/test_sf.py
@@ -5,7 +5,7 @@
import re
import pytest
import random
-import u_boot_utils
+import utils
"""
Note: This test relies on boardenv_* containing configuration values to define
@@ -44,11 +44,11 @@ env__sf_configs = (
)
"""
-def sf_prepare(u_boot_console, env__sf_config):
+def sf_prepare(ubman, env__sf_config):
"""Check global state of the SPI Flash before running any test.
Args:
- u_boot_console: A U-Boot console connection.
+ ubman: A U-Boot console connection.
env__sf_config: The single SPI Flash device configuration on which to
run the tests.
@@ -57,7 +57,7 @@ def sf_prepare(u_boot_console, env__sf_config):
"""
sf_params = {}
- sf_params['ram_base'] = u_boot_utils.find_ram_base(u_boot_console)
+ sf_params['ram_base'] = utils.find_ram_base(ubman)
probe_id = env__sf_config.get('id', 0)
speed = env__sf_config.get('speed', 0)
@@ -69,7 +69,7 @@ def sf_prepare(u_boot_console, env__sf_config):
cmd = 'sf probe %d %d' % (probe_id, sf_params['speed'])
- output = u_boot_console.run_command(cmd)
+ output = ubman.run_command(cmd)
assert 'SF: Detected' in output, 'No Flash device available'
m = re.search('page size (.+?) Bytes', output)
@@ -101,12 +101,12 @@ def sf_prepare(u_boot_console, env__sf_config):
return sf_params
-def sf_read(u_boot_console, env__sf_config, sf_params):
+def sf_read(ubman, env__sf_config, sf_params):
"""Helper function used to read and compute the CRC32 value of a section of
SPI Flash memory.
Args:
- u_boot_console: A U-Boot console connection.
+ ubman: A U-Boot console connection.
env__sf_config: The single SPI Flash device configuration on which to
run the tests.
sf_params: SPI Flash parameters.
@@ -122,26 +122,26 @@ def sf_read(u_boot_console, env__sf_config, sf_params):
crc_expected = env__sf_config.get('crc32', None)
cmd = 'mw.b %08x %02x %x' % (addr, pattern, count)
- u_boot_console.run_command(cmd)
- crc_pattern = u_boot_utils.crc32(u_boot_console, addr, count)
+ ubman.run_command(cmd)
+ crc_pattern = utils.crc32(ubman, addr, count)
if crc_expected:
assert crc_pattern != crc_expected
cmd = 'sf read %08x %08x %x' % (addr, offset, count)
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
assert 'Read: OK' in response, 'Read operation failed'
- crc_readback = u_boot_utils.crc32(u_boot_console, addr, count)
+ crc_readback = utils.crc32(ubman, addr, count)
assert crc_pattern != crc_readback, 'sf read did not update RAM content.'
if crc_expected:
assert crc_readback == crc_expected
return crc_readback
-def sf_update(u_boot_console, env__sf_config, sf_params):
+def sf_update(ubman, env__sf_config, sf_params):
"""Helper function used to update a section of SPI Flash memory.
Args:
- u_boot_console: A U-Boot console connection.
+ ubman: A U-Boot console connection.
env__sf_config: The single SPI Flash device configuration on which to
run the tests.
@@ -155,63 +155,63 @@ def sf_update(u_boot_console, env__sf_config, sf_params):
pattern = int(random.random() * 0xFF)
cmd = 'mw.b %08x %02x %x' % (addr, pattern, count)
- u_boot_console.run_command(cmd)
- crc_pattern = u_boot_utils.crc32(u_boot_console, addr, count)
+ ubman.run_command(cmd)
+ crc_pattern = utils.crc32(ubman, addr, count)
cmd = 'sf update %08x %08x %x' % (addr, offset, count)
- u_boot_console.run_command(cmd)
- crc_readback = sf_read(u_boot_console, env__sf_config, sf_params)
+ ubman.run_command(cmd)
+ crc_readback = sf_read(ubman, env__sf_config, sf_params)
assert crc_readback == crc_pattern
@pytest.mark.buildconfigspec('cmd_sf')
@pytest.mark.buildconfigspec('cmd_crc32')
@pytest.mark.buildconfigspec('cmd_memory')
-def test_sf_read(u_boot_console, env__sf_config):
- sf_params = sf_prepare(u_boot_console, env__sf_config)
- sf_read(u_boot_console, env__sf_config, sf_params)
+def test_sf_read(ubman, env__sf_config):
+ sf_params = sf_prepare(ubman, env__sf_config)
+ sf_read(ubman, env__sf_config, sf_params)
@pytest.mark.buildconfigspec('cmd_sf')
@pytest.mark.buildconfigspec('cmd_crc32')
@pytest.mark.buildconfigspec('cmd_memory')
-def test_sf_read_twice(u_boot_console, env__sf_config):
- sf_params = sf_prepare(u_boot_console, env__sf_config)
+def test_sf_read_twice(ubman, env__sf_config):
+ sf_params = sf_prepare(ubman, env__sf_config)
- crc1 = sf_read(u_boot_console, env__sf_config, sf_params)
+ crc1 = sf_read(ubman, env__sf_config, sf_params)
sf_params['ram_base'] += 0x100
- crc2 = sf_read(u_boot_console, env__sf_config, sf_params)
+ crc2 = sf_read(ubman, env__sf_config, sf_params)
assert crc1 == crc2, 'CRC32 of two successive read operation do not match'
@pytest.mark.buildconfigspec('cmd_sf')
@pytest.mark.buildconfigspec('cmd_crc32')
@pytest.mark.buildconfigspec('cmd_memory')
-def test_sf_erase(u_boot_console, env__sf_config):
+def test_sf_erase(ubman, env__sf_config):
if not env__sf_config.get('writeable', False):
pytest.skip('Flash config is tagged as not writeable')
- sf_params = sf_prepare(u_boot_console, env__sf_config)
+ sf_params = sf_prepare(ubman, env__sf_config)
addr = sf_params['ram_base']
offset = env__sf_config['offset']
count = sf_params['len']
cmd = 'sf erase %08x %x' % (offset, count)
- output = u_boot_console.run_command(cmd)
+ output = ubman.run_command(cmd)
assert 'Erased: OK' in output, 'Erase operation failed'
cmd = 'mw.b %08x ff %x' % (addr, count)
- u_boot_console.run_command(cmd)
- crc_ffs = u_boot_utils.crc32(u_boot_console, addr, count)
+ ubman.run_command(cmd)
+ crc_ffs = utils.crc32(ubman, addr, count)
- crc_read = sf_read(u_boot_console, env__sf_config, sf_params)
+ crc_read = sf_read(ubman, env__sf_config, sf_params)
assert crc_ffs == crc_read, 'Unexpected CRC32 after erase operation.'
@pytest.mark.buildconfigspec('cmd_sf')
@pytest.mark.buildconfigspec('cmd_crc32')
@pytest.mark.buildconfigspec('cmd_memory')
-def test_sf_update(u_boot_console, env__sf_config):
+def test_sf_update(ubman, env__sf_config):
if not env__sf_config.get('writeable', False):
pytest.skip('Flash config is tagged as not writeable')
- sf_params = sf_prepare(u_boot_console, env__sf_config)
- sf_update(u_boot_console, env__sf_config, sf_params)
+ sf_params = sf_prepare(ubman, env__sf_config)
+ sf_update(ubman, env__sf_config, sf_params)
diff --git a/test/py/tests/test_shell_basics.py b/test/py/tests/test_shell_basics.py
index 68a3f892f6b..97e22af5da5 100644
--- a/test/py/tests/test_shell_basics.py
+++ b/test/py/tests/test_shell_basics.py
@@ -7,39 +7,39 @@ import pytest
pytestmark = pytest.mark.buildconfigspec('cmd_echo')
-def test_shell_execute(u_boot_console):
+def test_shell_execute(ubman):
"""Test any shell command."""
- response = u_boot_console.run_command('echo hello')
+ response = ubman.run_command('echo hello')
assert response.strip() == 'hello'
-def test_shell_semicolon_two(u_boot_console):
+def test_shell_semicolon_two(ubman):
"""Test two shell commands separate by a semi-colon."""
cmd = 'echo hello; echo world'
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
# This validation method ignores the exact whitespace between the strings
assert response.index('hello') < response.index('world')
-def test_shell_semicolon_three(u_boot_console):
+def test_shell_semicolon_three(ubman):
"""Test three shell commands separate by a semi-colon, with variable
expansion dependencies between them."""
cmd = 'setenv list 1; setenv list ${list}2; setenv list ${list}3; ' + \
'echo ${list}'
- response = u_boot_console.run_command(cmd)
+ response = ubman.run_command(cmd)
assert response.strip() == '123'
- u_boot_console.run_command('setenv list')
+ ubman.run_command('setenv list')
-def test_shell_run(u_boot_console):
+def test_shell_run(ubman):
"""Test the "run" shell command."""
- u_boot_console.run_command('setenv foo \'setenv monty 1; setenv python 2\'')
- u_boot_console.run_command('run foo')
- response = u_boot_console.run_command('echo ${monty}')
+ ubman.run_command('setenv foo \'setenv monty 1; setenv python 2\'')
+ ubman.run_command('run foo')
+ response = ubman.run_command('echo ${monty}')
assert response.strip() == '1'
- response = u_boot_console.run_command('echo ${python}')
+ response = ubman.run_command('echo ${python}')
assert response.strip() == '2'
- u_boot_console.run_command('setenv foo')
- u_boot_console.run_command('setenv monty')
- u_boot_console.run_command('setenv python')
+ ubman.run_command('setenv foo')
+ ubman.run_command('setenv monty')
+ ubman.run_command('setenv python')
diff --git a/test/py/tests/test_sleep.py b/test/py/tests/test_sleep.py
index 66a57434bff..f1bf34e05b2 100644
--- a/test/py/tests/test_sleep.py
+++ b/test/py/tests/test_sleep.py
@@ -19,43 +19,43 @@ env__sleep_margin = 0.25
"""
-def test_sleep(u_boot_console):
+def test_sleep(ubman):
"""Test the sleep command, and validate that it sleeps for approximately
the correct amount of time."""
- sleep_skip = u_boot_console.config.env.get('env__sleep_accurate', True)
+ sleep_skip = ubman.config.env.get('env__sleep_accurate', True)
if not sleep_skip:
pytest.skip('sleep is not accurate')
- if u_boot_console.config.buildconfig.get('config_cmd_misc', 'n') != 'y':
+ if ubman.config.buildconfig.get('config_cmd_sleep', 'n') != 'y':
pytest.skip('sleep command not supported')
# 3s isn't too long, but is enough to cross a few second boundaries.
- sleep_time = u_boot_console.config.env.get('env__sleep_time', 3)
- sleep_margin = u_boot_console.config.env.get('env__sleep_margin', 0.25)
+ sleep_time = ubman.config.env.get('env__sleep_time', 3)
+ sleep_margin = ubman.config.env.get('env__sleep_margin', 0.25)
tstart = time.time()
- u_boot_console.run_command('sleep %d' % sleep_time)
+ ubman.run_command('sleep %d' % sleep_time)
tend = time.time()
elapsed = tend - tstart
assert elapsed >= (sleep_time - 0.01)
- if not u_boot_console.config.gdbserver:
+ if not ubman.config.gdbserver:
# margin is hopefully enough to account for any system overhead.
assert elapsed < (sleep_time + sleep_margin)
-@pytest.mark.buildconfigspec("cmd_misc")
-def test_time(u_boot_console):
+@pytest.mark.buildconfigspec("cmd_time")
+def test_time(ubman):
"""Test the time command, and validate that it gives approximately the
correct amount of command execution time."""
- sleep_skip = u_boot_console.config.env.get("env__sleep_accurate", True)
+ sleep_skip = ubman.config.env.get("env__sleep_accurate", True)
if not sleep_skip:
pytest.skip("sleep is not accurate")
- sleep_time = u_boot_console.config.env.get("env__sleep_time", 10)
- sleep_margin = u_boot_console.config.env.get("env__sleep_margin", 0.25)
- output = u_boot_console.run_command("time sleep %d" % sleep_time)
+ sleep_time = ubman.config.env.get("env__sleep_time", 10)
+ sleep_margin = ubman.config.env.get("env__sleep_margin", 0.25)
+ output = ubman.run_command("time sleep %d" % sleep_time)
execute_time = float(output.split()[1])
assert sleep_time >= (execute_time - 0.01)
- if not u_boot_console.config.gdbserver:
+ if not ubman.config.gdbserver:
# margin is hopefully enough to account for any system overhead.
assert sleep_time < (execute_time + sleep_margin)
diff --git a/test/py/tests/test_smbios.py b/test/py/tests/test_smbios.py
index 82b0b689830..3b85a7cc661 100644
--- a/test/py/tests/test_smbios.py
+++ b/test/py/tests/test_smbios.py
@@ -7,9 +7,9 @@ import pytest
@pytest.mark.buildconfigspec('cmd_smbios')
@pytest.mark.notbuildconfigspec('qfw_smbios')
@pytest.mark.notbuildconfigspec('sandbox')
-def test_cmd_smbios(u_boot_console):
+def test_cmd_smbios(ubman):
"""Run the smbios command"""
- output = u_boot_console.run_command('smbios')
+ output = ubman.run_command('smbios')
assert 'DMI type 127,' in output
@pytest.mark.buildconfigspec('cmd_smbios')
@@ -19,23 +19,39 @@ def test_cmd_smbios(u_boot_console):
# QEMU v8.2.0 lacks SMBIOS support for RISC-V
# Once support is available in our Docker image we can remove the constraint.
@pytest.mark.notbuildconfigspec('riscv')
-def test_cmd_smbios_qemu(u_boot_console):
+def test_cmd_smbios_qemu(ubman):
"""Run the smbios command on QEMU"""
- output = u_boot_console.run_command('smbios')
+ output = ubman.run_command('smbios')
assert 'DMI type 1,' in output
assert 'Manufacturer: QEMU' in output
assert 'DMI type 127,' in output
@pytest.mark.buildconfigspec('cmd_smbios')
@pytest.mark.buildconfigspec('sandbox')
-def test_cmd_smbios_sandbox(u_boot_console):
+def test_cmd_smbios_sandbox(ubman):
"""Run the smbios command on the sandbox"""
- output = u_boot_console.run_command('smbios')
+ output = ubman.run_command('smbios')
assert 'DMI type 0,' in output
- assert 'String 1: U-Boot' in output
+ assert 'Vendor: U-Boot' in output
assert 'DMI type 1,' in output
assert 'Manufacturer: sandbox' in output
assert 'DMI type 2,' in output
assert 'DMI type 3,' in output
assert 'DMI type 4,' in output
assert 'DMI type 127,' in output
+
+@pytest.mark.buildconfigspec('cmd_smbios')
+@pytest.mark.buildconfigspec('sysinfo_smbios')
+@pytest.mark.buildconfigspec('generate_smbios_table_verbose')
+def test_cmd_smbios_sysinfo_verbose(ubman):
+ """Run the smbios command"""
+ output = ubman.run_command('smbios')
+ assert 'DMI type 0,' in output
+ assert 'Vendor: U-Boot' in output
+ assert 'DMI type 1,' in output
+ assert 'Manufacturer: linux' in output
+ assert 'DMI type 2,' in output
+ assert 'DMI type 3,' in output
+ assert 'DMI type 7,' in output
+ assert 'DMI type 4,' in output
+ assert 'DMI type 127,' in output
diff --git a/test/py/tests/test_source.py b/test/py/tests/test_source.py
index bbc311df6d1..970d8c79869 100644
--- a/test/py/tests/test_source.py
+++ b/test/py/tests/test_source.py
@@ -3,35 +3,34 @@
import os
import pytest
-import u_boot_utils as util
+import utils
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_echo')
@pytest.mark.buildconfigspec('cmd_source')
@pytest.mark.buildconfigspec('fit')
-def test_source(u_boot_console):
+def test_source(ubman):
# Compile our test script image
- cons = u_boot_console
- mkimage = os.path.join(cons.config.build_dir, 'tools/mkimage')
- its = os.path.join(cons.config.source_dir, 'test/py/tests/source.its')
- fit = os.path.join(cons.config.build_dir, 'source.itb')
- util.run_and_log(cons, (mkimage, '-f', its, fit))
- cons.run_command(f'host load hostfs - $loadaddr {fit}')
+ mkimage = os.path.join(ubman.config.build_dir, 'tools/mkimage')
+ its = os.path.join(ubman.config.source_dir, 'test/py/tests/source.its')
+ fit = os.path.join(ubman.config.build_dir, 'source.itb')
+ utils.run_and_log(ubman, (mkimage, '-f', its, fit))
+ ubman.run_command(f'host load hostfs - $loadaddr {fit}')
- assert '2' in cons.run_command('source')
- assert '1' in cons.run_command('source :')
- assert '1' in cons.run_command('source :script-1')
- assert '2' in cons.run_command('source :script-2')
- assert 'Fail' in cons.run_command('source :not-a-script || echo Fail')
- assert '2' in cons.run_command('source \\#')
- assert '1' in cons.run_command('source \\#conf-1')
- assert '2' in cons.run_command('source \\#conf-2')
+ assert '2' in ubman.run_command('source')
+ assert '1' in ubman.run_command('source :')
+ assert '1' in ubman.run_command('source :script-1')
+ assert '2' in ubman.run_command('source :script-2')
+ assert 'Fail' in ubman.run_command('source :not-a-script || echo Fail')
+ assert '2' in ubman.run_command('source \\#')
+ assert '1' in ubman.run_command('source \\#conf-1')
+ assert '2' in ubman.run_command('source \\#conf-2')
- cons.run_command('fdt addr $loadaddr')
- cons.run_command('fdt rm /configurations default')
- assert '1' in cons.run_command('source')
- assert 'Fail' in cons.run_command('source \\# || echo Fail')
+ ubman.run_command('fdt addr $loadaddr')
+ ubman.run_command('fdt rm /configurations default')
+ assert '1' in ubman.run_command('source')
+ assert 'Fail' in ubman.run_command('source \\# || echo Fail')
- cons.run_command('fdt rm /images default')
- assert 'Fail' in cons.run_command('source || echo Fail')
- assert 'Fail' in cons.run_command('source \\# || echo Fail')
+ ubman.run_command('fdt rm /images default')
+ assert 'Fail' in ubman.run_command('source || echo Fail')
+ assert 'Fail' in ubman.run_command('source \\# || echo Fail')
diff --git a/test/py/tests/test_spi.py b/test/py/tests/test_spi.py
new file mode 100644
index 00000000000..09174f91e98
--- /dev/null
+++ b/test/py/tests/test_spi.py
@@ -0,0 +1,735 @@
+# SPDX-License-Identifier: GPL-2.0
+# (C) Copyright 2024, Advanced Micro Devices, Inc.
+
+"""
+Note: This test relies on boardenv_* containing configuration values to define
+spi minimum and maximum frequencies at which the flash part can operate on and
+these tests run at different spi frequency randomised values in the range
+multiple times based on the user defined iteration value.
+It also defines the SPI bus number containing the SPI-flash chip, SPI
+chip-select, SPI mode, SPI flash part name and timeout parameters. If minimum
+and maximum frequency is not defined, it will run on freq 0 by default.
+
+Without the boardenv_* configuration, this test will be automatically skipped.
+
+It also relies on configuration values for supported flashes for lock and
+unlock cases for SPI family flash. It will run lock-unlock cases only for the
+supported flash parts.
+
+For Example:
+
+# Details of SPI device test parameters required for SPI device testing:
+
+# bus - SPI bus number to init the flash device
+# chip_select - SPI chip select number to init the flash device
+# min_freq - Minimum frequency in hz at which the flash part can operate, set 0
+# or None for default frequency
+# max_freq - Maximum frequency in hz at which the flash part can operate, set 0
+# or None for default frequency
+# mode - SPI mode to init the flash device
+# part_name - SPI flash part name to be detected
+# timeout - Default timeout to run the sf commands
+# iteration - No of iteration to run SPI flash test
+
+env__spi_device_test = {
+ 'bus': 0,
+ 'chip_select': 0,
+ 'min_freq': 10000000,
+ 'max_freq': 100000000,
+ 'mode': 0,
+ 'part_name': 'n25q00a',
+ 'timeout': 100000,
+ 'iteration': 5,
+}
+
+# supported_flash - Flash parts name which support lock-unlock functionality
+env__spi_lock_unlock = {
+ 'supported_flash': 'mt25qu512a, n25q00a, n25q512ax3',
+}
+"""
+
+import random
+import re
+import pytest
+import utils
+
+SPI_DATA = {}
+EXPECTED_ERASE = 'Erased: OK'
+EXPECTED_WRITE = 'Written: OK'
+EXPECTED_READ = 'Read: OK'
+EXPECTED_ERASE_ERRORS = [
+ 'Erase operation failed',
+ 'Attempted to modify a protected sector',
+ 'Erased: ERROR',
+ 'is protected and cannot be erased',
+ 'ERROR: flash area is locked',
+]
+EXPECTED_WRITE_ERRORS = [
+ 'ERROR: flash area is locked',
+ 'Program operation failed',
+ 'Attempted to modify a protected sector',
+ 'Written: ERROR',
+]
+
+def get_params_spi(ubman):
+ ''' Get SPI device test parameters from boardenv file '''
+ f = ubman.config.env.get('env__spi_device_test', None)
+ if not f:
+ pytest.skip('No SPI test device configured')
+
+ bus = f.get('bus', 0)
+ cs = f.get('chip_select', 0)
+ mode = f.get('mode', 0)
+ part_name = f.get('part_name', None)
+ timeout = f.get('timeout', None)
+
+ if not part_name:
+ pytest.skip('No SPI test device configured')
+
+ return bus, cs, mode, part_name, timeout
+
+def spi_find_freq_range(ubman):
+ '''Find out minimum and maximum frequnecies that SPI device can operate'''
+ f = ubman.config.env.get('env__spi_device_test', None)
+ if not f:
+ pytest.skip('No SPI test device configured')
+
+ min_f = f.get('min_freq', None)
+ max_f = f.get('max_freq', None)
+ iterations = f.get('iteration', 1)
+
+ if not min_f:
+ min_f = 0
+ if not max_f:
+ max_f = 0
+
+ max_f = max(max_f, min_f)
+
+ return min_f, max_f, iterations
+
+def spi_pre_commands(ubman, freq):
+ ''' Find out SPI family flash memory parameters '''
+ bus, cs, mode, part_name, timeout = get_params_spi(ubman)
+
+ output = ubman.run_command(f'sf probe {bus}:{cs} {freq} {mode}')
+ if not 'SF: Detected' in output:
+ pytest.fail('No SPI device available')
+
+ if not part_name in output:
+ pytest.fail('Not recognized the SPI flash part name')
+
+ m = re.search('page size (.+?) Bytes', output)
+ assert m
+ try:
+ page_size = int(m.group(1))
+ except ValueError:
+ pytest.fail('Not recognized the SPI page size')
+
+ m = re.search('erase size (.+?) KiB', output)
+ assert m
+ try:
+ erase_size = int(m.group(1))
+ erase_size *= 1024
+ except ValueError:
+ pytest.fail('Not recognized the SPI erase size')
+
+ m = re.search('total (.+?) MiB', output)
+ assert m
+ try:
+ total_size = int(m.group(1))
+ total_size *= 1024 * 1024
+ except ValueError:
+ pytest.fail('Not recognized the SPI total size')
+
+ m = re.search('Detected (.+?) with', output)
+ assert m
+ try:
+ flash_part = m.group(1)
+ assert flash_part == part_name
+ except ValueError:
+ pytest.fail('Not recognized the SPI flash part')
+
+ global SPI_DATA
+ SPI_DATA = {
+ 'page_size': page_size,
+ 'erase_size': erase_size,
+ 'total_size': total_size,
+ 'flash_part': flash_part,
+ 'timeout': timeout,
+ }
+
+def get_page_size():
+ ''' Get the SPI page size from spi data '''
+ return SPI_DATA['page_size']
+
+def get_erase_size():
+ ''' Get the SPI erase size from spi data '''
+ return SPI_DATA['erase_size']
+
+def get_total_size():
+ ''' Get the SPI total size from spi data '''
+ return SPI_DATA['total_size']
+
+def get_flash_part():
+ ''' Get the SPI flash part name from spi data '''
+ return SPI_DATA['flash_part']
+
+def get_timeout():
+ ''' Get the SPI timeout from spi data '''
+ return SPI_DATA['timeout']
+
+def spi_erase_block(ubman, erase_size, total_size):
+ ''' Erase SPI flash memory block wise '''
+ for start in range(0, total_size, erase_size):
+ output = ubman.run_command(f'sf erase {hex(start)} {hex(erase_size)}')
+ assert EXPECTED_ERASE in output
+
+@pytest.mark.buildconfigspec('cmd_sf')
+def test_spi_erase_block(ubman):
+ ''' Test case to check SPI erase functionality by erasing memory regions
+ block-wise '''
+
+ min_f, max_f, loop = spi_find_freq_range(ubman)
+ i = 0
+ while i < loop:
+ spi_pre_commands(ubman, random.randint(min_f, max_f))
+ spi_erase_block(ubman, get_erase_size(), get_total_size())
+ i = i + 1
+
+def spi_write_twice(ubman, page_size, erase_size, total_size, timeout):
+ ''' Random write till page size, random till size and full size '''
+ addr = utils.find_ram_base(ubman)
+
+ old_size = 0
+ for size in (
+ random.randint(4, page_size),
+ random.randint(page_size, total_size),
+ total_size,
+ ):
+ offset = random.randint(4, page_size)
+ offset = offset & ~3
+ size = size & ~3
+ size = size - old_size
+ output = ubman.run_command(f'crc32 {hex(addr + total_size)} {hex(size)}')
+ m = re.search('==> (.+?)$', output)
+ if not m:
+ pytest.fail('CRC32 failed')
+
+ expected_crc32 = m.group(1)
+ if old_size % page_size:
+ old_size = int(old_size / page_size)
+ old_size *= page_size
+
+ if size % erase_size:
+ erasesize = int(size / erase_size + 1)
+ erasesize *= erase_size
+
+ eraseoffset = int(old_size / erase_size)
+ eraseoffset *= erase_size
+
+ timeout = 100000000
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command(
+ f'sf erase {hex(eraseoffset)} {hex(erasesize)}'
+ )
+ assert EXPECTED_ERASE in output
+
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command(
+ f'sf write {hex(addr + total_size)} {hex(old_size)} {hex(size)}'
+ )
+ assert EXPECTED_WRITE in output
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command(
+ f'sf read {hex(addr + total_size + offset)} {hex(old_size)} {hex(size)}'
+ )
+ assert EXPECTED_READ in output
+ output = ubman.run_command(
+ f'crc32 {hex(addr + total_size + offset)} {hex(size)}'
+ )
+ assert expected_crc32 in output
+ old_size = size
+
+@pytest.mark.buildconfigspec('cmd_bdi')
+@pytest.mark.buildconfigspec('cmd_sf')
+@pytest.mark.buildconfigspec('cmd_memory')
+def test_spi_write_twice(ubman):
+ ''' Test to write data with random size twice for SPI '''
+ min_f, max_f, loop = spi_find_freq_range(ubman)
+ i = 0
+ while i < loop:
+ spi_pre_commands(ubman, random.randint(min_f, max_f))
+ spi_write_twice(
+ ubman,
+ get_page_size(),
+ get_erase_size(),
+ get_total_size(),
+ get_timeout()
+ )
+ i = i + 1
+
+def spi_write_continues(ubman, page_size, erase_size, total_size, timeout):
+ ''' Write with random size of data to continue SPI write case '''
+ spi_erase_block(ubman, erase_size, total_size)
+ addr = utils.find_ram_base(ubman)
+
+ output = ubman.run_command(f'crc32 {hex(addr + 0x10000)} {hex(total_size)}')
+ m = re.search('==> (.+?)$', output)
+ if not m:
+ pytest.fail('CRC32 failed')
+ expected_crc32 = m.group(1)
+
+ old_size = 0
+ for size in (
+ random.randint(4, page_size),
+ random.randint(page_size, total_size),
+ total_size,
+ ):
+ size = size & ~3
+ size = size - old_size
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command(
+ f'sf write {hex(addr + 0x10000 + old_size)} {hex(old_size)} {hex(size)}'
+ )
+ assert EXPECTED_WRITE in output
+ old_size += size
+
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command(
+ f'sf read {hex(addr + 0x10000 + total_size)} 0 {hex(total_size)}'
+ )
+ assert EXPECTED_READ in output
+
+ output = ubman.run_command(
+ f'crc32 {hex(addr + 0x10000 + total_size)} {hex(total_size)}'
+ )
+ assert expected_crc32 in output
+
+@pytest.mark.buildconfigspec('cmd_bdi')
+@pytest.mark.buildconfigspec('cmd_sf')
+@pytest.mark.buildconfigspec('cmd_memory')
+def test_spi_write_continues(ubman):
+ ''' Test to write more random size data for SPI '''
+ min_f, max_f, loop = spi_find_freq_range(ubman)
+ i = 0
+ while i < loop:
+ spi_pre_commands(ubman, random.randint(min_f, max_f))
+ spi_write_twice(
+ ubman,
+ get_page_size(),
+ get_erase_size(),
+ get_total_size(),
+ get_timeout(),
+ )
+ i = i + 1
+
+def spi_read_twice(ubman, page_size, total_size, timeout):
+ ''' Read the whole SPI flash twice, random_size till full flash size,
+ random till page size '''
+ for size in random.randint(4, page_size), random.randint(4, total_size), total_size:
+ addr = utils.find_ram_base(ubman)
+ size = size & ~3
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command(
+ f'sf read {hex(addr + total_size)} 0 {hex(size)}'
+ )
+ assert EXPECTED_READ in output
+ output = ubman.run_command(f'crc32 {hex(addr + total_size)} {hex(size)}')
+ m = re.search('==> (.+?)$', output)
+ if not m:
+ pytest.fail('CRC32 failed')
+ expected_crc32 = m.group(1)
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command(
+ f'sf read {hex(addr + total_size + 10)} 0 {hex(size)}'
+ )
+ assert EXPECTED_READ in output
+ output = ubman.run_command(
+ f'crc32 {hex(addr + total_size + 10)} {hex(size)}'
+ )
+ assert expected_crc32 in output
+
+@pytest.mark.buildconfigspec('cmd_sf')
+@pytest.mark.buildconfigspec('cmd_bdi')
+@pytest.mark.buildconfigspec('cmd_memory')
+def test_spi_read_twice(ubman):
+ ''' Test to read random data twice from SPI '''
+ min_f, max_f, loop = spi_find_freq_range(ubman)
+ i = 0
+ while i < loop:
+ spi_pre_commands(ubman, random.randint(min_f, max_f))
+ spi_read_twice(ubman, get_page_size(), get_total_size(), get_timeout())
+ i = i + 1
+
+def spi_erase_all(ubman, total_size, timeout):
+ ''' Erase the full chip SPI '''
+ start = 0
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command(f'sf erase {start} {hex(total_size)}')
+ assert EXPECTED_ERASE in output
+
+@pytest.mark.buildconfigspec('cmd_sf')
+def test_spi_erase_all(ubman):
+ ''' Test to check full chip erase for SPI '''
+ min_f, max_f, loop = spi_find_freq_range(ubman)
+ i = 0
+ while i < loop:
+ spi_pre_commands(ubman, random.randint(min_f, max_f))
+ spi_erase_all(ubman, get_total_size(), get_timeout())
+ i = i + 1
+
+def flash_ops(
+ ubman, ops, start, size, offset=0, exp_ret=0, exp_str='', not_exp_str=''
+):
+ ''' Flash operations: erase, write and read '''
+
+ f = ubman.config.env.get('env__spi_device_test', None)
+ if not f:
+ timeout = 1000000
+
+ timeout = f.get('timeout', 1000000)
+
+ if ops == 'erase':
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command(f'sf erase {hex(start)} {hex(size)}')
+ else:
+ with ubman.temporary_timeout(timeout):
+ output = ubman.run_command(
+ f'sf {ops} {hex(offset)} {hex(start)} {hex(size)}'
+ )
+
+ if exp_str:
+ assert exp_str in output
+ if not_exp_str:
+ assert not_exp_str not in output
+
+ ret_code = ubman.run_command('echo $?')
+ if exp_ret >= 0:
+ assert ret_code.endswith(str(exp_ret))
+
+ return output, ret_code
+
+def spi_unlock_exit(ubman, addr, size):
+ ''' Unlock the flash before making it fail '''
+ ubman.run_command(f'sf protect unlock {hex(addr)} {hex(size)}')
+ assert False, 'FAIL: Flash lock is unable to protect the data!'
+
+def find_prot_region(lock_addr, lock_size):
+ ''' Get the protected and un-protected region of flash '''
+ total_size = get_total_size()
+ erase_size = get_erase_size()
+
+ if lock_addr < (total_size // 2):
+ sect_num = (lock_addr + lock_size) // erase_size
+ x = 1
+ while x < sect_num:
+ x *= 2
+ prot_start = 0
+ prot_size = x * erase_size
+ unprot_start = prot_start + prot_size
+ unprot_size = total_size - unprot_start
+ else:
+ sect_num = (total_size - lock_addr) // erase_size
+ x = 1
+ while x < sect_num:
+ x *= 2
+ prot_start = total_size - (x * erase_size)
+ prot_size = total_size - prot_start
+ unprot_start = 0
+ unprot_size = prot_start
+
+ return prot_start, prot_size, unprot_start, unprot_size
+
+def protect_ops(ubman, lock_addr, lock_size, ops="unlock"):
+ ''' Run the command to lock or Unlock the flash '''
+ ubman.run_command(f'sf protect {ops} {hex(lock_addr)} {hex(lock_size)}')
+ output = ubman.run_command('echo $?')
+ if ops == "lock" and not output.endswith('0'):
+ ubman.run_command(f'sf protect unlock {hex(lock_addr)} {hex(lock_size)}')
+ assert False, "sf protect lock command exits with non-zero return code"
+ assert output.endswith('0')
+
+def erase_write_ops(ubman, start, size):
+ ''' Basic erase and write operation for flash '''
+ addr = utils.find_ram_base(ubman)
+ flash_ops(ubman, 'erase', start, size, 0, 0, EXPECTED_ERASE)
+ flash_ops(ubman, 'write', start, size, addr, 0, EXPECTED_WRITE)
+
+def spi_lock_unlock(ubman, lock_addr, lock_size):
+ ''' Lock unlock operations for SPI family flash '''
+ addr = utils.find_ram_base(ubman)
+ erase_size = get_erase_size()
+
+ # Find the protected/un-protected region
+ prot_start, prot_size, unprot_start, unprot_size = find_prot_region(lock_addr, lock_size)
+
+ # Check erase/write operation before locking
+ erase_write_ops(ubman, prot_start, prot_size)
+
+ # Locking the flash
+ protect_ops(ubman, lock_addr, lock_size, 'lock')
+
+ # Check erase/write operation after locking
+ output, ret_code = flash_ops(ubman, 'erase', prot_start, prot_size, 0, -1)
+ if not any(error in output for error in EXPECTED_ERASE_ERRORS) or ret_code.endswith(
+ '0'
+ ):
+ spi_unlock_exit(ubman, lock_addr, lock_size)
+
+ output, ret_code = flash_ops(
+ ubman, 'write', prot_start, prot_size, addr, -1
+ )
+ if not any(error in output for error in EXPECTED_WRITE_ERRORS) or ret_code.endswith(
+ '0'
+ ):
+ spi_unlock_exit(ubman, lock_addr, lock_size)
+
+ # Check locked sectors
+ sect_lock_start = random.randrange(prot_start, (prot_start + prot_size), erase_size)
+ if prot_size > erase_size:
+ sect_lock_size = random.randrange(
+ erase_size, (prot_start + prot_size - sect_lock_start), erase_size
+ )
+ else:
+ sect_lock_size = erase_size
+ sect_write_size = random.randint(1, sect_lock_size)
+
+ output, ret_code = flash_ops(
+ ubman, 'erase', sect_lock_start, sect_lock_size, 0, -1
+ )
+ if not any(error in output for error in EXPECTED_ERASE_ERRORS) or ret_code.endswith(
+ '0'
+ ):
+ spi_unlock_exit(ubman, lock_addr, lock_size)
+
+ output, ret_code = flash_ops(
+ ubman, 'write', sect_lock_start, sect_write_size, addr, -1
+ )
+ if not any(error in output for error in EXPECTED_WRITE_ERRORS) or ret_code.endswith(
+ '0'
+ ):
+ spi_unlock_exit(ubman, lock_addr, lock_size)
+
+ # Check unlocked sectors
+ if unprot_size != 0:
+ sect_unlock_start = random.randrange(
+ unprot_start, (unprot_start + unprot_size), erase_size
+ )
+ if unprot_size > erase_size:
+ sect_unlock_size = random.randrange(
+ erase_size, (unprot_start + unprot_size - sect_unlock_start), erase_size
+ )
+ else:
+ sect_unlock_size = erase_size
+ sect_write_size = random.randint(1, sect_unlock_size)
+
+ output, ret_code = flash_ops(
+ ubman, 'erase', sect_unlock_start, sect_unlock_size, 0, -1
+ )
+ if EXPECTED_ERASE not in output or ret_code.endswith('1'):
+ spi_unlock_exit(ubman, lock_addr, lock_size)
+
+ output, ret_code = flash_ops(
+ ubman, 'write', sect_unlock_start, sect_write_size, addr, -1
+ )
+ if EXPECTED_WRITE not in output or ret_code.endswith('1'):
+ spi_unlock_exit(ubman, lock_addr, lock_size)
+
+ # Unlocking the flash
+ protect_ops(ubman, lock_addr, lock_size, 'unlock')
+
+ # Check erase/write operation after un-locking
+ erase_write_ops(ubman, prot_start, prot_size)
+
+ # Check previous locked sectors
+ sect_lock_start = random.randrange(prot_start, (prot_start + prot_size), erase_size)
+ if prot_size > erase_size:
+ sect_lock_size = random.randrange(
+ erase_size, (prot_start + prot_size - sect_lock_start), erase_size
+ )
+ else:
+ sect_lock_size = erase_size
+ sect_write_size = random.randint(1, sect_lock_size)
+
+ flash_ops(
+ ubman, 'erase', sect_lock_start, sect_lock_size, 0, 0, EXPECTED_ERASE
+ )
+ flash_ops(
+ ubman,
+ 'write',
+ sect_lock_start,
+ sect_write_size,
+ addr,
+ 0,
+ EXPECTED_WRITE,
+ )
+
+@pytest.mark.buildconfigspec('cmd_bdi')
+@pytest.mark.buildconfigspec('cmd_sf')
+@pytest.mark.buildconfigspec('cmd_memory')
+def test_spi_lock_unlock(ubman):
+ ''' Test to check the lock-unlock functionality for SPI family flash '''
+ min_f, max_f, loop = spi_find_freq_range(ubman)
+ flashes = ubman.config.env.get('env__spi_lock_unlock', False)
+ if not flashes:
+ pytest.skip('No SPI test device configured for lock/unlock')
+
+ i = 0
+ while i < loop:
+ spi_pre_commands(ubman, random.randint(min_f, max_f))
+ total_size = get_total_size()
+ flash_part = get_flash_part()
+
+ flashes_list = flashes.get('supported_flash', None).split(',')
+ flashes_list = [x.strip() for x in flashes_list]
+ if flash_part not in flashes_list:
+ pytest.skip('Detected flash does not support lock/unlock')
+
+ # For lower half of memory
+ lock_addr = random.randint(0, (total_size // 2) - 1)
+ lock_size = random.randint(1, ((total_size // 2) - lock_addr))
+ spi_lock_unlock(ubman, lock_addr, lock_size)
+
+ # For upper half of memory
+ lock_addr = random.randint((total_size // 2), total_size - 1)
+ lock_size = random.randint(1, (total_size - lock_addr))
+ spi_lock_unlock(ubman, lock_addr, lock_size)
+
+ # For entire flash
+ lock_addr = random.randint(0, total_size - 1)
+ lock_size = random.randint(1, (total_size - lock_addr))
+ spi_lock_unlock(ubman, lock_addr, lock_size)
+
+ i = i + 1
+
+@pytest.mark.buildconfigspec('cmd_bdi')
+@pytest.mark.buildconfigspec('cmd_sf')
+@pytest.mark.buildconfigspec('cmd_memory')
+def test_spi_negative(ubman):
+ ''' Negative tests for SPI '''
+ min_f, max_f, loop = spi_find_freq_range(ubman)
+ spi_pre_commands(ubman, random.randint(min_f, max_f))
+ total_size = get_total_size()
+ erase_size = get_erase_size()
+ page_size = get_page_size()
+ addr = utils.find_ram_base(ubman)
+ i = 0
+ while i < loop:
+ # Erase negative test
+ start = random.randint(0, total_size)
+ esize = erase_size
+
+ # If erasesize is not multiple of flash's erase size
+ while esize % erase_size == 0:
+ esize = random.randint(0, total_size - start)
+
+ error_msg = 'Erased: ERROR'
+ flash_ops(
+ ubman, 'erase', start, esize, 0, 1, error_msg, EXPECTED_ERASE
+ )
+
+ # If eraseoffset exceeds beyond flash size
+ eoffset = random.randint(total_size, (total_size + int(0x1000000)))
+ error_msg = 'Offset exceeds device limit'
+ flash_ops(
+ ubman, 'erase', eoffset, esize, 0, 1, error_msg, EXPECTED_ERASE
+ )
+
+ # If erasesize exceeds beyond flash size
+ esize = random.randint((total_size - start), (total_size + int(0x1000000)))
+ error_msg = 'ERROR: attempting erase past flash size'
+ flash_ops(
+ ubman, 'erase', start, esize, 0, 1, error_msg, EXPECTED_ERASE
+ )
+
+ # If erase size is 0
+ esize = 0
+ error_msg = None
+ flash_ops(
+ ubman, 'erase', start, esize, 0, 1, error_msg, EXPECTED_ERASE
+ )
+
+ # If erasesize is less than flash's page size
+ esize = random.randint(0, page_size)
+ start = random.randint(0, (total_size - page_size))
+ error_msg = 'Erased: ERROR'
+ flash_ops(
+ ubman, 'erase', start, esize, 0, 1, error_msg, EXPECTED_ERASE
+ )
+
+ # Write/Read negative test
+ # if Write/Read size exceeds beyond flash size
+ offset = random.randint(0, total_size)
+ size = random.randint((total_size - offset), (total_size + int(0x1000000)))
+ error_msg = 'Size exceeds partition or device limit'
+ flash_ops(
+ ubman, 'write', offset, size, addr, 1, error_msg, EXPECTED_WRITE
+ )
+ flash_ops(
+ ubman, 'read', offset, size, addr, 1, error_msg, EXPECTED_READ
+ )
+
+ # if Write/Read offset exceeds beyond flash size
+ offset = random.randint(total_size, (total_size + int(0x1000000)))
+ size = random.randint(0, total_size)
+ error_msg = 'Offset exceeds device limit'
+ flash_ops(
+ ubman, 'write', offset, size, addr, 1, error_msg, EXPECTED_WRITE
+ )
+ flash_ops(
+ ubman, 'read', offset, size, addr, 1, error_msg, EXPECTED_READ
+ )
+
+ # if Write/Read size is 0
+ offset = random.randint(0, 2)
+ size = 0
+ error_msg = None
+ flash_ops(
+ ubman, 'write', offset, size, addr, 1, error_msg, EXPECTED_WRITE
+ )
+ flash_ops(
+ ubman, 'read', offset, size, addr, 1, error_msg, EXPECTED_READ
+ )
+
+ # Read to relocation address
+ output = ubman.run_command('bdinfo')
+ m = re.search(r'relocaddr\s*= (.+)', output)
+ res_area = int(m.group(1), 16)
+
+ start = 0
+ size = 0x2000
+ error_msg = 'ERROR: trying to overwrite reserved memory'
+ flash_ops(
+ ubman, 'read', start, size, res_area, 1, error_msg, EXPECTED_READ
+ )
+
+ # Start reading from the reserved area
+ m = re.search(r'reserved\[0\]\s*\[(0x.+)-(0x.+)\]', output)
+ if not m or int(m.group(1), 16) == 0:
+ ubman.log.info('No reserved area is defined or start addr is 0x0!')
+ else:
+ rstart_area = int(m.group(1), 16)
+ rend_area = int(m.group(2), 16)
+
+ # Case 1: Start reading from the middle of the reserved area
+ r_size = rend_area - rstart_area
+ r_area = rstart_area + r_size
+ flash_ops(
+ ubman, 'read', start, size, r_area, 1, error_msg, EXPECTED_READ
+ )
+
+ # Case 2: Start reading from before the reserved area to cross-over
+ # the reserved area
+ rstart_area = rstart_area - int(size/2)
+ flash_ops(
+ ubman, 'read', start, size, rstart_area, 1, error_msg, EXPECTED_READ
+ )
+
+ # Case 3: Start reading till after the reserved area to cross-over
+ # the reserved area
+ rend_area = rend_area - int(size/2)
+ flash_ops(
+ ubman, 'read', start, size, rend_area, 1, error_msg, EXPECTED_READ
+ )
+
+ i = i + 1
diff --git a/test/py/tests/test_spl.py b/test/py/tests/test_spl.py
index 42e4c4342b2..48407399039 100644
--- a/test/py/tests/test_spl.py
+++ b/test/py/tests/test_spl.py
@@ -6,16 +6,16 @@ import os.path
import pytest
@pytest.mark.buildconfigspec('spl_unit_test')
-def test_ut_spl_init(u_boot_console):
+def test_ut_spl_init(ubman):
"""Initialize data for ut spl tests."""
- fn = u_boot_console.config.source_dir + '/spi.bin'
+ fn = ubman.config.source_dir + '/spi.bin'
if not os.path.exists(fn):
data = b'\x00' * (2 * 1024 * 1024)
with open(fn, 'wb') as fh:
fh.write(data)
-def test_spl(u_boot_console, ut_spl_subtest):
+def test_spl(ubman, ut_spl_subtest):
"""Execute a "ut" subtest.
The subtests are collected in function generate_ut_subtest() from linker
@@ -29,16 +29,15 @@ def test_spl(u_boot_console, ut_spl_subtest):
implemented in C function foo_test_bar().
Args:
- u_boot_console (ConsoleBase): U-Boot console
+ ubman (ConsoleBase): U-Boot console
ut_subtest (str): SPL test to be executed (e.g. 'dm platdata_phandle')
"""
try:
- cons = u_boot_console
- cons.restart_uboot_with_flags(['-u', '-k', ut_spl_subtest.split()[1]])
- output = cons.get_spawn_output().replace('\r', '')
- assert 'Failures: 0' in output
+ ubman.restart_uboot_with_flags(['-u', '-k', ut_spl_subtest.split()[1]])
+ output = ubman.get_spawn_output().replace('\r', '')
+ assert 'failures: 0' in output
finally:
# Restart afterward in case a non-SPL test is run next. This should not
# happen since SPL tests are run in their own invocation of test.py, but
# the cost of doing this is not too great at present.
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
diff --git a/test/py/tests/test_stackprotector.py b/test/py/tests/test_stackprotector.py
index b87392c54ff..a7e20d6307c 100644
--- a/test/py/tests/test_stackprotector.py
+++ b/test/py/tests/test_stackprotector.py
@@ -6,10 +6,10 @@ import signal
@pytest.mark.buildconfigspec('cmd_stackprotector_test')
@pytest.mark.notbuildconfigspec('asan')
-def test_stackprotector(u_boot_console):
+def test_stackprotector(ubman):
"""Test that the stackprotector function works."""
- u_boot_console.run_command('stackprot_test',wait_for_prompt=False)
+ ubman.run_command('stackprot_test',wait_for_prompt=False)
expected_response = 'Stack smashing detected'
- u_boot_console.wait_for(expected_response)
- u_boot_console.restart_uboot()
+ ubman.wait_for(expected_response)
+ ubman.restart_uboot()
diff --git a/test/py/tests/test_suite.py b/test/py/tests/test_suite.py
new file mode 100644
index 00000000000..7fe9a90dfd3
--- /dev/null
+++ b/test/py/tests/test_suite.py
@@ -0,0 +1,207 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright 2024 Google LLC
+
+import pytest
+import re
+
+# List of test suites we expect to find with 'ut info' and 'ut all'
+EXPECTED_SUITES = [
+ 'addrmap', 'bdinfo', 'bloblist', 'bootm', 'bootstd',
+ 'cmd', 'common', 'dm', 'env', 'exit', 'fdt_overlay',
+ 'fdt', 'font', 'hush', 'lib',
+ 'loadm', 'log', 'mbr', 'measurement', 'mem',
+ 'pci_mps', 'setexpr', 'upl',
+ ]
+
+
+# Set this to True to aid debugging of tests
+DEBUG_ME = False
+
+
+def collect_info(ubman, output):
+ """Process the output from 'ut all'
+
+ Args:
+ ubman: U-Boot console object
+ output: Output from running 'ut all'
+
+ Returns:
+ tuple:
+ set: suite names that were found in output
+ set: test names that were found in output
+ dict: test count for each suite:
+ key: suite name
+ value: number of tests for the suite found in output
+ set: missing suites (compared to EXPECTED_SUITES)
+ set: extra suites (compared to EXPECTED_SUITES)
+ """
+ suites = set()
+ tests = set()
+ cur_suite = None
+ test_count = None
+ exp_test_count = {}
+
+ # Collect suites{}
+ for line in output.splitlines():
+ line = line.rstrip()
+ if DEBUG_ME:
+ ubman.log.info(f'line: {line}')
+ m = re.search('----Running ([^ ]*) tests----', line)
+ if m:
+ if DEBUG_ME and cur_suite and cur_suite != 'info':
+ ubman.log.info(f'suite: {cur_suite} expected {exp_test_count[cur_suite]} found {test_count}')
+
+ cur_suite = m.group(1)
+ if DEBUG_ME:
+ ubman.log.info(f'cur_suite: {cur_suite}')
+ suites.add(cur_suite)
+
+ test_count = 0
+ m = re.match(rf'Running (\d+) {cur_suite} tests', line)
+ if m:
+ exp_test_count[cur_suite] = int(m.group(1))
+ m = re.search(r'Test: (\w*): ([-a-z0-9_]*\.c)?( .*)?', line)
+ if m:
+ test_name = m.group(1)
+ msg = m.group(3)
+ if DEBUG_ME:
+ ubman.log.info(f"test_name {test_name} msg '{msg}'")
+ full_name = f'{cur_suite}.{test_name}'
+ if msg == ' (flat tree)' and full_name not in tests:
+ tests.add(full_name)
+ test_count += 1
+ if not msg or 'skipped as it is manual' in msg:
+ tests.add(full_name)
+ test_count += 1
+ if DEBUG_ME:
+ ubman.log.info(f'test_count {test_count}')
+ if DEBUG_ME:
+ ubman.log.info(f'suite: {cur_suite} expected {exp_test_count[cur_suite]} found {test_count}')
+ ubman.log.info(f"Tests: {' '.join(sorted(list(tests)))}")
+
+ # Figure out what is missing, or extra
+ missing = set()
+ extra = set(suites)
+ for suite in EXPECTED_SUITES:
+ if suite in extra:
+ extra.remove(suite)
+ else:
+ missing.add(suite)
+
+ return suites, tests, exp_test_count, missing, extra
+
+
+def process_ut_info(ubman, output):
+ """Process the output of the 'ut info' command
+
+ Args:
+ ubman: U-Boot console object
+ output: Output from running 'ut all'
+
+ Returns:
+ tuple:
+ int: Number of suites reported
+ int: Number of tests reported
+ dict: test count for each suite:
+ key: suite name
+ value: number of tests reported for the suite
+
+ """
+ suite_count = None
+ total_test_count = None
+ test_count = {}
+ for line in output.splitlines():
+ line = line.rstrip()
+ if DEBUG_ME:
+ ubman.log.info(f'line: {line}')
+ m = re.match(r'Test suites: (.*)', line)
+ if m:
+ suite_count = int(m.group(1))
+ m = re.match(r'Total tests: (.*)', line)
+ if m:
+ total_test_count = int(m.group(1))
+ m = re.match(r' *([0-9?]*) (\w*)', line)
+ if m:
+ test_count[m.group(2)] = m.group(1)
+ return suite_count, total_test_count, test_count
+
+
+@pytest.mark.buildconfigspec('sandbox')
+@pytest.mark.notbuildconfigspec('sandbox_spl')
+@pytest.mark.notbuildconfigspec('sandbox64')
+# This test is disabled since it fails; remove the leading 'x' to try it
+def xtest_suite(ubman, u_boot_config):
+ """Perform various checks on the unit tests, including:
+
+ - The number of suites matches that reported by the 'ut info'
+ - Where available, the number of tests is each suite matches that
+ reported by 'ut -s info'
+ - The total number of tests adds up to the total that are actually run
+ with 'ut all'
+ - All suites are run with 'ut all'
+ - The expected set of suites is run (the list is hard-coded in this test)
+
+ """
+ buildconfig = u_boot_config.buildconfig
+ with ubman.log.section('Run all unit tests'):
+ # ut hush hush_test_simple_dollar prints "Unknown command" on purpose.
+ with ubman.disable_check('unknown_command'):
+ output = ubman.run_command('ut all')
+
+ # Process the output from the run
+ with ubman.log.section('Check output'):
+ suites, all_tests, exp_test_count, missing, extra = collect_info(ubman,
+ output)
+ ubman.log.info(f'missing {missing}')
+ ubman.log.info(f'extra {extra}')
+
+ # Make sure we got a test count for each suite
+ assert not (suites - exp_test_count.keys())
+
+ # Deal with missing suites
+ with ubman.log.section('Check missing suites'):
+ if 'config_cmd_seama' not in buildconfig:
+ ubman.log.info("CMD_SEAMA not enabled: Ignoring suite 'seama'")
+ missing.discard('seama')
+
+ # Run 'ut info' and compare with the log results
+ with ubman.log.section('Check suite test-counts'):
+ output = ubman.run_command('ut -s info')
+
+ suite_count, total_test_count, test_count = process_ut_info(ubman,
+ output)
+
+ if missing or extra:
+ ubman.log.info(f"suites: {' '.join(sorted(list(suites)))}")
+ ubman.log.error(f'missing: {sorted(list(missing))}')
+ ubman.log.error(f'extra: {sorted(list(extra))}')
+
+ assert not missing, f'Missing suites {missing}'
+ assert not extra, f'Extra suites {extra}'
+
+ ubman.log.info(str(exp_test_count))
+ for suite in EXPECTED_SUITES:
+ assert test_count[suite] in ['?', str(exp_test_count[suite])], \
+ f'suite {suite} expected {exp_test_count[suite]}'
+
+ assert suite_count == len(EXPECTED_SUITES)
+ assert total_test_count == len(all_tests)
+
+ # Run three suites
+ with ubman.log.section('Check multiple suites'):
+ output = ubman.run_command('ut bloblist,setexpr,mem')
+ assert 'Suites run: 3' in output
+
+ # Run a particular test
+ with ubman.log.section('Check single test'):
+ output = ubman.run_command('ut bloblist reloc')
+ assert 'Test: reloc: bloblist.c' in output
+
+ # Run tests multiple times
+ with ubman.log.section('Check multiple runs'):
+ output = ubman.run_command('ut -r2 bloblist')
+ lines = output.splitlines()
+ run = len([line for line in lines if 'Test:' in line])
+ count = re.search(r'Tests run: (\d*)', lines[-1]).group(1)
+
+ assert run == 2 * int(count)
diff --git a/test/py/tests/test_tpm2.py b/test/py/tests/test_tpm2.py
index 1d654cd4a23..064651c3e23 100644
--- a/test/py/tests/test_tpm2.py
+++ b/test/py/tests/test_tpm2.py
@@ -4,7 +4,7 @@
import os.path
import pytest
-import u_boot_utils
+import utils
import re
import time
@@ -31,109 +31,109 @@ skipped.
updates = 0
-def force_init(u_boot_console, force=False):
+def force_init(ubman, force=False):
"""When a test fails, U-Boot is reset. Because TPM stack must be initialized
after each reboot, we must ensure these lines are always executed before
trying any command or they will fail with no reason. Executing 'tpm init'
twice will spawn an error used to detect that the TPM was not reset and no
initialization code should be run.
"""
- skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', False)
+ skip_test = ubman.config.env.get('env__tpm_device_test_skip', False)
if skip_test:
pytest.skip('skip TPM device test')
- output = u_boot_console.run_command('tpm2 autostart')
+ output = ubman.run_command('tpm2 autostart')
if force or not 'Error' in output:
- u_boot_console.run_command('echo --- start of init ---')
- u_boot_console.run_command('tpm2 clear TPM2_RH_LOCKOUT')
- output = u_boot_console.run_command('echo $?')
+ ubman.run_command('echo --- start of init ---')
+ ubman.run_command('tpm2 clear TPM2_RH_LOCKOUT')
+ output = ubman.run_command('echo $?')
if not output.endswith('0'):
- u_boot_console.run_command('tpm2 clear TPM2_RH_PLATFORM')
- u_boot_console.run_command('echo --- end of init ---')
+ ubman.run_command('tpm2 clear TPM2_RH_PLATFORM')
+ ubman.run_command('echo --- end of init ---')
-def is_sandbox(cons):
+def is_sandbox(ubman):
# Array slice removes leading/trailing quotes.
- sys_arch = cons.config.buildconfig.get('config_sys_arch', '"sandbox"')[1:-1]
+ sys_arch = ubman.config.buildconfig.get('config_sys_arch', '"sandbox"')[1:-1]
return sys_arch == 'sandbox'
@pytest.mark.buildconfigspec('cmd_tpm_v2')
-def test_tpm2_init(u_boot_console):
+def test_tpm2_init(ubman):
"""Init the software stack to use TPMv2 commands."""
- skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', False)
+ skip_test = ubman.config.env.get('env__tpm_device_test_skip', False)
if skip_test:
pytest.skip('skip TPM device test')
- u_boot_console.run_command('tpm2 autostart')
- output = u_boot_console.run_command('echo $?')
+ ubman.run_command('tpm2 autostart')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_tpm_v2')
-def test_tpm2_startup(u_boot_console):
+def test_tpm2_startup(ubman):
"""Execute a TPM2_Startup command.
Initiate the TPM internal state machine.
"""
- skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', False)
+ skip_test = ubman.config.env.get('env__tpm_device_test_skip', False)
if skip_test:
pytest.skip('skip TPM device test')
- u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR')
- output = u_boot_console.run_command('echo $?')
+ ubman.run_command('tpm2 startup TPM2_SU_CLEAR')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
-def tpm2_sandbox_init(u_boot_console):
+def tpm2_sandbox_init(ubman):
"""Put sandbox back into a known state so we can run a test
This allows all tests to run in parallel, since no test depends on another.
"""
- u_boot_console.restart_uboot()
- u_boot_console.run_command('tpm2 autostart')
- output = u_boot_console.run_command('echo $?')
+ ubman.restart_uboot()
+ ubman.run_command('tpm2 autostart')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
- skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', False)
+ skip_test = ubman.config.env.get('env__tpm_device_test_skip', False)
if skip_test:
pytest.skip('skip TPM device test')
@pytest.mark.buildconfigspec('cmd_tpm_v2')
-def test_tpm2_sandbox_self_test_full(u_boot_console):
+def test_tpm2_sandbox_self_test_full(ubman):
"""Execute a TPM2_SelfTest (full) command.
Ask the TPM to perform all self tests to also enable full capabilities.
"""
- if is_sandbox(u_boot_console):
- u_boot_console.restart_uboot()
- u_boot_console.run_command('tpm2 autostart')
- output = u_boot_console.run_command('echo $?')
+ if is_sandbox(ubman):
+ ubman.restart_uboot()
+ ubman.run_command('tpm2 autostart')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
- u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR')
- output = u_boot_console.run_command('echo $?')
+ ubman.run_command('tpm2 startup TPM2_SU_CLEAR')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
- skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', False)
+ skip_test = ubman.config.env.get('env__tpm_device_test_skip', False)
if skip_test:
pytest.skip('skip TPM device test')
- u_boot_console.run_command('tpm2 self_test full')
- output = u_boot_console.run_command('echo $?')
+ ubman.run_command('tpm2 self_test full')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_tpm_v2')
-def test_tpm2_continue_self_test(u_boot_console):
+def test_tpm2_continue_self_test(ubman):
"""Execute a TPM2_SelfTest (continued) command.
Ask the TPM to finish its self tests (alternative to the full test) in order
to enter a fully operational state.
"""
- skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', False)
+ skip_test = ubman.config.env.get('env__tpm_device_test_skip', False)
if skip_test:
pytest.skip('skip TPM device test')
- if is_sandbox(u_boot_console):
- tpm2_sandbox_init(u_boot_console)
- u_boot_console.run_command('tpm2 self_test continue')
- output = u_boot_console.run_command('echo $?')
+ if is_sandbox(ubman):
+ tpm2_sandbox_init(ubman)
+ ubman.run_command('tpm2 self_test continue')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_tpm_v2')
-def test_tpm2_clear(u_boot_console):
+def test_tpm2_clear(ubman):
"""Execute a TPM2_Clear command.
Ask the TPM to reset entirely its internal state (including internal
@@ -144,22 +144,22 @@ def test_tpm2_clear(u_boot_console):
not have a password set, otherwise this test will fail. ENDORSEMENT and
PLATFORM hierarchies are also available.
"""
- if is_sandbox(u_boot_console):
- tpm2_sandbox_init(u_boot_console)
+ if is_sandbox(ubman):
+ tpm2_sandbox_init(ubman)
- skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', False)
+ skip_test = ubman.config.env.get('env__tpm_device_test_skip', False)
if skip_test:
pytest.skip('skip TPM device test')
- u_boot_console.run_command('tpm2 clear TPM2_RH_LOCKOUT')
- output = u_boot_console.run_command('echo $?')
+ ubman.run_command('tpm2 clear TPM2_RH_LOCKOUT')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
- u_boot_console.run_command('tpm2 clear TPM2_RH_PLATFORM')
- output = u_boot_console.run_command('echo $?')
+ ubman.run_command('tpm2 clear TPM2_RH_PLATFORM')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_tpm_v2')
-def test_tpm2_change_auth(u_boot_console):
+def test_tpm2_change_auth(ubman):
"""Execute a TPM2_HierarchyChangeAuth command.
Ask the TPM to change the owner, ie. set a new password: 'unicorn'
@@ -167,22 +167,22 @@ def test_tpm2_change_auth(u_boot_console):
Use the LOCKOUT hierarchy for this. ENDORSEMENT and PLATFORM hierarchies are
also available.
"""
- if is_sandbox(u_boot_console):
- tpm2_sandbox_init(u_boot_console)
- force_init(u_boot_console)
+ if is_sandbox(ubman):
+ tpm2_sandbox_init(ubman)
+ force_init(ubman)
- u_boot_console.run_command('tpm2 change_auth TPM2_RH_LOCKOUT unicorn')
- output = u_boot_console.run_command('echo $?')
+ ubman.run_command('tpm2 change_auth TPM2_RH_LOCKOUT unicorn')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
- u_boot_console.run_command('tpm2 clear TPM2_RH_LOCKOUT unicorn')
- output = u_boot_console.run_command('echo $?')
- u_boot_console.run_command('tpm2 clear TPM2_RH_PLATFORM')
+ ubman.run_command('tpm2 clear TPM2_RH_LOCKOUT unicorn')
+ output = ubman.run_command('echo $?')
+ ubman.run_command('tpm2 clear TPM2_RH_PLATFORM')
assert output.endswith('0')
@pytest.mark.buildconfigspec('sandbox')
@pytest.mark.buildconfigspec('cmd_tpm_v2')
-def test_tpm2_get_capability(u_boot_console):
+def test_tpm2_get_capability(ubman):
"""Execute a TPM_GetCapability command.
Display one capability. In our test case, let's display the default DAM
@@ -193,19 +193,19 @@ def test_tpm2_get_capability(u_boot_console):
There is no expected default values because it would depend on the chip
used. We can still save them in order to check they have changed later.
"""
- if is_sandbox(u_boot_console):
- tpm2_sandbox_init(u_boot_console)
+ if is_sandbox(ubman):
+ tpm2_sandbox_init(ubman)
- force_init(u_boot_console)
- ram = u_boot_utils.find_ram_base(u_boot_console)
+ force_init(ubman)
+ ram = utils.find_ram_base(ubman)
- read_cap = u_boot_console.run_command('tpm2 get_capability 0x6 0x20e 0x200 1') #0x%x 1' % ram)
- output = u_boot_console.run_command('echo $?')
+ read_cap = ubman.run_command('tpm2 get_capability 0x6 0x20e 0x200 1') #0x%x 1' % ram)
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
assert 'Property 0x0000020e: 0x00000000' in read_cap
@pytest.mark.buildconfigspec('cmd_tpm_v2')
-def test_tpm2_dam_parameters(u_boot_console):
+def test_tpm2_dam_parameters(ubman):
"""Execute a TPM2_DictionaryAttackParameters command.
Change Dictionary Attack Mitigation (DAM) parameters. Ask the TPM to change:
@@ -217,38 +217,38 @@ def test_tpm2_dam_parameters(u_boot_console):
the authentication, otherwise the lockout will be engaged after the first
failed authentication attempt.
"""
- if is_sandbox(u_boot_console):
- tpm2_sandbox_init(u_boot_console)
- force_init(u_boot_console)
- ram = u_boot_utils.find_ram_base(u_boot_console)
+ if is_sandbox(ubman):
+ tpm2_sandbox_init(ubman)
+ force_init(ubman)
+ ram = utils.find_ram_base(ubman)
# Set the DAM parameters to known values
- u_boot_console.run_command('tpm2 dam_parameters 3 10 0')
- output = u_boot_console.run_command('echo $?')
+ ubman.run_command('tpm2 dam_parameters 3 10 0')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
# Check the values have been saved
- read_cap = u_boot_console.run_command('tpm2 get_capability 0x6 0x20f 0x%x 3' % ram)
- output = u_boot_console.run_command('echo $?')
+ read_cap = ubman.run_command('tpm2 get_capability 0x6 0x20f 0x%x 3' % ram)
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
assert 'Property 0x0000020f: 0x00000003' in read_cap
assert 'Property 0x00000210: 0x0000000a' in read_cap
assert 'Property 0x00000211: 0x00000000' in read_cap
@pytest.mark.buildconfigspec('cmd_tpm_v2')
-def test_tpm2_pcr_read(u_boot_console):
+def test_tpm2_pcr_read(ubman):
"""Execute a TPM2_PCR_Read command.
Perform a PCR read of the 10th PCR. Must be zero.
"""
- if is_sandbox(u_boot_console):
- tpm2_sandbox_init(u_boot_console)
+ if is_sandbox(ubman):
+ tpm2_sandbox_init(ubman)
- force_init(u_boot_console)
- ram = u_boot_utils.find_ram_base(u_boot_console)
+ force_init(ubman)
+ ram = utils.find_ram_base(ubman)
- read_pcr = u_boot_console.run_command('tpm2 pcr_read 10 0x%x' % ram)
- output = u_boot_console.run_command('echo $?')
+ read_pcr = ubman.run_command('tpm2 pcr_read 10 0x%x' % ram)
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
# Save the number of PCR updates
@@ -257,11 +257,11 @@ def test_tpm2_pcr_read(u_boot_console):
updates = int(re.findall(r'\d+', str)[0])
# Check the output value
- assert 'PCR #10 content' in read_pcr
+ assert 'PCR #10 sha256 32 byte content' in read_pcr
assert '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' in read_pcr
@pytest.mark.buildconfigspec('cmd_tpm_v2')
-def test_tpm2_pcr_extend(u_boot_console):
+def test_tpm2_pcr_extend(ubman):
"""Execute a TPM2_PCR_Extend command.
Perform a PCR extension with a known hash in memory (zeroed since the board
@@ -270,25 +270,25 @@ def test_tpm2_pcr_extend(u_boot_console):
No authentication mechanism is used here, not protecting against packet
replay, yet.
"""
- if is_sandbox(u_boot_console):
- tpm2_sandbox_init(u_boot_console)
- force_init(u_boot_console)
- ram = u_boot_utils.find_ram_base(u_boot_console)
+ if is_sandbox(ubman):
+ tpm2_sandbox_init(ubman)
+ force_init(ubman)
+ ram = utils.find_ram_base(ubman)
- read_pcr = u_boot_console.run_command('tpm2 pcr_read 10 0x%x' % (ram + 0x20))
- output = u_boot_console.run_command('echo $?')
+ read_pcr = ubman.run_command('tpm2 pcr_read 10 0x%x' % (ram + 0x20))
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
str = re.findall(r'\d+ known updates', read_pcr)[0]
updates = int(re.findall(r'\d+', str)[0])
- u_boot_console.run_command('tpm2 pcr_extend 10 0x%x' % ram)
- output = u_boot_console.run_command('echo $?')
+ ubman.run_command('tpm2 pcr_extend 10 0x%x' % ram)
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
# Read the value back into a different place so we can still use 'ram' as
# our zero bytes
- read_pcr = u_boot_console.run_command('tpm2 pcr_read 10 0x%x' % (ram + 0x20))
- output = u_boot_console.run_command('echo $?')
+ read_pcr = ubman.run_command('tpm2 pcr_read 10 0x%x' % (ram + 0x20))
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
assert 'f5 a5 fd 42 d1 6a 20 30 27 98 ef 6e d3 09 97 9b' in read_pcr
assert '43 00 3d 23 20 d9 f0 e8 ea 98 31 a9 27 59 fb 4b' in read_pcr
@@ -297,12 +297,12 @@ def test_tpm2_pcr_extend(u_boot_console):
new_updates = int(re.findall(r'\d+', str)[0])
assert (updates + 1) == new_updates
- u_boot_console.run_command('tpm2 pcr_extend 10 0x%x' % ram)
- output = u_boot_console.run_command('echo $?')
+ ubman.run_command('tpm2 pcr_extend 10 0x%x' % ram)
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
- read_pcr = u_boot_console.run_command('tpm2 pcr_read 10 0x%x' % (ram + 0x20))
- output = u_boot_console.run_command('echo $?')
+ read_pcr = ubman.run_command('tpm2 pcr_read 10 0x%x' % (ram + 0x20))
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
assert '7a 05 01 f5 95 7b df 9c b3 a8 ff 49 66 f0 22 65' in read_pcr
assert 'f9 68 65 8b 7a 9c 62 64 2c ba 11 65 e8 66 42 f5' in read_pcr
@@ -312,7 +312,7 @@ def test_tpm2_pcr_extend(u_boot_console):
assert (updates + 2) == new_updates
@pytest.mark.buildconfigspec('cmd_tpm_v2')
-def test_tpm2_cleanup(u_boot_console):
+def test_tpm2_cleanup(ubman):
"""Ensure the TPM is cleared from password or test related configuration."""
- force_init(u_boot_console, True)
+ force_init(ubman, True)
diff --git a/test/py/tests/test_trace.py b/test/py/tests/test_trace.py
index 7c5696ce747..fcdcbe2c6db 100644
--- a/test/py/tests/test_trace.py
+++ b/test/py/tests/test_trace.py
@@ -6,28 +6,28 @@ import os
import pytest
import re
-import u_boot_utils as util
+import utils
# This is needed for Azure, since the default '..' directory is not writeable
TMPDIR = '/tmp/test_trace'
# Decode a function-graph line
-RE_LINE = re.compile(r'.*0\.\.\.\.\. \s*([0-9.]*): func.*[|](\s*)(\S.*)?([{};])$')
+RE_LINE = re.compile(r'.*0\.\.\.\.\.? \s*([0-9.]*): func.*[|](\s*)(\S.*)?([{};])$')
-def collect_trace(cons):
+def collect_trace(ubman):
"""Build U-Boot and run it to collect a trace
Args:
- cons (ConsoleBase): U-Boot console
+ ubman (ConsoleBase): U-Boot console
Returns:
tuple:
str: Filename of the output trace file
int: Microseconds taken for initf_dm according to bootstage
"""
- cons.run_command('trace pause')
- out = cons.run_command('trace stats')
+ ubman.run_command('trace pause')
+ out = ubman.run_command('trace stats')
# The output is something like this:
# 251,003 function sites
@@ -48,10 +48,10 @@ def collect_trace(cons):
assert int(vals['untracked function calls']) == 0
assert int(vals['maximum observed call depth']) > 30
assert (vals['call depth limit'] ==
- cons.config.buildconfig.get('config_trace_call_depth_limit'))
+ ubman.config.buildconfig.get('config_trace_call_depth_limit'))
assert int(vals['calls not traced due to depth']) > 100000
- out = cons.run_command('bootstage report')
+ out = ubman.run_command('bootstage report')
# Accumulated time:
# 19,104 dm_r
# 23,078 of_live
@@ -62,30 +62,56 @@ def collect_trace(cons):
# Read out the trace data
addr = 0x02000000
size = 0x02000000
- out = cons.run_command(f'trace calls {addr:x} {size:x}')
+ out = ubman.run_command(f'trace calls {addr:x} {size:x}')
print(out)
fname = os.path.join(TMPDIR, 'trace')
- out = cons.run_command(
+ out = ubman.run_command(
'host save hostfs - %x %s ${profoffset}' % (addr, fname))
return fname, int(dm_f_time[0])
-def check_function(cons, fname, proftool, map_fname, trace_dat):
+def wipe_and_collect_trace(ubman):
+ """Pause and wipe traces, return the number of calls (should be zero)
+
+ Args:
+ ubman (ConsoleBase): U-Boot console
+
+ Returns:
+ int: the number of traced function calls reported by 'trace stats'
+ """
+ ubman.run_command('trace pause')
+ ubman.run_command('trace wipe')
+ out = ubman.run_command('trace stats')
+
+ # The output is something like this:
+ # 117,221 function sites
+ # 0 function calls
+ # 0 untracked function calls
+ # 0 traced function calls
+
+ # Get a dict of values from the output
+ lines = [line.split(maxsplit=1) for line in out.splitlines() if line]
+ vals = {key: val.replace(',', '') for val, key in lines}
+
+ return int(vals['traced function calls'])
+
+
+def check_function(ubman, fname, proftool, map_fname, trace_dat):
"""Check that the 'function' output works
Args:
- cons (ConsoleBase): U-Boot console
+ ubman (ConsoleBase): U-Boot console
fname (str): Filename of trace file
proftool (str): Filename of proftool
map_fname (str): Filename of System.map
trace_dat (str): Filename of output file
"""
- out = util.run_and_log(
- cons, [proftool, '-t', fname, '-o', trace_dat, '-m', map_fname,
+ out = utils.run_and_log(
+ ubman, [proftool, '-t', fname, '-o', trace_dat, '-m', map_fname,
'dump-ftrace'])
# Check that trace-cmd can read it
- out = util.run_and_log(cons, ['trace-cmd', 'dump', trace_dat])
+ out = utils.run_and_log(ubman, ['trace-cmd', 'dump', trace_dat])
# Tracing meta data in file /tmp/test_trace/trace.dat:
# [Initial format]
@@ -114,7 +140,7 @@ def check_function(cons, fname, proftool, map_fname, trace_dat):
# Check that the trace has something useful
cmd = f"trace-cmd report -l {trace_dat} |grep -E '(initf_|initr_)'"
- out = util.run_and_log(cons, ['sh', '-c', cmd])
+ out = utils.run_and_log(ubman, ['sh', '-c', cmd])
# Format:
# u-boot-1 0..... 60.805596: function: initf_malloc
@@ -141,11 +167,11 @@ def check_function(cons, fname, proftool, map_fname, trace_dat):
assert max_delta < 5
-def check_funcgraph(cons, fname, proftool, map_fname, trace_dat):
+def check_funcgraph(ubman, fname, proftool, map_fname, trace_dat):
"""Check that the 'funcgraph' output works
Args:
- cons (ConsoleBase): U-Boot console
+ ubman (ConsoleBase): U-Boot console
fname (str): Filename of trace file
proftool (str): Filename of proftool
map_fname (str): Filename of System.map
@@ -156,13 +182,13 @@ def check_funcgraph(cons, fname, proftool, map_fname, trace_dat):
"""
# Generate the funcgraph format
- out = util.run_and_log(
- cons, [proftool, '-t', fname, '-o', trace_dat, '-m', map_fname,
+ out = utils.run_and_log(
+ ubman, [proftool, '-t', fname, '-o', trace_dat, '-m', map_fname,
'dump-ftrace', '-f', 'funcgraph'])
# Check that the trace has what we expect
cmd = f'trace-cmd report -l {trace_dat} |head -n 70'
- out = util.run_and_log(cons, ['sh', '-c', cmd])
+ out = utils.run_and_log(ubman, ['sh', '-c', cmd])
# First look for this:
# u-boot-1 0..... 282.101360: funcgraph_entry: 0.004 us | initf_malloc();
@@ -175,7 +201,7 @@ def check_funcgraph(cons, fname, proftool, map_fname, trace_dat):
# Then look for this:
# u-boot-1 0..... 282.101375: funcgraph_exit: 0.006 us | }
# Then check for this:
- # u-boot-1 0..... 282.101375: funcgraph_entry: 0.000 us | initcall_is_event();
+ # u-boot-1 0..... 282.101375: funcgraph_entry: 0.000 us | event_init();
expected_indent = None
found_start = False
@@ -198,13 +224,13 @@ def check_funcgraph(cons, fname, proftool, map_fname, trace_dat):
found_end = True
# The next function after initf_bootstage() exits should be
- # initcall_is_event()
- assert upto == 'initcall_is_event()'
+ # event_init()
+ assert upto == 'event_init()'
# Now look for initf_dm() and dm_timer_init() so we can check the bootstage
# time
cmd = f"trace-cmd report -l {trace_dat} |grep -E '(initf_dm|dm_timer_init)'"
- out = util.run_and_log(cons, ['sh', '-c', cmd])
+ out = utils.run_and_log(ubman, ['sh', '-c', cmd])
start_timestamp = None
end_timestamp = None
@@ -223,14 +249,14 @@ def check_funcgraph(cons, fname, proftool, map_fname, trace_dat):
return int((float(end_timestamp) - float(start_timestamp)) * 1000000)
-def check_flamegraph(cons, fname, proftool, map_fname, trace_fg):
+def check_flamegraph(ubman, fname, proftool, map_fname, trace_fg):
"""Check that the 'flamegraph' output works
This spot checks a few call counts and estimates the time taken by the
initf_dm() function
Args:
- cons (ConsoleBase): U-Boot console
+ ubman (ConsoleBase): U-Boot console
fname (str): Filename of trace file
proftool (str): Filename of proftool
map_fname (str): Filename of System.map
@@ -241,14 +267,14 @@ def check_flamegraph(cons, fname, proftool, map_fname, trace_fg):
"""
# Generate the flamegraph format
- out = util.run_and_log(
- cons, [proftool, '-t', fname, '-o', trace_fg, '-m', map_fname,
+ out = utils.run_and_log(
+ ubman, [proftool, '-t', fname, '-o', trace_fg, '-m', map_fname,
'dump-flamegraph'])
# We expect dm_timer_init() to be called twice: once before relocation and
# once after
look1 = 'initf_dm;dm_timer_init 1'
- look2 = 'board_init_r;initcall_run_list;initr_dm_devices;dm_timer_init 1'
+ look2 = 'board_init_r;initcall_run_r;initr_dm_devices;dm_timer_init 1'
found = 0
with open(trace_fg, 'r') as fd:
for line in fd:
@@ -258,8 +284,8 @@ def check_flamegraph(cons, fname, proftool, map_fname, trace_fg):
assert found == 2
# Generate the timing graph
- out = util.run_and_log(
- cons, [proftool, '-t', fname, '-o', trace_fg, '-m', map_fname,
+ utils.run_and_log(
+ ubman, [proftool, '-t', fname, '-o', trace_fg, '-m', map_fname,
'dump-flamegraph', '-f', 'timing'])
# Add up all the time spend in initf_dm() and its children
@@ -277,30 +303,33 @@ check_flamegraph
@pytest.mark.slow
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('trace')
-def test_trace(u_boot_console):
+def test_trace(ubman):
"""Test we can build sandbox with trace, collect and process a trace"""
- cons = u_boot_console
if not os.path.exists(TMPDIR):
os.mkdir(TMPDIR)
- proftool = os.path.join(cons.config.build_dir, 'tools', 'proftool')
- map_fname = os.path.join(cons.config.build_dir, 'System.map')
+ proftool = os.path.join(ubman.config.build_dir, 'tools', 'proftool')
+ map_fname = os.path.join(ubman.config.build_dir, 'System.map')
trace_dat = os.path.join(TMPDIR, 'trace.dat')
trace_fg = os.path.join(TMPDIR, 'trace.fg')
- fname, dm_f_time = collect_trace(cons)
+ fname, dm_f_time = collect_trace(ubman)
- check_function(cons, fname, proftool, map_fname, trace_dat)
- trace_time = check_funcgraph(cons, fname, proftool, map_fname, trace_dat)
+ check_function(ubman, fname, proftool, map_fname, trace_dat)
+ trace_time = check_funcgraph(ubman, fname, proftool, map_fname, trace_dat)
# Check that bootstage and funcgraph agree to within 10 microseconds
diff = abs(trace_time - dm_f_time)
print(f'trace_time {trace_time}, dm_f_time {dm_f_time}')
assert diff / dm_f_time < 0.01
- fg_time = check_flamegraph(cons, fname, proftool, map_fname, trace_fg)
+ fg_time = check_flamegraph(ubman, fname, proftool, map_fname, trace_fg)
# Check that bootstage and flamegraph agree to within 30%
# This allows for CI being slow to run
diff = abs(fg_time - dm_f_time)
assert diff / dm_f_time < 0.3
+
+ # Check that the trace buffer can be wiped
+ numcalls = wipe_and_collect_trace(ubman)
+ assert numcalls == 0
diff --git a/test/py/tests/test_ums.py b/test/py/tests/test_ums.py
index 749b1606235..caf6c0a7270 100644
--- a/test/py/tests/test_ums.py
+++ b/test/py/tests/test_ums.py
@@ -11,7 +11,7 @@ import os.path
import pytest
import re
import time
-import u_boot_utils
+import utils
"""
Note: This test relies on:
@@ -74,13 +74,13 @@ writable_fs_partition value.
"""
@pytest.mark.buildconfigspec('cmd_usb_mass_storage')
-def test_ums(u_boot_console, env__usb_dev_port, env__block_devs):
+def test_ums(ubman, env__usb_dev_port, env__block_devs):
"""Test the "ums" command; the host system must be able to enumerate a UMS
device when "ums" is running, block and optionally file I/O are tested,
and this device must disappear when "ums" is aborted.
Args:
- u_boot_console: A U-Boot console connection.
+ ubman: A U-Boot console connection.
env__usb_dev_port: The single USB device-mode port specification on
which to run the test. See the file-level comment above for
details of the format.
@@ -96,7 +96,7 @@ def test_ums(u_boot_console, env__usb_dev_port, env__block_devs):
if not have_writable_fs_partition:
# If 'writable_fs_subdir' is missing, we'll skip all parts of the
# testing which mount filesystems.
- u_boot_console.log.warning(
+ ubman.log.warning(
'boardenv missing "writable_fs_partition"; ' +
'UMS testing will be limited.')
@@ -109,18 +109,15 @@ def test_ums(u_boot_console, env__usb_dev_port, env__block_devs):
tgt_dev_type = env__block_devs[0]['type']
tgt_dev_id = env__block_devs[0]['id']
if have_writable_fs_partition:
- mount_point = u_boot_console.config.env['env__mount_points'][0]
+ mount_point = ubman.config.env['env__mount_points'][0]
mount_subdir = env__block_devs[0]['writable_fs_subdir']
part_num = env__block_devs[0]['writable_fs_partition']
host_ums_part_node = '%s-part%d' % (host_ums_dev_node, part_num)
+ test_f = utils.PersistentRandomFile(ubman, 'ums.bin', 1024 * 1024);
+ mounted_test_fn = mount_point + '/' + mount_subdir + test_f.fn
else:
host_ums_part_node = host_ums_dev_node
- test_f = u_boot_utils.PersistentRandomFile(u_boot_console, 'ums.bin',
- 1024 * 1024);
- if have_writable_fs_partition:
- mounted_test_fn = mount_point + '/' + mount_subdir + test_f.fn
-
def start_ums():
"""Start U-Boot's ums shell command.
@@ -133,13 +130,13 @@ def test_ums(u_boot_console, env__usb_dev_port, env__block_devs):
Nothing.
"""
- u_boot_console.log.action(
+ ubman.log.action(
'Starting long-running U-Boot ums shell command')
cmd = 'ums %s %s %s' % (tgt_usb_ctlr, tgt_dev_type, tgt_dev_id)
- u_boot_console.run_command(cmd, wait_for_prompt=False)
- u_boot_console.wait_for(re.compile('UMS: LUN.*[\r\n]'))
- fh = u_boot_utils.wait_until_open_succeeds(host_ums_part_node)
- u_boot_console.log.action('Reading raw data from UMS device')
+ ubman.run_command(cmd, wait_for_prompt=False)
+ ubman.wait_for(re.compile('UMS: LUN.*[\r\n]'))
+ fh = utils.wait_until_open_succeeds(host_ums_part_node)
+ ubman.log.action('Reading raw data from UMS device')
fh.read(4096)
fh.close()
@@ -153,9 +150,9 @@ def test_ums(u_boot_console, env__usb_dev_port, env__block_devs):
Nothing.
"""
- u_boot_console.log.action('Mounting exported UMS device')
+ ubman.log.action('Mounting exported UMS device')
cmd = ('/bin/mount', host_ums_part_node)
- u_boot_utils.run_and_log(u_boot_console, cmd)
+ utils.run_and_log(ubman, cmd)
def umount(ignore_errors):
"""Unmount the block device that U-Boot exports.
@@ -170,9 +167,9 @@ def test_ums(u_boot_console, env__usb_dev_port, env__block_devs):
Nothing.
"""
- u_boot_console.log.action('Unmounting UMS device')
+ ubman.log.action('Unmounting UMS device')
cmd = ('/bin/umount', host_ums_part_node)
- u_boot_utils.run_and_log(u_boot_console, cmd, ignore_errors)
+ utils.run_and_log(ubman, cmd, ignore_errors)
def stop_ums(ignore_errors):
"""Stop U-Boot's ums shell command from executing.
@@ -190,42 +187,40 @@ def test_ums(u_boot_console, env__usb_dev_port, env__block_devs):
Nothing.
"""
- u_boot_console.log.action(
+ ubman.log.action(
'Stopping long-running U-Boot ums shell command')
- u_boot_console.ctrlc()
- u_boot_utils.wait_until_file_open_fails(host_ums_part_node,
+ ubman.ctrlc()
+ utils.wait_until_file_open_fails(host_ums_part_node,
ignore_errors)
ignore_cleanup_errors = True
- try:
- start_ums()
- if not have_writable_fs_partition:
- # Skip filesystem-based testing if not configured
- return
+ if have_writable_fs_partition:
try:
- mount()
- u_boot_console.log.action('Writing test file via UMS')
- cmd = ('rm', '-f', mounted_test_fn)
- u_boot_utils.run_and_log(u_boot_console, cmd)
- if os.path.exists(mounted_test_fn):
- raise Exception('Could not rm target UMS test file')
- cmd = ('cp', test_f.abs_fn, mounted_test_fn)
- u_boot_utils.run_and_log(u_boot_console, cmd)
- ignore_cleanup_errors = False
+ start_ums()
+ try:
+ mount()
+ ubman.log.action('Writing test file via UMS')
+ cmd = ('rm', '-f', mounted_test_fn)
+ utils.run_and_log(ubman, cmd)
+ if os.path.exists(mounted_test_fn):
+ raise Exception('Could not rm target UMS test file')
+ cmd = ('cp', test_f.abs_fn, mounted_test_fn)
+ utils.run_and_log(ubman, cmd)
+ ignore_cleanup_errors = False
+ finally:
+ umount(ignore_errors=ignore_cleanup_errors)
finally:
- umount(ignore_errors=ignore_cleanup_errors)
- finally:
- stop_ums(ignore_errors=ignore_cleanup_errors)
+ stop_ums(ignore_errors=ignore_cleanup_errors)
ignore_cleanup_errors = True
try:
start_ums()
try:
mount()
- u_boot_console.log.action('Reading test file back via UMS')
- read_back_hash = u_boot_utils.md5sum_file(mounted_test_fn)
+ ubman.log.action('Reading test file back via UMS')
+ read_back_hash = utils.md5sum_file(mounted_test_fn)
cmd = ('rm', '-f', mounted_test_fn)
- u_boot_utils.run_and_log(u_boot_console, cmd)
+ utils.run_and_log(ubman, cmd)
ignore_cleanup_errors = False
finally:
umount(ignore_errors=ignore_cleanup_errors)
diff --git a/test/py/tests/test_unknown_cmd.py b/test/py/tests/test_unknown_cmd.py
index 8fc284a9249..b40c57f8a10 100644
--- a/test/py/tests/test_unknown_cmd.py
+++ b/test/py/tests/test_unknown_cmd.py
@@ -2,12 +2,12 @@
# Copyright (c) 2015 Stephen Warren
# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
-def test_unknown_command(u_boot_console):
+def test_unknown_command(ubman):
"""Test that executing an unknown command causes U-Boot to print an
error."""
# The "unknown command" error is actively expected here,
# so error detection for it is disabled.
- with u_boot_console.disable_check('unknown_command'):
- response = u_boot_console.run_command('non_existent_cmd')
+ with ubman.disable_check('unknown_command'):
+ response = ubman.run_command('non_existent_cmd')
assert('Unknown command \'non_existent_cmd\' - try \'help\'' in response)
diff --git a/test/py/tests/test_upl.py b/test/py/tests/test_upl.py
new file mode 100644
index 00000000000..c79c32adf0b
--- /dev/null
+++ b/test/py/tests/test_upl.py
@@ -0,0 +1,37 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2024 Google LLC
+#
+# Test addition of Universal Payload
+
+import os
+
+import pytest
+import utils
+
+@pytest.mark.boardspec('sandbox_vpl')
+def test_upl_handoff(ubman):
+ """Test of UPL handoff
+
+ This works by starting up U-Boot VPL, which gets to SPL and then sets up a
+ UPL handoff using the FIT containing U-Boot proper. It then jumps to U-Boot
+ proper and runs a test to check that the parameters are correct.
+
+ The entire FIT is loaded into memory in SPL (in upl_load_from_image()) so
+ that it can be inspected in upl_test_info_norun
+ """
+ ram = os.path.join(ubman.config.build_dir, 'ram.bin')
+ fdt = os.path.join(ubman.config.build_dir, 'u-boot.dtb')
+
+ # Remove any existing RAM file, so we don't have old data present
+ if os.path.exists(ram):
+ os.remove(ram)
+ flags = ['-m', ram, '-d', fdt, '--upl']
+ ubman.restart_uboot_with_flags(flags, use_dtb=False)
+
+ # Make sure that Universal Payload is detected in U-Boot proper
+ output = ubman.run_command('upl info')
+ assert 'UPL state: active' == output
+
+ # Check the FIT offsets look correct
+ output = ubman.run_command('ut upl -f upl_test_info_norun')
+ assert 'failures: 0' in output
diff --git a/test/py/tests/test_usb.py b/test/py/tests/test_usb.py
index fb3d20f0826..1dcd0834f55 100644
--- a/test/py/tests/test_usb.py
+++ b/test/py/tests/test_usb.py
@@ -4,7 +4,7 @@
import pytest
import random
import re
-import u_boot_utils
+import utils
"""
Note: This test doesn't rely on boardenv_* configuration values but it can
@@ -20,20 +20,20 @@ For example:
env__usb_device_test_skip = False
"""
-def setup_usb(u_boot_console):
- if u_boot_console.config.env.get('env__usb_device_test_skip', True):
+def setup_usb(ubman):
+ if ubman.config.env.get('env__usb_device_test_skip', True):
pytest.skip('USB device test is not enabled')
@pytest.mark.buildconfigspec('cmd_usb')
-def test_usb_start(u_boot_console):
- setup_usb(u_boot_console)
- output = u_boot_console.run_command('usb start')
+def test_usb_start(ubman):
+ setup_usb(ubman)
+ output = ubman.run_command('usb start')
# if output is empty, usb start may already run as part of preboot command
# re-start the usb, in that case
if not output:
- u_boot_console.run_command('usb stop')
- output = u_boot_console.run_command('usb start')
+ ubman.run_command('usb stop')
+ output = ubman.run_command('usb start')
if 'No USB device found' in output:
pytest.skip('No USB controller available')
@@ -61,26 +61,26 @@ def test_usb_start(u_boot_console):
if 'Starting the controller' in output:
assert 'USB XHCI' in output
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
return controllers, storage_device
@pytest.mark.buildconfigspec('cmd_usb')
-def test_usb_stop(u_boot_console):
- setup_usb(u_boot_console)
- output = u_boot_console.run_command('usb stop')
+def test_usb_stop(ubman):
+ setup_usb(ubman)
+ output = ubman.run_command('usb stop')
assert 'stopping USB..' in output
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
- output = u_boot_console.run_command('usb dev')
+ output = ubman.run_command('usb dev')
assert "USB is stopped. Please issue 'usb start' first." in output
@pytest.mark.buildconfigspec('cmd_usb')
-def test_usb_reset(u_boot_console):
- setup_usb(u_boot_console)
- output = u_boot_console.run_command('usb reset')
+def test_usb_reset(ubman):
+ setup_usb(ubman)
+ output = ubman.run_command('usb reset')
if 'No USB device found' in output:
pytest.skip('No USB controller available')
@@ -107,13 +107,13 @@ def test_usb_reset(u_boot_console):
if 'Starting the controller' in output:
assert 'USB XHCI' in output
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_usb')
-def test_usb_info(u_boot_console):
- controllers, storage_device = test_usb_start(u_boot_console)
- output = u_boot_console.run_command('usb info')
+def test_usb_info(ubman):
+ controllers, storage_device = test_usb_start(ubman)
+ output = ubman.run_command('usb info')
num_controller = len(re.findall(': Hub,', output))
num_mass_storage = len(re.findall(': Mass Storage,', output))
@@ -121,22 +121,22 @@ def test_usb_info(u_boot_console):
assert num_controller == controllers - 1
assert num_mass_storage == storage_device
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
for i in range(0, storage_device + controllers - 1):
- output = u_boot_console.run_command('usb info %d' % i)
+ output = ubman.run_command('usb info %d' % i)
num_controller = len(re.findall(': Hub,', output))
num_mass_storage = len(re.findall(': Mass Storage,', output))
assert num_controller + num_mass_storage == 1
assert 'No device available' not in output
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_usb')
-def test_usb_tree(u_boot_console):
- controllers, storage_device = test_usb_start(u_boot_console)
- output = u_boot_console.run_command('usb tree')
+def test_usb_tree(ubman):
+ controllers, storage_device = test_usb_start(ubman)
+ output = ubman.run_command('usb tree')
num_controller = len(re.findall('Hub', output))
num_mass_storage = len(re.findall('Mass Storage', output))
@@ -144,14 +144,14 @@ def test_usb_tree(u_boot_console):
assert num_controller == controllers - 1
assert num_mass_storage == storage_device
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_usb')
@pytest.mark.buildconfigspec('usb_storage')
-def test_usb_storage(u_boot_console):
- controllers, storage_device = test_usb_start(u_boot_console)
- output = u_boot_console.run_command('usb storage')
+def test_usb_storage(ubman):
+ controllers, storage_device = test_usb_start(ubman)
+ output = ubman.run_command('usb storage')
obj = re.findall(r'Capacity: (\d+|\d+[\.]?\d)', output)
devices = {}
@@ -167,17 +167,17 @@ def test_usb_storage(u_boot_console):
except ValueError:
pytest.fail('USB storage device capacity not recognized')
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_usb')
-def test_usb_dev(u_boot_console):
- controllers, storage_device = test_usb_start(u_boot_console)
- output = u_boot_console.run_command('usb dev')
+def test_usb_dev(ubman):
+ controllers, storage_device = test_usb_start(ubman)
+ output = ubman.run_command('usb dev')
assert 'no usb devices available' not in output
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
devices = {}
@@ -188,7 +188,7 @@ def test_usb_dev(u_boot_console):
fail = 0
for x in range(0, storage_device):
devices[x]['detected'] = 'yes'
- output = u_boot_console.run_command('usb dev %d' % x)
+ output = ubman.run_command('usb dev %d' % x)
if 'Card did not respond to voltage select' in output:
fail = 1
@@ -201,7 +201,7 @@ def test_usb_dev(u_boot_console):
devices[x]['detected'] = 'no'
assert 'is now current device' in output
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
if fail:
@@ -210,24 +210,25 @@ def test_usb_dev(u_boot_console):
return devices, controllers, storage_device
@pytest.mark.buildconfigspec('cmd_usb')
-def test_usb_part(u_boot_console):
- devices, controllers, storage_device = test_usb_dev(u_boot_console)
+def test_usb_part(ubman):
+ devices, controllers, storage_device = test_usb_dev(ubman)
if not devices:
pytest.skip('No devices detected')
- u_boot_console.run_command('usb part')
+ ubman.run_command('usb part')
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
for i in range(0, storage_device):
if devices[i]['detected'] == 'yes':
- u_boot_console.run_command('usb dev %d' % i)
- output = u_boot_console.run_command('usb part')
+ ubman.run_command('usb dev %d' % i)
+ output = ubman.run_command('usb part')
lines = output.split('\n')
part_fat = []
- part_ext = []
+ part_ext2 = []
+ part_ext4 = []
for line in lines:
obj = re.search(r'(\d)\s+\d+\s+\d+\s+\w+\d+\w+-\d+\s+(\d+\w+)', line)
if obj:
@@ -239,23 +240,29 @@ def test_usb_part(u_boot_console):
print('Fat detected')
part_fat.append(part_id)
elif part_type == '83':
- print('ext detected')
- part_ext.append(part_id)
+ print('ext(2/4) detected')
+ output = ubman.run_command(
+ 'fstype usb %d:%d' % (i, part_id)
+ )
+ if 'ext2' in output:
+ part_ext2.append(part_id)
+ elif 'ext4' in output:
+ part_ext4.append(part_id)
else:
pytest.fail('Unsupported Filesystem on device %d' % i)
- devices[i]['ext4'] = part_ext
- devices[i]['ext2'] = part_ext
+ devices[i]['ext4'] = part_ext4
+ devices[i]['ext2'] = part_ext2
devices[i]['fat'] = part_fat
- if not part_ext and not part_fat:
+ if not part_ext2 and not part_ext4 and not part_fat:
pytest.fail('No partition detected on device %d' % i)
return devices, controllers, storage_device
@pytest.mark.buildconfigspec('cmd_usb')
@pytest.mark.buildconfigspec('cmd_fat')
-def test_usb_fatls_fatinfo(u_boot_console):
- devices, controllers, storage_device = test_usb_part(u_boot_console)
+def test_usb_fatls_fatinfo(ubman):
+ devices, controllers, storage_device = test_usb_part(ubman)
if not devices:
pytest.skip('No devices detected')
@@ -263,7 +270,7 @@ def test_usb_fatls_fatinfo(u_boot_console):
fs = 'fat'
for x in range(0, int(storage_device)):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('usb dev %d' % x)
+ ubman.run_command('usb dev %d' % x)
try:
partitions = devices[x][fs]
except:
@@ -271,7 +278,7 @@ def test_usb_fatls_fatinfo(u_boot_console):
continue
for part in partitions:
- output = u_boot_console.run_command('fatls usb %d:%s' % (x, part))
+ output = ubman.run_command('fatls usb %d:%s' % (x, part))
if 'Unrecognized filesystem type' in output:
partitions.remove(part)
pytest.fail('Unrecognized filesystem')
@@ -279,7 +286,7 @@ def test_usb_fatls_fatinfo(u_boot_console):
if not re.search(r'\d file\(s\), \d dir\(s\)', output):
pytest.fail('%s read failed on device %d' % (fs.upper, x))
- output = u_boot_console.run_command('fatinfo usb %d:%s' % (x, part))
+ output = ubman.run_command('fatinfo usb %d:%s' % (x, part))
string = 'Filesystem: %s' % fs.upper
if re.search(string, output):
pytest.fail('%s FS failed on device %d' % (fs.upper(), x))
@@ -288,11 +295,52 @@ def test_usb_fatls_fatinfo(u_boot_console):
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
+def usb_fatload_fatwrite(ubman, fs, x, part):
+ addr = utils.find_ram_base(ubman)
+ size = random.randint(4, 1 * 1024 * 1024)
+ output = ubman.run_command('crc32 %x %x' % (addr, size))
+ m = re.search('==> (.+?)', output)
+ if not m:
+ pytest.fail('CRC32 failed')
+ expected_crc32 = m.group(1)
+
+ file = '%s_%d' % ('uboot_test', size)
+ output = ubman.run_command(
+ '%swrite usb %d:%s %x %s %x' % (fs, x, part, addr, file, size)
+ )
+ assert 'Unable to write' not in output
+ assert 'Error' not in output
+ assert 'overflow' not in output
+ expected_text = '%d bytes written' % size
+ assert expected_text in output
+
+ alignment = int(
+ ubman.config.buildconfig.get(
+ 'config_sys_cacheline_size', 128
+ )
+ )
+ offset = random.randrange(alignment, 1024, alignment)
+ output = ubman.run_command(
+ '%sload usb %d:%s %x %s' % (fs, x, part, addr + offset, file)
+ )
+ assert 'Invalid FAT entry' not in output
+ assert 'Unable to read file' not in output
+ assert 'Misaligned buffer address' not in output
+ expected_text = '%d bytes read' % size
+ assert expected_text in output
+
+ output = ubman.run_command(
+ 'crc32 %x $filesize' % (addr + offset)
+ )
+ assert expected_crc32 in output
+
+ return file, size, expected_crc32
+
@pytest.mark.buildconfigspec('cmd_usb')
@pytest.mark.buildconfigspec('cmd_fat')
@pytest.mark.buildconfigspec('cmd_memory')
-def test_usb_fatload_fatwrite(u_boot_console):
- devices, controllers, storage_device = test_usb_part(u_boot_console)
+def test_usb_fatload_fatwrite(ubman):
+ devices, controllers, storage_device = test_usb_part(ubman)
if not devices:
pytest.skip('No devices detected')
@@ -300,7 +348,7 @@ def test_usb_fatload_fatwrite(u_boot_console):
fs = 'fat'
for x in range(0, int(storage_device)):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('usb dev %d' % x)
+ ubman.run_command('usb dev %d' % x)
try:
partitions = devices[x][fs]
except:
@@ -309,53 +357,15 @@ def test_usb_fatload_fatwrite(u_boot_console):
for part in partitions:
part_detect = 1
- addr = u_boot_utils.find_ram_base(u_boot_console)
- size = random.randint(4, 1 * 1024 * 1024)
- output = u_boot_console.run_command('crc32 %x %x' % (addr, size))
- m = re.search('==> (.+?)', output)
- if not m:
- pytest.fail('CRC32 failed')
- expected_crc32 = m.group(1)
-
- file = '%s_%d' % ('uboot_test', size)
- output = u_boot_console.run_command(
- '%swrite usb %d:%s %x %s %x' % (fs, x, part, addr, file, size)
- )
- assert 'Unable to write' not in output
- assert 'Error' not in output
- assert 'overflow' not in output
- expected_text = '%d bytes written' % size
- assert expected_text in output
-
- alignment = int(
- u_boot_console.config.buildconfig.get(
- 'config_sys_cacheline_size', 128
- )
- )
- offset = random.randrange(alignment, 1024, alignment)
- output = u_boot_console.run_command(
- '%sload usb %d:%s %x %s' % (fs, x, part, addr + offset, file)
- )
- assert 'Invalid FAT entry' not in output
- assert 'Unable to read file' not in output
- assert 'Misaligned buffer address' not in output
- expected_text = '%d bytes read' % size
- assert expected_text in output
-
- output = u_boot_console.run_command(
- 'crc32 %x $filesize' % (addr + offset)
- )
- assert expected_crc32 in output
+ usb_fatload_fatwrite(ubman, fs, x, part)
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
- return file, size
-
@pytest.mark.buildconfigspec('cmd_usb')
@pytest.mark.buildconfigspec('cmd_ext4')
-def test_usb_ext4ls(u_boot_console):
- devices, controllers, storage_device = test_usb_part(u_boot_console)
+def test_usb_ext4ls(ubman):
+ devices, controllers, storage_device = test_usb_part(ubman)
if not devices:
pytest.skip('No devices detected')
@@ -369,9 +379,9 @@ def test_usb_ext4ls(u_boot_console):
print('No %s table on this device' % fs.upper())
continue
- u_boot_console.run_command('usb dev %d' % x)
+ ubman.run_command('usb dev %d' % x)
for part in partitions:
- output = u_boot_console.run_command('%sls usb %d:%s' % (fs, x, part))
+ output = ubman.run_command('%sls usb %d:%s' % (fs, x, part))
if 'Unrecognized filesystem type' in output:
partitions.remove(part)
pytest.fail('Unrecognized filesystem')
@@ -380,12 +390,45 @@ def test_usb_ext4ls(u_boot_console):
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
+def usb_ext4load_ext4write(ubman, fs, x, part):
+ addr = utils.find_ram_base(ubman)
+ size = random.randint(4, 1 * 1024 * 1024)
+ output = ubman.run_command('crc32 %x %x' % (addr, size))
+ m = re.search('==> (.+?)', output)
+ if not m:
+ pytest.fail('CRC32 failed')
+ expected_crc32 = m.group(1)
+ file = '%s_%d' % ('uboot_test', size)
+
+ output = ubman.run_command(
+ '%swrite usb %d:%s %x /%s %x' % (fs, x, part, addr, file, size)
+ )
+ assert 'Unable to write' not in output
+ assert 'Error' not in output
+ assert 'overflow' not in output
+ expected_text = '%d bytes written' % size
+ assert expected_text in output
+
+ offset = random.randrange(128, 1024, 128)
+ output = ubman.run_command(
+ '%sload usb %d:%s %x /%s' % (fs, x, part, addr + offset, file)
+ )
+ expected_text = '%d bytes read' % size
+ assert expected_text in output
+
+ output = ubman.run_command(
+ 'crc32 %x $filesize' % (addr + offset)
+ )
+ assert expected_crc32 in output
+
+ return file, size, expected_crc32
+
@pytest.mark.buildconfigspec('cmd_usb')
@pytest.mark.buildconfigspec('cmd_ext4')
-@pytest.mark.buildconfigspec('ext4_write')
+@pytest.mark.buildconfigspec('cmd_ext4_write')
@pytest.mark.buildconfigspec('cmd_memory')
-def test_usb_ext4load_ext4write(u_boot_console):
- devices, controllers, storage_device = test_usb_part(u_boot_console)
+def test_usb_ext4load_ext4write(ubman):
+ devices, controllers, storage_device = test_usb_part(ubman)
if not devices:
pytest.skip('No devices detected')
@@ -393,7 +436,7 @@ def test_usb_ext4load_ext4write(u_boot_console):
fs = 'ext4'
for x in range(0, int(storage_device)):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('usb dev %d' % x)
+ ubman.run_command('usb dev %d' % x)
try:
partitions = devices[x][fs]
except:
@@ -402,45 +445,15 @@ def test_usb_ext4load_ext4write(u_boot_console):
for part in partitions:
part_detect = 1
- addr = u_boot_utils.find_ram_base(u_boot_console)
- size = random.randint(4, 1 * 1024 * 1024)
- output = u_boot_console.run_command('crc32 %x %x' % (addr, size))
- m = re.search('==> (.+?)', output)
- if not m:
- pytest.fail('CRC32 failed')
- expected_crc32 = m.group(1)
- file = '%s_%d' % ('uboot_test', size)
-
- output = u_boot_console.run_command(
- '%swrite usb %d:%s %x /%s %x' % (fs, x, part, addr, file, size)
- )
- assert 'Unable to write' not in output
- assert 'Error' not in output
- assert 'overflow' not in output
- expected_text = '%d bytes written' % size
- assert expected_text in output
-
- offset = random.randrange(128, 1024, 128)
- output = u_boot_console.run_command(
- '%sload usb %d:%s %x /%s' % (fs, x, part, addr + offset, file)
- )
- expected_text = '%d bytes read' % size
- assert expected_text in output
-
- output = u_boot_console.run_command(
- 'crc32 %x $filesize' % (addr + offset)
- )
- assert expected_crc32 in output
+ usb_ext4load_ext4write(ubman, fs, x, part)
if not part_detect:
pytest.skip('No %s partition detected' % fs.upper())
- return file, size
-
@pytest.mark.buildconfigspec('cmd_usb')
@pytest.mark.buildconfigspec('cmd_ext2')
-def test_usb_ext2ls(u_boot_console):
- devices, controllers, storage_device = test_usb_part(u_boot_console)
+def test_usb_ext2ls(ubman):
+ devices, controllers, storage_device = test_usb_part(ubman)
if not devices:
pytest.skip('No devices detected')
@@ -448,7 +461,7 @@ def test_usb_ext2ls(u_boot_console):
fs = 'ext2'
for x in range(0, int(storage_device)):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('usb dev %d' % x)
+ ubman.run_command('usb dev %d' % x)
try:
partitions = devices[x][fs]
except:
@@ -457,7 +470,7 @@ def test_usb_ext2ls(u_boot_console):
for part in partitions:
part_detect = 1
- output = u_boot_console.run_command('%sls usb %d:%s' % (fs, x, part))
+ output = ubman.run_command('%sls usb %d:%s' % (fs, x, part))
if 'Unrecognized filesystem type' in output:
partitions.remove(part)
pytest.fail('Unrecognized filesystem')
@@ -469,11 +482,10 @@ def test_usb_ext2ls(u_boot_console):
@pytest.mark.buildconfigspec('cmd_usb')
@pytest.mark.buildconfigspec('cmd_ext2')
@pytest.mark.buildconfigspec('cmd_ext4')
-@pytest.mark.buildconfigspec('ext4_write')
+@pytest.mark.buildconfigspec('cmd_ext4_write')
@pytest.mark.buildconfigspec('cmd_memory')
-def test_usb_ext2load(u_boot_console):
- devices, controllers, storage_device = test_usb_part(u_boot_console)
- file, size = test_usb_ext4load_ext4write(u_boot_console)
+def test_usb_ext2load(ubman):
+ devices, controllers, storage_device = test_usb_part(ubman)
if not devices:
pytest.skip('No devices detected')
@@ -482,7 +494,7 @@ def test_usb_ext2load(u_boot_console):
fs = 'ext2'
for x in range(0, int(storage_device)):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('usb dev %d' % x)
+ ubman.run_command('usb dev %d' % x)
try:
partitions = devices[x][fs]
except:
@@ -491,21 +503,18 @@ def test_usb_ext2load(u_boot_console):
for part in partitions:
part_detect = 1
- addr = u_boot_utils.find_ram_base(u_boot_console)
- output = u_boot_console.run_command('crc32 %x %x' % (addr, size))
- m = re.search('==> (.+?)', output)
- if not m:
- pytest.fail('CRC32 failed')
- expected_crc32 = m.group(1)
+ file, size, expected_crc32 = \
+ usb_ext4load_ext4write(ubman, fs, x, part)
+ addr = utils.find_ram_base(ubman)
offset = random.randrange(128, 1024, 128)
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'%sload usb %d:%s %x /%s' % (fs, x, part, addr + offset, file)
)
expected_text = '%d bytes read' % size
assert expected_text in output
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'crc32 %x $filesize' % (addr + offset)
)
assert expected_crc32 in output
@@ -515,16 +524,16 @@ def test_usb_ext2load(u_boot_console):
@pytest.mark.buildconfigspec('cmd_usb')
@pytest.mark.buildconfigspec('cmd_fs_generic')
-def test_usb_ls(u_boot_console):
- devices, controllers, storage_device = test_usb_part(u_boot_console)
+def test_usb_ls(ubman):
+ devices, controllers, storage_device = test_usb_part(ubman)
if not devices:
pytest.skip('No devices detected')
part_detect = 0
for x in range(0, int(storage_device)):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('usb dev %d' % x)
- for fs in ['fat', 'ext4']:
+ ubman.run_command('usb dev %d' % x)
+ for fs in ['fat', 'ext2', 'ext4']:
try:
partitions = devices[x][fs]
except:
@@ -533,7 +542,7 @@ def test_usb_ls(u_boot_console):
for part in partitions:
part_detect = 1
- output = u_boot_console.run_command('ls usb %d:%s' % (x, part))
+ output = ubman.run_command('ls usb %d:%s' % (x, part))
if re.search(r'No \w+ table on this device', output):
pytest.fail(
'%s: Partition table not found %d' % (fs.upper(), x)
@@ -543,17 +552,18 @@ def test_usb_ls(u_boot_console):
pytest.skip('No partition detected')
@pytest.mark.buildconfigspec('cmd_usb')
+@pytest.mark.buildconfigspec('cmd_ext4_write')
@pytest.mark.buildconfigspec('cmd_fs_generic')
-def test_usb_load(u_boot_console):
- devices, controllers, storage_device = test_usb_part(u_boot_console)
+def test_usb_load(ubman):
+ devices, controllers, storage_device = test_usb_part(ubman)
if not devices:
pytest.skip('No devices detected')
part_detect = 0
for x in range(0, int(storage_device)):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('usb dev %d' % x)
- for fs in ['fat', 'ext4']:
+ ubman.run_command('usb dev %d' % x)
+ for fs in ['fat', 'ext2', 'ext4']:
try:
partitions = devices[x][fs]
except:
@@ -562,27 +572,25 @@ def test_usb_load(u_boot_console):
for part in partitions:
part_detect = 1
- addr = u_boot_utils.find_ram_base(u_boot_console)
+ addr = utils.find_ram_base(ubman)
if fs == 'fat':
- file, size = test_usb_fatload_fatwrite(u_boot_console)
- elif fs == 'ext4':
- file, size = test_usb_ext4load_ext4write(u_boot_console)
-
- output = u_boot_console.run_command('crc32 %x %x' % (addr, size))
- m = re.search('==> (.+?)', output)
- if not m:
- pytest.fail('CRC32 failed')
- expected_crc32 = m.group(1)
+ file, size, expected_crc32 = \
+ usb_fatload_fatwrite(ubman, fs, x, part)
+ elif fs in ['ext4', 'ext2']:
+ file, size, expected_crc32 = \
+ usb_ext4load_ext4write(ubman, fs, x, part)
+ else:
+ raise Exception('Unsupported filesystem type %s' % fs)
offset = random.randrange(128, 1024, 128)
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'load usb %d:%s %x /%s' % (x, part, addr + offset, file)
)
expected_text = '%d bytes read' % size
assert expected_text in output
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'crc32 %x $filesize' % (addr + offset)
)
assert expected_crc32 in output
@@ -592,16 +600,16 @@ def test_usb_load(u_boot_console):
@pytest.mark.buildconfigspec('cmd_usb')
@pytest.mark.buildconfigspec('cmd_fs_generic')
-def test_usb_save(u_boot_console):
- devices, controllers, storage_device = test_usb_part(u_boot_console)
+def test_usb_save(ubman):
+ devices, controllers, storage_device = test_usb_part(ubman)
if not devices:
pytest.skip('No devices detected')
part_detect = 0
for x in range(0, int(storage_device)):
if devices[x]['detected'] == 'yes':
- u_boot_console.run_command('usb dev %d' % x)
- for fs in ['fat', 'ext4']:
+ ubman.run_command('usb dev %d' % x)
+ for fs in ['fat', 'ext2', 'ext4']:
try:
partitions = devices[x][fs]
except:
@@ -610,12 +618,12 @@ def test_usb_save(u_boot_console):
for part in partitions:
part_detect = 1
- addr = u_boot_utils.find_ram_base(u_boot_console)
+ addr = utils.find_ram_base(ubman)
size = random.randint(4, 1 * 1024 * 1024)
file = '%s_%d' % ('uboot_test', size)
offset = random.randrange(128, 1024, 128)
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'save usb %d:%s %x /%s %x'
% (x, part, addr + offset, file, size)
)
diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index c169c835e38..cdf54adc600 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -1,16 +1,22 @@
# SPDX-License-Identifier: GPL-2.0
-# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
+"""
+Unit-test runner
+
+Provides a test_ut() function which is used by conftest.py to run each unit
+test one at a time, as well setting up some files needed by the tests.
+# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
+"""
import collections
-import getpass
import gzip
import os
import os.path
import pytest
-import u_boot_utils
+import utils
# pylint: disable=E0611
from tests import fs_helper
+from test_android import test_abootimg
def mkdir_cond(dirname):
"""Create a directory if it doesn't already exist
@@ -21,89 +27,26 @@ def mkdir_cond(dirname):
if not os.path.exists(dirname):
os.mkdir(dirname)
-def setup_image(cons, mmc_dev, part_type, second_part=False):
- """Create a 20MB disk image with a single partition
-
- Args:
- cons (ConsoleBase): Console to use
- mmc_dev (int): MMC device number to use, e.g. 1
- part_type (int): Partition type, e.g. 0xc for FAT32
- second_part (bool): True to contain a small second partition
-
- Returns:
- tuple:
- str: Filename of MMC image
- str: Directory name of 'mnt' directory
- """
- fname = os.path.join(cons.config.source_dir, f'mmc{mmc_dev}.img')
- mnt = os.path.join(cons.config.persistent_data_dir, 'mnt')
- mkdir_cond(mnt)
-
- spec = f'type={part_type:x}, size=18M, bootable'
- if second_part:
- spec += '\ntype=c'
-
- u_boot_utils.run_and_log(cons, 'qemu-img create %s 20M' % fname)
- u_boot_utils.run_and_log(cons, 'sudo sfdisk %s' % fname,
- stdin=spec.encode('utf-8'))
- return fname, mnt
-
-def mount_image(cons, fname, mnt, fstype):
- """Create a filesystem and mount it on partition 1
+def copy_partition(ubman, fsfile, outname):
+ """Copy a partition into a disk iamge
Args:
- cons (ConsoleBase): Console to use
- fname (str): Filename of MMC image
- mnt (str): Directory name of 'mnt' directory
- fstype (str): Filesystem type ('vfat' or 'ext4')
-
- Returns:
- str: Name of loop device used
+ ubman (ConsoleBase): U-Boot fixture
+ fsfile (str): Name of partition file
+ outname (str): Name of full-disk file to update
"""
- out = u_boot_utils.run_and_log(cons, 'sudo losetup --show -f -P %s' % fname)
- loop = out.strip()
- part = f'{loop}p1'
- u_boot_utils.run_and_log(cons, f'sudo mkfs.{fstype} {part}')
- opts = ''
- if fstype == 'vfat':
- opts += f' -o uid={os.getuid()},gid={os.getgid()}'
- u_boot_utils.run_and_log(cons, f'sudo mount -o loop {part} {mnt}{opts}')
- u_boot_utils.run_and_log(cons, f'sudo chown {getpass.getuser()} {mnt}')
- return loop
-
-def copy_prepared_image(cons, mmc_dev, fname):
- """Use a prepared image since we cannot create one
+ utils.run_and_log(ubman,
+ f'dd if={fsfile} of={outname} bs=1M seek=1 conv=notrunc')
- Args:
- cons (ConsoleBase): Console touse
- mmc_dev (int): MMC device number
- fname (str): Filename of MMC image
- """
- infname = os.path.join(cons.config.source_dir,
- f'test/py/tests/bootstd/mmc{mmc_dev}.img.xz')
- u_boot_utils.run_and_log(
- cons,
- ['sh', '-c', 'xz -dc %s >%s' % (infname, fname)])
-
-def setup_bootmenu_image(cons):
+def setup_bootmenu_image(ubman):
"""Create a 20MB disk image with a single ext4 partition
This is modelled on Armbian 22.08 Jammy
"""
mmc_dev = 4
- fname, mnt = setup_image(cons, mmc_dev, 0x83)
-
- loop = None
- mounted = False
- complete = False
- try:
- loop = mount_image(cons, fname, mnt, 'ext4')
- mounted = True
-
- vmlinux = 'Image'
- initrd = 'uInitrd'
- dtbdir = 'dtb'
- script = '''# DO NOT EDIT THIS FILE
+ fname, mnt = fs_helper.setup_image(ubman, mmc_dev, 0x83)
+
+ script = '''# DO NOT EDIT THIS FILE
#
# Please edit /boot/armbianEnv.txt to set supported parameters
#
@@ -176,68 +119,53 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}
# Recompile with:
# mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
-''' % (mmc_dev)
- bootdir = os.path.join(mnt, 'boot')
- mkdir_cond(bootdir)
- cmd_fname = os.path.join(bootdir, 'boot.cmd')
- scr_fname = os.path.join(bootdir, 'boot.scr')
- with open(cmd_fname, 'w') as outf:
- print(script, file=outf)
-
- infname = os.path.join(cons.config.source_dir,
- 'test/py/tests/bootstd/armbian.bmp.xz')
- bmp_file = os.path.join(bootdir, 'boot.bmp')
- u_boot_utils.run_and_log(
- cons,
- ['sh', '-c', f'xz -dc {infname} >{bmp_file}'])
-
- u_boot_utils.run_and_log(
- cons, f'mkimage -C none -A arm -T script -d {cmd_fname} {scr_fname}')
-
- kernel = 'vmlinuz-5.15.63-rockchip64'
- target = os.path.join(bootdir, kernel)
- with open(target, 'wb') as outf:
- print('kernel', outf)
-
- symlink = os.path.join(bootdir, 'Image')
- if os.path.exists(symlink):
- os.remove(symlink)
- u_boot_utils.run_and_log(
- cons, f'echo here {kernel} {symlink}')
- os.symlink(kernel, symlink)
-
- u_boot_utils.run_and_log(
- cons, f'mkimage -C none -A arm -T script -d {cmd_fname} {scr_fname}')
- complete = True
-
- except ValueError as exc:
- print('Falled to create image, failing back to prepared copy: %s',
- str(exc))
- finally:
- if mounted:
- 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)
-
- if not complete:
- copy_prepared_image(cons, mmc_dev, fname)
-
-def setup_bootflow_image(cons):
+'''
+ bootdir = os.path.join(mnt, 'boot')
+ mkdir_cond(bootdir)
+ cmd_fname = os.path.join(bootdir, 'boot.cmd')
+ scr_fname = os.path.join(bootdir, 'boot.scr')
+ with open(cmd_fname, 'w', encoding='ascii') as outf:
+ print(script, file=outf)
+
+ infname = os.path.join(ubman.config.source_dir,
+ 'test/py/tests/bootstd/armbian.bmp.xz')
+ bmp_file = os.path.join(bootdir, 'boot.bmp')
+ utils.run_and_log(
+ ubman,
+ ['sh', '-c', f'xz -dc {infname} >{bmp_file}'])
+
+ mkimage = ubman.config.build_dir + '/tools/mkimage'
+ utils.run_and_log(
+ ubman, f'{mkimage} -C none -A arm -T script -d {cmd_fname} {scr_fname}')
+
+ kernel = 'vmlinuz-5.15.63-rockchip64'
+ target = os.path.join(bootdir, kernel)
+ with open(target, 'wb') as outf:
+ print('kernel', outf)
+
+ symlink = os.path.join(bootdir, 'Image')
+ if os.path.exists(symlink):
+ os.remove(symlink)
+ utils.run_and_log(
+ ubman, f'echo here {kernel} {symlink}')
+ os.symlink(kernel, symlink)
+
+ fsfile = 'ext18M.img'
+ utils.run_and_log(ubman, f'fallocate -l 18M {fsfile}')
+ utils.run_and_log(ubman, f'mkfs.ext4 {fsfile} -d {mnt}')
+ copy_partition(ubman, fsfile, fname)
+ utils.run_and_log(ubman, f'rm -rf {mnt}')
+ utils.run_and_log(ubman, f'rm -f {fsfile}')
+
+def setup_bootflow_image(ubman):
"""Create a 20MB disk image with a single FAT partition"""
mmc_dev = 1
- fname, mnt = setup_image(cons, mmc_dev, 0xc, second_part=True)
-
- loop = None
- mounted = False
- complete = False
- try:
- loop = mount_image(cons, fname, mnt, 'vfat')
- mounted = True
-
- vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl'
- initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img'
- dtbdir = 'dtb-5.3.7-301.fc31.armv7hl'
- script = '''# extlinux.conf generated by appliance-creator
+ fname, mnt = fs_helper.setup_image(ubman, mmc_dev, 0xc, second_part=True)
+
+ vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl'
+ initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img'
+ dtbdir = 'dtb-5.3.7-301.fc31.armv7hl'
+ script = '''# extlinux.conf generated by appliance-creator
ui menu.c32
menu autoboot Welcome to Fedora-Workstation-armhfp-31-1.9. Automatic boot in # second{,s}. Press a key for options.
menu title Fedora-Workstation-armhfp-31-1.9 Boot Options.
@@ -250,51 +178,48 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)
append ro root=UUID=9732b35b-4cd5-458b-9b91-80f7047e0b8a rhgb quiet LANG=en_US.UTF-8 cma=192MB cma=256MB
fdtdir /%s/
initrd /%s''' % (vmlinux, dtbdir, initrd)
- ext = os.path.join(mnt, 'extlinux')
- mkdir_cond(ext)
-
- with open(os.path.join(ext, 'extlinux.conf'), 'w') as fd:
- print(script, file=fd)
-
- inf = os.path.join(cons.config.persistent_data_dir, 'inf')
- with open(inf, 'wb') as fd:
- fd.write(gzip.compress(b'vmlinux'))
- u_boot_utils.run_and_log(cons, 'mkimage -f auto -d %s %s' %
- (inf, os.path.join(mnt, vmlinux)))
-
- with open(os.path.join(mnt, initrd), 'w') as fd:
- print('initrd', file=fd)
-
- mkdir_cond(os.path.join(mnt, dtbdir))
-
- dtb_file = os.path.join(mnt, '%s/sandbox.dtb' % dtbdir)
- u_boot_utils.run_and_log(
- cons, 'dtc -o %s' % dtb_file, stdin=b'/dts-v1/; / {};')
- complete = True
- except ValueError as exc:
- print('Falled to create image, failing back to prepared copy: %s',
- str(exc))
- finally:
- if mounted:
- 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)
-
- if not complete:
- copy_prepared_image(cons, mmc_dev, fname)
-
-
-def setup_cros_image(cons):
+ ext = os.path.join(mnt, 'extlinux')
+ mkdir_cond(ext)
+
+ conf = os.path.join(ext, 'extlinux.conf')
+ with open(conf, 'w', encoding='ascii') as fd:
+ print(script, file=fd)
+
+ inf = os.path.join(ubman.config.persistent_data_dir, 'inf')
+ with open(inf, 'wb') as fd:
+ fd.write(gzip.compress(b'vmlinux'))
+ mkimage = ubman.config.build_dir + '/tools/mkimage'
+ utils.run_and_log(
+ ubman, f'{mkimage} -f auto -d {inf} {os.path.join(mnt, vmlinux)}')
+
+ with open(os.path.join(mnt, initrd), 'w', encoding='ascii') as fd:
+ print('initrd', file=fd)
+
+ mkdir_cond(os.path.join(mnt, dtbdir))
+
+ dtb_file = os.path.join(mnt, f'{dtbdir}/sandbox.dtb')
+ utils.run_and_log(
+ ubman, f'dtc -o {dtb_file}', stdin=b'/dts-v1/; / {};')
+
+ fsfile = 'vfat18M.img'
+ utils.run_and_log(ubman, f'fallocate -l 18M {fsfile}')
+ utils.run_and_log(ubman, f'mkfs.vfat {fsfile}')
+ utils.run_and_log(ubman, ['sh', '-c', f'mcopy -i {fsfile} {mnt}/* ::/'])
+ copy_partition(ubman, fsfile, fname)
+ utils.run_and_log(ubman, f'rm -rf {mnt}')
+ utils.run_and_log(ubman, f'rm -f {fsfile}')
+
+def setup_cros_image(ubman):
"""Create a 20MB disk image with ChromiumOS partitions"""
Partition = collections.namedtuple('part', 'start,size,name')
parts = {}
disk_data = None
- def pack_kernel(cons, arch, kern, dummy):
+ def pack_kernel(ubman, arch, kern, dummy):
"""Pack a kernel containing some fake data
Args:
- cons (ConsoleBase): Console to use
+ ubman (ConsoleBase): Console to use
arch (str): Architecture to use ('x86' or 'arm')
kern (str): Filename containing kernel
dummy (str): Dummy filename to use for config and bootloader
@@ -302,9 +227,10 @@ def setup_cros_image(cons):
Return:
bytes: Packed-kernel data
"""
- kern_part = os.path.join(cons.config.result_dir, 'kern-part-{arch}.bin')
- u_boot_utils.run_and_log(
- cons,
+ kern_part = os.path.join(ubman.config.result_dir,
+ f'kern-part-{arch}.bin')
+ utils.run_and_log(
+ ubman,
f'futility vbutil_kernel --pack {kern_part} '
'--keyblock doc/chromium/files/devkeys/kernel.keyblock '
'--signprivate doc/chromium/files/devkeys/kernel_data_key.vbprivk '
@@ -330,11 +256,9 @@ def setup_cros_image(cons):
disk_data = disk_data[:start] + data + disk_data[start + len(data):]
mmc_dev = 5
- fname = os.path.join(cons.config.source_dir, f'mmc{mmc_dev}.img')
- u_boot_utils.run_and_log(cons, 'qemu-img create %s 20M' % fname)
- #mnt = os.path.join(cons.config.persistent_data_dir, 'mnt')
- #mkdir_cond(mnt)
- u_boot_utils.run_and_log(cons, f'cgpt create {fname}')
+ fname = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img')
+ utils.run_and_log(ubman, f'qemu-img create {fname} 20M')
+ utils.run_and_log(ubman, f'cgpt create {fname}')
uuid_state = 'ebd0a0a2-b9e5-4433-87c0-68b6b72699c7'
uuid_kern = 'fe3a2a5d-4f32-41a7-b725-accc3285a309'
@@ -373,41 +297,42 @@ def setup_cros_image(cons):
size = int(size_str[:-1]) * sect_1mb
else:
size = int(size_str)
- u_boot_utils.run_and_log(
- cons,
+ utils.run_and_log(
+ ubman,
f"cgpt add -i {part['num']} -b {ptr} -s {size} -t {part['type']} {fname}")
ptr += size
- u_boot_utils.run_and_log(cons, f'cgpt boot -p {fname}')
- out = u_boot_utils.run_and_log(cons, f'cgpt show -q {fname}')
- '''We expect something like this:
- 8239 2048 1 Basic data
- 45 2048 2 ChromeOS kernel
- 8238 1 3 ChromeOS rootfs
- 2093 2048 4 ChromeOS kernel
- 8237 1 5 ChromeOS rootfs
- 41 1 6 ChromeOS kernel
- 42 1 7 ChromeOS rootfs
- 4141 2048 8 Basic data
- 43 1 9 ChromeOS reserved
- 44 1 10 ChromeOS reserved
- 40 1 11 ChromeOS firmware
- 6189 2048 12 EFI System Partition
- '''
+ utils.run_and_log(ubman, f'cgpt boot -p {fname}')
+ out = utils.run_and_log(ubman, f'cgpt show -q {fname}')
+
+ # We expect something like this:
+ # 8239 2048 1 Basic data
+ # 45 2048 2 ChromeOS kernel
+ # 8238 1 3 ChromeOS rootfs
+ # 2093 2048 4 ChromeOS kernel
+ # 8237 1 5 ChromeOS rootfs
+ # 41 1 6 ChromeOS kernel
+ # 42 1 7 ChromeOS rootfs
+ # 4141 2048 8 Basic data
+ # 43 1 9 ChromeOS reserved
+ # 44 1 10 ChromeOS reserved
+ # 40 1 11 ChromeOS firmware
+ # 6189 2048 12 EFI System Partition
# Create a dict (indexed by partition number) containing the above info
for line in out.splitlines():
start, size, num, name = line.split(maxsplit=3)
parts[int(num)] = Partition(int(start), int(size), name)
- dummy = os.path.join(cons.config.result_dir, 'dummy.txt')
+ # Set up the kernel command-line
+ dummy = os.path.join(ubman.config.result_dir, 'dummy.txt')
with open(dummy, 'wb') as outf:
- outf.write(b'dummy\n')
+ outf.write(b'BOOT_IMAGE=/vmlinuz-5.15.0-121-generic root=/dev/nvme0n1p1 ro quiet splash vt.handoff=7')
# For now we just use dummy kernels. This limits testing to just detecting
# a signed kernel. We could add support for the x86 data structures so that
# testing could cover getting the cmdline, setup.bin and other pieces.
- kern = os.path.join(cons.config.result_dir, 'kern.bin')
+ kern = os.path.join(ubman.config.result_dir, 'kern.bin')
with open(kern, 'wb') as outf:
outf.write(b'kernel\n')
@@ -415,74 +340,230 @@ def setup_cros_image(cons):
disk_data = inf.read()
# put x86 kernel in partition 2 and arm one in partition 4
- set_part_data(2, pack_kernel(cons, 'x86', kern, dummy))
- set_part_data(4, pack_kernel(cons, 'arm', kern, dummy))
+ set_part_data(2, pack_kernel(ubman, 'x86', kern, dummy))
+ set_part_data(4, pack_kernel(ubman, 'arm', kern, dummy))
with open(fname, 'wb') as outf:
outf.write(disk_data)
return fname
+def setup_android_image(ubman):
+ """Create a 20MB disk image with Android partitions"""
+ Partition = collections.namedtuple('part', 'start,size,name')
+ parts = {}
+ disk_data = None
+
+ def set_part_data(partnum, data):
+ """Set the contents of a disk partition
+
+ This updates disk_data by putting data in the right place
+
+ Args:
+ partnum (int): Partition number to set
+ data (bytes): Data for that partition
+ """
+ nonlocal disk_data
+
+ start = parts[partnum].start * sect_size
+ disk_data = disk_data[:start] + data + disk_data[start + len(data):]
+
+ mmc_dev = 7
+ fname = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img')
+ utils.run_and_log(ubman, f'qemu-img create {fname} 20M')
+ utils.run_and_log(ubman, f'cgpt create {fname}')
-def setup_cedit_file(cons):
- infname = os.path.join(cons.config.source_dir,
+ ptr = 40
+
+ # Number of sectors in 1MB
+ sect_size = 512
+ sect_1mb = (1 << 20) // sect_size
+
+ required_parts = [
+ {'num': 1, 'label':'misc', 'size': '1M'},
+ {'num': 2, 'label':'boot_a', 'size': '4M'},
+ {'num': 3, 'label':'boot_b', 'size': '4M'},
+ {'num': 4, 'label':'vendor_boot_a', 'size': '4M'},
+ {'num': 5, 'label':'vendor_boot_b', 'size': '4M'},
+ ]
+
+ for part in required_parts:
+ size_str = part['size']
+ if 'M' in size_str:
+ size = int(size_str[:-1]) * sect_1mb
+ else:
+ size = int(size_str)
+ utils.run_and_log(
+ ubman,
+ f"cgpt add -i {part['num']} -b {ptr} -s {size} -l {part['label']} -t basicdata {fname}")
+ ptr += size
+
+ utils.run_and_log(ubman, f'cgpt boot -p {fname}')
+ out = utils.run_and_log(ubman, f'cgpt show -q {fname}')
+
+ # Create a dict (indexed by partition number) containing the above info
+ for line in out.splitlines():
+ start, size, num, name = line.split(maxsplit=3)
+ parts[int(num)] = Partition(int(start), int(size), name)
+
+ with open(fname, 'rb') as inf:
+ disk_data = inf.read()
+
+ test_abootimg.AbootimgTestDiskImage(ubman, 'bootv4.img', test_abootimg.boot_img_hex)
+ boot_img = os.path.join(ubman.config.result_dir, 'bootv4.img')
+ with open(boot_img, 'rb') as inf:
+ set_part_data(2, inf.read())
+
+ test_abootimg.AbootimgTestDiskImage(ubman, 'vendor_boot.img', test_abootimg.vboot_img_hex)
+ vendor_boot_img = os.path.join(ubman.config.result_dir, 'vendor_boot.img')
+ with open(vendor_boot_img, 'rb') as inf:
+ set_part_data(4, inf.read())
+
+ with open(fname, 'wb') as outf:
+ outf.write(disk_data)
+
+ print(f'wrote to {fname}')
+
+ mmc_dev = 8
+ fname = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img')
+ utils.run_and_log(ubman, f'qemu-img create {fname} 20M')
+ utils.run_and_log(ubman, f'cgpt create {fname}')
+
+ ptr = 40
+
+ # Number of sectors in 1MB
+ sect_size = 512
+ sect_1mb = (1 << 20) // sect_size
+
+ required_parts = [
+ {'num': 1, 'label':'misc', 'size': '1M'},
+ {'num': 2, 'label':'boot_a', 'size': '4M'},
+ {'num': 3, 'label':'boot_b', 'size': '4M'},
+ ]
+
+ for part in required_parts:
+ size_str = part['size']
+ if 'M' in size_str:
+ size = int(size_str[:-1]) * sect_1mb
+ else:
+ size = int(size_str)
+ utils.run_and_log(
+ ubman,
+ f"cgpt add -i {part['num']} -b {ptr} -s {size} -l {part['label']} -t basicdata {fname}")
+ ptr += size
+
+ utils.run_and_log(ubman, f'cgpt boot -p {fname}')
+ out = utils.run_and_log(ubman, f'cgpt show -q {fname}')
+
+ # Create a dict (indexed by partition number) containing the above info
+ for line in out.splitlines():
+ start, size, num, name = line.split(maxsplit=3)
+ parts[int(num)] = Partition(int(start), int(size), name)
+
+ with open(fname, 'rb') as inf:
+ disk_data = inf.read()
+
+ test_abootimg.AbootimgTestDiskImage(ubman, 'boot.img', test_abootimg.img_hex)
+ boot_img = os.path.join(ubman.config.result_dir, 'boot.img')
+ with open(boot_img, 'rb') as inf:
+ set_part_data(2, inf.read())
+
+ with open(fname, 'wb') as outf:
+ outf.write(disk_data)
+
+ print(f'wrote to {fname}')
+
+ return fname
+
+def setup_cedit_file(ubman):
+ """Set up a .dtb file for use with testing expo and configuration editor"""
+ infname = os.path.join(ubman.config.source_dir,
'test/boot/files/expo_layout.dts')
- inhname = os.path.join(cons.config.source_dir,
+ inhname = os.path.join(ubman.config.source_dir,
'test/boot/files/expo_ids.h')
- expo_tool = os.path.join(cons.config.source_dir, 'tools/expo.py')
+ expo_tool = os.path.join(ubman.config.source_dir, 'tools/expo.py')
outfname = 'cedit.dtb'
- u_boot_utils.run_and_log(
- cons, f'{expo_tool} -e {inhname} -l {infname} -o {outfname}')
+ utils.run_and_log(
+ ubman, f'{expo_tool} -e {inhname} -l {infname} -o {outfname}')
@pytest.mark.buildconfigspec('ut_dm')
-def test_ut_dm_init(u_boot_console):
+def test_ut_dm_init(ubman):
"""Initialize data for ut dm tests."""
- fn = u_boot_console.config.source_dir + '/testflash.bin'
+ fn = ubman.config.source_dir + '/testflash.bin'
if not os.path.exists(fn):
data = b'this is a test'
data += b'\x00' * ((4 * 1024 * 1024) - len(data))
with open(fn, 'wb') as fh:
fh.write(data)
- fn = u_boot_console.config.source_dir + '/spi.bin'
+ fn = ubman.config.source_dir + '/spi.bin'
if not os.path.exists(fn):
data = b'\x00' * (2 * 1024 * 1024)
with open(fn, 'wb') as fh:
fh.write(data)
# Create a file with a single partition
- fn = u_boot_console.config.source_dir + '/scsi.img'
+ fn = ubman.config.source_dir + '/scsi.img'
if not os.path.exists(fn):
data = b'\x00' * (2 * 1024 * 1024)
with open(fn, 'wb') as fh:
fh.write(data)
- u_boot_utils.run_and_log(
- u_boot_console, f'sfdisk {fn}', stdin=b'type=83')
+ utils.run_and_log(
+ ubman, f'sfdisk {fn}', stdin=b'type=83')
- fs_helper.mk_fs(u_boot_console.config, 'ext2', 0x200000, '2MB')
- fs_helper.mk_fs(u_boot_console.config, 'fat32', 0x100000, '1MB')
+ fs_helper.mk_fs(ubman.config, 'ext2', 0x200000, '2MB', None)
+ fs_helper.mk_fs(ubman.config, 'fat32', 0x100000, '1MB', None)
mmc_dev = 6
- fn = os.path.join(u_boot_console.config.source_dir, f'mmc{mmc_dev}.img')
+ fn = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img')
data = b'\x00' * (12 * 1024 * 1024)
with open(fn, 'wb') as fh:
fh.write(data)
+
+def setup_efi_image(ubman):
+ """Create a 20MB disk image with an EFI app on it"""
+ devnum = 1
+ basename = 'flash'
+ fname, mnt = fs_helper.setup_image(ubman, devnum, 0xc, second_part=True,
+ basename=basename)
+
+ efi_dir = os.path.join(mnt, 'EFI')
+ mkdir_cond(efi_dir)
+ bootdir = os.path.join(efi_dir, 'BOOT')
+ mkdir_cond(bootdir)
+ efi_src = os.path.join(ubman.config.build_dir,
+ 'lib/efi_loader/testapp.efi')
+ efi_dst = os.path.join(bootdir, 'BOOTSBOX.EFI')
+ with open(efi_src, 'rb') as inf:
+ with open(efi_dst, 'wb') as outf:
+ outf.write(inf.read())
+ fsfile = 'vfat18M.img'
+ utils.run_and_log(ubman, f'fallocate -l 18M {fsfile}')
+ utils.run_and_log(ubman, f'mkfs.vfat {fsfile}')
+ utils.run_and_log(ubman, ['sh', '-c', f'mcopy -vs -i {fsfile} {mnt}/* ::/'])
+ copy_partition(ubman, fsfile, fname)
+ utils.run_and_log(ubman, f'rm -rf {mnt}')
+ utils.run_and_log(ubman, f'rm -f {fsfile}')
+
@pytest.mark.buildconfigspec('cmd_bootflow')
-def test_ut_dm_init_bootstd(u_boot_console):
+@pytest.mark.buildconfigspec('sandbox')
+def test_ut_dm_init_bootstd(ubman):
"""Initialise data for bootflow tests"""
- setup_bootflow_image(u_boot_console)
- setup_bootmenu_image(u_boot_console)
- setup_cedit_file(u_boot_console)
- setup_cros_image(u_boot_console)
+ setup_bootflow_image(ubman)
+ setup_bootmenu_image(ubman)
+ setup_cedit_file(ubman)
+ setup_cros_image(ubman)
+ setup_android_image(ubman)
+ setup_efi_image(ubman)
# Restart so that the new mmc1.img is picked up
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
-def test_ut(u_boot_console, ut_subtest):
+def test_ut(ubman, ut_subtest):
"""Execute a "ut" subtest.
The subtests are collected in function generate_ut_subtest() from linker
@@ -495,16 +576,16 @@ def test_ut(u_boot_console, ut_subtest):
implemented in C function foo_test_bar().
Args:
- u_boot_console (ConsoleBase): U-Boot console
+ ubman (ConsoleBase): U-Boot console
ut_subtest (str): test to be executed via command ut, e.g 'foo bar' to
execute command 'ut foo bar'
"""
if ut_subtest == 'hush hush_test_simple_dollar':
# ut hush hush_test_simple_dollar prints "Unknown command" on purpose.
- with u_boot_console.disable_check('unknown_command'):
- output = u_boot_console.run_command('ut ' + ut_subtest)
- assert('Unknown command \'quux\' - try \'help\'' in output)
+ with ubman.disable_check('unknown_command'):
+ output = ubman.run_command('ut ' + ut_subtest)
+ assert 'Unknown command \'quux\' - try \'help\'' in output
else:
- output = u_boot_console.run_command('ut ' + ut_subtest)
- assert output.endswith('Failures: 0')
+ output = ubman.run_command('ut ' + ut_subtest)
+ assert output.endswith('failures: 0')
diff --git a/test/py/tests/test_vbe.py b/test/py/tests/test_vbe.py
index 50b6c1cd911..a1f32f375b6 100644
--- a/test/py/tests/test_vbe.py
+++ b/test/py/tests/test_vbe.py
@@ -90,11 +90,10 @@ ut bootstd -f vbe_test_fixup_norun
@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')
+def test_vbe(ubman):
+ kernel = fit_util.make_kernel(ubman, 'vbe-kernel.bin', 'kernel')
+ fdt = fit_util.make_dtb(ubman, base_fdt, 'vbe-fdt')
+ fdt_out = fit_util.make_fname(ubman, 'fdt-out.dtb')
params = {
'fit_addr' : 0x1000,
@@ -108,13 +107,13 @@ def test_vbe(u_boot_console):
'compression' : 'none',
}
- mkimage = cons.config.build_dir + '/tools/mkimage'
- fit = fit_util.make_fit(cons, mkimage, base_its, params, 'test-vbe.fit',
+ mkimage = ubman.config.build_dir + '/tools/mkimage'
+ fit = fit_util.make_fit(ubman, 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())
+ with ubman.log.section('Kernel load'):
+ output = ubman.run_command_list(cmd.splitlines())
- assert 'Failures: 0' in output[-1]
+ assert 'failures: 0' in output[-1]
diff --git a/test/py/tests/test_vbe_vpl.py b/test/py/tests/test_vbe_vpl.py
index ed12d3a4618..f011b034f63 100644
--- a/test/py/tests/test_vbe_vpl.py
+++ b/test/py/tests/test_vbe_vpl.py
@@ -6,35 +6,34 @@
import os
import pytest
-import u_boot_utils
+import utils
@pytest.mark.boardspec('sandbox_vpl')
@pytest.mark.requiredtool('dtc')
-def test_vbe_vpl(u_boot_console):
- cons = u_boot_console
- #cmd = [cons.config.build_dir + fname, '-v']
- ram = os.path.join(cons.config.build_dir, 'ram.bin')
- fdt = os.path.join(cons.config.build_dir, 'arch/sandbox/dts/test.dtb')
- image_fname = os.path.join(cons.config.build_dir, 'image.bin')
+def test_vbe_vpl(ubman):
+ #cmd = [ubman.config.build_dir + fname, '-v']
+ ram = os.path.join(ubman.config.build_dir, 'ram.bin')
+ fdt = os.path.join(ubman.config.build_dir, 'arch/sandbox/dts/test.dtb')
+ image_fname = os.path.join(ubman.config.build_dir, 'image.bin')
# Enable firmware1 and the mmc that it uses. These are needed for the full
# VBE flow.
- u_boot_utils.run_and_log(
- cons, f'fdtput -t s {fdt} /bootstd/firmware0 status disabled')
- u_boot_utils.run_and_log(
- cons, f'fdtput -t s {fdt} /bootstd/firmware1 status okay')
- u_boot_utils.run_and_log(
- cons, f'fdtput -t s {fdt} /mmc3 status okay')
- u_boot_utils.run_and_log(
- cons, f'fdtput -t s {fdt} /mmc3 filename {image_fname}')
+ utils.run_and_log(
+ ubman, f'fdtput -t s {fdt} /bootstd/firmware0 status disabled')
+ utils.run_and_log(
+ ubman, f'fdtput -t s {fdt} /bootstd/firmware1 status okay')
+ utils.run_and_log(
+ ubman, f'fdtput -t s {fdt} /mmc3 status okay')
+ utils.run_and_log(
+ ubman, f'fdtput -t s {fdt} /mmc3 filename {image_fname}')
# Remove any existing RAM file, so we don't have old data present
if os.path.exists(ram):
os.remove(ram)
flags = ['-p', image_fname, '-w', '-s', 'state.dtb']
- cons.restart_uboot_with_flags(flags)
+ ubman.restart_uboot_with_flags(flags)
# Make sure that VBE was used in both VPL (to load SPL) and SPL (to load
# U-Boot
- output = cons.run_command('vbe state')
+ output = ubman.run_command('vbe state')
assert output == 'Phases: VPL SPL'
diff --git a/test/py/tests/test_vboot.py b/test/py/tests/test_vboot.py
index 7e0e8e44750..7a7f9c379de 100644
--- a/test/py/tests/test_vboot.py
+++ b/test/py/tests/test_vboot.py
@@ -42,12 +42,12 @@ import os
import shutil
import struct
import pytest
-import u_boot_utils as util
+import utils
import vboot_forge
import vboot_evil
# Common helper functions
-def dtc(dts, cons, dtc_args, datadir, tmpdir, dtb):
+def dtc(dts, ubman, dtc_args, datadir, tmpdir, dtb):
"""Run the device tree compiler to compile a .dts file
The output file will be the same as the input file but with a .dtb
@@ -55,31 +55,31 @@ def dtc(dts, cons, dtc_args, datadir, tmpdir, dtb):
Args:
dts: Device tree file to compile.
- cons: U-Boot console.
+ ubman: U-Boot console.
dtc_args: DTC arguments.
datadir: Path to data directory.
tmpdir: Path to temp directory.
dtb: Resulting DTB file.
"""
dtb = dts.replace('.dts', '.dtb')
- util.run_and_log(cons, 'dtc %s %s%s -O dtb '
- '-o %s%s' % (dtc_args, datadir, dts, tmpdir, dtb))
+ utils.run_and_log(ubman, 'dtc %s %s%s -O dtb '
+ '-o %s%s' % (dtc_args, datadir, dts, tmpdir, dtb))
-def make_fit(its, cons, mkimage, dtc_args, datadir, fit):
+def make_fit(its, ubman, mkimage, dtc_args, datadir, fit):
"""Make a new FIT from the .its source file.
This runs 'mkimage -f' to create a new FIT.
Args:
its: Filename containing .its source.
- cons: U-Boot console.
+ ubman: U-Boot console.
mkimage: Path to mkimage utility.
dtc_args: DTC arguments.
datadir: Path to data directory.
fit: Resulting FIT file.
"""
- util.run_and_log(cons, [mkimage, '-D', dtc_args, '-f',
- '%s%s' % (datadir, its), fit])
+ utils.run_and_log(ubman, [mkimage, '-D', dtc_args, '-f',
+ '%s%s' % (datadir, its), fit])
# Only run the full suite on a few combinations, since it doesn't add any more
# test coverage.
@@ -113,7 +113,7 @@ TESTDATA += [pytest.param(*v, marks=pytest.mark.slow) for v in TESTDATA_IN[1:]]
@pytest.mark.requiredtool('openssl')
@pytest.mark.parametrize("name,sha_algo,padding,sign_options,required,full_test,algo_arg,global_sign",
TESTDATA)
-def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
+def test_vboot(ubman, name, sha_algo, padding, sign_options, required,
full_test, algo_arg, global_sign):
"""Test verified boot signing with mkimage and verification with 'bootm'.
@@ -134,8 +134,8 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
options: Options provided to the compiler.
"""
dtb = dts.replace('.dts', '.dtb')
- util.run_and_log(cons, 'dtc %s %s%s -O dtb '
- '-o %s%s %s' % (dtc_args, datadir, dts, tmpdir, dtb, options))
+ utils.run_and_log(ubman, 'dtc %s %s%s -O dtb -o %s%s %s' %
+ (dtc_args, datadir, dts, tmpdir, dtb, options))
def run_binman(dtb):
"""Run binman to build an image
@@ -145,9 +145,9 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
"""
pythonpath = os.environ.get('PYTHONPATH', '')
os.environ['PYTHONPATH'] = pythonpath + ':' + '%s/../scripts/dtc/pylibfdt' % tmpdir
- util.run_and_log(cons, [binman, 'build', '-d', "%s/%s" % (tmpdir,dtb),
- '-a', "pre-load-key-path=%s" % tmpdir, '-O',
- tmpdir, '-I', tmpdir])
+ utils.run_and_log(ubman, [binman, 'build', '-d', "%s/%s" % (tmpdir,dtb),
+ '-a', "pre-load-key-path=%s" % tmpdir, '-O',
+ tmpdir, '-I', tmpdir])
os.environ['PYTHONPATH'] = pythonpath
def run_bootm(sha_algo, test_type, expect_string, boots, fit=None):
@@ -167,9 +167,9 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
"""
if not fit:
fit = '%stest.fit' % tmpdir
- cons.restart_uboot()
- with cons.log.section('Verified boot %s %s' % (sha_algo, test_type)):
- output = cons.run_command_list(
+ ubman.restart_uboot()
+ with ubman.log.section('Verified boot %s %s' % (sha_algo, test_type)):
+ output = ubman.run_command_list(
['host load hostfs - 100 %s' % fit,
'fdt addr 100',
'bootm 100'])
@@ -194,8 +194,8 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
args = [mkimage, '-F', '-k', tmpdir, '-K', dtb, '-r', fit]
if options:
args += options.split(' ')
- cons.log.action('%s: Sign images' % sha_algo)
- util.run_and_log(cons, args)
+ ubman.log.action('%s: Sign images' % sha_algo)
+ utils.run_and_log(ubman, args)
def sign_fit_dtb(sha_algo, options, dtb):
"""Sign the FIT
@@ -211,8 +211,8 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
args = [mkimage, '-F', '-k', tmpdir, '-K', dtb, '-r', fit]
if options:
args += options.split(' ')
- cons.log.action('%s: Sign images' % sha_algo)
- util.run_and_log(cons, args)
+ ubman.log.action('%s: Sign images' % sha_algo)
+ utils.run_and_log(ubman, args)
def sign_fit_norequire(sha_algo, options):
"""Sign the FIT
@@ -228,8 +228,8 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
args = [mkimage, '-F', '-k', tmpdir, '-K', dtb, fit]
if options:
args += options.split(' ')
- cons.log.action('%s: Sign images' % sha_algo)
- util.run_and_log(cons, args)
+ ubman.log.action('%s: Sign images' % sha_algo)
+ utils.run_and_log(ubman, args)
def replace_fit_totalsize(size):
"""Replace FIT header's totalsize with something greater.
@@ -278,14 +278,14 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
else:
rsa_keygen_bits = 2048
- util.run_and_log(cons, 'openssl genpkey -algorithm RSA -out %s%s.key '
+ utils.run_and_log(ubman, 'openssl genpkey -algorithm RSA -out %s%s.key '
'-pkeyopt rsa_keygen_bits:%d '
'-pkeyopt rsa_keygen_pubexp:%d' %
(tmpdir, name, rsa_keygen_bits, public_exponent))
# Create a certificate containing the public key
- util.run_and_log(cons, 'openssl req -batch -new -x509 -key %s%s.key '
- '-out %s%s.crt' % (tmpdir, name, tmpdir, name))
+ utils.run_and_log(ubman, 'openssl req -batch -new -x509 -key %s%s.key '
+ '-out %s%s.crt' % (tmpdir, name, tmpdir, name))
def test_with_algo(sha_algo, padding, sign_options):
"""Test verified boot with the given hash algorithm.
@@ -303,12 +303,12 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
# Compile our device tree files for kernel and U-Boot. These are
# regenerated here since mkimage will modify them (by adding a
# public key) below.
- dtc('sandbox-kernel.dts', cons, dtc_args, datadir, tmpdir, dtb)
- dtc('sandbox-u-boot.dts', cons, dtc_args, datadir, tmpdir, dtb)
+ dtc('sandbox-kernel.dts', ubman, dtc_args, datadir, tmpdir, dtb)
+ dtc('sandbox-u-boot.dts', ubman, dtc_args, datadir, tmpdir, dtb)
# Build the FIT, but don't sign anything yet
- cons.log.action('%s: Test FIT with signed images' % sha_algo)
- make_fit('sign-images-%s%s.its' % (sha_algo, padding), cons, mkimage, dtc_args, datadir, fit)
+ ubman.log.action('%s: Test FIT with signed images' % sha_algo)
+ make_fit('sign-images-%s%s.its' % (sha_algo, padding), ubman, mkimage, dtc_args, datadir, fit)
run_bootm(sha_algo, 'unsigned images', ' - OK' if algo_arg else 'dev-', True)
# Sign images with our dev keys
@@ -316,19 +316,19 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
run_bootm(sha_algo, 'signed images', 'dev+', True)
# Create a fresh .dtb without the public keys
- dtc('sandbox-u-boot.dts', cons, dtc_args, datadir, tmpdir, dtb)
+ dtc('sandbox-u-boot.dts', ubman, dtc_args, datadir, tmpdir, dtb)
- cons.log.action('%s: Test FIT with signed configuration' % sha_algo)
- make_fit('sign-configs-%s%s.its' % (sha_algo, padding), cons, mkimage, dtc_args, datadir, fit)
+ ubman.log.action('%s: Test FIT with signed configuration' % sha_algo)
+ make_fit('sign-configs-%s%s.its' % (sha_algo, padding), ubman, mkimage, dtc_args, datadir, fit)
run_bootm(sha_algo, 'unsigned config', '%s+ OK' % ('sha256' if algo_arg else sha_algo), True)
# Sign images with our dev keys
sign_fit(sha_algo, sign_options)
run_bootm(sha_algo, 'signed config', 'dev+', True)
- cons.log.action('%s: Check signed config on the host' % sha_algo)
+ ubman.log.action('%s: Check signed config on the host' % sha_algo)
- util.run_and_log(cons, [fit_check_sign, '-f', fit, '-k', dtb])
+ utils.run_and_log(ubman, [fit_check_sign, '-f', fit, '-k', dtb])
if full_test:
# Make sure that U-Boot checks that the config is in the list of
@@ -340,8 +340,8 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
root, strblock = vboot_forge.manipulate(root, strblock)
with open(ffit, 'w+b') as fd:
vboot_forge.write_fdt(root, strblock, fd)
- util.run_and_log_expect_exception(
- cons, [fit_check_sign, '-f', ffit, '-k', dtb],
+ utils.run_and_log_expect_exception(
+ ubman, [fit_check_sign, '-f', ffit, '-k', dtb],
1, 'Failed to verify required signature')
run_bootm(sha_algo, 'forged config', 'Bad Data Hash', False, ffit)
@@ -351,8 +351,8 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
shutil.copyfile(fit, efit)
vboot_evil.add_evil_node(fit, efit, evil_kernel, 'fakeroot')
- util.run_and_log_expect_exception(
- cons, [fit_check_sign, '-f', efit, '-k', dtb],
+ utils.run_and_log_expect_exception(
+ ubman, [fit_check_sign, '-f', efit, '-k', dtb],
1, 'Failed to verify required signature')
run_bootm(sha_algo, 'evil fakeroot', 'Bad FIT kernel image format',
False, efit)
@@ -363,42 +363,42 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
vboot_evil.add_evil_node(fit, efit, evil_kernel, 'kernel@')
msg = 'Signature checking prevents use of unit addresses (@) in nodes'
- util.run_and_log_expect_exception(
- cons, [fit_check_sign, '-f', efit, '-k', dtb],
+ utils.run_and_log_expect_exception(
+ ubman, [fit_check_sign, '-f', efit, '-k', dtb],
1, msg)
run_bootm(sha_algo, 'evil kernel@', msg, False, efit)
# Create a new properly signed fit and replace header bytes
- make_fit('sign-configs-%s%s.its' % (sha_algo, padding), cons, mkimage, dtc_args, datadir, fit)
+ make_fit('sign-configs-%s%s.its' % (sha_algo, padding), ubman, mkimage, dtc_args, datadir, fit)
sign_fit(sha_algo, sign_options)
- bcfg = u_boot_console.config.buildconfig
+ bcfg = ubman.config.buildconfig
max_size = int(bcfg.get('config_fit_signature_max_size', 0x10000000), 0)
existing_size = replace_fit_totalsize(max_size + 1)
run_bootm(sha_algo, 'Signed config with bad hash', 'Bad Data Hash',
False)
- cons.log.action('%s: Check overflowed FIT header totalsize' % sha_algo)
+ ubman.log.action('%s: Check overflowed FIT header totalsize' % sha_algo)
# Replace with existing header bytes
replace_fit_totalsize(existing_size)
run_bootm(sha_algo, 'signed config', 'dev+', True)
- cons.log.action('%s: Check default FIT header totalsize' % sha_algo)
+ ubman.log.action('%s: Check default FIT header totalsize' % sha_algo)
# Increment the first byte of the signature, which should cause failure
- sig = util.run_and_log(cons, 'fdtget -t bx %s %s value' %
- (fit, sig_node))
+ sig = utils.run_and_log(ubman, 'fdtget -t bx %s %s value' %
+ (fit, sig_node))
byte_list = sig.split()
byte = int(byte_list[0], 16)
byte_list[0] = '%x' % (byte + 1)
sig = ' '.join(byte_list)
- util.run_and_log(cons, 'fdtput -t bx %s %s value %s' %
- (fit, sig_node, sig))
+ utils.run_and_log(ubman, 'fdtput -t bx %s %s value %s' %
+ (fit, sig_node, sig))
run_bootm(sha_algo, 'Signed config with bad hash', 'Bad Data Hash',
False)
- cons.log.action('%s: Check bad config on the host' % sha_algo)
- util.run_and_log_expect_exception(
- cons, [fit_check_sign, '-f', fit, '-k', dtb],
+ ubman.log.action('%s: Check bad config on the host' % sha_algo)
+ utils.run_and_log_expect_exception(
+ ubman, [fit_check_sign, '-f', fit, '-k', dtb],
1, 'Failed to verify required signature')
def test_required_key(sha_algo, padding, sign_options):
@@ -416,19 +416,19 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
# Compile our device tree files for kernel and U-Boot. These are
# regenerated here since mkimage will modify them (by adding a
# public key) below.
- dtc('sandbox-kernel.dts', cons, dtc_args, datadir, tmpdir, dtb)
- dtc('sandbox-u-boot.dts', cons, dtc_args, datadir, tmpdir, dtb)
+ dtc('sandbox-kernel.dts', ubman, dtc_args, datadir, tmpdir, dtb)
+ dtc('sandbox-u-boot.dts', ubman, dtc_args, datadir, tmpdir, dtb)
- cons.log.action('%s: Test FIT with configs images' % sha_algo)
+ ubman.log.action('%s: Test FIT with configs images' % sha_algo)
# Build the FIT with prod key (keys required) and sign it. This puts the
# signature into sandbox-u-boot.dtb, marked 'required'
- make_fit('sign-configs-%s%s-prod.its' % (sha_algo, padding), cons, mkimage, dtc_args, datadir, fit)
+ make_fit('sign-configs-%s%s-prod.its' % (sha_algo, padding), ubman, mkimage, dtc_args, datadir, fit)
sign_fit(sha_algo, sign_options)
# Build the FIT with dev key (keys NOT required). This adds the
# signature into sandbox-u-boot.dtb, NOT marked 'required'.
- make_fit('sign-configs-%s%s.its' % (sha_algo, padding), cons, mkimage, dtc_args, datadir, fit)
+ make_fit('sign-configs-%s%s.its' % (sha_algo, padding), ubman, mkimage, dtc_args, datadir, fit)
sign_fit_norequire(sha_algo, sign_options)
# So now sandbox-u-boot.dtb two signatures, for the prod and dev keys.
@@ -440,7 +440,7 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
# Build the FIT with dev key (keys required) and sign it. This puts the
# signature into sandbox-u-boot.dtb, marked 'required'.
- make_fit('sign-configs-%s%s.its' % (sha_algo, padding), cons, mkimage, dtc_args, datadir, fit)
+ make_fit('sign-configs-%s%s.its' % (sha_algo, padding), ubman, mkimage, dtc_args, datadir, fit)
sign_fit(sha_algo, sign_options)
# Set the required-mode policy to "any".
@@ -449,8 +449,8 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
# a dev signature only (sign_fit() overwrites the FIT).
# Try to boot the FIT with dev key. This FIT should be accepted by
# U-Boot because the dev key is required and policy is "any" required key.
- util.run_and_log(cons, 'fdtput -t s %s /signature required-mode any' %
- (dtb))
+ utils.run_and_log(ubman, 'fdtput -t s %s /signature required-mode any' %
+ dtb)
run_bootm(sha_algo, 'multi required key', 'dev+', True)
# Set the required-mode policy to "all".
@@ -459,8 +459,8 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
# a dev signature only (sign_fit() overwrites the FIT).
# Try to boot the FIT with dev key. This FIT should not be accepted by
# U-Boot because the prod key is required and policy is "all" required key
- util.run_and_log(cons, 'fdtput -t s %s /signature required-mode all' %
- (dtb))
+ utils.run_and_log(ubman, 'fdtput -t s %s /signature required-mode all' %
+ dtb)
run_bootm(sha_algo, 'multi required key', '', False)
def test_global_sign(sha_algo, padding, sign_options):
@@ -473,22 +473,22 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
"""
dtb = '%ssandbox-u-boot-global%s.dtb' % (tmpdir, padding)
- cons.config.dtb = dtb
+ ubman.config.dtb = dtb
# Compile our device tree files for kernel and U-Boot. These are
# regenerated here since mkimage will modify them (by adding a
# public key) below.
- dtc('sandbox-kernel.dts', cons, dtc_args, datadir, tmpdir, dtb)
+ dtc('sandbox-kernel.dts', ubman, dtc_args, datadir, tmpdir, dtb)
dtc_options('sandbox-u-boot-global%s.dts' % padding, '-p 1024')
# Build the FIT with dev key (keys NOT required). This adds the
# signature into sandbox-u-boot.dtb, NOT marked 'required'.
- make_fit('simple-images.its', cons, mkimage, dtc_args, datadir, fit)
+ make_fit('simple-images.its', ubman, mkimage, dtc_args, datadir, fit)
sign_fit_dtb(sha_algo, '', dtb)
# Build the dtb for binman that define the pre-load header
# with the global sigature.
- dtc('sandbox-binman%s.dts' % padding, cons, dtc_args, datadir, tmpdir, dtb)
+ dtc('sandbox-binman%s.dts' % padding, ubman, dtc_args, datadir, tmpdir, dtb)
# Run binman to create the final image with the not signed fit
# and the pre-load header that contains the global signature.
@@ -508,15 +508,14 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
# Check that the boot fails if the global signature is not provided
run_bootm(sha_algo, 'global image signature', 'signature is mandatory', False)
- cons = u_boot_console
- tmpdir = os.path.join(cons.config.result_dir, name) + '/'
+ tmpdir = os.path.join(ubman.config.result_dir, name) + '/'
if not os.path.exists(tmpdir):
os.mkdir(tmpdir)
- datadir = cons.config.source_dir + '/test/py/tests/vboot/'
+ datadir = ubman.config.source_dir + '/test/py/tests/vboot/'
fit = '%stest.fit' % tmpdir
- mkimage = cons.config.build_dir + '/tools/mkimage'
- binman = cons.config.source_dir + '/tools/binman/binman'
- fit_check_sign = cons.config.build_dir + '/tools/fit_check_sign'
+ mkimage = ubman.config.build_dir + '/tools/mkimage'
+ binman = ubman.config.source_dir + '/tools/binman/binman'
+ fit_check_sign = ubman.config.build_dir + '/tools/fit_check_sign'
dtc_args = '-I dts -O dtb -i %s' % tmpdir
dtb = '%ssandbox-u-boot.dtb' % tmpdir
sig_node = '/configurations/conf-1/signature'
@@ -535,9 +534,9 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
# We need to use our own device tree file. Remember to restore it
# afterwards.
- old_dtb = cons.config.dtb
+ old_dtb = ubman.config.dtb
try:
- cons.config.dtb = dtb
+ ubman.config.dtb = dtb
if global_sign:
test_global_sign(sha_algo, padding, sign_options)
elif required:
@@ -546,8 +545,8 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
test_with_algo(sha_algo, padding, sign_options)
finally:
# Go back to the original U-Boot with the correct dtb.
- cons.config.dtb = old_dtb
- cons.restart_uboot()
+ ubman.config.dtb = old_dtb
+ ubman.restart_uboot()
TESTDATA_IN = [
@@ -577,7 +576,7 @@ TESTDATA += [pytest.param(*v, marks=pytest.mark.slow) for v in TESTDATA_IN[1:]]
@pytest.mark.requiredtool('dtc')
@pytest.mark.requiredtool('openssl')
@pytest.mark.parametrize("name,sha_algo,padding,sign_options,algo_arg", TESTDATA)
-def test_fdt_add_pubkey(u_boot_console, name, sha_algo, padding, sign_options, algo_arg):
+def test_fdt_add_pubkey(ubman, name, sha_algo, padding, sign_options, algo_arg):
"""Test fdt_add_pubkey utility with bunch of different algo options."""
def sign_fit(sha_algo, options):
@@ -593,8 +592,8 @@ def test_fdt_add_pubkey(u_boot_console, name, sha_algo, padding, sign_options, a
args = [mkimage, '-F', '-k', tmpdir, fit]
if options:
args += options.split(' ')
- cons.log.action('%s: Sign images' % sha_algo)
- util.run_and_log(cons, args)
+ ubman.log.action('%s: Sign images' % sha_algo)
+ utils.run_and_log(ubman, args)
def test_add_pubkey(sha_algo, padding, sign_options):
"""Test fdt_add_pubkey utility with given hash algorithm and padding.
@@ -609,32 +608,33 @@ def test_fdt_add_pubkey(u_boot_console, name, sha_algo, padding, sign_options, a
"""
# Create a fresh .dtb without the public keys
- dtc('sandbox-u-boot.dts', cons, dtc_args, datadir, tmpdir, dtb)
+ dtc('sandbox-u-boot.dts', ubman, dtc_args, datadir, tmpdir, dtb)
- cons.log.action('%s: Test fdt_add_pubkey with signed configuration' % sha_algo)
+ ubman.log.action('%s: Test fdt_add_pubkey with signed configuration' % sha_algo)
# Then add the dev key via the fdt_add_pubkey tool
- util.run_and_log(cons, [fdt_add_pubkey, '-a', '%s,%s' % ('sha256' if algo_arg else sha_algo, \
- 'rsa3072' if sha_algo == 'sha384' else 'rsa2048'),
- '-k', tmpdir, '-n', 'dev', '-r', 'conf', dtb])
+ utils.run_and_log(ubman,
+ [fdt_add_pubkey, '-a', '%s,%s' %
+ ('sha256' if algo_arg else sha_algo,
+ 'rsa3072' if sha_algo == 'sha384' else 'rsa2048'),
+ '-k', tmpdir, '-n', 'dev', '-r', 'conf', dtb])
- make_fit('sign-configs-%s%s.its' % (sha_algo, padding), cons, mkimage, dtc_args, datadir, fit)
+ make_fit('sign-configs-%s%s.its' % (sha_algo, padding), ubman, mkimage, dtc_args, datadir, fit)
# Sign images with our dev keys
sign_fit(sha_algo, sign_options)
# Check with fit_check_sign that FIT is signed with key
- util.run_and_log(cons, [fit_check_sign, '-f', fit, '-k', dtb])
+ utils.run_and_log(ubman, [fit_check_sign, '-f', fit, '-k', dtb])
- cons = u_boot_console
- tmpdir = os.path.join(cons.config.result_dir, name) + '/'
+ tmpdir = os.path.join(ubman.config.result_dir, name) + '/'
if not os.path.exists(tmpdir):
os.mkdir(tmpdir)
- datadir = cons.config.source_dir + '/test/py/tests/vboot/'
+ datadir = ubman.config.source_dir + '/test/py/tests/vboot/'
fit = '%stest.fit' % tmpdir
- mkimage = cons.config.build_dir + '/tools/mkimage'
- binman = cons.config.source_dir + '/tools/binman/binman'
- fit_check_sign = cons.config.build_dir + '/tools/fit_check_sign'
- fdt_add_pubkey = cons.config.build_dir + '/tools/fdt_add_pubkey'
+ mkimage = ubman.config.build_dir + '/tools/mkimage'
+ binman = ubman.config.source_dir + '/tools/binman/binman'
+ fit_check_sign = ubman.config.build_dir + '/tools/fit_check_sign'
+ fdt_add_pubkey = ubman.config.build_dir + '/tools/fdt_add_pubkey'
dtc_args = '-I dts -O dtb -i %s' % tmpdir
dtb = '%ssandbox-u-boot.dtb' % tmpdir
diff --git a/test/py/tests/test_vpl.py b/test/py/tests/test_vpl.py
index 4af578b9173..a269c7c262e 100644
--- a/test/py/tests/test_vpl.py
+++ b/test/py/tests/test_vpl.py
@@ -5,7 +5,7 @@
import os.path
import pytest
-def test_vpl(u_boot_console, ut_vpl_subtest):
+def test_vpl(ubman, ut_vpl_subtest):
"""Execute a "ut" subtest.
The subtests are collected in function generate_ut_subtest() from linker
@@ -19,16 +19,15 @@ def test_vpl(u_boot_console, ut_vpl_subtest):
implemented in C function foo_test_bar().
Args:
- u_boot_console (ConsoleBase): U-Boot console
+ ubman (ConsoleBase): U-Boot console
ut_subtest (str): VPL test to be executed (e.g. 'dm platdata_phandle')
"""
try:
- cons = u_boot_console
- cons.restart_uboot_with_flags(['-u', '-k', ut_vpl_subtest.split()[1]])
- output = cons.get_spawn_output().replace('\r', '')
- assert 'Failures: 0' in output
+ ubman.restart_uboot_with_flags(['-u', '-k', ut_vpl_subtest.split()[1]])
+ output = ubman.get_spawn_output().replace('\r', '')
+ assert 'failures: 0' in output
finally:
# Restart afterward in case a non-VPL test is run next. This should not
# happen since VPL tests are run in their own invocation of test.py, but
# the cost of doing this is not too great at present.
- u_boot_console.restart_uboot()
+ ubman.restart_uboot()
diff --git a/test/py/tests/test_xxd.py b/test/py/tests/test_xxd.py
new file mode 100644
index 00000000000..c457c54146c
--- /dev/null
+++ b/test/py/tests/test_xxd.py
@@ -0,0 +1,40 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+""" Unit test for xxd command
+"""
+
+import pytest
+from subprocess import call, check_call, CalledProcessError
+from tests import fs_helper
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_xxd')
+def test_xxd(ubman):
+ """ Unit test for xxd
+
+ Args:
+ ubman -- U-Boot console
+ """
+ try:
+ scratch_dir = ubman.config.persistent_data_dir + '/scratch'
+
+ check_call('mkdir -p %s' % scratch_dir, shell=True)
+
+ with open(scratch_dir + '/hello', 'w', encoding = 'ascii') as file:
+ file.write('hello world\n\x00\x01\x02\x03\x04\x05')
+
+ xxd_data = fs_helper.mk_fs(ubman.config, 'vfat', 0x100000,
+ 'test_xxd', scratch_dir)
+ response = ubman.run_command_list([ f'host bind 0 {xxd_data}',
+ 'xxd host 0 hello'])
+
+ assert '00000000: 68 65 6c 6c 6f 20 77 6f 72 6c 64 0a 00 01 02 03 hello world.....\r\r\n' + \
+ '00000010: 04 05 ..' \
+ in response
+ except CalledProcessError as err:
+ pytest.skip('Preparing test_xxd image failed')
+ call('rm -f %s' % xxd_data, shell=True)
+ return
+ finally:
+ call('rm -rf %s' % scratch_dir, shell=True)
+ call('rm -f %s' % xxd_data, shell=True)
diff --git a/test/py/tests/test_xxd/conftest.py b/test/py/tests/test_xxd/conftest.py
deleted file mode 100644
index 47c7cce1aa9..00000000000
--- a/test/py/tests/test_xxd/conftest.py
+++ /dev/null
@@ -1,36 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0+
-
-"""Fixture for xxd command test
-"""
-
-import os
-import shutil
-from subprocess import check_call, CalledProcessError
-import pytest
-
-@pytest.fixture(scope='session')
-def xxd_data(u_boot_config):
- """Set up a file system to be used in xxd tests
-
- Args:
- u_boot_config -- U-Boot configuration.
- """
- mnt_point = u_boot_config.persistent_data_dir + '/test_xxd'
- image_path = u_boot_config.persistent_data_dir + '/xxd.img'
-
- try:
- os.mkdir(mnt_point, mode = 0o755)
-
- with open(mnt_point + '/hello', 'w', encoding = 'ascii') as file:
- file.write('hello world\n\x00\x01\x02\x03\x04\x05')
-
- check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}',
- shell=True)
-
- yield image_path
- except CalledProcessError:
- pytest.skip('Setup failed')
- finally:
- shutil.rmtree(mnt_point)
- if os.path.exists(image_path):
- os.remove(image_path)
diff --git a/test/py/tests/test_xxd/test_xxd.py b/test/py/tests/test_xxd/test_xxd.py
deleted file mode 100644
index 06b9cfc0003..00000000000
--- a/test/py/tests/test_xxd/test_xxd.py
+++ /dev/null
@@ -1,23 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0+
-
-""" Unit test for xxd command
-"""
-
-import pytest
-
-@pytest.mark.boardspec('sandbox')
-@pytest.mark.buildconfigspec('cmd_xxd')
-def test_xxd(u_boot_console, xxd_data):
- """ Unit test for xxd
-
- Args:
- u_boot_console -- U-Boot console
- xxd_data -- Path to the disk image used for testing.
- """
- response = u_boot_console.run_command_list([
- f'host bind 0 {xxd_data}',
- 'xxd host 0 hello'])
-
- assert '00000000: 68 65 6c 6c 6f 20 77 6f 72 6c 64 0a 00 01 02 03 hello world.....\r\r\n' + \
- '00000010: 04 05 ..' \
- in response
diff --git a/test/py/tests/test_zynq_secure.py b/test/py/tests/test_zynq_secure.py
index 0ee5aebc484..f066a03b182 100644
--- a/test/py/tests/test_zynq_secure.py
+++ b/test/py/tests/test_zynq_secure.py
@@ -3,7 +3,7 @@
import pytest
import re
-import u_boot_utils
+import utils
import test_net
"""
@@ -36,8 +36,8 @@ env__zynq_rsa_readable_file = {
}
"""
-def zynq_secure_pre_commands(u_boot_console):
- output = u_boot_console.run_command('print modeboot')
+def zynq_secure_pre_commands(ubman):
+ output = ubman.run_command('print modeboot')
if not 'modeboot=' in output:
pytest.skip('bootmode cannnot be determined')
m = re.search('modeboot=(.+?)boot', output)
@@ -48,8 +48,8 @@ def zynq_secure_pre_commands(u_boot_console):
pytest.skip('skipping due to jtag bootmode')
@pytest.mark.buildconfigspec('cmd_zynq_aes')
-def test_zynq_aes_image(u_boot_console):
- f = u_boot_console.config.env.get('env__zynq_aes_readable_file', None)
+def test_zynq_aes_image(ubman):
+ f = ubman.config.env.get('env__zynq_aes_readable_file', None)
if not f:
pytest.skip('No TFTP readable file for zynq secure aes case to read')
@@ -61,130 +61,130 @@ def test_zynq_aes_image(u_boot_console):
if not dstsize:
pytest.skip('No dstlen specified in env file to read')
- zynq_secure_pre_commands(u_boot_console)
- test_net.test_net_dhcp(u_boot_console)
+ zynq_secure_pre_commands(ubman)
+ test_net.test_net_dhcp(ubman)
if not test_net.net_set_up:
- test_net.test_net_setup_static(u_boot_console)
+ test_net.test_net_setup_static(ubman)
srcaddr = f.get('srcaddr', None)
if not srcaddr:
- addr = u_boot_utils.find_ram_base(u_boot_console)
+ addr = utils.find_ram_base(ubman)
expected_tftp = 'Bytes transferred = '
fn = f['fn']
- output = u_boot_console.run_command('tftpboot %x %s' % (srcaddr, fn))
+ output = ubman.run_command('tftpboot %x %s' % (srcaddr, fn))
assert expected_tftp in output
expected_op = 'zynq aes [operation type] <srcaddr>'
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'zynq aes %x $filesize %x %x' % (srcaddr, dstaddr, dstsize)
)
assert expected_op not in output
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_zynq_aes')
-def test_zynq_aes_bitstream(u_boot_console):
- f = u_boot_console.config.env.get('env__zynq_aes_readable_file', None)
+def test_zynq_aes_bitstream(ubman):
+ f = ubman.config.env.get('env__zynq_aes_readable_file', None)
if not f:
pytest.skip('No TFTP readable file for zynq secure aes case to read')
- zynq_secure_pre_commands(u_boot_console)
- test_net.test_net_dhcp(u_boot_console)
+ zynq_secure_pre_commands(ubman)
+ test_net.test_net_dhcp(ubman)
if not test_net.net_set_up:
- test_net.test_net_setup_static(u_boot_console)
+ test_net.test_net_setup_static(ubman)
srcaddr = f.get('srcaddr', None)
if not srcaddr:
- addr = u_boot_utils.find_ram_base(u_boot_console)
+ addr = utils.find_ram_base(ubman)
expected_tftp = 'Bytes transferred = '
fn = f['fnbit']
- output = u_boot_console.run_command('tftpboot %x %s' % (srcaddr, fn))
+ output = ubman.run_command('tftpboot %x %s' % (srcaddr, fn))
assert expected_tftp in output
expected_op = 'zynq aes [operation type] <srcaddr>'
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'zynq aes load %x $filesize' % (srcaddr)
)
assert expected_op not in output
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_zynq_aes')
-def test_zynq_aes_partial_bitstream(u_boot_console):
- f = u_boot_console.config.env.get('env__zynq_aes_readable_file', None)
+def test_zynq_aes_partial_bitstream(ubman):
+ f = ubman.config.env.get('env__zynq_aes_readable_file', None)
if not f:
pytest.skip('No TFTP readable file for zynq secure aes case to read')
- zynq_secure_pre_commands(u_boot_console)
- test_net.test_net_dhcp(u_boot_console)
+ zynq_secure_pre_commands(ubman)
+ test_net.test_net_dhcp(ubman)
if not test_net.net_set_up:
- test_net.test_net_setup_static(u_boot_console)
+ test_net.test_net_setup_static(ubman)
srcaddr = f.get('srcaddr', None)
if not srcaddr:
- addr = u_boot_utils.find_ram_base(u_boot_console)
+ addr = utils.find_ram_base(ubman)
expected_tftp = 'Bytes transferred = '
fn = f['fnpbit']
- output = u_boot_console.run_command('tftpboot %x %s' % (srcaddr, fn))
+ output = ubman.run_command('tftpboot %x %s' % (srcaddr, fn))
assert expected_tftp in output
expected_op = 'zynq aes [operation type] <srcaddr>'
- output = u_boot_console.run_command('zynq aes loadp %x $filesize' % (srcaddr))
+ output = ubman.run_command('zynq aes loadp %x $filesize' % (srcaddr))
assert expected_op not in output
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_zynq_rsa')
-def test_zynq_rsa_image(u_boot_console):
- f = u_boot_console.config.env.get('env__zynq_rsa_readable_file', None)
+def test_zynq_rsa_image(ubman):
+ f = ubman.config.env.get('env__zynq_rsa_readable_file', None)
if not f:
pytest.skip('No TFTP readable file for zynq secure rsa case to read')
- zynq_secure_pre_commands(u_boot_console)
- test_net.test_net_dhcp(u_boot_console)
+ zynq_secure_pre_commands(ubman)
+ test_net.test_net_dhcp(ubman)
if not test_net.net_set_up:
- test_net.test_net_setup_static(u_boot_console)
+ test_net.test_net_setup_static(ubman)
srcaddr = f.get('srcaddr', None)
if not srcaddr:
- addr = u_boot_utils.find_ram_base(u_boot_console)
+ addr = utils.find_ram_base(ubman)
expected_tftp = 'Bytes transferred = '
fn = f['fn']
- output = u_boot_console.run_command('tftpboot %x %s' % (srcaddr, fn))
+ output = ubman.run_command('tftpboot %x %s' % (srcaddr, fn))
assert expected_tftp in output
expected_op = 'zynq rsa <baseaddr>'
- output = u_boot_console.run_command('zynq rsa %x ' % (srcaddr))
+ output = ubman.run_command('zynq rsa %x ' % (srcaddr))
assert expected_op not in output
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_zynq_rsa')
-def test_zynq_rsa_image_invalid(u_boot_console):
- f = u_boot_console.config.env.get('env__zynq_rsa_readable_file', None)
+def test_zynq_rsa_image_invalid(ubman):
+ f = ubman.config.env.get('env__zynq_rsa_readable_file', None)
if not f:
pytest.skip('No TFTP readable file for zynq secure rsa case to read')
- zynq_secure_pre_commands(u_boot_console)
- test_net.test_net_dhcp(u_boot_console)
+ zynq_secure_pre_commands(ubman)
+ test_net.test_net_dhcp(ubman)
if not test_net.net_set_up:
- test_net.test_net_setup_static(u_boot_console)
+ test_net.test_net_setup_static(ubman)
srcaddr = f.get('srcaddr', None)
if not srcaddr:
- addr = u_boot_utils.find_ram_base(u_boot_console)
+ addr = utils.find_ram_base(ubman)
expected_tftp = 'Bytes transferred = '
fninvalid = f['fninvalid']
- output = u_boot_console.run_command('tftpboot %x %s' % (srcaddr, fninvalid))
+ output = ubman.run_command('tftpboot %x %s' % (srcaddr, fninvalid))
assert expected_tftp in output
expected_op = 'zynq rsa <baseaddr>'
- output = u_boot_console.run_command('zynq rsa %x ' % (srcaddr))
+ output = ubman.run_command('zynq rsa %x ' % (srcaddr))
assert expected_op in output
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert not output.endswith('0')
diff --git a/test/py/tests/test_zynqmp_rpu.py b/test/py/tests/test_zynqmp_rpu.py
index 479a612b4ec..cda8c9203b7 100644
--- a/test/py/tests/test_zynqmp_rpu.py
+++ b/test/py/tests/test_zynqmp_rpu.py
@@ -33,8 +33,8 @@ env__zynqmp_rpu_apps = {
"""
# Get rpu apps params from env
-def get_rpu_apps_env(u_boot_console):
- rpu_apps = u_boot_console.config.env.get('env__zynqmp_rpu_apps', False)
+def get_rpu_apps_env(ubman):
+ rpu_apps = ubman.config.env.get('env__zynqmp_rpu_apps', False)
if not rpu_apps:
pytest.skip('ZynqMP RPU application info not defined!')
@@ -65,144 +65,158 @@ def get_rpu_apps_env(u_boot_console):
return apps, procs, cpu_nums, addrs, outputs, tftp_addrs
# Check return code
-def ret_code(u_boot_console):
- return u_boot_console.run_command('echo $?')
+def ret_code(ubman):
+ return ubman.run_command('echo $?')
# Initialize tcm
-def tcminit(u_boot_console, rpu_mode):
- output = u_boot_console.run_command('zynqmp tcminit %s' % rpu_mode)
+def tcminit(ubman, rpu_mode):
+ output = ubman.run_command(f'zynqmp tcminit {rpu_mode}')
assert 'Initializing TCM overwrites TCM content' in output
- return ret_code(u_boot_console)
+ return ret_code(ubman)
# Load application in DDR
-def load_app_ddr(u_boot_console, tftp_addr, app):
- output = u_boot_console.run_command('tftpboot %x %s' % (tftp_addr, app))
+def load_app_ddr(ubman, tftp_addr, app):
+ output = ubman.run_command('tftpboot %x %s' % (tftp_addr, app))
assert 'TIMEOUT' not in output
assert 'Bytes transferred = ' in output
# Load elf
- u_boot_console.run_command('bootelf -p %x' % tftp_addr)
- assert ret_code(u_boot_console).endswith('0')
+ ubman.run_command('bootelf -p %x' % tftp_addr)
+ assert ret_code(ubman).endswith('0')
# Disable cpus
-def disable_cpus(u_boot_console, cpu_nums):
+def disable_cpus(ubman, cpu_nums):
for num in cpu_nums:
- u_boot_console.run_command(f'cpu {num} disable')
+ ubman.run_command(f'cpu {num} disable')
+
+# Get random RPU mode between string and integer
+def get_rpu_mode(rpu_mode):
+ if rpu_mode == 0 or rpu_mode == 'lockstep':
+ return random.choice(['lockstep', 0])
+ elif rpu_mode == 1 or rpu_mode == 'split':
+ return random.choice(['split', 1])
# Load apps on RPU cores
-def rpu_apps_load(u_boot_console, rpu_mode):
+def rpu_apps_load(ubman, rpu_mode):
apps, procs, cpu_nums, addrs, outputs, tftp_addrs = get_rpu_apps_env(
- u_boot_console)
- test_net.test_net_dhcp(u_boot_console)
+ ubman)
+ test_net.test_net_dhcp(ubman)
if not test_net.net_set_up:
- test_net.test_net_setup_static(u_boot_console)
+ test_net.test_net_setup_static(ubman)
try:
- assert tcminit(u_boot_console, rpu_mode).endswith('0')
+ assert tcminit(ubman, get_rpu_mode(rpu_mode)).endswith('0')
for i in range(len(apps)):
if rpu_mode == 'lockstep' and procs[i] != 'rpu0':
continue
- load_app_ddr(u_boot_console, tftp_addrs[i], apps[i])
- rel_addr = int(addrs[i] + 0x3C)
+ load_app_ddr(ubman, tftp_addrs[i], apps[i])
+ rel_addr = hex(int(addrs[i] + 0x3C))
# Release cpu at app load address
cpu_num = cpu_nums[i]
- cmd = 'cpu %d release %x %s' % (cpu_num, rel_addr, rpu_mode)
- output = u_boot_console.run_command(cmd)
- exp_op = f'Using TCM jump trampoline for address {hex(rel_addr)}'
+ cmd = f'cpu {cpu_num} release {rel_addr} {rpu_mode}'
+ output = ubman.run_command(cmd)
+ exp_op = f'Using TCM jump trampoline for address {rel_addr}'
assert exp_op in output
assert f'R5 {rpu_mode} mode' in output
- u_boot_console.wait_for(outputs[i])
- assert ret_code(u_boot_console).endswith('0')
+ ubman.wait_for(outputs[i])
+ assert ret_code(ubman).endswith('0')
finally:
- disable_cpus(u_boot_console, cpu_nums)
+ disable_cpus(ubman, cpu_nums)
@pytest.mark.buildconfigspec('cmd_zynqmp')
-def test_zynqmp_rpu_app_load_split(u_boot_console):
- rpu_apps_load(u_boot_console, 'split')
+def test_zynqmp_rpu_app_load_split(ubman):
+ rpu_apps_load(ubman, 'split')
@pytest.mark.buildconfigspec('cmd_zynqmp')
-def test_zynqmp_rpu_app_load_lockstep(u_boot_console):
- rpu_apps_load(u_boot_console, 'lockstep')
+def test_zynqmp_rpu_app_load_lockstep(ubman):
+ rpu_apps_load(ubman, 'lockstep')
@pytest.mark.buildconfigspec('cmd_zynqmp')
-def test_zynqmp_rpu_app_load_negative(u_boot_console):
+def test_zynqmp_rpu_app_load_negative(ubman):
apps, procs, cpu_nums, addrs, outputs, tftp_addrs = get_rpu_apps_env(
- u_boot_console)
+ ubman)
# Invalid commands
- u_boot_console.run_command('zynqmp tcminit mode')
- assert ret_code(u_boot_console).endswith('1')
-
rand_str = ''.join(random.choices(string.ascii_lowercase, k=4))
- u_boot_console.run_command('zynqmp tcminit %s' % rand_str)
- assert ret_code(u_boot_console).endswith('1')
-
rand_num = random.randint(2, 100)
- u_boot_console.run_command('zynqmp tcminit %d' % rand_num)
- assert ret_code(u_boot_console).endswith('1')
+ inv_modes = ['mode', rand_str, rand_num, 'splittt', 'locksteppp', '00', 11]
- test_net.test_net_dhcp(u_boot_console)
+ for mode in inv_modes:
+ ubman.run_command(f'zynqmp tcminit {mode}')
+ assert ret_code(ubman).endswith('1')
+
+ test_net.test_net_dhcp(ubman)
if not test_net.net_set_up:
- test_net.test_net_setup_static(u_boot_console)
+ test_net.test_net_setup_static(ubman)
try:
rpu_mode = 'split'
- assert tcminit(u_boot_console, rpu_mode).endswith('0')
+ assert tcminit(ubman, get_rpu_mode(rpu_mode)).endswith('0')
+ inv_modes += [0, 1]
for i in range(len(apps)):
- load_app_ddr(u_boot_console, tftp_addrs[i], apps[i])
+ load_app_ddr(ubman, tftp_addrs[i], apps[i])
# Run in split mode at different load address
- rel_addr = int(addrs[i]) + random.randint(200, 1000)
+ rel_addr = hex(int(addrs[i]) + random.randint(200, 1000))
cpu_num = cpu_nums[i]
- cmd = 'cpu %d release %x %s' % (cpu_num, rel_addr, rpu_mode)
- output = u_boot_console.run_command(cmd)
- exp_op = f'Using TCM jump trampoline for address {hex(rel_addr)}'
+ cmd = f'cpu {cpu_num} release {rel_addr} {rpu_mode}'
+ output = ubman.run_command(cmd)
+ exp_op = f'Using TCM jump trampoline for address {rel_addr}'
assert exp_op in output
assert f'R5 {rpu_mode} mode' in output
assert not outputs[i] in output
# Invalid rpu mode
- rand_str = ''.join(random.choices(string.ascii_lowercase, k=4))
- cmd = 'cpu %d release %x %s' % (cpu_num, rel_addr, rand_str)
- output = u_boot_console.run_command(cmd)
- assert exp_op in output
- assert f'Unsupported mode' in output
- assert not ret_code(u_boot_console).endswith('0')
+ for mode in inv_modes:
+ cmd = f'cpu {cpu_num} release {rel_addr} {mode}'
+ output = ubman.run_command(cmd)
+ assert exp_op in output
+ assert f'Unsupported mode' in output
+ assert not ret_code(ubman).endswith('0')
# Switch to lockstep mode, without disabling CPUs
rpu_mode = 'lockstep'
- u_boot_console.run_command('zynqmp tcminit %s' % rpu_mode)
- assert not ret_code(u_boot_console).endswith('0')
+ output = ubman.run_command(
+ f'zynqmp tcminit {get_rpu_mode(rpu_mode)}'
+ )
+ assert 'ERROR: ' in output
# Disable cpus
- disable_cpus(u_boot_console, cpu_nums)
+ disable_cpus(ubman, cpu_nums)
# Switch to lockstep mode, after disabling CPUs
- output = u_boot_console.run_command('zynqmp tcminit %s' % rpu_mode)
+ output = ubman.run_command(
+ f'zynqmp tcminit {get_rpu_mode(rpu_mode)}'
+ )
assert 'Initializing TCM overwrites TCM content' in output
- assert ret_code(u_boot_console).endswith('0')
+ assert ret_code(ubman).endswith('0')
- # Run lockstep mode for RPU1
+ # Run lockstep mode for RPU1/RPU0
for i in range(len(apps)):
- if procs[i] == 'rpu0':
- continue
-
- load_app_ddr(u_boot_console, tftp_addrs[i], apps[i])
- rel_addr = int(addrs[i] + 0x3C)
+ load_app_ddr(ubman, tftp_addrs[i], apps[i])
+ rel_addr = hex(int(addrs[i] + 0x3C))
cpu_num = cpu_nums[i]
- cmd = 'cpu %d release %x %s' % (cpu_num, rel_addr, rpu_mode)
- output = u_boot_console.run_command(cmd)
- exp_op = f'Using TCM jump trampoline for address {hex(rel_addr)}'
+ cmd = f'cpu {cpu_num} release {rel_addr} {rpu_mode}'
+ output = ubman.run_command(cmd)
+ exp_op = f'Using TCM jump trampoline for address {rel_addr}'
assert exp_op in output
- assert f'R5 {rpu_mode} mode' in output
- assert u_boot_console.p.expect([outputs[i]])
+
+ if procs[i] == 'rpu1':
+ assert 'Lockstep mode should run on ZYNQMP_CORE_RPU0' in output
+ assert not ret_code(ubman).endswith('0')
+ elif procs[i] == 'rpu0':
+ assert f'R5 {rpu_mode} mode' in output
+ ubman.wait_for(outputs[i])
+ assert ret_code(ubman).endswith('0')
+ else:
+ assert False, 'ERROR: Invalid processor!'
finally:
- disable_cpus(u_boot_console, cpu_nums)
+ disable_cpus(ubman, cpu_nums)
# This forces the console object to be shutdown, so any subsequent test
# will reset the board back into U-Boot.
- u_boot_console.drain_console()
- u_boot_console.cleanup_spawn()
+ ubman.drain_console()
+ ubman.cleanup_spawn()
diff --git a/test/py/tests/test_zynqmp_secure.py b/test/py/tests/test_zynqmp_secure.py
index 570bd2439c1..c057e36383f 100644
--- a/test/py/tests/test_zynqmp_secure.py
+++ b/test/py/tests/test_zynqmp_secure.py
@@ -3,7 +3,7 @@
import pytest
import re
-import u_boot_utils
+import utils
import test_net
"""
@@ -30,75 +30,75 @@ env__zynqmp_secure_readable_file = {
"""
@pytest.mark.buildconfigspec('cmd_zynqmp')
-def test_zynqmp_secure_boot_image(u_boot_console):
+def test_zynqmp_secure_boot_image(ubman):
"""This test verifies secure boot image at the DDR address for
authentication only case.
"""
- f = u_boot_console.config.env.get('env__zynqmp_secure_readable_file', None)
+ f = ubman.config.env.get('env__zynqmp_secure_readable_file', None)
if not f:
pytest.skip('No TFTP readable file for zynqmp secure cases to read')
- test_net.test_net_dhcp(u_boot_console)
+ test_net.test_net_dhcp(ubman)
if not test_net.net_set_up:
- test_net.test_net_setup_static(u_boot_console)
+ test_net.test_net_setup_static(ubman)
addr = f.get('addr', None)
if not addr:
- addr = u_boot_utils.find_ram_base(u_boot_console)
+ addr = utils.find_ram_base(ubman)
expected_tftp = 'Bytes transferred = '
fn = f['fn']
- output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn))
+ output = ubman.run_command('tftpboot %x %s' % (addr, fn))
assert expected_tftp in output
- output = u_boot_console.run_command('zynqmp secure %x $filesize' % (addr))
+ output = ubman.run_command('zynqmp secure %x $filesize' % (addr))
assert 'Verified image at' in output
ver_addr = re.search(r'Verified image at 0x(.+)', output).group(1)
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
- output = u_boot_console.run_command('print zynqmp_verified_img_addr')
+ output = ubman.run_command('print zynqmp_verified_img_addr')
assert f'zynqmp_verified_img_addr={ver_addr}' in output
assert 'Error' not in output
@pytest.mark.buildconfigspec('cmd_zynqmp')
-def test_zynqmp_secure_boot_img_kup(u_boot_console):
+def test_zynqmp_secure_boot_img_kup(ubman):
"""This test verifies secure boot image at the DDR address for encryption
with kup key case.
"""
- f = u_boot_console.config.env.get('env__zynqmp_secure_readable_file', None)
+ f = ubman.config.env.get('env__zynqmp_secure_readable_file', None)
if not f:
pytest.skip('No TFTP readable file for zynqmp secure cases to read')
- test_net.test_net_dhcp(u_boot_console)
+ test_net.test_net_dhcp(ubman)
if not test_net.net_set_up:
- test_net.test_net_setup_static(u_boot_console)
+ test_net.test_net_setup_static(ubman)
keyaddr = f.get('keyaddr', None)
if not keyaddr:
- addr = u_boot_utils.find_ram_base(u_boot_console)
+ addr = utils.find_ram_base(ubman)
expected_tftp = 'Bytes transferred = '
keyfn = f['keyfn']
- output = u_boot_console.run_command('tftpboot %x %s' % (keyaddr, keyfn))
+ output = ubman.run_command('tftpboot %x %s' % (keyaddr, keyfn))
assert expected_tftp in output
addr = f.get('addr', None)
if not addr:
- addr = u_boot_utils.find_ram_base(u_boot_console)
+ addr = utils.find_ram_base(ubman)
expected_tftp = 'Bytes transferred = '
fn = f['enckupfn']
- output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn))
+ output = ubman.run_command('tftpboot %x %s' % (addr, fn))
assert expected_tftp in output
- output = u_boot_console.run_command(
+ output = ubman.run_command(
'zynqmp secure %x $filesize %x' % (addr, keyaddr)
)
assert 'Verified image at' in output
ver_addr = re.search(r'Verified image at 0x(.+)', output).group(1)
- output = u_boot_console.run_command('echo $?')
+ output = ubman.run_command('echo $?')
assert output.endswith('0')
- output = u_boot_console.run_command('print zynqmp_verified_img_addr')
+ output = ubman.run_command('print zynqmp_verified_img_addr')
assert f'zynqmp_verified_img_addr={ver_addr}' in output
assert 'Error' not in output
diff --git a/test/py/u_boot_utils.py b/test/py/utils.py
index 9e161fbc238..ca80e4b0b0a 100644
--- a/test/py/u_boot_utils.py
+++ b/test/py/utils.py
@@ -55,7 +55,7 @@ class PersistentRandomFile:
"""Generate and store information about a persistent file containing
random data."""
- def __init__(self, u_boot_console, fn, size):
+ def __init__(self, ubman, fn, size):
"""Create or process the persistent file.
If the file does not exist, it is generated.
@@ -66,7 +66,7 @@ class PersistentRandomFile:
the current test run.
Args:
- u_boot_console: A console connection to U-Boot.
+ ubman: A console connection to U-Boot.
fn: The filename (without path) to create.
size: The desired size of the file in bytes.
@@ -76,14 +76,14 @@ class PersistentRandomFile:
self.fn = fn
- self.abs_fn = u_boot_console.config.persistent_data_dir + '/' + fn
+ self.abs_fn = ubman.config.persistent_data_dir + '/' + fn
if os.path.exists(self.abs_fn):
- u_boot_console.log.action('Persistent data file ' + self.abs_fn +
+ ubman.log.action('Persistent data file ' + self.abs_fn +
' already exists')
self.content_hash = md5sum_file(self.abs_fn)
else:
- u_boot_console.log.action('Generating ' + self.abs_fn +
+ ubman.log.action('Generating ' + self.abs_fn +
' (random, persistent, %d bytes)' % size)
data = os.urandom(size)
with open(self.abs_fn, 'wb') as fh:
@@ -157,11 +157,11 @@ def wait_until_file_open_fails(fn, ignore_errors):
return
raise Exception('File can still be opened')
-def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None, env=None):
+def run_and_log(ubman, cmd, ignore_errors=False, stdin=None, env=None):
"""Run a command and log its output.
Args:
- u_boot_console: A console connection to U-Boot.
+ ubman: A console connection to U-Boot.
cmd: The command to run, as an array of argv[], or a string.
If a string, note that it is split up so that quoted spaces
will not be preserved. E.g. "fred and" becomes ['"fred', 'and"']
@@ -177,25 +177,25 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None, env=None):
"""
if isinstance(cmd, str):
cmd = cmd.split()
- runner = u_boot_console.log.get_runner(cmd[0], sys.stdout)
+ runner = ubman.log.get_runner(cmd[0], sys.stdout)
output = runner.run(cmd, ignore_errors=ignore_errors, stdin=stdin, env=env)
runner.close()
return output
-def run_and_log_expect_exception(u_boot_console, cmd, retcode, msg):
+def run_and_log_expect_exception(ubman, cmd, retcode, msg):
"""Run a command that is expected to fail.
This runs a command and checks that it fails with the expected return code
and exception method. If not, an exception is raised.
Args:
- u_boot_console: A console connection to U-Boot.
+ ubman: A console connection to U-Boot.
cmd: The command to run, as an array of argv[].
retcode: Expected non-zero return code from the command.
msg: String that should be contained within the command's output.
"""
try:
- runner = u_boot_console.log.get_runner(cmd[0], sys.stdout)
+ runner = ubman.log.get_runner(cmd[0], sys.stdout)
runner.run(cmd)
except Exception:
assert retcode == runner.exit_status
@@ -207,7 +207,7 @@ def run_and_log_expect_exception(u_boot_console, cmd, retcode, msg):
runner.close()
ram_base = None
-def find_ram_base(u_boot_console):
+def find_ram_base(ubman):
"""Find the running U-Boot's RAM location.
Probe the running U-Boot to determine the address of the first bank
@@ -218,22 +218,22 @@ def find_ram_base(u_boot_console):
actively read once.
Args:
- u_boot_console: A console connection to U-Boot.
+ ubman: A console connection to U-Boot.
Returns:
The address of U-Boot's first RAM bank, as an integer.
"""
global ram_base
- if u_boot_console.config.buildconfig.get('config_cmd_bdi', 'n') != 'y':
+ if ubman.config.buildconfig.get('config_cmd_bdi', 'n') != 'y':
pytest.skip('bdinfo command not supported')
if ram_base == -1:
pytest.skip('Previously failed to find RAM bank start')
if ram_base is not None:
return ram_base
- with u_boot_console.log.section('find_ram_base'):
- response = u_boot_console.run_command('bdinfo')
+ with ubman.log.section('find_ram_base'):
+ response = ubman.run_command('bdinfo')
for l in response.split('\n'):
if '-> start' in l or 'memstart =' in l:
ram_base = int(l.split('=')[1].strip(), 16)
@@ -311,11 +311,11 @@ def persistent_file_helper(u_boot_log, filename):
statement
Usage:
- with persistent_file_helper(u_boot_console.log, filename):
+ with persistent_file_helper(ubman.log, filename):
code to generate the file, if it's missing.
Args:
- u_boot_log: u_boot_console.log.
+ u_boot_log: ubman.log.
filename: The filename of the generated file.
Returns:
@@ -324,11 +324,11 @@ def persistent_file_helper(u_boot_log, filename):
return PersistentFileHelperCtxMgr(u_boot_log, filename)
-def crc32(u_boot_console, address, count):
+def crc32(ubman, address, count):
"""Helper function used to compute the CRC32 value of a section of RAM.
Args:
- u_boot_console: A U-Boot console connection.
+ ubman: A U-Boot console connection.
address: Address where data starts.
count: Amount of data to use for calculation.
@@ -336,10 +336,10 @@ def crc32(u_boot_console, address, count):
CRC32 value
"""
- bcfg = u_boot_console.config.buildconfig
+ bcfg = ubman.config.buildconfig
has_cmd_crc32 = bcfg.get('config_cmd_crc32', 'n') == 'y'
assert has_cmd_crc32, 'Cannot compute crc32 without CONFIG_CMD_CRC32.'
- output = u_boot_console.run_command('crc32 %08x %x' % (address, count))
+ output = ubman.run_command('crc32 %08x %x' % (address, count))
m = re.search('==> ([0-9a-fA-F]{8})$', output)
assert m, 'CRC32 operation failed.'
diff --git a/test/stdint/int-types.c b/test/stdint/int-types.c
index f6d09e8643d..9051e32c7ce 100644
--- a/test/stdint/int-types.c
+++ b/test/stdint/int-types.c
@@ -1,4 +1,4 @@
-#include <common.h>
+#include <linux/types.h>
int test_types(void)
{
diff --git a/test/test-main.c b/test/test-main.c
index b7015d9f38d..cabc736a524 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -4,7 +4,8 @@
* Written by Simon Glass <sjg@chromium.org>
*/
-#include <common.h>
+#define LOG_CATEGORY LOGC_TEST
+
#include <blk.h>
#include <console.h>
#include <cyclic.h>
@@ -13,6 +14,8 @@
#include <net.h>
#include <of_live.h>
#include <os.h>
+#include <spl.h>
+#include <usb.h>
#include <dm/ofnode.h>
#include <dm/root.h>
#include <dm/test.h>
@@ -47,7 +50,7 @@ enum fdtchk_t {
static enum fdtchk_t fdt_action(void)
{
/* For sandbox SPL builds, do nothing */
- if (IS_ENABLED(CONFIG_SANDBOX) && IS_ENABLED(CONFIG_SPL_BUILD))
+ if (IS_ENABLED(CONFIG_SANDBOX) && IS_ENABLED(CONFIG_XPL_BUILD))
return FDTCHK_NONE;
/* Do a copy for sandbox (but only the U-Boot build, not SPL) */
@@ -61,16 +64,29 @@ static enum fdtchk_t fdt_action(void)
/* This is valid when a test is running, NULL otherwise */
static struct unit_test_state *cur_test_state;
-struct unit_test_state *test_get_state(void)
+struct unit_test_state *ut_get_state(void)
{
return cur_test_state;
}
-void test_set_state(struct unit_test_state *uts)
+void ut_set_state(struct unit_test_state *uts)
{
cur_test_state = uts;
}
+void ut_init_state(struct unit_test_state *uts)
+{
+ memset(uts, '\0', sizeof(*uts));
+}
+
+void ut_uninit_state(struct unit_test_state *uts)
+{
+ if (IS_ENABLED(CONFIG_SANDBOX)) {
+ os_free(uts->fdt_copy);
+ os_free(uts->other_fdt);
+ }
+}
+
/**
* dm_test_pre_run() - Get ready to run a driver model test
*
@@ -182,7 +198,7 @@ static bool ut_test_run_on_flattree(struct unit_test *test)
{
const char *fname = strrchr(test->file, '/') + 1;
- if (!(test->flags & UT_TESTF_DM))
+ if (!(test->flags & UTF_DM))
return false;
return !strstr(fname, "video") || strstr(test->name, "video_base");
@@ -240,15 +256,22 @@ static bool test_matches(const char *prefix, const char *test_name,
* ut_list_has_dm_tests() - Check if a list of tests has driver model ones
*
* @tests: List of tests to run
- * @count: Number of tests to ru
- * Return: true if any of the tests have the UT_TESTF_DM flag
+ * @count: Number of tests to run
+ * @prefix: String prefix for the tests. Any tests that have this prefix will be
+ * printed without the prefix, so that it is easier to see the unique part
+ * of the test name. If NULL, no prefix processing is done
+ * @select_name: Name of a single test being run (from the list provided). If
+ * NULL all tests are being run
+ * Return: true if any of the tests have the UTF_DM flag
*/
-static bool ut_list_has_dm_tests(struct unit_test *tests, int count)
+static bool ut_list_has_dm_tests(struct unit_test *tests, int count,
+ const char *prefix, const char *select_name)
{
struct unit_test *test;
for (test = tests; test < tests + count; test++) {
- if (test->flags & UT_TESTF_DM)
+ if (test_matches(prefix, test->name, select_name) &&
+ (test->flags & UTF_DM))
return true;
}
@@ -290,26 +313,63 @@ static int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
{
ut_assertok(event_init());
- if (test->flags & UT_TESTF_DM)
+ /*
+ * Remove any USB keyboard, so that we can add and remove USB devices
+ * in tests.
+ *
+ * For UTF_DM tests, the old driver model state is saved and
+ * restored across each test. Within in each test there is therefore a
+ * new driver model state, which means that any USB keyboard device in
+ * stdio points to the old state.
+ *
+ * This is fine in most cases. But if a non-UTF_DM test starts up
+ * USB (thus creating a stdio record pointing to the USB keyboard
+ * device) then when the test finishes, the new driver model state is
+ * freed, meaning that there is now a stale pointer in stdio.
+ *
+ * This means that any future UTF_DM test which uses stdin will
+ * cause the console system to call tstc() on the stale device pointer,
+ * causing a crash.
+ *
+ * We don't want to fix this by enabling UTF_DM for all tests as
+ * this causes other problems. For example, bootflow_efi relies on
+ * U-Boot going through a proper init - without that we don't have the
+ * TCG measurement working and get an error
+ * 'tcg2 measurement fails(0x8000000000000007)'. Once we tidy up how EFI
+ * runs tests (e.g. get rid of all the restarting of U-Boot) we could
+ * potentially make the bootstd tests set UTF_DM, but other tests
+ * might do the same thing.
+ *
+ * We could add a test flag to declare that USB is being used, but that
+ * seems unnecessary, at least for now. We could detect USB being used
+ * in a test, but there is no obvious drawback to clearing out stale
+ * pointers always.
+ *
+ * So just remove any USB keyboards from the console tables. This allows
+ * UTF_DM and non-UTF_DM tests to coexist happily.
+ */
+ usb_kbd_remove_for_test();
+
+ if (test->flags & UTF_DM)
ut_assertok(dm_test_pre_run(uts));
ut_set_skip_delays(uts, false);
uts->start = mallinfo();
- if (test->flags & UT_TESTF_SCAN_PDATA)
+ if (test->flags & UTF_SCAN_PDATA)
ut_assertok(dm_scan_plat(false));
- if (test->flags & UT_TESTF_PROBE_TEST)
+ if (test->flags & UTF_PROBE_TEST)
ut_assertok(do_autoprobe(uts));
if (CONFIG_IS_ENABLED(OF_REAL) &&
- (test->flags & UT_TESTF_SCAN_FDT)) {
+ (test->flags & UTF_SCAN_FDT)) {
/*
* only set this if we know the ethernet uclass will be created
*/
- eth_set_enable_bootdevs(test->flags & UT_TESTF_ETH_BOOTDEV);
- test_sf_set_enable_bootdevs(test->flags & UT_TESTF_SF_BOOTDEV);
+ eth_set_enable_bootdevs(test->flags & UTF_ETH_BOOTDEV);
+ test_sf_set_enable_bootdevs(test->flags & UTF_SF_BOOTDEV);
ut_assertok(dm_extended_scan(false));
}
@@ -317,10 +377,10 @@ static int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
* Do this after FDT scan since dm_scan_other() in bootstd-uclass.c
* checks for the existence of bootstd
*/
- if (test->flags & UT_TESTF_SCAN_PDATA)
+ if (test->flags & UTF_SCAN_PDATA)
ut_assertok(dm_scan_other(false));
- if (IS_ENABLED(CONFIG_SANDBOX) && (test->flags & UT_TESTF_OTHER_FDT)) {
+ if (IS_ENABLED(CONFIG_SANDBOX) && (test->flags & UTF_OTHER_FDT)) {
/* make sure the other FDT is available */
ut_assertok(test_load_other_fdt(uts));
@@ -334,7 +394,7 @@ static int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
}
}
- if (test->flags & UT_TESTF_CONSOLE_REC) {
+ if (test->flags & UTF_CONSOLE) {
int ret = console_record_reset_enable();
if (ret) {
@@ -342,6 +402,12 @@ static int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
return -EAGAIN;
}
}
+ if (test->flags & UFT_BLOBLIST) {
+ log_debug("save bloblist %p\n", gd_bloblist());
+ uts->old_bloblist = gd_bloblist();
+ gd_set_bloblist(NULL);
+ }
+
ut_silence_console(uts);
return 0;
@@ -357,7 +423,7 @@ static int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
static int test_post_run(struct unit_test_state *uts, struct unit_test *test)
{
ut_unsilence_console(uts);
- if (test->flags & UT_TESTF_DM)
+ if (test->flags & UTF_DM)
ut_assertok(dm_test_post_run(uts));
ut_assertok(cyclic_unregister_all());
ut_assertok(event_uninit());
@@ -365,6 +431,11 @@ static int test_post_run(struct unit_test_state *uts, struct unit_test *test)
free(uts->of_other);
uts->of_other = NULL;
+ if (test->flags & UFT_BLOBLIST) {
+ gd_set_bloblist(uts->old_bloblist);
+ log_debug("restore bloblist %p\n", gd_bloblist());
+ }
+
blkcache_free();
return 0;
@@ -378,7 +449,7 @@ static int test_post_run(struct unit_test_state *uts, struct unit_test *test)
*/
static int skip_test(struct unit_test_state *uts)
{
- uts->skip_count++;
+ uts->cur.skip_count++;
return -EAGAIN;
}
@@ -390,7 +461,7 @@ static int skip_test(struct unit_test_state *uts)
* the name of each test before running it.
*
* @uts: Test state to update. The caller should ensure that this is zeroed for
- * the first call to this function. On exit, @uts->fail_count is
+ * the first call to this function. On exit, @uts->cur.fail_count is
* incremented by the number of failures (0, one hopes)
* @test_name: Test to run
* @name: Name of test, possibly skipping a prefix that should not be displayed
@@ -404,12 +475,12 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
const char *note = "";
int ret;
- if ((test->flags & UT_TESTF_DM) && !uts->of_live)
+ if ((test->flags & UTF_DM) && !uts->of_live)
note = " (flat tree)";
printf("Test: %s: %s%s\n", test_name, fname, note);
/* Allow access to test state from drivers */
- test_set_state(uts);
+ ut_set_state(uts);
ret = test_pre_run(uts, test);
if (ret == -EAGAIN)
@@ -425,7 +496,7 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
if (ret)
return ret;
- test_set_state( NULL);
+ ut_set_state(NULL);
return 0;
}
@@ -440,27 +511,31 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
* SPL.
*
* @uts: Test state to update. The caller should ensure that this is zeroed for
- * the first call to this function. On exit, @uts->fail_count is
+ * the first call to this function. On exit, @uts->cur.fail_count is
* incremented by the number of failures (0, one hopes)
* @test: Test to run
+ * @leaf: Part of the name to show, or NULL to use test->name
* Return: 0 if all tests passed, -EAGAIN if the test should be skipped, -1 if
* any failed
*/
static int ut_run_test_live_flat(struct unit_test_state *uts,
- struct unit_test *test)
+ struct unit_test *test, const char *leaf)
{
- int runs;
+ int runs, ret;
- if ((test->flags & UT_TESTF_OTHER_FDT) && !IS_ENABLED(CONFIG_SANDBOX))
+ if ((test->flags & UTF_OTHER_FDT) && !IS_ENABLED(CONFIG_SANDBOX))
return skip_test(uts);
/* Run with the live tree if possible */
runs = 0;
if (CONFIG_IS_ENABLED(OF_LIVE)) {
- if (!(test->flags & UT_TESTF_FLAT_TREE)) {
+ if (!(test->flags & UTF_FLAT_TREE)) {
uts->of_live = true;
- ut_assertok(ut_run_test(uts, test, test->name));
- runs++;
+ ret = ut_run_test(uts, test, leaf ?: test->name);
+ if (ret != -EAGAIN) {
+ ut_assertok(ret);
+ runs++;
+ }
}
}
@@ -477,15 +552,18 @@ static int ut_run_test_live_flat(struct unit_test_state *uts,
* boards)
*/
if ((!CONFIG_IS_ENABLED(OF_LIVE) ||
- (test->flags & UT_TESTF_SCAN_FDT)) &&
- !(test->flags & UT_TESTF_LIVE_TREE) &&
+ (test->flags & UTF_SCAN_FDT)) &&
+ !(test->flags & UTF_LIVE_TREE) &&
(CONFIG_IS_ENABLED(OFNODE_MULTI_TREE) ||
- !(test->flags & UT_TESTF_OTHER_FDT)) &&
+ !(test->flags & UTF_OTHER_FDT)) &&
(!runs || ut_test_run_on_flattree(test)) &&
!(gd->flags & GD_FLG_FDT_CHANGED)) {
uts->of_live = false;
- ut_assertok(ut_run_test(uts, test, test->name));
- runs++;
+ ret = ut_run_test(uts, test, leaf ?: test->name);
+ if (ret != -EAGAIN) {
+ ut_assertok(ret);
+ runs++;
+ }
}
return 0;
@@ -498,7 +576,7 @@ static int ut_run_test_live_flat(struct unit_test_state *uts,
* the name of each test before running it.
*
* @uts: Test state to update. The caller should ensure that this is zeroed for
- * the first call to this function. On exit, @uts->fail_count is
+ * the first call to this function. On exit, @uts->cur.fail_count is
* incremented by the number of failures (0, one hopes)
* @prefix: String prefix for the tests. Any tests that have this prefix will be
* printed without the prefix, so that it is easier to see the unique part
@@ -507,6 +585,9 @@ static int ut_run_test_live_flat(struct unit_test_state *uts,
* @count: Number of tests to run
* @select_name: Name of a single test to run (from the list provided). If NULL
* then all tests are run
+ * @test_insert: String describing a test to run after n other tests run, in the
+ * format n:name where n is the number of tests to run before this one and
+ * name is the name of the test to run
* Return: 0 if all tests passed, -ENOENT if test @select_name was not found,
* -EBADF if any failed
*/
@@ -514,6 +595,7 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
struct unit_test *tests, int count,
const char *select_name, const char *test_insert)
{
+ int prefix_len = prefix ? strlen(prefix) : 0;
struct unit_test *test, *one;
int found = 0;
int pos = 0;
@@ -538,10 +620,11 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
const char *test_name = test->name;
int ret, i, old_fail_count;
- if (!test_matches(prefix, test_name, select_name))
+ if (!(test->flags & (UTF_INIT | UTF_UNINIT)) &&
+ !test_matches(prefix, test_name, select_name))
continue;
- if (test->flags & UT_TESTF_MANUAL) {
+ if (test->flags & UTF_MANUAL) {
int len;
/*
@@ -551,36 +634,39 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
*/
len = strlen(test_name);
if (len < 6 || strcmp(test_name + len - 6, "_norun")) {
- printf("Test %s is manual so must have a name ending in _norun\n",
+ printf("Test '%s' is manual so must have a name ending in _norun\n",
test_name);
- uts->fail_count++;
+ uts->cur.fail_count++;
return -EBADF;
}
if (!uts->force_run) {
- if (select_name) {
- printf("Test %s skipped as it is manual (use -f to run it)\n",
- test_name);
- }
+ printf("Test: %s: skipped as it is manual (use -f to run it)\n",
+ test_name);
continue;
}
}
- old_fail_count = uts->fail_count;
+ old_fail_count = uts->cur.fail_count;
+ uts->cur.test_count++;
if (one && upto == pos) {
- ret = ut_run_test_live_flat(uts, one);
- if (uts->fail_count != old_fail_count) {
- printf("Test %s failed %d times (position %d)\n",
+ ret = ut_run_test_live_flat(uts, one, NULL);
+ if (uts->cur.fail_count != old_fail_count) {
+ printf("Test '%s' failed %d times (position %d)\n",
one->name,
- uts->fail_count - old_fail_count, pos);
+ uts->cur.fail_count - old_fail_count,
+ pos);
}
return -EBADF;
}
+ if (prefix_len && !strncmp(test_name, prefix, prefix_len))
+ test_name = test_name + prefix_len;
+
for (i = 0; i < uts->runs_per_test; i++)
- ret = ut_run_test_live_flat(uts, test);
- if (uts->fail_count != old_fail_count) {
- printf("Test %s failed %d times\n", select_name,
- uts->fail_count - old_fail_count);
+ ret = ut_run_test_live_flat(uts, test, test_name);
+ if (uts->cur.fail_count != old_fail_count) {
+ printf("Test '%s' failed %d times\n", test_name,
+ uts->cur.fail_count - old_fail_count);
}
found++;
if (ret == -EAGAIN)
@@ -591,23 +677,50 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
if (select_name && !found)
return -ENOENT;
- return uts->fail_count ? -EBADF : 0;
+ return uts->cur.fail_count ? -EBADF : 0;
+}
+
+void ut_report(struct ut_stats *stats, int run_count)
+{
+ if (run_count > 1)
+ printf("Suites run: %d, total tests", run_count);
+ else
+ printf("Tests");
+ printf(" run: %d, ", stats->test_count);
+ if (stats && stats->test_count) {
+ ulong dur = stats->duration_ms;
+
+ printf("%ld ms, average: %ld ms, ", dur,
+ dur ? dur / stats->test_count : 0);
+ }
+ if (stats->skip_count)
+ printf("skipped: %d, ", stats->skip_count);
+ printf("failures: %d\n", stats->fail_count);
}
-int ut_run_list(const char *category, const char *prefix,
- struct unit_test *tests, int count, const char *select_name,
- int runs_per_test, bool force_run, const char *test_insert)
+int ut_run_list(struct unit_test_state *uts, const char *category,
+ const char *prefix, struct unit_test *tests, int count,
+ const char *select_name, int runs_per_test, bool force_run,
+ const char *test_insert)
{
- struct unit_test_state uts = { .fail_count = 0 };
+ ;
bool has_dm_tests = false;
+ ulong start_offset = 0;
+ ulong test_offset = 0;
int ret;
+ memset(&uts->cur, '\0', sizeof(struct ut_stats));
+ if (CONFIG_IS_ENABLED(UNIT_TEST_DURATION)) {
+ uts->cur.start = get_timer(0);
+ start_offset = timer_test_get_offset();
+ }
+
if (!CONFIG_IS_ENABLED(OF_PLATDATA) &&
- ut_list_has_dm_tests(tests, count)) {
+ ut_list_has_dm_tests(tests, count, prefix, select_name)) {
has_dm_tests = true;
/*
* If we have no device tree, or it only has a root node, then
- * these * tests clearly aren't going to work...
+ * these tests clearly aren't going to work...
*/
if (!gd->fdt_blob || fdt_next_node(gd->fdt_blob, 0, NULL) < 0) {
puts("Please run with test device tree:\n"
@@ -619,35 +732,39 @@ int ut_run_list(const char *category, const char *prefix,
if (!select_name)
printf("Running %d %s tests\n", count, category);
- uts.of_root = gd_of_root();
- uts.runs_per_test = runs_per_test;
+ uts->of_root = gd_of_root();
+ uts->runs_per_test = runs_per_test;
if (fdt_action() == FDTCHK_COPY && gd->fdt_blob) {
- uts.fdt_size = fdt_totalsize(gd->fdt_blob);
- uts.fdt_copy = os_malloc(uts.fdt_size);
- if (!uts.fdt_copy) {
+ uts->fdt_size = fdt_totalsize(gd->fdt_blob);
+ uts->fdt_copy = os_malloc(uts->fdt_size);
+ if (!uts->fdt_copy) {
printf("Out of memory for device tree copy\n");
return -ENOMEM;
}
- memcpy(uts.fdt_copy, gd->fdt_blob, uts.fdt_size);
+ memcpy(uts->fdt_copy, gd->fdt_blob, uts->fdt_size);
}
- uts.force_run = force_run;
- ret = ut_run_tests(&uts, prefix, tests, count, select_name,
+ uts->force_run = force_run;
+ ret = ut_run_tests(uts, prefix, tests, count, select_name,
test_insert);
/* Best efforts only...ignore errors */
if (has_dm_tests)
- dm_test_restore(uts.of_root);
- if (IS_ENABLED(CONFIG_SANDBOX)) {
- os_free(uts.fdt_copy);
- os_free(uts.other_fdt);
- }
+ dm_test_restore(uts->of_root);
- if (uts.skip_count)
- printf("Skipped: %d, ", uts.skip_count);
if (ret == -ENOENT)
printf("Test '%s' not found\n", select_name);
- else
- printf("Failures: %d\n", uts.fail_count);
+ if (CONFIG_IS_ENABLED(UNIT_TEST_DURATION)) {
+ test_offset = timer_test_get_offset() - start_offset;
+
+ uts->cur.duration_ms = get_timer(uts->cur.start) - test_offset;
+ }
+ ut_report(&uts->cur, 1);
+
+ uts->total.skip_count += uts->cur.skip_count;
+ uts->total.fail_count += uts->cur.fail_count;
+ uts->total.test_count += uts->cur.test_count;
+ uts->total.duration_ms += uts->cur.duration_ms;
+ uts->run_count++;
return ret;
}
diff --git a/test/trace/test-trace.sh b/test/trace/test-trace.sh
deleted file mode 100755
index 5130b2bf017..00000000000
--- a/test/trace/test-trace.sh
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/bin/bash
-# SPDX-License-Identifier: GPL-2.0+
-# Copyright (c) 2013 The Chromium OS Authors.
-#
-
-# Simple test script for tracing with sandbox
-
-TRACE_OPT="FTRACE=1"
-
-BASE="$(dirname $0)/.."
-. $BASE/common.sh
-
-run_trace() {
- echo "Run trace"
- ./${OUTPUT_DIR}/u-boot <<END
-trace stats
-hash sha256 0 10000
-trace pause
-trace stats
-hash sha256 0 10000
-trace stats
-trace resume
-hash sha256 0 10000
-trace pause
-trace stats
-reset
-END
-}
-
-check_results() {
- echo "Check results"
-
- # Expect sha256 to run 3 times, so we see the string 6 times
- if [ $(grep -c sha256 ${tmp}) -ne 6 ]; then
- fail "sha256 error"
- fi
-
- # 4 sets of results (output of 'trace stats')
- if [ $(grep -c "traced function calls" ${tmp}) -ne 4 ]; then
- fail "trace output error"
- fi
-
- # Check trace counts. We expect to see an increase in the number of
- # traced function calls between each 'trace stats' command, except
- # between calls 2 and 3, where tracing is paused.
- # This code gets the sign of the difference between each number and
- # its predecessor.
- counts="$(tr -d ',\r' <${tmp} | awk \
- '/traced function calls/ { diff = $1 - upto; upto = $1; \
- printf "%d ", diff < 0 ? -1 : (diff > 0 ? 1 : 0)}')"
-
- if [ "${counts}" != "1 1 0 1 " ]; then
- fail "trace collection error: ${counts}"
- fi
-}
-
-echo "Simple trace test / sanity check using sandbox"
-echo
-tmp="$(tempfile)"
-build_uboot "${TRACE_OPT}"
-run_trace >${tmp}
-check_results ${tmp}
-rm ${tmp}
-echo "Test passed"
diff --git a/test/ut.c b/test/ut.c
index 628e9dc9805..a16fdfb3a93 100644
--- a/test/ut.c
+++ b/test/ut.c
@@ -5,7 +5,6 @@
* Copyright (c) 2013 Google, Inc
*/
-#include <common.h>
#include <console.h>
#include <malloc.h>
#ifdef CONFIG_SANDBOX
@@ -22,7 +21,7 @@ void ut_fail(struct unit_test_state *uts, const char *fname, int line,
{
gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
printf("%s:%d, %s(): %s\n", fname, line, func, cond);
- uts->fail_count++;
+ uts->cur.fail_count++;
}
void ut_failf(struct unit_test_state *uts, const char *fname, int line,
@@ -36,7 +35,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
vprintf(fmt, args);
va_end(args);
putc('\n');
- uts->fail_count++;
+ uts->cur.fail_count++;
}
ulong ut_check_free(void)
@@ -60,9 +59,11 @@ static int readline_check(struct unit_test_state *uts)
ut_fail(uts, __FILE__, __LINE__, __func__,
"Console record buffer too small - increase CONFIG_CONSOLE_RECORD_OUT_SIZE");
return ret;
+ } else if (ret == -ENOENT) {
+ strcpy(uts->actual_str, "<no-more-output>");
}
- return 0;
+ return ret;
}
int ut_check_console_line(struct unit_test_state *uts, const char *fmt, ...)
@@ -80,8 +81,8 @@ int ut_check_console_line(struct unit_test_state *uts, const char *fmt, ...)
return -EOVERFLOW;
}
ret = readline_check(uts);
- if (ret < 0)
- return ret;
+ if (ret == -ENOENT)
+ return 1;
return strcmp(uts->expect_str, uts->actual_str);
}