From 681a8e8aa14c9c7987862db895c4d7d3f417f3e7 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Sat, 27 Jun 2020 22:04:56 -0700 Subject: [PATCH] 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. --- configure.ac | 5 ++--- lib/libx52/Makefile.am | 6 ++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index 22ffcf8..7e1e294 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/lib/libx52/Makefile.am b/lib/libx52/Makefile.am index 77f605c..43114ce 100644 --- a/lib/libx52/Makefile.am +++ b/lib/libx52/Makefile.am @@ -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