cmd: cat: add new command
PATCH v5 1/1 cmd: cat: add new command
Add cat command to print file content to standard out
---
v5:
- Removed "default n" from Kconfig
- Renamed 'buffer_sysmem_addr' in 'addr'
- User yield instead of return in conftest.py
- Catch 'CalledProcessError' in conftest.py
- Clean up files after test execution
- Use u_boot_console.run_command_list() instead of u_boot_console.run_command()
- Removed unnecessary unmap_sysmem() call
- Added Reviewed-by Simon
v4:
- Return only values from enum command_ret_t in do_cat()
- Use calloc() instead of malloc() for zero initialized memory
- Make use of CONFIG_SYS_LONGHELP
- Improved error messages
v3:
- Disable 'cat' by default (CONFIG_CMD_CAT=n)
- Enable 'cat' in sandbox and sandbox64 defconfig
- Use map_to_sysmem() to fix "phys_to_virt: Cannot map sandbox address"
- Use puts() instead of a loop
- Added python test
- Added usage documentation
v2:
- Moved cat from boot to shell commands
- Added MAINTAINERS entry
- Added comments
- Improved variable naming
MAINTAINERS | 5 ++ cmd/Kconfig | 5 ++ cmd/Makefile | 1 + cmd/cat.c | 85 ++++++++++++++++++++++++++++++ configs/sandbox64_defconfig | 1 + configs/sandbox_defconfig | 1 + doc/usage/cmd/cat.rst | 49 +++++++++++++++++ test/py/tests/test_cat/conftest.py | 35 ++++++++++++ test/py/tests/test_cat/test_cat.py | 20 +++++++ 9 files changed, 202 insertions(+) create mode 100644 cmd/cat.c create mode 100644 doc/usage/cmd/cat.rst create mode 100644 test/py/tests/test_cat/conftest.py create mode 100644 test/py/tests/test_cat/test_cat.py
MAINTAINERS +5 -0
@@ -765,6 +765,11 @@ M: Simon Glass <[email protected]> S: Maintained F: tools/buildman/ +CAT +M: Roger Knecht <[email protected]> +S: Maintained +F: cmd/cat.c + CFI FLASH M: Stefan Roese <[email protected]> S: Maintained
cmd/Kconfig +5 -0
@@ -1531,6 +1531,11 @@ endmenu menu "Shell scripting commands" +config CMD_CAT + bool "cat" + help + Print file to standard output + config CMD_ECHO bool "echo" default y
cmd/Makefile +1 -0
@@ -38,6 +38,7 @@ obj-$(CONFIG_CMD_BOOTZ) += bootz.o obj-$(CONFIG_CMD_BOOTI) += booti.o obj-$(CONFIG_CMD_BTRFS) += btrfs.o obj-$(CONFIG_CMD_BUTTON) += button.o +obj-$(CONFIG_CMD_CAT) += cat.o obj-$(CONFIG_CMD_CACHE) += cache.o obj-$(CONFIG_CMD_CBFS) += cbfs.o obj-$(CONFIG_CMD_CLK) += clk.o
cmd/cat.c new file +85 -0
85 lines not on this page · raw message
configs/sandbox64_defconfig +1 -0
@@ -22,6 +22,7 @@ CONFIG_CONSOLE_RECORD=y CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000 CONFIG_PRE_CONSOLE_BUFFER=y CONFIG_DISPLAY_BOARDINFO_LATE=y +CONFIG_CMD_CAT=y CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y CONFIG_CMD_BOOTZ=y
configs/sandbox_defconfig +1 -0
@@ -36,6 +36,7 @@ CONFIG_LOG_DEFAULT_LEVEL=6 CONFIG_DISPLAY_BOARDINFO_LATE=y CONFIG_STACKPROTECTOR=y CONFIG_ANDROID_AB=y +CONFIG_CMD_CAT=y CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y CONFIG_CMD_BOOTM_PRE_LOAD=y
doc/usage/cmd/cat.rst new file +49 -0
49 lines not on this page · raw message
test/py/tests/test_cat/conftest.py new file +35 -0
@@ -0,0 +1,35 @@ +# SPDX-License-Identifier: GPL-2.0+ + +"""Fixture for cat command test +""" + +import os +import shutil +from subprocess import check_call +import pytest + [email protected](scope='session') +def cat_data(u_boot_config): + """Set up a file system to be used in cat tests + + Args: + u_boot_config -- U-boot configuration. + """ + mnt_point = u_boot_config.persistent_data_dir + '/test_cat' + image_path = u_boot_config.persistent_data_dir + '/cat.img' + + try: + os.mkdir(mnt_point, mode = 0o755) + + with open(mnt_point + '/hello', 'w', encoding = 'ascii') as file: + file.write('hello world\n') + + check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat {mnt_point} {image_path}', + shell=True) + + yield image_path + except CalledProcessError: + pytest.skip('Setup failed') + finally: + shutil.rmtree(mnt_point) + os.remove(image_path)
test/py/tests/test_cat/test_cat.py new file +20 -0
@@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0+ + +""" Unit test for cat command +""" + +import pytest + [email protected]('sandbox') [email protected]('cmd_cat') +def test_cat(u_boot_console, cat_data): + """ Unit test for cat + + Args: + u_boot_console -- U-Boot console + cat_data -- Path to the disk image used for testing. + """ + response = u_boot_console.run_command_list([ + f'host bind 0 {cat_data}', + 'cat host 0 hello']) + assert 'hello world' in response
--
2.25.1
Quoted 4 lines · Roger Knecht
Add cat command to print file content to standard out
Reviewed-by Simon Glass <[email protected]>Signed-off-by Roger Knecht <[email protected]>
Two problems:
https://source.denx.de/u-boot/u-boot/-/jobs/490480
https://source.denx.de/u-boot/u-boot/-/jobs/490473
Signature · 1 line
Tom
Quoted 11 lines · Tom Rini
Quoted 4 lines · Roger Knecht
Add cat command to print file content to standard out
Reviewed-by Simon Glass [email protected]Signed-off-by Roger Knecht [email protected]Two problems:
https://source.denx.de/u-boot/u-boot/-/jobs/490480
https://source.denx.de/u-boot/u-boot/-/jobs/490473
Sorry for the inconvenience. Fixed patch will follow soon.
Regards,
Roger