unit-tests: Use some include magic to define test suite constructors
Avoid editing of several files when creating test suites by using a single header file to define test suite constructor functions.
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
* for more details.
|
* for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "test_runner.h"
|
#include "test_suite.h"
|
||||||
|
|
||||||
#include <library.h>
|
#include <library.h>
|
||||||
#include <plugins/plugin_feature.h>
|
#include <plugins/plugin_feature.h>
|
||||||
@@ -51,17 +51,12 @@ static bool load_plugins()
|
|||||||
return lib->plugins->load(lib->plugins, PLUGINS);
|
return lib->plugins->load(lib->plugins, PLUGINS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* declare test suite constructors */
|
||||||
* Check if a specific feature is available, return falg if so
|
#define TEST_SUITE(x) test_suite_t* x();
|
||||||
*/
|
#define TEST_SUITE_DEPEND(x, ...) TEST_SUITE(x)
|
||||||
static int check_feature(plugin_feature_t feature, int flag)
|
#include "test_runner.h"
|
||||||
{
|
#undef TEST_SUITE
|
||||||
if (lib->plugins->has_feature(lib->plugins, feature))
|
#undef TEST_SUITE_DEPEND
|
||||||
{
|
|
||||||
return flag;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load all available test suites
|
* Load all available test suites
|
||||||
@@ -69,10 +64,18 @@ static int check_feature(plugin_feature_t feature, int flag)
|
|||||||
static array_t *load_suites()
|
static array_t *load_suites()
|
||||||
{
|
{
|
||||||
array_t *suites;
|
array_t *suites;
|
||||||
enum {
|
struct {
|
||||||
OTEST_RSA = (1<<0),
|
test_suite_t *(*suite)();
|
||||||
OTEST_ECDSA = (1<<1),
|
plugin_feature_t feature;
|
||||||
} otest = 0;
|
} 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;
|
||||||
|
|
||||||
library_init(NULL);
|
library_init(NULL);
|
||||||
|
|
||||||
@@ -85,43 +88,29 @@ static array_t *load_suites()
|
|||||||
}
|
}
|
||||||
lib->plugins->status(lib->plugins, LEVEL_CTRL);
|
lib->plugins->status(lib->plugins, LEVEL_CTRL);
|
||||||
|
|
||||||
/* we have to build the test suite array without leak detective, so
|
if (lib->leak_detective)
|
||||||
* separate plugin checks and suite creation */
|
{
|
||||||
otest |= check_feature(PLUGIN_DEPENDS(PRIVKEY_GEN, KEY_RSA), OTEST_RSA);
|
old = lib->leak_detective->set_state(lib->leak_detective, FALSE);
|
||||||
otest |= check_feature(PLUGIN_DEPENDS(PRIVKEY_GEN, KEY_ECDSA), OTEST_ECDSA);
|
}
|
||||||
|
|
||||||
library_deinit();
|
|
||||||
|
|
||||||
suites = array_create(0, 0);
|
suites = array_create(0, 0);
|
||||||
|
|
||||||
array_insert(suites, -1, bio_reader_suite_create());
|
for (i = 0; i < countof(constructors); i++)
|
||||||
array_insert(suites, -1, bio_writer_suite_create());
|
|
||||||
array_insert(suites, -1, chunk_suite_create());
|
|
||||||
array_insert(suites, -1, enum_suite_create());
|
|
||||||
array_insert(suites, -1, enumerator_suite_create());
|
|
||||||
array_insert(suites, -1, linked_list_suite_create());
|
|
||||||
array_insert(suites, -1, linked_list_enumerator_suite_create());
|
|
||||||
array_insert(suites, -1, hashtable_suite_create());
|
|
||||||
array_insert(suites, -1, array_suite_create());
|
|
||||||
array_insert(suites, -1, identification_suite_create());
|
|
||||||
array_insert(suites, -1, threading_suite_create());
|
|
||||||
array_insert(suites, -1, watcher_suite_create());
|
|
||||||
array_insert(suites, -1, stream_suite_create());
|
|
||||||
array_insert(suites, -1, utils_suite_create());
|
|
||||||
array_insert(suites, -1, host_suite_create());
|
|
||||||
array_insert(suites, -1, vectors_suite_create());
|
|
||||||
array_insert(suites, -1, pen_suite_create());
|
|
||||||
array_insert(suites, -1, asn1_suite_create());
|
|
||||||
array_insert(suites, -1, printf_suite_create());
|
|
||||||
if (otest & OTEST_RSA)
|
|
||||||
{
|
{
|
||||||
array_insert(suites, -1, rsa_suite_create());
|
if (constructors[i].feature.type == 0 ||
|
||||||
|
lib->plugins->has_feature(lib->plugins, constructors[i].feature))
|
||||||
|
{
|
||||||
|
array_insert(suites, -1, constructors[i].suite());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (otest & OTEST_ECDSA)
|
|
||||||
|
if (lib->leak_detective)
|
||||||
{
|
{
|
||||||
array_insert(suites, -1, ecdsa_suite_create());
|
lib->leak_detective->set_state(lib->leak_detective, old);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
library_deinit();
|
||||||
|
|
||||||
return suites;
|
return suites;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,31 +13,24 @@
|
|||||||
* for more details.
|
* for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TEST_RUNNER_H_
|
TEST_SUITE(bio_reader_suite_create)
|
||||||
#define TEST_RUNNER_H_
|
TEST_SUITE(bio_writer_suite_create)
|
||||||
|
TEST_SUITE(chunk_suite_create)
|
||||||
#include <test_suite.h>
|
TEST_SUITE(enum_suite_create)
|
||||||
|
TEST_SUITE(enumerator_suite_create)
|
||||||
Suite *bio_reader_suite_create();
|
TEST_SUITE(linked_list_suite_create)
|
||||||
Suite *bio_writer_suite_create();
|
TEST_SUITE(linked_list_enumerator_suite_create)
|
||||||
Suite *chunk_suite_create();
|
TEST_SUITE(hashtable_suite_create)
|
||||||
Suite *enum_suite_create();
|
TEST_SUITE(array_suite_create)
|
||||||
Suite *enumerator_suite_create();
|
TEST_SUITE(identification_suite_create)
|
||||||
Suite *linked_list_suite_create();
|
TEST_SUITE(threading_suite_create)
|
||||||
Suite *linked_list_enumerator_suite_create();
|
TEST_SUITE(watcher_suite_create)
|
||||||
Suite *hashtable_suite_create();
|
TEST_SUITE(stream_suite_create)
|
||||||
Suite *array_suite_create();
|
TEST_SUITE(utils_suite_create)
|
||||||
Suite *identification_suite_create();
|
TEST_SUITE(vectors_suite_create)
|
||||||
Suite *threading_suite_create();
|
TEST_SUITE_DEPEND(ecdsa_suite_create, PRIVKEY_GEN, KEY_ECDSA)
|
||||||
Suite *watcher_suite_create();
|
TEST_SUITE_DEPEND(rsa_suite_create, PRIVKEY_GEN, KEY_RSA)
|
||||||
Suite *stream_suite_create();
|
TEST_SUITE(host_suite_create)
|
||||||
Suite *utils_suite_create();
|
TEST_SUITE(printf_suite_create)
|
||||||
Suite *vectors_suite_create();
|
TEST_SUITE(pen_suite_create)
|
||||||
Suite *ecdsa_suite_create();
|
TEST_SUITE(asn1_suite_create)
|
||||||
Suite *rsa_suite_create();
|
|
||||||
Suite *host_suite_create();
|
|
||||||
Suite *printf_suite_create();
|
|
||||||
Suite *pen_suite_create();
|
|
||||||
Suite *asn1_suite_create();
|
|
||||||
|
|
||||||
#endif /** TEST_RUNNER_H_ */
|
|
||||||
|
|||||||
Reference in New Issue
Block a user