Test Framework Crash in release mode only
-
Description:
Test project using QT test framework has persistent crash in release mode only. Running in debug never throws the exception. Changing the order of the tests can sometimes make it seem to go away but then it will start happening again. At this point I am fairly convinced it has not one thing to do with the code my tests are testing. I can run the tests back to back to back also and have it occur sometimes and not occur other times.Setup:
We have a large number of classes that inherit from QObject and define private slots for the tests. We used to use initTestCase()/cleanupTestCase() but I moved all of the init/destroy to ctor/dtor as part of my attempts to debug/fix this very issue.int main(int argc, char argv[])
{
QCoreApplication app(argc, argv);
QList<QObject> tests = QList<QObject*>
{
new testA(),
new testB(),
...
};int summary = 0; foreach (QObject* test, tests) { summary += QTest::qExec(test); app.processEvents(); QThread::msleep(100); delete test; app.processEvents(); QThread::msleep(100); } return -summary;}
One thing that is odd is the exception seems to bubble up from cleanupTestCase() (see below), but none of my test
classes even define that slot. Does QObject define those slots virtually and provide a default implementation if I don't define them in my test class?********* Start testing of CotTests *********
Config: Using QtTest library 6.5.3, Qt 6.5.3 (x86_64-little_endian-llp64 shared
(dynamic) release build; by MSVC 2019), windows 11PASS : CotTests::initTestCase()
PASS : CotTests::test_ProtocolBasic()
PASS : CotTests::test_CotManager()
PASS : CotTests::cleanupTestCase()
A crash occurred in C:\Source\Trakka\GIT\8-0101-0001\MapQt\MapQtTest\build\Deskt
top_Qt_6_5_3_MSVC2019_64bit-Release\release\MapQtTest.exe.
Function time: 3ms Total time: 502msException address: 0x00007FF69E0406C3
Exception code : 0xc0000005
Totals: 4 passed, 0 failed, 0 skipped, 0 blacklisted, 503ms
********* Finished testing of CotTests *********
********* Start testing of Gdl90Tests *********
Config: Using QtTest library 6.5.3, Qt 6.5.3 (x86_64-little_endian-llp64 shared
(dynamic) release build; by MSVC 2019), windows 11PASS : Gdl90Tests::initTestCase()
PASS : Gdl90Tests::test_HeartbeatChecksum()
PASS : Gdl90Tests::test_ParseTrafficReport()
PASS : Gdl90Tests::test_AdsbManager()
PASS : Gdl90Tests::cleanupTestCase()
Totals: 5 passed, 0 failed, 0 skipped, 0 blacklisted, 5ms
********* Finished testing of Gdl90Tests *********The rest of the exception stack trace is displayed at the end of my test output (see below) but it will pre-empt any tests still running and cause them to not finish (when this occurs).
Stack:
1: QTest::toString() - 0x00007FFC58839620
2: UnhandledExceptionFilter() - 0x00007FFC83B2B030
3: RtlCopyMemory() - 0x00007FFC86696C40
4: _C_specific_handler() - 0x00007FFC8667F5F0
5: _chkstk() - 0x00007FFC86695050
6: RtlFindCharInUnicodeString() - 0x00007FFC8660DDC0
7: KiUserExceptionDispatcher() - 0x00007FFC86694140
8: Unable to obtain symbol
9: Unable to obtain symbol
10: QMetaCallEvent::placeMetaCall() - 0x00007FFBEBCCE540
11: QObject::event() - 0x00007FFBEBCCC7F0
12: QQuickItem::event() - 0x00007FFBF771EB20
PASS : StreetInfoProviderTests::test_easyRoadCase05()
13: QCoreApplication::notify() - 0x00007FFBEBC89FC0
PASS : StreetInfoProviderTests::cleanupTestCase()
14: QCoreApplication::notifyInternal2() - 0x00007FFBEBC8A030
15: QCoreApplicationPrivate::sendPostedEvents() - 0x00007FFBEBC8C720
16: QEventDispatcherWin32::processEvents() - 0x00007FFBEBDEA2D0
17: QEventLoop::exec() - 0x00007FFBEBC8F920
18: QThread::exec() - 0x00007FFBEBD6E800
19: QThread::start() - 0x00007FFBEBDF0470
20: BaseThreadInitThunk() - 0x00007FFC85252560
21: RtlUserThreadStart() - 0x00007FFC8664AEE0
qtc.process_stub: Inferior error: QProcess::Crashed "Process crashed"
Terminal process exited with code -1073741819
-
I would say again a problem of mixing debug and release libraries here again.
In your case Qt release libs and msvcrt debug libraries. You somewhere convert a std::string to a QString.
Fix your project to only link against the appropriate debug/release libs.
You can use 'dependencies-gui' to check if my assumption is correct. Or run the app in a debugger and see what dlls are loaded.