Skip to content

Commit

Permalink
cleanup perfparser tests
Browse files Browse the repository at this point in the history
* dropped unused headers
* COMPARE_OR_THROW -> QCOMPARE
* VERIFY_OR_THROW -> QVERIFY
  • Loading branch information
GitMensch committed Nov 7, 2023
1 parent 89c3808 commit 15d51e7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ build*/
elfutils.build.tar.bz2
rustc_demangle.build.tar.bz2
d-demangle.tar.gz
*.actual
*.actual*
*.orig
scripts/output
92 changes: 44 additions & 48 deletions tests/integrationtests/tst_perfparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
#include "perfparser.h"
#include "perfrecord.h"
#include "recordhost.h"
#include "unistd.h"
#include "util.h"

#include "../testutils.h"
#include <hotspot-config.h>

#include <exception>

namespace {
template<typename T>
bool searchForChildSymbol(const T& root, const QString& searchString, bool exact = true)
Expand Down Expand Up @@ -741,11 +738,11 @@ private slots:
+ QStringList {QStringLiteral("-c"), QStringLiteral("1000000"), QStringLiteral("--no-buildid-cache")},
fileName, false, exePath, exeOptions);

VERIFY_OR_THROW(recordingFinishedSpy.wait(10000));
QVERIFY(recordingFinishedSpy.wait(10000));

COMPARE_OR_THROW(recordingFailedSpy.count(), 0);
COMPARE_OR_THROW(recordingFinishedSpy.count(), 1);
COMPARE_OR_THROW(QFileInfo::exists(fileName), true);
QCOMPARE(recordingFailedSpy.count(), 0);
QCOMPARE(recordingFinishedSpy.count(), 1);
QCOMPARE(QFileInfo::exists(fileName), true);

m_perfCommand = perf.perfCommand();
}
Expand All @@ -768,7 +765,7 @@ private slots:
r = p;
}
}
VERIFY_OR_THROW(hasCost);
QVERIFY(hasCost);
}
for (const auto& child : row.children) {
validateCosts(costs, child);
Expand All @@ -790,39 +787,38 @@ private slots:

parser.startParseFile(fileName);

VERIFY_OR_THROW(parsingFinishedSpy.wait(6000));
QVERIFY(parsingFinishedSpy.wait(6000));

// Verify that the test passed
COMPARE_OR_THROW(parsingFailedSpy.count(), 0);
COMPARE_OR_THROW(parsingFinishedSpy.count(), 1);
QCOMPARE(parsingFailedSpy.count(), 0);
QCOMPARE(parsingFinishedSpy.count(), 1);

// Verify the summary data isn't empty
COMPARE_OR_THROW(summaryDataSpy.count(), 1);
QCOMPARE(summaryDataSpy.count(), 1);
QList<QVariant> summaryDataArgs = summaryDataSpy.takeFirst();
m_summaryData = qvariant_cast<Data::Summary>(summaryDataArgs.at(0));
COMPARE_OR_THROW(m_perfCommand, m_summaryData.command);
VERIFY_OR_THROW(m_summaryData.sampleCount > 0);
VERIFY_OR_THROW(m_summaryData.applicationTime.delta() > 0);
VERIFY_OR_THROW(m_summaryData.cpusAvailable > 0);
COMPARE_OR_THROW(m_summaryData.processCount, quint32(1)); // for now we always have a single process
VERIFY_OR_THROW(m_summaryData.threadCount > 0); // and at least one thread
COMPARE_OR_THROW(m_summaryData.cpuArchitecture, m_cpuArchitecture);
COMPARE_OR_THROW(m_summaryData.linuxKernelVersion, m_linuxKernelVersion);
COMPARE_OR_THROW(m_summaryData.hostName, m_machineHostName);
QCOMPARE(m_perfCommand, m_summaryData.command);
QVERIFY(m_summaryData.sampleCount > 0);
QVERIFY(m_summaryData.applicationTime.delta() > 0);
QVERIFY(m_summaryData.cpusAvailable > 0);
QCOMPARE(m_summaryData.processCount, quint32(1)); // for now we always have a single process
QVERIFY(m_summaryData.threadCount > 0); // and at least one thread
QCOMPARE(m_summaryData.cpuArchitecture, m_cpuArchitecture);
QCOMPARE(m_summaryData.linuxKernelVersion, m_linuxKernelVersion);
QCOMPARE(m_summaryData.hostName, m_machineHostName);

if (checkFrequency) {
// Verify the sample frequency is acceptable, greater than 500Hz
double frequency = (1E9 * m_summaryData.sampleCount) / m_summaryData.applicationTime.delta();
VERIFY_OR_THROW2(frequency > 500,
qPrintable(QLatin1String("Low Frequency: ") + QString::number(frequency)));
QVERIFY2(frequency > 500, qPrintable(QLatin1String("Low Frequency: ") + QString::number(frequency)));
}

// Verify the top Bottom-Up symbol result contains the expected data
COMPARE_OR_THROW(bottomUpDataSpy.count(), 1);
QCOMPARE(bottomUpDataSpy.count(), 1);
QList<QVariant> bottomUpDataArgs = bottomUpDataSpy.takeFirst();
m_bottomUpData = bottomUpDataArgs.at(0).value<Data::BottomUpResults>();
validateCosts(m_bottomUpData.costs, m_bottomUpData.root);
VERIFY_OR_THROW(m_bottomUpData.root.children.count() > 0);
QVERIFY(m_bottomUpData.root.children.count() > 0);

if (topBottomUpSymbol.isValid()) {
int bottomUpTopIndex = maxElementTopIndex(m_bottomUpData);
Expand All @@ -831,14 +827,14 @@ private slots:
if (actualTopBottomUpSymbol == ComparableSymbol(QStringLiteral("__FRAME_END__"), {})) {
QEXPECT_FAIL("", "bad symbol offsets - bug in mmap handling or symbol cache?", Continue);
}
COMPARE_OR_THROW(actualTopBottomUpSymbol, topBottomUpSymbol);
QCOMPARE(actualTopBottomUpSymbol, topBottomUpSymbol);
}

// Verify the top Top-Down symbol result contains the expected data
COMPARE_OR_THROW(topDownDataSpy.count(), 1);
QCOMPARE(topDownDataSpy.count(), 1);
QList<QVariant> topDownDataArgs = topDownDataSpy.takeFirst();
m_topDownData = topDownDataArgs.at(0).value<Data::TopDownResults>();
VERIFY_OR_THROW(m_topDownData.root.children.count() > 0);
QVERIFY(m_topDownData.root.children.count() > 0);

if (topTopDownSymbol.isValid()
&& QLatin1String(QTest::currentTestFunction()) != QLatin1String("testCppRecursionCallGraphDwarf")) {
Expand All @@ -848,40 +844,40 @@ private slots:
if (actualTopTopDownSymbol == ComparableSymbol(QStringLiteral("__FRAME_END__"), {})) {
QEXPECT_FAIL("", "bad symbol offsets - bug in mmap handling or symbol cache?", Continue);
}
COMPARE_OR_THROW(actualTopTopDownSymbol, topTopDownSymbol);
QCOMPARE(actualTopTopDownSymbol, topTopDownSymbol);
}

// Verify the Caller/Callee data isn't empty
COMPARE_OR_THROW(callerCalleeDataSpy.count(), 1);
QCOMPARE(callerCalleeDataSpy.count(), 1);
QList<QVariant> callerCalleeDataArgs = callerCalleeDataSpy.takeFirst();
m_callerCalleeData = callerCalleeDataArgs.at(0).value<Data::CallerCalleeResults>();
VERIFY_OR_THROW(m_callerCalleeData.entries.count() > 0);
QVERIFY(m_callerCalleeData.entries.count() > 0);

// Verify that no individual cost in the Caller/Callee data is greater than the total cost of all samples
for (const auto& entry : std::as_const(m_callerCalleeData.entries)) {
VERIFY_OR_THROW(m_callerCalleeData.inclusiveCosts.cost(0, entry.id)
<= static_cast<qint64>(m_summaryData.costs[0].totalPeriod));
QVERIFY(m_callerCalleeData.inclusiveCosts.cost(0, entry.id)
<= static_cast<qint64>(m_summaryData.costs[0].totalPeriod));
}

// Verify that the events data is not empty and somewhat sane
COMPARE_OR_THROW(eventsDataSpy.count(), 1);
QCOMPARE(eventsDataSpy.count(), 1);
m_eventData = eventsDataSpy.first().first().value<Data::EventResults>();
VERIFY_OR_THROW(!m_eventData.stacks.isEmpty());
VERIFY_OR_THROW(!m_eventData.threads.isEmpty());
COMPARE_OR_THROW(static_cast<quint32>(m_eventData.threads.size()), m_summaryData.threadCount);
QVERIFY(!m_eventData.stacks.isEmpty());
QVERIFY(!m_eventData.threads.isEmpty());
QCOMPARE(static_cast<quint32>(m_eventData.threads.size()), m_summaryData.threadCount);
for (const auto& thread : std::as_const(m_eventData.threads)) {
VERIFY_OR_THROW(!thread.name.isEmpty());
VERIFY_OR_THROW(thread.pid != 0);
VERIFY_OR_THROW(thread.tid != 0);
VERIFY_OR_THROW(thread.time.isValid());
VERIFY_OR_THROW(thread.time.end > thread.time.start);
VERIFY_OR_THROW(thread.offCpuTime == 0 || thread.offCpuTime < thread.time.delta());
}
VERIFY_OR_THROW(!m_eventData.totalCosts.isEmpty());
QVERIFY(!thread.name.isEmpty());
QVERIFY(thread.pid != 0);
QVERIFY(thread.tid != 0);
QVERIFY(thread.time.isValid());
QVERIFY(thread.time.end > thread.time.start);
QVERIFY(thread.offCpuTime == 0 || thread.offCpuTime < thread.time.delta());
}
QVERIFY(!m_eventData.totalCosts.isEmpty());
for (const auto& costs : std::as_const(m_eventData.totalCosts)) {
VERIFY_OR_THROW(!costs.label.isEmpty());
VERIFY_OR_THROW(costs.sampleCount > 0);
VERIFY_OR_THROW(costs.totalPeriod > 0);
QVERIFY(!costs.label.isEmpty());
QVERIFY(costs.sampleCount > 0);
QVERIFY(costs.totalPeriod > 0);
}
}
};
Expand Down

0 comments on commit 15d51e7

Please sign in to comment.