From f31650b23b4b80f86b7fe0ec879984439a32838c Mon Sep 17 00:00:00 2001 From: Daniel Campello Date: Tue, 15 Mar 2022 14:19:34 -0600 Subject: tests: add more mock wrappers This change allows for tests to run when the compiler is inlining some other interfaces. This happens when compiling on the chromium chroot environment. * __fgets_chk() is being used instead of fgets() in get_max_kernel_buf_size() on linux_spi.c * __vfprintf_chk() is being used instead of fprintf() in disable_power_management() on power.c * __open64_2() is being used instead of open() in i2c_open_path() on i2c_helper_linux.c BUG=b:224828279 TEST=./test_build.sh; FEATURES=test emerge-volteer flashrom Signed-off-by: Daniel Campello Change-Id: I9776104d655c37891093da08789d37e5e27700de Reviewed-on: https://review.coreboot.org/c/flashrom/+/62844 Tested-by: build bot (Jenkins) Reviewed-by: Anastasia Klimchuk Reviewed-by: Edward O'Callaghan --- tests/meson.build | 3 +++ tests/tests.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/tests/meson.build b/tests/meson.build index 610d1c61..90e0df11 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -36,6 +36,7 @@ mocks = [ '-Wl,--wrap=sio_read', '-Wl,--wrap=open', '-Wl,--wrap=open64', + '-Wl,--wrap=__open64_2', '-Wl,--wrap=ioctl', '-Wl,--wrap=read', '-Wl,--wrap=write', @@ -56,7 +57,9 @@ mocks = [ '-Wl,--wrap=fsync', '-Wl,--wrap=fread', '-Wl,--wrap=fgets', + '-Wl,--wrap=__fgets_chk', '-Wl,--wrap=fprintf', + '-Wl,--wrap=__vfprintf_chk', '-Wl,--wrap=fclose', '-Wl,--wrap=feof', '-Wl,--wrap=ferror', diff --git a/tests/tests.c b/tests/tests.c index f1fb3f3e..33b2ea20 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -90,6 +90,14 @@ int __wrap_open64(const char *pathname, int flags) return NON_ZERO; } +int __wrap___open64_2(const char *pathname, int flags) +{ + LOG_ME; + if (get_io() && get_io()->open) + return get_io()->open(get_io()->state, pathname, flags); + return NON_ZERO; +} + int __wrap_ioctl(int fd, unsigned long int request, ...) { LOG_ME; @@ -198,6 +206,14 @@ char *__wrap_fgets(char *buf, int len, FILE *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); + return NULL; +} + size_t __wrap_fread(void *ptr, size_t size, size_t nmemb, FILE *fp) { LOG_ME; @@ -250,6 +266,14 @@ int __wrap_fprintf(FILE *fp, const char *fmt, ...) return 0; } +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); + return 0; +} + int __wrap_fclose(FILE *fp) { LOG_ME; -- cgit v1.2.3