From 093e8c8de5c15fb19cc7af4d34cb60363cc90a41 Mon Sep 17 00:00:00 2001 From: Brandon Maier Date: Mon, 9 Jan 2023 12:42:58 -0600 Subject: test: compression: use sizeof() instead of magic numbers Signed-off-by: Brandon Maier --- test/compression.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/compression.c b/test/compression.c index ba98d21802c..de6dfbbfcda 100644 --- a/test/compression.c +++ b/test/compression.c @@ -53,7 +53,7 @@ static const char bzip2_compressed[] = "\xe1\xf0\x9d\xa4\x15\x8b\xb8\xc6\x93\xdc\x3d\xd9\x3c\x22\x55\xef" "\xfb\xbb\x2a\xd3\x87\xa2\x8b\x04\xd9\x19\xf8\xe2\xfd\x4f\xdb\x1a" "\x07\xc8\x60\xa3\x3f\xf8\xbb\x92\x29\xc2\x84\x87\x2b\x1e\xe8\x48"; -static const unsigned long bzip2_compressed_size = 240; +static const unsigned long bzip2_compressed_size = sizeof(bzip2_compressed) - 1; /* lzma -z -c /tmp/plain.txt > /tmp/plain.lzma */ static const char lzma_compressed[] = @@ -72,7 +72,7 @@ static const char lzma_compressed[] = "\x6b\x85\x40\x08\x1f\xdf\x26\x25\x3b\x72\x44\xb0\xb8\x21\x2f\xb3" "\xd7\x9b\x24\x30\x78\x26\x44\x07\xc3\x33\xd1\x4d\x03\x1b\xe1\xff" "\xfd\xf5\x50\x8d\xca"; -static const unsigned long lzma_compressed_size = 229; +static const unsigned long lzma_compressed_size = sizeof(lzma_compressed) - 1; /* lzop -c /tmp/plain.txt > /tmp/plain.lzo */ static const char lzo_compressed[] = @@ -97,7 +97,7 @@ static const char lzo_compressed[] = "\x6c\x79\x20\x69\x6e\x20\x74\x68\x65\x20\x66\x61\x63\x65\x20\x6f" "\x66\x20\x73\x68\x6f\x72\x74\x20\x74\x65\x78\x74\x0a\x6d\x65\x73" "\x73\x61\x67\x65\x73\x2e\x0a\x11\x00\x00\x00\x00\x00\x00"; -static const unsigned long lzo_compressed_size = 334; +static const unsigned long lzo_compressed_size = sizeof(lzo_compressed) - 1; /* lz4 -z /tmp/plain.txt > /tmp/plain.lz4 */ static const char lz4_compressed[] = @@ -119,7 +119,7 @@ static const char lz4_compressed[] = "\x6c\x79\x4e\x00\x30\x61\x63\x65\x27\x01\x01\x95\x00\x01\x2d\x01" "\xb0\x0a\x6d\x65\x73\x73\x61\x67\x65\x73\x2e\x0a\x00\x00\x00\x00" "\x9d\x12\x8c\x9d"; -static const unsigned long lz4_compressed_size = 276; +static const unsigned long lz4_compressed_size = sizeof(lz4_compressed) - 1; #define TEST_BUFFER_SIZE 512 -- cgit v1.2.3 From 601d1bfe9e313938e24a83f64d2d45aa62a16abd Mon Sep 17 00:00:00 2001 From: Enric Balletbo i Serra Date: Tue, 10 Jan 2023 17:19:35 +0100 Subject: test/py: gpt: add test for the gpt partition type GUID identifier Add sandbox test for the gpt partition type command, the test uses the persistent data test_gpt_disk_image.bin to check that the first partition type GUID that identifies the type of the partition has the "Linux filesystem data" type ( 0FC63DAF-8483-4772-8E79-3D69D8477DE4 ). Signed-off-by: Enric Balletbo i Serra --- test/py/tests/test_gpt.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test') diff --git a/test/py/tests/test_gpt.py b/test/py/tests/test_gpt.py index cb44e1d7896..73bfbf77a27 100644 --- a/test/py/tests/test_gpt.py +++ b/test/py/tests/test_gpt.py @@ -134,6 +134,29 @@ def test_gpt_save_guid(state_disk_image, u_boot_console): output = u_boot_console.run_command('printenv newguid') assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('cmd_gpt') +@pytest.mark.requiredtool('sgdisk') +def test_gpt_part_type_uuid(state_disk_image, u_boot_console): + """Test the gpt partittion type UUID command.""" + + u_boot_console.run_command('host bind 0 ' + state_disk_image.path) + output = u_boot_console.run_command('part type host 0:1') + assert '0fc63daf-8483-4772-8e79-3d69d8477de4' in output + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('cmd_gpt') +@pytest.mark.requiredtool('sgdisk') +def test_gpt_part_type_save_uuid(state_disk_image, u_boot_console): + """Test the gpt partittion type to save UUID into a string.""" + + if u_boot_console.config.buildconfig.get('config_cmd_gpt', 'n') != 'y': + pytest.skip('gpt command not supported') + u_boot_console.run_command('host bind 0 ' + state_disk_image.path) + output = u_boot_console.run_command('part type host 0:1 newguid') + output = u_boot_console.run_command('printenv newguid') + assert '0fc63daf-8483-4772-8e79-3d69d8477de4' in output + @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('cmd_gpt') @pytest.mark.buildconfigspec('cmd_gpt_rename') -- cgit v1.2.3 From 65d373abb0e8267ca98723429b330186af35e0e1 Mon Sep 17 00:00:00 2001 From: Brandon Maier Date: Thu, 12 Jan 2023 10:27:46 -0600 Subject: test: compression: add zstd uncompression test Signed-off-by: Brandon Maier --- test/Kconfig | 2 +- test/compression.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/Kconfig b/test/Kconfig index 9f4641ae6bc..465028265b2 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -69,7 +69,7 @@ endif config UT_COMPRESSION bool "Unit test for compression" depends on UNIT_TEST - depends on CMDLINE && GZIP_COMPRESSED && BZIP2 && LZMA && LZO && LZ4 + depends on CMDLINE && GZIP_COMPRESSED && BZIP2 && LZMA && LZO && LZ4 && ZSTD default y help Enables tests for compression and decompression routines for simple diff --git a/test/compression.c b/test/compression.c index de6dfbbfcda..3df90819a1f 100644 --- a/test/compression.c +++ b/test/compression.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -22,6 +23,7 @@ #include #include +#include #include #include #include @@ -121,6 +123,23 @@ static const char lz4_compressed[] = "\x9d\x12\x8c\x9d"; static const unsigned long lz4_compressed_size = sizeof(lz4_compressed) - 1; +/* zstd -19 -c /tmp/plain.txt > /tmp/plain.zst */ +static const char zstd_compressed[] = + "\x28\xb5\x2f\xfd\x64\x5e\x00\xbd\x05\x00\x02\x0e\x26\x1a\x70\x17" + "\xb8\x0d\x0c\x53\x5c\x9d\x97\xee\xa0\x5d\x84\x89\x3f\x5c\x7a\x78" + "\x00\x80\x80\x0f\xe8\xdf\xaf\x06\x66\xd0\x23\xa6\x7a\x64\x8e\xf4" + "\x0d\x5b\x47\x65\x26\x7e\x81\xdd\x0b\xe7\x5a\x95\x3d\x49\xcc\x67" + "\xe0\x2d\x46\x58\xb6\xac\x64\x16\xf2\xe0\xf8\x16\x17\xaf\xda\x8f" + "\x37\xc0\xc3\x0d\x3b\x89\x57\x15\x1e\x46\x46\x12\x9a\x84\xbe\xa6" + "\xab\xcf\x50\x90\x5f\x78\x01\xd2\xc0\x51\x72\x59\x0b\xea\xab\xf2" + "\xd4\x2b\x2d\x26\x7c\x10\x66\x78\x42\x64\x45\x3f\xa5\x15\x6f\xbd" + "\x4a\x61\xe1\xc8\x27\xc0\xe3\x95\x0c\xf9\xca\x7c\xf5\x13\x30\xc3" + "\x1a\x7c\x7d\xa4\x17\x0b\xff\x14\xa6\x7a\x95\xa0\x34\xbc\xce\x21" + "\x78\x36\x23\x33\x11\x09\x00\x60\x13\x00\x63\xa3\x8e\x28\x94\x55" + "\x15\xb6\x26\x68\x05\x4f\x23\x12\xee\x53\x55\x2d\x44\x2f\x54\x95" + "\x01\xe4\xf4\x6e\xfa"; +static const unsigned long zstd_compressed_size = sizeof(zstd_compressed) - 1; + #define TEST_BUFFER_SIZE 512 @@ -296,6 +315,45 @@ static int uncompress_using_lz4(struct unit_test_state *uts, return (ret != 0); } +static int compress_using_zstd(struct unit_test_state *uts, + void *in, unsigned long in_size, + void *out, unsigned long out_max, + unsigned long *out_size) +{ + /* There is no zstd compression in u-boot, so fake it. */ + ut_asserteq(in_size, strlen(plain)); + ut_asserteq_mem(plain, in, in_size); + + if (zstd_compressed_size > out_max) + return -1; + + memcpy(out, zstd_compressed, zstd_compressed_size); + if (out_size) + *out_size = zstd_compressed_size; + + return 0; +} + +static int uncompress_using_zstd(struct unit_test_state *uts, + void *in, unsigned long in_size, + void *out, unsigned long out_max, + unsigned long *out_size) +{ + struct abuf in_buf, out_buf; + int ret; + + abuf_init_set(&in_buf, in, in_size); + abuf_init_set(&out_buf, out, out_max); + + ret = zstd_decompress(&in_buf, &out_buf); + if (ret >= 0) { + *out_size = ret; + ret = 0; + } + + return ret; +} + #define errcheck(statement) if (!(statement)) { \ fprintf(stderr, "\tFailed: %s\n", #statement); \ ret = 1; \ @@ -443,6 +501,13 @@ static int compression_test_lz4(struct unit_test_state *uts) } COMPRESSION_TEST(compression_test_lz4, 0); +static int compression_test_zstd(struct unit_test_state *uts) +{ + return run_test(uts, "zstd", compress_using_zstd, + uncompress_using_zstd); +} +COMPRESSION_TEST(compression_test_zstd, 0); + static int compress_using_none(struct unit_test_state *uts, void *in, unsigned long in_size, void *out, unsigned long out_max, @@ -533,6 +598,12 @@ static int compression_test_bootm_lz4(struct unit_test_state *uts) } COMPRESSION_TEST(compression_test_bootm_lz4, 0); +static int compression_test_bootm_zstd(struct unit_test_state *uts) +{ + return run_bootm_test(uts, IH_COMP_ZSTD, compress_using_zstd); +} +COMPRESSION_TEST(compression_test_bootm_zstd, 0); + static int compression_test_bootm_none(struct unit_test_state *uts) { return run_bootm_test(uts, IH_COMP_NONE, compress_using_none); -- cgit v1.2.3