diff --git a/src/parsers/perf/perfparser.cpp b/src/parsers/perf/perfparser.cpp index 1a0ecfb9..0f15db01 100644 --- a/src/parsers/perf/perfparser.cpp +++ b/src/parsers/perf/perfparser.cpp @@ -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; + 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); } } diff --git a/tests/integrationtests/perf.data.PerfFormatLost b/tests/integrationtests/perf.data.PerfFormatLost new file mode 100644 index 00000000..04605d8a Binary files /dev/null and b/tests/integrationtests/perf.data.PerfFormatLost differ diff --git a/tests/integrationtests/tst_perfparser.cpp b/tests/integrationtests/tst_perfparser.cpp index 17a79bc9..421c82ba 100644 --- a/tests/integrationtests/tst_perfparser.cpp +++ b/tests/integrationtests/tst_perfparser.cpp @@ -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); @@ -230,22 +231,19 @@ private slots: { QTest::addColumn("perfFile"); QTest::addColumn("errorMessagePart"); - QTest::addColumn("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 } @@ -265,7 +263,6 @@ private slots: QFETCH(QString, perfFile); QFETCH(QString, errorMessagePart); - QFETCH(int, waitTime); QVERIFY(!perfFile.isEmpty() && QFile::exists(perfFile)); parser.startParseFile(perfFile); @@ -273,12 +270,12 @@ private slots: 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)); @@ -286,6 +283,19 @@ private slots: } } + /* 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;