TestLeakAutoVar: Split recursiveCountLimit test to separate class (#2995)

This test is by far the slowest one to run. Split it to a separate class
to make it easy to select if it should be run during development.
This commit is contained in:
Rikard Falkeborn 2020-12-31 09:34:53 +01:00 committed by GitHub
parent e7bdf5f71c
commit fb35756126
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 48 deletions

View File

@ -172,7 +172,7 @@ if (BUILD_TESTS)
fixture_cost(TestIO 20) fixture_cost(TestIO 20)
fixture_cost(cfg-std_c 8) fixture_cost(cfg-std_c 8)
fixture_cost(TestThreadExecutor 5) fixture_cost(TestThreadExecutor 5)
fixture_cost(TestLeakAutoVar 4) fixture_cost(TestLeakAutoVarRecursiveCountLimit 4)
fixture_cost(TestTokenizer 4) fixture_cost(TestTokenizer 4)
endif() endif()
endif() endif()

View File

@ -188,8 +188,6 @@ private:
TEST_CASE(smartPtrInContainer); // #8262 TEST_CASE(smartPtrInContainer); // #8262
TEST_CASE(recursiveCountLimit); // #5872 #6157 #9097
TEST_CASE(functionCallCastConfig); // #9652 TEST_CASE(functionCallCastConfig); // #9652
} }
@ -225,32 +223,6 @@ private:
c.runChecks(&tokenizer, &settings, this); c.runChecks(&tokenizer, &settings, this);
} }
void checkP(const char code[], bool cpp = false) {
// Clear the error buffer..
errout.str("");
// Raw tokens..
std::vector<std::string> files(1, cpp?"test.cpp":"test.c");
std::istringstream istr(code);
const simplecpp::TokenList tokens1(istr, files, files[0]);
// Preprocess..
simplecpp::TokenList tokens2(files);
std::map<std::string, simplecpp::TokenList*> filedata;
simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI());
// Tokenizer..
Tokenizer tokenizer(&settings, this);
tokenizer.createTokens(std::move(tokens2));
tokenizer.simplifyTokens1("");
// Check for leaks..
CheckLeakAutoVar c;
settings.checkLibrary = true;
settings.addEnabled("information");
c.runChecks(&tokenizer, &settings, this);
}
void assign1() { void assign1() {
check("void f() {\n" check("void f() {\n"
" char *p = malloc(10);\n" " char *p = malloc(10);\n"
@ -2074,25 +2046,6 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void recursiveCountLimit() { // #5872 #6157 #9097
ASSERT_THROW(checkP("#define ONE else if (0) { }\n"
"#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n"
"#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n"
"#define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN\n"
"void foo() {\n"
" if (0) { }\n"
" THOU THOU\n"
"}"), InternalError);
ASSERT_NO_THROW(checkP("#define ONE if (0) { }\n"
"#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n"
"#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n"
"#define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN\n"
"void foo() {\n"
" if (0) { }\n"
" THOU THOU\n"
"}"));
}
void functionCallCastConfig() { // #9652 void functionCallCastConfig() { // #9652
Settings settingsFunctionCall = settings; Settings settingsFunctionCall = settings;
@ -2122,6 +2075,67 @@ private:
REGISTER_TEST(TestLeakAutoVar) REGISTER_TEST(TestLeakAutoVar)
class TestLeakAutoVarRecursiveCountLimit : public TestFixture {
public:
TestLeakAutoVarRecursiveCountLimit() : TestFixture("TestLeakAutoVarRecursiveCountLimit") {
}
private:
Settings settings;
void checkP(const char code[], bool cpp = false) {
// Clear the error buffer..
errout.str("");
// Raw tokens..
std::vector<std::string> files(1, cpp?"test.cpp":"test.c");
std::istringstream istr(code);
const simplecpp::TokenList tokens1(istr, files, files[0]);
// Preprocess..
simplecpp::TokenList tokens2(files);
std::map<std::string, simplecpp::TokenList*> filedata;
simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI());
// Tokenizer..
Tokenizer tokenizer(&settings, this);
tokenizer.createTokens(std::move(tokens2));
tokenizer.simplifyTokens1("");
// Check for leaks..
CheckLeakAutoVar c;
settings.checkLibrary = true;
settings.addEnabled("information");
c.runChecks(&tokenizer, &settings, this);
}
void run() OVERRIDE {
LOAD_LIB_2(settings.library, "std.cfg");
TEST_CASE(recursiveCountLimit); // #5872 #6157 #9097
}
void recursiveCountLimit() { // #5872 #6157 #9097
ASSERT_THROW(checkP("#define ONE else if (0) { }\n"
"#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n"
"#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n"
"#define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN\n"
"void foo() {\n"
" if (0) { }\n"
" THOU THOU\n"
"}"), InternalError);
ASSERT_NO_THROW(checkP("#define ONE if (0) { }\n"
"#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n"
"#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n"
"#define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN\n"
"void foo() {\n"
" if (0) { }\n"
" THOU THOU\n"
"}"));
}
};
REGISTER_TEST(TestLeakAutoVarRecursiveCountLimit)
class TestLeakAutoVarStrcpy: public TestFixture { class TestLeakAutoVarStrcpy: public TestFixture {
public: public: