dm: sandbox: Add a new HOST uclass
cover dm: sandbox: Add a new HOST uclass
At present sandbox uses the root device as the parent for block devices it creates to provide access to files on the host. This is convenient but is not really correct, since the root device should not have any particular meaning for its children.
This series tidies this up, introducing a new uclass and updating the implementation accordingly. Rather than numbering host devices, it is now possible to provide a label, which is easier to deal with.
The host command has some minor updates, including showing the label. A test and documentation are added for it also.
A few other minor improvements are included also.
Simon Glass (17):
dm: sandbox: Drop non-BLK code from host implementation
sandbox: Add missing comments for os_alarm()
test: Split out mk_fs function into a helper
test: Correct pylint warnings in fs_helper
dm: test: Drop the special function for running DM tests
dm: test: Clear the block cache after running a test
test: Drop an unused parameter to ut_run_test_live_flat()
test: Tidy up help for ut command
test: doc: Add documentation for ut command
test: Allow showing basic information about tests
test: Add a way to detect a test that breaks another
dm: blk: Tidy up obtaining a block device from its parent
dm: sandbox: Create a new HOST uclass
dm: sandbox: Create a block driver
dm: sandbox: Switch over to using the new host uclass
dm: Add documentation for host command and implementation
dm: Add tests for the sandbox host driver
arch/sandbox/cpu/spl.c | 2 +-
arch/sandbox/dts/sandbox.dts | 4 -
cmd/host.c | 210 ++++++++++------
disk/part.c | 4 +-
doc/arch/index.rst | 2 +-
doc/arch/sandbox/block_impl.rst | 39 +++
doc/arch/sandbox/index.rst | 12 +
doc/arch/{ => sandbox}/sandbox.rst | 9 +-
doc/develop/tests_sandbox.rst | 69 +++++
doc/usage/cmd/host.rst | 116 +++++++++
doc/usage/cmd/ut.rst | 117 +++++++++
doc/usage/index.rst | 2 +
drivers/block/Makefile | 2 +-
drivers/block/blk-uclass.c | 28 ++-
drivers/block/blkcache.c | 23 +-
drivers/block/host-uclass.c | 176 +++++++++++++
drivers/block/host_dev.c | 142 +++++++++++
drivers/block/sandbox.c | 236 ++----------------
include/blk.h | 37 ++-
include/dm/uclass-id.h | 1 +
include/os.h | 4 +
include/sandbox_host.h | 125 ++++++++++
include/sandboxblockdev.h | 31 ---
include/test/ut.h | 7 +-
lib/efi_loader/efi_device_path.c | 5 +-
lib/efi_loader/efi_disk.c | 2 +-
test/cmd_ut.c | 80 ++++--
test/dm/Makefile | 1 +
test/dm/blk.c | 49 ++--
test/dm/host.c | 195 +++++++++++++++
test/dm/test-dm.c | 49 +---
test/py/tests/fs_helper.py | 68 +++++
.../py/tests/test_eficonfig/test_eficonfig.py | 3 +
test/py/tests/test_fs/conftest.py | 58 +----
test/py/tests/test_ut.py | 6 +
test/test-main.c | 47 +++-
36 files changed, 1435 insertions(+), 526 deletions(-)
create mode 100644 doc/arch/sandbox/block_impl.rst
create mode 100644 doc/arch/sandbox/index.rst
rename doc/arch/{ => sandbox}/sandbox.rst (98%)
create mode 100644 doc/usage/cmd/host.rst
create mode 100644 doc/usage/cmd/ut.rst
create mode 100644 drivers/block/host-uclass.c
create mode 100644 drivers/block/host_dev.c
create mode 100644 include/sandbox_host.h
delete mode 100644 include/sandboxblockdev.h
create mode 100644 test/dm/host.c
create mode 100644 test/py/tests/fs_helper.pySignature · 1 line
2.38.1.273.g43a17bfeac-goog
PATCH 1/17 dm: sandbox: Drop non-BLK code from host implementation
This is not used anymore. Drop it.
---
cmd/host.c | 4 -- drivers/block/sandbox.c | 102 -------------------------------------- include/sandboxblockdev.h | 3 -- 3 files changed, 109 deletions(-)
cmd/host.c +0 -4
@@ -108,11 +108,7 @@ static int do_host_info(struct cmd_tbl *cmdtp, int flag, int argc, }struct host_block_dev *host_dev; -#ifdef CONFIG_BLK host_dev =dev_get_plat (blk_dev->bdev); -#else - host_dev = blk_dev->priv; -#endif printf ("%12lu %s\n" , (unsigned long )blk_dev->lba, host_dev->filename); }
drivers/block/sandbox.c +0 -102
154 lines not on this page · raw message
include/sandboxblockdev.h +0 -3
@@ -10,9 +10,6 @@#define SANDBOX_HOST_MAX_DEVICES 4struct host_block_dev { -#ifndef CONFIG_BLK -struct blk_desc blk_dev; -#endif char *filename;int fd; };
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Re: [PATCH 01/17] dm: sandbox: Drop non-BLK code from host implementation
This is not used anymore. Drop it.
---
cmd/host.c | 4 -- drivers/block/sandbox.c | 102 -------------------------------------- include/sandboxblockdev.h | 3 -- 3 files changed, 109 deletions(-)
Applied to u-boot-dm, thanks!
PATCH 2/17 sandbox: Add missing comments for os_alarm()
In reply to Simon GlassAdd the documentation to avoid a warning with 'make htmldocs'.
---
include/os.h | 4 ++++ 1 file changed, 4 insertions(+)
include/os.h +4 -0
@@ -110,6 +110,10 @@ void os_exit(int exit_code) __attribute__((noreturn));/** * os_alarm() - access to the OS alarm() system call +* +* @seconds: number of seconds before the signal is sent +* Returns: number of seconds remaining until any previously scheduled alarm was +* due to be delivered; 0 if there was no previously scheduled alarm */ unsigned int os_alarm (unsigned int seconds);
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Re: [PATCH 02/17] sandbox: Add missing comments for os_alarm()
Add the documentation to avoid a warning with 'make htmldocs'.
---
include/os.h | 4 ++++ 1 file changed, 4 insertions(+)
Applied to u-boot-dm, thanks!
Re: [PATCH 02/17] sandbox: Add missing comments for os_alarm()
In reply to Simon GlassQuoted 15 lines · Simon Glass
Add the documentation to avoid a warning with 'make htmldocs'.
Fixes 10107efedd5 ("sandbox: add SIGALRM-based watchdog device")Signed-off-by Simon Glass <[email protected]>---
include/os.h | 4 ++++ 1 file changed, 4 insertions(+)include/os.h +0
-0
include/os.h void os_exit(int exit_code) __attribute__((noreturn)); · line 112
Quoted 3 lines
include/os.h +0
-0@@ -110,6 +110,10 @@ void os_exit(int exit_code) __attribute__((noreturn));/** * os_alarm() - access to the OS alarm() system call
alarm() is not a system call but a POSIX function.
Best regards
Heinrich
Quoted 7 lines
include/os.h +4
-0+* +* @seconds: number of seconds before the signal is sent +* Returns: number of seconds remaining until any previously scheduled alarm was +* due to be delivered; 0 if there was no previously scheduled alarm */ unsigned int os_alarm (unsigned int seconds);
Re: [PATCH 02/17] sandbox: Add missing comments for os_alarm()
Hi Heinrich,
Quoted 18 lines · Heinrich Schuchardt
Quoted 16 lines · Simon Glass
Add the documentation to avoid a warning with 'make htmldocs'.
Fixes 10107efedd5 ("sandbox: add SIGALRM-based watchdog device")Signed-off-by Simon Glass <[email protected]>---
include/os.h | 4 ++++ 1 file changed, 4 insertions(+)include/os.h +0
-0@@ -110,6 +110,10 @@ void os_exit(int exit_code) __attribute__((noreturn));
Quoted 4 lines
include/os.h void os_exit(int exit_code) __attribute__((noreturn)); · line 112
Quoted 2 lines
include/os.h +0
-0/** * os_alarm() - access to the OS alarm() system call
alarm()is not a system call but a POSIX function.
I saw this in the other thread.
I would say that alarm() is a system call which is why it is in section 2 of the manual. I don't really care but someone else feels the same way.
Do you feel strongly about this?
Regards,
Simon
PATCH 3/17 test: Split out mk_fs function into a helper
In reply to Simon GlassThis function is useful for other tests. Move it into common code.
---
test/py/tests/fs_helper.py | 54 ++++++++++++++++++++++++++++ test/py/tests/test_fs/conftest.py | 58 ++++--------------------------- 2 files changed, 60 insertions(+), 52 deletions(-) create mode 100644 test/py/tests/fs_helper.py
test/py/tests/fs_helper.py new file +54 -0
@@ -0,0 +1,54 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Helper functions for dealing with filesystems +# +# Copyright (c) 2018, Linaro Limited +# Author: Takahiro Akashi <[email protected]> + +import re +import os +from subprocess import call, check_call, check_output, CalledProcessError + +def mk_fs(config, fs_type, size, prefix): + """Create a file system volume + + Args: + 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 + """ + fs_img = '%s.%s.img' % (prefix, 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
test/py/tests/test_fs/conftest.py +6 -52
100 lines not on this page · raw message
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Re: [PATCH 03/17] test: Split out mk_fs function into a helper
This function is useful for other tests. Move it into common code.
---
test/py/tests/fs_helper.py | 54 ++++++++++++++++++++++++++++ test/py/tests/test_fs/conftest.py | 58 ++++--------------------------- 2 files changed, 60 insertions(+), 52 deletions(-) create mode 100644 test/py/tests/fs_helper.py
Applied to u-boot-dm, thanks!
PATCH 4/17 test: Correct pylint warnings in fs_helper
In reply to Simon GlassTidy this up so that pylint is happy. Use hex for the 1MB size and make sure it is not a floating-point value.
Add a little main program to allow the code to be tried out, since at present is only called from a long-running test.
---
test/py/tests/fs_helper.py | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-)
test/py/tests/fs_helper.py +25 -13
@@ -1,10 +1,10 @@ # SPDX-License-Identifier: GPL-2.0+ # -# Helper functions for dealing with filesystems -# # 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
@@ -13,12 +13,16 @@ def mk_fs(config, fs_type, size, prefix): """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 + + Raises: + CalledProcessError: if any error occurs when creating the filesystem """ - fs_img = '%s.%s.img' % (prefix, fs_type) - fs_img = config.persistent_data_dir + '/' + fs_img + fs_img = f'{prefix}.{fs_type}.img' + fs_img = os.path.join(config.persistent_data_dir, fs_img) if fs_type == 'fat16': mkfs_opt = '-F 16'
@@ -32,23 +36,31 @@ def mk_fs(config, fs_type, size, prefix): else: fs_lnxtype = fs_type - count = (size + 1048576 - 1) / 1048576 + 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('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) + 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('tune2fs -l %s' % fs_img, shell=True).decode() + sb_content = check_output(f'tune2fs -l {fs_img}', + shell=True).decode() if 'metadata_csum' in sb_content: - check_call('tune2fs -O ^metadata_csum %s' % fs_img, shell=True) + check_call(f'tune2fs -O ^metadata_csum {fs_img}', shell=True) return fs_img except CalledProcessError: - call('rm -f %s' % fs_img, shell=True) + 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')
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Re: [PATCH 04/17] test: Correct pylint warnings in fs_helper
Tidy this up so that pylint is happy. Use hex for the 1MB size and make sure it is not a floating-point value.
Add a little main program to allow the code to be tried out, since at present is only called from a long-running test.
---
test/py/tests/fs_helper.py | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-)
Applied to u-boot-dm, thanks!
PATCH 5/17 dm: test: Drop the special function for running DM tests
In reply to Simon GlassThis is not needed since the flag takes care of all differences. Make use of the common function.
---
test/dm/test-dm.c | 49 ++++------------------------------------------- 1 file changed, 4 insertions(+), 45 deletions(-)
test/dm/test-dm.c +4 -45
@@ -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); }
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Re: [PATCH 05/17] dm: test: Drop the special function for running DM tests
This is not needed since the flag takes care of all differences. Make use of the common function.
---
test/dm/test-dm.c | 49 ++++------------------------------------------- 1 file changed, 4 insertions(+), 45 deletions(-)
Applied to u-boot-dm, thanks!
PATCH 6/17 dm: test: Clear the block cache after running a test
In reply to Simon GlassSome tests access data in block devices and so cause the cache to fill up. This results in memory being allocated.
Some tests check the malloc usage at the beginning and then again at the end, to ensure there is no memory leak caused by the test. The block cache makes this difficult, since the any test may cause entries to be allocated or even freed, if the cache becomes full.
It is simpler to clear the block cache after each test. This ensures that it will not introduce noise in tests which check malloc usage.
Add the logic to clear the cache, using the existing blkcache_invalidate() function. Drop the duplicate code at the same time.
---
drivers/block/blkcache.c | 23 ++++++++++------------- include/blk.h | 9 +++++++-- test/test-main.c | 3 +++ 3 files changed, 20 insertions(+), 15 deletions(-)
drivers/block/blkcache.c +10 -13
@@ -150,8 +150,8 @@ void blkcache_invalidate(int iftype, int devnum)list_for_each_safe (entry, n, &block_cache) { node = (struct block_cache_node *)entry; -if ((node->iftype == iftype) && - (node->devnum == devnum)) { +if (iftype ==-1 || + (node->iftype == iftype && node->devnum == devnum)) {list_del (entry);free (node->cache);free (node);
@@ -162,18 +162,10 @@ void blkcache_invalidate(int iftype, int devnum)void blkcache_configure (unsigned blocks,unsigned entries) { -struct block_cache_node *node; +/* invalidate cache if there is a change */ if ((blocks != _stats.max_blocks_per_entry) || - (entries != _stats.max_entries)) { -/* invalidate cache */ -while (!list_empty (&block_cache)) { - node = (struct block_cache_node *)block_cache.next; -list_del (&node->lh); -free (node->cache); -free (node); - } - _stats.entries =0 ; - } + (entries != _stats.max_entries)) +blkcache_invalidate (-1 ,0 ); _stats.max_blocks_per_entry = blocks; _stats.max_entries = entries;
@@ -188,3 +180,8 @@ void blkcache_stats(struct block_cache_stats *stats) _stats.hits =0 ; _stats.misses =0 ; } + +void blkcache_free (void ) +{ +blkcache_invalidate (-1 ,0 ); +}
include/blk.h +7 -2
@@ -147,8 +147,8 @@ void blkcache_fill(int iftype, int dev,* blkcache_invalidate() - discard the cache for a set of blocks * because of a write or device (re)initialization. * -* @param iftype - uclass_id_x for type of device -* @param dev - device index of particular type +* @iftype - UCLASS_ID_ for type of device, or -1 for any +* @dev - device index of particular type, if @iftype is not -1 */ void blkcache_invalidate (int iftype,int dev);
@@ -178,6 +178,9 @@ struct block_cache_stats {*/ void blkcache_stats (struct block_cache_stats *stats); +/** blkcache_free() - free all memory allocated to the block cache */ +void blkcache_free (void ); +#else static inline int blkcache_read(int iftype, int dev,
@@ -193,6 +196,8 @@ static inline void blkcache_fill(int iftype, int dev,static inline void blkcache_invalidate (int iftype,int dev) {} +static inline void blkcache_free (void ) {} +#endif #if CONFIG_IS_ENABLED (BLK )
test/test-main.c +3 -0
@@ -5,6 +5,7 @@*/ #include <common.h> +#include <blk.h> #include <console.h> #include <cyclic.h> #include <dm.h>
@@ -353,6 +354,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 ; }
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Re: [PATCH 06/17] dm: test: Clear the block cache after running a test
Some tests access data in block devices and so cause the cache to fill up. This results in memory being allocated.
Some tests check the malloc usage at the beginning and then again at the end, to ensure there is no memory leak caused by the test. The block cache makes this difficult, since the any test may cause entries to be allocated or even freed, if the cache becomes full.
It is simpler to clear the block cache after each test. This ensures that it will not introduce noise in tests which check malloc usage.
Add the logic to clear the cache, using the existing blkcache_invalidate() function. Drop the duplicate code at the same time.
---
drivers/block/blkcache.c | 23 ++++++++++------------- include/blk.h | 9 +++++++-- test/test-main.c | 3 +++ 3 files changed, 20 insertions(+), 15 deletions(-)
Applied to u-boot-dm, thanks!
PATCH 7/17 test: Drop an unused parameter to ut_run_test_live_flat()
In reply to Simon GlassThe select_name parameter is not used anymore. Drop it.
---
test/test-main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
test/test-main.c +2 -3
@@ -432,12 +432,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;
@@ -537,7 +536,7 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix, } old_fail_count = uts->fail_count;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);
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Re: [PATCH 07/17] test: Drop an unused parameter to ut_run_test_live_flat()
The select_name parameter is not used anymore. Drop it.
---
test/test-main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
Applied to u-boot-dm, thanks!
PATCH 8/17 test: Tidy up help for ut command
In reply to Simon GlassSort this and put the command summary at the top instead of the bottom.
Adjust it so that the newlines are at the start of the strings, so that there is not a blank line at the end.
---
test/cmd_ut.c | 57 +++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 25 deletions(-)
test/cmd_ut.c +32 -25
@@ -137,56 +137,63 @@ 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" +"Suites:" +"\nall - execute all enabled 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_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(
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Re: [PATCH 08/17] test: Tidy up help for ut command
Sort this and put the command summary at the top instead of the bottom.
Adjust it so that the newlines are at the start of the strings, so that there is not a blank line at the end.
---
test/cmd_ut.c | 57 +++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 25 deletions(-)
Applied to u-boot-dm, thanks!
PATCH 9/17 test: doc: Add documentation for ut command
In reply to Simon GlassBefore adding more options, document this command.
---
doc/usage/cmd/ut.rst | 102 +++++++++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 2 files changed, 103 insertions(+) create mode 100644 doc/usage/cmd/ut.rst
doc/usage/cmd/ut.rst new file +102 -0
@@ -0,0 +1,102 @@ +.. SPDX-License-Identifier: GPL-2.0+: + +ut command +========== + +Synopis +------- + +:: + + ut [-r<runs>] [-f] [<suite> [<test>]] + + <runs> Number of times to run each test + -f Force 'manual' tests to run as well + <suite> Test suite to run, or `all` + <test> Name of single test to run + +Description +----------- + +The ut command runs unit tests written in C. + +Typically the command is run on :ref:`arch/sandbox/sandbox:sandbox` since it +includes a near-complete set of emulators, no code-size limits, many CONFIG +options enabled and runs easily in CI without needing QEMU. It is also possible +to run some tests on real boards. + +For a list of available test suites, type `ut` by itself. + +Each test is normally run once, although those marked with `UT_TESTF_DM` are +run with livetree and flattree where possible. To run a test more than once, +use the `-r` flag. + +Manual tests are normally skipped by this command. Use `-f` to run them. See +See :ref:`develop/tests_writing:mixing python and c` for more information on +manual test. + +Generally all tests in the suite are run. To run just a single test from the +suite, provide the <test> argument. + +See :ref:`develop/tests_writing:writing c tests` for more information on how to +write unit tests. + +Example +------- + +List available unit-test suites:: + + => ut + ut - unit tests + + Usage: + ut [-r] [-f] [<suite>] - run unit tests + -r<runs> Number of times to run each test + -f Force 'manual' tests to run as well + <suite> Test suite to run, or all + + Suites: + all - execute all enabled tests + addrmap - very basic test of addrmap command + bloblist - bloblist implementation + bootstd - standard boot implementation + compression - compressors and bootm decompression + dm - driver model + env - environment + fdt - fdt command + loadm - loadm command parameters and loading memory blob + lib - library functions + log - logging functions + mem - memory-related commands + overlay - device tree overlays + print - printing things to the console + setexpr - setexpr command + str - basic test of string functions + time - very basic test of time functions + unicode - Unicode functions + +Run one of the suites:: + + => ut bloblist + Running 14 bloblist tests + Test: bloblist_test_align: bloblist.c + Test: bloblist_test_bad_blob: bloblist.c + Test: bloblist_test_blob: bloblist.c + Test: bloblist_test_blob_ensure: bloblist.c + Test: bloblist_test_blob_maxsize: bloblist.c + Test: bloblist_test_checksum: bloblist.c + Test: bloblist_test_cmd_info: bloblist.c + Test: bloblist_test_cmd_list: bloblist.c + Test: bloblist_test_grow: bloblist.c + Test: bloblist_test_init: bloblist.c + Test: bloblist_test_reloc: bloblist.c + Test: bloblist_test_resize_fail: bloblist.c + Test: bloblist_test_resize_last: bloblist.c + Test: bloblist_test_shrink: bloblist.c + Failures: 0 + +Run just a single test in a suite:: + + => ut bloblist bloblist_test_grow + Test: bloblist_test_grow: bloblist.c + Failures: 0
doc/usage/index.rst +1 -0
@@ -72,6 +72,7 @@ Shell commands cmd/tftpput cmd/true cmd/ums + cmd/ut cmd/wdt cmd/xxd
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Re: [PATCH 09/17] test: doc: Add documentation for ut command
Before adding more options, document this command.
---
doc/usage/cmd/ut.rst | 102 +++++++++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 2 files changed, 103 insertions(+) create mode 100644 doc/usage/cmd/ut.rst
Applied to u-boot-dm, thanks!
PATCH 10/17 test: Allow showing basic information about tests
In reply to Simon GlassAdd a 'ut info' command to show the number of suites and tests. This is useful to get a feel for the scale of the tests.
---
doc/usage/cmd/ut.rst | 6 ++++++ test/cmd_ut.c | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-)
doc/usage/cmd/ut.rst +6 -0
@@ -100,3 +100,9 @@ Run just a single test in a suite:: => ut bloblist bloblist_test_grow Test: bloblist_test_grow: bloblist.c Failures: 0 + +Show information about tests:: + + => ut info + Test suites: 21 + Total tests: 642
test/cmd_ut.c +15 -1
@@ -14,6 +14,9 @@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[])
@@ -45,6 +48,7 @@ int cmd_ut_category(const char *name, const char *prefix,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_BOOTSTDU_BOOT_CMD_MKENT (bootstd,CONFIG_SYS_MAXARGS ,1 , do_ut_bootstd, "", ""),
@@ -116,6 +120,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;
@@ -142,8 +155,9 @@ static char ut_help_text[] =" -f Force 'manual' tests to run as well\n" " <suite> Test suite to run, or all\n" "\n" -"Suites:" +"\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
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Re: [PATCH 10/17] test: Allow showing basic information about tests
Add a 'ut info' command to show the number of suites and tests. This is useful to get a feel for the scale of the tests.
---
doc/usage/cmd/ut.rst | 6 ++++++ test/cmd_ut.c | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-)
Applied to u-boot-dm, thanks!
PATCH 11/17 test: Add a way to detect a test that breaks another
In reply to Simon GlassWhen running unit tests, some may have side effects which cause a subsequent test to break. This can sometimes be seen when using 'ut dm' or similar.
Add a new argument which allows a particular (failing) test to be run immediately after a certain number of tests have run. This allows the test causing the failure to be determined.
Update the documentation also.
---
arch/sandbox/cpu/spl.c | 2 +- doc/develop/tests_sandbox.rst | 69 +++++++++++++++++++++++++++++++++++ doc/usage/cmd/ut.rst | 11 +++++- include/test/ut.h | 7 +++- test/cmd_ut.c | 9 ++++- test/test-main.c | 39 +++++++++++++++++--- 6 files changed, 127 insertions(+), 10 deletions(-)
arch/sandbox/cpu/spl.c +1 -1
@@ -89,7 +89,7 @@ void spl_board_init(void)int ret; ret =ut_run_list ("spl" ,NULL , tests, count, - state->select_unittests,1 , false); + state->select_unittests,1 , false,NULL );/* continue execution into U-Boot */ } }
doc/develop/tests_sandbox.rst +69 -0
75 lines not on this page · raw message
doc/usage/cmd/ut.rst +10 -1
@@ -8,10 +8,12 @@ Synopis :: - ut [-r<runs>] [-f] [<suite> [<test>]] + ut [-r<runs>] [-f] [-I<n>:<one_test>] [<suite> [<test>]] <runs> Number of times to run each test -f Force 'manual' tests to run as well + <n> Run <one test> after <n> other tests have run + <one_test> Name of the 'one' test to run <suite> Test suite to run, or `all` <test> Name of single test to run
@@ -35,6 +37,13 @@ Manual tests are normally skipped by this command. Use `-f` to run them. See See :ref:`develop/tests_writing:mixing python and c` for more information on manual test. +When running unit tests, some may have side effects which cause a subsequent +test to break. This can sometimes be seen when using 'ut dm' or similar. To +fix this, select the 'one' test which breaks. Then tell the 'ut' command to +run this one test after a certain number of other tests have run. Using a +binary search method with `-I` you can quickly figure one which test is causing +the problem. + Generally all tests in the suite are run. To run just a single test from the suite, provide the <test> argument.
include/test/ut.h +6 -1
@@ -410,10 +410,15 @@ void test_set_state(struct unit_test_state *uts);* then all tests are run * @runs_per_test: Number of times to run each test (typically 1) * @force_run: Run tests that are marked as manual-only (UT_TESTF_MANUAL) +* @test_insert: String describing a test to run after n other tests run, in the +* format n:name where n is the number of tests to run before this one and +* name is the name of the test to run. This is used to find which test causes +* another test to fail. If the one test fails, testing stops immediately. +* Pass NULL to disable this * Return: 0 if all tests passed, -1 if any failed */ int ut_run_list (const char *name,const char *prefix,struct unit_test *tests,int count,const char *select_name,int runs_per_test, -bool force_run); +bool force_run,const char *test_insert);#endif
test/cmd_ut.c +7 -2
@@ -21,6 +21,7 @@ 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;
@@ -35,13 +36,17 @@ 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 ; }
test/test-main.c +34 -5
@@ -499,12 +499,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;
@@ -535,6 +552,17 @@ 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);if (uts->fail_count != old_fail_count) {
@@ -555,7 +583,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;
@@ -590,7 +618,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)
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Re: [PATCH 11/17] test: Add a way to detect a test that breaks another
When running unit tests, some may have side effects which cause a subsequent test to break. This can sometimes be seen when using 'ut dm' or similar.
Add a new argument which allows a particular (failing) test to be run immediately after a certain number of tests have run. This allows the test causing the failure to be determined.
Update the documentation also.
---
arch/sandbox/cpu/spl.c | 2 +- doc/develop/tests_sandbox.rst | 69 +++++++++++++++++++++++++++++++++++ doc/usage/cmd/ut.rst | 11 +++++- include/test/ut.h | 7 +++- test/cmd_ut.c | 9 ++++- test/test-main.c | 39 +++++++++++++++++--- 6 files changed, 127 insertions(+), 10 deletions(-)
Applied to u-boot-dm, thanks!
PATCH 12/17 dm: blk: Tidy up obtaining a block device from its parent
In reply to Simon GlassThis function now finds its block-device child by looking for a child device of the correct uclass (UCLASS_BLK). It cannot produce a device of any other type, so drop the superfluous check.
Provide a version which does not probe the device, since that is often needed when setting up the device's platdata.
Also fix up the function's comment.
---
drivers/block/blk-uclass.c | 26 +++++++++++++++----------- include/blk.h | 28 +++++++++++++++++++++++++++- test/dm/blk.c | 2 +- 3 files changed, 43 insertions(+), 13 deletions(-)
drivers/block/blk-uclass.c +15 -11
@@ -491,24 +491,28 @@ unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,return ops->erase (dev, start, blkcnt); } -int blk_get_from_parent (struct udevice *parent,struct udevice **devp) +int blk_find_from_parent (struct udevice *parent,struct udevice **devp) {struct udevice *dev; -enum uclass_id id; -int ret; -device_find_first_child (parent, &dev); -if (!dev) { +if (device_find_first_child_by_uclass (parent,UCLASS_BLK , &dev)) {debug ("%s: No block device found for parent '%s'\n" , __func__, parent->name);return -ENODEV ; } - id =device_get_uclass_id (dev); -if (id !=UCLASS_BLK ) { -debug ("%s: Incorrect uclass %s for block device '%s'\n" , - __func__,uclass_get_name (id), dev->name); -return -ENOTBLK ; - } + *devp = dev; + +return 0 ; +} + +int blk_get_from_parent (struct udevice *parent,struct udevice **devp) +{ +struct udevice *dev; +int ret; + + ret =blk_find_from_parent (parent, &dev); +if (ret) +return ret; ret =device_probe (dev);if (ret)return ret;
include/blk.h +27 -1
@@ -416,10 +416,36 @@ int blk_next_free_devnum(enum uclass_id uclass_id);*/ int blk_select_hwpart (struct udevice *dev,int hwpart); +/** +* blk_find_from_parent() - find a block device by looking up its parent +* +* All block devices have a parent 'media' device which provides the block +* driver for the block device, ensuring that access to the underlying medium +* is available. +* +* The block device is not activated by this function. See +* blk_get_from_parent() for that. +* +* @parent: Media device +* @devp: Returns the associated block device, if any +* Returns: 0 if OK, -ENODEV if @parent is not a media device and has no +* UCLASS_BLK child +*/ +int blk_find_from_parent (struct udevice *parent,struct udevice **devp); +/** * blk_get_from_parent() - obtain a block device by looking up its parent * -* All devices with +* All block devices have a parent 'media' device which provides the block +* driver for the block device, ensuring that access to the underlying medium +* is available. +* +* The block device is probed and ready for use. +* +* @parent: Media device +* @devp: Returns the associated block device, if any +* Returns: 0 if OK, -ENODEV if @parent is not a media device and has no +* UCLASS_BLK child */ int blk_get_from_parent (struct udevice *parent,struct udevice **devp);
test/dm/blk.c +1 -1
@@ -160,7 +160,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));
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Re: [PATCH 12/17] dm: blk: Tidy up obtaining a block device from its parent
This function now finds its block-device child by looking for a child device of the correct uclass (UCLASS_BLK). It cannot produce a device of any other type, so drop the superfluous check.
Provide a version which does not probe the device, since that is often needed when setting up the device's platdata.
Also fix up the function's comment.
---
drivers/block/blk-uclass.c | 26 +++++++++++++++----------- include/blk.h | 28 +++++++++++++++++++++++++++- test/dm/blk.c | 2 +- 3 files changed, 43 insertions(+), 13 deletions(-)
Applied to u-boot-dm, thanks!
PATCH 13/17 dm: sandbox: Create a new HOST uclass
In reply to Simon GlassSandbox supports block devices which can access files on the host machine. At present there is no uclass for this. The devices are attached to the root devic. The block-device type is therefore set to UCLASS_ROOT which is confusing.
Block devices should be attached to a 'media' device instead, something which handles access to the actual media and provides the block driver for the block device.
Create a new uclass to handle this. It supports two operations, to attach and detach a file on the host machine.
For now this is not fully plumbed in.
---
drivers/block/Makefile | 2 +- drivers/block/host-uclass.c | 176 ++++++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/sandbox_host.h | 125 +++++++++++++++++++++++++ 4 files changed, 303 insertions(+), 1 deletion(-) create mode 100644 drivers/block/host-uclass.c create mode 100644 include/sandbox_host.h
drivers/block/Makefile +1 -1
@@ -12,7 +12,7 @@ endif ifndef CONFIG_SPL_BUILD obj-$(CONFIG_IDE) += ide.o endif -obj-$(CONFIG_SANDBOX) += sandbox.o +obj-$(CONFIG_SANDBOX) += sandbox.o host-uclass.o obj-$(CONFIG_$(SPL_TPL_)BLOCK_CACHE) += blkcache.o obj-$(CONFIG_EFI_MEDIA) += efi-media-uclass.o
drivers/block/host-uclass.c new file +176 -0
176 lines not on this page · raw message
include/dm/uclass-id.h +1 -0
@@ -62,6 +62,7 @@ enum uclass_id {UCLASS_GPIO ,/* Bank of general-purpose I/O pins */ UCLASS_HASH ,/* Hash device */ UCLASS_HWSPINLOCK ,/* Hardware semaphores */ +UCLASS_HOST ,/* Sandbox host device */ UCLASS_I2C ,/* I2C bus */ UCLASS_I2C_EEPROM ,/* I2C EEPROM device */ UCLASS_I2C_GENERIC, /* Generic I2C device */
include/sandbox_host.h new file +125 -0
125 lines not on this page · raw message
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Re: [PATCH 13/17] dm: sandbox: Create a new HOST uclass
Sandbox supports block devices which can access files on the host machine. At present there is no uclass for this. The devices are attached to the root devic. The block-device type is therefore set to UCLASS_ROOT which is confusing.
Block devices should be attached to a 'media' device instead, something which handles access to the actual media and provides the block driver for the block device.
Create a new uclass to handle this. It supports two operations, to attach and detach a file on the host machine.
For now this is not fully plumbed in.
---
drivers/block/Makefile | 2 +- drivers/block/host-uclass.c | 176 ++++++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/sandbox_host.h | 125 +++++++++++++++++++++++++ 4 files changed, 303 insertions(+), 1 deletion(-) create mode 100644 drivers/block/host-uclass.c create mode 100644 include/sandbox_host.h
Applied to u-boot-dm, thanks!
PATCH 14/17 dm: sandbox: Create a block driver
In reply to Simon GlassCreate a block driver for the new HOST uclass. This handles attaching and detaching host files.
For now the uclass is not used but this will be plumbed in with future patches.
---
drivers/block/Makefile | 2 +- drivers/block/host_dev.c | 142 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 drivers/block/host_dev.c
drivers/block/Makefile +1 -1
@@ -12,7 +12,7 @@ endif ifndef CONFIG_SPL_BUILD obj-$(CONFIG_IDE) += ide.o endif -obj-$(CONFIG_SANDBOX) += sandbox.o host-uclass.o +obj-$(CONFIG_SANDBOX) += sandbox.o host-uclass.o host_dev.o obj-$(CONFIG_$(SPL_TPL_)BLOCK_CACHE) += blkcache.o obj-$(CONFIG_EFI_MEDIA) += efi-media-uclass.o
drivers/block/host_dev.c new file +142 -0
142 lines not on this page · raw message
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Re: [PATCH 14/17] dm: sandbox: Create a block driver
Create a block driver for the new HOST uclass. This handles attaching and detaching host files.
For now the uclass is not used but this will be plumbed in with future patches.
---
drivers/block/Makefile | 2 +- drivers/block/host_dev.c | 142 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 drivers/block/host_dev.c
Applied to u-boot-dm, thanks!
PATCH 15/17 dm: sandbox: Switch over to using the new host uclass
In reply to Simon GlassUpdate the sandbox implementation to use UCLASS_HOST and adjust all the pieces to continue to work:
- Update the 'host' command to use the new API
- Replace various uses of UCLASS_ROOT with UCLASS_HOST
- Disable test_eficonfig since it doesn't work (this should have a unit test to allow this to be debugged)
- Update the blk test to use the new API
- Drop the old header file
Unfortunately it does not seem to be possible to split this change up further.
---
arch/sandbox/dts/sandbox.dts | 4 - cmd/host.c | 204 ++++++++++++------ disk/part.c | 4 +- drivers/block/blk-uclass.c | 2 +- drivers/block/sandbox.c | 134 ++---------- include/sandboxblockdev.h | 28 --- lib/efi_loader/efi_device_path.c | 5 +- lib/efi_loader/efi_disk.c | 2 +- test/dm/blk.c | 47 ++-- .../py/tests/test_eficonfig/test_eficonfig.py | 3 + 10 files changed, 184 insertions(+), 249 deletions(-) delete mode 100644 include/sandboxblockdev.h
arch/sandbox/dts/sandbox.dts +0 -4
@@ -65,10 +65,6 @@ reg = <0x10002000 0x1000>; }; - host-fs { - compatible = "sandbox,bootdev-host"; - }; - i2c_0: i2c@0 { #address-cells = <1>; #size-cells = <0>;
cmd/host.c +133 -71
276 lines not on this page · raw message
disk/part.c +2 -2
@@ -139,7 +139,7 @@ void dev_print(struct blk_desc *dev_desc)case UCLASS_USB :case UCLASS_NVME :case UCLASS_PVBLOCK : -case UCLASS_ROOT : +case UCLASS_HOST : printf ("Vendor: %s Rev: %s Prod: %s\n", dev_desc->vendor, dev_desc->revision,
@@ -264,7 +264,7 @@ static void print_part_header(const char *type, struct blk_desc *dev_desc)case UCLASS_MMC :puts ("MMC" );break ; -case UCLASS_ROOT : +case UCLASS_HOST :puts ("HOST" );break ;case UCLASS_NVME :
drivers/block/blk-uclass.c +1 -1
@@ -26,7 +26,7 @@ static struct { { UCLASS_USB, "usb" }, { UCLASS_MMC, "mmc" }, { UCLASS_AHCI, "sata" }, - { UCLASS_ROOT, "host" }, + { UCLASS_HOST, "host" }, { UCLASS_NVME, "nvme" }, { UCLASS_EFI_MEDIA, "efi" }, { UCLASS_EFI_LOADER, "efiloader" },
drivers/block/sandbox.c +17 -117
170 lines not on this page · raw message
include/sandboxblockdev.h deleted +0 -28
@@ -1,28 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* -* Copyright (c) 2013, Henrik Nordstrom <[email protected]> -*/ - -#ifndef __SANDBOX_BLOCK_DEV__ -#define __SANDBOX_BLOCK_DEV__ - -/* Maximum number of host devices - see drivers/block/sandbox.c */ -#define SANDBOX_HOST_MAX_DEVICES 4 - -struct host_block_dev { -char *filename; -int fd; -}; - -/** -* host_dev_bind() - Bind or unbind a device -* -* @dev: Device number (0=first slot) -* @filename: Host filename to use, or NULL to unbind -* @removable: true if the block device should mark itself as removable -*/ -int host_dev_bind (int dev,char *filename,bool removable); - -int host_get_dev_err (int dev,struct blk_desc **blk_devp); - -#endif
lib/efi_loader/efi_device_path.c +2 -3
@@ -17,7 +17,6 @@#include <nvme.h> #include <efi_loader.h> #include <part.h> -#include <sandboxblockdev.h> #include <uuid.h> #include <asm-generic/unaligned.h> #include <linux/compat.h> /* U16_MAX */
@@ -556,7 +555,7 @@ __maybe_unused static unsigned int dp_size(struct udevice *dev)sizeof (struct efi_device_path_nvme );#endif #ifdef CONFIG_SANDBOX -case UCLASS_ROOT : +case UCLASS_HOST :/* * Sandbox's host device will be represented * as vendor device with extra one byte for
@@ -633,7 +632,7 @@ __maybe_unused static void *dp_fill(void *buf, struct udevice *dev)case UCLASS_BLK :switch (dev->parent->uclass->uc_drv->id) {#ifdef CONFIG_SANDBOX -case UCLASS_ROOT : { +case UCLASS_HOST : {/* stop traversing parents at this point: */ struct efi_device_path_vendor *dp;struct blk_desc *desc =dev_get_uclass_plat (dev);
lib/efi_loader/efi_disk.c +1 -1
@@ -551,7 +551,7 @@ static int efi_disk_create_raw(struct udevice *dev)if (ret ==EFI_NOT_READY )log_notice ("Disk %s not ready\n" , dev->name);else -log_err ("Adding disk for %s failed\n" , dev->name); +log_err ("Adding disk for %s failed (err=%ld/%#lx)\n" , dev->name, ret, ret);return -1 ; }
test/dm/blk.c +25 -22
76 lines not on this page · raw message
test/py/tests/test_eficonfig/test_eficonfig.py +3 -0
@@ -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()
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
PATCH 16/17 dm: Add documentation for host command and implementation
In reply to Simon GlassDocument the 'host' command and also the internals of how it is implemented.
---
doc/arch/index.rst | 2 +-
doc/arch/sandbox/block_impl.rst | 39 ++++++++++
doc/arch/sandbox/index.rst | 12 +++
doc/arch/{ => sandbox}/sandbox.rst | 9 ++-
doc/usage/cmd/host.rst | 116 +++++++++++++++++++++++++++++
doc/usage/index.rst | 1 +
6 files changed, 175 insertions(+), 4 deletions(-)
create mode 100644 doc/arch/sandbox/block_impl.rst
create mode 100644 doc/arch/sandbox/index.rst
rename doc/arch/{ => sandbox}/sandbox.rst (98%)
create mode 100644 doc/usage/cmd/host.rstdoc/arch/index.rst +1 -1
@@ -11,7 +11,7 @@ Architecture-specific doc m68k mips nios2 - sandbox + sandbox/index sh x86 xtensa
doc/arch/sandbox/block_impl.rst new file +39 -0
@@ -0,0 +1,39 @@ +.. SPDX-License-Identifier: GPL-2.0+ */ +.. Copyright (c) 2014 The Chromium OS Authors. +.. sectionauthor:: Simon Glass <[email protected]> + +Sandbox block devices (implementation) +====================================== + +(See :ref:`sandbox_blk` for operation) + +Sandbox block devices are implemented using the `UCLASS_HOST` uclass. Only one +driver is provided (`host_sb_drv`) so all devices in the uclass use the same +driver. + +The uclass has a simple API allowing files to be attached and detached. +Attaching a file results in it appearing as a block device in sandbox. This +allows filesystems and whole disk images to be accessed from U-Boot. This is +particularly useful for tests. + +Devices are created using `host_create_device()`. This sets up a new +`UCLASS_HOST`. + +The device can then be attached to a file with `host_attach_file()`. This +creates the child block device (and bootdev device). + +The host device's block device must be probed before use, as normal. + +To destroy a device, call host_destroy_device(). This removes the device (and +its children of course), then closes any attached file, then unbinds the device. + +There is no arbitrary limit to the number of host devices that can be created. + + +Uclass API +---------- + +This is incomplete as it isn't clear how to make Sphinx do the right thing for +struct host_ops. See `include/sandbox_host.h` for full details. + +.. kernel-doc:: include/sandbox_host.h
doc/arch/sandbox/index.rst new file +12 -0
@@ -0,0 +1,12 @@ +.. SPDX-License-Identifier: GPL-2.0+ */ +.. Copyright 2022 Google LLC +.. sectionauthor:: Simon Glass <[email protected]> + +Sandbox +======= + +.. toctree:: + :maxdepth: 2 + + sandbox + block_impl
doc/arch/sandbox/sandbox.rst renamed from doc/arch/sandbox.rst +6 -3
@@ -43,7 +43,7 @@ Note that standalone/API support is not available at present. Prerequisites ------------- -Install the dependencies noted in :doc:`../build/gcc`. +Install the dependencies noted in :doc:`../../build/gcc`. Basic Operation
@@ -374,6 +374,7 @@ also use low-level SPI commands:: This is issuing a READ_ID command and getting back 20 (ST Micro) part 0x2015 (the M25P16). +.. _sandbox_blk: Block Device Emulation ----------------------
@@ -401,6 +402,8 @@ or utilize the device described in test/py/make_test_disk.py:: import make_test_disk make_test_disk.makeDisk() +For more technical details, see :doc:`block_impl`. + Writing Sandbox Drivers -----------------------
@@ -600,8 +603,8 @@ Testing U-Boot sandbox can be used to run various tests, mostly in the test/ directory. -See :doc:`../develop/tests_sandbox` for more information and -:doc:`../develop/testing` for information about testing generally. +See :doc:`../../develop/tests_sandbox` for more information and +:doc:`../../develop/testing` for information about testing generally. Memory Map
doc/usage/cmd/host.rst new file +116 -0
116 lines not on this page · raw message
doc/usage/index.rst +1 -0
@@ -50,6 +50,7 @@ Shell commands cmd/fdt cmd/for cmd/gpio + cmd/host cmd/load cmd/loadm cmd/loady
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Re: [PATCH 16/17] dm: Add documentation for host command and implementation
Document the 'host' command and also the internals of how it is implemented.
---
doc/arch/index.rst | 2 +-
doc/arch/sandbox/block_impl.rst | 39 ++++++++++
doc/arch/sandbox/index.rst | 12 +++
doc/arch/{ => sandbox}/sandbox.rst | 9 ++-
doc/usage/cmd/host.rst | 116 +++++++++++++++++++++++++++++
doc/usage/index.rst | 1 +
6 files changed, 175 insertions(+), 4 deletions(-)
create mode 100644 doc/arch/sandbox/block_impl.rst
create mode 100644 doc/arch/sandbox/index.rst
rename doc/arch/{ => sandbox}/sandbox.rst (98%)
create mode 100644 doc/usage/cmd/host.rstApplied to u-boot-dm, thanks!
PATCH 17/17 dm: Add tests for the sandbox host driver
In reply to Simon GlassAdd some unit tests for this.
---
test/dm/Makefile | 1 + test/dm/host.c | 195 +++++++++++++++++++++++++++++++++++++ test/py/tests/fs_helper.py | 6 +- test/py/tests/test_ut.py | 6 ++ 4 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 test/dm/host.c
test/dm/Makefile +1 -0
@@ -48,6 +48,7 @@ obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o endif obj-$(CONFIG_FIRMWARE) += firmware.o obj-$(CONFIG_DM_FPGA) += fpga.o +obj-$(CONFIG_SANDBOX) += host.o obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o obj-$(CONFIG_DM_I2C) += i2c.o obj-$(CONFIG_SOUND) += i2s.o
test/dm/host.c new file +195 -0
195 lines not on this page · raw message
test/py/tests/fs_helper.py +4 -2
@@ -9,7 +9,7 @@ import re import os from subprocess import call, check_call, check_output, CalledProcessError -def mk_fs(config, fs_type, size, prefix): +def mk_fs(config, fs_type, size, prefix, use_src_dir=False): """Create a file system volume Args:
@@ -17,12 +17,14 @@ def mk_fs(config, fs_type, size, prefix): 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.persistent_data_dir, fs_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'
test/py/tests/test_ut.py +6 -0
@@ -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"""
Signature · 1 line
2.38.1.273.g43a17bfeac-goog
Re: [PATCH 17/17] dm: Add tests for the sandbox host driver
Add some unit tests for this.
---
test/dm/Makefile | 1 + test/dm/host.c | 195 +++++++++++++++++++++++++++++++++++++ test/py/tests/fs_helper.py | 6 +- test/py/tests/test_ut.py | 6 ++ 4 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 test/dm/host.c
Applied to u-boot-dm, thanks!