mirror of
https://xff.cz/git/u-boot/
synced 2025-09-01 16:52:14 +02:00
test: compression: Convert to unit test framework
Adjust this test to use the unit test framework. Drop the two existing commands for running the tests and replace them with a single 'ut compression' command, with sub-commands. Signed-off-by: Simon Glass <sjg@chromium.org> [trini: Continue to have ret = run_test_internal(...) in run_test so ret is always initialized] Signed-off-by: Tom Rini <trini@konsulko.com>
This commit is contained in:
17
include/test/compression.h
Normal file
17
include/test/compression.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017 Google, Inc
|
||||||
|
* Written by Simon Glass <sjg@chromium.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0+
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __TEST_COMPRESSION_H__
|
||||||
|
#define __TEST_COMPRESSION_H__
|
||||||
|
|
||||||
|
#include <test/test.h>
|
||||||
|
|
||||||
|
/* Declare a new compression test */
|
||||||
|
#define COMPRESSION_TEST(_name, _flags) \
|
||||||
|
UNIT_TEST(_name, _flags, compression_test)
|
||||||
|
|
||||||
|
#endif /* __TEST_ENV_H__ */
|
@@ -28,5 +28,6 @@ int do_ut_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
|
|||||||
int do_ut_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
|
int do_ut_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
|
||||||
int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
|
int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
|
||||||
int do_ut_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
|
int do_ut_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
|
||||||
|
int do_ut_compression(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
|
||||||
|
|
||||||
#endif /* __TEST_SUITES_H__ */
|
#endif /* __TEST_SUITES_H__ */
|
||||||
|
@@ -50,6 +50,10 @@ static cmd_tbl_t cmd_ut_sub[] = {
|
|||||||
#ifdef CONFIG_UT_TIME
|
#ifdef CONFIG_UT_TIME
|
||||||
U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
|
U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef CONFIG_SANDBOX
|
||||||
|
U_BOOT_CMD_MKENT(compression, CONFIG_SYS_MAXARGS, 1, do_ut_compression,
|
||||||
|
"", ""),
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
@@ -101,6 +105,9 @@ static char ut_help_text[] =
|
|||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_UT_TIME
|
#ifdef CONFIG_UT_TIME
|
||||||
"ut time - Very basic test of time functions\n"
|
"ut time - Very basic test of time functions\n"
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_SANDBOX
|
||||||
|
"ut compression - Test compressors and bootm decompression\n"
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
#endif
|
#endif
|
||||||
|
@@ -4,8 +4,6 @@
|
|||||||
* SPDX-License-Identifier: GPL-2.0+
|
* SPDX-License-Identifier: GPL-2.0+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DEBUG
|
|
||||||
|
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <bootm.h>
|
#include <bootm.h>
|
||||||
#include <command.h>
|
#include <command.h>
|
||||||
@@ -21,6 +19,9 @@
|
|||||||
#include <lzma/LzmaTools.h>
|
#include <lzma/LzmaTools.h>
|
||||||
|
|
||||||
#include <linux/lzo.h>
|
#include <linux/lzo.h>
|
||||||
|
#include <test/compression.h>
|
||||||
|
#include <test/suites.h>
|
||||||
|
#include <test/ut.h>
|
||||||
|
|
||||||
static const char plain[] =
|
static const char plain[] =
|
||||||
"I am a highly compressable bit of text.\n"
|
"I am a highly compressable bit of text.\n"
|
||||||
@@ -120,10 +121,11 @@ static const unsigned long lz4_compressed_size = 276;
|
|||||||
|
|
||||||
#define TEST_BUFFER_SIZE 512
|
#define TEST_BUFFER_SIZE 512
|
||||||
|
|
||||||
typedef int (*mutate_func)(void *, unsigned long, void *, unsigned long,
|
typedef int (*mutate_func)(struct unit_test_state *uts, void *, unsigned long,
|
||||||
unsigned long *);
|
void *, unsigned long, unsigned long *);
|
||||||
|
|
||||||
static int compress_using_gzip(void *in, unsigned long in_size,
|
static int compress_using_gzip(struct unit_test_state *uts,
|
||||||
|
void *in, unsigned long in_size,
|
||||||
void *out, unsigned long out_max,
|
void *out, unsigned long out_max,
|
||||||
unsigned long *out_size)
|
unsigned long *out_size)
|
||||||
{
|
{
|
||||||
@@ -137,7 +139,8 @@ static int compress_using_gzip(void *in, unsigned long in_size,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uncompress_using_gzip(void *in, unsigned long in_size,
|
static int uncompress_using_gzip(struct unit_test_state *uts,
|
||||||
|
void *in, unsigned long in_size,
|
||||||
void *out, unsigned long out_max,
|
void *out, unsigned long out_max,
|
||||||
unsigned long *out_size)
|
unsigned long *out_size)
|
||||||
{
|
{
|
||||||
@@ -151,13 +154,14 @@ static int uncompress_using_gzip(void *in, unsigned long in_size,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compress_using_bzip2(void *in, unsigned long in_size,
|
static int compress_using_bzip2(struct unit_test_state *uts,
|
||||||
|
void *in, unsigned long in_size,
|
||||||
void *out, unsigned long out_max,
|
void *out, unsigned long out_max,
|
||||||
unsigned long *out_size)
|
unsigned long *out_size)
|
||||||
{
|
{
|
||||||
/* There is no bzip2 compression in u-boot, so fake it. */
|
/* There is no bzip2 compression in u-boot, so fake it. */
|
||||||
assert(in_size == strlen(plain));
|
ut_asserteq(in_size, strlen(plain));
|
||||||
assert(memcmp(plain, in, in_size) == 0);
|
ut_asserteq(0, memcmp(plain, in, in_size));
|
||||||
|
|
||||||
if (bzip2_compressed_size > out_max)
|
if (bzip2_compressed_size > out_max)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -169,7 +173,8 @@ static int compress_using_bzip2(void *in, unsigned long in_size,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uncompress_using_bzip2(void *in, unsigned long in_size,
|
static int uncompress_using_bzip2(struct unit_test_state *uts,
|
||||||
|
void *in, unsigned long in_size,
|
||||||
void *out, unsigned long out_max,
|
void *out, unsigned long out_max,
|
||||||
unsigned long *out_size)
|
unsigned long *out_size)
|
||||||
{
|
{
|
||||||
@@ -184,13 +189,14 @@ static int uncompress_using_bzip2(void *in, unsigned long in_size,
|
|||||||
return (ret != BZ_OK);
|
return (ret != BZ_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compress_using_lzma(void *in, unsigned long in_size,
|
static int compress_using_lzma(struct unit_test_state *uts,
|
||||||
|
void *in, unsigned long in_size,
|
||||||
void *out, unsigned long out_max,
|
void *out, unsigned long out_max,
|
||||||
unsigned long *out_size)
|
unsigned long *out_size)
|
||||||
{
|
{
|
||||||
/* There is no lzma compression in u-boot, so fake it. */
|
/* There is no lzma compression in u-boot, so fake it. */
|
||||||
assert(in_size == strlen(plain));
|
ut_asserteq(in_size, strlen(plain));
|
||||||
assert(memcmp(plain, in, in_size) == 0);
|
ut_asserteq(0, memcmp(plain, in, in_size));
|
||||||
|
|
||||||
if (lzma_compressed_size > out_max)
|
if (lzma_compressed_size > out_max)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -202,7 +208,8 @@ static int compress_using_lzma(void *in, unsigned long in_size,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uncompress_using_lzma(void *in, unsigned long in_size,
|
static int uncompress_using_lzma(struct unit_test_state *uts,
|
||||||
|
void *in, unsigned long in_size,
|
||||||
void *out, unsigned long out_max,
|
void *out, unsigned long out_max,
|
||||||
unsigned long *out_size)
|
unsigned long *out_size)
|
||||||
{
|
{
|
||||||
@@ -216,13 +223,14 @@ static int uncompress_using_lzma(void *in, unsigned long in_size,
|
|||||||
return (ret != SZ_OK);
|
return (ret != SZ_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compress_using_lzo(void *in, unsigned long in_size,
|
static int compress_using_lzo(struct unit_test_state *uts,
|
||||||
|
void *in, unsigned long in_size,
|
||||||
void *out, unsigned long out_max,
|
void *out, unsigned long out_max,
|
||||||
unsigned long *out_size)
|
unsigned long *out_size)
|
||||||
{
|
{
|
||||||
/* There is no lzo compression in u-boot, so fake it. */
|
/* There is no lzo compression in u-boot, so fake it. */
|
||||||
assert(in_size == strlen(plain));
|
ut_asserteq(in_size, strlen(plain));
|
||||||
assert(memcmp(plain, in, in_size) == 0);
|
ut_asserteq(0, memcmp(plain, in, in_size));
|
||||||
|
|
||||||
if (lzo_compressed_size > out_max)
|
if (lzo_compressed_size > out_max)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -234,7 +242,8 @@ static int compress_using_lzo(void *in, unsigned long in_size,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uncompress_using_lzo(void *in, unsigned long in_size,
|
static int uncompress_using_lzo(struct unit_test_state *uts,
|
||||||
|
void *in, unsigned long in_size,
|
||||||
void *out, unsigned long out_max,
|
void *out, unsigned long out_max,
|
||||||
unsigned long *out_size)
|
unsigned long *out_size)
|
||||||
{
|
{
|
||||||
@@ -249,13 +258,14 @@ static int uncompress_using_lzo(void *in, unsigned long in_size,
|
|||||||
return (ret != LZO_E_OK);
|
return (ret != LZO_E_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compress_using_lz4(void *in, unsigned long in_size,
|
static int compress_using_lz4(struct unit_test_state *uts,
|
||||||
|
void *in, unsigned long in_size,
|
||||||
void *out, unsigned long out_max,
|
void *out, unsigned long out_max,
|
||||||
unsigned long *out_size)
|
unsigned long *out_size)
|
||||||
{
|
{
|
||||||
/* There is no lz4 compression in u-boot, so fake it. */
|
/* There is no lz4 compression in u-boot, so fake it. */
|
||||||
assert(in_size == strlen(plain));
|
ut_asserteq(in_size, strlen(plain));
|
||||||
assert(memcmp(plain, in, in_size) == 0);
|
ut_asserteq(0, memcmp(plain, in, in_size));
|
||||||
|
|
||||||
if (lz4_compressed_size > out_max)
|
if (lz4_compressed_size > out_max)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -267,7 +277,8 @@ static int compress_using_lz4(void *in, unsigned long in_size,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uncompress_using_lz4(void *in, unsigned long in_size,
|
static int uncompress_using_lz4(struct unit_test_state *uts,
|
||||||
|
void *in, unsigned long in_size,
|
||||||
void *out, unsigned long out_max,
|
void *out, unsigned long out_max,
|
||||||
unsigned long *out_size)
|
unsigned long *out_size)
|
||||||
{
|
{
|
||||||
@@ -298,7 +309,7 @@ struct buf_state {
|
|||||||
void *compare_buf;
|
void *compare_buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int run_test_internal(char *name,
|
static int run_test_internal(struct unit_test_state *uts, char *name,
|
||||||
mutate_func compress, mutate_func uncompress,
|
mutate_func compress, mutate_func uncompress,
|
||||||
struct buf_state *buf)
|
struct buf_state *buf)
|
||||||
{
|
{
|
||||||
@@ -307,8 +318,9 @@ static int run_test_internal(char *name,
|
|||||||
/* Compress works as expected. */
|
/* Compress works as expected. */
|
||||||
printf("\torig_size:%lu\n", buf->orig_size);
|
printf("\torig_size:%lu\n", buf->orig_size);
|
||||||
memset(buf->compressed_buf, 'A', TEST_BUFFER_SIZE);
|
memset(buf->compressed_buf, 'A', TEST_BUFFER_SIZE);
|
||||||
errcheck(compress(buf->orig_buf, buf->orig_size, buf->compressed_buf,
|
errcheck(compress(uts, buf->orig_buf, buf->orig_size,
|
||||||
buf->compressed_size, &buf->compressed_size) == 0);
|
buf->compressed_buf, buf->compressed_size,
|
||||||
|
&buf->compressed_size) == 0);
|
||||||
printf("\tcompressed_size:%lu\n", buf->compressed_size);
|
printf("\tcompressed_size:%lu\n", buf->compressed_size);
|
||||||
errcheck(buf->compressed_size > 0);
|
errcheck(buf->compressed_size > 0);
|
||||||
errcheck(buf->compressed_size < buf->orig_size);
|
errcheck(buf->compressed_size < buf->orig_size);
|
||||||
@@ -317,7 +329,7 @@ static int run_test_internal(char *name,
|
|||||||
errcheck(((char *)buf->compressed_buf)[buf->compressed_size] == 'A');
|
errcheck(((char *)buf->compressed_buf)[buf->compressed_size] == 'A');
|
||||||
|
|
||||||
/* Uncompresses with space remaining. */
|
/* Uncompresses with space remaining. */
|
||||||
errcheck(uncompress(buf->compressed_buf, buf->compressed_size,
|
errcheck(uncompress(uts, buf->compressed_buf, buf->compressed_size,
|
||||||
buf->uncompressed_buf, buf->uncompressed_size,
|
buf->uncompressed_buf, buf->uncompressed_size,
|
||||||
&buf->uncompressed_size) == 0);
|
&buf->uncompressed_size) == 0);
|
||||||
printf("\tuncompressed_size:%lu\n", buf->uncompressed_size);
|
printf("\tuncompressed_size:%lu\n", buf->uncompressed_size);
|
||||||
@@ -327,7 +339,7 @@ static int run_test_internal(char *name,
|
|||||||
|
|
||||||
/* Uncompresses with exactly the right size output buffer. */
|
/* Uncompresses with exactly the right size output buffer. */
|
||||||
memset(buf->uncompressed_buf, 'A', TEST_BUFFER_SIZE);
|
memset(buf->uncompressed_buf, 'A', TEST_BUFFER_SIZE);
|
||||||
errcheck(uncompress(buf->compressed_buf, buf->compressed_size,
|
errcheck(uncompress(uts, buf->compressed_buf, buf->compressed_size,
|
||||||
buf->uncompressed_buf, buf->orig_size,
|
buf->uncompressed_buf, buf->orig_size,
|
||||||
&buf->uncompressed_size) == 0);
|
&buf->uncompressed_size) == 0);
|
||||||
errcheck(buf->uncompressed_size == buf->orig_size);
|
errcheck(buf->uncompressed_size == buf->orig_size);
|
||||||
@@ -337,7 +349,7 @@ static int run_test_internal(char *name,
|
|||||||
|
|
||||||
/* Make sure compression does not over-run. */
|
/* Make sure compression does not over-run. */
|
||||||
memset(buf->compare_buf, 'A', TEST_BUFFER_SIZE);
|
memset(buf->compare_buf, 'A', TEST_BUFFER_SIZE);
|
||||||
ret = compress(buf->orig_buf, buf->orig_size,
|
ret = compress(uts, buf->orig_buf, buf->orig_size,
|
||||||
buf->compare_buf, buf->compressed_size - 1,
|
buf->compare_buf, buf->compressed_size - 1,
|
||||||
NULL);
|
NULL);
|
||||||
errcheck(((char *)buf->compare_buf)[buf->compressed_size] == 'A');
|
errcheck(((char *)buf->compare_buf)[buf->compressed_size] == 'A');
|
||||||
@@ -346,7 +358,7 @@ static int run_test_internal(char *name,
|
|||||||
|
|
||||||
/* Make sure decompression does not over-run. */
|
/* Make sure decompression does not over-run. */
|
||||||
memset(buf->compare_buf, 'A', TEST_BUFFER_SIZE);
|
memset(buf->compare_buf, 'A', TEST_BUFFER_SIZE);
|
||||||
ret = uncompress(buf->compressed_buf, buf->compressed_size,
|
ret = uncompress(uts, buf->compressed_buf, buf->compressed_size,
|
||||||
buf->compare_buf, buf->uncompressed_size - 1,
|
buf->compare_buf, buf->uncompressed_size - 1,
|
||||||
NULL);
|
NULL);
|
||||||
errcheck(((char *)buf->compare_buf)[buf->uncompressed_size - 1] == 'A');
|
errcheck(((char *)buf->compare_buf)[buf->uncompressed_size - 1] == 'A');
|
||||||
@@ -360,7 +372,8 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int run_test(char *name, mutate_func compress, mutate_func uncompress)
|
static int run_test(struct unit_test_state *uts, char *name,
|
||||||
|
mutate_func compress, mutate_func uncompress)
|
||||||
{
|
{
|
||||||
struct buf_state sbuf, *buf = &sbuf;
|
struct buf_state sbuf, *buf = &sbuf;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -380,7 +393,7 @@ static int run_test(char *name, mutate_func compress, mutate_func uncompress)
|
|||||||
buf->compare_buf = malloc(buf->uncompressed_size);
|
buf->compare_buf = malloc(buf->uncompressed_size);
|
||||||
errcheck(buf->compare_buf);
|
errcheck(buf->compare_buf);
|
||||||
|
|
||||||
ret = run_test_internal(name, compress, uncompress, buf);
|
ret = run_test_internal(uts, name, compress, uncompress, buf);
|
||||||
out:
|
out:
|
||||||
printf(" %s: %s\n", name, ret == 0 ? "ok" : "FAILED");
|
printf(" %s: %s\n", name, ret == 0 ? "ok" : "FAILED");
|
||||||
|
|
||||||
@@ -391,23 +404,41 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_ut_compression(cmd_tbl_t *cmdtp, int flag, int argc,
|
static int compression_test_gzip(struct unit_test_state *uts)
|
||||||
char *const argv[])
|
|
||||||
{
|
{
|
||||||
int err = 0;
|
return run_test(uts, "gzip", compress_using_gzip,
|
||||||
|
uncompress_using_gzip);
|
||||||
err += run_test("gzip", compress_using_gzip, uncompress_using_gzip);
|
|
||||||
err += run_test("bzip2", compress_using_bzip2, uncompress_using_bzip2);
|
|
||||||
err += run_test("lzma", compress_using_lzma, uncompress_using_lzma);
|
|
||||||
err += run_test("lzo", compress_using_lzo, uncompress_using_lzo);
|
|
||||||
err += run_test("lz4", compress_using_lz4, uncompress_using_lz4);
|
|
||||||
|
|
||||||
printf("ut_compression %s\n", err == 0 ? "ok" : "FAILED");
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
COMPRESSION_TEST(compression_test_gzip, 0);
|
||||||
|
|
||||||
static int compress_using_none(void *in, unsigned long in_size,
|
static int compression_test_bzip2(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
return run_test(uts, "bzip2", compress_using_bzip2,
|
||||||
|
uncompress_using_bzip2);
|
||||||
|
}
|
||||||
|
COMPRESSION_TEST(compression_test_bzip2, 0);
|
||||||
|
|
||||||
|
static int compression_test_lzma(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
return run_test(uts, "lzma", compress_using_lzma,
|
||||||
|
uncompress_using_lzma);
|
||||||
|
}
|
||||||
|
COMPRESSION_TEST(compression_test_lzma, 0);
|
||||||
|
|
||||||
|
static int compression_test_lzo(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
return run_test(uts, "lzo", compress_using_lzo, uncompress_using_lzo);
|
||||||
|
}
|
||||||
|
COMPRESSION_TEST(compression_test_lzo, 0);
|
||||||
|
|
||||||
|
static int compression_test_lz4(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
return run_test(uts, "lz4", compress_using_lz4, uncompress_using_lz4);
|
||||||
|
}
|
||||||
|
COMPRESSION_TEST(compression_test_lz4, 0);
|
||||||
|
|
||||||
|
static int compress_using_none(struct unit_test_state *uts,
|
||||||
|
void *in, unsigned long in_size,
|
||||||
void *out, unsigned long out_max,
|
void *out, unsigned long out_max,
|
||||||
unsigned long *out_size)
|
unsigned long *out_size)
|
||||||
{
|
{
|
||||||
@@ -425,7 +456,8 @@ static int compress_using_none(void *in, unsigned long in_size,
|
|||||||
* @compress: Our function to compress data
|
* @compress: Our function to compress data
|
||||||
* @return 0 if OK, non-zero on failure
|
* @return 0 if OK, non-zero on failure
|
||||||
*/
|
*/
|
||||||
static int run_bootm_test(int comp_type, mutate_func compress)
|
static int run_bootm_test(struct unit_test_state *uts, int comp_type,
|
||||||
|
mutate_func compress)
|
||||||
{
|
{
|
||||||
ulong compress_size = 1024;
|
ulong compress_size = 1024;
|
||||||
void *compress_buff;
|
void *compress_buff;
|
||||||
@@ -438,20 +470,18 @@ static int run_bootm_test(int comp_type, mutate_func compress)
|
|||||||
printf("Testing: %s\n", genimg_get_comp_name(comp_type));
|
printf("Testing: %s\n", genimg_get_comp_name(comp_type));
|
||||||
compress_buff = map_sysmem(image_start, 0);
|
compress_buff = map_sysmem(image_start, 0);
|
||||||
unc_len = strlen(plain);
|
unc_len = strlen(plain);
|
||||||
compress((void *)plain, unc_len, compress_buff, compress_size,
|
compress(uts, (void *)plain, unc_len, compress_buff, compress_size,
|
||||||
&compress_size);
|
&compress_size);
|
||||||
err = bootm_decomp_image(comp_type, load_addr, image_start,
|
err = bootm_decomp_image(comp_type, load_addr, image_start,
|
||||||
IH_TYPE_KERNEL, map_sysmem(load_addr, 0),
|
IH_TYPE_KERNEL, map_sysmem(load_addr, 0),
|
||||||
compress_buff, compress_size, unc_len,
|
compress_buff, compress_size, unc_len,
|
||||||
&load_end);
|
&load_end);
|
||||||
if (err)
|
ut_assertok(err);
|
||||||
return err;
|
|
||||||
err = bootm_decomp_image(comp_type, load_addr, image_start,
|
err = bootm_decomp_image(comp_type, load_addr, image_start,
|
||||||
IH_TYPE_KERNEL, map_sysmem(load_addr, 0),
|
IH_TYPE_KERNEL, map_sysmem(load_addr, 0),
|
||||||
compress_buff, compress_size, unc_len - 1,
|
compress_buff, compress_size, unc_len - 1,
|
||||||
&load_end);
|
&load_end);
|
||||||
if (!err)
|
ut_assert(err);
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
/* We can't detect corruption when not decompressing */
|
/* We can't detect corruption when not decompressing */
|
||||||
if (comp_type == IH_COMP_NONE)
|
if (comp_type == IH_COMP_NONE)
|
||||||
@@ -462,35 +492,52 @@ static int run_bootm_test(int comp_type, mutate_func compress)
|
|||||||
IH_TYPE_KERNEL, map_sysmem(load_addr, 0),
|
IH_TYPE_KERNEL, map_sysmem(load_addr, 0),
|
||||||
compress_buff, compress_size, 0x10000,
|
compress_buff, compress_size, 0x10000,
|
||||||
&load_end);
|
&load_end);
|
||||||
if (!err)
|
ut_assert(err);
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_ut_image_decomp(cmd_tbl_t *cmdtp, int flag, int argc,
|
static int compression_test_bootm_gzip(struct unit_test_state *uts)
|
||||||
char *const argv[])
|
|
||||||
{
|
{
|
||||||
int err = 0;
|
return run_bootm_test(uts, IH_COMP_GZIP, compress_using_gzip);
|
||||||
|
|
||||||
err = run_bootm_test(IH_COMP_GZIP, compress_using_gzip);
|
|
||||||
err |= run_bootm_test(IH_COMP_BZIP2, compress_using_bzip2);
|
|
||||||
err |= run_bootm_test(IH_COMP_LZMA, compress_using_lzma);
|
|
||||||
err |= run_bootm_test(IH_COMP_LZO, compress_using_lzo);
|
|
||||||
err |= run_bootm_test(IH_COMP_LZ4, compress_using_lz4);
|
|
||||||
err |= run_bootm_test(IH_COMP_NONE, compress_using_none);
|
|
||||||
|
|
||||||
printf("ut_image_decomp %s\n", err == 0 ? "ok" : "FAILED");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
COMPRESSION_TEST(compression_test_bootm_gzip, 0);
|
||||||
|
|
||||||
U_BOOT_CMD(
|
static int compression_test_bootm_bzip2(struct unit_test_state *uts)
|
||||||
ut_compression, 5, 1, do_ut_compression,
|
{
|
||||||
"Basic test of compressors: gzip bzip2 lzma lzo", ""
|
return run_bootm_test(uts, IH_COMP_BZIP2, compress_using_bzip2);
|
||||||
);
|
}
|
||||||
|
COMPRESSION_TEST(compression_test_bootm_bzip2, 0);
|
||||||
|
|
||||||
U_BOOT_CMD(
|
static int compression_test_bootm_lzma(struct unit_test_state *uts)
|
||||||
ut_image_decomp, 5, 1, do_ut_image_decomp,
|
{
|
||||||
"Basic test of bootm decompression", ""
|
return run_bootm_test(uts, IH_COMP_LZMA, compress_using_lzma);
|
||||||
);
|
}
|
||||||
|
COMPRESSION_TEST(compression_test_bootm_lzma, 0);
|
||||||
|
|
||||||
|
static int compression_test_bootm_lzo(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
return run_bootm_test(uts, IH_COMP_LZO, compress_using_lzo);
|
||||||
|
}
|
||||||
|
COMPRESSION_TEST(compression_test_bootm_lzo, 0);
|
||||||
|
|
||||||
|
static int compression_test_bootm_lz4(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
return run_bootm_test(uts, IH_COMP_LZ4, compress_using_lz4);
|
||||||
|
}
|
||||||
|
COMPRESSION_TEST(compression_test_bootm_lz4, 0);
|
||||||
|
|
||||||
|
static int compression_test_bootm_none(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
return run_bootm_test(uts, IH_COMP_NONE, compress_using_none);
|
||||||
|
}
|
||||||
|
COMPRESSION_TEST(compression_test_bootm_none, 0);
|
||||||
|
|
||||||
|
int do_ut_compression(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
|
{
|
||||||
|
struct unit_test *tests = ll_entry_start(struct unit_test,
|
||||||
|
compression_test);
|
||||||
|
const int n_ents = ll_entry_count(struct unit_test, compression_test);
|
||||||
|
|
||||||
|
return cmd_ut_category("compression", tests, n_ents, argc, argv);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user