diff options
author | Peter Marheine <pmarheine@chromium.org> | 2021-08-10 15:38:47 +1000 |
---|---|---|
committer | Edward O'Callaghan <quasisec@chromium.org> | 2021-08-19 03:53:41 +0000 |
commit | 47f4c18260e1eff46b0605b1039166238fc4797c (patch) | |
tree | 4c0ba8d00f032f19bf83c2427e163a7a3f07b55e /tests/init_shutdown.c | |
parent | b261bec1eea70aa67966b7f3ed36d4ae61cc31e0 (diff) | |
download | flashrom-47f4c18260e1eff46b0605b1039166238fc4797c.tar.gz flashrom-47f4c18260e1eff46b0605b1039166238fc4797c.tar.bz2 flashrom-47f4c18260e1eff46b0605b1039166238fc4797c.zip |
tests: add init_shutdown test for realtek_mst_i2c_spi
This can catch regressions like the earlier one in this programmer that
caused initialization to always fail. Requires support for mocking POSIX
file I/O functions because the programmer does ioctls on the opened
file.
TEST=ninja test
Signed-off-by: Peter Marheine <pmarheine@chromium.org>
Change-Id: I5a5c617d1ec35d2a3bbe622e5add82a65eb396f0
Reviewed-on: https://review.coreboot.org/c/flashrom/+/56911
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Diffstat (limited to 'tests/init_shutdown.c')
-rw-r--r-- | tests/init_shutdown.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/init_shutdown.c b/tests/init_shutdown.c index eeea3cc1..d1d0c7f3 100644 --- a/tests/init_shutdown.c +++ b/tests/init_shutdown.c @@ -209,3 +209,57 @@ void linux_spi_init_and_shutdown_test_success(void **state) skip(); #endif } + +#define REALTEK_MST_MOCK_FD 0x10ec + +static int realtek_mst_open(void *state, const char *pathname, int flags) +{ + assert_string_equal(pathname, "/dev/i2c-254"); + assert_int_equal(flags & O_RDWR, O_RDWR); + return REALTEK_MST_MOCK_FD; +} + +static int realtek_mst_ioctl(void *state, int fd, unsigned long request, va_list args) +{ + assert_int_equal(fd, REALTEK_MST_MOCK_FD); + assert_int_equal(request, I2C_SLAVE); + /* Only access to I2C address 0x4a is expected */ + unsigned long addr = va_arg(args, unsigned long); + assert_int_equal(addr, 0x4a); + + return 0; +} + +static int realtek_mst_read(void *state, int fd, void *buf, size_t sz) +{ + assert_int_equal(fd, REALTEK_MST_MOCK_FD); + assert_int_equal(sz, 1); + return sz; +} + +static int realtek_mst_write(void *state, int fd, const void *buf, size_t sz) +{ + assert_int_equal(fd, REALTEK_MST_MOCK_FD); + const LargestIntegralType accepted_sizes[] = {1, 2}; + assert_in_set(sz, accepted_sizes, ARRAY_SIZE(accepted_sizes)); + return sz; +} + +void realtek_mst_init_and_shutdown_test_success(void **state) +{ +#if CONFIG_REALTEK_MST_I2C_SPI == 1 + const struct io_mock realtek_mst_io = { + .open = realtek_mst_open, + .ioctl = realtek_mst_ioctl, + .read = realtek_mst_read, + .write = realtek_mst_write, + }; + io_mock_register(&realtek_mst_io); + + run_lifecycle(state, &programmer_realtek_mst_i2c_spi, "bus=254,enter-isp=0"); + + io_mock_register(NULL); +#else + skip(); +#endif /* CONFIG_REALTEK_I2C_SPI */ +} |