diff options
author | Jakub Czapiga <jacz@semihalf.com> | 2021-11-15 08:36:07 +0000 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2022-01-10 14:30:04 +0000 |
commit | 63e54275f684da6f6db8289561726adab5254b39 (patch) | |
tree | a01a1b40170f88ef0036585564eb30ac8b57ef48 /payloads/libpayload/tests/mocks | |
parent | 1fa3da4d9b30ad7e63b79b6966794ee179dc6501 (diff) |
libpayload: Implement new CBFS access API
This commit adds new CBFS API, which is based on the one available in
the main coreboot source tree. Libpayload implementation supports RO/RW
file lookups and file contents verification.
Change-Id: I00da0658dbac0cddf92ad55611def947932d23c7
Signed-off-by: Jakub Czapiga <jacz@semihalf.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/59497
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'payloads/libpayload/tests/mocks')
-rw-r--r-- | payloads/libpayload/tests/mocks/cbfs_file_mock.c | 95 | ||||
-rw-r--r-- | payloads/libpayload/tests/mocks/die.c | 16 |
2 files changed, 111 insertions, 0 deletions
diff --git a/payloads/libpayload/tests/mocks/cbfs_file_mock.c b/payloads/libpayload/tests/mocks/cbfs_file_mock.c new file mode 100644 index 0000000000..3ad078c7b0 --- /dev/null +++ b/payloads/libpayload/tests/mocks/cbfs_file_mock.c @@ -0,0 +1,95 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <mocks/cbfs_util.h> + + +const u8 test_data_1[TEST_DATA_1_SIZE] = { TEST_DATA_1 }; +const u8 test_data_2[TEST_DATA_2_SIZE] = { TEST_DATA_2 }; +const u8 test_data_int_1[TEST_DATA_INT_1_SIZE] = { LE64(TEST_DATA_INT_1) }; +const u8 test_data_int_2[TEST_DATA_INT_2_SIZE] = { LE64(TEST_DATA_INT_2) }; +const u8 test_data_int_3[TEST_DATA_INT_3_SIZE] = { LE64(TEST_DATA_INT_3) }; + +const u8 good_hash[VB2_SHA256_DIGEST_SIZE] = { TEST_SHA256 }; +const u8 bad_hash[VB2_SHA256_DIGEST_SIZE] = { INVALID_SHA256 }; + +const struct cbfs_test_file file_no_hash = { + .header = HEADER_INITIALIZER(CBFS_TYPE_RAW, 0, TEST_DATA_1_SIZE), + .filename = TEST_DATA_1_FILENAME, + .attrs_and_data = { + TEST_DATA_1, + }, +}; + +const struct cbfs_test_file file_valid_hash = { + .header = HEADER_INITIALIZER(CBFS_TYPE_RAW, HASH_ATTR_SIZE, TEST_DATA_1_SIZE), + .filename = TEST_DATA_1_FILENAME, + .attrs_and_data = { + BE32(CBFS_FILE_ATTR_TAG_HASH), + BE32(HASH_ATTR_SIZE), + BE32(VB2_HASH_SHA256), + TEST_SHA256, + TEST_DATA_1, + }, +}; + +const struct cbfs_test_file file_broken_hash = { + .header = HEADER_INITIALIZER(CBFS_TYPE_RAW, HASH_ATTR_SIZE, TEST_DATA_1_SIZE), + .filename = TEST_DATA_1_FILENAME, + .attrs_and_data = { + BE32(CBFS_FILE_ATTR_TAG_HASH), + BE32(HASH_ATTR_SIZE), + BE32(VB2_HASH_SHA256), + INVALID_SHA256, + TEST_DATA_1, + }, +}; + +const struct cbfs_test_file test_file_1 = { + .header = HEADER_INITIALIZER(CBFS_TYPE_RAW, 0, TEST_DATA_1_SIZE), + .filename = TEST_DATA_1_FILENAME, + .attrs_and_data = { + TEST_DATA_1, + }, +}; + +const struct cbfs_test_file test_file_2 = { + .header = HEADER_INITIALIZER(CBFS_TYPE_RAW, sizeof(struct cbfs_file_attr_compression), + TEST_DATA_2_SIZE), + .filename = TEST_DATA_2_FILENAME, + .attrs_and_data = { + BE32(CBFS_FILE_ATTR_TAG_COMPRESSION), + BE32(sizeof(struct cbfs_file_attr_compression)), + BE32(CBFS_COMPRESS_LZMA), + BE32(TEST_DATA_2_SIZE), + TEST_DATA_2, + }, +}; + +const struct cbfs_test_file test_file_int_1 = { + .header = HEADER_INITIALIZER(CBFS_TYPE_RAW, 0, TEST_DATA_INT_1_SIZE), + .filename = TEST_DATA_INT_1_FILENAME, + .attrs_and_data = { + LE64(TEST_DATA_INT_1), + }, +}; + +const struct cbfs_test_file test_file_int_2 = { + .header = HEADER_INITIALIZER(CBFS_TYPE_RAW, 0, TEST_DATA_INT_2_SIZE), + .filename = TEST_DATA_INT_2_FILENAME, + .attrs_and_data = { + LE64(TEST_DATA_INT_2), + }, +}; + +const struct cbfs_test_file test_file_int_3 = { + .header = HEADER_INITIALIZER(CBFS_TYPE_RAW, sizeof(struct cbfs_file_attr_compression), + TEST_DATA_INT_3_SIZE), + .filename = TEST_DATA_INT_3_FILENAME, + .attrs_and_data = { + BE32(CBFS_FILE_ATTR_TAG_COMPRESSION), + BE32(sizeof(struct cbfs_file_attr_compression)), + BE32(CBFS_COMPRESS_LZ4), + BE32(TEST_DATA_INT_3_SIZE), + LE64(TEST_DATA_INT_3), + }, +}; diff --git a/payloads/libpayload/tests/mocks/die.c b/payloads/libpayload/tests/mocks/die.c new file mode 100644 index 0000000000..a67105a12b --- /dev/null +++ b/payloads/libpayload/tests/mocks/die.c @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <tests/test.h> +#include <stdbool.h> + +void die_work(const char *file, const char *func, int line, const char *fmt, ...) +{ + /* Failing asserts are jumping to the user code (test) if expect_assert_failed() was + previously called. Otherwise it jumps to the cmocka code and fails the test. */ + mock_assert(false, "Mock assetion called", file, line); + + /* Should never be reached */ + print_error("%s() called...\n", __func__); + while (1) + ; +} |