Browse code

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 <dazo@privateinternetaccess.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1464703645-26640-1-git-send-email-openvpn@sf.lists.topphemmelig.net>
URL: http://article.gmane.org/gmane.network.openvpn.devel/11758

David Sommerseth authored on 2016/05/31 19:28:46
Showing 3 changed files
... ...
@@ -1211,6 +1211,22 @@ TEST_CFLAGS="-I\$(top_srcdir)/include -I\$(abs_top_builddir)/vendor/dist/include
1211 1211
 AC_SUBST([TEST_LDFLAGS])
1212 1212
 AC_SUBST([TEST_CFLAGS])
1213 1213
 
1214
+# Check if cmake is available and cmocka git submodule is initialized,
1215
+# needed for unit testing
1216
+AC_CHECK_PROGS([CMAKE], [cmake])
1217
+if test -n "${CMAKE}"; then
1218
+   if test -f vendor/cmocka/CMakeLists.txt; then
1219
+      AM_CONDITIONAL([CMOCKA_INITIALIZED], [true])
1220
+   else
1221
+      AM_CONDITIONAL([CMOCKA_INITIALIZED], [false])
1222
+      AC_MSG_RESULT([!! WARNING !! The cmoka git submodule has not been initialized or updated.  Unit testing cannot be performed.])
1223
+   fi
1224
+else
1225
+   AC_MSG_RESULT([!! WARNING !! CMake is NOT available.  Unit testing cannot be performed.])
1226
+   AM_CONDITIONAL([CMOCKA_INITIALIZED], [false])
1227
+fi
1228
+
1229
+
1214 1230
 AC_CONFIG_FILES([
1215 1231
 	version.sh
1216 1232
 	Makefile
... ...
@@ -1,3 +1,5 @@
1 1
 AUTOMAKE_OPTIONS = foreign
2 2
 
3
+if CMOCKA_INITIALIZED
3 4
 SUBDIRS = example_test plugins
5
+endif
... ...
@@ -15,7 +15,9 @@ distdir:
15 15
 
16 16
 libcmocka: distdir
17 17
 	mkdir -p $(cmockabuild)
18
+if CMOCKA_INITIALIZED
18 19
 	(cd $(cmockabuild) && cmake -DCMAKE_INSTALL_PREFIX=$(cmockainstall) $(cmockasrc) && make && make install)
20
+endif
19 21
 
20 22
 check: libcmocka
21 23