Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/40539 )
Change subject: tests: Add device/i2c-test test case ......................................................................
Patch Set 3:
(1 comment)
https://review.coreboot.org/c/coreboot/+/40539/3/tests/device/i2c-test.c File tests/device/i2c-test.c:
https://review.coreboot.org/c/coreboot/+/40539/3/tests/device/i2c-test.c@48 PS3, Line 48: int __wrap_platform_i2c_transfer(unsigned int bus, struct i2c_msg *segments,
Can you put this mock into a separate C file? In general, we would like mocks to be available to mul […]
I don't think I agree with this, at least not as a general rule. Sometimes the same function will need to be mocked in multiple tests, yes, but that doesn't mean they will actually be the same mocks. The mock often has to be carefully designed to match the thing you want to test. In this case for example, if we wrote tests for the TPM I2C driver we might also want to mock platform_i2c_transfer(), but it would have to be a more complicated mock that is able to return answers like a real TPM.
I'm sure we will have cases where we want to share mocks, but I wouldn't want to force that on every mock written for every test (that just seems to create unnecessary friction which could keep people from wanting to write tests). If we want to demonstrate a test with a shared mock for others to copy, let's first find a situation where that would actually be useful and then implement it there.