Avoid loading libraries multiple times in test suite

-> Massive speedup for test suite (especially on slow systems)
This commit is contained in:
PKEuS 2014-03-24 09:59:05 +01:00
parent aa05bf0f16
commit 9b4b90f6a0
6 changed files with 41 additions and 45 deletions

View File

@ -125,16 +125,14 @@ public:
}
private:
Settings settings1;
void check(const char code[], const Settings *settings = nullptr) {
// Clear the error buffer..
errout.str("");
Settings settings1;
if (!settings) {
LOAD_LIB("gtk.cfg");
settings1.library = _lib;
if (!settings)
settings = &settings1;
}
// Tokenize..
Tokenizer tokenizer(settings, this);
@ -150,6 +148,8 @@ private:
void run() {
LOAD_LIB_2(settings1.library, "gtk.cfg");
// Check that getcode works correctly..
TEST_CASE(testgetcode);
@ -4241,9 +4241,8 @@ private:
// Test that posix.cfg is configured correctly
void posixcfg() {
LOAD_LIB("posix.cfg");
Settings settings;
settings.library = _lib;
LOAD_LIB_2(settings.library, "posix.cfg");
const char code[] = "void leaks() {\n"
" void* leak1 = fdopendir();\n"
@ -4255,17 +4254,19 @@ private:
" void *p2 = opendir(); closedir(p2);\n"
" void *p3 = socket(); close(p3);\n"
"}";
check(code,&settings);
check(code, &settings);
ASSERT_EQUALS("[test.cpp:5]: (error) Resource leak: leak1\n"
"[test.cpp:5]: (error) Resource leak: leak2\n"
"[test.cpp:5]: (error) Resource leak: leak3\n", errout.str());
LOAD_LIB_2(settings.library, "gtk.cfg");
check("void f(char *a) {\n"
" char *s = g_strdup(a);\n"
" mkstemp(s);\n"
" mkdtemp(s);\n"
" mktemp(s);\n"
"}");
"}", &settings);
ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: s\n", errout.str());
}
};
@ -6115,26 +6116,12 @@ public:
}
private:
Settings settings;
void check(const char code[]) {
// Clear the error buffer..
errout.str("");
Settings settings;
settings.standards.posix = true;
LOAD_LIB("gtk.cfg");
settings.library = _lib;
// Add some test allocation functions to the library.
// When not run as a unit test, these are read from
// an XML file (e.g. cfg/posix.cfg).
int id = 0;
while (!settings.library.ismemory(++id))
continue;
settings.library.setalloc("malloc", id);
settings.library.setalloc("calloc", id);
settings.library.setalloc("strdup", id);
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
@ -6147,6 +6134,21 @@ private:
}
void run() {
settings.standards.posix = true;
LOAD_LIB_2(settings.library, "gtk.cfg");
// Add some test allocation functions to the library.
// When not run as a unit test, these are read from
// an XML file (e.g. cfg/posix.cfg).
int id = 0;
while (!settings.library.ismemory(++id))
continue;
settings.library.setalloc("malloc", id);
settings.library.setalloc("calloc", id);
settings.library.setalloc("strdup", id);
// pass allocated memory to function..
TEST_CASE(functionParameter);
// never use leakable resource
@ -6304,14 +6306,12 @@ public:
}
private:
Settings settings;
void check(const char code[]) {
// Clear the error buffer..
errout.str("");
Settings settings;
LOAD_LIB("gtk.cfg");
settings.library = _lib;
// Preprocess...
Preprocessor preprocessor(&settings, this);
std::istringstream istrpreproc(code);
@ -6331,6 +6331,8 @@ private:
}
void run() {
LOAD_LIB_2(settings.library, "gtk.cfg");
TEST_CASE(glib1);
}

View File

@ -29,9 +29,11 @@ public:
}
private:
Settings settings;
void run() {
LOAD_LIB_2(settings.library, "std.cfg");
TEST_CASE(nullpointerAfterLoop);
TEST_CASE(nullpointer1);
TEST_CASE(nullpointer2);
@ -86,12 +88,8 @@ private:
// Clear the error buffer..
errout.str("");
Settings settings;
settings.addEnabled("warning");
settings.inconclusive = inconclusive;
_lib = Library();
LOAD_LIB("std.cfg");
settings.library = _lib;
// Tokenize..
Tokenizer tokenizer(&settings, this);

View File

@ -4874,9 +4874,8 @@ private:
ASSERT_EQUALS("", errout.str());
{
LOAD_LIB("std.cfg");
Settings settings;
settings.library = _lib;
LOAD_LIB_2(settings.library, "std.cfg");
check("void foo() {\n"
" if ((strcmp(a, b) == 0) || (strcmp(a, b) == 0)) {}\n"
"}", "test.cpp", false, false, false, true, &settings);

View File

@ -85,10 +85,10 @@ public:
#define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance; }
#ifdef _WIN32
#define REQUIRE_LIB( NAME ) { if (!_lib.load("./testrunner", "../cfg/" NAME) && !_lib.load("./testrunner", "cfg/" NAME)) { complainMissingLib(NAME); return; } }
#define LOAD_LIB_2( LIB, NAME ) { if (!(LIB).load("./testrunner", "../cfg/" NAME) && !(LIB).load("./testrunner", "cfg/" NAME)) { complainMissingLib(NAME); return; } }
#else
#define REQUIRE_LIB( NAME ) { if (!_lib.load("./testrunner", "cfg/" NAME)) { complainMissingLib(NAME); return; } }
#define LOAD_LIB_2( LIB, NAME ) { if (!(LIB).load("./testrunner", "cfg/" NAME)) { complainMissingLib(NAME); return; } }
#endif
#define LOAD_LIB( NAME ) { REQUIRE_LIB(NAME); }
#define LOAD_LIB( NAME ) { LOAD_LIB_2(_lib, NAME); }
#endif

View File

@ -1840,7 +1840,6 @@ private:
//ASSERT(db && db->findScopeByName("InfiniteA") && !db->findScopeByName("InfiniteA")->functionList.front().isImplicitlyVirtual());
TODO_ASSERT_EQUALS(1, 0, db->findScopeByName("InfiniteA")->functionList.size());
}
}
void garbage() {

View File

@ -29,9 +29,11 @@ public:
}
private:
Settings settings;
void run() {
LOAD_LIB_2(settings.library, "std.cfg");
TEST_CASE(uninitvar1);
TEST_CASE(uninitvar_bitop); // using uninitialized operand in bit operation
TEST_CASE(uninitvar_alloc); // data is allocated but not initialized
@ -76,10 +78,6 @@ private:
// Clear the error buffer..
errout.str("");
Settings settings;
LOAD_LIB("std.cfg");
settings.library = _lib;
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);