We used to ship git submodule instructions to build a local copy of
cmocka in vendor/cmocka/ and use that (if cmake is installed) to build
unit tests. With the network test driver this turns out to be a
LD_LIBRARY_PATH vs. SUDO complication which is really outweighing the
benefit of a local build today - so, use the system-wide installation
if available (querying pgk-config). Do not build unit-tests otherwise.
v2: (inspired by patch from David Sommerseth)
introduce "configure --disable-unit-test" switch
simplify configure.ac logic
use CMOCKA_LIBS and CMOCKA_INCLUDE (set by PKG_CHECK)
v3:
repair conflict with commit 7473f326366fbceb
CMOCKA_INCLUDE is not correct, must be CMOCKA_CFLAGS (see config.status)
Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <20190623183210.6005-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18570.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
| ... | ... |
@@ -156,6 +156,20 @@ Test SSL/TLS negotiations (runs for 2 minutes): |
| 156 | 156 |
For more thorough client-server tests you can configure your own, private test |
| 157 | 157 |
environment. See tests/t_client.rc-sample for details. |
| 158 | 158 |
|
| 159 |
+To do the C unit tests, you need to have the "cmocka" test framework |
|
| 160 |
+installed on your system. More recent distributions already ship this |
|
| 161 |
+as part of their packages/ports. If your system does not have it, |
|
| 162 |
+you can install cmocka with these commands: |
|
| 163 |
+ |
|
| 164 |
+ $ git clone https://git.cryptomilk.org/projects/cmocka.git |
|
| 165 |
+ $ cd cmocka |
|
| 166 |
+ $ mkdir build |
|
| 167 |
+ $ cd build |
|
| 168 |
+ $ cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Debug .. |
|
| 169 |
+ $ make |
|
| 170 |
+ $ sudo make install |
|
| 171 |
+ |
|
| 172 |
+ |
|
| 159 | 173 |
************************************************************************* |
| 160 | 174 |
|
| 161 | 175 |
OPTIONS for ./configure: |
| ... | ... |
@@ -1361,33 +1361,32 @@ AC_SUBST([sampledir]) |
| 1361 | 1361 |
AC_SUBST([systemdunitdir]) |
| 1362 | 1362 |
AC_SUBST([tmpfilesdir]) |
| 1363 | 1363 |
|
| 1364 |
+AC_ARG_ENABLE( |
|
| 1365 |
+ [unit-tests], |
|
| 1366 |
+ [AS_HELP_STRING([--disable-unit-tests], |
|
| 1367 |
+ [Disables building and running the unit tests suite])], |
|
| 1368 |
+ [], |
|
| 1369 |
+ [enable_unit_tests="yes"] |
|
| 1370 |
+) |
|
| 1371 |
+ |
|
| 1372 |
+# Check if cmocka is available - needed for unit testing |
|
| 1373 |
+PKG_CHECK_MODULES( |
|
| 1374 |
+ [CMOCKA], [cmocka], |
|
| 1375 |
+ [have_cmocka="yes"], |
|
| 1376 |
+ [AC_MSG_WARN([cmocka.pc not found on the system. Unit tests disabled])] |
|
| 1377 |
+) |
|
| 1378 |
+AM_CONDITIONAL([ENABLE_UNITTESTS], [test "${enable_unit_tests}" = "yes" -a "${have_cmocka}" = "yes" ])
|
|
| 1379 |
+AC_SUBST([ENABLE_UNITTESTS]) |
|
| 1380 |
+ |
|
| 1364 | 1381 |
TEST_LDFLAGS="${OPTIONAL_CRYPTO_LIBS} ${OPTIONAL_PKCS11_HELPER_LIBS}"
|
| 1365 |
-TEST_LDFLAGS="${TEST_LDFLAGS} ${OPTIONAL_LZO_LIBS}"
|
|
| 1366 |
-TEST_LDFLAGS="${TEST_LDFLAGS} -lcmocka -L\$(top_builddir)/vendor/dist/lib"
|
|
| 1367 |
-TEST_LDFLAGS="${TEST_LDFLAGS} -Wl,-rpath,\$(top_builddir)/vendor/dist/lib"
|
|
| 1382 |
+TEST_LDFLAGS="${TEST_LDFLAGS} ${OPTIONAL_LZO_LIBS} ${CMOCKA_LIBS}"
|
|
| 1368 | 1383 |
TEST_CFLAGS="${OPTIONAL_CRYPTO_CFLAGS} ${OPTIONAL_PKCS11_HELPER_CFLAGS}"
|
| 1369 | 1384 |
TEST_CFLAGS="${TEST_CFLAGS} ${OPTIONAL_LZO_CFLAGS}"
|
| 1370 |
-TEST_CFLAGS="${TEST_CFLAGS} -I\$(top_srcdir)/include -I\$(top_builddir)/vendor/dist/include"
|
|
| 1385 |
+TEST_CFLAGS="${TEST_CFLAGS} -I\$(top_srcdir)/include ${CMOCKA_CFLAGS}"
|
|
| 1371 | 1386 |
|
| 1372 | 1387 |
AC_SUBST([TEST_LDFLAGS]) |
| 1373 | 1388 |
AC_SUBST([TEST_CFLAGS]) |
| 1374 | 1389 |
|
| 1375 |
-# Check if cmake is available and cmocka git submodule is initialized, |
|
| 1376 |
-# needed for unit testing |
|
| 1377 |
-AC_CHECK_PROGS([CMAKE], [cmake]) |
|
| 1378 |
-if test -n "${CMAKE}"; then
|
|
| 1379 |
- if test -f "${srcdir}/vendor/cmocka/CMakeLists.txt"; then
|
|
| 1380 |
- AM_CONDITIONAL([CMOCKA_INITIALIZED], [true]) |
|
| 1381 |
- else |
|
| 1382 |
- AM_CONDITIONAL([CMOCKA_INITIALIZED], [false]) |
|
| 1383 |
- AC_MSG_RESULT([!! WARNING !! The cmoka git submodule has not been initialized or updated. Unit testing cannot be performed.]) |
|
| 1384 |
- fi |
|
| 1385 |
-else |
|
| 1386 |
- AC_MSG_RESULT([!! WARNING !! CMake is NOT available. Unit testing cannot be performed.]) |
|
| 1387 |
- AM_CONDITIONAL([CMOCKA_INITIALIZED], [false]) |
|
| 1388 |
-fi |
|
| 1389 |
- |
|
| 1390 |
- |
|
| 1391 | 1390 |
AC_CONFIG_FILES([ |
| 1392 | 1391 |
version.sh |
| 1393 | 1392 |
Makefile |
| ... | ... |
@@ -1415,7 +1414,6 @@ AC_CONFIG_FILES([ |
| 1415 | 1415 |
tests/unit_tests/openvpn/Makefile |
| 1416 | 1416 |
tests/unit_tests/plugins/Makefile |
| 1417 | 1417 |
tests/unit_tests/plugins/auth-pam/Makefile |
| 1418 |
- vendor/Makefile |
|
| 1419 | 1418 |
sample/Makefile |
| 1420 | 1419 |
]) |
| 1421 | 1420 |
AC_CONFIG_FILES([tests/t_client.sh], [chmod +x tests/t_client.sh]) |
| 6 | 6 |
deleted file mode 100644 |
| ... | ... |
@@ -1,22 +0,0 @@ |
| 1 |
-cmockasrc = $(srcdir)/cmocka |
|
| 2 |
-# Not just '$(builddir)/cmocka', because cmocka requires an out-of-source build |
|
| 3 |
-cmockabuild = $(builddir)/cmocka_build |
|
| 4 |
-cmockadist = $(builddir)/dist |
|
| 5 |
- |
|
| 6 |
-MAINTAINERCLEANFILES = \ |
|
| 7 |
- $(srcdir)/Makefile.in \ |
|
| 8 |
- "$(cmockabuild)" \ |
|
| 9 |
- "$(cmockadist)" |
|
| 10 |
- |
|
| 11 |
-libcmocka: |
|
| 12 |
-if CMOCKA_INITIALIZED |
|
| 13 |
- mkdir -p $(cmockabuild) $(cmockadist) |
|
| 14 |
- ## Compensate for the cd in the paths |
|
| 15 |
- (cd $(cmockabuild) && cmake -DCMAKE_INSTALL_PREFIX=../$(cmockadist) ../$(cmockasrc) && make && make install) |
|
| 16 |
-endif |
|
| 17 |
- |
|
| 18 |
-check: libcmocka |
|
| 19 |
- |
|
| 20 |
-clean: |
|
| 21 |
- rm -rf $(cmockabuild) |
|
| 22 |
- rm -rf $(cmockainstall) |
| 23 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,8 +0,0 @@ |
| 1 |
-Vendor |
|
| 2 |
-======== |
|
| 3 |
- |
|
| 4 |
-Vendor source libraries are included in this directory. Libraries are included |
|
| 5 |
-when there is no good way to ensure that the package is available on all |
|
| 6 |
-systems. |
|
| 7 |
- |
|
| 8 |
-`Makefile.am` compiles these libraries and installs them into ./dist. |