tests: Rework mocking facility

Using the linker's --wrap feature has the downside that it only covers
references across object files: If foo.c defines a() and b(), with b
calling a, --wrap=a does nothing to that call.

Instead, use objcopy to mark a weak and global so it can be overridden
by another implementation, but only for files originating in src/.

That way mocks - implemented in tests/ - become the source of truth.

TEST=Had such an issue with get_log_level() in a follow-up commit, and
the mock now takes over. Also, all existing unit tests still pass.

Change-Id: I99c6d6e44ecfc73366bf464d9c51c7da3f8db388
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/55360
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Jakub Czapiga <jacz@semihalf.com>
This commit is contained in:
Patrick Georgi
2021-06-09 18:37:42 +02:00
parent 36c90179f0
commit ce55ca2fca
6 changed files with 24 additions and 20 deletions

View File

@@ -30,7 +30,7 @@ i2c_ex_devs_t i2c_ex_devs[] = {
} },
};
int __wrap_platform_i2c_transfer(unsigned int bus, struct i2c_msg *segments,
int platform_i2c_transfer(unsigned int bus, struct i2c_msg *segments,
int count)
{
int i;
@@ -77,13 +77,13 @@ static void mock_expect_params_platform_i2c_transfer(void)
I2C_M_RECV_LEN, I2C_M_NOSTART};
/* Flags should always be only within supported range */
expect_in_set_count(__wrap_platform_i2c_transfer, segments->flags,
expect_in_set_count(platform_i2c_transfer, segments->flags,
expected_flags, -1);
expect_not_value_count(__wrap_platform_i2c_transfer, segments->buf,
expect_not_value_count(platform_i2c_transfer, segments->buf,
NULL, -1);
expect_in_range_count(__wrap_platform_i2c_transfer, count, 1, INT_MAX,
expect_in_range_count(platform_i2c_transfer, count, 1, INT_MAX,
-1);
}