Improved speed of testrunner: Avoid repeated loading of the same library

This commit is contained in:
PKEuS 2014-09-10 17:12:16 +02:00
parent 3fade4d28c
commit 0a416910c4
3 changed files with 18 additions and 34 deletions

View File

@ -165,6 +165,13 @@ public:
*/
std::string addEnabled(const std::string &str);
/**
* @brief Disables all severities, except from error.
*/
void clearEnabled() {
_enabled.clear();
}
enum Language {
None, C, CPP
};

View File

@ -29,8 +29,11 @@ public:
}
private:
Settings settings;
void run() {
LOAD_LIB_2(settings.library, "std.cfg");
TEST_CASE(coutCerrMisusage);
TEST_CASE(wrongMode_simple);
@ -49,6 +52,8 @@ private:
TEST_CASE(testPrintfArgument);
TEST_CASE(testPosixPrintfScanfParameterPosition); // #4900
LOAD_LIB_2(settings.library, "windows.cfg");
TEST_CASE(testMicrosoftPrintfArgument); // ticket #4902
TEST_CASE(testMicrosoftScanfArgument);
TEST_CASE(testMicrosoftCStringFormatArguments); // ticket #4920
@ -60,7 +65,7 @@ private:
// Clear the error buffer..
errout.str("");
Settings settings;
settings.clearEnabled();
settings.addEnabled("warning");
settings.addEnabled("style");
if (portability)
@ -68,8 +73,6 @@ private:
settings.inconclusive = inconclusive;
settings.platform(platform);
settings.library = _lib;
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
@ -612,8 +615,6 @@ private:
void testScanf1() {
LOAD_LIB("std.cfg");
check("void foo() {\n"
" int a, b;\n"
" FILE *file = fopen(\"test\", \"r\");\n"
@ -632,8 +633,6 @@ private:
}
void testScanf2() {
LOAD_LIB("std.cfg");
check("void foo() {\n"
" scanf(\"%5s\", bar);\n" // Width specifier given
" scanf(\"%5[^~]\", bar);\n" // Width specifier given
@ -660,8 +659,6 @@ private:
}
void testScanf4() { // ticket #2553
LOAD_LIB("std.cfg");
check("void f()\n"
"{\n"
" char str [8];\n"
@ -674,8 +671,6 @@ private:
void testScanfArgument() {
LOAD_LIB("std.cfg");
check("void foo() {\n"
" scanf(\"%1d\", &foo);\n"
" sscanf(bar, \"%1d\", &foo);\n"
@ -2276,7 +2271,6 @@ private:
}
void testPrintfArgument() {
LOAD_LIB("std.cfg");
check("void foo() {\n"
" printf(\"%u\");\n"
" printf(\"%u%s\", 123);\n"
@ -3108,8 +3102,6 @@ private:
}
void testPosixPrintfScanfParameterPosition() { // #4900 - No support for parameters in format strings
LOAD_LIB("std.cfg");
check("void foo() {"
" int bar;"
" printf(\"%1$d\", 1);"
@ -3134,9 +3126,6 @@ private:
void testMicrosoftPrintfArgument() {
LOAD_LIB("std.cfg");
LOAD_LIB("windows.cfg");
check("void foo() {\n"
" size_t s;\n"
" ptrdiff_t p;\n"
@ -3226,9 +3215,6 @@ private:
}
void testMicrosoftScanfArgument() {
LOAD_LIB("std.cfg");
LOAD_LIB("windows.cfg");
check("void foo() {\n"
" size_t s;\n"
" ptrdiff_t p;\n"
@ -3333,9 +3319,6 @@ private:
}
void testMicrosoftSecurePrintfArgument() {
LOAD_LIB("std.cfg");
LOAD_LIB("windows.cfg");
check("void foo() {\n"
" int i;\n"
" unsigned int u;\n"
@ -3526,8 +3509,6 @@ private:
}
void testMicrosoftSecureScanfArgument() {
LOAD_LIB("windows.cfg");
check("void foo() {\n"
" int i;\n"
" unsigned int u;\n"

View File

@ -126,6 +126,7 @@ public:
private:
Settings settings1;
Settings settings2;
void check(const char code[], const Settings *settings = nullptr) {
// Clear the error buffer..
@ -150,6 +151,7 @@ private:
void run() {
LOAD_LIB_2(settings1.library, "std.cfg");
LOAD_LIB_2(settings1.library, "gtk.cfg");
LOAD_LIB_2(settings2.library, "std.cfg");
// Check that getcode works correctly..
TEST_CASE(testgetcode);
@ -367,20 +369,14 @@ private:
TEST_CASE(posixcfg);
}
void loadlib(Library& library) {
LOAD_LIB_2(library, "std.cfg");
}
std::string getcode(const char code[], const char varname[], bool classfunc=false) {
// Clear the error buffer..
errout.str("");
Settings settings;
settings.standards.posix = true;
loadlib(settings.library);
settings2.standards.posix = true;
// Tokenize..
Tokenizer tokenizer(&settings, this);
Tokenizer tokenizer(&settings2, this);
std::istringstream istr(code);
if (!tokenizer.tokenize(istr, "test.cpp"))
return "";
@ -389,7 +385,7 @@ private:
const unsigned int varId(Token::findmatch(tokenizer.tokens(), varname)->varId());
// getcode..
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, nullptr);
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings2, nullptr);
std::list<const Token *> callstack;
callstack.push_back(0);
CheckMemoryLeak::AllocType allocType, deallocType;