From 987910e8abb40e357ac1aa6bf658b4660cc7f376 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Tue, 31 May 2016 12:28:46 +0200 Subject: [PATCH] Only build and run cmocka unit tests if its submodule is initialized Commit 40cb4cfc5d01110 added infrastructure to write unit tests using cmocka. This was implemented using a git submodule to fetch an up-to-date cmocka test framework. The issue which appeared was that 'make check' stopped working if the cmocka submodule was not initialized and updated. As we do not want this to be a hard depenency, this patch makes running these unit tests conditional. If cmocka has not been initialized, skip them or if it has been initialized all unit tests will be run. [v2 - Also check if cmake is available, as cmocka depends on that to be built ] Signed-off-by: David Sommerseth Acked-by: Gert Doering Message-Id: <1464703645-26640-1-git-send-email-openvpn@sf.lists.topphemmelig.net> URL: http://article.gmane.org/gmane.network.openvpn.devel/11758 (cherry picked from commit 45f6e7991cfa3bb8a44f981b6cf1e794d617d51e) --- configure.ac | 16 ++++++++++++++++ tests/unit_tests/Makefile.am | 2 ++ vendor/Makefile.am | 2 ++ 3 files changed, 20 insertions(+) diff --git a/configure.ac b/configure.ac index d112b43b3..56f667e40 100644 --- a/configure.ac +++ b/configure.ac @@ -1132,6 +1132,22 @@ TEST_CFLAGS="-I\$(top_srcdir)/include -I\$(abs_top_builddir)/vendor/dist/include AC_SUBST([TEST_LDFLAGS]) AC_SUBST([TEST_CFLAGS]) +# Check if cmake is available and cmocka git submodule is initialized, +# needed for unit testing +AC_CHECK_PROGS([CMAKE], [cmake]) +if test -n "${CMAKE}"; then + if test -f vendor/cmocka/CMakeLists.txt; then + AM_CONDITIONAL([CMOCKA_INITIALIZED], [true]) + else + AM_CONDITIONAL([CMOCKA_INITIALIZED], [false]) + AC_MSG_RESULT([!! WARNING !! The cmoka git submodule has not been initialized or updated. Unit testing cannot be performed.]) + fi +else + AC_MSG_RESULT([!! WARNING !! CMake is NOT available. Unit testing cannot be performed.]) + AM_CONDITIONAL([CMOCKA_INITIALIZED], [false]) +fi + + AC_CONFIG_FILES([ version.sh Makefile diff --git a/tests/unit_tests/Makefile.am b/tests/unit_tests/Makefile.am index e076db82c..8868c1cb4 100644 --- a/tests/unit_tests/Makefile.am +++ b/tests/unit_tests/Makefile.am @@ -1,3 +1,5 @@ AUTOMAKE_OPTIONS = foreign +if CMOCKA_INITIALIZED SUBDIRS = example_test plugins +endif diff --git a/vendor/Makefile.am b/vendor/Makefile.am index f68240e90..84656a115 100644 --- a/vendor/Makefile.am +++ b/vendor/Makefile.am @@ -15,7 +15,9 @@ distdir: libcmocka: distdir mkdir -p $(cmockabuild) +if CMOCKA_INITIALIZED (cd $(cmockabuild) && cmake -DCMAKE_INSTALL_PREFIX=$(cmockainstall) $(cmockasrc) && make && make install) +endif check: libcmocka -- 2.47.2