forked from qt-creator/qt-creator
Valgrind: Move test object creation closer to tested code
Change-Id: I896c7f7c1d99a62bc869f3511c036123a78afc29 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -11,10 +11,13 @@
|
|||||||
#include "xmlprotocol/status.h"
|
#include "xmlprotocol/status.h"
|
||||||
#include "xmlprotocol/suppression.h"
|
#include "xmlprotocol/suppression.h"
|
||||||
|
|
||||||
|
#include <utils/process.h>
|
||||||
#include <utils/processinterface.h>
|
#include <utils/processinterface.h>
|
||||||
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QStringList>
|
||||||
#include <QTcpServer>
|
#include <QTcpServer>
|
||||||
|
#include <QTcpSocket>
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
@@ -24,14 +27,14 @@ QT_BEGIN_NAMESPACE
|
|||||||
namespace QTest {
|
namespace QTest {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline bool qCompare(int const &t1, MemcheckError const &t2,
|
bool qCompare(int const &t1, MemcheckError const &t2,
|
||||||
char const *actual, char const *expected, char const *file, int line)
|
char const *actual, char const *expected, char const *file, int line)
|
||||||
{
|
{
|
||||||
return qCompare(t1, int(t2), actual, expected, file, line);
|
return qCompare(t1, int(t2), actual, expected, file, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool qCompare(const QString &t1, char const *t2,
|
bool qCompare(const QString &t1, char const *t2,
|
||||||
char const *actual, char const *expected, char const *file, int line)
|
char const *actual, char const *expected, char const *file, int line)
|
||||||
{
|
{
|
||||||
return qCompare(t1, QString::fromLatin1(t2), actual, expected, file, line);
|
return qCompare(t1, QString::fromLatin1(t2), actual, expected, file, line);
|
||||||
}
|
}
|
||||||
@@ -39,7 +42,37 @@ inline bool qCompare(const QString &t1, char const *t2,
|
|||||||
} // namespace QTest
|
} // namespace QTest
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Valgrind::Test {
|
namespace Valgrind::Internal {
|
||||||
|
|
||||||
|
class ValgrindMemcheckParserTest : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void initTestCase();
|
||||||
|
void cleanup();
|
||||||
|
|
||||||
|
void testMemcheckSample1();
|
||||||
|
void testMemcheckSample2();
|
||||||
|
void testMemcheckSample3();
|
||||||
|
void testMemcheckCharm();
|
||||||
|
void testHelgrindSample1();
|
||||||
|
|
||||||
|
void testValgrindCrash();
|
||||||
|
void testValgrindGarbage();
|
||||||
|
|
||||||
|
void testParserStop();
|
||||||
|
void testRealValgrind();
|
||||||
|
void testValgrindStartError_data();
|
||||||
|
void testValgrindStartError();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void initTest(const QString &testfile, const QStringList &otherArgs = {});
|
||||||
|
|
||||||
|
QTcpServer *m_server = nullptr;
|
||||||
|
std::unique_ptr<Utils::Process> m_process;
|
||||||
|
std::unique_ptr<QTcpSocket> m_socket;
|
||||||
|
};
|
||||||
|
|
||||||
static void dumpError(const Error &e)
|
static void dumpError(const Error &e)
|
||||||
{
|
{
|
||||||
@@ -555,4 +588,11 @@ void ValgrindMemcheckParserTest::testValgrindStartError()
|
|||||||
// just finish without deadlock and we are fine
|
// just finish without deadlock and we are fine
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Valgrind::Test
|
QObject *createValgrindMemcheckParserTest()
|
||||||
|
{
|
||||||
|
return new ValgrindMemcheckParserTest;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Valgrind::Internal
|
||||||
|
|
||||||
|
#include "valgrindmemcheckparsertest.moc"
|
||||||
|
@@ -3,45 +3,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <utils/process.h>
|
#include <QObject>
|
||||||
|
|
||||||
#include <QStringList>
|
namespace Valgrind::Internal {
|
||||||
#include <QTcpSocket>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QObject *createValgrindMemcheckParserTest();
|
||||||
class QTcpServer;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace Valgrind::Test {
|
} // Valgrind::Internal
|
||||||
|
|
||||||
class ValgrindMemcheckParserTest : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void initTestCase();
|
|
||||||
void cleanup();
|
|
||||||
|
|
||||||
void testMemcheckSample1();
|
|
||||||
void testMemcheckSample2();
|
|
||||||
void testMemcheckSample3();
|
|
||||||
void testMemcheckCharm();
|
|
||||||
void testHelgrindSample1();
|
|
||||||
|
|
||||||
void testValgrindCrash();
|
|
||||||
void testValgrindGarbage();
|
|
||||||
|
|
||||||
void testParserStop();
|
|
||||||
void testRealValgrind();
|
|
||||||
void testValgrindStartError_data();
|
|
||||||
void testValgrindStartError();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void initTest(const QString &testfile, const QStringList &otherArgs = {});
|
|
||||||
|
|
||||||
QTcpServer *m_server = nullptr;
|
|
||||||
std::unique_ptr<Utils::Process> m_process;
|
|
||||||
std::unique_ptr<QTcpSocket> m_socket;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Valgrind::Test
|
|
||||||
|
@@ -54,8 +54,8 @@ public:
|
|||||||
|
|
||||||
RunConfiguration::registerAspect<ValgrindRunConfigurationAspect>();
|
RunConfiguration::registerAspect<ValgrindRunConfigurationAspect>();
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
addTest<Test::ValgrindMemcheckParserTest>();
|
addTestCreator(createValgrindMemcheckParserTest);
|
||||||
addTest<Test::ValgrindTestRunnerTest>();
|
addTestCreator(createValgrindTestRunnerTest);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
#include "valgrindtestrunnertest.h"
|
#include "valgrindtestrunnertest.h"
|
||||||
|
|
||||||
#include "valgrindprocess.h"
|
#include "valgrindprocess.h"
|
||||||
|
#include "xmlprotocol/error.h"
|
||||||
#include "xmlprotocol/frame.h"
|
#include "xmlprotocol/frame.h"
|
||||||
#include "xmlprotocol/stack.h"
|
#include "xmlprotocol/stack.h"
|
||||||
|
|
||||||
@@ -12,6 +13,7 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QStringList>
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
|
|
||||||
#define HEADER_LENGTH 3
|
#define HEADER_LENGTH 3
|
||||||
@@ -19,9 +21,7 @@
|
|||||||
using namespace Valgrind::XmlProtocol;
|
using namespace Valgrind::XmlProtocol;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Valgrind::Test {
|
namespace Valgrind::Internal {
|
||||||
|
|
||||||
//BEGIN Test Helpers and boilerplate code
|
|
||||||
|
|
||||||
static const QString appSrcDir(TESTRUNNER_SRC_DIR);
|
static const QString appSrcDir(TESTRUNNER_SRC_DIR);
|
||||||
static const QString appBinDir(TESTRUNNER_APP_DIR);
|
static const QString appBinDir(TESTRUNNER_APP_DIR);
|
||||||
@@ -36,6 +36,46 @@ static QString srcDirForApp(const QString &app)
|
|||||||
return QDir::cleanPath(appSrcDir + '/' + app);
|
return QDir::cleanPath(appSrcDir + '/' + app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ValgrindTestRunnerTest : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ValgrindTestRunnerTest(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void init();
|
||||||
|
void cleanup();
|
||||||
|
|
||||||
|
void testLeak1();
|
||||||
|
void testLeak2();
|
||||||
|
void testLeak3();
|
||||||
|
void testLeak4();
|
||||||
|
|
||||||
|
void testUninit1();
|
||||||
|
void testUninit2();
|
||||||
|
void testUninit3();
|
||||||
|
|
||||||
|
void testFree1();
|
||||||
|
void testFree2();
|
||||||
|
|
||||||
|
void testInvalidjump();
|
||||||
|
void testSyscall();
|
||||||
|
void testOverlap();
|
||||||
|
|
||||||
|
void logMessageReceived(const QByteArray &message);
|
||||||
|
void internalError(const QString &error);
|
||||||
|
void error(const Valgrind::XmlProtocol::Error &error);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString runTestBinary(const QString &binary, const QStringList &vArgs = QStringList());
|
||||||
|
|
||||||
|
ValgrindProcess *m_runner = nullptr;
|
||||||
|
QList<QByteArray> m_logMessages;
|
||||||
|
QList<XmlProtocol::Error> m_errors;
|
||||||
|
bool m_expectCrash = false;
|
||||||
|
};
|
||||||
|
|
||||||
ValgrindTestRunnerTest::ValgrindTestRunnerTest(QObject *parent)
|
ValgrindTestRunnerTest::ValgrindTestRunnerTest(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
@@ -749,4 +789,11 @@ void ValgrindTestRunnerTest::testOverlap()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Valgrind::Test
|
QObject *createValgrindTestRunnerTest()
|
||||||
|
{
|
||||||
|
return new ValgrindTestRunnerTest;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Valgrind::Internal
|
||||||
|
|
||||||
|
#include "valgrindtestrunnertest.moc"
|
||||||
|
@@ -3,53 +3,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "xmlprotocol/error.h"
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
namespace Valgrind { class ValgrindProcess; }
|
namespace Valgrind::Internal {
|
||||||
|
|
||||||
namespace Valgrind::Test {
|
QObject *createValgrindTestRunnerTest();
|
||||||
|
|
||||||
class ValgrindTestRunnerTest : public QObject
|
} // Valgrind::Internal
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit ValgrindTestRunnerTest(QObject *parent = nullptr);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void init();
|
|
||||||
void cleanup();
|
|
||||||
|
|
||||||
void testLeak1();
|
|
||||||
void testLeak2();
|
|
||||||
void testLeak3();
|
|
||||||
void testLeak4();
|
|
||||||
|
|
||||||
void testUninit1();
|
|
||||||
void testUninit2();
|
|
||||||
void testUninit3();
|
|
||||||
|
|
||||||
void testFree1();
|
|
||||||
void testFree2();
|
|
||||||
|
|
||||||
void testInvalidjump();
|
|
||||||
void testSyscall();
|
|
||||||
void testOverlap();
|
|
||||||
|
|
||||||
void logMessageReceived(const QByteArray &message);
|
|
||||||
void internalError(const QString &error);
|
|
||||||
void error(const Valgrind::XmlProtocol::Error &error);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString runTestBinary(const QString &binary, const QStringList &vArgs = QStringList());
|
|
||||||
|
|
||||||
ValgrindProcess *m_runner = nullptr;
|
|
||||||
QList<QByteArray> m_logMessages;
|
|
||||||
QList<XmlProtocol::Error> m_errors;
|
|
||||||
bool m_expectCrash = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Valgrind::Test
|
|
||||||
|
Reference in New Issue
Block a user