1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-07-02 22:43:17 +02:00

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>
This commit is contained in:
Peter Marheine
2021-08-10 15:38:47 +10:00
committed by Edward O'Callaghan
parent b261bec1ee
commit 47f4c18260
5 changed files with 100 additions and 0 deletions

View File

@ -83,21 +83,49 @@ uint8_t __wrap_sio_read(uint16_t port, uint8_t reg)
int __wrap_open(const char *pathname, int flags)
{
LOG_ME;
if (current_io && current_io->open)
return current_io->open(current_io->state, pathname, flags);
return MOCK_HANDLE;
}
int __wrap_open64(const char *pathname, int flags)
{
LOG_ME;
if (current_io && current_io->open)
return current_io->open(current_io->state, pathname, flags);
return MOCK_HANDLE;
}
int __wrap_ioctl(int fd, unsigned long int request, ...)
{
LOG_ME;
if (current_io && current_io->ioctl) {
va_list args;
int out;
va_start(args, request);
out = current_io->ioctl(current_io->state, fd, request, args);
va_end(args);
return out;
}
return MOCK_HANDLE;
}
int __wrap_write(int fd, const void *buf, size_t sz)
{
LOG_ME;
if (current_io && current_io->write)
return current_io->write(current_io->state, fd, buf, sz);
return sz;
}
int __wrap_read(int fd, void *buf, size_t sz)
{
LOG_ME;
if (current_io && current_io->read)
return current_io->read(current_io->state, fd, buf, sz);
return sz;
}
FILE *__wrap_fopen(const char *pathname, const char *mode)
{
LOG_ME;
@ -250,6 +278,7 @@ int main(void)
cmocka_unit_test(dediprog_init_and_shutdown_test_success),
cmocka_unit_test(ene_lpc_init_and_shutdown_test_success),
cmocka_unit_test(linux_spi_init_and_shutdown_test_success),
cmocka_unit_test(realtek_mst_init_and_shutdown_test_success),
};
ret |= cmocka_run_group_tests_name("init_shutdown.c tests", init_shutdown_tests, NULL, NULL);