unit-tests: Add option to exclude specific test suites

Listing test suites in TESTS_SUITES_EXCLUDE allows excluding specific
test suites from running.
This commit is contained in:
Tobias Brunner
2014-09-09 10:56:14 +02:00
parent 5818467639
commit 4f71ee2cf6
2 changed files with 32 additions and 14 deletions
+31 -14
View File
@@ -58,40 +58,57 @@ 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; enumerator_t *enumerator, *names;
hashtable_t *selected; hashtable_t *listed;
test_suite_t *suite; test_suite_t *suite;
char *suites, *name; char *name;
suites = getenv("TESTS_SUITES"); listed = hashtable_create(hashtable_hash_str, hashtable_equals_str, 8);
if (!suites) names = enumerator_create_token(filter, ",", " ");
{
return;
}
selected = hashtable_create(hashtable_hash_str, hashtable_equals_str, 8);
names = enumerator_create_token(suites, ",", " ");
while (names->enumerate(names, &name)) while (names->enumerate(names, &name))
{ {
selected->put(selected, name, name); listed->put(listed, name, name);
} }
enumerator = array_create_enumerator(loaded); enumerator = array_create_enumerator(loaded);
while (enumerator->enumerate(enumerator, &suite)) 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); array_remove_at(loaded, enumerator);
destroy_suite(suite); destroy_suite(suite);
} }
} }
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
selected->destroy(selected); listed->destroy(listed);
names->destroy(names); 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. * Load all available test suites, or optionally only selected ones.
*/ */
+1
View File
@@ -70,6 +70,7 @@ struct test_configuration_t {
* - TESTS_VERBOSITY: Numerical loglevel for debug log * - TESTS_VERBOSITY: Numerical loglevel for debug log
* - TESTS_STRONGSWAN_CONF: Specify a path to a custom strongswan.conf * - TESTS_STRONGSWAN_CONF: Specify a path to a custom strongswan.conf
* - TESTS_SUITES: Run specific test suites only * - 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 * - TESTS_REDUCED_KEYLENGTHS: Test minimal keylengths for public key tests only
* *
* @param name name of test runner * @param name name of test runner