What is the proper way to run CommandLineTestRunner::RunAllTests() multiple times

75 views
Skip to first unread message

Forrest Stanley

unread,
Jul 7, 2022, 12:18:07 AM7/7/22
to cpputest
I am running cpputest on an embedded device. Created a menu to selectively run tests based on input. The problem I'm running into is that the first time I run CommandLineTestRunner::RunAllTests(), everything works. The second time I run it, memory, all the memory overload tests fail. It seems like there is something not getting free'd after running CommandLineTestRunner::RunAllTests the first time

I verified this on my PC, and got the same results. Running the CppUTests included in the repo, i am getting failures the second time I run RunAllTests.

Here's what the failing main() looks like (that I created just to verify the issue). (I pulled this main.cpp from the cpputest\examples\AllTests\AllTests.cpp file.

int main(int ac, char** av)
{
MyDummyComparator dummyComparator;
MockSupportPlugin mockPlugin;
IEEE754ExceptionsPlugin ieee754Plugin;

mockPlugin.installComparator("MyDummyType", dummyComparator);
TestRegistry::getCurrentRegistry()->installPlugin(&mockPlugin);
TestRegistry::getCurrentRegistry()->installPlugin(&ieee754Plugin);
printf("Running\r\n");
int r = CommandLineTestRunner::RunAllTests(ac, av);
Sleep(1000 * 5);
printf("Running Again\r\n");
r = CommandLineTestRunner::RunAllTests(ac, av);

return r;
}

What should I do or clear to run the tests a second time?

Forrest Stanley

unread,
Jul 7, 2022, 3:07:03 PM7/7/22
to cpputest
I managed to get this working by creating the CommandLineTestRunner object and running it, like so:

printf("Running\r\n");
{
CommandLineTestRunner commandLineTestRunner(ac, av, TestRegistry::getCurrentRegistry());
r = commandLineTestRunner.runAllTestsMain();
}
Sleep(1000 * 5);
printf("Running Again\r\n");
{
CommandLineTestRunner commandLineTestRunner(ac, av, TestRegistry::getCurrentRegistry());
r = commandLineTestRunner.runAllTestsMain();
}


I can just throw that in my loop on the actual device. Unless there is a better way to clear the object called when CommandLineTestRunner::RunAllTests(ac, av) is used?

Bas Vodde

unread,
Jul 8, 2022, 3:33:09 AM7/8/22
to cppu...@googlegroups.com

Hi,

I think that is a good solution. When creating two CommandLineTestRunners then the behavior is somewhat unpredictable as the constructor is called of the second before the destructor of the first.

It might be fixable, though this situation is rather uncommon.

Thanks,

Bas

--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cpputest/df9a0d8d-636c-4432-9398-5007dec3e6f0n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages