Valgrind: Modernize code

* QLatin1String
* initializer list

Change-Id: I6654fcd8b8ec513d1802a4ba3fe3f5833a29136b
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Stenger
2017-02-09 14:34:21 +01:00
parent e952b9d4f3
commit fe16f0b38e
2 changed files with 73 additions and 79 deletions

View File

@@ -100,9 +100,9 @@ static QString fakeValgrindExecutable()
return valgrindFakePath + "/valgrind-fake";
}
static QString dataFile(const QLatin1String &file)
static QString dataFile(const QString &file)
{
return QLatin1String(PARSERTESTS_DATA_DIR) + QLatin1String("/") + file;
return QString(PARSERTESTS_DATA_DIR) + '/' + file;
}
void ValgrindMemcheckParserTest::initTestCase()
@@ -114,7 +114,7 @@ void ValgrindMemcheckParserTest::initTestCase()
m_process = 0;
}
void ValgrindMemcheckParserTest::initTest(const QLatin1String &testfile, const QStringList &otherArgs)
void ValgrindMemcheckParserTest::initTest(const QString &testfile, const QStringList &otherArgs)
{
QVERIFY(!m_server->hasPendingConnections());
@@ -127,12 +127,8 @@ void ValgrindMemcheckParserTest::initTest(const QLatin1String &testfile, const Q
m_process->start(
fakeValgrind,
QStringList()
<< QString::fromLatin1("--xml-socket=127.0.0.1:%1").arg(m_server->serverPort())
<< QLatin1String("-i")
<< dataFile(testfile)
<< otherArgs
);
QStringList({ QString("--xml-socket=127.0.0.1:%1").arg(m_server->serverPort()), "-i",
dataFile(testfile)}) << otherArgs);
QVERIFY(m_process->waitForStarted(5000));
QCOMPARE(m_process->state(), QProcess::Running);
@@ -158,7 +154,7 @@ void ValgrindMemcheckParserTest::testHelgrindSample1()
{
QSKIP("testfile does not exist");
initTest(QLatin1String("helgrind-output-sample1.xml"));
initTest("helgrind-output-sample1.xml");
QList<Error> expectedErrors;
{
@@ -166,58 +162,58 @@ void ValgrindMemcheckParserTest::testHelgrindSample1()
error1.setUnique(0x0);
error1.setTid(1);
error1.setKind(LockOrder);
error1.setWhat(QLatin1String("Thread #1: lock order \"0xA39C270 before 0xA3AC010\" violated"));
error1.setWhat("Thread #1: lock order \"0xA39C270 before 0xA3AC010\" violated");
error1.setHelgrindThreadId(1);
Stack stack1;
Frame frame11;
frame11.setInstructionPointer(0x4C2B806);
frame11.setObject(QLatin1String("/usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so"));
frame11.setFunctionName(QLatin1String("QMutex::lock()"));
frame11.setDirectory(QLatin1String("/build/buildd/valgrind-3.6.0~svn20100212/helgrind"));
frame11.setFileName(QLatin1String("hg_intercepts.c"));
frame11.setObject("/usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so");
frame11.setFunctionName("QMutex::lock()");
frame11.setDirectory("/build/buildd/valgrind-3.6.0~svn20100212/helgrind");
frame11.setFileName("hg_intercepts.c");
frame11.setLine(1988);
Frame frame12;
frame12.setInstructionPointer(0x72E57EE);
frame12.setObject(QLatin1String("/home/frank/local/qt4-4.6.3-shared-debug/lib/libQtCore.so.4.6.3"));
frame12.setFunctionName(QLatin1String("QMutexLocker::relock()"));
frame12.setDirectory(QLatin1String("/home/frank/source/tarballs/qt-4.6.3-build/src/corelib/../../include/QtCore/../../src/corelib/thread"));
frame12.setFileName(QLatin1String("qmutex.h"));
frame12.setObject("/home/frank/local/qt4-4.6.3-shared-debug/lib/libQtCore.so.4.6.3");
frame12.setFunctionName("QMutexLocker::relock()");
frame12.setDirectory("/home/frank/source/tarballs/qt-4.6.3-build/src/corelib/../../include/QtCore/../../src/corelib/thread");
frame12.setFileName("qmutex.h");
frame12.setLine(120);
stack1.setFrames(QVector<Frame>() << frame11 << frame12);
Stack stack2;
stack2.setAuxWhat(QLatin1String("Required order was established by acquisition of lock at 0xA39C270"));
stack2.setAuxWhat("Required order was established by acquisition of lock at 0xA39C270");
Frame frame21;
frame21.setInstructionPointer(0x4C2B806);
frame21.setObject(QLatin1String("/usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so"));
frame21.setFunctionName(QLatin1String("QMutex::lock()"));
frame21.setDirectory(QLatin1String("/build/buildd/valgrind-3.6.0~svn20100212/helgrind"));
frame21.setFileName(QLatin1String("hg_intercepts.c"));
frame21.setObject("/usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so");
frame21.setFunctionName("QMutex::lock()");
frame21.setDirectory("/build/buildd/valgrind-3.6.0~svn20100212/helgrind");
frame21.setFileName("hg_intercepts.c");
frame21.setLine(1989);
Frame frame22;
frame22.setInstructionPointer(0x72E57EE);
frame22.setObject(QLatin1String("/home/frank/local/qt4-4.6.3-shared-debug/lib/libQtCore.so.4.6.3"));
frame22.setFunctionName(QLatin1String("QMutexLocker::relock()"));
frame22.setDirectory(QLatin1String("/home/frank/source/tarballs/qt-4.6.3-build/src/corelib/../../include/QtCore/../../src/corelib/thread"));
frame22.setFileName(QLatin1String("qmutex.h"));
frame22.setObject("/home/frank/local/qt4-4.6.3-shared-debug/lib/libQtCore.so.4.6.3");
frame22.setFunctionName("QMutexLocker::relock()");
frame22.setDirectory("/home/frank/source/tarballs/qt-4.6.3-build/src/corelib/../../include/QtCore/../../src/corelib/thread");
frame22.setFileName("qmutex.h");
frame22.setLine(121);
stack2.setFrames(QVector<Frame>() << frame21 << frame22);
Stack stack3;
stack3.setAuxWhat(QLatin1String("followed by a later acquisition of lock at 0xA3AC010"));
stack3.setAuxWhat("followed by a later acquisition of lock at 0xA3AC010");
Frame frame31;
frame31.setInstructionPointer(0x4C2B806);
frame31.setObject(QLatin1String("/usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so"));
frame31.setFunctionName(QLatin1String("QMutex::lock()"));
frame31.setDirectory(QLatin1String("/build/buildd/valgrind-3.6.0~svn20100212/helgrind"));
frame31.setFileName(QLatin1String("hg_intercepts.c"));
frame31.setObject("/usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so");
frame31.setFunctionName("QMutex::lock()");
frame31.setDirectory("/build/buildd/valgrind-3.6.0~svn20100212/helgrind");
frame31.setFileName("hg_intercepts.c");
frame31.setLine(1990);
Frame frame32;
frame32.setInstructionPointer(0x72E57EE);
frame32.setObject(QLatin1String("/home/frank/local/qt4-4.6.3-shared-debug/lib/libQtCore.so.4.6.3"));
frame32.setFunctionName(QLatin1String("QMutexLocker::relock()"));
frame32.setDirectory(QLatin1String("/home/frank/source/tarballs/qt-4.6.3-build/src/corelib/../../include/QtCore/../../src/corelib/thread"));
frame32.setFileName(QLatin1String("qmutex.h"));
frame32.setObject("/home/frank/local/qt4-4.6.3-shared-debug/lib/libQtCore.so.4.6.3");
frame32.setFunctionName("QMutexLocker::relock()");
frame32.setDirectory("/home/frank/source/tarballs/qt-4.6.3-build/src/corelib/../../include/QtCore/../../src/corelib/thread");
frame32.setFileName("qmutex.h");
frame32.setLine(122);
stack3.setFrames(QVector<Frame>() << frame31 << frame32);
@@ -252,41 +248,41 @@ void ValgrindMemcheckParserTest::testHelgrindSample1()
void ValgrindMemcheckParserTest::testMemcheckSample1()
{
initTest(QLatin1String("memcheck-output-sample1.xml"));
initTest("memcheck-output-sample1.xml");
QList<Error> expectedErrors;
{
Error error;
error.setKind(InvalidRead);
error.setWhat(QLatin1String("Invalid read of size 4"));
error.setWhat("Invalid read of size 4");
error.setUnique(0x9);
error.setTid(1);
Frame f1;
f1.setInstructionPointer(0x6E47964);
f1.setObject(QLatin1String("/usr/lib/libQtGui.so.4.7.0"));
f1.setFunctionName(QLatin1String("QFrame::frameStyle() const"));
f1.setDirectory(QLatin1String("/build/buildd/qt4-x11-4.7.0/src/gui/widgets"));
f1.setFileName(QLatin1String("qframe.cpp"));
f1.setObject("/usr/lib/libQtGui.so.4.7.0");
f1.setFunctionName("QFrame::frameStyle() const");
f1.setDirectory("/build/buildd/qt4-x11-4.7.0/src/gui/widgets");
f1.setFileName("qframe.cpp");
f1.setLine(252);
Frame f2;
f2.setInstructionPointer(0x118F2AF7);
f2.setObject(QLatin1String("/usr/lib/kde4/plugins/styles/oxygen.so"));
f2.setObject("/usr/lib/kde4/plugins/styles/oxygen.so");
Frame f3;
f3.setInstructionPointer(0x6A81671);
f3.setObject(QLatin1String("/usr/lib/libQtGui.so.4.7.0"));
f3.setFunctionName(QLatin1String("QWidget::event(QEvent*)"));
f3.setDirectory(QLatin1String("/build/buildd/qt4-x11-4.7.0/src/gui/kernel"));
f3.setFileName(QLatin1String("qwidget.cpp"));
f3.setObject("/usr/lib/libQtGui.so.4.7.0");
f3.setFunctionName("QWidget::event(QEvent*)");
f3.setDirectory("/build/buildd/qt4-x11-4.7.0/src/gui/kernel");
f3.setFileName("qwidget.cpp");
f3.setLine(8273);
Frame f4;
f4.setInstructionPointer(0x6A2B6EB);
f4.setObject(QLatin1String("/usr/lib/libQtGui.so.4.7.0"));
f4.setDirectory(QLatin1String("/build/buildd/qt4-x11-4.7.0/src/gui/kernel"));
f4.setFileName(QLatin1String("qapplication.cpp"));
f4.setFunctionName(QLatin1String("QApplicationPrivate::notify_helper(QObject*, QEvent*)"));
f4.setObject("/usr/lib/libQtGui.so.4.7.0");
f4.setDirectory("/build/buildd/qt4-x11-4.7.0/src/gui/kernel");
f4.setFileName("qapplication.cpp");
f4.setFunctionName("QApplicationPrivate::notify_helper(QObject*, QEvent*)");
f4.setLine(4396);
Stack s1;
s1.setAuxWhat(QLatin1String("Address 0x11527cb8 is not stack'd, malloc'd or (recently) free'd"));
s1.setAuxWhat("Address 0x11527cb8 is not stack'd, malloc'd or (recently) free'd");
s1.setFrames(QVector<Frame>() << f1 << f2 << f3 << f4);
error.setStacks( QVector<Stack>() << s1 );
@@ -297,9 +293,9 @@ void ValgrindMemcheckParserTest::testMemcheckSample1()
expectedErrorCounts.push_back(QPair<qint64,qint64>(9, 2));
QVector<QPair<QString,qint64> > expectedSuppCounts;
expectedSuppCounts.push_back(qMakePair(QString::fromLatin1("X on SUSE11 writev uninit padding"), static_cast<qint64>(12)));
expectedSuppCounts.push_back(qMakePair(QString::fromLatin1("dl-hack3-cond-1"), static_cast<qint64>(2)));
expectedSuppCounts.push_back(qMakePair(QString::fromLatin1("glibc-2.5.x-on-SUSE-10.2-(PPC)-2a"), static_cast<qint64>(2)));
expectedSuppCounts.push_back(qMakePair(QString("X on SUSE11 writev uninit padding"), static_cast<qint64>(12)));
expectedSuppCounts.push_back(qMakePair(QString("dl-hack3-cond-1"), static_cast<qint64>(2)));
expectedSuppCounts.push_back(qMakePair(QString("glibc-2.5.x-on-SUSE-10.2-(PPC)-2a"), static_cast<qint64>(2)));
Parser parser;
Recorder rec(&parser);
@@ -330,7 +326,7 @@ void ValgrindMemcheckParserTest::testMemcheckSample2()
{
QSKIP("testfile does not exist");
initTest(QLatin1String("memcheck-output-sample2.xml"));
initTest("memcheck-output-sample2.xml");
Parser parser;
Recorder rec(&parser);
@@ -349,14 +345,14 @@ void ValgrindMemcheckParserTest::testMemcheckSample2()
const QVector<Stack> stacks = errors.first().stacks();
QCOMPARE(stacks.size(), 2);
QCOMPARE(stacks.first().auxWhat(), QString());
QCOMPARE(stacks.last().auxWhat(), QLatin1String("Address 0x11b66c50 is 0 bytes inside a block of size 16 free'd"));
QCOMPARE(stacks.last().auxWhat(), "Address 0x11b66c50 is 0 bytes inside a block of size 16 free'd");
}
void ValgrindMemcheckParserTest::testMemcheckSample3()
{
QSKIP("testfile does not exist");
initTest(QLatin1String("memcheck-output-sample3.xml"));
initTest("memcheck-output-sample3.xml");
Parser parser;
Recorder rec(&parser);
@@ -376,25 +372,25 @@ void ValgrindMemcheckParserTest::testMemcheckSample3()
const QVector<Stack> stacks = error.stacks();
QCOMPARE(error.unique(), 0x1ll);
QCOMPARE(error.what(), QLatin1String("Conditional jump or move depends on uninitialised value(s)"));
QCOMPARE(error.what(), "Conditional jump or move depends on uninitialised value(s)");
QCOMPARE(error.kind(), UninitCondition);
QCOMPARE(stacks.size(), 1);
QCOMPARE(stacks.first().frames().size(), 12);
QVERIFY(!error.suppression().isNull());
QCOMPARE(error.suppression().frames().count(), stacks.first().frames().size());
QCOMPARE(error.suppression().kind(), QLatin1String("Memcheck:Cond"));
QCOMPARE(error.suppression().kind(), "Memcheck:Cond");
QVERIFY(!error.suppression().rawText().trimmed().isEmpty());
// rawtext contains <...> while <name></name> does not
QCOMPARE(error.suppression().name(), QLatin1String("insert_a_suppression_name_here"));
QCOMPARE(error.suppression().name(), "insert_a_suppression_name_here");
Suppression sup = error.suppression();
sup.setName(QLatin1String("<insert_a_suppression_name_here>"));
sup.setName("<insert_a_suppression_name_here>");
QCOMPARE(sup.toString().trimmed(), sup.rawText().trimmed());
QCOMPARE(error.suppression().frames().first().object(),
QLatin1String("/usr/lib/kde4/plugins/styles/qtcurve.so"));
"/usr/lib/kde4/plugins/styles/qtcurve.so");
QVERIFY(error.suppression().frames().first().function().isEmpty());
QCOMPARE(error.suppression().frames().last().function(), QLatin1String("main"));
QCOMPARE(error.suppression().frames().last().function(), "main");
QVERIFY(error.suppression().frames().last().object().isEmpty());
}
@@ -409,7 +405,7 @@ void ValgrindMemcheckParserTest::testMemcheckCharm()
QSKIP("testfile does not exist");
// a somewhat larger file, to make sure buffering and partial I/O works ok
initTest(QLatin1String("memcheck-output-untitled.xml"));
initTest("memcheck-output-untitled.xml");
Parser parser;
Recorder rec(&parser);
@@ -427,7 +423,7 @@ void ValgrindMemcheckParserTest::testMemcheckCharm()
void ValgrindMemcheckParserTest::testValgrindCrash()
{
initTest(QLatin1String("memcheck-output-sample1.xml"), QStringList() << "--crash");
initTest("memcheck-output-sample1.xml", QStringList("--crash"));
Parser parser;
parser.parse(m_socket);
@@ -442,7 +438,7 @@ void ValgrindMemcheckParserTest::testValgrindCrash()
void ValgrindMemcheckParserTest::testValgrindGarbage()
{
initTest(QLatin1String("memcheck-output-sample1.xml"), QStringList() << "--garbage");
initTest("memcheck-output-sample1.xml", QStringList("--garbage"));
Parser parser;
parser.parse(m_socket);
@@ -460,9 +456,8 @@ void ValgrindMemcheckParserTest::testParserStop()
Memcheck::MemcheckRunner runner;
runner.setValgrindExecutable(fakeValgrindExecutable());
runner.setParser(&parser);
runner.setValgrindArguments(QStringList() << QLatin1String("-i")
<< dataFile(QLatin1String("memcheck-output-sample1.xml"))
<< "--wait" << "5");
runner.setValgrindArguments(QStringList({ "-i", dataFile("memcheck-output-sample1.xml"),
"--wait", "5" }));
runner.setProcessChannelMode(QProcess::ForwardedChannels);
runner.setDevice(ProjectExplorer::DeviceManager::instance()->defaultDevice(
@@ -487,7 +482,7 @@ void ValgrindMemcheckParserTest::testRealValgrind()
debuggee.executable = executable;
debuggee.environment = sysEnv;
Memcheck::MemcheckRunner runner;
runner.setValgrindExecutable(QLatin1String("valgrind"));
runner.setValgrindExecutable("valgrind");
runner.setDebuggee(debuggee);
runner.setDevice(ProjectExplorer::DeviceManager::instance()->defaultDevice(
Core::Id(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE)));
@@ -504,14 +499,13 @@ void ValgrindMemcheckParserTest::testValgrindStartError_data()
QTest::addColumn<QString>("debuggee");
QTest::addColumn<QString>("debuggeeArgs");
QTest::newRow("invalid_client") << QString::fromLatin1("valgrind") << QStringList()
<< QString::fromLatin1("please-dont-let-this-app-exist") << QString();
QTest::newRow("invalid_client") << "valgrind" << QStringList()
<< "please-dont-let-this-app-exist" << QString();
QTest::newRow("invalid_valgrind") << QString::fromLatin1("valgrind-that-does-not-exist") << QStringList()
<< fakeValgrindExecutable() << QString();
QTest::newRow("invalid_valgrind") << "valgrind-that-does-not-exist" << QStringList()
<< fakeValgrindExecutable() << QString();
QTest::newRow("invalid_valgrind_args") << QString::fromLatin1("valgrind")
<< (QStringList() << QString::fromLatin1("--foobar-fail"))
QTest::newRow("invalid_valgrind_args") << "valgrind" << QStringList("--foobar-fail")
<< fakeValgrindExecutable() << QString();
}

View File

@@ -161,7 +161,7 @@ private Q_SLOTS:
void testValgrindStartError();
private:
void initTest(const QLatin1String &testfile, const QStringList &otherArgs = QStringList());
void initTest(const QString &testfile, const QStringList &otherArgs = QStringList());
QTcpServer *m_server = 0;
QProcess *m_process = 0;