mirror of
https://xff.cz/git/u-boot/
synced 2025-10-28 17:13:38 +01:00
test: spl: Support testing LEGACY_LZMA filesystem images
These will soon be supported, so we need to be able to test it. Export the lzma data and generally use the same process in spl_test_mmc_fs as do_spl_test_load. If we end up needing this in third place in the future, it would probably be good to refactor things out. Signed-off-by: Sean Anderson <seanga2@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -81,6 +81,10 @@ size_t create_image(void *dst, enum spl_test_image type,
|
|||||||
int check_image_info(struct unit_test_state *uts, struct spl_image_info *info1,
|
int check_image_info(struct unit_test_state *uts, struct spl_image_info *info1,
|
||||||
struct spl_image_info *info2);
|
struct spl_image_info *info2);
|
||||||
|
|
||||||
|
/* Some compressed data and it size */
|
||||||
|
extern const char lzma_compressed[];
|
||||||
|
extern const size_t lzma_compressed_size;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* typedef write_image_t - Callback for writing an image
|
* typedef write_image_t - Callback for writing an image
|
||||||
* @uts: Current unit test state
|
* @uts: Current unit test state
|
||||||
|
|||||||
@@ -374,7 +374,7 @@ SPL_IMG_TEST(spl_test_image, FIT_EXTERNAL, 0);
|
|||||||
* LZMA is too complex to generate on the fly, so let's use some data I put in
|
* LZMA is too complex to generate on the fly, so let's use some data I put in
|
||||||
* the oven^H^H^H^H compressed earlier
|
* the oven^H^H^H^H compressed earlier
|
||||||
*/
|
*/
|
||||||
static const char lzma_compressed[] = {
|
const char lzma_compressed[] = {
|
||||||
0x5d, 0x00, 0x00, 0x80, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
0x5d, 0x00, 0x00, 0x80, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||||
0xff, 0x00, 0x02, 0x05, 0x55, 0x4e, 0x82, 0xbc, 0xc2, 0x42, 0xf6, 0x88,
|
0xff, 0x00, 0x02, 0x05, 0x55, 0x4e, 0x82, 0xbc, 0xc2, 0x42, 0xf6, 0x88,
|
||||||
0x6c, 0x99, 0xd6, 0x82, 0x48, 0xa6, 0x06, 0x67, 0xf8, 0x46, 0x7c, 0xe9,
|
0x6c, 0x99, 0xd6, 0x82, 0x48, 0xa6, 0x06, 0x67, 0xf8, 0x46, 0x7c, 0xe9,
|
||||||
@@ -610,6 +610,8 @@ static const char lzma_compressed[] = {
|
|||||||
0x1e, 0xff, 0xff, 0x80, 0x8e, 0x00, 0x00
|
0x1e, 0xff, 0xff, 0x80, 0x8e, 0x00, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const size_t lzma_compressed_size = sizeof(lzma_compressed);
|
||||||
|
|
||||||
int do_spl_test_load(struct unit_test_state *uts, const char *test_name,
|
int do_spl_test_load(struct unit_test_state *uts, const char *test_name,
|
||||||
enum spl_test_image type, struct spl_image_loader *loader,
|
enum spl_test_image type, struct spl_image_loader *loader,
|
||||||
int (*write_image)(struct unit_test_state *, void *, size_t))
|
int (*write_image)(struct unit_test_state *, void *, size_t))
|
||||||
|
|||||||
@@ -320,10 +320,11 @@ static int spl_test_mmc_fs(struct unit_test_state *uts, const char *test_name,
|
|||||||
const char *filename = CONFIG_SPL_FS_LOAD_PAYLOAD_NAME;
|
const char *filename = CONFIG_SPL_FS_LOAD_PAYLOAD_NAME;
|
||||||
struct blk_desc *dev_desc;
|
struct blk_desc *dev_desc;
|
||||||
size_t fs_size, fs_data, img_size, img_data,
|
size_t fs_size, fs_data, img_size, img_data,
|
||||||
data_size = SPL_TEST_DATA_SIZE;
|
plain_size = SPL_TEST_DATA_SIZE;
|
||||||
struct spl_image_info info_write = {
|
struct spl_image_info info_write = {
|
||||||
.name = test_name,
|
.name = test_name,
|
||||||
.size = data_size,
|
.size = type == LEGACY_LZMA ? lzma_compressed_size :
|
||||||
|
plain_size,
|
||||||
}, info_read = { };
|
}, info_read = { };
|
||||||
struct disk_partition part = {
|
struct disk_partition part = {
|
||||||
.start = 1,
|
.start = 1,
|
||||||
@@ -335,7 +336,7 @@ static int spl_test_mmc_fs(struct unit_test_state *uts, const char *test_name,
|
|||||||
.boot_device = loader->boot_device,
|
.boot_device = loader->boot_device,
|
||||||
};
|
};
|
||||||
void *fs;
|
void *fs;
|
||||||
char *data;
|
char *data, *plain;
|
||||||
|
|
||||||
img_size = create_image(NULL, type, &info_write, &img_data);
|
img_size = create_image(NULL, type, &info_write, &img_data);
|
||||||
ut_assert(img_size);
|
ut_assert(img_size);
|
||||||
@@ -345,7 +346,15 @@ static int spl_test_mmc_fs(struct unit_test_state *uts, const char *test_name,
|
|||||||
ut_assertnonnull(fs);
|
ut_assertnonnull(fs);
|
||||||
|
|
||||||
data = fs + fs_data + img_data;
|
data = fs + fs_data + img_data;
|
||||||
generate_data(data, data_size, test_name);
|
if (type == LEGACY_LZMA) {
|
||||||
|
plain = malloc(plain_size);
|
||||||
|
ut_assertnonnull(plain);
|
||||||
|
generate_data(plain, plain_size, "lzma");
|
||||||
|
memcpy(data, lzma_compressed, lzma_compressed_size);
|
||||||
|
} else {
|
||||||
|
plain = data;
|
||||||
|
generate_data(plain, plain_size, test_name);
|
||||||
|
}
|
||||||
ut_asserteq(img_size, create_image(fs + fs_data, type, &info_write,
|
ut_asserteq(img_size, create_image(fs + fs_data, type, &info_write,
|
||||||
NULL));
|
NULL));
|
||||||
ut_asserteq(fs_size, create_fs(fs, img_size, filename, NULL));
|
ut_asserteq(fs_size, create_fs(fs, img_size, filename, NULL));
|
||||||
@@ -366,8 +375,12 @@ static int spl_test_mmc_fs(struct unit_test_state *uts, const char *test_name,
|
|||||||
ut_assertok(loader->load_image(&info_read, &bootdev));
|
ut_assertok(loader->load_image(&info_read, &bootdev));
|
||||||
if (check_image_info(uts, &info_write, &info_read))
|
if (check_image_info(uts, &info_write, &info_read))
|
||||||
return CMD_RET_FAILURE;
|
return CMD_RET_FAILURE;
|
||||||
ut_asserteq_mem(data, phys_to_virt(info_write.load_addr), data_size);
|
if (type == LEGACY_LZMA)
|
||||||
|
ut_asserteq(plain_size, info_read.size);
|
||||||
|
ut_asserteq_mem(plain, phys_to_virt(info_write.load_addr), plain_size);
|
||||||
|
|
||||||
|
if (type == LEGACY_LZMA)
|
||||||
|
free(plain);
|
||||||
free(fs);
|
free(fs);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user