From 0a416910c4aa437a455827c52eeeee0d4e3e26ca Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 10 Sep 2014 17:12:16 +0200 Subject: [PATCH] Improved speed of testrunner: Avoid repeated loading of the same library --- lib/settings.h | 7 +++++++ test/testio.cpp | 31 ++++++------------------------- test/testmemleak.cpp | 14 +++++--------- 3 files changed, 18 insertions(+), 34 deletions(-) diff --git a/lib/settings.h b/lib/settings.h index 65a7ff796..91de260e4 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -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 }; diff --git a/test/testio.cpp b/test/testio.cpp index 5204c9ed8..97a36492c 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -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" diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 21802140c..8c7060dc1 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -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 callstack; callstack.push_back(0); CheckMemoryLeak::AllocType allocType, deallocType;