Skip to contentSkip to conversation

Only build and run cmocka unit tests if its submodule is initialized

PATCH Superseded David Sommerseth 2 participants 5 messages May 31, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Only build and run cmocka unit tests if its submodule is initialized

From: David Sommerseth <[email protected]...>

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.

---
 configure.ac                 | 3 +++
 tests/unit_tests/Makefile.am | 2 ++
 vendor/Makefile.am           | 2 ++
 3 files changed, 7 insertions(+)
configure.ac +3 -0
index 5e69f91..fa0f868 100644
@@ -1211,6 +1211,9 @@ TEST_CFLAGS="-I\$(top_srcdir)/include -I\$(abs_top_builddir)/vendor/dist/include
 AC_SUBST([TEST_LDFLAGS])
 AC_SUBST([TEST_CFLAGS])
 
+# Check if cmocka git submodule is initialized
+AM_CONDITIONAL([CMOCKA_INITIALIZED], [test -f vendor/cmocka/CMakeLists.txt])
+
 AC_CONFIG_FILES([
 	version.sh
 	Makefile
tests/unit_tests/Makefile.am +2 -0
index e076db8..8868c1c 100644
@@ -1,3 +1,5 @@
 AUTOMAKE_OPTIONS = foreign
 
+if CMOCKA_INITIALIZED
 SUBDIRS = example_test plugins
+endif
vendor/Makefile.am +2 -0
index f68240e..84656a1 100644
@@ -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
 
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v2 1/1 Only build and run cmocka unit tests if its submodule is initialized

From: David Sommerseth <[email protected]...>

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 ]

---
 configure.ac                 | 16 ++++++++++++++++
 tests/unit_tests/Makefile.am |  2 ++
 vendor/Makefile.am           |  2 ++
 3 files changed, 20 insertions(+)
configure.ac +16 -0
index 5e69f91..af21617 100644
@@ -1211,6 +1211,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 available.  Unit testing cannot be performed.])
+   AM_CONDITIONAL([CMOCKA_INITIALIZED], [false])
+fi
+
+
 AC_CONFIG_FILES([
 	version.sh
 	Makefile
tests/unit_tests/Makefile.am +2 -0
index e076db8..8868c1c 100644
@@ -1,3 +1,5 @@
 AUTOMAKE_OPTIONS = foreign
 
+if CMOCKA_INITIALIZED
 SUBDIRS = example_test plugins
+endif
vendor/Makefile.am +2 -0
index f68240e..84656a1 100644
@@ -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
 
Signature · 1 line
1.8.3.1
#2 lore raw

Hi,

Quoted 1 line · David Sommerseth

+ AC_MSG_RESULT([!! WARNING !! CMake is available. Unit testing cannot be performed.])

NAK, as this should be "CMake is NOT available" - otherwise, I would be happy to ACK it :-)

The rest looks good.

(See my comment on IRC for "do we want all these patches in 2.3", though)

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#3 lore raw

Hi,

Quoted 5 lines · Gert Doering
Quoted 1 line · David Sommerseth

+ AC_MSG_RESULT([!! WARNING !! CMake is available. Unit testing cannot be performed.])

NAK, as this should be "CMake is NOT available" - otherwise, I would be happy to ACK it :-)

For the sake of the archives: ACK for "v2 + that typo" :-)

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#4 lore raw
In reply to David Sommerseth

From: David Sommerseth <[email protected]...>

Your patch has been applied to the master and release/2.3 branches.

commit 45f6e7991cfa3bb8a44f981b6cf1e794d617d51e master commit 987910e8abb40e357ac1aa6bf658b4660cc7f376 release/2.3

Author: David Sommerseth
Date:   Tue May 31 12:28:46 2016 +0200
     Only build and run cmocka unit tests if its submodule is initialized

     Signed-off-by: David Sommerseth <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/11758

--
kind regards,

David Sommerseth