Skip to content

Commit 0a41691

Browse files
committed
Improved speed of testrunner: Avoid repeated loading of the same library
1 parent 3fade4d commit 0a41691

File tree

3 files changed

+18
-34
lines changed

3 files changed

+18
-34
lines changed

lib/settings.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ class CPPCHECKLIB Settings {
165165
*/
166166
std::string addEnabled(const std::string &str);
167167

168+
/**
169+
* @brief Disables all severities, except from error.
170+
*/
171+
void clearEnabled() {
172+
_enabled.clear();
173+
}
174+
168175
enum Language {
169176
None, C, CPP
170177
};

test/testio.cpp

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ class TestIO : public TestFixture {
2929
}
3030

3131
private:
32+
Settings settings;
3233

3334
void run() {
35+
LOAD_LIB_2(settings.library, "std.cfg");
36+
3437
TEST_CASE(coutCerrMisusage);
3538

3639
TEST_CASE(wrongMode_simple);
@@ -49,6 +52,8 @@ class TestIO : public TestFixture {
4952
TEST_CASE(testPrintfArgument);
5053
TEST_CASE(testPosixPrintfScanfParameterPosition); // #4900
5154

55+
LOAD_LIB_2(settings.library, "windows.cfg");
56+
5257
TEST_CASE(testMicrosoftPrintfArgument); // ticket #4902
5358
TEST_CASE(testMicrosoftScanfArgument);
5459
TEST_CASE(testMicrosoftCStringFormatArguments); // ticket #4920
@@ -60,16 +65,14 @@ class TestIO : public TestFixture {
6065
// Clear the error buffer..
6166
errout.str("");
6267

63-
Settings settings;
68+
settings.clearEnabled();
6469
settings.addEnabled("warning");
6570
settings.addEnabled("style");
6671
if (portability)
6772
settings.addEnabled("portability");
6873
settings.inconclusive = inconclusive;
6974
settings.platform(platform);
7075

71-
settings.library = _lib;
72-
7376
// Tokenize..
7477
Tokenizer tokenizer(&settings, this);
7578
std::istringstream istr(code);
@@ -612,8 +615,6 @@ class TestIO : public TestFixture {
612615

613616

614617
void testScanf1() {
615-
LOAD_LIB("std.cfg");
616-
617618
check("void foo() {\n"
618619
" int a, b;\n"
619620
" FILE *file = fopen(\"test\", \"r\");\n"
@@ -632,8 +633,6 @@ class TestIO : public TestFixture {
632633
}
633634

634635
void testScanf2() {
635-
LOAD_LIB("std.cfg");
636-
637636
check("void foo() {\n"
638637
" scanf(\"%5s\", bar);\n" // Width specifier given
639638
" scanf(\"%5[^~]\", bar);\n" // Width specifier given
@@ -660,8 +659,6 @@ class TestIO : public TestFixture {
660659
}
661660

662661
void testScanf4() { // ticket #2553
663-
LOAD_LIB("std.cfg");
664-
665662
check("void f()\n"
666663
"{\n"
667664
" char str [8];\n"
@@ -674,8 +671,6 @@ class TestIO : public TestFixture {
674671

675672

676673
void testScanfArgument() {
677-
LOAD_LIB("std.cfg");
678-
679674
check("void foo() {\n"
680675
" scanf(\"%1d\", &foo);\n"
681676
" sscanf(bar, \"%1d\", &foo);\n"
@@ -2276,7 +2271,6 @@ class TestIO : public TestFixture {
22762271
}
22772272

22782273
void testPrintfArgument() {
2279-
LOAD_LIB("std.cfg");
22802274
check("void foo() {\n"
22812275
" printf(\"%u\");\n"
22822276
" printf(\"%u%s\", 123);\n"
@@ -3108,8 +3102,6 @@ class TestIO : public TestFixture {
31083102
}
31093103

31103104
void testPosixPrintfScanfParameterPosition() { // #4900 - No support for parameters in format strings
3111-
LOAD_LIB("std.cfg");
3112-
31133105
check("void foo() {"
31143106
" int bar;"
31153107
" printf(\"%1$d\", 1);"
@@ -3134,9 +3126,6 @@ class TestIO : public TestFixture {
31343126

31353127

31363128
void testMicrosoftPrintfArgument() {
3137-
LOAD_LIB("std.cfg");
3138-
LOAD_LIB("windows.cfg");
3139-
31403129
check("void foo() {\n"
31413130
" size_t s;\n"
31423131
" ptrdiff_t p;\n"
@@ -3226,9 +3215,6 @@ class TestIO : public TestFixture {
32263215
}
32273216

32283217
void testMicrosoftScanfArgument() {
3229-
LOAD_LIB("std.cfg");
3230-
LOAD_LIB("windows.cfg");
3231-
32323218
check("void foo() {\n"
32333219
" size_t s;\n"
32343220
" ptrdiff_t p;\n"
@@ -3333,9 +3319,6 @@ class TestIO : public TestFixture {
33333319
}
33343320

33353321
void testMicrosoftSecurePrintfArgument() {
3336-
LOAD_LIB("std.cfg");
3337-
LOAD_LIB("windows.cfg");
3338-
33393322
check("void foo() {\n"
33403323
" int i;\n"
33413324
" unsigned int u;\n"
@@ -3526,8 +3509,6 @@ class TestIO : public TestFixture {
35263509
}
35273510

35283511
void testMicrosoftSecureScanfArgument() {
3529-
LOAD_LIB("windows.cfg");
3530-
35313512
check("void foo() {\n"
35323513
" int i;\n"
35333514
" unsigned int u;\n"

test/testmemleak.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class TestMemleakInFunction : public TestFixture {
126126

127127
private:
128128
Settings settings1;
129+
Settings settings2;
129130

130131
void check(const char code[], const Settings *settings = nullptr) {
131132
// Clear the error buffer..
@@ -150,6 +151,7 @@ class TestMemleakInFunction : public TestFixture {
150151
void run() {
151152
LOAD_LIB_2(settings1.library, "std.cfg");
152153
LOAD_LIB_2(settings1.library, "gtk.cfg");
154+
LOAD_LIB_2(settings2.library, "std.cfg");
153155

154156
// Check that getcode works correctly..
155157
TEST_CASE(testgetcode);
@@ -367,20 +369,14 @@ class TestMemleakInFunction : public TestFixture {
367369
TEST_CASE(posixcfg);
368370
}
369371

370-
void loadlib(Library& library) {
371-
LOAD_LIB_2(library, "std.cfg");
372-
}
373-
374372
std::string getcode(const char code[], const char varname[], bool classfunc=false) {
375373
// Clear the error buffer..
376374
errout.str("");
377375

378-
Settings settings;
379-
settings.standards.posix = true;
380-
loadlib(settings.library);
376+
settings2.standards.posix = true;
381377

382378
// Tokenize..
383-
Tokenizer tokenizer(&settings, this);
379+
Tokenizer tokenizer(&settings2, this);
384380
std::istringstream istr(code);
385381
if (!tokenizer.tokenize(istr, "test.cpp"))
386382
return "";
@@ -389,7 +385,7 @@ class TestMemleakInFunction : public TestFixture {
389385
const unsigned int varId(Token::findmatch(tokenizer.tokens(), varname)->varId());
390386

391387
// getcode..
392-
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, nullptr);
388+
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings2, nullptr);
393389
std::list<const Token *> callstack;
394390
callstack.push_back(0);
395391
CheckMemoryLeak::AllocType allocType, deallocType;

0 commit comments

Comments
 (0)