Change libx52 mock tests to use preprocessor overrides

Prior to this change, libx52 tests needed a linker that supported the
--wrap argument. This is not available on OSX, and therefore, we had to
disable the unit tests on non-Linux systems.

Since we needed to rebuild the libx52 library anyway for the test, it is
simpler to just define libusb_control_transfer to point to our mock
function. This allows us to verify libx52 on all supported platforms.
pull/22/head
nirenjan 2020-06-27 22:04:56 -07:00
parent 8388f3308e
commit 681a8e8aa1
2 changed files with 4 additions and 7 deletions

View File

@ -73,11 +73,10 @@ AM_COND_IF([HAVE_DOXYGEN],
[AC_CONFIG_FILES([Doxyfile])],
[AC_MSG_WARN(["Doxygen not found; continuing without doxygen support"])])
# cmocka unit tests, currently only supported on Linux
# cmocka unit tests
AX_PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.1], [], [have_cmocka=yes], [have_cmocka=no])
AM_CONDITIONAL([HAVE_CMOCKA], [test "x$have_cmocka" = xyes])
AM_COND_IF([HAVE_CMOCKA], [AM_COND_IF([LINUX], [],
[AC_MSG_WARN(["cmocka found; disabling mock tests on ${host_os}])])],
AM_COND_IF([HAVE_CMOCKA], [],
[AC_MSG_WARN(["cmocka not found; disabling unit test build"])])
# Check for the presence of tm_gmtoff in struct tm. If we have this, then we

View File

@ -31,7 +31,6 @@ x52include_HEADERS = libx52.h
# pkg-config files
pkgconfig_DATA = libx52.pc
if LINUX
if HAVE_CMOCKA
LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/tap-driver.sh
TESTS = libx52test
@ -40,15 +39,14 @@ check_PROGRAMS = libx52test
nodist_libx52test_SOURCES = test_libx52.c
libx52test_SOURCES = $(libx52_la_SOURCES)
libx52test_CFLAGS = @LIBUSB_CFLAGS@ -DLOCALEDIR='"$(localedir)"' -I $(top_srcdir)
libx52test_CFLAGS += -DGENERATED_TESTS='"test_libx52.c"'
libx52test_LDFLAGS = -Wl,--wrap=libusb_control_transfer @CMOCKA_LIBS@ @LIBUSB_LIBS@
libx52test_CFLAGS += -Dlibusb_control_transfer=__wrap_libusb_control_transfer
libx52test_LDFLAGS = @CMOCKA_LIBS@ @LIBUSB_LIBS@
libx52test_LDADD = libx52.la
CLEANFILES = test_libx52.c
test_libx52.c: $(srcdir)/x52_test_gen.py $(srcdir)/x52_tests.json
$(AM_V_GEN) $(PYTHON) $(srcdir)/x52_test_gen.py $(srcdir)/x52_tests.json > $@
endif
endif
# Extra files that need to be in the distribution
EXTRA_DIST = libx52.h x52_commands.h x52_common.h README.md