unit-tests: load plugins in test-runner from build directory
authorMartin Willi <martin@revosec.ch>
Thu, 20 Jun 2013 07:34:18 +0000 (09:34 +0200)
committerMartin Willi <martin@revosec.ch>
Fri, 21 Jun 2013 08:53:23 +0000 (10:53 +0200)
src/libstrongswan/tests/Makefile.am
src/libstrongswan/tests/test_runner.c

index 44d797e..ca0a8c1 100644 (file)
@@ -11,6 +11,7 @@ test_runner_SOURCES = \
 
 test_runner_CFLAGS = \
   -I$(top_srcdir)/src/libstrongswan \
+  -DPLUGINDIR=\""$(top_builddir)/src/libstrongswan/plugins\"" \
   -DPLUGINS=\""${s_plugins}\"" \
   @COVERAGE_CFLAGS@ \
   @CHECK_CFLAGS@
index a30b106..c80f9fc 100644 (file)
 #include <library.h>
 #include <plugins/plugin_feature.h>
 
+#include <dirent.h>
+
+/**
+ * Load plugins from builddir
+ */
+static bool load_plugins()
+{
+       enumerator_t *enumerator;
+       char *name, path[PATH_MAX], dir[64];
+       bool success = TRUE;
+
+       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);
+               if (!lib->plugins->load(lib->plugins, path, name))
+               {
+                       success = FALSE;
+                       break;
+               }
+       }
+       enumerator->destroy(enumerator);
+
+       return success;
+}
+
 int main()
 {
        SRunner *sr;
@@ -39,7 +67,7 @@ int main()
                        lib->settings->get_str(lib->settings,
                                "libstrongswan.plugins.random.urandom", "/dev/urandom"));
 
-       if (!lib->plugins->load(lib->plugins, NULL, PLUGINS))
+       if (!load_plugins())
        {
                library_deinit();
                return EXIT_FAILURE;