From fb35756126b6ed2485fdffb6ed65e620ca2a38f1 Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Thu, 31 Dec 2020 09:34:53 +0100 Subject: [PATCH] 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. --- test/CMakeLists.txt | 2 +- test/testleakautovar.cpp | 108 ++++++++++++++++++++++----------------- 2 files changed, 62 insertions(+), 48 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7f475534e..88f3a9291 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -172,7 +172,7 @@ if (BUILD_TESTS) fixture_cost(TestIO 20) fixture_cost(cfg-std_c 8) fixture_cost(TestThreadExecutor 5) - fixture_cost(TestLeakAutoVar 4) + fixture_cost(TestLeakAutoVarRecursiveCountLimit 4) fixture_cost(TestTokenizer 4) endif() endif() diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 4c375deae..272b783db 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -188,8 +188,6 @@ private: TEST_CASE(smartPtrInContainer); // #8262 - TEST_CASE(recursiveCountLimit); // #5872 #6157 #9097 - TEST_CASE(functionCallCastConfig); // #9652 } @@ -225,32 +223,6 @@ private: c.runChecks(&tokenizer, &settings, this); } - void checkP(const char code[], bool cpp = false) { - // Clear the error buffer.. - errout.str(""); - - // Raw tokens.. - std::vector 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 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() { check("void f() {\n" " char *p = malloc(10);\n" @@ -2074,25 +2046,6 @@ private: 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 Settings settingsFunctionCall = settings; @@ -2122,6 +2075,67 @@ private: 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 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 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 { public: