-TESTS = test_runner
+check_LTLIBRARIES = libtest.la
+
+libtest_la_SOURCES = \
+ test_suite.c test_suite.h \
+ test_runner.c test_runner.h
+
+libtest_la_CFLAGS = \
+ -I$(top_srcdir)/src/libstrongswan \
+ @COVERAGE_CFLAGS@
+
+libtest_la_LDFLAGS = @COVERAGE_LDFLAGS@
+libtest_la_LIBADD = \
+ $(top_builddir)/src/libstrongswan/libstrongswan.la \
+ $(PTHREADLIB)
+
+
+TESTS = tests
check_PROGRAMS = $(TESTS)
-test_runner_SOURCES = \
- test_runner.c test_runner.h test_suite.c test_suite.h \
+tests_SOURCES = tests.h tests.c \
suites/test_linked_list.c \
suites/test_enumerator.c \
suites/test_linked_list_enumerator.c \
suites/test_asn1.c \
suites/test_printf.c
-test_runner_CFLAGS = \
+tests_CFLAGS = \
-I$(top_srcdir)/src/libstrongswan \
+ -I$(top_srcdir)/src/libstrongswan/tests \
-DPLUGINDIR=\""$(top_builddir)/src/libstrongswan/plugins\"" \
-DPLUGINS=\""${s_plugins}\"" \
@COVERAGE_CFLAGS@
-test_runner_LDFLAGS = @COVERAGE_LDFLAGS@
-test_runner_LDADD = \
+tests_LDFLAGS = @COVERAGE_LDFLAGS@
+tests_LDADD = \
$(top_builddir)/src/libstrongswan/libstrongswan.la \
- $(PTHREADLIB)
+ libtest.la
* for more details.
*/
-#include "test_suite.h"
+#include "test_runner.h"
#include <library.h>
#include <plugins/plugin_feature.h>
/**
* Load plugins from builddir
*/
-static bool load_plugins()
+static bool load_plugins(char *plugindirs[], char *plugins)
{
enumerator_t *enumerator;
char *name, path[PATH_MAX], dir[64];
+ int i;
- enumerator = enumerator_create_token(PLUGINS, " ", "");
+ enumerator = enumerator_create_token(plugins, " ", "");
while (enumerator->enumerate(enumerator, &name))
{
snprintf(dir, sizeof(dir), "%s", name);
translate(dir, "-", "_");
- snprintf(path, sizeof(path), "%s/%s/.libs", PLUGINDIR, dir);
- lib->plugins->add_path(lib->plugins, path);
+ for (i = 0; plugindirs[i]; i++)
+ {
+ snprintf(path, sizeof(path), "%s/%s/.libs", plugindirs[i], dir);
+ lib->plugins->add_path(lib->plugins, path);
+ }
}
enumerator->destroy(enumerator);
- return lib->plugins->load(lib->plugins, PLUGINS);
+ return lib->plugins->load(lib->plugins, plugins);
}
-/* declare test suite constructors */
-#define TEST_SUITE(x) test_suite_t* x();
-#define TEST_SUITE_DEPEND(x, ...) TEST_SUITE(x)
-#include "test_runner.h"
-#undef TEST_SUITE
-#undef TEST_SUITE_DEPEND
-
/**
* Load all available test suites
*/
-static array_t *load_suites()
+static array_t *load_suites(test_configuration_t configs[],
+ char *plugindirs[], char *plugins)
{
array_t *suites;
- struct {
- test_suite_t *(*suite)();
- plugin_feature_t feature;
- } constructors[] = {
-#define TEST_SUITE(x) \
- { .suite = x, },
-#define TEST_SUITE_DEPEND(x, type, args) \
- { .suite = x, .feature = PLUGIN_DEPENDS(type, args) },
-#include "test_runner.h"
- };
bool old = FALSE;
int i;
test_setup_handler();
- if (!load_plugins())
+ if (!load_plugins(plugindirs, plugins))
{
library_deinit();
return NULL;
suites = array_create(0, 0);
- for (i = 0; i < countof(constructors); i++)
+ for (i = 0; configs[i].suite; i++)
{
- if (constructors[i].feature.type == 0 ||
- lib->plugins->has_feature(lib->plugins, constructors[i].feature))
+ if (configs[i].feature.type == 0 ||
+ lib->plugins->has_feature(lib->plugins, configs[i].feature))
{
- array_insert(suites, -1, constructors[i].suite());
+ array_insert(suites, -1, configs[i].suite());
}
}
/**
* Test initialization, initializes libstrongswan for the next run
*/
-static bool pre_test()
+static bool pre_test(char *plugindirs[], char *plugins)
{
library_init(NULL);
lib->leak_detective->set_report_cb(lib->leak_detective,
NULL, NULL, NULL);
}
- if (!load_plugins())
+ if (!load_plugins(plugindirs, plugins))
{
library_deinit();
return FALSE;
/**
* Run a single test case with fixtures
*/
-static bool run_case(test_case_t *tcase)
+static bool run_case(test_case_t *tcase, char *plugindirs[], char *plugins)
{
enumerator_t *enumerator;
test_function_t *tfun;
for (i = tfun->start; i < tfun->end; i++)
{
- if (pre_test())
+ if (pre_test(plugindirs, plugins))
{
bool ok = FALSE, leaks = FALSE;
/**
* Run a single test suite
*/
-static bool run_suite(test_suite_t *suite)
+static bool run_suite(test_suite_t *suite, char *plugindirs[], char *plugins)
{
enumerator_t *enumerator;
test_case_t *tcase;
enumerator = array_create_enumerator(suite->tcases);
while (enumerator->enumerate(enumerator, &tcase))
{
- if (run_case(tcase))
+ if (run_case(tcase, plugindirs, plugins))
{
passed++;
}
return FALSE;
}
-int main(int argc, char *argv[])
+/**
+ * See header.
+ */
+int test_runner_run(test_configuration_t configs[],
+ char *plugindirs[], char *plugins)
{
array_t *suites;
test_suite_t *suite;
/* redirect all output to stderr (to redirect make's stdout to /dev/null) */
dup2(2, 1);
- suites = load_suites();
+ suites = load_suites(configs, plugindirs, plugins);
if (!suites)
{
return EXIT_FAILURE;
enumerator = array_create_enumerator(suites);
while (enumerator->enumerate(enumerator, &suite))
{
- if (run_suite(suite))
+ if (run_suite(suite, plugindirs, plugins))
{
passed++;
}
/*
- * Copyright (C) 2013 Tobias Brunner
- * Hochschule fuer Technik Rapperswil
+ * Copyright (C) 2013 Martin Willi
+ * Copyright (C) 2013 revosec AG
*
* 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
* for more details.
*/
-TEST_SUITE(bio_reader_suite_create)
-TEST_SUITE(bio_writer_suite_create)
-TEST_SUITE(chunk_suite_create)
-TEST_SUITE(enum_suite_create)
-TEST_SUITE(enumerator_suite_create)
-TEST_SUITE(linked_list_suite_create)
-TEST_SUITE(linked_list_enumerator_suite_create)
-TEST_SUITE(hashtable_suite_create)
-TEST_SUITE(array_suite_create)
-TEST_SUITE(identification_suite_create)
-TEST_SUITE(threading_suite_create)
-TEST_SUITE(watcher_suite_create)
-TEST_SUITE(stream_suite_create)
-TEST_SUITE(utils_suite_create)
-TEST_SUITE(vectors_suite_create)
-TEST_SUITE_DEPEND(ecdsa_suite_create, PRIVKEY_GEN, KEY_ECDSA)
-TEST_SUITE_DEPEND(rsa_suite_create, PRIVKEY_GEN, KEY_RSA)
-TEST_SUITE(host_suite_create)
-TEST_SUITE(printf_suite_create)
-TEST_SUITE(pen_suite_create)
-TEST_SUITE(asn1_suite_create)
+#include "test_suite.h"
+
+#include <plugins/plugin_feature.h>
+
+typedef struct test_configuration_t test_configuration_t;
+
+/**
+ * Test configuration, suite constructor with plugin dependency
+ */
+struct test_configuration_t {
+
+ /**
+ * Constructor function to create suite.
+ */
+ test_suite_t *(*suite)();
+
+ /**
+ * Plugin feature this test suite depends on
+ */
+ plugin_feature_t feature;
+};
+
+/**
+ * Run test configuration, loading plugins from plugin base directory.
+ *
+ * Both the configs and the plugindirs array must be terminated with a NULL
+ * element.
+ *
+ * @param configs test suite constructors with dependencies
+ * @param plugindirs base directories containing plugin directories to load
+ * @param plugins plugin names to load, space separated
+ * @return test result, EXIT_SUCCESS if all tests passed
+ */
+int test_runner_run(test_configuration_t config[],
+ char *plugindirs[], char *plugins);
--- /dev/null
+/*
+ * Copyright (C) 2013 Martin Willi
+ * Copyright (C) 2013 revosec AG
+ *
+ * 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>
+
+/* declare test suite constructors */
+#define TEST_SUITE(x) test_suite_t* x();
+#define TEST_SUITE_DEPEND(x, ...) TEST_SUITE(x)
+#include "tests.h"
+#undef TEST_SUITE
+#undef TEST_SUITE_DEPEND
+
+static test_configuration_t tests[] = {
+#define TEST_SUITE(x) \
+ { .suite = x, },
+#define TEST_SUITE_DEPEND(x, type, args) \
+ { .suite = x, .feature = PLUGIN_DEPENDS(type, args) },
+#include "tests.h"
+ { .suite = NULL, }
+};
+
+static char *plugindirs[] = {
+ PLUGINDIR,
+ NULL,
+};
+
+int main(int argc, char *argv[])
+{
+ return test_runner_run(tests, plugindirs, PLUGINS);
+}
--- /dev/null
+/*
+ * 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.
+ */
+
+TEST_SUITE(bio_reader_suite_create)
+TEST_SUITE(bio_writer_suite_create)
+TEST_SUITE(chunk_suite_create)
+TEST_SUITE(enum_suite_create)
+TEST_SUITE(enumerator_suite_create)
+TEST_SUITE(linked_list_suite_create)
+TEST_SUITE(linked_list_enumerator_suite_create)
+TEST_SUITE(hashtable_suite_create)
+TEST_SUITE(array_suite_create)
+TEST_SUITE(identification_suite_create)
+TEST_SUITE(threading_suite_create)
+TEST_SUITE(watcher_suite_create)
+TEST_SUITE(stream_suite_create)
+TEST_SUITE(utils_suite_create)
+TEST_SUITE(vectors_suite_create)
+TEST_SUITE_DEPEND(ecdsa_suite_create, PRIVKEY_GEN, KEY_ECDSA)
+TEST_SUITE_DEPEND(rsa_suite_create, PRIVKEY_GEN, KEY_RSA)
+TEST_SUITE(host_suite_create)
+TEST_SUITE(printf_suite_create)
+TEST_SUITE(pen_suite_create)
+TEST_SUITE(asn1_suite_create)