Skip to contentSkip to conversation

Add unit testing support

Openvpn-devel In review [email protected]... 4 participants 8 messages May 25, 2016 – May 31, 2016 Kbuild

lore
Share & tools
lore
#1 lore raw

PATCH 1/2 Add unit testing support via cmocka

From: Jens Neuhalfen <[email protected]...>

cmocka [1,2] is a testing framework for C. Adding unit test capabilities to the openvpn repository will greatly ease the task of writing correct code.

cmocka source code is added as git submodule in ./vendor. A submodule approach has been chosen over a classical library dependency because libcmocka is not available, or only available in very old versions (e.g. on Ubuntu).

cmocka is build during 'make check' and installed in vendor/dist/.

[1] https://cmocka.org/
[2] https://lwn.net/Articles/558106/

---
 .gitmodules                               |  4 +++
 Makefile.am                               |  2 +-
 configure.ac                              | 16 +++++++++++
 tests/Makefile.am                         |  3 +-
 tests/unit_tests/.gitignore               |  1 +
 tests/unit_tests/Makefile.am              |  3 ++
 tests/unit_tests/README.md                | 40 ++++++++++++++++++++++++++
 tests/unit_tests/example_test/Makefile.am | 13 +++++++++
 tests/unit_tests/example_test/README.md   |  3 ++
 tests/unit_tests/example_test/test.c      | 47 +++++++++++++++++++++++++++++++
 tests/unit_tests/example_test/test2.c     | 22 +++++++++++++++
 vendor/.gitignore                         |  2 ++
 vendor/Makefile.am                        | 24 ++++++++++++++++
 vendor/README.md                          |  9 ++++++
 vendor/cmocka                             |  1 +
 15 files changed, 188 insertions(+), 2 deletions(-)
 create mode 100644 .gitmodules
 create mode 100644 tests/unit_tests/.gitignore
 create mode 100644 tests/unit_tests/Makefile.am
 create mode 100644 tests/unit_tests/README.md
 create mode 100644 tests/unit_tests/example_test/Makefile.am
 create mode 100644 tests/unit_tests/example_test/README.md
 create mode 100644 tests/unit_tests/example_test/test.c
 create mode 100644 tests/unit_tests/example_test/test2.c
 create mode 100644 vendor/.gitignore
 create mode 100644 vendor/Makefile.am
 create mode 100644 vendor/README.md
 create mode 160000 vendor/cmocka
.gitmodules new file +4 -0
new file mode 100644
index 0000000..e9c6388
@@ -0,0 +1,4 @@
+[submodule "vendor/cmocka"]
+	path = vendor/cmocka
+	url = git://git.cryptomilk.org/projects/cmocka.git
+	branch = master
Makefile.am +1 -1
index 66d9f23..364785c 100644
@@ -54,7 +54,7 @@ BUILT_SOURCES = \
 	config-version.h
 endif
 
-SUBDIRS = build distro include src sample doc tests
+SUBDIRS = build distro include src sample doc vendor tests
 
 dist_doc_DATA = \
 	README \
configure.ac +16 -0
index 97ad856..fb3fa3c 100644
@@ -1198,6 +1198,19 @@ sampledir="\$(docdir)/sample"
 AC_SUBST([plugindir])
 AC_SUBST([sampledir])
 
+VENDOR_SRC_ROOT="\$(abs_top_srcdir)/vendor/"
+VENDOR_DIST_ROOT="\$(abs_top_builddir)/vendor/dist"
+VENDOR_BUILD_ROOT="\$(abs_top_builddir)/vendor/.build"
+AC_SUBST([VENDOR_SRC_ROOT])
+AC_SUBST([VENDOR_BUILD_ROOT])
+AC_SUBST([VENDOR_DIST_ROOT])
+
+TEST_LDFLAGS="-lcmocka -L\$(abs_top_builddir)/vendor/dist/lib -Wl,-rpath,\$(abs_top_builddir)/vendor/dist/lib"
+TEST_CFLAGS="-I\$(top_srcdir)/include -I\$(abs_top_builddir)/vendor/dist/include"
+
+AC_SUBST([TEST_LDFLAGS])
+AC_SUBST([TEST_CFLAGS])
+
 AC_CONFIG_FILES([
 	version.sh
 	Makefile
@@ -1216,6 +1229,9 @@ AC_CONFIG_FILES([
 	src/plugins/auth-pam/Makefile
 	src/plugins/down-root/Makefile
 	tests/Makefile
+        tests/unit_tests/Makefile
+        tests/unit_tests/example_test/Makefile
+        vendor/Makefile
 	sample/Makefile
 	doc/Makefile
 ])
tests/Makefile.am +2 -1
index b7980e0..2cba9e6 100644
@@ -12,6 +12,8 @@
 MAINTAINERCLEANFILES = \
 	$(srcdir)/Makefile.in
 
+SUBDIRS = unit_tests
+
 test_scripts = t_client.sh t_lpback.sh t_cltsrv.sh
 
 TESTS_ENVIRONMENT = top_srcdir="$(top_srcdir)"
@@ -20,4 +22,3 @@ TESTS = $(test_scripts)
 dist_noinst_SCRIPTS = \
 	$(test_scripts) \
 	t_cltsrv-down.sh
-
tests/unit_tests/.gitignore new file +1 -0
new file mode 100644
index 0000000..8655de8
@@ -0,0 +1 @@
+*_testdriver
tests/unit_tests/Makefile.am new file +3 -0
new file mode 100644
index 0000000..18267bd
@@ -0,0 +1,3 @@
+AUTOMAKE_OPTIONS = foreign
+
+SUBDIRS = example_test
tests/unit_tests/README.md new file +40 -0
new file mode 100644
index 0000000..ef81b23
@@ -0,0 +1,40 @@
+Unit Tests
+===========
+
+This directory contains unit tests for openvpn. New features/bugfixes should be written in a test friendly way and come with corresponding tests.
+
+Run tests
+----------
+
+Tests are run by `make check`. A failed tests stops test execution. To run all
+tests regardless of errors call `make -k check`.
+
+Add new tests to existing test suite
+-------------------------------------
+
+Test suites are organized in directories. [example_test/](example_test/) is an example
+for a test suite with two test executables. Feel free to use it as a template for new tests.
+
+Test suites
+--------------------
+
+Test suites live inside a subdirectory of `$ROOT/tests/unit_tests`, e.g. `$ROOT/tests/unit_tests/my_feature`.
+
+Test suites are configured by a `Makefile.am`. Tests are executed by testdrivers. One testsuite can contain more than one testdriver.
+
+### Hints
+* Name suites & testdrivers in a way that the name of the driver says something about which component/feature is tested
+* Name the testdriver executable `*_testdriver`. This way it gets picked up by the default `.gitignore`
+  * If this is not feasible: Add all output to a `.gitignore`* Use descriptive test names: `coffee_brewing__with_no_beans__fails` vs. `test34`
+* Testing a configurable feature?  Wrap test execution with a conditional (see [auth_pam](plugins/auth-pam/Makefile.am) for an example)
+* Add multiple test-drivers when one testdriver looks crowded with tests
+
+### New Test Suites
+1.  Organize tests in folders for features.
+2.  Add the new test directory to `SUBDIRS` in `Makefile.am`
+3.  Edit `configure.ac` and add the new `Makefile` to `AC_CONFIG_FILES`
+4.  Run `./configure`, and *enable* the feature you'd like to test
+5.  Make sure that `make check` runs your tests
+6.  Check: Would a stranger be able to easily find your tests by you looking at the test output?  
+7. Run `./configure`, and *disable* the feature you'd like to test
+8.  Make sure that `make check` does *not run* your tests
tests/unit_tests/example_test/Makefile.am new file +13 -0
new file mode 100644
index 0000000..04a5ad3
@@ -0,0 +1,13 @@
+AUTOMAKE_OPTIONS = foreign
+
+check_PROGRAMS = example_testdriver example2_testdriver
+
+TESTS = $(check_PROGRAMS)
+
+example_testdriver_CFLAGS  = @TEST_CFLAGS@
+example_testdriver_LDFLAGS = @TEST_LDFLAGS@
+example_testdriver_SOURCES = test.c
+
+example2_testdriver_CFLAGS  = @TEST_CFLAGS@
+example2_testdriver_LDFLAGS = @TEST_LDFLAGS@
+example2_testdriver_SOURCES = test2.c
tests/unit_tests/example_test/README.md new file +3 -0
new file mode 100644
index 0000000..cb75d68
@@ -0,0 +1,3 @@
+This test only checks that test compilation works. This example contains two test executables.
+
+These tests can be used as template for 'real' tests.
tests/unit_tests/example_test/test.c new file +47 -0

47 lines not on this page · raw message

tests/unit_tests/example_test/test2.c new file +22 -0
new file mode 100644
index 0000000..2924c61
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+
+static void test_true(void **state) {
+    (void) state;
+}
+
+
+int main(void) {
+    const struct CMUnitTest tests[] = {
+        cmocka_unit_test(test_true),
+    };
+
+    return cmocka_run_group_tests_name("success_test2", tests, NULL, NULL);
+}
+
vendor/.gitignore new file +2 -0
new file mode 100644
index 0000000..e11dfec
@@ -0,0 +1,2 @@
+.build/
+dist/
vendor/Makefile.am new file +24 -0
new file mode 100644
index 0000000..f68240e
@@ -0,0 +1,24 @@
+AUTOMAKE_OPTIONS = foreign
+
+cmockasrc     = @VENDOR_SRC_ROOT@/cmocka  # needs an absolute path bc. of the cmake invocation
+cmockabuild   = @VENDOR_BUILD_ROOT@/cmocka
+cmockainstall = @VENDOR_DIST_ROOT@
+
+MAINTAINERCLEANFILES = \
+	$(srcdir)/Makefile.in \
+	$(cmockabuild) \
+	$(cmockainstall) \
+	@VENDOR_BUILD_ROOT@
+
+distdir:
+	mkdir -p $(cmockainstall)
+
+libcmocka: distdir
+	mkdir -p $(cmockabuild)
+	(cd $(cmockabuild) && cmake -DCMAKE_INSTALL_PREFIX=$(cmockainstall) $(cmockasrc) && make && make install)
+
+check: libcmocka
+
+clean:
+	rm -rf $(cmockabuild)
+	rm -rf $(cmockainstall)
vendor/README.md new file +9 -0
new file mode 100644
index 0000000..6a46b35
@@ -0,0 +1,9 @@
+Vendor
+========
+
+Vendor source libraries are included in this directory. Libraries are included
+when there is no good way to ensure that the package is available on all 
+systems.
+
+`Makefile.am` compiles these libraries and installs them into ./dist.
+
vendor/cmocka new file +1 -0
new file mode 160000
index 0000000..b2732b5
@@ -0,0 +1 @@
+Subproject commit b2732b52202ae48f866a024c633466efdbb8e85a
Signature · 1 line
2.8.3
#2 lore raw

Re: [Openvpn-devel] [PATCH 1/2] Add unit testing support via cmocka

Quoted 352 lines · On Wed, May 25, 2016 at 7:57 PM, <[email protected]...> wrote:

From: Jens Neuhalfen <[email protected]...>

cmocka [1,2] is a testing framework for C. Adding unit test capabilities to the openvpn repository will greatly ease the task of writing correct code.

cmocka source code is added as git submodule in ./vendor. A submodule approach has been chosen over a classical library dependency because libcmocka is not available, or only available in very old versions (e.g. on Ubuntu).

cmocka is build during 'make check' and installed in vendor/dist/.

[1] https://cmocka.org/
[2] https://lwn.net/Articles/558106/

---
 .gitmodules                               |  4 +++
 Makefile.am                               |  2 +-
 configure.ac                              | 16 +++++++++++
 tests/Makefile.am                         |  3 +-
 tests/unit_tests/.gitignore               |  1 +
 tests/unit_tests/Makefile.am              |  3 ++
 tests/unit_tests/README.md                | 40 ++++++++++++++++++++++++++
 tests/unit_tests/example_test/Makefile.am | 13 +++++++++
 tests/unit_tests/example_test/README.md   |  3 ++
 tests/unit_tests/example_test/test.c      | 47 +++++++++++++++++++++++++++++++
 tests/unit_tests/example_test/test2.c     | 22 +++++++++++++++
 vendor/.gitignore                         |  2 ++
 vendor/Makefile.am                        | 24 ++++++++++++++++
 vendor/README.md                          |  9 ++++++
 vendor/cmocka                             |  1 +
 15 files changed, 188 insertions(+), 2 deletions(-)
 create mode 100644 .gitmodules
 create mode 100644 tests/unit_tests/.gitignore
 create mode 100644 tests/unit_tests/Makefile.am
 create mode 100644 tests/unit_tests/README.md
 create mode 100644 tests/unit_tests/example_test/Makefile.am
 create mode 100644 tests/unit_tests/example_test/README.md
 create mode 100644 tests/unit_tests/example_test/test.c
 create mode 100644 tests/unit_tests/example_test/test2.c
 create mode 100644 vendor/.gitignore
 create mode 100644 vendor/Makefile.am
 create mode 100644 vendor/README.md
 create mode 160000 vendor/cmocka
.gitmodules new file +4 -0
new file mode 100644
index 0000000..e9c6388
@@ -0,0 +1,4 @@
+[submodule "vendor/cmocka"]
+       path = vendor/cmocka
+       url = git://git.cryptomilk.org/projects/cmocka.git
+       branch = master
Makefile.am +1 -1
index 66d9f23..364785c 100644
@@ -54,7 +54,7 @@ BUILT_SOURCES = \
        config-version.h
 endif
 
-SUBDIRS = build distro include src sample doc tests
+SUBDIRS = build distro include src sample doc vendor tests
 
 dist_doc_DATA = \
        README \
configure.ac +16 -0
index 97ad856..fb3fa3c 100644
@@ -1198,6 +1198,19 @@ sampledir="\$(docdir)/sample"
 AC_SUBST([plugindir])
 AC_SUBST([sampledir])
 
+VENDOR_SRC_ROOT="\$(abs_top_srcdir)/vendor/"
+VENDOR_DIST_ROOT="\$(abs_top_builddir)/vendor/dist"
+VENDOR_BUILD_ROOT="\$(abs_top_builddir)/vendor/.build"
+AC_SUBST([VENDOR_SRC_ROOT])
+AC_SUBST([VENDOR_BUILD_ROOT])
+AC_SUBST([VENDOR_DIST_ROOT])
+
+TEST_LDFLAGS="-lcmocka -L\$(abs_top_builddir)/vendor/dist/lib -Wl,-rpath,\$(abs_top_builddir)/vendor/dist/lib"
+TEST_CFLAGS="-I\$(top_srcdir)/include -I\$(abs_top_builddir)/vendor/dist/include"
+
+AC_SUBST([TEST_LDFLAGS])
+AC_SUBST([TEST_CFLAGS])
+
 AC_CONFIG_FILES([
        version.sh
        Makefile
@@ -1216,6 +1229,9 @@ AC_CONFIG_FILES([
        src/plugins/auth-pam/Makefile
        src/plugins/down-root/Makefile
        tests/Makefile
+        tests/unit_tests/Makefile
+        tests/unit_tests/example_test/Makefile
+        vendor/Makefile
        sample/Makefile
        doc/Makefile
 ])
tests/Makefile.am +2 -1
index b7980e0..2cba9e6 100644
@@ -12,6 +12,8 @@
 MAINTAINERCLEANFILES = \
        $(srcdir)/Makefile.in
 
+SUBDIRS = unit_tests
+
 test_scripts = t_client.sh t_lpback.sh t_cltsrv.sh
 
 TESTS_ENVIRONMENT = top_srcdir="$(top_srcdir)"
@@ -20,4 +22,3 @@ TESTS = $(test_scripts)
 dist_noinst_SCRIPTS = \
        $(test_scripts) \
        t_cltsrv-down.sh
-
tests/unit_tests/.gitignore new file +1 -0
new file mode 100644
index 0000000..8655de8
@@ -0,0 +1 @@
+*_testdriver
tests/unit_tests/Makefile.am new file +3 -0
new file mode 100644
index 0000000..18267bd
@@ -0,0 +1,3 @@
+AUTOMAKE_OPTIONS = foreign
+
+SUBDIRS = example_test
tests/unit_tests/README.md new file +40 -0
new file mode 100644
index 0000000..ef81b23
@@ -0,0 +1,40 @@
+Unit Tests
+===========
+
+This directory contains unit tests for openvpn. New features/bugfixes should be written in a test friendly way and come with corresponding tests.
+
+Run tests
+----------
+
+Tests are run by `make check`. A failed tests stops test execution. To run all
+tests regardless of errors call `make -k check`.
+
+Add new tests to existing test suite
+-------------------------------------
+
+Test suites are organized in directories. [example_test/](example_test/) is an example
+for a test suite with two test executables. Feel free to use it as a template for new tests.
+
+Test suites
+--------------------
+
+Test suites live inside a subdirectory of `$ROOT/tests/unit_tests`, e.g. `$ROOT/tests/unit_tests/my_feature`.
+
+Test suites are configured by a `Makefile.am`. Tests are executed by testdrivers. One testsuite can contain more than one testdriver.
+
+### Hints
+* Name suites & testdrivers in a way that the name of the driver says something about which component/feature is tested
+* Name the testdriver executable `*_testdriver`. This way it gets picked up by the default `.gitignore`
+  * If this is not feasible: Add all output to a `.gitignore`* Use descriptive test names: `coffee_brewing__with_no_beans__fails` vs. `test34`
+* Testing a configurable feature?  Wrap test execution with a conditional (see [auth_pam](plugins/auth-pam/Makefile.am) for an example)
+* Add multiple test-drivers when one testdriver looks crowded with tests
+
+### New Test Suites
+1.  Organize tests in folders for features.
+2.  Add the new test directory to `SUBDIRS` in `Makefile.am`
+3.  Edit `configure.ac` and add the new `Makefile` to `AC_CONFIG_FILES`
+4.  Run `./configure`, and *enable* the feature you'd like to test
+5.  Make sure that `make check` runs your tests
+6.  Check: Would a stranger be able to easily find your tests by you looking at the test output?
+7. Run `./configure`, and *disable* the feature you'd like to test
+8.  Make sure that `make check` does *not run* your tests
tests/unit_tests/example_test/Makefile.am new file +13 -0
new file mode 100644
index 0000000..04a5ad3
@@ -0,0 +1,13 @@
+AUTOMAKE_OPTIONS = foreign
+
+check_PROGRAMS = example_testdriver example2_testdriver
+
+TESTS = $(check_PROGRAMS)
+
+example_testdriver_CFLAGS  = @TEST_CFLAGS@
+example_testdriver_LDFLAGS = @TEST_LDFLAGS@
+example_testdriver_SOURCES = test.c
+
+example2_testdriver_CFLAGS  = @TEST_CFLAGS@
+example2_testdriver_LDFLAGS = @TEST_LDFLAGS@
+example2_testdriver_SOURCES = test2.c
tests/unit_tests/example_test/README.md new file +3 -0
new file mode 100644
index 0000000..cb75d68
@@ -0,0 +1,3 @@
+This test only checks that test compilation works. This example contains two test executables.
+
+These tests can be used as template for 'real' tests.
tests/unit_tests/example_test/test.c new file +47 -0
new file mode 100644
index 0000000..c746b8b
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+static int setup(void **state) {
+     int *answer  = malloc(sizeof(int));
+
+     *answer=42;
+     *state=answer;
+
+     return 0;
+}
+
+static int teardown(void **state) {
+     free(*state);
+
+     return 0;
+}
+
+static void null_test_success(void **state) {
+    (void) state;
+}
+
+static void int_test_success(void **state) {
+     int *answer = *state;
+     assert_int_equal(*answer, 42);
+}
+
+static void failing_test(void **state) {
+     // This tests fails to test that make check fails
+     assert_int_equal(0, 42);
+}
+
+int main(void) {
+    const struct CMUnitTest tests[] = {
+        cmocka_unit_test(null_test_success),
+        cmocka_unit_test_setup_teardown(int_test_success, setup, teardown),
+//        cmocka_unit_test(failing_test),
+    };
+
+    return cmocka_run_group_tests_name("success_test", tests, NULL, NULL);
+}
+
tests/unit_tests/example_test/test2.c new file +22 -0
new file mode 100644
index 0000000..2924c61
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+
+static void test_true(void **state) {
+    (void) state;
+}
+
+
+int main(void) {
+    const struct CMUnitTest tests[] = {
+        cmocka_unit_test(test_true),
+    };
+
+    return cmocka_run_group_tests_name("success_test2", tests, NULL, NULL);
+}
+
vendor/.gitignore new file +2 -0
new file mode 100644
index 0000000..e11dfec
@@ -0,0 +1,2 @@
+.build/
+dist/
vendor/Makefile.am new file +24 -0
new file mode 100644
index 0000000..f68240e
@@ -0,0 +1,24 @@
+AUTOMAKE_OPTIONS = foreign
+
+cmockasrc     = @VENDOR_SRC_ROOT@/cmocka  # needs an absolute path bc. of the cmake invocation
+cmockabuild   = @VENDOR_BUILD_ROOT@/cmocka
+cmockainstall = @VENDOR_DIST_ROOT@
+
+MAINTAINERCLEANFILES = \
+       $(srcdir)/Makefile.in \
+       $(cmockabuild) \
+       $(cmockainstall) \
+       @VENDOR_BUILD_ROOT@
+
+distdir:
+       mkdir -p $(cmockainstall)
+
+libcmocka: distdir
+       mkdir -p $(cmockabuild)
+       (cd $(cmockabuild) && cmake -DCMAKE_INSTALL_PREFIX=$(cmockainstall) $(cmockasrc) && make && make install)
+
+check: libcmocka
+
+clean:
+       rm -rf $(cmockabuild)
+       rm -rf $(cmockainstall)
vendor/README.md new file +9 -0
new file mode 100644
index 0000000..6a46b35
@@ -0,0 +1,9 @@
+Vendor
+========
+
+Vendor source libraries are included in this directory. Libraries are included
+when there is no good way to ensure that the package is available on all
+systems.
+
+`Makefile.am` compiles these libraries and installs them into ./dist.
+
vendor/cmocka new file +1 -1
new file mode 160000
index 0000000..b2732b5
@@ -0,0 +1 @@
+Subproject commit b2732b52202ae48f866a024c633466efdbb8e85a
--
Quoted 1 line

2.8.3

ACK

-Steffan

#3 lore raw

[Openvpn-devel] [PATCH applied] Re: Add unit testing support via cmocka

In reply to [email protected]...

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

commit 1ca6bd4284e64ab3822f9e28fa16cb35499f2232 master commit 1739c102a5c7db510f0ae3c125501a3d1ba3e85f release/2.3

Author: Jens Neuhalfen
Date:   Wed May 25 19:57:55 2016 +0200
     Add unit testing support via cmocka

     Signed-off-by: Jens Neuhalfen <[email protected]...>
     Acked-by: Steffan Karger <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/11725
     Signed-off-by: David Sommerseth <[email protected]...>

--
kind regards,

David Sommerseth

#4 lore raw

Re: [Openvpn-devel] [PATCH 1/2] Add unit testing support via cmocka

In reply to [email protected]...

Hi,

Quoted 5 lines · On Wed, May 25, 2016 at 07:57:55PM +0200, [email protected]... wrote:

From: Jens Neuhalfen <[email protected]...>

cmocka [1,2] is a testing framework for C. Adding unit test capabilities to the openvpn repository will greatly ease the task of writing correct code.

Quoted 8 lines

cmocka source code is added as git submodule in ./vendor. A submodule approach has been chosen over a classical library dependency because libcmocka is not available, or only available in very old versions (e.g. on Ubuntu).

cmocka is build during 'make check' and installed in vendor/dist/.

[1] https://cmocka.org/
[2] https://lwn.net/Articles/558106/

This patch needs more work - David merged it tonight, and it blew up half our buildslaves.

Two main issues I could identify:

- if cmake is not installed, it should result in "SKIPPED" tests, not in build/make failures - since we do not list it in our build requirements (and we shouldn't, for normal builds), building and testing needs to be possible if cmake is not existing - of course, without the cmocka tests

- if the build is done in a directory with blanks in, which our buildbots like to do, things blow up due to lack of quoting

   rm -rf /var/lib/buildbot/slaves/openvpn/build-ubuntu-1204-i386-stable-master--disable-server --enable-small /build/vendor/.build/cmocka
   rm: unrecognized option '--enable-small'

the "--enable-small" bit is part of the current directory name, and has a blank before it... (which might not be considered good practice, but better it blows up for us than for users)

It also blows up in configure already when building for windows, but I'm not sure I understand why - Samuli is looking into that.

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]...
#5 lore raw

PATCH 2/2 Add a test for auth-pam searchandreplace

In reply to [email protected]...

From: Jens Neuhalfen <[email protected]...>

No functional changes.

Utility functions of auth-pam are split into a dedicated file. This allows the test programs to easily test these functions without adding dependencies.

Add a minimal test for searchandreplace as a proof of concept.

---
 configure.ac                                       |   2 +
 src/plugins/auth-pam/Makefile.am                   |   1 +
 src/plugins/auth-pam/auth-pam.c                    |  91 +----------------
 src/plugins/auth-pam/utils.c                       | 113 +++++++++++++++++++++
 src/plugins/auth-pam/utils.h                       |  54 ++++++++++
 tests/unit_tests/Makefile.am                       |   2 +-
 tests/unit_tests/plugins/Makefile.am               |   3 +
 tests/unit_tests/plugins/auth-pam/Makefile.am      |  12 +++
 .../plugins/auth-pam/test_search_and_replace.c     |  79 ++++++++++++++
 9 files changed, 266 insertions(+), 91 deletions(-)
 create mode 100644 src/plugins/auth-pam/utils.c
 create mode 100644 src/plugins/auth-pam/utils.h
 create mode 100644 tests/unit_tests/plugins/Makefile.am
 create mode 100644 tests/unit_tests/plugins/auth-pam/Makefile.am
 create mode 100644 tests/unit_tests/plugins/auth-pam/test_search_and_replace.c
configure.ac +2 -0
index fb3fa3c..5e69f91 100644
@@ -1230,6 +1230,8 @@ AC_CONFIG_FILES([
 	src/plugins/down-root/Makefile
 	tests/Makefile
         tests/unit_tests/Makefile
+        tests/unit_tests/plugins/Makefile
+        tests/unit_tests/plugins/auth-pam/Makefile
         tests/unit_tests/example_test/Makefile
         vendor/Makefile
 	sample/Makefile
src/plugins/auth-pam/Makefile.am +1 -0
index 2aef311..e6dc27e 100644
@@ -18,6 +18,7 @@ dist_doc_DATA = README.auth-pam
 endif
 
 openvpn_plugin_auth_pam_la_SOURCES = \
+	utils.c \
 	auth-pam.c \
 	pamdl.c  pamdl.h \
 	auth-pam.exports
src/plugins/auth-pam/auth-pam.c +1 -90

109 lines not on this page · raw message

src/plugins/auth-pam/utils.c new file +113 -0

113 lines not on this page · raw message

src/plugins/auth-pam/utils.h new file +54 -0

54 lines not on this page · raw message

tests/unit_tests/Makefile.am +1 -1
index 18267bd..e076db8 100644
@@ -1,3 +1,3 @@
 AUTOMAKE_OPTIONS = foreign
 
-SUBDIRS = example_test
+SUBDIRS = example_test plugins
tests/unit_tests/plugins/Makefile.am new file +3 -0
new file mode 100644
index 0000000..a3696d5
@@ -0,0 +1,3 @@
+AUTOMAKE_OPTIONS = foreign
+
+SUBDIRS = auth-pam
tests/unit_tests/plugins/auth-pam/Makefile.am new file +12 -0
new file mode 100644
index 0000000..07233ee
@@ -0,0 +1,12 @@
+AUTOMAKE_OPTIONS = foreign
+
+if ENABLE_PLUGIN_AUTH_PAM
+check_PROGRAMS = auth_pam_testdriver
+TESTS = $(check_PROGRAMS)
+endif
+
+sut_sourcedir = $(top_srcdir)/src/plugins/auth-pam
+
+auth_pam_testdriver_SOURCES = test_search_and_replace.c  $(sut_sourcedir)/utils.h $(sut_sourcedir)/utils.c
+auth_pam_testdriver_CFLAGS  = @TEST_CFLAGS@ -I$(sut_sourcedir)
+auth_pam_testdriver_LDFLAGS = @TEST_LDFLAGS@
tests/unit_tests/plugins/auth-pam/test_search_and_replace.c new file +79 -0

79 lines not on this page · raw message

Signature · 1 line
2.8.3
#6 lore raw

Re: [Openvpn-devel] [PATCH 2/2] Add a test for auth-pam searchandreplace

Hi,

Sorry for not noticing before, but one last nit:

Quoted 9 lines · On Wed, May 25, 2016 at 7:57 PM, <[email protected]...> wrote:
+/*  Read 'tosearch', replace all occurences of 'searchfor' with 'replacewith' and return
+ *  a pointer to the NEW string.  Does not modify the input strings.  Will not enter an
+ *  infinite loop with clever 'searchfor' and 'replacewith' strings.
+ *  Daniel Johnson - [email protected]... / [email protected]...

+ *
+ * Retuns NULL when
+ * - any parameter is NULL
+ * - the worst-case result is to large ( >= SIZE_MAX)
+ */

Now that you're touching these anyway, let's turn these into doxygen-style comments (/** */). But maybe Gert/David can do that when applying the patch, a v2 just for this seems a bit too much. Also goes for:

Quoted 5 lines

+/*
+ * Given an environmental variable name, search
+ * the envp array for its value, returning it
+ * if found or NULL otherwise.
+ */

and

Quoted 3 lines

+/*
+ * Return the length of a string array
+ */

But for everything else: ACK. Cool to have the infrastructure for unit testing in place. Let's hope others will now thankfully make use of this.

-Steffan

#7 lore raw

[Openvpn-devel] [PATCH applied] Re: Add a test for auth-pam searchandreplace

In reply to [email protected]...

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

commit 4ae44ef456c5d6f133ba0a059c6af3a7988868c7 master commit 0b8e0f53faa19bb1c326587bc8e612e4b1e8897d release/2.3

Author: Jens Neuhalfen
Date:   Wed May 25 19:57:56 2016 +0200
     Add a test for auth-pam searchandreplace

     Signed-off-by: Jens Neuhalfen <[email protected]...>
     Acked-by: Steffan Karger <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/11724
     Signed-off-by: David Sommerseth <[email protected]...>

[ Modified during commit: Enhanced documentation of functions in utils.h
to comply with doxygen standards ]

--
kind regards,

David Sommerseth