Add test runner for unit tests in libstrongswan
authorTobias Brunner <tobias@strongswan.org>
Tue, 26 Mar 2013 09:21:32 +0000 (10:21 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 11 Jun 2013 09:03:10 +0000 (11:03 +0200)
configure.in
src/libstrongswan/Makefile.am
src/libstrongswan/tests/.gitignore [new file with mode: 0644]
src/libstrongswan/tests/Makefile.am [new file with mode: 0644]
src/libstrongswan/tests/test_runner.c [new file with mode: 0644]
src/libstrongswan/tests/test_runner.h [new file with mode: 0644]

index 8df0c2a..b366a6a 100644 (file)
@@ -1320,6 +1320,7 @@ AC_CONFIG_FILES([
        src/libstrongswan/plugins/gcm/Makefile
        src/libstrongswan/plugins/af_alg/Makefile
        src/libstrongswan/plugins/test_vectors/Makefile
+       src/libstrongswan/tests/Makefile
        src/libhydra/Makefile
        src/libhydra/plugins/attr/Makefile
        src/libhydra/plugins/attr_sql/Makefile
index 2465fb0..bde6964 100644 (file)
@@ -455,3 +455,10 @@ if MONOLITHIC
   libstrongswan_la_LIBADD += plugins/test_vectors/libstrongswan-test-vectors.la
 endif
 endif
+
+if UNITTESTS
+if MONOLITHIC
+  SUBDIRS += .
+endif
+  SUBDIRS += tests
+endif
diff --git a/src/libstrongswan/tests/.gitignore b/src/libstrongswan/tests/.gitignore
new file mode 100644 (file)
index 0000000..35429f6
--- /dev/null
@@ -0,0 +1 @@
+test_runner
diff --git a/src/libstrongswan/tests/Makefile.am b/src/libstrongswan/tests/Makefile.am
new file mode 100644 (file)
index 0000000..215cdde
--- /dev/null
@@ -0,0 +1,15 @@
+TESTS = test_runner
+
+check_PROGRAMS = $(TESTS)
+
+test_runner_SOURCES = \
+  test_runner.c test_runner.h
+
+
+test_runner_CFLAGS = \
+  -I$(top_srcdir)/src/libstrongswan \
+  @CHECK_CFLAGS@
+
+test_runner_LDADD = \
+  $(top_builddir)/src/libstrongswan/libstrongswan.la \
+  @CHECK_LIBS@
diff --git a/src/libstrongswan/tests/test_runner.c b/src/libstrongswan/tests/test_runner.c
new file mode 100644 (file)
index 0000000..264dd70
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2013 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include "test_runner.h"
+
+#include <library.h>
+
+int main()
+{
+       SRunner *sr;
+       int nf;
+
+       /* if a test fails there is no cleanup, so disable leak detective */
+       setenv("LEAK_DETECTIVE_DISABLE", "1", 1);
+
+       library_init(NULL);
+
+       sr = srunner_create(NULL);
+
+       srunner_run_all(sr, CK_NORMAL);
+       nf = srunner_ntests_failed(sr);
+
+       srunner_free(sr);
+       library_deinit();
+
+       return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/src/libstrongswan/tests/test_runner.h b/src/libstrongswan/tests/test_runner.h
new file mode 100644 (file)
index 0000000..f7a7d75
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2013 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#ifndef TEST_RUNNER_H_
+#define TEST_RUNNER_H_
+
+#include <check.h>
+
+#endif /** TEST_RUNNER_H_ */