Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added test for PERF_FORMAT_LOST attribute #579

Merged
merged 3 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/parsers/perf/perfparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,9 +1055,10 @@ class PerfParserPrivate : public QObject
for (const auto& cost : sample.costs) {
if (core.costs.size() <= cost.attributeId) {
const auto oldSize = core.costs.size();
core.costs.resize(cost.attributeId + 1);
const auto newSize = cost.attributeId + 1;
milianw marked this conversation as resolved.
Show resolved Hide resolved
core.costs.resize(newSize);

for (int i = oldSize; i < core.costs.size(); i++) {
for (int i = oldSize; i < newSize; i++) {
core.costs[i].costName = strings.at(attributes[i].name.id);
}
}
Expand Down
Binary file added tests/integrationtests/perf.data.PerfFormatLost
Binary file not shown.
34 changes: 22 additions & 12 deletions tests/integrationtests/tst_perfparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class TestPerfParser : public QObject
private slots:
void initTestCase()
{
qputenv("DEBUGINFOD_URLS", {});
RecordHost host;
QSignalSpy capabilitiesSpy(&host, &RecordHost::perfCapabilitiesChanged);
QSignalSpy installedSpy(&host, &RecordHost::isPerfInstalledChanged);
Expand Down Expand Up @@ -230,22 +231,19 @@ private slots:
{
QTest::addColumn<QString>("perfFile");
QTest::addColumn<QString>("errorMessagePart");
QTest::addColumn<int>("waitTime");

const auto perfData = QFINDTESTDATA("file_content/true.perfparser");
QTest::addRow("pre-exported perfparser") << perfData << QString() << 2000;
QTest::addRow("pre-exported perfparser") << perfData << QString();
const auto perfDataSomeName = QStringLiteral("fruitper");
QFile::copy(perfData, perfDataSomeName); // we can ignore errors (file exist) here
QTest::addRow("pre-exported perfparser \"bad extension\"") << perfDataSomeName << QString() << 2000;
QTest::addRow("pre-exported perfparser \"bad extension\"") << perfDataSomeName << QString();
QTest::addRow("no expected magic header")
<< QFINDTESTDATA("tst_perfparser.cpp") << QStringLiteral("File format unknown") << 1000;
QTest::addRow("PERF v1") << QFINDTESTDATA("file_content/perf.data.true.v1") << QStringLiteral("V1 perf data")
<< 1000;
<< QFINDTESTDATA("tst_perfparser.cpp") << QStringLiteral("File format unknown");
QTest::addRow("PERF v1") << QFINDTESTDATA("file_content/perf.data.true.v1") << QStringLiteral("V1 perf data");

// TODO: check why we need this long waittime
QTest::addRow("PERF v2") << QFINDTESTDATA("file_content/perf.data.true.v2") << QString() << 9000;
QTest::addRow("PERF v2") << QFINDTESTDATA("file_content/perf.data.true.v2") << QString();
#if KFArchive_FOUND
QTest::addRow("PERF v2, gzipped") << QFINDTESTDATA("file_content/perf.data.true.v2.gz") << QString() << 10000;
QTest::addRow("PERF v2, gzipped") << QFINDTESTDATA("file_content/perf.data.true.v2.gz") << QString();
#endif
}

Expand All @@ -265,27 +263,39 @@ private slots:

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

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

if (errorMessagePart.isEmpty()) {
// if we don't expect an error message (Null String created by `QString()`)
// then expect a finish within the given time frame
QTRY_COMPARE_WITH_TIMEOUT(parsingFinishedSpy.count(), 1, waitTime);
QTRY_COMPARE_WITH_TIMEOUT(parsingFinishedSpy.count(), 1, 2000);
QCOMPARE(parsingFailedSpy.count(), 0);
} else {
// otherwise wait for failed parsing, the check for if the required part is
// found in the error message (we only check a part to allow adjustments later)
QTRY_COMPARE_WITH_TIMEOUT(parsingFailedSpy.count(), 1, waitTime);
QTRY_COMPARE_WITH_TIMEOUT(parsingFailedSpy.count(), 1, 2000);
QCOMPARE(parsingFinishedSpy.count(), 0);
const auto message = parsingFailedSpy.takeFirst().at(0).toString();
QVERIFY(message.contains(errorMessagePart));
QVERIFY(message.contains(perfFile));
}
}

/* tests a perf file that has data with PERF_FORMAT_LOST attribute, see KDAB/hotspot#578 */
void testPerfFormatLost()
{
PerfParser parser(this);
QSignalSpy parsingFailedSpy(&parser, &PerfParser::parsingFailed);
QSignalSpy parsingFinishedSpy(&parser, &PerfParser::parsingFinished);

parser.startParseFile(QFINDTESTDATA("perf.data.PerfFormatLost"));

QTRY_COMPARE_WITH_TIMEOUT(parsingFinishedSpy.count(), 1, 58000);
QCOMPARE(parsingFailedSpy.count(), 0);
}

void testCppInliningNoOptions()
{
const QStringList perfOptions;
Expand Down