unittests: fix syscall mocks on 32-bit with time64 glibc
PATCH 1/1 unittests: fix syscall mocks on 32-bit with time64 glibc
On 32-bit systems (e.g. armhf), building with -D_FORTIFY_SOURCE=2, -D_FILE_OFFSET_BITS=64, and -D_TIME_BITS=64 CFLAGS fails many tests. These flags activate glibc symbol redirects that bypass the --wrap linker interpositions used by the cmocka mocks:
- _FORTIFY_SOURCE=2 + _FILE_OFFSET_BITS=64: open(path, flags) -> open64()
- _FILE_OFFSET_BITS=64: lseek() -> lseek64()
- _TIME_BITS=64 (glibc >= 2.34): ioctl() -> __ioctl_time64()
Add --wrap entries for each redirected symbol and provide thin forwarders that delegate to the primary __wrap_open / __wrap_lseek / __wrap_ioctl functions via plain function calls. This ensures that __func__ inside those functions resolves correctly for cmocka's expectation lookup.
--- tests/unittests/Makemodule.am | 4 ++-- tests/unittests/test_lib.h | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-)
tests/unittests/Makemodule.am +2 -2
@@ -1,13 +1,13 @@ ubilib_test_SOURCES = tests/unittests/libubi_test.c lib/libubi.c ubilib_test_SOURCES += tests/unittests/test_lib.h ubilib_test_LDADD = $(CMOCKA_LIBS) -ubilib_test_LDFLAGS = -Wl,--wrap=open -Wl,--wrap=close -Wl,--wrap=ioctl -Wl,--wrap=read -Wl,--wrap=lseek +ubilib_test_LDFLAGS = -Wl,--wrap=open -Wl,--wrap=open64 -Wl,--wrap=close -Wl,--wrap=ioctl -Wl,--wrap=__ioctl_time64 -Wl,--wrap=read -Wl,--wrap=lseek -Wl,--wrap=lseek64 ubilib_test_CPPFLAGS = -O0 --std=gnu99 $(CMOCKA_CFLAGS) -I$(top_srcdir)/include -DSYSFS_ROOT='"$(top_srcdir)/tests/unittests/sysfs_mock"' mtdlib_test_SOURCES = tests/unittests/libmtd_test.c lib/libmtd.c lib/libmtd_legacy.c mtdlib_test_SOURCES += tests/unittests/test_lib.h mtdlib_test_LDADD = $(CMOCKA_LIBS) -mtdlib_test_LDFLAGS = -Wl,--wrap=open -Wl,--wrap=close -Wl,--wrap=ioctl -Wl,--wrap=read -Wl,--wrap=lseek -Wl,--wrap=write +mtdlib_test_LDFLAGS = -Wl,--wrap=open -Wl,--wrap=open64 -Wl,--wrap=close -Wl,--wrap=ioctl -Wl,--wrap=__ioctl_time64 -Wl,--wrap=read -Wl,--wrap=lseek -Wl,--wrap=lseek64 -Wl,--wrap=write mtdlib_test_CPPFLAGS = -O0 -D_GNU_SOURCE --std=gnu99 $(CMOCKA_CFLAGS) -I$(top_srcdir)/lib/ -I$(top_srcdir)/include -DSYSFS_ROOT='"$(top_srcdir)/tests/unittests/sysfs_mock"' TEST_BINS = \
tests/unittests/test_lib.h +19 -0
@@ -89,6 +89,25 @@ off_t __wrap_lseek(int fd, off_t seek, int whence)return mock_type (off_t); } +int __wrap_open64 (const char *path,int flags) +{ +return __wrap_open (path, flags); +} + +off_t __wrap_lseek64 (int fd,off_t offset,int whence) +{ +return __wrap_lseek (fd, offset, whence); +} + +int __wrap___ioctl_time64 (int fd,unsigned long req, ...) +{ +va_list ap; +va_start (ap, req); + void *arg = va_arg(ap, void *); +va_end (ap); +return __wrap_ioctl (fd, req, arg); +} +#define expect_open (X ,Y ,Z ) do { \ expect_string(__wrap_open, path, X);\ will_return(__wrap_open, Y);\
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/