summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Kconfig23
-rw-r--r--test/Makefile3
-rw-r--r--test/boot/bootdev.c1
-rw-r--r--test/boot/bootflow.c1
-rw-r--r--test/boot/bootm.c1
-rw-r--r--test/boot/bootmeth.c1
-rw-r--r--test/boot/bootstd_common.c29
-rw-r--r--test/boot/bootstd_common.h10
-rw-r--r--test/boot/expo.c1
-rw-r--r--test/boot/image.c1
-rw-r--r--test/boot/measurement.c1
-rw-r--r--test/boot/upl.c1
-rw-r--r--test/boot/vbe_simple.c4
-rw-r--r--test/cmd/addrmap.c1
-rw-r--r--test/cmd/bdinfo.c1
-rw-r--r--test/cmd/exit.c1
-rw-r--r--test/cmd/fdt.c1
-rw-r--r--test/cmd/font.c1
-rw-r--r--test/cmd/loadm.c1
-rw-r--r--test/cmd/mbr.c1
-rw-r--r--test/cmd/pci_mps.c1
-rw-r--r--test/cmd/seama.c1
-rw-r--r--test/cmd/setexpr.c1
-rw-r--r--test/cmd_ut.c243
-rw-r--r--test/common/bloblist.c1
-rw-r--r--test/dm/Kconfig2
-rw-r--r--test/dm/mux-cmd.c6
-rw-r--r--test/env/Kconfig1
-rw-r--r--test/env/cmd_ut_env.c1
-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)2
-rw-r--r--test/fdt_overlay/cmd_ut_fdt_overlay.c (renamed from test/overlay/cmd_ut_overlay.c)221
-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.dtso)0
-rw-r--r--test/fdt_overlay/test-fdt-overlay.dtso (renamed from test/overlay/test-fdt-overlay.dtso)0
-rw-r--r--test/lib/longjmp.c2
-rw-r--r--test/log/cont_test.c1
-rw-r--r--test/log/nolog_test.c1
-rw-r--r--test/log/pr_cont_test.c1
-rw-r--r--test/log/syslog_test.c1
-rw-r--r--test/log/syslog_test_ndebug.c1
-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)105
-rw-r--r--test/py/requirements.txt28
-rw-r--r--test/py/tests/test_fs/conftest.py121
-rw-r--r--test/py/tests/test_fs/fstest_helpers.py2
-rw-r--r--test/py/tests/test_fs/test_rename.py372
-rw-r--r--test/py/tests/test_spi.py44
-rw-r--r--test/py/tests/test_suite.py34
-rw-r--r--test/py/tests/test_ums.py40
-rw-r--r--test/py/tests/test_usb.py2
-rw-r--r--test/test-main.c41
53 files changed, 914 insertions, 454 deletions
diff --git a/test/Kconfig b/test/Kconfig
index 558a9cd49b4..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
@@ -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 47a07d653a9..99d4797d968 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -14,11 +14,14 @@ endif
ifneq ($(CONFIG_HUSH_PARSER),)
obj-$(CONFIG_$(XPL_)CMDLINE) += hush/
endif
+obj-$(CONFIG_UT_OPTEE) += optee/
obj-y += ut.o
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/
else
obj-$(CONFIG_SPL_UT_LOAD) += image/
diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c
index 8c44afd9297..5f07430714e 100644
--- a/test/boot/bootdev.c
+++ b/test/boot/bootdev.c
@@ -12,7 +12,6 @@
#include <bootflow.h>
#include <mapmem.h>
#include <os.h>
-#include <test/suites.h>
#include <test/ut.h>
#include "bootstd_common.h"
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index a8735c1c23d..eb7f00af39a 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -21,7 +21,6 @@
#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"
diff --git a/test/boot/bootm.c b/test/boot/bootm.c
index 7e0ccb0e23f..1d1efe71ad5 100644
--- a/test/boot/bootm.c
+++ b/test/boot/bootm.c
@@ -7,7 +7,6 @@
#include <bootm.h>
#include <asm/global_data.h>
-#include <test/suites.h>
#include <test/test.h>
#include <test/ut.h>
diff --git a/test/boot/bootmeth.c b/test/boot/bootmeth.c
index 18ae6d7fe13..577f259fb37 100644
--- a/test/boot/bootmeth.c
+++ b/test/boot/bootmeth.c
@@ -9,7 +9,6 @@
#include <bootmeth.h>
#include <bootstd.h>
#include <dm.h>
-#include <test/suites.h>
#include <test/ut.h>
#include "bootstd_common.h"
diff --git a/test/boot/bootstd_common.c b/test/boot/bootstd_common.c
index 724e3d9bdd2..052c0fe5cc6 100644
--- a/test/boot/bootstd_common.c
+++ b/test/boot/bootstd_common.c
@@ -13,7 +13,6 @@
#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)
{
@@ -93,20 +99,3 @@ void bootstd_reset_usb(void)
{
usb_started = false;
}
-
-int do_ut_bootstd(struct unit_test_state *uts, struct cmd_tbl *cmdtp, int flag,
- int argc, char *const argv[])
-{
- struct unit_test *tests = UNIT_TEST_SUITE_START(bootstd);
- const int n_ents = UNIT_TEST_SUITE_COUNT(bootstd);
- 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(uts, "bootstd", "bootstd_",
- tests, n_ents, argc, argv);
-}
diff --git a/test/boot/bootstd_common.h b/test/boot/bootstd_common.h
index ea3ecd1166c..c61698adc02 100644
--- a/test/boot/bootstd_common.h
+++ b/test/boot/bootstd_common.h
@@ -13,6 +13,7 @@
/* Declare a new bootdev 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)
@@ -36,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
diff --git a/test/boot/expo.c b/test/boot/expo.c
index db14ff86f8b..1d283a2ac95 100644
--- a/test/boot/expo.c
+++ b/test/boot/expo.c
@@ -10,7 +10,6 @@
#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>
diff --git a/test/boot/image.c b/test/boot/image.c
index 0894e30587f..4df7b17ce88 100644
--- a/test/boot/image.c
+++ b/test/boot/image.c
@@ -7,7 +7,6 @@
*/
#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 5a49c7a6b23..1d38663fc0f 100644
--- a/test/boot/measurement.c
+++ b/test/boot/measurement.c
@@ -8,7 +8,6 @@
#include <bootm.h>
#include <malloc.h>
-#include <test/suites.h>
#include <test/test.h>
#include <test/ut.h>
#include <asm/io.h>
diff --git a/test/boot/upl.c b/test/boot/upl.c
index aa58cdf083b..eec89026fc3 100644
--- a/test/boot/upl.c
+++ b/test/boot/upl.c
@@ -10,7 +10,6 @@
#include <mapmem.h>
#include <upl.h>
#include <dm/ofnode.h>
-#include <test/suites.h>
#include <test/test.h>
#include <test/ut.h>
#include "bootstd_common.h"
diff --git a/test/boot/vbe_simple.c b/test/boot/vbe_simple.c
index 4fe4323b401..c37de627c52 100644
--- a/test/boot/vbe_simple.c
+++ b/test/boot/vbe_simple.c
@@ -11,7 +11,6 @@
#include <image.h>
#include <of_live.h>
#include <vbe.h>
-#include <test/suites.h>
#include <test/ut.h>
#include "bootstd_common.h"
@@ -33,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)));
diff --git a/test/cmd/addrmap.c b/test/cmd/addrmap.c
index 1f2deb15052..72798b96edd 100644
--- a/test/cmd/addrmap.c
+++ b/test/cmd/addrmap.c
@@ -6,7 +6,6 @@
*/
#include <console.h>
-#include <test/suites.h>
#include <test/ut.h>
/* Declare a new addrmap test */
diff --git a/test/cmd/bdinfo.c b/test/cmd/bdinfo.c
index 7408c271a30..09f44ee41ed 100644
--- a/test/cmd/bdinfo.c
+++ b/test/cmd/bdinfo.c
@@ -10,7 +10,6 @@
#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>
diff --git a/test/cmd/exit.c b/test/cmd/exit.c
index 71c37edcdf6..fdde054b928 100644
--- a/test/cmd/exit.c
+++ b/test/cmd/exit.c
@@ -8,7 +8,6 @@
#include <console.h>
#include <mapmem.h>
#include <asm/global_data.h>
-#include <test/suites.h>
#include <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index ab6dbd45e54..c11c181c807 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -10,7 +10,6 @@
#include <mapmem.h>
#include <asm/global_data.h>
#include <linux/libfdt.h>
-#include <test/suites.h>
#include <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
diff --git a/test/cmd/font.c b/test/cmd/font.c
index af88d1b5459..7ae648d7395 100644
--- a/test/cmd/font.c
+++ b/test/cmd/font.c
@@ -8,7 +8,6 @@
#include <console.h>
#include <dm.h>
#include <video_console.h>
-#include <test/suites.h>
#include <test/ut.h>
/* Declare a new fdt test */
diff --git a/test/cmd/loadm.c b/test/cmd/loadm.c
index 3c623aa655f..043cd25dfb6 100644
--- a/test/cmd/loadm.c
+++ b/test/cmd/loadm.c
@@ -13,7 +13,6 @@
#include <mapmem.h>
#include <asm/global_data.h>
#include <dm/test.h>
-#include <test/suites.h>
#include <test/test.h>
#include <test/ut.h>
diff --git a/test/cmd/mbr.c b/test/cmd/mbr.c
index 45bab04923a..e651256a4cb 100644
--- a/test/cmd/mbr.c
+++ b/test/cmd/mbr.c
@@ -15,7 +15,6 @@
#include <dm/device-internal.h>
#include <dm/lists.h>
#include <linux/sizes.h>
-#include <test/suites.h>
#include <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
diff --git a/test/cmd/pci_mps.c b/test/cmd/pci_mps.c
index 8b3ea4a6134..6618c247d13 100644
--- a/test/cmd/pci_mps.c
+++ b/test/cmd/pci_mps.c
@@ -8,7 +8,6 @@
*/
#include <console.h>
-#include <test/suites.h>
#include <test/ut.h>
#define PCI_MPS_TEST(_name, _flags) UNIT_TEST(_name, _flags, pci_mps)
diff --git a/test/cmd/seama.c b/test/cmd/seama.c
index 1edc3fcac5a..39f85f1c502 100644
--- a/test/cmd/seama.c
+++ b/test/cmd/seama.c
@@ -7,7 +7,6 @@
#include <command.h>
#include <dm.h>
-#include <test/suites.h>
#include <test/test.h>
#include <test/ut.h>
diff --git a/test/cmd/setexpr.c b/test/cmd/setexpr.c
index 5e9b577fe36..85803eb54b8 100644
--- a/test/cmd/setexpr.c
+++ b/test/cmd/setexpr.c
@@ -9,7 +9,6 @@
#include <console.h>
#include <mapmem.h>
#include <dm/test.h>
-#include <test/suites.h>
#include <test/ut.h>
#define BUF_SIZE 0x100
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index fbfdaaae0b5..44e5fdfdaa6 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -7,7 +7,6 @@
#include <command.h>
#include <console.h>
#include <vsprintf.h>
-#include <test/suites.h>
#include <test/test.h>
#include <test/ut.h>
@@ -20,77 +19,31 @@
* @name: Name of suite
* @start: First test in suite
* @end: End test in suite (points to the first test in the next suite)
- * @cmd: Command to use to run the suite
* @help: Help-string to show for this suite
*/
struct suite {
const char *name;
struct unit_test *start;
struct unit_test *end;
- ut_cmd_func cmd;
const char *help;
};
-static int do_ut_all(struct unit_test_state *uts, struct cmd_tbl *cmdtp,
- int flag, int argc, char *const argv[]);
+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[]);
-
-int cmd_ut_category(struct unit_test_state *uts, const char *name,
- const char *prefix, struct unit_test *tests, int n_ents,
- int argc, char *const argv[])
-{
- const char *test_insert = NULL;
- int runs_per_text = 1;
- bool force_run = false;
- int ret;
-
- while (argc > 1 && *argv[1] == '-') {
- const char *str = argv[1];
-
- 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, name, prefix, tests, n_ents,
- cmd_arg1(argc, argv), runs_per_text, force_run,
- test_insert);
-
- return ret ? CMD_RET_FAILURE : 0;
-}
+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 uses a subcommand to run */
-#define SUITE_CMD(_name, _cmd_func, _help) { \
- #_name, \
- suite_start_ ## _name, \
- suite_end_ ## _name, \
- _cmd_func, \
- _help, \
- }
-
/* declare a test suite which can be run directly without a subcommand */
#define SUITE(_name, _help) { \
#_name, \
suite_start_ ## _name, \
suite_end_ ## _name, \
- NULL, \
_help, \
}
@@ -105,6 +58,7 @@ 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);
@@ -114,7 +68,6 @@ SUITE_DECL(mbr);
SUITE_DECL(measurement);
SUITE_DECL(mem);
SUITE_DECL(optee);
-SUITE_DECL(overlay);
SUITE_DECL(pci_mps);
SUITE_DECL(seama);
SUITE_DECL(setexpr);
@@ -125,15 +78,14 @@ static struct suite suites[] = {
SUITE(bdinfo, "bdinfo (board info) command"),
SUITE(bloblist, "bloblist implementation"),
SUITE(bootm, "bootm command"),
-#ifdef CONFIG_UT_BOOTSTD
- SUITE_CMD(bootstd, do_ut_bootstd, "standard boot implementation"),
-#endif
+ 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"),
@@ -142,12 +94,7 @@ static struct suite suites[] = {
SUITE(mbr, "mbr command"),
SUITE(measurement, "TPM-based measured boot"),
SUITE(mem, "memory-related commands"),
-#ifdef CONFIG_UT_OPTEE
- SUITE_CMD(optee, do_ut_optee, "OP-TEE"),
-#endif
-#ifdef CONFIG_UT_OVERLAY
- SUITE_CMD(overlay, do_ut_overlay, "device tree overlays"),
-#endif
+ SUITE(optee, "OP-TEE"),
SUITE(pci_mps, "PCI Express Maximum Payload Size"),
SUITE(seama, "seama command parameters loading and decoding"),
SUITE(setexpr, "setexpr command"),
@@ -167,33 +114,59 @@ static bool has_tests(struct suite *ste)
{
int n_ents = ste->end - ste->start;
- return n_ents || ste->cmd;
+ return n_ents;
}
/** run_suite() - Run a suite of tests */
static int run_suite(struct unit_test_state *uts, struct suite *ste,
- struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[])
+ 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;
- if (ste->cmd) {
- ret = ste->cmd(uts, cmdtp, flag, argc, argv);
- } else {
- int n_ents = ste->end - ste->start;
- char prefix[30];
+ /* use a standard prefix */
+ snprintf(prefix, sizeof(prefix), "%s_test_", ste->name);
- /* use a standard prefix */
- snprintf(prefix, sizeof(prefix), "%s_test", ste->name);
- ret = cmd_ut_category(uts, ste->name, prefix, ste->start,
- n_ents, argc, argv);
- }
+ ret = ut_run_list(uts, ste->name, prefix, ste->start, n_ents,
+ select_name, runs_per_test, force_run, test_insert);
return ret;
}
-static int do_ut_all(struct unit_test_state *uts, struct cmd_tbl *cmdtp,
- int flag, int argc, char *const argv[])
+static void show_stats(struct unit_test_state *uts)
+{
+ if (uts->run_count < 2)
+ return;
+
+ 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;
+
+ printf("Average test time: %ld ms, worst case '%s' took %d ms\n",
+ avg, uts->worst->name, uts->worst_ms);
+ }
+}
+
+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;
+
+ 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;
@@ -201,25 +174,23 @@ static int do_ut_all(struct unit_test_state *uts, struct cmd_tbl *cmdtp,
for (i = 0; i < ARRAY_SIZE(suites); i++) {
struct suite *ste = &suites[i];
- char *const argv[] = {(char *)ste->name, NULL};
if (has_tests(ste)) {
printf("----Running %s tests----\n", ste->name);
- retval = run_suite(uts, ste, cmdtp, flag, 1, argv);
+ retval = run_suite(uts, ste, select_name, runs_per_test,
+ force_run, test_insert);
if (!any_fail)
any_fail = retval;
+ update_stats(uts, ste);
}
}
- ut_report(&uts->total, uts->run_count);
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)
{
int suite_count, i;
- const char *flags;
for (suite_count = 0, i = 0; i < ARRAY_SIZE(suites); i++) {
struct suite *ste = &suites[i];
@@ -231,24 +202,26 @@ static int do_ut_info(struct cmd_tbl *cmdtp, int flag, int argc,
printf("Test suites: %d\n", suite_count);
printf("Total tests: %d\n", (int)UNIT_TEST_ALL_COUNT());
- flags = cmd_arg1(argc, argv);
- if (flags && !strcmp("-s", flags)) {
- int i;
+ if (show_suites) {
+ int i, total;
puts("\nTests Suite Purpose");
puts("\n----- ------------ -------------------------\n");
- for (i = 0; i < ARRAY_SIZE(suites); i++) {
+ 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", n_ent);
- else if (ste->cmd)
- printf("%5s", "?");
- else /* suite is not present */
- continue;
- printf(" %-13.13s %s\n", ste->name, ste->help);
+ 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;
@@ -269,37 +242,77 @@ static struct suite *find_suite(const char *name)
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;
- const char *name;
+ char *name;
int ret;
- if (argc < 2)
- return CMD_RET_USAGE;
-
/* drop initial "ut" arg */
argc--;
argv++;
+ 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;
+
ut_init_state(&uts);
name = argv[0];
+ select_name = cmd_arg1(argc, argv);
if (!strcmp(name, "all")) {
- ret = do_ut_all(&uts, cmdtp, flag, argc, argv);
+ ret = do_ut_all(&uts, select_name, runs_per_text, force_run,
+ test_insert);
} else if (!strcmp(name, "info")) {
- ret = do_ut_info(cmdtp, flag, argc, argv);
+ ret = do_ut_info(show_suites);
} else {
- ste = find_suite(argv[0]);
- if (!ste) {
- printf("Suite '%s' not found\n", argv[0]);
- return CMD_RET_FAILURE;
- } else if (!has_tests(ste)) {
- /* perhaps a Kconfig option needs to be set? */
- printf("Suite '%s' is not enabled\n", argv[0]);
- return CMD_RET_FAILURE;
+ int any_fail = 0;
+ const char *p;
+
+ 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 = run_suite(&uts, ste, cmdtp, flag, argc, argv);
+ ret = any_fail;
}
+ show_stats(&uts);
if (ret)
return ret;
ut_uninit_state(&uts);
@@ -308,14 +321,16 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
}
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 [-s] - show info about tests [and suites]"
+ "Options for <suite>:\n"
+ "all - execute all enabled tests\n"
+ "info - show info about tests [and suites]"
);
U_BOOT_CMD(
diff --git a/test/common/bloblist.c b/test/common/bloblist.c
index ab8f41c6808..797bde27025 100644
--- a/test/common/bloblist.c
+++ b/test/common/bloblist.c
@@ -6,7 +6,6 @@
#include <bloblist.h>
#include <log.h>
#include <mapmem.h>
-#include <test/suites.h>
#include <test/test.h>
#include <test/ut.h>
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/mux-cmd.c b/test/dm/mux-cmd.c
index 6eb3b283161..bd02cda84db 100644
--- a/test/dm/mux-cmd.c
+++ b/test/dm/mux-cmd.c
@@ -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);
@@ -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);
@@ -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);
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/cmd_ut_env.c b/test/env/cmd_ut_env.c
index 81d1bb2f80d..43f1b7d1cef 100644
--- a/test/env/cmd_ut_env.c
+++ b/test/env/cmd_ut_env.c
@@ -5,7 +5,6 @@
*/
#include <test/env.h>
-#include <test/suites.h>
#include <test/ut.h>
static int env_test_env_cmd(struct unit_test_state *uts)
diff --git a/test/overlay/Kconfig b/test/fdt_overlay/Kconfig
index 881848968bb..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 && SANDBOX
+ depends on OF_CONTROL && SANDBOX
default y
select OF_LIBFDT_OVERLAY
help
diff --git a/test/overlay/Makefile b/test/fdt_overlay/Makefile
index 47937e3c108..5625c0d8885 100644
--- a/test/overlay/Makefile
+++ b/test/fdt_overlay/Makefile
@@ -4,7 +4,7 @@
# Copyright (c) 2016 Free Electrons
# Test files
-obj-y += cmd_ut_overlay.o
+obj-y += cmd_ut_fdt_overlay.o
DTC_FLAGS += -@
diff --git a/test/overlay/cmd_ut_overlay.c b/test/fdt_overlay/cmd_ut_fdt_overlay.c
index aefa147ec04..0084033b6ca 100644
--- a/test/overlay/cmd_ut_overlay.c
+++ b/test/fdt_overlay/cmd_ut_fdt_overlay.c
@@ -6,6 +6,7 @@
#include <command.h>
#include <errno.h>
+#include <fdtdec.h>
#include <fdt_support.h>
#include <image.h>
#include <log.h>
@@ -13,9 +14,8 @@
#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)
@@ -26,32 +26,61 @@ 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)
@@ -68,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;
@@ -90,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;
@@ -102,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;
@@ -115,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;
@@ -128,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;
@@ -142,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");
@@ -156,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");
@@ -186,95 +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 unit_test_state *uts, 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);
- const int n_ents = UNIT_TEST_SUITE_COUNT(overlay);
- 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;
- int ret = -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(uts, "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.dtso b/test/fdt_overlay/test-fdt-overlay-stacked.dtso
index 6411adec539..6411adec539 100644
--- a/test/overlay/test-fdt-overlay-stacked.dtso
+++ b/test/fdt_overlay/test-fdt-overlay-stacked.dtso
diff --git a/test/overlay/test-fdt-overlay.dtso b/test/fdt_overlay/test-fdt-overlay.dtso
index 5a21b346d07..5a21b346d07 100644
--- a/test/overlay/test-fdt-overlay.dtso
+++ b/test/fdt_overlay/test-fdt-overlay.dtso
diff --git a/test/lib/longjmp.c b/test/lib/longjmp.c
index 79d889bdd5f..74c3465b8c2 100644
--- a/test/lib/longjmp.c
+++ b/test/lib/longjmp.c
@@ -5,10 +5,10 @@
* Copyright (c) 2021, Heinrich Schuchardt <xypron.glpk@gmx.de>
*/
+#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/log/cont_test.c b/test/log/cont_test.c
index 32b1c792367..3b3b791f025 100644
--- a/test/log/cont_test.c
+++ b/test/log/cont_test.c
@@ -9,7 +9,6 @@
#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;
diff --git a/test/log/nolog_test.c b/test/log/nolog_test.c
index 341dbfc9310..1913e6817a7 100644
--- a/test/log/nolog_test.c
+++ b/test/log/nolog_test.c
@@ -13,7 +13,6 @@
#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;
diff --git a/test/log/pr_cont_test.c b/test/log/pr_cont_test.c
index 7734e927f98..67d8ac59db9 100644
--- a/test/log/pr_cont_test.c
+++ b/test/log/pr_cont_test.c
@@ -8,7 +8,6 @@
#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>
diff --git a/test/log/syslog_test.c b/test/log/syslog_test.c
index c4180f775b9..98b91436580 100644
--- a/test/log/syslog_test.c
+++ b/test/log/syslog_test.c
@@ -15,7 +15,6 @@
#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 b10e636812b..dfd0217c1e4 100644
--- a/test/log/syslog_test_ndebug.c
+++ b/test/log/syslog_test_ndebug.c
@@ -12,7 +12,6 @@
#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 fc6674764f9..658621fa2fa 100644
--- a/test/optee/cmd_ut_optee.c
+++ b/test/optee/optee.c
@@ -14,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)
@@ -26,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;
@@ -46,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)
{
@@ -89,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);
- const int n_ents = UNIT_TEST_SUITE_COUNT(optee);
- 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/requirements.txt b/test/py/requirements.txt
index 75760f96e56..acfe17dce9f 100644
--- a/test/py/requirements.txt
+++ b/test/py/requirements.txt
@@ -1,30 +1,4 @@
-atomicwrites==1.4.1
-attrs==19.3.0
-concurrencytest==0.1.2
-coverage==6.2
-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==24.1
-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.32.3
-setuptools==70.3.0
-six==1.16.0
-testtools==2.3.0
-traceback2==1.4.0
-unittest2==1.1.0
-wcwidth==0.1.7
-zipp==3.19.2
diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py
index af2adaf1645..7bfcf41ed6f 100644
--- a/test/py/tests/test_fs/conftest.py
+++ b/test/py/tests/test_fs/conftest.py
@@ -18,6 +18,7 @@ supported_fs_fat = ['fat12', 'fat16']
supported_fs_mkdir = ['fat12', 'fat16', 'fat32']
supported_fs_unlink = ['fat12', 'fat16', 'fat32']
supported_fs_symlink = ['ext4']
+supported_fs_rename = ['fat12', 'fat16', 'fat32']
#
# Filesystem test specific setup
@@ -55,6 +56,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 +70,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,6 +102,9 @@ 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
@@ -528,6 +534,121 @@ def fs_obj_symlink(request, u_boot_config):
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)
+ return
+ else:
+ yield [fs_ubtype, fs_img, md5val]
+ finally:
+ call('rm -rf %s' % mount_dir, shell=True)
+ call('rm -f %s' % fs_img, shell=True)
+
+#
# Fixture for fat test
#
@pytest.fixture()
diff --git a/test/py/tests/test_fs/fstest_helpers.py b/test/py/tests/test_fs/fstest_helpers.py
index faec2982489..c1447b4d43e 100644
--- a/test/py/tests/test_fs/fstest_helpers.py
+++ b/test/py/tests/test_fs/fstest_helpers.py
@@ -9,5 +9,7 @@ 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 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_rename.py b/test/py/tests/test_fs/test_rename.py
new file mode 100644
index 00000000000..df2b2fd2945
--- /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, u_boot_console, fs_obj_rename):
+ """
+ Test Case 1 - rename a file (successful mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with u_boot_console.log.section('Test Case 1 - rename a file'):
+ d = 'test1'
+ src = '%s/file1' % d
+ dst = '%s/file2' % d
+ output = u_boot_console.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = u_boot_console.run_command_list([
+ 'load host 0:0 %x /%s' % (ADDR, dst),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = u_boot_console.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('file1' not in ''.join(output))
+
+ output = u_boot_console.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, u_boot_console, fs_obj_rename):
+ """
+ Test Case 2 - rename a file to an existing file (successful mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with u_boot_console.log.section('Test Case 2 - rename a file to an existing file'):
+ d = 'test2'
+ src = '%s/file1' % d
+ dst = '%s/file_exist' % d
+ output = u_boot_console.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = u_boot_console.run_command_list([
+ 'load host 0:0 %x /%s' % (ADDR, dst),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = u_boot_console.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('file1' not in ''.join(output))
+
+ output = u_boot_console.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, u_boot_console, fs_obj_rename):
+ """
+ Test Case 3 - rename a directory (successful mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with u_boot_console.log.section('Test Case 3 - rename a directory'):
+ d = 'test3'
+ src = '%s/dir1' % d
+ dst = '%s/dir2' % d
+ output = u_boot_console.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = u_boot_console.run_command_list([
+ 'load host 0:0 %x /%s/file1' % (ADDR, dst),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = u_boot_console.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('dir1' not in ''.join(output))
+
+ output = u_boot_console.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, u_boot_console, fs_obj_rename):
+ """
+ Test Case 4 - rename a directory to an existing directory (successful
+ mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with u_boot_console.log.section('Test Case 4 - rename a directory to an existing directory'):
+ d = 'test4'
+ src = '%s/dir1' % d
+ dst = '%s/dir2' % d
+ output = u_boot_console.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = u_boot_console.run_command_list([
+ 'load host 0:0 %x /%s/dir1/file1' % (ADDR, dst),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = u_boot_console.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('dir1' not in ''.join(output))
+
+ output = u_boot_console.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, u_boot_console, fs_obj_rename):
+ """
+ Test Case 5 - rename a directory to an existing file (failed mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with u_boot_console.log.section('Test Case 5 - rename a directory to an existing file'):
+ d = 'test5'
+ src = '%s/dir1' % d
+ dst = '%s/file2' % d
+ output = u_boot_console.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = u_boot_console.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('dir1' in ''.join(output))
+ assert('file2' in ''.join(output))
+
+ output = u_boot_console.run_command_list([
+ 'load host 0:0 %x /%s' % (ADDR, dst),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = u_boot_console.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, u_boot_console, 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 u_boot_console.log.section('Test Case 6 - rename a file to an existing empty directory'):
+ d = 'test6'
+ src = '%s/existing' % d
+ dst = '%s/dir2' % d
+ output = u_boot_console.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = u_boot_console.run_command_list([
+ 'load host 0:0 %x /%s' % (ADDR, src),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = u_boot_console.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('dir2' in ''.join(output))
+ assert('existing' in ''.join(output))
+
+ output = u_boot_console.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, u_boot_console, 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 u_boot_console.log.section('Test Case 7 - rename a directory to a non-empty directory'):
+ d = 'test7'
+ src = '%s/dir1' % d
+ dst = '%s/dir2' % d
+ output = u_boot_console.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = u_boot_console.run_command_list([
+ 'load host 0:0 %x /%s/dir1/file1' % (ADDR, dst),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = u_boot_console.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('dir1' in ''.join(output))
+ assert('dir2' in ''.join(output))
+
+ output = u_boot_console.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, u_boot_console, fs_obj_rename):
+ """
+ Test Case 8 - rename a directory inside itself (failed mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with u_boot_console.log.section('Test Case 8 - rename a directory inside itself'):
+ d = 'test8'
+ src = '%s/dir1' % d
+ dst = '%s/dir1/dir1' % d
+ output = u_boot_console.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = u_boot_console.run_command_list([
+ 'load host 0:0 %x /%s/file1' % (ADDR, src),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = u_boot_console.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('dir1' in ''.join(output))
+
+ output = u_boot_console.run_command_list([
+ 'ls host 0:0 %s' % (src),
+ ])
+ assert('file1' in ''.join(output))
+ assert('dir1' not in ''.join(output))
+
+ output = u_boot_console.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, u_boot_console, fs_obj_rename):
+ """
+ Test Case 9 - rename a directory inside itself with backtracks (failed
+ mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with u_boot_console.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 = u_boot_console.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, dst),
+ ])
+ assert('' == ''.join(output))
+
+ output = u_boot_console.run_command_list([
+ 'ls host 0:0 %s/dir1' % (d),
+ ])
+ assert('nested' in ''.join(output))
+
+ output = u_boot_console.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, u_boot_console, fs_obj_rename):
+ """
+ Test Case 10 - rename a file to itself (successful mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with u_boot_console.log.section('Test Case 10 - rename a file to itself'):
+ d = 'test10'
+ src = '%s/file1' % d
+ output = u_boot_console.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, src),
+ ])
+ assert('' == ''.join(output))
+
+ output = u_boot_console.run_command_list([
+ 'load host 0:0 %x /%s' % (ADDR, src),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = u_boot_console.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('file1' in ''.join(output))
+
+ output = u_boot_console.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, u_boot_console, fs_obj_rename):
+ """
+ Test Case 11 - rename a directory to itself (successful mv)
+ """
+ fs_type, fs_img, md5val = fs_obj_rename
+ with u_boot_console.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 = u_boot_console.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ 'setenv filesize',
+ 'mv host 0:0 %s %s' % (src, d),
+ ])
+ assert('' == ''.join(output))
+
+ output = u_boot_console.run_command_list([
+ 'load host 0:0 %x /%s/file1' % (ADDR, src),
+ 'printenv filesize'])
+ assert('filesize=400' in output)
+
+ output = u_boot_console.run_command_list([
+ 'ls host 0:0 %s' % (d),
+ ])
+ assert('dir1' in ''.join(output))
+
+ output = u_boot_console.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_spi.py b/test/py/tests/test_spi.py
index 0abdfa78b76..d57db9178e9 100644
--- a/test/py/tests/test_spi.py
+++ b/test/py/tests/test_spi.py
@@ -119,37 +119,35 @@ def spi_pre_commands(u_boot_console, freq):
pytest.fail('Not recognized the SPI flash part name')
m = re.search('page size (.+?) Bytes', output)
- if m:
- try:
- page_size = int(m.group(1))
- except ValueError:
- pytest.fail('Not recognized the SPI page size')
+ 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)
- if m:
- try:
- erase_size = int(m.group(1))
- except ValueError:
- pytest.fail('Not recognized the SPI erase size')
-
+ 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)
- if m:
- try:
- total_size = int(m.group(1))
- except ValueError:
- pytest.fail('Not recognized the SPI total size')
-
+ 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)
- if m:
- try:
- flash_part = m.group(1)
- assert flash_part == part_name
- except ValueError:
- pytest.fail('Not recognized the SPI flash part')
+ 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 = {
diff --git a/test/py/tests/test_suite.py b/test/py/tests/test_suite.py
index 73c185349b4..9ddc883394b 100644
--- a/test/py/tests/test_suite.py
+++ b/test/py/tests/test_suite.py
@@ -7,10 +7,10 @@ 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',
+ 'cmd', 'common', 'dm', 'env', 'exit', 'fdt_overlay',
'fdt', 'font', 'hush', 'lib',
'loadm', 'log', 'mbr', 'measurement', 'mem',
- 'overlay', 'pci_mps', 'setexpr', 'upl',
+ 'pci_mps', 'setexpr', 'upl',
]
@@ -66,11 +66,12 @@ def collect_info(cons, output):
msg = m.group(3)
if DEBUG_ME:
cons.log.info(f"test_name {test_name} msg '{msg}'")
- if msg == ' (flat tree)' and test_name not in tests:
- tests.add(test_name)
+ 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(test_name)
+ tests.add(full_name)
test_count += 1
if DEBUG_ME:
cons.log.info(f'test_count {test_count}')
@@ -134,7 +135,7 @@ def xtest_suite(u_boot_console, u_boot_config):
- 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 info -s'
+ 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'
@@ -166,7 +167,7 @@ def xtest_suite(u_boot_console, u_boot_config):
# Run 'ut info' and compare with the log results
with cons.log.section('Check suite test-counts'):
- output = cons.run_command('ut info -s')
+ output = cons.run_command('ut -s info')
suite_count, total_test_count, test_count = process_ut_info(cons,
output)
@@ -186,3 +187,22 @@ def xtest_suite(u_boot_console, u_boot_config):
assert suite_count == len(EXPECTED_SUITES)
assert total_test_count == len(all_tests)
+
+ # Run three suites
+ with cons.log.section('Check multiple suites'):
+ output = cons.run_command('ut bloblist,setexpr,mem')
+ assert 'Suites run: 3' in output
+
+ # Run a particular test
+ with cons.log.section('Check single test'):
+ output = cons.run_command('ut bloblist reloc')
+ assert 'Test: reloc: bloblist.c' in output
+
+ # Run tests multiple times
+ with cons.log.section('Check multiple runs'):
+ output = cons.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_ums.py b/test/py/tests/test_ums.py
index 749b1606235..387571c5140 100644
--- a/test/py/tests/test_ums.py
+++ b/test/py/tests/test_ums.py
@@ -113,14 +113,12 @@ def test_ums(u_boot_console, env__usb_dev_port, env__block_devs):
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 = u_boot_utils.PersistentRandomFile(u_boot_console, '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.
@@ -197,25 +195,23 @@ def test_ums(u_boot_console, env__usb_dev_port, env__block_devs):
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()
+ 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
+ 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:
diff --git a/test/py/tests/test_usb.py b/test/py/tests/test_usb.py
index 566d73b7c64..9bef883325f 100644
--- a/test/py/tests/test_usb.py
+++ b/test/py/tests/test_usb.py
@@ -580,6 +580,8 @@ def test_usb_load(u_boot_console):
elif fs in ['ext4', 'ext2']:
file, size, expected_crc32 = \
usb_ext4load_ext4write(u_boot_console, fs, x, part)
+ else:
+ raise Exception('Unsupported filesystem type %s' % fs)
offset = random.randrange(128, 1024, 128)
output = u_boot_console.run_command(
diff --git a/test/test-main.c b/test/test-main.c
index 22b9b46d9cd..cabc736a524 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -14,6 +14,7 @@
#include <net.h>
#include <of_live.h>
#include <os.h>
+#include <spl.h>
#include <usb.h>
#include <dm/ofnode.h>
#include <dm/root.h>
@@ -513,11 +514,12 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
* 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, ret;
@@ -529,7 +531,7 @@ static int ut_run_test_live_flat(struct unit_test_state *uts,
if (CONFIG_IS_ENABLED(OF_LIVE)) {
if (!(test->flags & UTF_FLAT_TREE)) {
uts->of_live = true;
- ret = ut_run_test(uts, test, test->name);
+ ret = ut_run_test(uts, test, leaf ?: test->name);
if (ret != -EAGAIN) {
ut_assertok(ret);
runs++;
@@ -557,7 +559,7 @@ static int ut_run_test_live_flat(struct unit_test_state *uts,
(!runs || ut_test_run_on_flattree(test)) &&
!(gd->flags & GD_FLG_FDT_CHANGED)) {
uts->of_live = false;
- ret = ut_run_test(uts, test, test->name);
+ ret = ut_run_test(uts, test, leaf ?: test->name);
if (ret != -EAGAIN) {
ut_assertok(ret);
runs++;
@@ -593,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;
@@ -617,7 +620,8 @@ 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 & UTF_MANUAL) {
@@ -645,7 +649,7 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
uts->cur.test_count++;
if (one && upto == pos) {
- ret = ut_run_test_live_flat(uts, one);
+ 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,
@@ -655,8 +659,11 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
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);
+ 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);
@@ -680,6 +687,12 @@ void ut_report(struct ut_stats *stats, int 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);
@@ -692,16 +705,22 @@ int ut_run_list(struct unit_test_state *uts, const char *category,
{
;
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, 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"
@@ -732,13 +751,19 @@ int ut_run_list(struct unit_test_state *uts, const char *category,
if (has_dm_tests)
dm_test_restore(uts->of_root);
- ut_report(&uts->cur, 1);
if (ret == -ENOENT)
printf("Test '%s' not found\n", select_name);
+ 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;