summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu-Ping Wu <yupingso@chromium.org>2022-07-05 15:45:20 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-09-21 09:44:53 +0000
commitce6207613256d4f54637b580e4e863565d18dacc (patch)
tree15c480714e79ccff5fbc71d7c01e542f7cf28f82
parent956c2efb0af310a3089b362fdb5d5f70238758f2 (diff)
downloadvboot-ce6207613256d4f54637b580e4e863565d18dacc.tar.gz
tests: Remove --allow-multiple-definition linker option
The --allow-multiple-definition linker option was added in CL:6770 to allow mocking functions. Now that we're exclusively using the weak attribute (or equivalently test_mockable in vboot_reference) in other firmware repositories (coreboot, depthcharge) for unit testing, the --allow-multiple-definition option should no longer be needed. In addition, one problem with --allow-multiple-definition is that, when a function being mocked is automatically inlined by compiler optimization, the mock function may not be called at all, leading to unexpected behavior. Marking that function as test_mockable can prevent this situation. Therefore, add test_mockable to all the functions being mocked, and remove the linker option from Makefile. BUG=none TEST=make -j32 test_setup && make runtests BRANCH=none Change-Id: Ifcd8138641d17bff689dd5093cdd69e4da9f0b0c Signed-off-by: Yu-Ping Wu <yupingso@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3744746 Reviewed-by: Jakub Czapiga <czapiga@google.com> Commit-Queue: Jakub Czapiga <czapiga@google.com>
-rw-r--r--Makefile3
-rw-r--r--firmware/2lib/2common.c3
-rw-r--r--firmware/2lib/2gbb.c2
-rw-r--r--firmware/2lib/2kernel.c1
-rw-r--r--firmware/2lib/2misc.c4
-rw-r--r--firmware/2lib/2nvstorage.c1
-rw-r--r--firmware/2lib/2secdata_fwmp.c1
-rw-r--r--firmware/2lib/2secdata_kernel.c1
-rw-r--r--firmware/2lib/2struct.c1
-rw-r--r--futility/futility.c1
-rw-r--r--host/lib/subprocess.c1
11 files changed, 16 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 5e239dd9..335e8ac3 100644
--- a/Makefile
+++ b/Makefile
@@ -673,7 +673,6 @@ FUTIL_SRCS = \
futility/cmd_update.c \
futility/cmd_validate_rec_mrc.c \
futility/cmd_vbutil_firmware.c \
- futility/cmd_vbutil_firmware.c \
futility/cmd_vbutil_kernel.c \
futility/cmd_vbutil_key.c \
futility/cmd_vbutil_keyblock.c \
@@ -1204,8 +1203,6 @@ ${BUILD}/tests/hmac_test: LDLIBS += ${CRYPTO_LIBS}
${TEST21_BINS}: LDLIBS += ${CRYPTO_LIBS}
-# Allow multiple definitions, so tests can mock functions from other libraries
-${BUILD}/tests/%: LDFLAGS += -Xlinker --allow-multiple-definition
${BUILD}/tests/%: LDLIBS += -lrt -luuid
${BUILD}/tests/%: LIBS += ${TESTLIB}
diff --git a/firmware/2lib/2common.c b/firmware/2lib/2common.c
index d6ee701e..dd376825 100644
--- a/firmware/2lib/2common.c
+++ b/firmware/2lib/2common.c
@@ -9,6 +9,7 @@
#include "2common.h"
#include "2rsa.h"
+test_mockable
vb2_error_t vb2_safe_memcmp(const void *s1, const void *s2, size_t size)
{
const unsigned char *us1 = s1;
@@ -147,6 +148,7 @@ vb2_error_t vb2_verify_member_inside(const void *parent, size_t parent_size,
return VB2_SUCCESS;
}
+test_mockable
vb2_error_t vb2_verify_digest(const struct vb2_public_key *key,
struct vb2_signature *sig, const uint8_t *digest,
const struct vb2_workbuf *wb)
@@ -182,6 +184,7 @@ vb2_error_t vb2_verify_digest(const struct vb2_public_key *key,
return vb2_rsa_verify_digest(key, sig_data, digest, wb);
}
+test_mockable
vb2_error_t vb2_verify_data(const uint8_t *data, uint32_t size,
struct vb2_signature *sig,
const struct vb2_public_key *key,
diff --git a/firmware/2lib/2gbb.c b/firmware/2lib/2gbb.c
index 9238c30c..b882d7ec 100644
--- a/firmware/2lib/2gbb.c
+++ b/firmware/2lib/2gbb.c
@@ -49,6 +49,7 @@ static vb2_error_t vb2_gbb_read_key(struct vb2_context *ctx, uint32_t offset,
return VB2_SUCCESS;
}
+test_mockable
vb2_error_t vb2_gbb_read_root_key(struct vb2_context *ctx,
struct vb2_packed_key **keyp, uint32_t *size,
struct vb2_workbuf *wb)
@@ -62,6 +63,7 @@ vb2_error_t vb2_gbb_read_root_key(struct vb2_context *ctx,
return ret;
}
+test_mockable
vb2_error_t vb2_gbb_read_recovery_key(struct vb2_context *ctx,
struct vb2_packed_key **keyp,
uint32_t *size, struct vb2_workbuf *wb)
diff --git a/firmware/2lib/2kernel.c b/firmware/2lib/2kernel.c
index ff89e142..8844357c 100644
--- a/firmware/2lib/2kernel.c
+++ b/firmware/2lib/2kernel.c
@@ -38,6 +38,7 @@ int vb2api_is_developer_signed(struct vb2_context *ctx)
return 0;
}
+test_mockable
vb2_error_t vb2api_kernel_phase1(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
diff --git a/firmware/2lib/2misc.c b/firmware/2lib/2misc.c
index e15d760b..f1eba3c5 100644
--- a/firmware/2lib/2misc.c
+++ b/firmware/2lib/2misc.c
@@ -169,6 +169,7 @@ void vb2_check_recovery(struct vb2_context *ctx)
sd->status |= VB2_SD_STATUS_RECOVERY_DECIDED;
}
+test_mockable
vb2_error_t vb2_fw_init_gbb(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
@@ -195,6 +196,7 @@ vb2_error_t vb2_fw_init_gbb(struct vb2_context *ctx)
return VB2_SUCCESS;
}
+test_mockable
vb2_error_t vb2_check_dev_switch(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
@@ -295,6 +297,7 @@ vb2_error_t vb2_check_dev_switch(struct vb2_context *ctx)
return VB2_SUCCESS;
}
+test_mockable
vb2_error_t vb2_check_tpm_clear(struct vb2_context *ctx)
{
vb2_error_t rv;
@@ -323,6 +326,7 @@ vb2_error_t vb2_check_tpm_clear(struct vb2_context *ctx)
return VB2_SUCCESS;
}
+test_mockable
vb2_error_t vb2_select_fw_slot(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
diff --git a/firmware/2lib/2nvstorage.c b/firmware/2lib/2nvstorage.c
index 4fd9808a..82be4dd3 100644
--- a/firmware/2lib/2nvstorage.c
+++ b/firmware/2lib/2nvstorage.c
@@ -237,6 +237,7 @@ uint32_t vb2_nv_get(struct vb2_context *ctx, enum vb2_nv_param param)
#define SETBIT(offs, mask) \
{ if (value) p[offs] |= mask; else p[offs] &= ~mask; }
+test_mockable
void vb2_nv_set(struct vb2_context *ctx,
enum vb2_nv_param param,
uint32_t value)
diff --git a/firmware/2lib/2secdata_fwmp.c b/firmware/2lib/2secdata_fwmp.c
index cec24813..1d5abd83 100644
--- a/firmware/2lib/2secdata_fwmp.c
+++ b/firmware/2lib/2secdata_fwmp.c
@@ -79,6 +79,7 @@ uint32_t vb2api_secdata_fwmp_create(struct vb2_context *ctx)
return sizeof(*sec);
}
+test_mockable
vb2_error_t vb2_secdata_fwmp_init(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
diff --git a/firmware/2lib/2secdata_kernel.c b/firmware/2lib/2secdata_kernel.c
index 754552c0..838c992f 100644
--- a/firmware/2lib/2secdata_kernel.c
+++ b/firmware/2lib/2secdata_kernel.c
@@ -292,6 +292,7 @@ const uint8_t *vb2_secdata_kernel_get_ec_hash(struct vb2_context *ctx)
return sec->ec_hash;
}
+test_mockable
void vb2_secdata_kernel_set_ec_hash(struct vb2_context *ctx,
const uint8_t *sha256)
{
diff --git a/firmware/2lib/2struct.c b/firmware/2lib/2struct.c
index 0223570f..605359bc 100644
--- a/firmware/2lib/2struct.c
+++ b/firmware/2lib/2struct.c
@@ -63,6 +63,7 @@ vb2_error_t vb2_check_keyblock(const struct vb2_keyblock *block, uint32_t size,
return VB2_SUCCESS;
}
+test_mockable
vb2_error_t vb2_verify_keyblock(struct vb2_keyblock *block, uint32_t size,
const struct vb2_public_key *key,
const struct vb2_workbuf *wb)
diff --git a/futility/futility.c b/futility/futility.c
index 0f262c2e..75cef671 100644
--- a/futility/futility.c
+++ b/futility/futility.c
@@ -294,6 +294,7 @@ static char *simple_basename(char *str)
/* Here we go */
#define OPT_HELP 1000
+test_mockable
int main(int argc, char *argv[], char *envp[])
{
char *progname;
diff --git a/host/lib/subprocess.c b/host/lib/subprocess.c
index 8905d1c2..ee181591 100644
--- a/host/lib/subprocess.c
+++ b/host/lib/subprocess.c
@@ -290,6 +290,7 @@ struct subprocess_target subprocess_stderr = {
.fd = STDERR_FILENO,
};
+test_mockable
int subprocess_run(const char *const argv[],
struct subprocess_target *input,
struct subprocess_target *output,