test: compression: add zstd uncompression test
Signed-off-by: Brandon Maier <brandon.maier@collins.com>
This commit is contained in:
parent
4b9b25d943
commit
65d373abb0
6 changed files with 76 additions and 1 deletions
|
@ -211,6 +211,7 @@ CONFIG_CMD_DHRYSTONE=y
|
||||||
CONFIG_RSA_VERIFY_WITH_PKEY=y
|
CONFIG_RSA_VERIFY_WITH_PKEY=y
|
||||||
CONFIG_TPM=y
|
CONFIG_TPM=y
|
||||||
CONFIG_LZ4=y
|
CONFIG_LZ4=y
|
||||||
|
CONFIG_ZSTD=y
|
||||||
CONFIG_ERRNO_STR=y
|
CONFIG_ERRNO_STR=y
|
||||||
# CONFIG_CMD_BOOTEFI_BOOTMGR is not set
|
# CONFIG_CMD_BOOTEFI_BOOTMGR is not set
|
||||||
CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y
|
CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y
|
||||||
|
|
|
@ -236,6 +236,7 @@ CONFIG_CMD_DHRYSTONE=y
|
||||||
CONFIG_RSA_VERIFY_WITH_PKEY=y
|
CONFIG_RSA_VERIFY_WITH_PKEY=y
|
||||||
CONFIG_TPM=y
|
CONFIG_TPM=y
|
||||||
CONFIG_LZ4=y
|
CONFIG_LZ4=y
|
||||||
|
CONFIG_ZSTD=y
|
||||||
CONFIG_ERRNO_STR=y
|
CONFIG_ERRNO_STR=y
|
||||||
CONFIG_UNIT_TEST=y
|
CONFIG_UNIT_TEST=y
|
||||||
CONFIG_SPL_UNIT_TEST=y
|
CONFIG_SPL_UNIT_TEST=y
|
||||||
|
|
|
@ -239,6 +239,7 @@ CONFIG_CMD_DHRYSTONE=y
|
||||||
CONFIG_RSA_VERIFY_WITH_PKEY=y
|
CONFIG_RSA_VERIFY_WITH_PKEY=y
|
||||||
CONFIG_TPM=y
|
CONFIG_TPM=y
|
||||||
CONFIG_LZ4=y
|
CONFIG_LZ4=y
|
||||||
|
CONFIG_ZSTD=y
|
||||||
CONFIG_ERRNO_STR=y
|
CONFIG_ERRNO_STR=y
|
||||||
CONFIG_SPL_HEXDUMP=y
|
CONFIG_SPL_HEXDUMP=y
|
||||||
CONFIG_UNIT_TEST=y
|
CONFIG_UNIT_TEST=y
|
||||||
|
|
|
@ -254,6 +254,7 @@ CONFIG_CMD_DHRYSTONE=y
|
||||||
CONFIG_RSA_VERIFY_WITH_PKEY=y
|
CONFIG_RSA_VERIFY_WITH_PKEY=y
|
||||||
CONFIG_TPM=y
|
CONFIG_TPM=y
|
||||||
CONFIG_LZ4=y
|
CONFIG_LZ4=y
|
||||||
|
CONFIG_ZSTD=y
|
||||||
# CONFIG_VPL_LZMA is not set
|
# CONFIG_VPL_LZMA is not set
|
||||||
CONFIG_ERRNO_STR=y
|
CONFIG_ERRNO_STR=y
|
||||||
CONFIG_UNIT_TEST=y
|
CONFIG_UNIT_TEST=y
|
||||||
|
|
|
@ -69,7 +69,7 @@ endif
|
||||||
config UT_COMPRESSION
|
config UT_COMPRESSION
|
||||||
bool "Unit test for compression"
|
bool "Unit test for compression"
|
||||||
depends on UNIT_TEST
|
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
|
default y
|
||||||
help
|
help
|
||||||
Enables tests for compression and decompression routines for simple
|
Enables tests for compression and decompression routines for simple
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
|
#include <abuf.h>
|
||||||
#include <bootm.h>
|
#include <bootm.h>
|
||||||
#include <command.h>
|
#include <command.h>
|
||||||
#include <gzip.h>
|
#include <gzip.h>
|
||||||
|
@ -22,6 +23,7 @@
|
||||||
#include <lzma/LzmaTools.h>
|
#include <lzma/LzmaTools.h>
|
||||||
|
|
||||||
#include <linux/lzo.h>
|
#include <linux/lzo.h>
|
||||||
|
#include <linux/zstd.h>
|
||||||
#include <test/compression.h>
|
#include <test/compression.h>
|
||||||
#include <test/suites.h>
|
#include <test/suites.h>
|
||||||
#include <test/ut.h>
|
#include <test/ut.h>
|
||||||
|
@ -121,6 +123,23 @@ static const char lz4_compressed[] =
|
||||||
"\x9d\x12\x8c\x9d";
|
"\x9d\x12\x8c\x9d";
|
||||||
static const unsigned long lz4_compressed_size = sizeof(lz4_compressed) - 1;
|
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
|
#define TEST_BUFFER_SIZE 512
|
||||||
|
|
||||||
|
@ -296,6 +315,45 @@ static int uncompress_using_lz4(struct unit_test_state *uts,
|
||||||
return (ret != 0);
|
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)) { \
|
#define errcheck(statement) if (!(statement)) { \
|
||||||
fprintf(stderr, "\tFailed: %s\n", #statement); \
|
fprintf(stderr, "\tFailed: %s\n", #statement); \
|
||||||
ret = 1; \
|
ret = 1; \
|
||||||
|
@ -443,6 +501,13 @@ static int compression_test_lz4(struct unit_test_state *uts)
|
||||||
}
|
}
|
||||||
COMPRESSION_TEST(compression_test_lz4, 0);
|
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,
|
static int compress_using_none(struct unit_test_state *uts,
|
||||||
void *in, unsigned long in_size,
|
void *in, unsigned long in_size,
|
||||||
void *out, unsigned long out_max,
|
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);
|
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)
|
static int compression_test_bootm_none(struct unit_test_state *uts)
|
||||||
{
|
{
|
||||||
return run_bootm_test(uts, IH_COMP_NONE, compress_using_none);
|
return run_bootm_test(uts, IH_COMP_NONE, compress_using_none);
|
||||||
|
|
Loading…
Reference in a new issue