diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index 5314a8b2444..3f671dd078d 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -510,6 +510,12 @@ stages: qemu_riscv64_spl: TEST_PY_BD: "qemu-riscv64_spl" TEST_PY_TEST_SPEC: "not sleep" + qemu_riscv64_smode: + TEST_PY_BD: "qemu-riscv64_smode" + TEST_PY_TEST_SPEC: "not sleep" + qemu_riscv64_smode_acpi: + TEST_PY_BD: "qemu-riscv64_smode_acpi" + TEST_PY_TEST_SPEC: "not sleep" qemu_x86: TEST_PY_BD: "qemu-x86" TEST_PY_TEST_SPEC: "not sleep" diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 434945ce350..86d3c741ea1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -466,6 +466,18 @@ qemu-riscv64_spl test.py: TEST_PY_TEST_SPEC: "not sleep" <<: *buildman_and_testpy_dfn +qemu-riscv64_smode test.py: + variables: + TEST_PY_BD: "qemu-riscv64_smode" + TEST_PY_TEST_SPEC: "not sleep" + <<: *buildman_and_testpy_dfn + +qemu-riscv64_smode_acpi test.py: + variables: + TEST_PY_BD: "qemu-riscv64_smode_acpi" + TEST_PY_TEST_SPEC: "not sleep" + <<: *buildman_and_testpy_dfn + qemu-x86 test.py: variables: TEST_PY_BD: "qemu-x86" diff --git a/common/Kconfig b/common/Kconfig index 0c25a8fc866..47d17f4e7c6 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -26,7 +26,7 @@ config CONSOLE_RECORD_INIT_F config CONSOLE_RECORD_OUT_SIZE hex "Output buffer size" depends on CONSOLE_RECORD - default 0x400 if CONSOLE_RECORD + default 0x6000 help Set the size of the console recording output buffer. When this fills up, no more data will be recorded until some is removed. The buffer diff --git a/configs/qemu-riscv64_smode_acpi_defconfig b/configs/qemu-riscv64_smode_acpi_defconfig index e78e5ffb390..11592091443 100644 --- a/configs/qemu-riscv64_smode_acpi_defconfig +++ b/configs/qemu-riscv64_smode_acpi_defconfig @@ -1,2 +1,3 @@ #include #include +CONFIG_CONSOLE_RECORD=y diff --git a/doc/api/index.rst b/doc/api/index.rst index d97630e7671..44922a742c3 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -27,6 +27,7 @@ U-Boot API documentation serial setjmp sysreset + test timer unicode uthread diff --git a/doc/api/test.rst b/doc/api/test.rst new file mode 100644 index 00000000000..359cbd0617d --- /dev/null +++ b/doc/api/test.rst @@ -0,0 +1,11 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later +.. Copyright (c) 2025 Heinrich Schuchardt + +Test Framework +============== + +Assertions and reporting functions +---------------------------------- + +.. kernel-doc:: include/test/ut.h + :internal: diff --git a/doc/board/samsung/e850-96.rst b/doc/board/samsung/e850-96.rst index 2b66e6568fb..3174a7daff9 100644 --- a/doc/board/samsung/e850-96.rst +++ b/doc/board/samsung/e850-96.rst @@ -637,9 +637,14 @@ machine: `-- pxelinux.cfg `-- 01-02-36-f5-1c-81-13 - where ``'01-02-36-f5-1c-81-13'`` file contains extlinux configuration for - TFTP to load and boot. The name of this file is the Ethernet MAC address, - which can be looked up in the ``$ethaddr`` environment variable in U-Boot. + where ``'01-02-36-f5-1c-81-13'`` file contains extlinux configuration for TFTP + to load and boot. The name of this file has to be in the format of + ``'01-MAC-address'``. The Ethernet MAC address in this case is + ``02-36-f5-1c-81-13``, and it can be looked up in the ``$ethaddr`` environment + variable in U-Boot:: + + => env print ethaddr + ethaddr=02:36:f5:1c:81:13 An example of such configuration file is:: @@ -667,11 +672,11 @@ machine: arch/arm64/configs/defconfig ---------------------------- - # Needed for boot from USB storage (mounting rootfs from USB drive) + # Keep USB PHY driver built-in, as the Ethernet controller sits on USB bus CONFIG_PHY_EXYNOS5_USBDRD=y CONFIG_TYPEC=y - # Needed for NFS boot + # Keep Ethernet driver built-in CONFIG_USB_NET_SMSC95XX=y CONFIG_USB_USBNET=y diff --git a/doc/board/ti/am6254atl_sk.rst b/doc/board/ti/am6254atl_sk.rst index 3219c86385d..cf58ed4c03f 100644 --- a/doc/board/ti/am6254atl_sk.rst +++ b/doc/board/ti/am6254atl_sk.rst @@ -60,7 +60,7 @@ Set the variables corresponding to this platform: export UBOOT_CFG_CORTEXR=am6254atl_evm_r5_defconfig export UBOOT_CFG_CORTEXA=am6254atl_evm_a53_defconfig export TFA_BOARD=lite - export TFA_EXTRA_ARGS="PRELOADED_BL33_BASE=0x81880000 BL32_BASE=0x80080000" + export TFA_EXTRA_ARGS="PRELOADED_BL33_BASE=0x82000000 BL32_BASE=0x80080000" export OPTEE_PLATFORM=k3-am62x export OPTEE_EXTRA_ARGS="CFG_TZDRAM_START=0x80080000" diff --git a/doc/board/ti/k3.rst b/doc/board/ti/k3.rst index fafef239e01..37a66b3c69d 100644 --- a/doc/board/ti/k3.rst +++ b/doc/board/ti/k3.rst @@ -184,7 +184,7 @@ online * **TI Firmware (TIFS, DM, SYSFW)** - | **source:** https://git.ti.com/git/processor-firmware/ti-linux-firmware.git + | **source:** https://github.com/TexasInstruments/ti-linux-firmware | **branch:** ti-linux-firmware .. note:: diff --git a/doc/develop/pytest/usage.rst b/doc/develop/pytest/usage.rst index 800a0323d0a..7335a39b963 100644 --- a/doc/develop/pytest/usage.rst +++ b/doc/develop/pytest/usage.rst @@ -392,7 +392,7 @@ to flash, pulsing the board's reset signal is likely all this script needs to do. However, in some scenarios, this script may perform other actions. For example, it may call out to some SoC- or board-specific vendor utility in order to download the U-Boot binary directly into RAM and execute it. This would -avoid the need for ``u-boot-test-flash1`` to actually write U-Boot to flash, +avoid the need for ``u-boot-test-flash`` to actually write U-Boot to flash, thus saving wear on the flash chip(s). u-boot-test-release diff --git a/doc/develop/tests_writing.rst b/doc/develop/tests_writing.rst index 062194659b5..1a020caa411 100644 --- a/doc/develop/tests_writing.rst +++ b/doc/develop/tests_writing.rst @@ -206,8 +206,44 @@ some common test tasks. (there are also UEFI C tests in lib/efi_selftest/ not considered here.) +Add a C test to an existing suite +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Use this when you are adding to or modifying an existing feature outside driver +model. An example is bloblist. + +Add a new function in the same file as the rest of the suite and register it +with the suite. For example, to add a new mem_search test:: + + /* Test 'ms' command with 32-bit values */ + static int mem_test_ms_new_thing(struct unit_test_state *uts) + { + /* test code here */ + + return 0; + } + MEM_TEST(mem_test_ms_new_thing, UTF_CONSOLE); + +Note that the MEM_TEST() macros is defined at the top of the file. + +Example commit: 9fe064646d2 ("bloblist: Support relocating to a larger space") [1] + +* A successful test returns 0. +* A skipped test returns -EAGAIN. +* Any other value signals a failure. + +Include ``test/ut.h`` defines a number of macros to check values and to return +from the test function if the assertion fails. See :doc:`../api/test` +for details. + +[1] https://gitlab.denx.de/u-boot/u-boot/-/commit/9fe064646d2 + + Add a new driver model test -~~~~~~~~~~~~~~~~~~~~~~~~~~~ +''''''''''''''''''''''''''' + +``dm`` is the test suite that contains C tests for U-boot +:doc:`Driver Model `. Use this when adding a test for a new or existing uclass, adding new operations or features to a uclass, adding new ofnode or dev_read_() functions, or anything @@ -249,31 +285,6 @@ Example commit: c48cb7ebfb4 ("sandbox: add ADC unit tests") [1] [1] https://gitlab.denx.de/u-boot/u-boot/-/commit/c48cb7ebfb4 -Add a C test to an existing suite -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Use this when you are adding to or modifying an existing feature outside driver -model. An example is bloblist. - -Add a new function in the same file as the rest of the suite and register it -with the suite. For example, to add a new mem_search test:: - - /* Test 'ms' command with 32-bit values */ - static int mem_test_ms_new_thing(struct unit_test_state *uts) - { - /* test code here */ - - return 0; - } - MEM_TEST(mem_test_ms_new_thing, UTF_CONSOLE); - -Note that the MEM_TEST() macros is defined at the top of the file. - -Example commit: 9fe064646d2 ("bloblist: Support relocating to a larger space") [1] - -[1] https://gitlab.denx.de/u-boot/u-boot/-/commit/9fe064646d2 - - Add a new test suite ~~~~~~~~~~~~~~~~~~~~ diff --git a/include/test/ut.h b/include/test/ut.h index be5502e03a1..6510c35997f 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -130,18 +130,28 @@ int ut_check_console_end(struct unit_test_state *uts); * * This only supports a byte dump. * - * @total_bytes: Size of the expected dump in bytes` - * Return: 0 if OK (looks like a dump and the length matches), other value on - * error + * @uts: Test state + * @total_bytes: Size of the expected dump in bytes + * Return: 0 if OK (looks like a dump and the length matches), + * other value on error */ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); -/* Report a failure, with printf() string */ +/** + * ut_report() - Report a failure, with printf() string + * + * @fmt: format string + * @args: arguments to be printed + */ #define ut_reportf(fmt, args...) \ ut_failf(uts, __FILE__, __LINE__, __func__, "report", \ fmt, ##args) -/* Assert that a condition is non-zero */ +/** + * ut_assert() - Assert that a condition is true (not 0) + * + * @cond: condition + */ #define ut_assert(cond) ({ \ int __ret = 0; \ \ @@ -152,7 +162,13 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that a condition is non-zero, with printf() string */ +/** + * ut_assertf() - Assert that a condition is true with printf string + * + * @cond: condition + * @fmt: format string + * @args: arguments to be printed + */ #define ut_assertf(cond, fmt, args...) ({ \ int __ret = 0; \ \ @@ -164,7 +180,12 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that two int expressions are equal */ +/** + * ut_asserteq() - Assert that two int32 expressions are equal + * + * @expr1: expected value + * @expr2: actual value + */ #define ut_asserteq(expr1, expr2) ({ \ unsigned int _val1 = (expr1), _val2 = (expr2); \ int __ret = 0; \ @@ -179,7 +200,12 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that two 64 int expressions are equal */ +/** + * ut_asserteq_64() - Assert that two int64 expressions are equal + * + * @expr1: expected value + * @expr2: actual value + */ #define ut_asserteq_64(expr1, expr2) ({ \ u64 _val1 = (expr1), _val2 = (expr2); \ int __ret = 0; \ @@ -197,7 +223,12 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that two string expressions are equal */ +/** + * ut_asserteq_str() - Assert that two string expressions are equal + * + * @expr1: expected value + * @expr2: actual value + */ #define ut_asserteq_str(expr1, expr2) ({ \ const char *_val1 = (expr1), *_val2 = (expr2); \ int __ret = 0; \ @@ -211,9 +242,12 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* - * Assert that two string expressions are equal, up to length of the - * first +/** + * ut_asserteq_strn() - Assert that two string expressions are equal + * up to the length of the first expression + * + * @expr1: expected value + * @expr2: actual value */ #define ut_asserteq_strn(expr1, expr2) ({ \ const char *_val1 = (expr1), *_val2 = (expr2); \ @@ -230,7 +264,13 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that two memory areas are equal */ +/** + * ut_asserteq_mem() - Assert that two memory areas are equal + * + * @expr1: expected value + * @expr2: actual value + * @len: length of the memory areas + */ #define ut_asserteq_mem(expr1, expr2, len) ({ \ const u8 *_val1 = (u8 *)(expr1), *_val2 = (u8 *)(expr2); \ const uint __len = len; \ @@ -250,7 +290,12 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that two pointers are equal */ +/** + * ut_asserteq_ptr() - Assert that two string pointers are equal + * + * @expr1: expected value + * @expr2: actual value + */ #define ut_asserteq_ptr(expr1, expr2) ({ \ const void *_val1 = (expr1), *_val2 = (expr2); \ int __ret = 0; \ @@ -264,7 +309,13 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that two addresses (converted from pointers) are equal */ +/** + * ut_asserteq_addr() - Assert that two addresses (converted from pointers) + * are equal + * + * @expr1: expected value + * @expr2: actual value + */ #define ut_asserteq_addr(expr1, expr2) ({ \ ulong _val1 = map_to_sysmem(expr1); \ ulong _val2 = map_to_sysmem(expr2); \ @@ -279,7 +330,11 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that a pointer is NULL */ +/** + * ut_assertnull() - Assert that a pointer is NULL + * + * @expr: pointer + */ #define ut_assertnull(expr) ({ \ const void *_val = (expr); \ int __ret = 0; \ @@ -293,7 +348,11 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that a pointer is not NULL */ +/** + * ut_assertnonnull() - Assert that a pointer is not NULL + * + * @expr: pointer + */ #define ut_assertnonnull(expr) ({ \ const void *_val = (expr); \ int __ret = 0; \ @@ -307,7 +366,11 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that a pointer is not an error pointer */ +/** + * ut_assertok_ptr() - Assert that a pointer is not an error pointer + * + * @expr: pointer + */ #define ut_assertok_ptr(expr) ({ \ const void *_val = (expr); \ int __ret = 0; \ @@ -322,10 +385,19 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that an operation succeeds (returns 0) */ +/** + * ut_assertok() - Assert that an operation succeeds (returns 0) + * + * @cond: expression + */ #define ut_assertok(cond) ut_asserteq(0, cond) -/* Assert that the next console output line matches */ +/** + * ut_assert_nextline() - Assert that the next console output line matches + * + * @fmt: format string + * @args: print arguments + */ #define ut_assert_nextline(fmt, args...) ({ \ int __ret = 0; \ \ @@ -338,7 +410,13 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that the next console output line matches up to the length */ +/** + * ut_assert_nextlinen() - Assert that the next console output line matches + * up to the length of the expected string. + * + * @fmt: format string + * @args: print arguments + */ #define ut_assert_nextlinen(fmt, args...) ({ \ int __ret = 0; \ \ @@ -351,7 +429,10 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that there is a 'next' console output line, and skip it */ +/** + * ut_assert_skipline() - Assert that there is a 'next' console output line, + * and skip it + */ #define ut_assert_skipline() ({ \ int __ret = 0; \ \ @@ -363,7 +444,13 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that a following console output line matches */ +/** + * ut_assert_skip_to_line() - Assert that a following console output line + * matches + * + * @fmt: format string + * @args: print arguments + */ #define ut_assert_skip_to_line(fmt, args...) ({ \ int __ret = 0; \ \ @@ -376,7 +463,13 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that a following console output line matches */ +/** + * ut_assert_skip_to_linen() - Assert that a following console output line + * matches up to the length of the expected string + * + * @fmt: format string + * @args: print arguments + */ #define ut_assert_skip_to_linen(fmt, args...) ({ \ int __ret = 0; \ \ @@ -389,7 +482,9 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that there is no more console output */ +/** + * ut_assert_console_end() - Assert that there is no more console output + */ #define ut_assert_console_end() ({ \ int __ret = 0; \ \ @@ -402,7 +497,12 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that the next lines are print_buffer() dump at an address */ +/** + * ut_assert_nextlines_are_dump - Assert that the next lines are print_buffer() + * dump at an address + * + * @total_bytes: Size of the expected dump in bytes + */ #define ut_assert_nextlines_are_dump(total_bytes) ({ \ int __ret = 0; \ \ @@ -416,7 +516,10 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) -/* Assert that the next console output line is empty */ +/** + * ut_assert_nextline_empty() - Assert that the next console output line is + * empty + */ #define ut_assert_nextline_empty() \ ut_assert_nextline("%s", "") @@ -451,6 +554,8 @@ void ut_silence_console(struct unit_test_state *uts); * * This restarts console output again and turns off console recording. This * happens on all boards, including sandbox. + * + * @uts: Test state */ void ut_unsilence_console(struct unit_test_state *uts); diff --git a/test/cmd/bdinfo.c b/test/cmd/bdinfo.c index 09f44ee41ed..28d448a0866 100644 --- a/test/cmd/bdinfo.c +++ b/test/cmd/bdinfo.c @@ -161,9 +161,9 @@ static int bdinfo_test_all(struct unit_test_state *uts) ut_assertok(bdinfo_check_mem(uts)); /* CONFIG_SYS_HAS_SRAM testing not supported */ - ut_assertok(test_num_l(uts, "flashstart", 0)); - ut_assertok(test_num_l(uts, "flashsize", 0)); - ut_assertok(test_num_l(uts, "flashoffset", 0)); + ut_check_console_linen(uts, "flashstart"); + ut_check_console_linen(uts, "flashsize"); + ut_check_console_linen(uts, "flashoffset"); ut_assert_nextline("baudrate = %lu bps", env_get_ulong("baudrate", 10, 1234)); ut_assertok(test_num_l(uts, "relocaddr", gd->relocaddr)); @@ -215,8 +215,15 @@ static int bdinfo_test_all(struct unit_test_state *uts) ut_assertok(test_num_l(uts, "malloc base", gd_malloc_start())); } + /* Check arch_print_bdinfo() output */ if (IS_ENABLED(CONFIG_X86)) - ut_check_skip_to_linen(uts, " high end ="); + ut_check_skip_to_linen(uts, "tsc"); + +#ifdef CONFIG_RISCV + ut_check_console_linen(uts, "boot hart"); + if (gd->arch.firmware_fdt_addr) + ut_check_console_linen(uts, "firmware fdt"); +#endif return 0; } diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index 96a8488e172..4c3c6308ab4 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -264,7 +265,7 @@ FDT_TEST(fdt_test_addr_resize, UTF_CONSOLE); static int fdt_test_move(struct unit_test_state *uts) { char fdt[256]; - ulong addr, newaddr = 0x10000; + ulong addr, newaddr; const int size = sizeof(fdt); uint32_t ts; void *buf; @@ -274,8 +275,10 @@ static int fdt_test_move(struct unit_test_state *uts) ts = fdt_totalsize(fdt); /* Moved target DT location */ - buf = map_sysmem(newaddr, size); + buf = memalign(8, size); + ut_assertnonnull(buf); memset(buf, 0, size); + newaddr = map_to_sysmem(buf); /* Test moving the working FDT to a new location */ ut_assertok(run_commandf("fdt move %08lx %08lx %x", addr, newaddr, ts)); @@ -287,6 +290,8 @@ static int fdt_test_move(struct unit_test_state *uts) ut_assert_nextline("Total of %d byte(s) were the same", ts); ut_assert_console_end(); + free(buf); + return 0; } FDT_TEST(fdt_test_move, UTF_CONSOLE); @@ -1267,6 +1272,7 @@ static int fdt_test_chosen(struct unit_test_state *uts) { const char *env_bootargs = env_get("bootargs"); char fdt[8192]; + struct udevice *dev; ulong addr; ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt), &addr)); @@ -1280,11 +1286,16 @@ static int fdt_test_chosen(struct unit_test_state *uts) /* Test add new chosen node without initrd */ ut_assertok(run_commandf("fdt chosen")); ut_assertok(run_commandf("fdt print /chosen")); - ut_assert_nextline("chosen {"); + ut_assert(0 < console_record_readline(uts->actual_str, + sizeof(uts->actual_str))); + if (!strcmp("No RNG device", uts->actual_str)) + ut_assert(0 < console_record_readline(uts->actual_str, + sizeof(uts->actual_str))); + ut_asserteq_str("chosen {", uts->actual_str); 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) && + if (!uclass_get_device(UCLASS_RNG, 0, &dev) && !IS_ENABLED(CONFIG_MEASURED_BOOT) && !IS_ENABLED(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT)) ut_assert_nextlinen("\tkaslr-seed = "); @@ -1294,7 +1305,12 @@ static int fdt_test_chosen(struct unit_test_state *uts) /* Test add new chosen node with initrd */ ut_assertok(run_commandf("fdt chosen 0x1234 0x5678")); ut_assertok(run_commandf("fdt print /chosen")); - ut_assert_nextline("chosen {"); + ut_assert(0 < console_record_readline(uts->actual_str, + sizeof(uts->actual_str))); + if (!strcmp("No RNG device", uts->actual_str)) + ut_assert(0 < console_record_readline(uts->actual_str, + sizeof(uts->actual_str))); + ut_asserteq_str("chosen {", uts->actual_str); ut_assert_nextline("\tlinux,initrd-end = <0x%08x 0x%08x>;", upper_32_bits(0x1234 + 0x5678 - 1), lower_32_bits(0x1234 + 0x5678 - 1)); @@ -1303,7 +1319,7 @@ 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) && + if (!uclass_get_device(UCLASS_RNG, 0, &dev) && !IS_ENABLED(CONFIG_MEASURED_BOOT) && !IS_ENABLED(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT)) ut_assert_nextlinen("\tkaslr-seed = "); @@ -1319,6 +1335,9 @@ static int fdt_test_apply(struct unit_test_state *uts) char fdt[8192], fdto[8192]; ulong addr, addro; + if (!IS_ENABLED(CONFIG_OF_LIBFDT_OVERLAY)) + return -EAGAIN; + /* Create base DT with __symbols__ node */ ut_assertok(fdt_create(fdt, sizeof(fdt))); ut_assertok(fdt_finish_reservemap(fdt)); diff --git a/test/common/print.c b/test/common/print.c index 76ee851fe6a..f33476a36b4 100644 --- a/test/common/print.c +++ b/test/common/print.c @@ -168,12 +168,8 @@ static int print_display_buffer(struct unit_test_state *uts) u8 *buf; int i; - /* This test requires writable memory at zero */ - if (IS_ENABLED(CONFIG_X86)) - return -EAGAIN; - - buf = map_sysmem(0, BUF_SIZE); - memset(buf, '\0', BUF_SIZE); + buf = calloc(1, BUF_SIZE); + ut_assertnonnull(buf); for (i = 0; i < 0x11; i++) buf[i] = i * 0x11; @@ -232,7 +228,7 @@ static int print_display_buffer(struct unit_test_state *uts) ut_assert_nextline("00000000: 00 1f 20 21 7e 7f 80 81 ff 99 .. !~....."); ut_assert_console_end(); - unmap_sysmem(buf); + free(buf); return 0; } @@ -244,13 +240,14 @@ static int print_hexdump_line(struct unit_test_state *uts) u8 *buf; int i; - buf = map_sysmem(0, BUF_SIZE); - memset(buf, '\0', BUF_SIZE); + buf = calloc(1, BUF_SIZE); + ut_assertnonnull(buf); for (i = 0; i < 0x11; i++) buf[i] = i * 0x11; /* Check buffer size calculations */ - linebuf = map_sysmem(0x400, BUF_SIZE); + linebuf = calloc(1, BUF_SIZE); + ut_assertnonnull(buf); memset(linebuf, '\xff', BUF_SIZE); ut_asserteq(-ENOSPC, hexdump_line(0, buf, 1, 0x10, 0, linebuf, 75)); ut_asserteq(0xff, linebuf[0]); @@ -258,7 +255,8 @@ static int print_hexdump_line(struct unit_test_state *uts) ut_asserteq('\0', linebuf[75]); ut_asserteq(0xff, linebuf[76]); - unmap_sysmem(buf); + free(linebuf); + free(buf); return 0; } @@ -268,70 +266,71 @@ static int print_do_hex_dump(struct unit_test_state *uts) { u8 *buf; int i; + ulong addr; - /* This test requires writable memory at zero */ - if (IS_ENABLED(CONFIG_X86)) - return -EAGAIN; - - buf = map_sysmem(0, BUF_SIZE); - memset(buf, '\0', BUF_SIZE); + buf = calloc(1, BUF_SIZE); + ut_assertnonnull(buf); + addr = map_to_sysmem(buf); for (i = 0; i < 0x11; i++) buf[i] = i * 0x11; /* bytes */ 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); + IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, addr); ut_assert_nextline("%0*lx: 10 00 ..", - IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x10UL); + IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, + addr + 0x10UL); ut_assert_console_end(); /* line length */ 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); + IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, addr); ut_assert_nextline("%0*lx: 88 99 aa bb cc dd ee ff ........", - IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x8UL); + IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, + addr + 0x8UL); ut_assert_nextline("%0*lx: 10 00 ..", - IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x10UL); + IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, + addr + 0x10UL); ut_assert_console_end(); - unmap_sysmem(buf); /* long line */ 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........................................................", - IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL); + IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, addr); ut_assert_nextline("%0*lx: 00 41 .A", - IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x40UL); + IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, + addr + 0x40UL); ut_assert_console_end(); /* 16-bit */ 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); + IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, addr); ut_assert_nextline("%0*lx: 0010 ..", - IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x10UL); + IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, + addr + 0x10UL); ut_assert_console_end(); - unmap_sysmem(buf); /* 32-bit */ 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); + IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, addr); ut_assert_nextline("%0*lx: 00000010 ....", - IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x10UL); + IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, + addr + 0x10UL); ut_assert_console_end(); - unmap_sysmem(buf); /* 64-bit */ 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); + IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, addr); ut_assert_nextline("%0*lx: 0000000000000010 ........", - IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x10UL); + IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, + addr + 0x10UL); ut_assert_console_end(); - unmap_sysmem(buf); /* ASCII */ buf[1] = 31; @@ -342,9 +341,9 @@ static int print_do_hex_dump(struct unit_test_state *uts) buf[8] = 255; print_hex_dump("", DUMP_PREFIX_ADDRESS, 0, 1, buf, 10, true); ut_assert_nextline("%0*lx: 00 1f 20 21 7e 7f 80 81 ff 99 .. !~.....", - IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL); + IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, addr); ut_assert_console_end(); - unmap_sysmem(buf); + free(buf); return 0; }