summaryrefslogtreecommitdiff
path: root/tests/mock/cbfs_file_mock.c
diff options
context:
space:
mode:
authorJakub Czapiga <jacz@semihalf.com>2021-07-22 08:52:46 +0200
committerJulius Werner <jwerner@chromium.org>2021-09-02 00:31:02 +0000
commit6f3fd6358f605c181f958ded9ef92803cec172fd (patch)
treec9c9a79bcf6d8c2837c686f8b966395eba5e8ef0 /tests/mock/cbfs_file_mock.c
parent6813d561b2fcd89e0df23a3c41843433767edec3 (diff)
tests: Add lib/cbfs-verification-test test case
This commit adds test case for lib/cbfs verification mechanisms. Signed-off-by: Jakub Czapiga <jacz@semihalf.com> Change-Id: I1d8cbb1c2d0a9db3236de065428b70a9c2a66330 Reviewed-on: https://review.coreboot.org/c/coreboot/+/56601 Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'tests/mock/cbfs_file_mock.c')
-rw-r--r--tests/mock/cbfs_file_mock.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/mock/cbfs_file_mock.c b/tests/mock/cbfs_file_mock.c
new file mode 100644
index 0000000000..a4feb618f7
--- /dev/null
+++ b/tests/mock/cbfs_file_mock.c
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <tests/lib/cbfs_util.h>
+
+TEST_REGION(cbfs_cache, TEST_CBFS_CACHE_SIZE);
+
+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] = { BE64(TEST_DATA_INT_1) };
+const u8 test_data_int_2[TEST_DATA_INT_2_SIZE] = { BE64(TEST_DATA_INT_2) };
+const u8 test_data_int_3[TEST_DATA_INT_3_SIZE] = { BE64(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,
+ },
+};