diff options
Diffstat (limited to 'payloads/libpayload/tests')
-rw-r--r-- | payloads/libpayload/tests/libcbfs/cbfs-verification-test.c | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/payloads/libpayload/tests/libcbfs/cbfs-verification-test.c b/payloads/libpayload/tests/libcbfs/cbfs-verification-test.c index 1dcccf9ce9..8e50f39d45 100644 --- a/payloads/libpayload/tests/libcbfs/cbfs-verification-test.c +++ b/payloads/libpayload/tests/libcbfs/cbfs-verification-test.c @@ -43,14 +43,18 @@ vb2_error_t vb2_hash_verify(const void *buf, uint32_t size, const struct vb2_has unsigned long ulzman(const unsigned char *src, unsigned long srcn, unsigned char *dst, unsigned long dstn) { - fail_msg("Unexpected call to %s", __func__); - return 0; + size_t copy_size = MIN(srcn, dstn); + function_called(); + memcpy(dst, src, copy_size); + return copy_size; } size_t ulz4fn(const void *src, size_t srcn, void *dst, size_t dstn) { - fail_msg("Unexpected call to %s", __func__); - return 0; + size_t copy_size = MIN(srcn, dstn); + function_called(); + memcpy(dst, src, copy_size); + return copy_size; } enum cb_err cbfs_mcache_lookup(const void *mcache, size_t mcache_size, const char *name, @@ -167,7 +171,7 @@ static void test_cbfs_map_no_hash(void **state) } } -static void test_cbfs_map_valid_hash(void **state) +static void test_cbfs_map_valid_hash_impl(void **state, bool lz4_compressed) { void *mapping = NULL; size_t size = 0; @@ -181,8 +185,17 @@ static void test_cbfs_map_valid_hash(void **state) expect_cbfs_lookup(TEST_DATA_1_FILENAME, CB_SUCCESS, (const union cbfs_mdata *)&file_valid_hash, be32toh(file_valid_hash.header.offset)); - will_return(cbfs_find_attr, NULL); + if (lz4_compressed) { + struct cbfs_file_attr_compression cattr = { + .compression = htobe32(CBFS_COMPRESS_LZ4), + .decompressed_size = htobe32(TEST_DATA_1_SIZE), + }; + will_return(cbfs_find_attr, &cattr); + expect_function_call(ulz4fn); + } else { + will_return(cbfs_find_attr, NULL); + } if (CONFIG(LP_CBFS_VERIFICATION)) { will_return(cbfs_file_hash, &hash); @@ -203,6 +216,16 @@ static void test_cbfs_map_valid_hash(void **state) } } +static void test_cbfs_map_valid_hash(void **state) +{ + test_cbfs_map_valid_hash_impl(state, false); +} + +static void test_cbfs_map_valid_hash_with_lz4(void **state) +{ + test_cbfs_map_valid_hash_impl(state, true); +} + static void test_cbfs_map_invalid_hash(void **state) { void *mapping = NULL; @@ -240,6 +263,7 @@ int main(void) const struct CMUnitTest tests[] = { cmocka_unit_test_setup(test_cbfs_map_no_hash, setup_test_cbfs), cmocka_unit_test_setup(test_cbfs_map_valid_hash, setup_test_cbfs), + cmocka_unit_test_setup(test_cbfs_map_valid_hash_with_lz4, setup_test_cbfs), cmocka_unit_test_setup(test_cbfs_map_invalid_hash, setup_test_cbfs), }; |