summaryrefslogtreecommitdiffstats
path: root/Documentation/tutorial
diff options
context:
space:
mode:
authorPatrick Georgi <pgeorgi@google.com>2021-06-09 18:37:42 +0200
committerPatrick Georgi <pgeorgi@google.com>2021-06-10 19:26:46 +0000
commitce55ca2fcaab23010b2f7e310c921f65b037034d (patch)
treeab160de356ce394bded5e4406096eba7dc278d20 /Documentation/tutorial
parent36c90179f0c7ef0d11ca78a109bd563b3ec0e0a9 (diff)
downloadcoreboot-ce55ca2fcaab23010b2f7e310c921f65b037034d.tar.gz
coreboot-ce55ca2fcaab23010b2f7e310c921f65b037034d.tar.bz2
coreboot-ce55ca2fcaab23010b2f7e310c921f65b037034d.zip
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>
Diffstat (limited to 'Documentation/tutorial')
-rw-r--r--Documentation/tutorial/part3.md18
1 files changed, 9 insertions, 9 deletions
diff --git a/Documentation/tutorial/part3.md b/Documentation/tutorial/part3.md
index 6d147ff9a9e6..7cdf7d9f214a 100644
--- a/Documentation/tutorial/part3.md
+++ b/Documentation/tutorial/part3.md
@@ -274,8 +274,8 @@ without changing the source code.
coreboot unit test infrastructure supports overriding of functions at link time.
This is as simple as adding a `name_of_function` to be mocked into
-<test_name>-mocks variable in Makefile.inc. The result is that every time the
-function is called, `wrap_name_of_function` will be called instead.
+<test_name>-mocks variable in Makefile.inc. The result is that the test's
+implementation of that function is called instead of coreboot's.
```eval_rst
.. admonition:: i2c-test example
@@ -284,13 +284,13 @@ function is called, `wrap_name_of_function` will be called instead.
i2c-test-mocks += platform_i2c_transfer
- Now, dev can write own implementation of `platform_i2c_transfer` and define it
- as `wrap_platform_i2c_transfer`. This implementation instead of accessing real
- i2c bus, will write/read from fake structs.
+ Now, dev can write own implementation of `platform_i2c_transfer`. This
+ implementation instead of accessing real i2c bus, will write/read from
+ fake structs.
.. code-block:: c
- 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)
{
}
@@ -324,13 +324,13 @@ in which mock should have particular value, or be inside a described range.
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);
}