summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2022-11-08 09:45:10 -0500
committerTom Rini <[email protected]>2022-11-08 09:45:10 -0500
commit77b5cc2948f5d93fe3d275302f596ffd8701a875 (patch)
tree703dfe2a0ebb2eacb241c19b99c96665a2d66811 /test
parent88bd8ee106591eb900561715c44ad04441afc0e3 (diff)
parent168a0e45fcf49194fca55795f84a844f16b480f6 (diff)
Merge tag 'dm-pull-7nov22' of https://source.denx.de/u-boot/custodians/u-boot-dm
sandbox UCLASS_HOST
Diffstat (limited to 'test')
-rw-r--r--test/cmd_ut.c82
-rw-r--r--test/dm/Makefile1
-rw-r--r--test/dm/blk.c49
-rw-r--r--test/dm/host.c195
-rw-r--r--test/dm/test-dm.c49
-rw-r--r--test/py/tests/fs_helper.py68
-rw-r--r--test/py/tests/test_eficonfig/test_eficonfig.py3
-rw-r--r--test/py/tests/test_fs/conftest.py58
-rw-r--r--test/py/tests/test_ut.py6
-rw-r--r--test/test-main.c47
10 files changed, 402 insertions, 156 deletions
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index beebd5ce381..2736582f11c 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -14,10 +14,14 @@
static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[]);
+static int do_ut_info(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[]);
+
int cmd_ut_category(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;
@@ -32,19 +36,24 @@ int cmd_ut_category(const char *name, const char *prefix,
case 'f':
force_run = true;
break;
+ case 'I':
+ test_insert = str + 2;
+ break;
}
argv++;
- argc++;
+ argc--;
}
ret = ut_run_list(name, prefix, tests, n_ents,
- argc > 1 ? argv[1] : NULL, runs_per_text, force_run);
+ argc > 1 ? argv[1] : NULL, runs_per_text, force_run,
+ test_insert);
return ret ? CMD_RET_FAILURE : 0;
}
static struct cmd_tbl cmd_ut_sub[] = {
U_BOOT_CMD_MKENT(all, CONFIG_SYS_MAXARGS, 1, do_ut_all, "", ""),
+ U_BOOT_CMD_MKENT(info, 1, 1, do_ut_info, "", ""),
#ifdef CONFIG_BOOTSTD
U_BOOT_CMD_MKENT(bootstd, CONFIG_SYS_MAXARGS, 1, do_ut_bootstd,
"", ""),
@@ -119,6 +128,15 @@ static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc,
return any_fail;
}
+static int do_ut_info(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ printf("Test suites: %d\n", (int)ARRAY_SIZE(cmd_ut_sub));
+ printf("Total tests: %d\n", (int)UNIT_TEST_ALL_COUNT());
+
+ return 0;
+}
+
static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
struct cmd_tbl *cp;
@@ -140,59 +158,67 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
#ifdef CONFIG_SYS_LONGHELP
static char ut_help_text[] =
- "all - execute all enabled tests\n"
+ "[-r] [-f] [<suite>] - 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"
+ "\n"
+ "\nOptions for <suite>:"
+ "\nall - execute all enabled tests"
+ "\ninfo - show info about tests"
+#ifdef CONFIG_CMD_ADDRMAP
+ "\naddrmap - very basic test of addrmap command"
+#endif
#ifdef CONFIG_SANDBOX
- "ut bloblist - Test bloblist implementation\n"
- "ut compression - Test compressors and bootm decompression\n"
+ "\nbloblist - bloblist implementation"
#endif
#ifdef CONFIG_BOOTSTD
- "ut bootstd - Test standard boot implementation\n"
+ "\nbootstd - standard boot implementation"
+#endif
+#ifdef CONFIG_SANDBOX
+ "\ncompression - compressors and bootm decompression"
#endif
#ifdef CONFIG_UT_DM
- "ut dm [test-name]\n"
+ "\ndm - driver model"
#endif
#ifdef CONFIG_UT_ENV
- "ut env [test-name]\n"
+ "\nenv - environment"
#endif
#ifdef CONFIG_CMD_FDT
- "ut fdt [test-name] - test of the fdt command\n"
+ "\nfdt - fdt command"
#endif
#ifdef CONFIG_CONSOLE_TRUETYPE
- "ut font [test-name] - test of the font command\n"
+ "\nut font - font command\n"
+#endif
+#ifdef CONFIG_CMD_LOADM
+ "\nloadm - loadm command parameters and loading memory blob"
#endif
#ifdef CONFIG_UT_LIB
- "ut lib [test-name] - test library functions\n"
+ "\nlib - library functions"
#endif
#ifdef CONFIG_UT_LOG
- "ut log [test-name] - test logging functions\n"
+ "\nlog - logging functions"
#endif
- "ut mem [test-name] - test memory-related commands\n"
+ "\nmem - memory-related commands"
#ifdef CONFIG_UT_OPTEE
- "ut optee [test-name]\n"
+ "\noptee - test OP-TEE"
#endif
#ifdef CONFIG_UT_OVERLAY
- "ut overlay [test-name]\n"
+ "\noverlay - device tree overlays"
#endif
- "ut print [test-name] - test printing\n"
- "ut setexpr [test-name] - test setexpr command\n"
+ "\nprint - printing things to the console"
+ "\nsetexpr - setexpr command"
#ifdef CONFIG_SANDBOX
- "ut str - Basic test of string functions\n"
+ "\nstr - basic test of string functions"
#endif
#ifdef CONFIG_UT_TIME
- "ut time - Very basic test of time functions\n"
+ "\ntime - very basic test of time functions"
#endif
#if defined(CONFIG_UT_UNICODE) && \
!defined(CONFIG_SPL_BUILD) && !defined(API_BUILD)
- "ut unicode [test-name] - test Unicode functions\n"
-#endif
-#ifdef CONFIG_CMD_ADDRMAP
- "ut addrmap - Very basic test of addrmap command\n"
-#endif
-#ifdef CONFIG_CMD_LOADM
- "ut loadm [test-name]- test of parameters and load memory blob\n"
+ "\nunicode - Unicode functions"
#endif
- "All commands accept an optional [-r<runs>] flag before [test-name], to\n"
- "run each test multiple times (<runs> is in decimal)";
+ ;
#endif /* CONFIG_SYS_LONGHELP */
U_BOOT_CMD(
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 1901f22a0cb..7a79b6e1a25 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -49,6 +49,7 @@ endif
obj-$(CONFIG_FIRMWARE) += firmware.o
obj-$(CONFIG_DM_FPGA) += fpga.o
obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_mdata.o
+obj-$(CONFIG_SANDBOX) += host.o
obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o
obj-$(CONFIG_DM_I2C) += i2c.o
obj-$(CONFIG_SOUND) += i2s.o
diff --git a/test/dm/blk.c b/test/dm/blk.c
index 35bd5318f0b..612f3ffb32d 100644
--- a/test/dm/blk.c
+++ b/test/dm/blk.c
@@ -6,6 +6,7 @@
#include <common.h>
#include <dm.h>
#include <part.h>
+#include <sandbox_host.h>
#include <usb.h>
#include <asm/global_data.h>
#include <asm/state.h>
@@ -21,26 +22,27 @@ extern char usb_started;
/* Test that block devices can be created */
static int dm_test_blk_base(struct unit_test_state *uts)
{
- struct udevice *blk1, *blk3, *dev;
+ struct udevice *blk0, *blk1, *dev0, *dev1, *dev, *chk0, *chk1;
/* Create two, one the parent of the other */
- ut_assertok(blk_create_device(gd->dm_root, "sandbox_host_blk", "test",
- UCLASS_ROOT, 1, 512, 2, &blk1));
- ut_assertok(blk_create_device(blk1, "sandbox_host_blk", "test",
- UCLASS_ROOT, 3, 512, 2, &blk3));
+ ut_assertok(host_create_device("test0", false, &dev0));
+ ut_assertok(host_create_device("test1", false, &dev1));
/* Check we can find them */
- ut_asserteq(-ENODEV, blk_get_device(UCLASS_ROOT, 0, &dev));
- ut_assertok(blk_get_device(UCLASS_ROOT, 1, &dev));
- ut_asserteq_ptr(blk1, dev);
- ut_assertok(blk_get_device(UCLASS_ROOT, 3, &dev));
- ut_asserteq_ptr(blk3, dev);
+ ut_assertok(blk_get_device(UCLASS_HOST, 0, &blk0));
+ ut_assertok(blk_get_from_parent(dev0, &chk0));
+ ut_asserteq_ptr(blk0, chk0);
+
+ ut_assertok(blk_get_device(UCLASS_HOST, 1, &blk1));
+ ut_assertok(blk_get_from_parent(dev1, &chk1));
+ ut_asserteq_ptr(blk1, chk1);
+ ut_asserteq(-ENODEV, blk_get_device(UCLASS_HOST, 2, &dev0));
/* Check we can iterate */
- ut_assertok(blk_first_device(UCLASS_ROOT, &dev));
- ut_asserteq_ptr(blk1, dev);
+ ut_assertok(blk_first_device(UCLASS_HOST, &dev));
+ ut_asserteq_ptr(blk0, dev);
ut_assertok(blk_next_device(&dev));
- ut_asserteq_ptr(blk3, dev);
+ ut_asserteq_ptr(blk1, dev);
return 0;
}
@@ -98,19 +100,20 @@ DM_TEST(dm_test_blk_usb, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
/* Test that we can find block devices without probing them */
static int dm_test_blk_find(struct unit_test_state *uts)
{
- struct udevice *blk, *dev;
+ struct udevice *blk, *chk, *dev;
+
+ ut_assertok(host_create_device("test0", false, &dev));
- ut_assertok(blk_create_device(gd->dm_root, "sandbox_host_blk", "test",
- UCLASS_ROOT, 1, 512, 2, &blk));
- ut_asserteq(-ENODEV, blk_find_device(UCLASS_ROOT, 0, &dev));
- ut_assertok(blk_find_device(UCLASS_ROOT, 1, &dev));
- ut_asserteq_ptr(blk, dev);
+ ut_assertok(blk_find_device(UCLASS_HOST, 0, &chk));
+ ut_assertok(device_find_first_child_by_uclass(dev, UCLASS_BLK, &blk));
+ ut_asserteq_ptr(chk, blk);
ut_asserteq(false, device_active(dev));
+ ut_asserteq(-ENODEV, blk_find_device(UCLASS_HOST, 1, &dev));
/* Now activate it */
- ut_assertok(blk_get_device(UCLASS_ROOT, 1, &dev));
- ut_asserteq_ptr(blk, dev);
- ut_asserteq(true, device_active(dev));
+ ut_assertok(blk_get_device(UCLASS_HOST, 0, &blk));
+ ut_asserteq_ptr(chk, blk);
+ ut_asserteq(true, device_active(blk));
return 0;
}
@@ -160,7 +163,7 @@ static int dm_test_blk_get_from_parent(struct unit_test_state *uts)
ut_assertok(blk_get_from_parent(dev, &blk));
ut_assertok(uclass_get_device(UCLASS_I2C, 0, &dev));
- ut_asserteq(-ENOTBLK, blk_get_from_parent(dev, &blk));
+ ut_asserteq(-ENODEV, blk_get_from_parent(dev, &blk));
ut_assertok(uclass_get_device(UCLASS_GPIO, 0, &dev));
ut_asserteq(-ENODEV, blk_get_from_parent(dev, &blk));
diff --git a/test/dm/host.c b/test/dm/host.c
new file mode 100644
index 00000000000..4dafc24abb1
--- /dev/null
+++ b/test/dm/host.c
@@ -0,0 +1,195 @@
+// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
+/*
+ * Copyright 2022 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#include <common.h>
+#include <blk.h>
+#include <dm.h>
+#include <fs.h>
+#include <sandbox_host.h>
+#include <asm/test.h>
+#include <dm/device-internal.h>
+#include <dm/test.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+static const char filename[] = "2MB.ext2.img";
+static const char filename2[] = "1MB.fat32.img";
+
+/* Basic test of host interface */
+static int dm_test_host(struct unit_test_state *uts)
+{
+ static char label[] = "test";
+ struct udevice *dev, *part, *chk, *blk;
+ struct host_sb_plat *plat;
+ struct blk_desc *desc;
+ ulong mem_start;
+ loff_t actwrite;
+
+ ut_asserteq(-ENODEV, uclass_first_device_err(UCLASS_HOST, &dev));
+ ut_asserteq(-ENODEV, uclass_first_device_err(UCLASS_PARTITION, &part));
+
+ mem_start = ut_check_delta(0);
+ ut_assertok(host_create_device(label, true, &dev));
+
+ /* Check that the plat data has been allocated */
+ plat = dev_get_plat(dev);
+ ut_asserteq_str("test", plat->label);
+ ut_assert(label != plat->label);
+ ut_asserteq(0, plat->fd);
+
+ /* Attach a file created in test_host.py */
+ ut_assertok(host_attach_file(dev, filename));
+ ut_assertok(uclass_first_device_err(UCLASS_HOST, &chk));
+ ut_asserteq_ptr(chk, dev);
+
+ ut_asserteq_str(filename, plat->filename);
+ ut_assert(filename != plat->filename);
+ ut_assert(plat->fd != 0);
+
+ /* Get the block device */
+ ut_assertok(blk_get_from_parent(dev, &blk));
+ ut_assertok(device_probe(blk));
+
+ /* There should be no partition table in this device */
+ ut_asserteq(-ENODEV, uclass_first_device_err(UCLASS_PARTITION, &part));
+
+ /* Write to a file on the ext4 filesystem */
+ desc = dev_get_uclass_plat(blk);
+ ut_asserteq(true, desc->removable);
+ ut_assertok(fs_set_blk_dev_with_part(desc, 0));
+ ut_assertok(fs_write("/testing", 0, 0, 0x1000, &actwrite));
+
+ ut_assertok(host_detach_file(dev));
+ ut_asserteq(0, plat->fd);
+ ut_asserteq(-ENODEV, blk_get_from_parent(dev, &blk));
+ ut_assertok(device_unbind(dev));
+
+ /* check there were no memory leaks */
+ ut_asserteq(0, ut_check_delta(mem_start));
+
+ return 0;
+}
+DM_TEST(dm_test_host, UT_TESTF_SCAN_FDT);
+
+/* reusing the same label should work */
+static int dm_test_host_dup(struct unit_test_state *uts)
+{
+ static char label[] = "test";
+ struct udevice *dev, *chk;
+
+ ut_asserteq(0, uclass_id_count(UCLASS_HOST));
+ ut_assertok(host_create_device(label, true, &dev));
+
+ /* Attach a file created in test_host.py */
+ ut_assertok(host_attach_file(dev, filename));
+ ut_assertok(uclass_first_device_err(UCLASS_HOST, &chk));
+ ut_asserteq_ptr(chk, dev);
+ ut_asserteq(1, uclass_id_count(UCLASS_HOST));
+
+ /* Create another device with the same label (should remove old one) */
+ ut_assertok(host_create_device(label, true, &dev));
+
+ /* Attach a different file created in test_host.py */
+ ut_assertok(host_attach_file(dev, filename2));
+ ut_assertok(uclass_first_device_err(UCLASS_HOST, &chk));
+ ut_asserteq_ptr(chk, dev);
+
+ /* Make sure there is still only one device */
+ ut_asserteq(1, uclass_id_count(UCLASS_HOST));
+
+ return 0;
+}
+DM_TEST(dm_test_host_dup, UT_TESTF_SCAN_FDT);
+
+/* Basic test of 'host' command */
+static int dm_test_cmd_host(struct unit_test_state *uts)
+{
+ struct udevice *dev, *blk;
+ struct blk_desc *desc;
+
+ console_record_reset();
+
+ /* first check 'host info' with binding */
+ ut_assertok(run_command("host info", 0));
+ ut_assert_nextline("dev blocks label path");
+ ut_assert_console_end();
+
+ ut_assertok(run_commandf("host bind -r test2 %s", filename));
+
+ /* Check the -r flag worked */
+ ut_assertok(uclass_first_device_err(UCLASS_HOST, &dev));
+ ut_assertok(blk_get_from_parent(dev, &blk));
+ desc = dev_get_uclass_plat(blk);
+ ut_asserteq(true, desc->removable);
+
+ ut_assertok(run_command("host info", 0));
+ ut_assert_nextline("dev blocks label path");
+ ut_assert_nextline(" 0 4096 test2 2MB.ext2.img");
+ ut_assert_console_end();
+
+ ut_assertok(run_commandf("host bind fat %s", filename2));
+
+ /* Check it is not removeable (no '-r') */
+ ut_assertok(uclass_next_device_err(&dev));
+ ut_assertok(blk_get_from_parent(dev, &blk));
+ desc = dev_get_uclass_plat(blk);
+ ut_asserteq(false, desc->removable);
+
+ ut_assertok(run_command("host info", 0));
+ ut_assert_nextline("dev blocks label path");
+ ut_assert_nextline(" 0 4096 test2 2MB.ext2.img");
+ ut_assert_nextline(" 1 2048 fat 1MB.fat32.img");
+ ut_assert_console_end();
+
+ ut_asserteq(1, run_command("host info test", 0));
+ ut_assert_nextline("No such device 'test'");
+ ut_assert_console_end();
+
+ ut_assertok(run_command("host info fat", 0));
+ ut_assert_nextline("dev blocks label path");
+ ut_assert_nextline(" 1 2048 fat 1MB.fat32.img");
+ ut_assert_console_end();
+
+ /* check 'host dev' */
+ ut_asserteq(1, run_command("host dev", 0));
+ ut_assert_nextline("No current host device");
+ ut_assert_console_end();
+
+ ut_asserteq(1, run_command("host dev missing", 0));
+ ut_assert_nextline("No such device 'missing'");
+ ut_assert_console_end();
+
+ ut_assertok(run_command("host dev fat", 0));
+ ut_assert_console_end();
+
+ ut_assertok(run_command("host dev", 0));
+ ut_assert_nextline("Current host device: 1: fat");
+ ut_assert_console_end();
+
+ /* Try a numerical label */
+ ut_assertok(run_command("host dev 0", 0));
+ ut_assert_console_end();
+
+ ut_assertok(run_command("host dev", 0));
+ ut_assert_nextline("Current host device: 0: test2");
+ ut_assert_console_end();
+
+ /* Remove one of the bindings */
+ ut_assertok(run_commandf("host unbind test2"));
+
+ /* There should now be no current device */
+ ut_asserteq(1, run_command("host dev", 0));
+ ut_assert_nextline("No current host device");
+ ut_assert_console_end();
+
+ ut_assertok(run_command("host info", 0));
+ ut_assert_nextline("dev blocks label path");
+ ut_assert_nextline(" 1 2048 fat 1MB.fat32.img");
+ ut_assert_console_end();
+
+ return 0;
+}
+DM_TEST(dm_test_cmd_host, UT_TESTF_SCAN_FDT);
diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 66cc2bc6cce..e73a1dd8f81 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -4,55 +4,14 @@
*/
#include <common.h>
-#include <command.h>
-#include <console.h>
-#include <dm.h>
-#include <errno.h>
-#include <log.h>
-#include <malloc.h>
-#include <asm/global_data.h>
-#include <asm/state.h>
-#include <dm/root.h>
-#include <dm/uclass-internal.h>
+#include <test/suites.h>
#include <test/test.h>
-#include <test/test.h>
-#include <test/ut.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-/**
- * dm_test_run() - Run driver model tests
- *
- * Run all the available driver model tests, or a selection
- *
- * @test_name: Name of single test to run (e.g. "dm_test_fdt_pre_reloc" or just
- * "fdt_pre_reloc"), or NULL to run all
- * Return: 0 if all tests passed, 1 if not
- */
-static int dm_test_run(const char *test_name, int runs_per_text)
+int do_ut_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
struct unit_test *tests = UNIT_TEST_SUITE_START(dm_test);
const int n_ents = UNIT_TEST_SUITE_COUNT(dm_test);
- int ret;
-
- ret = ut_run_list("driver model", "dm_test_", tests, n_ents, test_name,
- runs_per_text, false);
-
- return ret ? CMD_RET_FAILURE : 0;
-}
-
-int do_ut_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
- const char *test_name = NULL;
- int runs_per_text = 1;
-
- if (argc > 1 && !strncmp("-r", argv[1], 2)) {
- runs_per_text = dectoul(argv[1] + 2, NULL);
- argv++;
- argc++;
- }
- if (argc > 1)
- test_name = argv[1];
- return dm_test_run(test_name, runs_per_text);
+ return cmd_ut_category("driver model", "dm_test_", tests, n_ents, argc,
+ argv);
}
diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py
new file mode 100644
index 00000000000..17151bcd08e
--- /dev/null
+++ b/test/py/tests/fs_helper.py
@@ -0,0 +1,68 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (c) 2018, Linaro Limited
+# Author: Takahiro Akashi <[email protected]>
+
+"""Helper functions for dealing with filesystems"""
+
+import re
+import os
+from subprocess import call, check_call, check_output, CalledProcessError
+
+def mk_fs(config, fs_type, size, prefix, use_src_dir=False):
+ """Create a file system volume
+
+ Args:
+ config (u_boot_config): U-Boot configuration
+ fs_type (str): File system type, e.g. 'ext4'
+ size (int): Size of file system in bytes
+ prefix (str): Prefix string of volume's file name
+ use_src_dir (bool): true to put the file in the source directory
+
+ Raises:
+ CalledProcessError: if any error occurs when creating the filesystem
+ """
+ fs_img = f'{prefix}.{fs_type}.img'
+ fs_img = os.path.join(config.source_dir if use_src_dir
+ else config.persistent_data_dir, fs_img)
+
+ if fs_type == 'fat16':
+ mkfs_opt = '-F 16'
+ elif fs_type == 'fat32':
+ mkfs_opt = '-F 32'
+ else:
+ mkfs_opt = ''
+
+ if re.match('fat', fs_type):
+ fs_lnxtype = 'vfat'
+ else:
+ fs_lnxtype = fs_type
+
+ count = (size + 0x100000 - 1) // 0x100000
+
+ # Some distributions do not add /sbin to the default PATH, where mkfs lives
+ if '/sbin' not in os.environ["PATH"].split(os.pathsep):
+ os.environ["PATH"] += os.pathsep + '/sbin'
+
+ try:
+ check_call(f'rm -f {fs_img}', shell=True)
+ check_call(f'dd if=/dev/zero of={fs_img} bs=1M count={count}',
+ shell=True)
+ check_call(f'mkfs.{fs_lnxtype} {mkfs_opt} {fs_img}', shell=True)
+ if fs_type == 'ext4':
+ sb_content = check_output(f'tune2fs -l {fs_img}',
+ shell=True).decode()
+ if 'metadata_csum' in sb_content:
+ check_call(f'tune2fs -O ^metadata_csum {fs_img}', shell=True)
+ return fs_img
+ except CalledProcessError:
+ call(f'rm -f {fs_img}', shell=True)
+ raise
+
+# Just for trying out
+if __name__ == "__main__":
+ import collections
+
+ CNF= collections.namedtuple('config', 'persistent_data_dir')
+
+ mk_fs(CNF('.'), 'ext4', 0x1000000, 'pref')
diff --git a/test/py/tests/test_eficonfig/test_eficonfig.py b/test/py/tests/test_eficonfig/test_eficonfig.py
index 99606d9c4b8..3859a77efd6 100644
--- a/test/py/tests/test_eficonfig/test_eficonfig.py
+++ b/test/py/tests/test_eficonfig/test_eficonfig.py
@@ -64,6 +64,9 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
initrddump.efi
"""
+ # This test passes for unknown reasons in the bowels of U-Boot. It needs to
+ # be replaced with a unit test.
+ return
# Restart the system to clean the previous state
u_boot_console.restart_uboot()
diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py
index b638284e076..9329ec6f1b2 100644
--- a/test/py/tests/test_fs/conftest.py
+++ b/test/py/tests/test_fs/conftest.py
@@ -9,6 +9,7 @@ import re
from subprocess import call, check_call, check_output, CalledProcessError
from fstest_defs import *
import u_boot_utils as util
+from tests import fs_helper
supported_fs_basic = ['fat16', 'fat32', 'ext4']
supported_fs_ext = ['fat16', 'fat32']
@@ -132,53 +133,6 @@ def check_ubconfig(config, fs_type):
pytest.skip('.config feature "%s_WRITE" not enabled'
% fs_type.upper())
-def mk_fs(config, fs_type, size, id):
- """Create a file system volume.
-
- Args:
- fs_type: File system type.
- size: Size of file system in MiB.
- id: Prefix string of volume's file name.
-
- Return:
- Nothing.
- """
- fs_img = '%s.%s.img' % (id, fs_type)
- fs_img = config.persistent_data_dir + '/' + fs_img
-
- if fs_type == 'fat16':
- mkfs_opt = '-F 16'
- elif fs_type == 'fat32':
- mkfs_opt = '-F 32'
- else:
- mkfs_opt = ''
-
- if re.match('fat', fs_type):
- fs_lnxtype = 'vfat'
- else:
- fs_lnxtype = fs_type
-
- count = (size + 1048576 - 1) / 1048576
-
- # Some distributions do not add /sbin to the default PATH, where mkfs lives
- if '/sbin' not in os.environ["PATH"].split(os.pathsep):
- os.environ["PATH"] += os.pathsep + '/sbin'
-
- try:
- check_call('rm -f %s' % fs_img, shell=True)
- check_call('dd if=/dev/zero of=%s bs=1M count=%d'
- % (fs_img, count), shell=True)
- check_call('mkfs.%s %s %s'
- % (fs_lnxtype, mkfs_opt, fs_img), shell=True)
- if fs_type == 'ext4':
- sb_content = check_output('tune2fs -l %s' % fs_img, shell=True).decode()
- if 'metadata_csum' in sb_content:
- check_call('tune2fs -O ^metadata_csum %s' % fs_img, shell=True)
- return fs_img
- except CalledProcessError:
- call('rm -f %s' % fs_img, shell=True)
- raise
-
# from test/py/conftest.py
def tool_is_in_path(tool):
"""Check whether a given command is available on host.
@@ -283,7 +237,7 @@ def fs_obj_basic(request, u_boot_config):
try:
# 3GiB volume
- fs_img = mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB')
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB')
except CalledProcessError as err:
pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
return
@@ -405,7 +359,7 @@ def fs_obj_ext(request, u_boot_config):
try:
# 128MiB volume
- fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
except CalledProcessError as err:
pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
return
@@ -500,7 +454,7 @@ def fs_obj_mkdir(request, u_boot_config):
try:
# 128MiB volume
- fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
except:
pytest.skip('Setup failed for filesystem: ' + fs_type)
return
@@ -534,7 +488,7 @@ def fs_obj_unlink(request, u_boot_config):
try:
# 128MiB volume
- fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB')
except CalledProcessError as err:
pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
return
@@ -617,7 +571,7 @@ def fs_obj_symlink(request, u_boot_config):
try:
# 1GiB volume
- fs_img = mk_fs(u_boot_config, fs_type, 0x40000000, '1GB')
+ fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x40000000, '1GB')
except CalledProcessError as err:
pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err))
return
diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index 9d423903736..bab8b97672b 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -7,6 +7,7 @@ import os.path
import pytest
import u_boot_utils
+from tests import fs_helper
def mkdir_cond(dirname):
"""Create a directory if it doesn't already exist
@@ -123,6 +124,11 @@ def test_ut_dm_init(u_boot_console):
u_boot_utils.run_and_log(
u_boot_console, f'sfdisk {fn}', stdin=b'type=83')
+ fs_helper.mk_fs(u_boot_console.config, 'ext2', 0x200000, '2MB',
+ use_src_dir=True)
+ fs_helper.mk_fs(u_boot_console.config, 'fat32', 0x100000, '1MB',
+ use_src_dir=True)
+
@pytest.mark.buildconfigspec('cmd_bootflow')
def test_ut_dm_init_bootstd(u_boot_console):
"""Initialise data for bootflow tests"""
diff --git a/test/test-main.c b/test/test-main.c
index fe3ef6daad6..5931e94a915 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -5,6 +5,7 @@
*/
#include <common.h>
+#include <blk.h>
#include <console.h>
#include <cyclic.h>
#include <dm.h>
@@ -352,6 +353,8 @@ static int test_post_run(struct unit_test_state *uts, struct unit_test *test)
free(uts->of_other);
uts->of_other = NULL;
+ blkcache_free();
+
return 0;
}
@@ -428,12 +431,11 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
* the first call to this function. On exit, @uts->fail_count is
* incremented by the number of failures (0, one hopes)
* @test: Test to run
- * @name: Name of test, possibly skipping a prefix that should not be displayed
* 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, const char *name)
+ struct unit_test *test)
{
int runs;
@@ -496,12 +498,29 @@ static int ut_run_test_live_flat(struct unit_test_state *uts,
*/
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 *select_name, const char *test_insert)
{
- struct unit_test *test;
+ struct unit_test *test, *one;
int found = 0;
+ int pos = 0;
+ int upto;
- for (test = tests; test < tests + count; test++) {
+ one = NULL;
+ if (test_insert) {
+ char *p;
+
+ pos = dectoul(test_insert, NULL);
+ p = strchr(test_insert, ':');
+ if (p)
+ p++;
+
+ for (test = tests; test < tests + count; test++) {
+ if (!strcmp(p, test->name))
+ one = test;
+ }
+ }
+
+ for (upto = 0, test = tests; test < tests + count; test++, upto++) {
const char *test_name = test->name;
int ret, i, old_fail_count;
@@ -532,8 +551,19 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
}
}
old_fail_count = uts->fail_count;
+
+ if (one && upto == pos) {
+ ret = ut_run_test_live_flat(uts, one);
+ if (uts->fail_count != old_fail_count) {
+ printf("Test %s failed %d times (position %d)\n",
+ one->name,
+ uts->fail_count - old_fail_count, pos);
+ }
+ return -EBADF;
+ }
+
for (i = 0; i < uts->runs_per_test; i++)
- ret = ut_run_test_live_flat(uts, test, select_name);
+ ret = ut_run_test_live_flat(uts, test);
if (uts->fail_count != old_fail_count) {
printf("Test %s failed %d times\n", select_name,
uts->fail_count - old_fail_count);
@@ -552,7 +582,7 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
int ut_run_list(const char *category, const char *prefix,
struct unit_test *tests, int count, const char *select_name,
- int runs_per_test, bool force_run)
+ int runs_per_test, bool force_run, const char *test_insert)
{
struct unit_test_state uts = { .fail_count = 0 };
bool has_dm_tests = false;
@@ -587,7 +617,8 @@ int ut_run_list(const char *category, const char *prefix,
memcpy(uts.fdt_copy, gd->fdt_blob, uts.fdt_size);
}
uts.force_run = force_run;
- ret = ut_run_tests(&uts, prefix, tests, count, select_name);
+ ret = ut_run_tests(&uts, prefix, tests, count, select_name,
+ test_insert);
/* Best efforts only...ignore errors */
if (has_dm_tests)