* Re: [PATCH v2 2/2] test: cmd: Add test for zip/unzip/gzwrite commands
2026-01-29 23:55 ` [PATCH v2 2/2] test: cmd: Add test for zip/unzip/gzwrite commands Marek Vasut
@ 2026-01-30 7:57 ` Mattijs Korpershoek
2026-02-02 20:03 ` Heinrich Schuchardt
2026-02-03 21:31 ` Simon Glass
2 siblings, 0 replies; 8+ messages in thread
From: Mattijs Korpershoek @ 2026-01-30 7:57 UTC (permalink / raw)
To: Marek Vasut, u-boot
Cc: Marek Vasut, Alexander Graf, Heinrich Schuchardt,
Ilias Apalodimas, Jerome Forissier, Mattijs Korpershoek,
Neil Armstrong, Peng Fan, Quentin Schulz, Simon Glass, Tom Rini,
Yuya Hamamachi
Hi Marek,
Thank you for the patch.
On Fri, Jan 30, 2026 at 00:55, Marek Vasut <marek.vasut+renesas@mailbox.org> wrote:
> Add simple test for zip/unzip/gzwrite commands. The test works as
> follows. First, create three buffers with a bit of space between
> each of them, fill them with random data, then compress data in
> buffer 1 into buffer 2, decompress data in buffer 2 either directly
> into buffer 3 or into MMC 1 and then read them back into buffer 3,
> and finally compare buffer 1 and buffer 3, they have to be identical.
>
> The buffers are filled with random data to detect out of bounds writes.
> Test for various sizes, both small and large and unaligned.
>
> The test uses ut_assert_skip_to_line() to skip over gzwrite progress
> bar. Since the progress bar updates fill up the console record buffer,
> increase the size of it to compensate.
>
> Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
I've applied the deps from the cover letter, then I ran:
$ ./test/py/test.py --bd sandbox --build -k ut # to build mmc9.img
$ ./test/py/test.py --bd sandbox --build -k cmd_zip
Tests pass, so:
Tested-by: Mattijs Korpershoek <mkorpershoek@kernel.org>
Also, code looks good to me:
Reviewed-by: Mattijs Korpershoek <mkorpershoek@kernel.org>
> ---
> Cc: Alexander Graf <agraf@csgraf.de>
> Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> Cc: Jerome Forissier <jerome@forissier.org>
> Cc: Mattijs Korpershoek <mkorpershoek@kernel.org>
> Cc: Neil Armstrong <neil.armstrong@linaro.org>
> Cc: Peng Fan <peng.fan@nxp.com>
> Cc: Quentin Schulz <quentin.schulz@cherry.de>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Tom Rini <trini@konsulko.com>
> Cc: Yuya Hamamachi <yuya.hamamachi.sx@renesas.com>
> Cc: u-boot@lists.denx.de
> ---
> V2: Use ut_assert_skip_to_line() to skip over the progress bar.
> Since that fills up the console record buffer, increase the
> size of it to compensate.
> ---
> arch/sandbox/dts/test.dts | 7 +++
> common/Kconfig | 2 +-
> test/cmd/Makefile | 4 ++
> test/cmd/unzip.c | 123 ++++++++++++++++++++++++++++++++++++++
> test/py/tests/test_ut.py | 6 ++
> 5 files changed, 141 insertions(+), 1 deletion(-)
> create mode 100644 test/cmd/unzip.c
>
> diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
> index b7402d7042a..762c1d9bbe2 100644
> --- a/arch/sandbox/dts/test.dts
> +++ b/arch/sandbox/dts/test.dts
> @@ -1272,6 +1272,13 @@
> filename = "mmc8.img";
> };
>
> + /* This is used for zip/unzip/gzwrite tests. */
> + mmc9 {
> + status = "disabled";
> + compatible = "sandbox,mmc";
> + filename = "mmc9.img";
> + };
> +
> pch {
> compatible = "sandbox,pch";
> };
> diff --git a/common/Kconfig b/common/Kconfig
> index 47d17f4e7c6..63448bdc13b 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -26,7 +26,7 @@ config CONSOLE_RECORD_INIT_F
> config CONSOLE_RECORD_OUT_SIZE
> hex "Output buffer size"
> depends on CONSOLE_RECORD
> - default 0x6000
> + default 0x20000
> help
> Set the size of the console recording output buffer. When this fills
> up, no more data will be recorded until some is removed. The buffer
> diff --git a/test/cmd/Makefile b/test/cmd/Makefile
> index 2476068aee6..273009a034f 100644
> --- a/test/cmd/Makefile
> +++ b/test/cmd/Makefile
> @@ -45,3 +45,7 @@ endif
> obj-$(CONFIG_ARM_FFA_TRANSPORT) += armffa.o
> endif
> obj-$(CONFIG_CMD_SPAWN) += spawn.o
> +
> +ifdef CONFIG_CMD_ZIP
> +obj-$(CONFIG_CMD_UNZIP) += unzip.o
> +endif
> diff --git a/test/cmd/unzip.c b/test/cmd/unzip.c
> new file mode 100644
> index 00000000000..dc4a9c93745
> --- /dev/null
> +++ b/test/cmd/unzip.c
> @@ -0,0 +1,123 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Tests for zip/unzip/gzwrite commands
> + *
> + * Copyright 2026, Marek Vasut <marek.vasut+renesas@mailbox.org>
> + */
> +
> +#include <command.h>
> +#include <env.h>
> +#include <dm.h>
> +#include <dm/lists.h>
> +#include <dm/test.h>
> +#include <linux/sizes.h>
> +#include <mapmem.h>
> +#include <part.h>
> +#include <test/cmd.h>
> +#include <test/test.h>
> +#include <test/ut.h>
> +#include <u-boot/crc.h>
> +
> +static const int sizes[] = { 32, SZ_1K, SZ_4K, SZ_1M, SZ_16M, SZ_1M - 1, SZ_1M + 1, 6758401 };
> +
> +static int do_test_cmd_zip_unzip(struct unit_test_state *uts, const int size,
> + const bool gzwrite)
> +{
> + env_set_hex("size", size);
> +
> + /*
> + * Prepare three buffers, $loadadd, $encaddr, $decaddr, and
> + * fill them all with random data. Add slight space between
> + * the compressed buffer 'encaddr' and uncompressed buffer
> + * 'decaddr', because the compressed data with gzip header
> + * might be longer than uncompressed source data 'loadaddr',
> + * and if the uncompressed data buffer 'decaddr' followed
> + * 'encaddr', the decompression could corrupt end of 'encaddr'
> + * buffer.
> + */
> + ut_assertok(run_command("setexpr encaddr $loadaddr + $size", 0));
> + ut_assertok(run_command("setexpr encaddr $encaddr + 0x10000", 0));
> +
> + ut_assertok(run_command("setexpr decaddr $encaddr + $size", 0));
> + ut_assertok(run_command("setexpr decaddr $decaddr + 0x10000", 0));
> +
> + ut_assertok(run_command("random $loadaddr $size", 0));
> + ut_assert_nextline("%d bytes filled with random data", size);
> + ut_assertok(run_command("random $encaddr $size", 0));
> + ut_assert_nextline("%d bytes filled with random data", size);
> + ut_assertok(run_command("random $decaddr $size", 0));
> + ut_assert_nextline("%d bytes filled with random data", size);
> +
> + /* Compress data in $loadaddr into $encaddr */
> + ut_assertok(run_command("zip $loadaddr $size $encaddr", 0));
> + console_record_readline(uts->actual_str, sizeof(uts->actual_str));
> + ut_assert(strstr(uts->actual_str, "Compressed size: "));
> +
> + if (gzwrite) {
> + unsigned int sectsize = DIV_ROUND_UP(size, 512);
> + unsigned char *db = map_sysmem(env_get_ulong("loadaddr", 16, 0), size);
> + u32 crc = crc32(0, db, size);
> +
> + ut_assertok(run_command("gzwrite mmc 9 $encaddr $filesize", 0));
> + ut_assert_skip_to_line("\t%u bytes, crc 0x%08x", size, crc);
> +
> + env_set_hex("sectsize", sectsize);
> + ut_assertok(run_command("mmc read $decaddr 0 $sectsize", 0));
> + ut_assert_nextline("MMC read: dev # 9, block # 0, count %u ... %u blocks read: OK",
> + sectsize, sectsize);
> + } else {
> + /* Decompress data in $encaddr into $decaddr */
> + ut_assertok(run_command("unzip $encaddr $decaddr $filesize", 0));
> + ut_assert_nextline("Uncompressed size: %u = 0x%X", size, size);
> + }
> +
> + /* Input data and compressed-decompressed data */
> + ut_assertok(run_command("cmp.b $loadaddr $decaddr $size", 0));
> + ut_assert_nextline("Total of %u byte(s) were the same", size);
> +
> + ut_assert_console_end();
> +
> + return 0;
> +}
> +
> +static int dm_test_cmd_zip_unzip(struct unit_test_state *uts)
> +{
> + int i, ret;
> +
> + for (i = 0; i < ARRAY_SIZE(sizes); i++) {
> + ret = do_test_cmd_zip_unzip(uts, sizes[i], false);
> + if (ret)
> + return ret;
> + }
> +
> + return 0;
> +}
> +DM_TEST(dm_test_cmd_zip_unzip, UTF_CONSOLE);
> +
> +static int dm_test_cmd_zip_gzwrite(struct unit_test_state *uts)
> +{
> + struct blk_desc *mmc_dev_desc;
> + struct udevice *dev;
> + ofnode root, node;
> + int i, ret;
> +
> + /* Enable the mmc9 node for this test */
> + root = oftree_root(oftree_default());
> + node = ofnode_find_subnode(root, "mmc9");
> + ut_assert(ofnode_valid(node));
> + ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false));
> +
> + ut_asserteq(9, blk_get_device_by_str("mmc", "9", &mmc_dev_desc));
> + ut_assertok(run_commandf("mmc dev 9"));
> + ut_assert_nextline("switch to partitions #0, OK");
> + ut_assert_nextline("mmc9 is current device");
> +
> + for (i = 0; i < ARRAY_SIZE(sizes); i++) {
> + ret = do_test_cmd_zip_unzip(uts, sizes[i], true);
> + if (ret)
> + return ret;
> + }
> +
> + return 0;
> +}
> +DM_TEST(dm_test_cmd_zip_gzwrite, UTF_CONSOLE);
> diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
> index 6d535b5206d..b7166d59943 100644
> --- a/test/py/tests/test_ut.py
> +++ b/test/py/tests/test_ut.py
> @@ -522,6 +522,12 @@ def test_ut_dm_init(ubman):
> with open(fn, 'wb') as fh:
> fh.write(data)
>
> + mmc_dev = 9
> + fn = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img')
> + data = b'\x00' * (32 * 1024 * 1024)
> + with open(fn, 'wb') as fh:
> + fh.write(data)
> +
>
> def setup_efi_image(ubman):
> """Create a 20MB disk image with an EFI app on it"""
> --
> 2.51.0
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2 2/2] test: cmd: Add test for zip/unzip/gzwrite commands
2026-01-29 23:55 ` [PATCH v2 2/2] test: cmd: Add test for zip/unzip/gzwrite commands Marek Vasut
2026-01-30 7:57 ` Mattijs Korpershoek
@ 2026-02-02 20:03 ` Heinrich Schuchardt
2026-02-03 21:31 ` Simon Glass
2 siblings, 0 replies; 8+ messages in thread
From: Heinrich Schuchardt @ 2026-02-02 20:03 UTC (permalink / raw)
To: Marek Vasut
Cc: Alexander Graf, Ilias Apalodimas, Jerome Forissier,
Mattijs Korpershoek, Neil Armstrong, Peng Fan, Quentin Schulz,
Simon Glass, Tom Rini, Yuya Hamamachi, u-boot
On 1/30/26 00:55, Marek Vasut wrote:
> Add simple test for zip/unzip/gzwrite commands. The test works as
> follows. First, create three buffers with a bit of space between
> each of them, fill them with random data, then compress data in
> buffer 1 into buffer 2, decompress data in buffer 2 either directly
> into buffer 3 or into MMC 1 and then read them back into buffer 3,
> and finally compare buffer 1 and buffer 3, they have to be identical.
>
> The buffers are filled with random data to detect out of bounds writes.
> Test for various sizes, both small and large and unaligned.
>
> The test uses ut_assert_skip_to_line() to skip over gzwrite progress
> bar. Since the progress bar updates fill up the console record buffer,
> increase the size of it to compensate.
>
> Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
> ---
> Cc: Alexander Graf <agraf@csgraf.de>
> Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> Cc: Jerome Forissier <jerome@forissier.org>
> Cc: Mattijs Korpershoek <mkorpershoek@kernel.org>
> Cc: Neil Armstrong <neil.armstrong@linaro.org>
> Cc: Peng Fan <peng.fan@nxp.com>
> Cc: Quentin Schulz <quentin.schulz@cherry.de>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Tom Rini <trini@konsulko.com>
> Cc: Yuya Hamamachi <yuya.hamamachi.sx@renesas.com>
> Cc: u-boot@lists.denx.de
> ---
> V2: Use ut_assert_skip_to_line() to skip over the progress bar.
> Since that fills up the console record buffer, increase the
> size of it to compensate.
> ---
> arch/sandbox/dts/test.dts | 7 +++
> common/Kconfig | 2 +-
> test/cmd/Makefile | 4 ++
> test/cmd/unzip.c | 123 ++++++++++++++++++++++++++++++++++++++
> test/py/tests/test_ut.py | 6 ++
> 5 files changed, 141 insertions(+), 1 deletion(-)
> create mode 100644 test/cmd/unzip.c
>
> diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
> index b7402d7042a..762c1d9bbe2 100644
> --- a/arch/sandbox/dts/test.dts
> +++ b/arch/sandbox/dts/test.dts
> @@ -1272,6 +1272,13 @@
> filename = "mmc8.img";
> };
>
> + /* This is used for zip/unzip/gzwrite tests. */
> + mmc9 {
> + status = "disabled";
> + compatible = "sandbox,mmc";
> + filename = "mmc9.img";
> + };
> +
> pch {
> compatible = "sandbox,pch";
> };
> diff --git a/common/Kconfig b/common/Kconfig
> index 47d17f4e7c6..63448bdc13b 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -26,7 +26,7 @@ config CONSOLE_RECORD_INIT_F
> config CONSOLE_RECORD_OUT_SIZE
> hex "Output buffer size"
> depends on CONSOLE_RECORD
> - default 0x6000
> + default 0x20000
> help
> Set the size of the console recording output buffer. When this fills
> up, no more data will be recorded until some is removed. The buffer
> diff --git a/test/cmd/Makefile b/test/cmd/Makefile
> index 2476068aee6..273009a034f 100644
> --- a/test/cmd/Makefile
> +++ b/test/cmd/Makefile
> @@ -45,3 +45,7 @@ endif
> obj-$(CONFIG_ARM_FFA_TRANSPORT) += armffa.o
> endif
> obj-$(CONFIG_CMD_SPAWN) += spawn.o
> +
> +ifdef CONFIG_CMD_ZIP
> +obj-$(CONFIG_CMD_UNZIP) += unzip.o
Building the test depends on CONFIG_CMD_RANDOM. Please, add all missing
dependencies.
Best regards
Heinrich
> +endif
> diff --git a/test/cmd/unzip.c b/test/cmd/unzip.c
> new file mode 100644
> index 00000000000..dc4a9c93745
> --- /dev/null
> +++ b/test/cmd/unzip.c
> @@ -0,0 +1,123 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Tests for zip/unzip/gzwrite commands
> + *
> + * Copyright 2026, Marek Vasut <marek.vasut+renesas@mailbox.org>
> + */
> +
> +#include <command.h>
> +#include <env.h>
> +#include <dm.h>
> +#include <dm/lists.h>
> +#include <dm/test.h>
> +#include <linux/sizes.h>
> +#include <mapmem.h>
> +#include <part.h>
> +#include <test/cmd.h>
> +#include <test/test.h>
> +#include <test/ut.h>
> +#include <u-boot/crc.h>
> +
> +static const int sizes[] = { 32, SZ_1K, SZ_4K, SZ_1M, SZ_16M, SZ_1M - 1, SZ_1M + 1, 6758401 };
> +
> +static int do_test_cmd_zip_unzip(struct unit_test_state *uts, const int size,
> + const bool gzwrite)
> +{
> + env_set_hex("size", size);
> +
> + /*
> + * Prepare three buffers, $loadadd, $encaddr, $decaddr, and
> + * fill them all with random data. Add slight space between
> + * the compressed buffer 'encaddr' and uncompressed buffer
> + * 'decaddr', because the compressed data with gzip header
> + * might be longer than uncompressed source data 'loadaddr',
> + * and if the uncompressed data buffer 'decaddr' followed
> + * 'encaddr', the decompression could corrupt end of 'encaddr'
> + * buffer.
> + */
> + ut_assertok(run_command("setexpr encaddr $loadaddr + $size", 0));
> + ut_assertok(run_command("setexpr encaddr $encaddr + 0x10000", 0));
> +
> + ut_assertok(run_command("setexpr decaddr $encaddr + $size", 0));
> + ut_assertok(run_command("setexpr decaddr $decaddr + 0x10000", 0));
> +
> + ut_assertok(run_command("random $loadaddr $size", 0));
> + ut_assert_nextline("%d bytes filled with random data", size);
> + ut_assertok(run_command("random $encaddr $size", 0));
> + ut_assert_nextline("%d bytes filled with random data", size);
> + ut_assertok(run_command("random $decaddr $size", 0));
> + ut_assert_nextline("%d bytes filled with random data", size);
> +
> + /* Compress data in $loadaddr into $encaddr */
> + ut_assertok(run_command("zip $loadaddr $size $encaddr", 0));
> + console_record_readline(uts->actual_str, sizeof(uts->actual_str));
> + ut_assert(strstr(uts->actual_str, "Compressed size: "));
> +
> + if (gzwrite) {
> + unsigned int sectsize = DIV_ROUND_UP(size, 512);
> + unsigned char *db = map_sysmem(env_get_ulong("loadaddr", 16, 0), size);
> + u32 crc = crc32(0, db, size);
> +
> + ut_assertok(run_command("gzwrite mmc 9 $encaddr $filesize", 0));
> + ut_assert_skip_to_line("\t%u bytes, crc 0x%08x", size, crc);
> +
> + env_set_hex("sectsize", sectsize);
> + ut_assertok(run_command("mmc read $decaddr 0 $sectsize", 0));
> + ut_assert_nextline("MMC read: dev # 9, block # 0, count %u ... %u blocks read: OK",
> + sectsize, sectsize);
> + } else {
> + /* Decompress data in $encaddr into $decaddr */
> + ut_assertok(run_command("unzip $encaddr $decaddr $filesize", 0));
> + ut_assert_nextline("Uncompressed size: %u = 0x%X", size, size);
> + }
> +
> + /* Input data and compressed-decompressed data */
> + ut_assertok(run_command("cmp.b $loadaddr $decaddr $size", 0));
> + ut_assert_nextline("Total of %u byte(s) were the same", size);
> +
> + ut_assert_console_end();
> +
> + return 0;
> +}
> +
> +static int dm_test_cmd_zip_unzip(struct unit_test_state *uts)
> +{
> + int i, ret;
> +
> + for (i = 0; i < ARRAY_SIZE(sizes); i++) {
> + ret = do_test_cmd_zip_unzip(uts, sizes[i], false);
> + if (ret)
> + return ret;
> + }
> +
> + return 0;
> +}
> +DM_TEST(dm_test_cmd_zip_unzip, UTF_CONSOLE);
> +
> +static int dm_test_cmd_zip_gzwrite(struct unit_test_state *uts)
> +{
> + struct blk_desc *mmc_dev_desc;
> + struct udevice *dev;
> + ofnode root, node;
> + int i, ret;
> +
> + /* Enable the mmc9 node for this test */
> + root = oftree_root(oftree_default());
> + node = ofnode_find_subnode(root, "mmc9");
> + ut_assert(ofnode_valid(node));
> + ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false));
> +
> + ut_asserteq(9, blk_get_device_by_str("mmc", "9", &mmc_dev_desc));
> + ut_assertok(run_commandf("mmc dev 9"));
> + ut_assert_nextline("switch to partitions #0, OK");
> + ut_assert_nextline("mmc9 is current device");
> +
> + for (i = 0; i < ARRAY_SIZE(sizes); i++) {
> + ret = do_test_cmd_zip_unzip(uts, sizes[i], true);
> + if (ret)
> + return ret;
> + }
> +
> + return 0;
> +}
> +DM_TEST(dm_test_cmd_zip_gzwrite, UTF_CONSOLE);
> diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
> index 6d535b5206d..b7166d59943 100644
> --- a/test/py/tests/test_ut.py
> +++ b/test/py/tests/test_ut.py
> @@ -522,6 +522,12 @@ def test_ut_dm_init(ubman):
> with open(fn, 'wb') as fh:
> fh.write(data)
>
> + mmc_dev = 9
> + fn = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img')
> + data = b'\x00' * (32 * 1024 * 1024)
> + with open(fn, 'wb') as fh:
> + fh.write(data)
> +
>
> def setup_efi_image(ubman):
> """Create a 20MB disk image with an EFI app on it"""
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2 2/2] test: cmd: Add test for zip/unzip/gzwrite commands
2026-01-29 23:55 ` [PATCH v2 2/2] test: cmd: Add test for zip/unzip/gzwrite commands Marek Vasut
2026-01-30 7:57 ` Mattijs Korpershoek
2026-02-02 20:03 ` Heinrich Schuchardt
@ 2026-02-03 21:31 ` Simon Glass
2026-02-04 23:44 ` Marek Vasut
2 siblings, 1 reply; 8+ messages in thread
From: Simon Glass @ 2026-02-03 21:31 UTC (permalink / raw)
To: Marek Vasut
Cc: u-boot, Alexander Graf, Heinrich Schuchardt, Ilias Apalodimas,
Jerome Forissier, Mattijs Korpershoek, Neil Armstrong, Peng Fan,
Quentin Schulz, Tom Rini, Yuya Hamamachi
Hi Marek,
On Fri, 30 Jan 2026 at 12:57, Marek Vasut
<marek.vasut+renesas@mailbox.org> wrote:
>
> Add simple test for zip/unzip/gzwrite commands. The test works as
> follows. First, create three buffers with a bit of space between
> each of them, fill them with random data, then compress data in
> buffer 1 into buffer 2, decompress data in buffer 2 either directly
> into buffer 3 or into MMC 1 and then read them back into buffer 3,
> and finally compare buffer 1 and buffer 3, they have to be identical.
>
> The buffers are filled with random data to detect out of bounds writes.
> Test for various sizes, both small and large and unaligned.
>
> The test uses ut_assert_skip_to_line() to skip over gzwrite progress
> bar. Since the progress bar updates fill up the console record buffer,
> increase the size of it to compensate.
>
> Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
> ---
> Cc: Alexander Graf <agraf@csgraf.de>
> Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> Cc: Jerome Forissier <jerome@forissier.org>
> Cc: Mattijs Korpershoek <mkorpershoek@kernel.org>
> Cc: Neil Armstrong <neil.armstrong@linaro.org>
> Cc: Peng Fan <peng.fan@nxp.com>
> Cc: Quentin Schulz <quentin.schulz@cherry.de>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Tom Rini <trini@konsulko.com>
> Cc: Yuya Hamamachi <yuya.hamamachi.sx@renesas.com>
> Cc: u-boot@lists.denx.de
> ---
> V2: Use ut_assert_skip_to_line() to skip over the progress bar.
> Since that fills up the console record buffer, increase the
> size of it to compensate.
> ---
> arch/sandbox/dts/test.dts | 7 +++
> common/Kconfig | 2 +-
> test/cmd/Makefile | 4 ++
> test/cmd/unzip.c | 123 ++++++++++++++++++++++++++++++++++++++
> test/py/tests/test_ut.py | 6 ++
> 5 files changed, 141 insertions(+), 1 deletion(-)
> create mode 100644 test/cmd/unzip.c
>
> diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
> index b7402d7042a..762c1d9bbe2 100644
> --- a/arch/sandbox/dts/test.dts
> +++ b/arch/sandbox/dts/test.dts
> @@ -1272,6 +1272,13 @@
> filename = "mmc8.img";
> };
>
> + /* This is used for zip/unzip/gzwrite tests. */
> + mmc9 {
> + status = "disabled";
> + compatible = "sandbox,mmc";
> + filename = "mmc9.img";
> + };
> +
> pch {
> compatible = "sandbox,pch";
> };
> diff --git a/common/Kconfig b/common/Kconfig
> index 47d17f4e7c6..63448bdc13b 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -26,7 +26,7 @@ config CONSOLE_RECORD_INIT_F
> config CONSOLE_RECORD_OUT_SIZE
> hex "Output buffer size"
> depends on CONSOLE_RECORD
> - default 0x6000
> + default 0x20000
> help
> Set the size of the console recording output buffer. When this fills
> up, no more data will be recorded until some is removed. The buffer
> diff --git a/test/cmd/Makefile b/test/cmd/Makefile
> index 2476068aee6..273009a034f 100644
> --- a/test/cmd/Makefile
> +++ b/test/cmd/Makefile
> @@ -45,3 +45,7 @@ endif
> obj-$(CONFIG_ARM_FFA_TRANSPORT) += armffa.o
> endif
> obj-$(CONFIG_CMD_SPAWN) += spawn.o
> +
> +ifdef CONFIG_CMD_ZIP
> +obj-$(CONFIG_CMD_UNZIP) += unzip.o
> +endif
> diff --git a/test/cmd/unzip.c b/test/cmd/unzip.c
> new file mode 100644
> index 00000000000..dc4a9c93745
> --- /dev/null
> +++ b/test/cmd/unzip.c
> @@ -0,0 +1,123 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Tests for zip/unzip/gzwrite commands
> + *
> + * Copyright 2026, Marek Vasut <marek.vasut+renesas@mailbox.org>
> + */
> +
> +#include <command.h>
> +#include <env.h>
> +#include <dm.h>
> +#include <dm/lists.h>
> +#include <dm/test.h>
> +#include <linux/sizes.h>
> +#include <mapmem.h>
> +#include <part.h>
> +#include <test/cmd.h>
> +#include <test/test.h>
> +#include <test/ut.h>
> +#include <u-boot/crc.h>
> +
> +static const int sizes[] = { 32, SZ_1K, SZ_4K, SZ_1M, SZ_16M, SZ_1M - 1, SZ_1M + 1, 6758401 };
> +
> +static int do_test_cmd_zip_unzip(struct unit_test_state *uts, const int size,
> + const bool gzwrite)
> +{
> + env_set_hex("size", size);
> +
> + /*
> + * Prepare three buffers, $loadadd, $encaddr, $decaddr, and
> + * fill them all with random data. Add slight space between
> + * the compressed buffer 'encaddr' and uncompressed buffer
> + * 'decaddr', because the compressed data with gzip header
> + * might be longer than uncompressed source data 'loadaddr',
> + * and if the uncompressed data buffer 'decaddr' followed
> + * 'encaddr', the decompression could corrupt end of 'encaddr'
> + * buffer.
> + */
> + ut_assertok(run_command("setexpr encaddr $loadaddr + $size", 0));
> + ut_assertok(run_command("setexpr encaddr $encaddr + 0x10000", 0));
> +
> + ut_assertok(run_command("setexpr decaddr $encaddr + $size", 0));
> + ut_assertok(run_command("setexpr decaddr $decaddr + 0x10000", 0));
> +
> + ut_assertok(run_command("random $loadaddr $size", 0));
> + ut_assert_nextline("%d bytes filled with random data", size);
> + ut_assertok(run_command("random $encaddr $size", 0));
> + ut_assert_nextline("%d bytes filled with random data", size);
> + ut_assertok(run_command("random $decaddr $size", 0));
> + ut_assert_nextline("%d bytes filled with random data", size);
I would argue for calling the functions directly instead of via run_command()
> +
> + /* Compress data in $loadaddr into $encaddr */
> + ut_assertok(run_command("zip $loadaddr $size $encaddr", 0));
Perhaps add a flag to avoid generating so much output from this command?
> + console_record_readline(uts->actual_str, sizeof(uts->actual_str));
> + ut_assert(strstr(uts->actual_str, "Compressed size: "));
> +
> + if (gzwrite) {
> + unsigned int sectsize = DIV_ROUND_UP(size, 512);
> + unsigned char *db = map_sysmem(env_get_ulong("loadaddr", 16, 0), size);
> + u32 crc = crc32(0, db, size);
> +
> + ut_assertok(run_command("gzwrite mmc 9 $encaddr $filesize", 0));
> + ut_assert_skip_to_line("\t%u bytes, crc 0x%08x", size, crc);
> +
> + env_set_hex("sectsize", sectsize);
> + ut_assertok(run_command("mmc read $decaddr 0 $sectsize", 0));
You can use run_commandf and %lx for the args. No need to set env vars.
> + ut_assert_nextline("MMC read: dev # 9, block # 0, count %u ... %u blocks read: OK",
> + sectsize, sectsize);
> + } else {
> + /* Decompress data in $encaddr into $decaddr */
> + ut_assertok(run_command("unzip $encaddr $decaddr $filesize", 0));
> + ut_assert_nextline("Uncompressed size: %u = 0x%X", size, size);
> + }
> +
> + /* Input data and compressed-decompressed data */
> + ut_assertok(run_command("cmp.b $loadaddr $decaddr $size", 0));
> + ut_assert_nextline("Total of %u byte(s) were the same", size);
ut_asserteq_mem()
> +
> + ut_assert_console_end();
> +
> + return 0;
> +}
> +
> +static int dm_test_cmd_zip_unzip(struct unit_test_state *uts)
> +{
> + int i, ret;
> +
> + for (i = 0; i < ARRAY_SIZE(sizes); i++) {
> + ret = do_test_cmd_zip_unzip(uts, sizes[i], false);
> + if (ret)
> + return ret;
> + }
> +
> + return 0;
> +}
> +DM_TEST(dm_test_cmd_zip_unzip, UTF_CONSOLE);
> +
> +static int dm_test_cmd_zip_gzwrite(struct unit_test_state *uts)
> +{
> + struct blk_desc *mmc_dev_desc;
> + struct udevice *dev;
> + ofnode root, node;
> + int i, ret;
> +
> + /* Enable the mmc9 node for this test */
> + root = oftree_root(oftree_default());
> + node = ofnode_find_subnode(root, "mmc9");
> + ut_assert(ofnode_valid(node));
> + ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false));
> +
> + ut_asserteq(9, blk_get_device_by_str("mmc", "9", &mmc_dev_desc));
> + ut_assertok(run_commandf("mmc dev 9"));
> + ut_assert_nextline("switch to partitions #0, OK");
> + ut_assert_nextline("mmc9 is current device");
Is this actually needed? It seems that the zip command specifies the device.
> +
> + for (i = 0; i < ARRAY_SIZE(sizes); i++) {
> + ret = do_test_cmd_zip_unzip(uts, sizes[i], true);
> + if (ret)
> + return ret;
> + }
> +
> + return 0;
> +}
> +DM_TEST(dm_test_cmd_zip_gzwrite, UTF_CONSOLE);
> diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
> index 6d535b5206d..b7166d59943 100644
> --- a/test/py/tests/test_ut.py
> +++ b/test/py/tests/test_ut.py
> @@ -522,6 +522,12 @@ def test_ut_dm_init(ubman):
> with open(fn, 'wb') as fh:
> fh.write(data)
>
> + mmc_dev = 9
> + fn = os.path.join(ubman.config.source_dir, f'mmc{mmc_dev}.img')
> + data = b'\x00' * (32 * 1024 * 1024)
> + with open(fn, 'wb') as fh:
> + fh.write(data)
> +
>
> def setup_efi_image(ubman):
> """Create a 20MB disk image with an EFI app on it"""
> --
> 2.51.0
>
Regards,
Simon
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2 2/2] test: cmd: Add test for zip/unzip/gzwrite commands
2026-02-03 21:31 ` Simon Glass
@ 2026-02-04 23:44 ` Marek Vasut
0 siblings, 0 replies; 8+ messages in thread
From: Marek Vasut @ 2026-02-04 23:44 UTC (permalink / raw)
To: Simon Glass
Cc: u-boot, Alexander Graf, Heinrich Schuchardt, Ilias Apalodimas,
Jerome Forissier, Mattijs Korpershoek, Neil Armstrong, Peng Fan,
Quentin Schulz, Tom Rini, Yuya Hamamachi
On 2/3/26 10:31 PM, Simon Glass wrote:
Hello Simon,
>> + ut_assertok(run_command("random $loadaddr $size", 0));
>> + ut_assert_nextline("%d bytes filled with random data", size);
>> + ut_assertok(run_command("random $encaddr $size", 0));
>> + ut_assert_nextline("%d bytes filled with random data", size);
>> + ut_assertok(run_command("random $decaddr $size", 0));
>> + ut_assert_nextline("%d bytes filled with random data", size);
>
> I would argue for calling the functions directly instead of via run_command()
It seems I cannot include sys/random.h in this test to get access to
getrandom() function , do you have any suggestion here ?
>> +
>> + /* Compress data in $loadaddr into $encaddr */
>> + ut_assertok(run_command("zip $loadaddr $size $encaddr", 0));
>
> Perhaps add a flag to avoid generating so much output from this command?
It is the gzwrite command which generates a lot of output, not the zip
command. And the excess output from gzwrite command is solved in this v2
without any need for special flags to gzwrite like in V1 of this patchset.
[...]
^ permalink raw reply [flat|nested] 8+ messages in thread