unit-tests: Add option to exclude specific test suites
authorTobias Brunner <tobias@strongswan.org>
Fri, 11 Jul 2014 08:51:31 +0000 (10:51 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 9 Sep 2014 08:56:14 +0000 (10:56 +0200)
Listing test suites in TESTS_SUITES_EXCLUDE allows excluding specific
test suites from running.

src/libstrongswan/tests/test_runner.c
src/libstrongswan/tests/test_runner.h

index 8f2e985..b773028 100644 (file)
@@ -58,41 +58,58 @@ static void destroy_suite(test_suite_t *suite)
 }
 
 /**
- * Removes and destroys test suites that are not selected.
+ * Filter loaded test suites, either remove suites listed (exclude=TRUE), or all
+ * that are not listed (exclude=FALSE).
  */
-static void filter_suites(array_t *loaded)
+static void apply_filter(array_t *loaded, char *filter, bool exclude)
 {
        enumerator_t *enumerator, *names;
-       hashtable_t *selected;
+       hashtable_t *listed;
        test_suite_t *suite;
-       char *suites, *name;
+       char *name;
 
-       suites = getenv("TESTS_SUITES");
-       if (!suites)
-       {
-               return;
-       }
-       selected = hashtable_create(hashtable_hash_str, hashtable_equals_str, 8);
-       names = enumerator_create_token(suites, ",", " ");
+       listed = hashtable_create(hashtable_hash_str, hashtable_equals_str, 8);
+       names = enumerator_create_token(filter, ",", " ");
        while (names->enumerate(names, &name))
        {
-               selected->put(selected, name, name);
+               listed->put(listed, name, name);
        }
        enumerator = array_create_enumerator(loaded);
        while (enumerator->enumerate(enumerator, &suite))
        {
-               if (!selected->get(selected, suite->name))
+               if ((exclude && listed->get(listed, suite->name)) ||
+                       (!exclude && !listed->get(listed, suite->name)))
                {
                        array_remove_at(loaded, enumerator);
                        destroy_suite(suite);
                }
        }
        enumerator->destroy(enumerator);
-       selected->destroy(selected);
+       listed->destroy(listed);
        names->destroy(names);
 }
 
 /**
+ * Removes and destroys test suites that are not selected or
+ * explicitly excluded.
+ */
+static void filter_suites(array_t *loaded)
+{
+       char *filter;
+
+       filter = getenv("TESTS_SUITES");
+       if (filter)
+       {
+               apply_filter(loaded, filter, FALSE);
+       }
+       filter = getenv("TESTS_SUITES_EXCLUDE");
+       if (filter)
+       {
+               apply_filter(loaded, filter, TRUE);
+       }
+}
+
+/**
  * Load all available test suites, or optionally only selected ones.
  */
 static array_t *load_suites(test_configuration_t configs[],
index de87a1f..7250f8a 100644 (file)
@@ -70,6 +70,7 @@ struct test_configuration_t {
  * - TESTS_VERBOSITY: Numerical loglevel for debug log
  * - TESTS_STRONGSWAN_CONF: Specify a path to a custom strongswan.conf
  * - TESTS_SUITES: Run specific test suites only
+ * - TESTS_SUITES_EXCLUDE: Don't run specific test suites
  * - TESTS_REDUCED_KEYLENGTHS: Test minimal keylengths for public key tests only
  *
  * @param name                 name of test runner