Anastasia Klimchuk has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/68433 )
Change subject: tests: Add prefix to io_mock functions not to clash with macros ......................................................................
tests: Add prefix to io_mock functions not to clash with macros
Flashrom I/O mock functions need to be renamed so that they do not have name clash with standard I/O, because the latter are allowed to be macros. Adding a prefix to flashrom mock functions avoids them being accidentally expanded. Standard I/O functions are expanded and flashrom mocks stays as they are.
BUG=b:237606255 TEST=ninja test 1) gcc 12.2.0 on Debian 2)
Ticket: https://ticket.coreboot.org/issues/411 Change-Id: I7998a8fb1b9e65621e12adbfab5460a245d5606b Signed-off-by: Anastasia Klimchuk aklm@chromium.org --- M tests/chip.c M tests/io_mock.c M tests/io_mock.h M tests/linux_mtd.c M tests/linux_spi.c M tests/parade_lspcon.c M tests/realtek_mst_i2c_spi.c M tests/tests.c 8 files changed, 71 insertions(+), 49 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/33/68433/1
diff --git a/tests/chip.c b/tests/chip.c index 6f03172..8ddf469 100644 --- a/tests/chip.c +++ b/tests/chip.c @@ -425,7 +425,7 @@ .paths = { NULL }, }; const struct io_mock verify_chip_io = { - .fread = verify_chip_fread, + .iom_fread = verify_chip_fread, .fallback_open_state = &data, };
@@ -460,7 +460,7 @@ .paths = { NULL }, }; const struct io_mock verify_chip_io = { - .fread = verify_chip_fread, + .iom_fread = verify_chip_fread, .fallback_open_state = &data, };
diff --git a/tests/io_mock.c b/tests/io_mock.c index 9f86fcd..c04e9c5 100644 --- a/tests/io_mock.c +++ b/tests/io_mock.c @@ -22,7 +22,7 @@ void io_mock_register(const struct io_mock *io) { /* A test can either register its own mock open function or fallback_open_state. */ - assert_true(io == NULL || io->open == NULL || io->fallback_open_state == NULL); + assert_true(io == NULL || io->iom_open == NULL || io->fallback_open_state == NULL); current_io = io; }
diff --git a/tests/io_mock.h b/tests/io_mock.h index 9e92a9d..644da74 100644 --- a/tests/io_mock.h +++ b/tests/io_mock.h @@ -101,17 +101,17 @@ void (*libusb_free_config_descriptor)(void *state, struct libusb_config_descriptor *);
/* POSIX File I/O */ - int (*open)(void *state, const char *pathname, int flags); - int (*ioctl)(void *state, int fd, unsigned long request, va_list args); - int (*read)(void *state, int fd, void *buf, size_t sz); - int (*write)(void *state, int fd, const void *buf, size_t sz); + int (*iom_open)(void *state, const char *pathname, int flags); + int (*iom_ioctl)(void *state, int fd, unsigned long request, va_list args); + int (*iom_read)(void *state, int fd, void *buf, size_t sz); + int (*iom_write)(void *state, int fd, const void *buf, size_t sz);
/* Standard I/O */ - FILE* (*fopen)(void *state, const char *pathname, const char *mode); - char* (*fgets)(void *state, char *buf, int len, FILE *fp); - size_t (*fread)(void *state, void *buf, size_t size, size_t len, FILE *fp); - int (*fprintf)(void *state, FILE *fp, const char *fmt, va_list args); - int (*fclose)(void *state, FILE *fp); + FILE* (*iom_fopen)(void *state, const char *pathname, const char *mode); + char* (*iom_fgets)(void *state, char *buf, int len, FILE *fp); + size_t (*iom_fread)(void *state, void *buf, size_t size, size_t len, FILE *fp); + int (*iom_fprintf)(void *state, FILE *fp, const char *fmt, va_list args); + int (*iom_fclose)(void *state, FILE *fp);
/* * An alternative to custom open mock. A test can either register its diff --git a/tests/linux_mtd.c b/tests/linux_mtd.c index 10ccb5e..3aaa5ab 100644 --- a/tests/linux_mtd.c +++ b/tests/linux_mtd.c @@ -81,9 +81,9 @@ }; const struct io_mock linux_mtd_io = { .state = &linux_mtd_io_state, - .fopen = linux_mtd_fopen, - .fread = linux_mtd_fread, - .fclose = linux_mtd_fclose, + .iom_fopen = linux_mtd_fopen, + .iom_fread = linux_mtd_fread, + .iom_fclose = linux_mtd_fclose, .fallback_open_state = &linux_mtd_fallback_open_state, };
diff --git a/tests/linux_spi.c b/tests/linux_spi.c index 2e3dc95..1009634 100644 --- a/tests/linux_spi.c +++ b/tests/linux_spi.c @@ -60,8 +60,8 @@ .flags = { O_RDWR }, }; const struct io_mock linux_spi_io = { - .fgets = linux_spi_fgets, - .ioctl = linux_spi_ioctl, + .iom_fgets = linux_spi_fgets, + .iom_ioctl = linux_spi_ioctl, .fallback_open_state = &linux_spi_fallback_open_state, };
diff --git a/tests/parade_lspcon.c b/tests/parade_lspcon.c index 9d7bd23..980e128 100644 --- a/tests/parade_lspcon.c +++ b/tests/parade_lspcon.c @@ -108,9 +108,9 @@ }; const struct io_mock parade_lspcon_io = { .state = ¶de_lspcon_io_state, - .ioctl = parade_lspcon_ioctl, - .read = parade_lspcon_read, - .write = parade_lspcon_write, + .iom_ioctl = parade_lspcon_ioctl, + .iom_read = parade_lspcon_read, + .iom_write = parade_lspcon_write, .fallback_open_state = ¶de_lspcon_fallback_open_state, };
diff --git a/tests/realtek_mst_i2c_spi.c b/tests/realtek_mst_i2c_spi.c index 0526124..753f06b 100644 --- a/tests/realtek_mst_i2c_spi.c +++ b/tests/realtek_mst_i2c_spi.c @@ -50,9 +50,9 @@ .flags = { O_RDWR }, }; const struct io_mock realtek_mst_io = { - .ioctl = realtek_mst_ioctl, - .read = realtek_mst_read, - .write = realtek_mst_write, + .iom_ioctl = realtek_mst_ioctl, + .iom_read = realtek_mst_read, + .iom_write = realtek_mst_write, .fallback_open_state = &realtek_mst_fallback_open_state, };
diff --git a/tests/tests.c b/tests/tests.c index c110e48..69c2b87 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -77,8 +77,8 @@
static int mock_open(const char *pathname, int flags) { - if (get_io() && get_io()->open) - return get_io()->open(get_io()->state, pathname, flags); + if (get_io() && get_io()->iom_open) + return get_io()->iom_open(get_io()->state, pathname, flags);
if (get_io() && get_io()->fallback_open_state) { struct io_mock_fallback_open_state *io_state; @@ -117,11 +117,11 @@ int __wrap_ioctl(int fd, unsigned long int request, ...) { LOG_ME; - if (get_io() && get_io()->ioctl) { + if (get_io() && get_io()->iom_ioctl) { va_list args; int out; va_start(args, request); - out = get_io()->ioctl(get_io()->state, fd, request, args); + out = get_io()->iom_ioctl(get_io()->state, fd, request, args); va_end(args); return out; } @@ -131,32 +131,32 @@ int __wrap_write(int fd, const void *buf, size_t sz) { LOG_ME; - if (get_io() && get_io()->write) - return get_io()->write(get_io()->state, fd, buf, sz); + if (get_io() && get_io()->iom_write) + return get_io()->iom_write(get_io()->state, fd, buf, sz); return sz; }
int __wrap_read(int fd, void *buf, size_t sz) { LOG_ME; - if (get_io() && get_io()->read) - return get_io()->read(get_io()->state, fd, buf, sz); + if (get_io() && get_io()->iom_read) + return get_io()->iom_read(get_io()->state, fd, buf, sz); return sz; }
FILE *__wrap_fopen(const char *pathname, const char *mode) { LOG_ME; - if (get_io() && get_io()->fopen) - return get_io()->fopen(get_io()->state, pathname, mode); + if (get_io() && get_io()->iom_fopen) + return get_io()->iom_fopen(get_io()->state, pathname, mode); return not_null(); }
FILE *__wrap_fopen64(const char *pathname, const char *mode) { LOG_ME; - if (get_io() && get_io()->fopen) - return get_io()->fopen(get_io()->state, pathname, mode); + if (get_io() && get_io()->iom_fopen) + return get_io()->iom_fopen(get_io()->state, pathname, mode); return not_null(); }
@@ -217,24 +217,24 @@ char *__wrap_fgets(char *buf, int len, FILE *fp) { LOG_ME; - if (get_io() && get_io()->fgets) - return get_io()->fgets(get_io()->state, buf, len, fp); + if (get_io() && get_io()->iom_fgets) + return get_io()->iom_fgets(get_io()->state, buf, len, fp); return NULL; }
char *__wrap___fgets_chk(char *buf, int len, FILE *fp) { LOG_ME; - if (get_io() && get_io()->fgets) - return get_io()->fgets(get_io()->state, buf, len, fp); + if (get_io() && get_io()->iom_fgets) + return get_io()->iom_fgets(get_io()->state, buf, len, fp); return NULL; }
size_t __wrap_fread(void *ptr, size_t size, size_t nmemb, FILE *fp) { LOG_ME; - if (get_io() && get_io()->fread) - return get_io()->fread(get_io()->state, ptr, size, nmemb, fp); + if (get_io() && get_io()->iom_fread) + return get_io()->iom_fread(get_io()->state, ptr, size, nmemb, fp); return nmemb; }
@@ -271,11 +271,11 @@ int __wrap_fprintf(FILE *fp, const char *fmt, ...) { LOG_ME; - if (get_io() && get_io()->fprintf) { + if (get_io() && get_io()->iom_fprintf) { va_list args; int out; va_start(args, fmt); - out = get_io()->fprintf(get_io()->state, fp, fmt, args); + out = get_io()->iom_fprintf(get_io()->state, fp, fmt, args); va_end(args); return out; } @@ -285,24 +285,24 @@ int __wrap___vfprintf_chk(FILE *fp, const char *fmt, va_list args) { LOG_ME; - if (get_io() && get_io()->fprintf) - return get_io()->fprintf(get_io()->state, fp, fmt, args); + if (get_io() && get_io()->iom_fprintf) + return get_io()->iom_fprintf(get_io()->state, fp, fmt, args); return 0; }
int __wrap___fprintf_chk(FILE *fp, const char *fmt, va_list args) { LOG_ME; - if (get_io() && get_io()->fprintf) - return get_io()->fprintf(get_io()->state, fp, fmt, args); + if (get_io() && get_io()->iom_fprintf) + return get_io()->iom_fprintf(get_io()->state, fp, fmt, args); return 0; }
int __wrap_fclose(FILE *fp) { LOG_ME; - if (get_io() && get_io()->fclose) - return get_io()->fclose(get_io()->state, fp); + if (get_io() && get_io()->iom_fclose) + return get_io()->iom_fclose(get_io()->state, fp); return 0; }