Valgrind test: Hide Recorder and Dumper in cpp file

Inline Recorder's and Dumper's slots.
Clean some namespace specifiers.

Change-Id: I1111e8fb3c912dc1f253ebb2ed7f8e9c3fff67e0
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Jarek Kobus
2023-08-05 10:33:26 +02:00
parent 91f01c17f9
commit 00a34e60fc
2 changed files with 62 additions and 115 deletions

View File

@@ -3,23 +3,21 @@
#include "valgrindmemcheckparsertest.h"
#include "valgrindrunner.h"
#include "xmlprotocol/error.h"
#include "xmlprotocol/frame.h"
#include "xmlprotocol/parser.h"
#include "xmlprotocol/stack.h"
#include "xmlprotocol/status.h"
#include "xmlprotocol/suppression.h"
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/runcontrol.h>
#include <QFile>
#include <QFileInfo>
#include <QProcess>
#include <QString>
#include <QTest>
#include <QTcpServer>
#include <QTcpSocket>
#include <QSignalSpy>
#include <QTest>
using namespace Utils;
using namespace Valgrind::XmlProtocol;
@@ -43,16 +41,9 @@ inline bool qCompare(const QString &t1, char const *t2,
} // namespace QTest
QT_END_NAMESPACE
namespace Valgrind {
namespace Test {
namespace Valgrind::Test {
static void dumpFrame(const Frame &f)
{
qDebug() << f.instructionPointer() << f.directory() << f.fileName() << f.functionName()
<< f.line() << f.object();
}
void dumpError(const Error &e)
static void dumpError(const Error &e)
{
qDebug() << e.kind() << e.leakedBlocks() << e.leakedBytes() << e.what() << e.tid() << e.unique();
qDebug() << "stacks:" << e.stacks().size();
@@ -60,15 +51,61 @@ void dumpError(const Error &e)
qDebug() << s.auxWhat() << s.directory() << s.file() << s.line() << s.helgrindThreadId();
qDebug() << "frames:";
for (const Frame &f : s.frames()) {
dumpFrame(f);
qDebug() << f.instructionPointer() << f.directory() << f.fileName() << f.functionName()
<< f.line() << f.object();
}
}
}
class Recorder : public QObject
{
public:
explicit Recorder(Parser *parser)
{
connect(parser, &Parser::error, this, [this](const Error &err) { errors.append(err); });
connect(parser, &Parser::errorCount, this, [this](qint64 unique, qint64 count) {
errorcounts.push_back({unique, count});
});
connect(parser, &Parser::suppressionCount, this, [this](const QString &name, qint64 count) {
suppcounts.push_back({name, count});
});
}
QList<Error> errors;
QList<QPair<qint64, qint64>> errorcounts;
QList<QPair<QString, qint64>> suppcounts;
};
class RunnerDumper : public QObject
{
public:
explicit RunnerDumper(ValgrindRunner *runner)
{
connect(runner, &ValgrindRunner::error, this, [](const Error &err) {
qDebug() << "error received";
dumpError(err);
});
connect(runner, &ValgrindRunner::internalError, this, [](const QString &err) {
qDebug() << "internal error received:" << err;
});
connect(runner, &ValgrindRunner::status, this, [](const Status &status) {
qDebug() << "status received:" << status.state() << status.time();
});
connect(runner, &ValgrindRunner::logMessageReceived, this, [](const QByteArray &log) {
qDebug() << "log message received:" << log;
});
connect(runner, &ValgrindRunner::processErrorReceived, this, [this](const QString &) {
m_errorReceived = true;
});
}
bool m_errorReceived = false;
};
static QString fakeValgrindExecutable()
{
QString valgrindFakePath(VALGRIND_FAKE_PATH);
if (Utils::HostOsInfo::isWindowsHost()) {
const QString valgrindFakePath(VALGRIND_FAKE_PATH);
if (HostOsInfo::isWindowsHost()) {
QFileInfo fi(QString(valgrindFakePath + "/debug"), "valgrind-fake.exe");
if (fi.exists())
return fi.canonicalFilePath();
@@ -465,7 +502,7 @@ void ValgrindMemcheckParserTest::testParserStop()
void ValgrindMemcheckParserTest::testRealValgrind()
{
const Utils::Environment &sysEnv = Utils::Environment::systemEnvironment();
const Environment &sysEnv = Environment::systemEnvironment();
auto fileName = sysEnv.searchInPath("valgrind");
if (fileName.isEmpty())
QSKIP("This test needs valgrind in PATH");
@@ -510,7 +547,7 @@ void ValgrindMemcheckParserTest::testValgrindStartError()
ProjectExplorer::Runnable debuggeeExecutable;
debuggeeExecutable.command.setExecutable(FilePath::fromString(debuggee));
debuggeeExecutable.command.setArguments(debuggeeArgs);
debuggeeExecutable.environment = Utils::Environment::systemEnvironment();
debuggeeExecutable.environment = Environment::systemEnvironment();
ValgrindRunner runner;
runner.setValgrindCommand({FilePath::fromString(valgrindExe), valgrindArgs});
@@ -522,5 +559,4 @@ void ValgrindMemcheckParserTest::testValgrindStartError()
// just finish without deadlock and we are fine
}
} // namespace Test
} // namespace Valgrind
} // namespace Valgrind::Test

View File

@@ -4,103 +4,15 @@
#pragma once
#include <QObject>
#include <QPair>
#include <QStringList>
#include <QVector>
#include <QDebug>
#include "xmlprotocol/error.h"
#include "xmlprotocol/status.h"
#include "xmlprotocol/parser.h"
#include "valgrindrunner.h"
QT_BEGIN_NAMESPACE
class QProcess;
class QTcpServer;
class QTcpSocket;
class QProcess;
QT_END_NAMESPACE
namespace Valgrind {
namespace Test {
void dumpError(const Valgrind::XmlProtocol::Error &e);
class Recorder : public QObject
{
public:
explicit Recorder(XmlProtocol::Parser *parser)
{
connect(parser, &XmlProtocol::Parser::error,
this, &Recorder::error);
connect(parser, &XmlProtocol::Parser::errorCount,
this, &Recorder::errorCount);
connect(parser, &XmlProtocol::Parser::suppressionCount,
this, &Recorder::suppressionCount);
}
QList<Valgrind::XmlProtocol::Error> errors;
QVector<QPair<qint64,qint64> > errorcounts;
QVector<QPair<QString,qint64> > suppcounts;
public:
void error(const Valgrind::XmlProtocol::Error &err)
{
errors.append(err);
}
void errorCount(qint64 unique, qint64 count)
{
errorcounts.push_back({unique, count});
}
void suppressionCount(const QString &name, qint64 count)
{
suppcounts.push_back({name, count});
}
};
class RunnerDumper : public QObject
{
public:
explicit RunnerDumper(ValgrindRunner *runner)
{
connect(runner, &ValgrindRunner::error, this, &RunnerDumper::error);
connect(runner, &ValgrindRunner::internalError, this, &RunnerDumper::internalError);
connect(runner, &ValgrindRunner::status, this, &RunnerDumper::status);
connect(runner, &ValgrindRunner::logMessageReceived,
this, &RunnerDumper::logMessageReceived);
connect(runner, &ValgrindRunner::processErrorReceived,
this, &RunnerDumper::processErrorReceived);
}
void error(const Valgrind::XmlProtocol::Error &e)
{
qDebug() << "error received";
dumpError(e);
}
void internalError(const QString& error)
{
qDebug() << "internal error received:" << error;
}
void status(const Valgrind::XmlProtocol::Status &status)
{
qDebug() << "status received:" << status.state() << status.time();
}
void logMessageReceived(const QByteArray &log)
{
qDebug() << "log message received:" << log;
}
void processErrorReceived(const QString &s)
{
Q_UNUSED(s)
// qDebug() << "error received:" << s; // this can be a lot of text
m_errorReceived = true;
}
public:
bool m_errorReceived = false;
};
namespace Valgrind::Test {
class ValgrindMemcheckParserTest : public QObject
{
@@ -125,12 +37,11 @@ private slots:
void testValgrindStartError();
private:
void initTest(const QString &testfile, const QStringList &otherArgs = QStringList());
void initTest(const QString &testfile, const QStringList &otherArgs = {});
QTcpServer *m_server = nullptr;
QProcess *m_process = nullptr;
QTcpSocket *m_socket = nullptr;
};
} // namespace Test
} // namespace Valgrind
} // namespace Valgrind::Test