Fix valgrind tests

Change-Id: I71bd88fb5a2041aacc3fa2e0de17820ee1db6c69
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
Christian Stenger
2013-04-08 17:26:37 +02:00
parent dc0c47c7fd
commit 2cb6b27de2
13 changed files with 117 additions and 58 deletions

View File

@@ -1,6 +1,8 @@
TEMPLATE = app TEMPLATE = app
TARGET = free1 TARGET = free1
CONFIG += debug
QT -= core gui QT -= core gui
macx:CONFIG -= app_bundle macx:CONFIG -= app_bundle

View File

@@ -1,6 +1,8 @@
TEMPLATE = app TEMPLATE = app
TARGET = free2 TARGET = free2
CONFIG += debug
QT -= core gui QT -= core gui
macx:CONFIG -= app_bundle macx:CONFIG -= app_bundle

View File

@@ -1,6 +1,8 @@
TEMPLATE = app TEMPLATE = app
TARGET = invalidjump TARGET = invalidjump
CONFIG += debug
QT -= core gui QT -= core gui
macx:CONFIG -= app_bundle macx:CONFIG -= app_bundle

View File

@@ -1,6 +1,8 @@
TEMPLATE = app TEMPLATE = app
TARGET = leak1 TARGET = leak1
CONFIG += debug
QT += core QT += core
macx:CONFIG -= app_bundle macx:CONFIG -= app_bundle

View File

@@ -1,6 +1,8 @@
TEMPLATE = app TEMPLATE = app
TARGET = leak2 TARGET = leak2
CONFIG += debug
QT += core QT += core
macx:CONFIG -= app_bundle macx:CONFIG -= app_bundle

View File

@@ -1,6 +1,8 @@
TEMPLATE = app TEMPLATE = app
TARGET = leak3 TARGET = leak3
CONFIG += debug
QT += core QT += core
macx:CONFIG -= app_bundle macx:CONFIG -= app_bundle

View File

@@ -1,6 +1,8 @@
TEMPLATE = app TEMPLATE = app
TARGET = leak4 TARGET = leak4
CONFIG += debug
QT += core QT += core
macx:CONFIG -= app_bundle macx:CONFIG -= app_bundle

View File

@@ -1,6 +1,9 @@
TEMPLATE = app TEMPLATE = app
TARGET = overlap TARGET = overlap
CONFIG += debug
QMAKE_CXXFLAGS = -O0 -fno-builtin
QT -= core gui QT -= core gui
macx:CONFIG -= app_bundle macx:CONFIG -= app_bundle

View File

@@ -1,6 +1,9 @@
TEMPLATE = app TEMPLATE = app
TARGET = syscall TARGET = syscall
CONFIG += debug
QMAKE_CXXFLAGS = -O0
QT += core QT += core
macx:CONFIG -= app_bundle macx:CONFIG -= app_bundle

View File

@@ -1,6 +1,9 @@
TEMPLATE = app TEMPLATE = app
TARGET = uninit1 TARGET = uninit1
CONFIG += debug
QMAKE_CXXFLAGS = -O0
QT -= core gui QT -= core gui
macx:CONFIG -= app_bundle macx:CONFIG -= app_bundle

View File

@@ -1,6 +1,9 @@
TEMPLATE = app TEMPLATE = app
TARGET = uninit2 TARGET = uninit2
CONFIG += debug
QMAKE_CXXFLAGS = -O0
QT -= core gui QT -= core gui
macx:CONFIG -= app_bundle macx:CONFIG -= app_bundle

View File

@@ -1,6 +1,9 @@
TEMPLATE = app TEMPLATE = app
TARGET = uninit3 TARGET = uninit3
CONFIG += debug
QMAKE_CXXFLAGS = -O0
QT -= core gui QT -= core gui
macx:CONFIG -= app_bundle macx:CONFIG -= app_bundle

View File

@@ -45,6 +45,13 @@
const QString appSrcDir(TESTRUNNER_SRC_DIR); const QString appSrcDir(TESTRUNNER_SRC_DIR);
const QString appBinDir(TESTRUNNER_APP_DIR); const QString appBinDir(TESTRUNNER_APP_DIR);
#define HEADER_LENGTH 29
bool on64bit()
{
return sizeof(char*) == 8;
}
QString srcDirForApp(const QString &app) QString srcDirForApp(const QString &app)
{ {
return appSrcDir + QDir::separator() + app; return appSrcDir + QDir::separator() + app;
@@ -151,12 +158,15 @@ void TestRunner::testLeak1()
QCOMPARE(stack.frames().count(), 2); QCOMPARE(stack.frames().count(), 2);
{ {
const Frame frame = stack.frames().at(0); const Frame frame = stack.frames().at(0);
if (on64bit())
QCOMPARE(frame.functionName(), QLatin1String("operator new(unsigned long)")); QCOMPARE(frame.functionName(), QLatin1String("operator new(unsigned long)"));
else
QCOMPARE(frame.functionName(), QLatin1String("operator new(unsigned int)"));
} }
{ {
const Frame frame = stack.frames().at(1); const Frame frame = stack.frames().at(1);
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 5); QCOMPARE(frame.line(), 5 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
@@ -169,7 +179,6 @@ void TestRunner::testLeak2()
const QString binary = runTestBinary(QLatin1String("leak2/leak2")); const QString binary = runTestBinary(QLatin1String("leak2/leak2"));
QVERIFY(m_logMessages.isEmpty()); QVERIFY(m_logMessages.isEmpty());
QCOMPARE(m_errors.count(), 1); QCOMPARE(m_errors.count(), 1);
const Error error = m_errors.first(); const Error error = m_errors.first();
QCOMPARE(error.kind(), int(Leak_PossiblyLost)); QCOMPARE(error.kind(), int(Leak_PossiblyLost));
@@ -189,12 +198,16 @@ void TestRunner::testLeak2()
} }
{ {
const Frame frame = stack.frames().at(2); const Frame frame = stack.frames().at(2);
if (on64bit()) {
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 7); QCOMPARE(frame.line(), 7 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
QCOMPARE(QDir::cleanPath(frame.directory()), srcDirForApp("leak2")); QCOMPARE(QDir::cleanPath(frame.directory()), srcDirForApp("leak2"));
} else {
QCOMPARE(frame.functionName(), QLatin1String("(below main)"));
}
} }
} }
@@ -223,12 +236,16 @@ void TestRunner::testLeak3()
} }
{ {
const Frame frame = stack.frames().at(2); const Frame frame = stack.frames().at(2);
if (on64bit()) {
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 7); QCOMPARE(frame.line(), 7 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
QCOMPARE(QDir::cleanPath(frame.directory()), srcDirForApp("leak3")); QCOMPARE(QDir::cleanPath(frame.directory()), srcDirForApp("leak3"));
} else {
QCOMPARE(frame.functionName(), QLatin1String("(below main)"));
}
} }
} }
@@ -254,21 +271,15 @@ void TestRunner::testLeak4()
QCOMPARE(stack.frames().count(), 3); QCOMPARE(stack.frames().count(), 3);
{ {
const Frame frame = stack.frames().at(0); const Frame frame = stack.frames().at(0);
if (on64bit())
QCOMPARE(frame.functionName(), QLatin1String("operator new(unsigned long)")); QCOMPARE(frame.functionName(), QLatin1String("operator new(unsigned long)"));
} else
{ QCOMPARE(frame.functionName(), QLatin1String("operator new(unsigned int)"));
const Frame frame = stack.frames().at(2);
QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 14);
QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp"));
QCOMPARE(QDir::cleanPath(frame.directory()), srcDir);
} }
{ {
const Frame frame = stack.frames().at(1); const Frame frame = stack.frames().at(1);
QCOMPARE(frame.functionName(), QLatin1String("Foo::Foo()")); QCOMPARE(frame.functionName(), QLatin1String("Foo::Foo()"));
QCOMPARE(frame.line(), 6); QCOMPARE(frame.line(), 6 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
@@ -277,7 +288,7 @@ void TestRunner::testLeak4()
{ {
const Frame frame = stack.frames().at(2); const Frame frame = stack.frames().at(2);
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 14); QCOMPARE(frame.line(), 14 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
@@ -289,19 +300,25 @@ void TestRunner::testLeak4()
const Error error = m_errors.last(); const Error error = m_errors.last();
QCOMPARE(error.kind(), int(Leak_DefinitelyLost)); QCOMPARE(error.kind(), int(Leak_DefinitelyLost));
QCOMPARE(error.leakedBlocks(), qint64(1)); QCOMPARE(error.leakedBlocks(), qint64(1));
if (on64bit())
QCOMPARE(error.leakedBytes(), quint64(16)); QCOMPARE(error.leakedBytes(), quint64(16));
else
QCOMPARE(error.leakedBytes(), quint64(12));
QCOMPARE(error.stacks().count(), 1); QCOMPARE(error.stacks().count(), 1);
const Stack stack = error.stacks().first(); const Stack stack = error.stacks().first();
QCOMPARE(stack.line(), qint64(-1)); QCOMPARE(stack.line(), qint64(-1));
QCOMPARE(stack.frames().count(), 2); QCOMPARE(stack.frames().count(), 2);
{ {
const Frame frame = stack.frames().at(0); const Frame frame = stack.frames().at(0);
if (on64bit())
QCOMPARE(frame.functionName(), QLatin1String("operator new(unsigned long)")); QCOMPARE(frame.functionName(), QLatin1String("operator new(unsigned long)"));
else
QCOMPARE(frame.functionName(), QLatin1String("operator new(unsigned int)"));
} }
{ {
const Frame frame = stack.frames().at(1); const Frame frame = stack.frames().at(1);
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 14); QCOMPARE(frame.line(), 14 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
@@ -330,7 +347,7 @@ void TestRunner::uninit1()
const Frame frame = stack.frames().first(); const Frame frame = stack.frames().first();
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 4); QCOMPARE(frame.line(), 6 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
@@ -344,7 +361,7 @@ void TestRunner::uninit1()
const Frame frame = stack.frames().first(); const Frame frame = stack.frames().first();
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 2); QCOMPARE(frame.line(), 4 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
@@ -375,7 +392,7 @@ void TestRunner::uninit2()
const Frame frame = stack.frames().first(); const Frame frame = stack.frames().first();
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 4); QCOMPARE(frame.line(), 6 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
@@ -389,7 +406,7 @@ void TestRunner::uninit2()
const Frame frame = stack.frames().first(); const Frame frame = stack.frames().first();
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 2); QCOMPARE(frame.line(), 4 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
@@ -408,7 +425,7 @@ void TestRunner::uninit2()
const Frame frame = stack.frames().first(); const Frame frame = stack.frames().first();
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 4); QCOMPARE(frame.line(), 6 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
@@ -439,7 +456,7 @@ void TestRunner::uninit3()
const Frame frame = stack.frames().first(); const Frame frame = stack.frames().first();
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 4); QCOMPARE(frame.line(), 6 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
@@ -453,7 +470,7 @@ void TestRunner::uninit3()
const Frame frame = stack.frames().first(); const Frame frame = stack.frames().first();
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 2); QCOMPARE(frame.line(), 4 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
@@ -472,7 +489,7 @@ void TestRunner::uninit3()
const Frame frame = stack.frames().first(); const Frame frame = stack.frames().first();
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 4); QCOMPARE(frame.line(), 6 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
@@ -496,21 +513,32 @@ void TestRunner::syscall()
{ {
const Stack stack = error.stacks().first(); const Stack stack = error.stacks().first();
QCOMPARE(stack.line(), qint64(-1)); QCOMPARE(stack.line(), qint64(-1));
QCOMPARE(stack.frames().count(), 3); if (on64bit()) {
QCOMPARE(stack.frames().count(), 4);
{ {
///TODO: is this platform specific?
const Frame frame = stack.frames().at(0); const Frame frame = stack.frames().at(0);
QCOMPARE(frame.functionName(), QLatin1String("_Exit")); QCOMPARE(frame.functionName(), QLatin1String("_Exit"));
} }
{ {
const Frame frame = stack.frames().at(1); const Frame frame = stack.frames().at(1);
QCOMPARE(frame.functionName(), QLatin1String("exit")); QCOMPARE(frame.functionName(), QLatin1String("__run_exit_handlers"));
} }
{ {
const Frame frame = stack.frames().at(2); const Frame frame = stack.frames().at(2);
QCOMPARE(frame.functionName(), QLatin1String("exit"));
}
{
const Frame frame = stack.frames().at(3);
QCOMPARE(frame.functionName(), QLatin1String("(below main)")); QCOMPARE(frame.functionName(), QLatin1String("(below main)"));
} }
} else {
QCOMPARE(stack.frames().count(), 1);
{
const Frame frame = stack.frames().at(0);
QCOMPARE(frame.functionName(), QLatin1String("_Exit"));
}
}
} }
//BEGIN second stack //BEGIN second stack
{ {
@@ -520,7 +548,7 @@ void TestRunner::syscall()
const Frame frame = stack.frames().first(); const Frame frame = stack.frames().first();
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 2); QCOMPARE(frame.line(), 4 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
@@ -553,7 +581,7 @@ void TestRunner::free1()
{ {
const Frame frame = stack.frames().last(); const Frame frame = stack.frames().last();
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 7); QCOMPARE(frame.line(), 7 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
@@ -566,7 +594,6 @@ void TestRunner::free1()
QCOMPARE(stack.line(), qint64(-1)); QCOMPARE(stack.line(), qint64(-1));
QCOMPARE(stack.frames().count(), 2); QCOMPARE(stack.frames().count(), 2);
{ {
const Frame frame = stack.frames().first(); const Frame frame = stack.frames().first();
QCOMPARE(frame.functionName(), QLatin1String("operator delete(void*)")); QCOMPARE(frame.functionName(), QLatin1String("operator delete(void*)"));
@@ -574,7 +601,7 @@ void TestRunner::free1()
{ {
const Frame frame = stack.frames().last(); const Frame frame = stack.frames().last();
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 6); QCOMPARE(frame.line(), 6 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
@@ -608,7 +635,7 @@ void TestRunner::free2()
{ {
const Frame frame = stack.frames().last(); const Frame frame = stack.frames().last();
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 6); QCOMPARE(frame.line(), 6 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
@@ -624,12 +651,15 @@ void TestRunner::free2()
{ {
const Frame frame = stack.frames().first(); const Frame frame = stack.frames().first();
if (on64bit())
QCOMPARE(frame.functionName(), QLatin1String("operator new(unsigned long)")); QCOMPARE(frame.functionName(), QLatin1String("operator new(unsigned long)"));
else
QCOMPARE(frame.functionName(), QLatin1String("operator new(unsigned int)"));
} }
{ {
const Frame frame = stack.frames().last(); const Frame frame = stack.frames().last();
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 5); QCOMPARE(frame.line(), 5 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));
@@ -684,12 +714,12 @@ void TestRunner::overlap()
QCOMPARE(stack.frames().count(), 2); QCOMPARE(stack.frames().count(), 2);
{ {
const Frame frame = stack.frames().at(0); const Frame frame = stack.frames().at(0);
QCOMPARE(frame.functionName(), QLatin1String("memcpy")); QVERIFY(frame.functionName().startsWith(QLatin1String("memcpy")));
} }
{ {
const Frame frame = stack.frames().last(); const Frame frame = stack.frames().last();
QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.functionName(), QLatin1String("main"));
QCOMPARE(frame.line(), 6); QCOMPARE(frame.line(), 6 + HEADER_LENGTH);
QCOMPARE(frame.object(), binary); QCOMPARE(frame.object(), binary);
QCOMPARE(frame.file(), QLatin1String("main.cpp")); QCOMPARE(frame.file(), QLatin1String("main.cpp"));