Valgrind: Make the (threaded) parser a proper member of the runner

Simplifies user code, and it was only ever used in a 1:1 relation,
even in the tests.

Change-Id: I3ce4fc83a361aceb730c05420efdb4ea52d37cda
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2017-06-21 09:01:48 +02:00
parent 7edd5876a5
commit fc8dee4675
9 changed files with 25 additions and 60 deletions

View File

@@ -55,9 +55,9 @@ MemcheckToolRunner::MemcheckToolRunner(RunControl *runControl, bool withGdb)
: ValgrindToolRunner(runControl), m_withGdb(withGdb) : ValgrindToolRunner(runControl), m_withGdb(withGdb)
{ {
setDisplayName("MemcheckToolRunner"); setDisplayName("MemcheckToolRunner");
connect(&m_parser, &XmlProtocol::ThreadedParser::error, connect(m_runner.parser(), &XmlProtocol::ThreadedParser::error,
this, &MemcheckToolRunner::parserError); this, &MemcheckToolRunner::parserError);
connect(&m_parser, &XmlProtocol::ThreadedParser::suppressionCount, connect(m_runner.parser(), &XmlProtocol::ThreadedParser::suppressionCount,
this, &MemcheckToolRunner::suppressionCount); this, &MemcheckToolRunner::suppressionCount);
if (withGdb) { if (withGdb) {
@@ -67,7 +67,7 @@ MemcheckToolRunner::MemcheckToolRunner(RunControl *runControl, bool withGdb)
this, &MemcheckToolRunner::appendLog); this, &MemcheckToolRunner::appendLog);
m_runner.disableXml(); m_runner.disableXml();
} else { } else {
connect(&m_parser, &XmlProtocol::ThreadedParser::internalError, connect(m_runner.parser(), &XmlProtocol::ThreadedParser::internalError,
this, &MemcheckToolRunner::internalParserError); this, &MemcheckToolRunner::internalParserError);
} }
} }
@@ -86,8 +86,6 @@ void MemcheckToolRunner::start()
{ {
// MemcheckTool::engineStarting(this); // MemcheckTool::engineStarting(this);
m_runner.setParser(&m_parser);
appendMessage(tr("Analyzing memory of %1").arg(executable()) + QLatin1Char('\n'), appendMessage(tr("Analyzing memory of %1").arg(executable()) + QLatin1Char('\n'),
Utils::NormalMessageFormat); Utils::NormalMessageFormat);
ValgrindToolRunner::start(); ValgrindToolRunner::start();
@@ -95,7 +93,7 @@ void MemcheckToolRunner::start()
void MemcheckToolRunner::stop() void MemcheckToolRunner::stop()
{ {
disconnect(&m_parser, &ThreadedParser::internalError, disconnect(m_runner.parser(), &ThreadedParser::internalError,
this, &MemcheckToolRunner::internalParserError); this, &MemcheckToolRunner::internalParserError);
ValgrindToolRunner::stop(); ValgrindToolRunner::stop();
} }

View File

@@ -60,7 +60,6 @@ private:
void startDebugger(); void startDebugger();
void appendLog(const QByteArray &data); void appendLog(const QByteArray &data);
XmlProtocol::ThreadedParser m_parser;
ValgrindRunner m_runner; ValgrindRunner m_runner;
const bool m_withGdb; const bool m_withGdb;
}; };

View File

@@ -455,10 +455,8 @@ void ValgrindMemcheckParserTest::testValgrindGarbage()
void ValgrindMemcheckParserTest::testParserStop() void ValgrindMemcheckParserTest::testParserStop()
{ {
ThreadedParser parser;
ValgrindRunner runner; ValgrindRunner runner;
runner.setValgrindExecutable(fakeValgrindExecutable()); runner.setValgrindExecutable(fakeValgrindExecutable());
runner.setParser(&parser);
runner.setValgrindArguments({"-i", dataFile("memcheck-output-sample1.xml"), "--wait", "5" }); runner.setValgrindArguments({"-i", dataFile("memcheck-output-sample1.xml"), "--wait", "5" });
runner.setProcessChannelMode(QProcess::ForwardedChannels); runner.setProcessChannelMode(QProcess::ForwardedChannels);
@@ -477,7 +475,6 @@ void ValgrindMemcheckParserTest::testRealValgrind()
QSKIP("This test needs valgrind in PATH"); QSKIP("This test needs valgrind in PATH");
QString executable = QProcessEnvironment::systemEnvironment().value("VALGRIND_TEST_BIN", fakeValgrindExecutable()); QString executable = QProcessEnvironment::systemEnvironment().value("VALGRIND_TEST_BIN", fakeValgrindExecutable());
qDebug() << "running exe:" << executable << " HINT: set VALGRIND_TEST_BIN to change this"; qDebug() << "running exe:" << executable << " HINT: set VALGRIND_TEST_BIN to change this";
ThreadedParser parser;
ProjectExplorer::StandardRunnable debuggee; ProjectExplorer::StandardRunnable debuggee;
debuggee.executable = executable; debuggee.executable = executable;
@@ -487,8 +484,7 @@ void ValgrindMemcheckParserTest::testRealValgrind()
runner.setDebuggee(debuggee); runner.setDebuggee(debuggee);
runner.setDevice(ProjectExplorer::DeviceManager::instance()->defaultDevice( runner.setDevice(ProjectExplorer::DeviceManager::instance()->defaultDevice(
ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE)); ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE));
runner.setParser(&parser); RunnerDumper dumper(&runner);
RunnerDumper dumper(&runner, &parser);
runner.start(); runner.start();
runner.waitForFinished(); runner.waitForFinished();
} }
@@ -517,21 +513,18 @@ void ValgrindMemcheckParserTest::testValgrindStartError()
QFETCH(QString, debuggee); QFETCH(QString, debuggee);
QFETCH(QString, debuggeeArgs); QFETCH(QString, debuggeeArgs);
ThreadedParser parser;
ProjectExplorer::StandardRunnable debuggeeExecutable; ProjectExplorer::StandardRunnable debuggeeExecutable;
debuggeeExecutable.executable = debuggee; debuggeeExecutable.executable = debuggee;
debuggeeExecutable.environment = Utils::Environment::systemEnvironment(); debuggeeExecutable.environment = Utils::Environment::systemEnvironment();
debuggeeExecutable.commandLineArguments = debuggeeArgs; debuggeeExecutable.commandLineArguments = debuggeeArgs;
ValgrindRunner runner; ValgrindRunner runner;
runner.setParser(&parser);
runner.setValgrindExecutable(valgrindExe); runner.setValgrindExecutable(valgrindExe);
runner.setValgrindArguments(valgrindArgs); runner.setValgrindArguments(valgrindArgs);
runner.setDebuggee(debuggeeExecutable); runner.setDebuggee(debuggeeExecutable);
runner.setDevice(ProjectExplorer::DeviceManager::instance()->defaultDevice( runner.setDevice(ProjectExplorer::DeviceManager::instance()->defaultDevice(
ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE)); ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE));
RunnerDumper dumper(&runner, &parser); RunnerDumper dumper(&runner);
runner.start(); runner.start();
runner.waitForFinished(); runner.waitForFinished();
QVERIFY(dumper.m_errorReceived); QVERIFY(dumper.m_errorReceived);

View File

@@ -53,14 +53,13 @@ class Recorder : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit Recorder(Valgrind::XmlProtocol::Parser *parser, QObject *parent = 0) explicit Recorder(XmlProtocol::Parser *parser)
: QObject(parent)
{ {
connect(parser, &Valgrind::XmlProtocol::Parser::error, connect(parser, &XmlProtocol::Parser::error,
this, &Recorder::error); this, &Recorder::error);
connect(parser, &Valgrind::XmlProtocol::Parser::errorCount, connect(parser, &XmlProtocol::Parser::errorCount,
this, &Recorder::errorCount); this, &Recorder::errorCount);
connect(parser, &Valgrind::XmlProtocol::Parser::suppressionCount, connect(parser, &XmlProtocol::Parser::suppressionCount,
this, &Recorder::suppressionCount); this, &Recorder::suppressionCount);
} }
@@ -91,13 +90,13 @@ class RunnerDumper : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit RunnerDumper(ValgrindRunner *runner, XmlProtocol::ThreadedParser *parser) explicit RunnerDumper(ValgrindRunner *runner)
{ {
connect(parser, &XmlProtocol::ThreadedParser::error, connect(runner->parser(), &XmlProtocol::ThreadedParser::error,
this, &RunnerDumper::error); this, &RunnerDumper::error);
connect(parser, &XmlProtocol::ThreadedParser::internalError, connect(runner->parser(), &XmlProtocol::ThreadedParser::internalError,
this, &RunnerDumper::internalError); this, &RunnerDumper::internalError);
connect(parser, &XmlProtocol::ThreadedParser::status, connect(runner->parser(), &XmlProtocol::ThreadedParser::status,
this, &RunnerDumper::status); this, &RunnerDumper::status);
connect(runner, &ValgrindRunner::logMessageReceived, connect(runner, &ValgrindRunner::logMessageReceived,
this, &RunnerDumper::logMessageReceived); this, &RunnerDumper::logMessageReceived);

View File

@@ -59,7 +59,7 @@ public:
QString tool; QString tool;
QTcpServer xmlServer; QTcpServer xmlServer;
XmlProtocol::ThreadedParser *parser = nullptr; XmlProtocol::ThreadedParser parser;
QTcpServer logServer; QTcpServer logServer;
QTcpSocket *logSocket = nullptr; QTcpSocket *logSocket = nullptr;
bool disableXml = false; bool disableXml = false;
@@ -77,7 +77,7 @@ ValgrindRunner::~ValgrindRunner()
// make sure we don't delete the thread while it's still running // make sure we don't delete the thread while it's still running
waitForFinished(); waitForFinished();
} }
if (d->parser->isRunning()) { if (d->parser.isRunning()) {
// make sure we don't delete the thread while it's still running // make sure we don't delete the thread while it's still running
waitForFinished(); waitForFinished();
} }
@@ -238,10 +238,9 @@ ValgrindProcess *ValgrindRunner::valgrindProcess() const
return d->process; return d->process;
} }
void ValgrindRunner::setParser(XmlProtocol::ThreadedParser *parser) XmlProtocol::ThreadedParser *ValgrindRunner::parser() const
{ {
QTC_ASSERT(!d->parser, qt_noop()); return &d->parser;
d->parser = parser;
} }
@@ -257,7 +256,7 @@ void ValgrindRunner::xmlSocketConnected()
QTcpSocket *socket = d->xmlServer.nextPendingConnection(); QTcpSocket *socket = d->xmlServer.nextPendingConnection();
QTC_ASSERT(socket, return); QTC_ASSERT(socket, return);
d->xmlServer.close(); d->xmlServer.close();
d->parser->parse(socket); d->parser.parse(socket);
} }
void ValgrindRunner::logSocketConnected() void ValgrindRunner::logSocketConnected()

View File

@@ -70,7 +70,7 @@ public:
ValgrindProcess *valgrindProcess() const; ValgrindProcess *valgrindProcess() const;
void setParser(XmlProtocol::ThreadedParser *parser); XmlProtocol::ThreadedParser *parser() const;
void disableXml(); void disableXml();
signals: signals:

View File

@@ -112,9 +112,6 @@ void ValgrindTestRunnerTest::cleanup()
Q_ASSERT(m_runner); Q_ASSERT(m_runner);
delete m_runner; delete m_runner;
m_runner = 0; m_runner = 0;
Q_ASSERT(m_parser);
delete m_parser;
m_parser = 0;
m_logMessages.clear(); m_logMessages.clear();
m_errors.clear(); m_errors.clear();
@@ -137,14 +134,10 @@ void ValgrindTestRunnerTest::init()
this, &ValgrindTestRunnerTest::logMessageReceived); this, &ValgrindTestRunnerTest::logMessageReceived);
connect(m_runner, &ValgrindRunner::processErrorReceived, connect(m_runner, &ValgrindRunner::processErrorReceived,
this, &ValgrindTestRunnerTest::internalError); this, &ValgrindTestRunnerTest::internalError);
Q_ASSERT(!m_parser); connect(m_runner->parser(), &ThreadedParser::internalError,
m_parser = new ThreadedParser;
connect(m_parser, &ThreadedParser::internalError,
this, &ValgrindTestRunnerTest::internalError); this, &ValgrindTestRunnerTest::internalError);
connect(m_parser, &ThreadedParser::error, connect(m_runner->parser(), &ThreadedParser::error,
this, &ValgrindTestRunnerTest::error); this, &ValgrindTestRunnerTest::error);
m_runner->setParser(m_parser);
} }
//BEGIN: Actual test cases //BEGIN: Actual test cases
@@ -735,7 +728,6 @@ void ValgrindTestRunnerTest::testInvalidjump()
} }
} }
void ValgrindTestRunnerTest::testOverlap() void ValgrindTestRunnerTest::testOverlap()
{ {
const QString app("overlap"); const QString app("overlap");

View File

@@ -33,7 +33,6 @@
namespace Valgrind { namespace Valgrind {
namespace XmlProtocol { class ThreadedParser; }
class ValgrindRunner; class ValgrindRunner;
namespace Test { namespace Test {
@@ -72,7 +71,6 @@ private slots:
private: private:
QString runTestBinary(const QString &binary, const QStringList &vArgs = QStringList()); QString runTestBinary(const QString &binary, const QStringList &vArgs = QStringList());
XmlProtocol::ThreadedParser *m_parser = nullptr;
ValgrindRunner *m_runner = nullptr; ValgrindRunner *m_runner = nullptr;
QList<QByteArray> m_logMessages; QList<QByteArray> m_logMessages;
QList<XmlProtocol::Error> m_errors; QList<XmlProtocol::Error> m_errors;

View File

@@ -38,33 +38,20 @@
using namespace Valgrind; using namespace Valgrind;
using namespace Valgrind::XmlProtocol; using namespace Valgrind::XmlProtocol;
static QString fakeValgrindExecutable()
{
return QLatin1String(VALGRIND_FAKE_PATH);
}
static QString dataFile(const QLatin1String &file)
{
return QLatin1String(PARSERTESTS_DATA_DIR) + QLatin1String("/") + file;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication app(argc, argv); QApplication app(argc, argv);
qRegisterMetaType<Error>(); qRegisterMetaType<Error>();
ThreadedParser parser;
ValgrindRunner runner; ValgrindRunner runner;
runner.setValgrindExecutable(fakeValgrindExecutable()); runner.setValgrindExecutable(VALGRIND_FAKE_PATH);
runner.setValgrindArguments(QStringList() << QLatin1String("-i") << dataFile(QLatin1String("memcheck-output-sample1.xml")) ); runner.setValgrindArguments({"-i", PARSERTESTS_DATA_DIR "/memcheck-output-sample1.xml"});
runner.setParser(&parser);
ModelDemo demo(&runner); ModelDemo demo(&runner);
QObject::connect(&runner, &ValgrindRunner::finished, QObject::connect(&runner, &ValgrindRunner::finished,
&demo, &ModelDemo::finished); &demo, &ModelDemo::finished);
ErrorListModel model; ErrorListModel model;
QObject::connect(&parser, &ThreadedParser::error, QObject::connect(runner.parser(), &ThreadedParser::error,
&model, &ErrorListModel::addError, &model, &ErrorListModel::addError,
Qt::QueuedConnection); Qt::QueuedConnection);