Skip to content

Commit

Permalink
added missing tests for handling perf data files
Browse files Browse the repository at this point in the history
  • Loading branch information
GitMensch committed Nov 7, 2023
1 parent 15d51e7 commit abb544c
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
84 changes: 84 additions & 0 deletions tests/integrationtests/tst_perfparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,90 @@ private slots:
m_machineHostName = QSysInfo::machineHostName();
}

void testFileErrorHandling()
{
PerfParser parser(this);
QSignalSpy parsingFailedSpy(&parser, &PerfParser::parsingFailed);
QString message;

const auto notThereFile = QStringLiteral("not_here");
parser.initParserArgs(notThereFile);

QCOMPARE(parsingFailedSpy.count(), 1);
message = qvariant_cast<QString>(parsingFailedSpy.takeFirst().at(0));
QVERIFY(message.contains(notThereFile));
QVERIFY(message.contains(QLatin1String("does not exist")));

const auto parentDirs = QStringLiteral("../..");
parser.initParserArgs(parentDirs);
// note: initializing parser args reset the attached spy counter
QCOMPARE(parsingFailedSpy.count(), 1);
message = qvariant_cast<QString>(parsingFailedSpy.takeFirst().at(0));
QVERIFY(message.contains(parentDirs));
QVERIFY(message.contains(QLatin1String("is not a file")));

const auto noRead = QStringLiteral("no_r_possible");
const auto shell = QStandardPaths::findExecutable(QStringLiteral("bash"));
if (!shell.isEmpty()) {
QProcess::execute(
shell, {QLatin1String("-c"), QStringLiteral("rm -rf %1 && touch %1 && chmod a-r %1").arg(noRead)});
parser.initParserArgs(noRead);

QCOMPARE(parsingFailedSpy.count(), 1);
message = qvariant_cast<QString>(parsingFailedSpy.takeFirst().at(0));
QVERIFY(message.contains(noRead));
QVERIFY(message.contains(QLatin1String("not readable")));
}
}

void testFileContent_data()
{
QTest::addColumn<QString>("perfFile");
QTest::addColumn<QString>("errorMessagePart");
QTest::addColumn<int>("waitTime");

QTest::addRow("pre-exported perfparser") << QFINDTESTDATA("file_content/true.perfparser") << QString() << 2000;
QTest::addRow("invalid data") << QFINDTESTDATA("tst_perfparser.cpp") << QStringLiteral("invalid perf data file")
<< 1000;
QTest::addRow("PERF v1") << QFINDTESTDATA("file_content/perf.data.true.v1")
<< QStringLiteral("invalid perf data file") << 1000;

/* FIXME: this waittime and the one below must be so high as unavailable elf files are checked
again and again via PerfSymbolTable::registerElf, as seen in the output */
QTest::addRow("PERF v2") << QFINDTESTDATA("file_content/perf.data.true.v2") << QString() << 8000;
#if KFArchive_FOUND
QTest::addRow("PERF v2 gz") << QFINDTESTDATA("file_content/perf.data.true.v2.gz") << QString() << 9000;
#endif
}

void testFileContent()
{
Settings::instance()->setAppPath(
QFileInfo(QStandardPaths::findExecutable(QStringLiteral("true"))).dir().path());
Settings::instance()->setExtraLibPaths(QFINDTESTDATA("file_content"));

PerfParser parser(this);
QSignalSpy parsingFailedSpy(&parser, &PerfParser::parsingFailed);
QSignalSpy parsingFinishedSpy(&parser, &PerfParser::parsingFinished);

QFETCH(QString, perfFile);
QFETCH(QString, errorMessagePart);
QFETCH(int, waitTime);

QVERIFY(!perfFile.isEmpty() && QFile::exists(perfFile));
parser.startParseFile(perfFile);

if (errorMessagePart.isNull()) {
QTRY_COMPARE_WITH_TIMEOUT(parsingFinishedSpy.count(), 1, waitTime);
QCOMPARE(parsingFailedSpy.count(), 0);
} else {
QTRY_COMPARE_WITH_TIMEOUT(parsingFailedSpy.count(), 1, waitTime);
QCOMPARE(parsingFinishedSpy.count(), 0);
const auto message = qvariant_cast<QString>(parsingFailedSpy.takeFirst().at(0));
QVERIFY(message.contains(errorMessagePart));
}
}

void testCppInliningNoOptions()
{
const QStringList perfOptions;
Expand Down

0 comments on commit abb544c

Please sign in to comment.