From 3354deef704a272e7c0e0a68173313dbd0e0ab67 Mon Sep 17 00:00:00 2001 From: Manoj Gupta Date: Sun, 23 Feb 2020 13:21:05 -0800 Subject: vboot: Add mockable attribute to some overridden functions A newer clang version has an optimization that is breaking vboot_reference unit tests. The root cause appears to be: Many functions inside unit tests are supposed to override the functions defined in the main library but the main library functions are not defined as weak. Fix by marking some of the overridden function by test_mockable which is already used for some of the functions. This is similar to a prior bug 723906 where unit tests were broken after binutils upgrade. BUG=chromium:1055151 TEST=unit tests passed with ToT clang Change-Id: Ib9f16e1af59632b6a82411656ebba75e26b5d211 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2069806 Reviewed-by: Julius Werner Reviewed-by: Joel Kitching Tested-by: Manoj Gupta Commit-Queue: Manoj Gupta --- firmware/2lib/2misc.c | 3 +++ firmware/2lib/2secdata_fwmp.c | 1 + firmware/2lib/2sha_utility.c | 4 ++++ firmware/lib/vboot_api_kernel.c | 1 + firmware/lib20/kernel.c | 2 ++ firmware/lib20/packed_key.c | 1 + 6 files changed, 12 insertions(+) diff --git a/firmware/2lib/2misc.c b/firmware/2lib/2misc.c index 54ddb900..9eafdeec 100644 --- a/firmware/2lib/2misc.c +++ b/firmware/2lib/2misc.c @@ -48,6 +48,7 @@ uint32_t vb2api_get_firmware_size(struct vb2_context *ctx) return pre->body_signature.data_size; } +test_mockable vb2_error_t vb2_read_gbb_header(struct vb2_context *ctx, struct vb2_gbb_header *gbb) { @@ -81,6 +82,7 @@ vb2_error_t vb2_read_gbb_header(struct vb2_context *ctx, return VB2_SUCCESS; } +test_mockable void vb2api_fail(struct vb2_context *ctx, uint8_t reason, uint8_t subcode) { struct vb2_shared_data *sd = vb2_get_sd(ctx); @@ -396,6 +398,7 @@ vb2_error_t vb2_enable_developer_mode(struct vb2_context *ctx) return VB2_SUCCESS; } +test_mockable int vb2_allow_recovery(struct vb2_context *ctx) { /* VB2_GBB_FLAG_FORCE_MANUAL_RECOVERY forces this to always return diff --git a/firmware/2lib/2secdata_fwmp.c b/firmware/2lib/2secdata_fwmp.c index 170fc5c2..ec6cc6c3 100644 --- a/firmware/2lib/2secdata_fwmp.c +++ b/firmware/2lib/2secdata_fwmp.c @@ -11,6 +11,7 @@ #include "2secdata.h" #include "2secdata_struct.h" +test_mockable vb2_error_t vb2api_secdata_fwmp_check(struct vb2_context *ctx, uint8_t *size) { struct vb2_secdata_fwmp *sec = diff --git a/firmware/2lib/2sha_utility.c b/firmware/2lib/2sha_utility.c index 378f4c8a..16a41f94 100644 --- a/firmware/2lib/2sha_utility.c +++ b/firmware/2lib/2sha_utility.c @@ -116,6 +116,7 @@ const char *vb2_get_hash_algorithm_name(enum vb2_hash_algorithm alg) } } +test_mockable vb2_error_t vb2_digest_init(struct vb2_digest_context *dc, enum vb2_hash_algorithm hash_alg) { @@ -143,6 +144,7 @@ vb2_error_t vb2_digest_init(struct vb2_digest_context *dc, } } +test_mockable vb2_error_t vb2_digest_extend(struct vb2_digest_context *dc, const uint8_t *buf, uint32_t size) { @@ -167,6 +169,7 @@ vb2_error_t vb2_digest_extend(struct vb2_digest_context *dc, const uint8_t *buf, } } +test_mockable vb2_error_t vb2_digest_finalize(struct vb2_digest_context *dc, uint8_t *digest, uint32_t digest_size) { @@ -194,6 +197,7 @@ vb2_error_t vb2_digest_finalize(struct vb2_digest_context *dc, uint8_t *digest, } } +test_mockable vb2_error_t vb2_digest_buffer(const uint8_t *buf, uint32_t size, enum vb2_hash_algorithm hash_alg, uint8_t *digest, uint32_t digest_size) diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c index 72224e19..fce32a1b 100644 --- a/firmware/lib/vboot_api_kernel.c +++ b/firmware/lib/vboot_api_kernel.c @@ -57,6 +57,7 @@ static vb2_error_t handle_battery_cutoff(struct vb2_context *ctx) return VB2_SUCCESS; } +test_mockable vb2_error_t VbTryLoadKernel(struct vb2_context *ctx, uint32_t get_info_flags) { vb2_error_t rv = VB2_ERROR_LK_NO_DISK_FOUND; diff --git a/firmware/lib20/kernel.c b/firmware/lib20/kernel.c index 2c837efd..8e340349 100644 --- a/firmware/lib20/kernel.c +++ b/firmware/lib20/kernel.c @@ -35,6 +35,7 @@ static int vb2_need_signed_kernel(struct vb2_context *ctx) return 0; } +test_mockable vb2_error_t vb2_verify_keyblock_hash(const struct vb2_keyblock *block, uint32_t size, const struct vb2_workbuf *wb) @@ -238,6 +239,7 @@ vb2_error_t vb2_load_kernel_keyblock(struct vb2_context *ctx) return VB2_SUCCESS; } +test_mockable vb2_error_t vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble, uint32_t size, const struct vb2_public_key *key, diff --git a/firmware/lib20/packed_key.c b/firmware/lib20/packed_key.c index 29f924b3..20b36a37 100644 --- a/firmware/lib20/packed_key.c +++ b/firmware/lib20/packed_key.c @@ -10,6 +10,7 @@ #include "2sysincludes.h" #include "vb2_common.h" +test_mockable vb2_error_t vb2_unpack_key_buffer(struct vb2_public_key *key, const uint8_t *buf, uint32_t size) { -- cgit v1.2.1