Skip to content

Commit

Permalink
Unbreak tst_perfparser::testCustomCostAggregation
Browse files Browse the repository at this point in the history
Do not assume the data comes from the same machine we are running
the test on. Don't use assertions and don't overwrite the expected
data file. Write to a different file and then diff that if needed.
Don't enforce UTF8 strings, write to QByteArray directly.

The expected files also seem to be wrong, I'm updating them now
based on the results from my machine.
  • Loading branch information
milianw committed Jun 6, 2022
1 parent d0fb09e commit 8482895
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 132 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ build*/
elfutils.build.tar.bz2
rustc_demangle.build.tar.bz2
d-demangle.tar.gz
*.actual
Original file line number Diff line number Diff line change
Expand Up @@ -75,43 +75,6 @@
__libc_start_call_main
__libc_start_main_alias_2
_start
__schedule
__schedule
schedule
do_nanosleep
hrtimer_nanosleep
common_nsleep
__x64_sys_clock_nanosleep
do_syscall_64
entry_SYSCALL_64_after_hwframe
__clock_nanosleep
__GI___nanosleep
void std::this_thread::sleep_for<long, std::ratio<1l, 1000l> >(std::chrono::duration<long, std::ratio<1l, 1000l> > const&)
void std::this_thread::sleep_for<long, std::ratio<1l, 1000l> >(std::chrono::duration<long, std::ratio<1l, 1000l> > const&)
std::__invoke_impl<void, main()::<lambda()> >::operator()
std::__invoke_impl<void, main()::<lambda()> >
std::__invoke<main()::<lambda()> >
std::thread::_Invoker<std::tuple<main()::<lambda()> > >::_M_invoke<0>
std::thread::_Invoker<std::tuple<main()::<lambda()> > >::operator()
std::thread::_State_impl<std::thread::_Invoker<std::tuple<main()::<lambda()> > > >::_M_run
std::execute_native_thread_routine
start_thread
__GI___clone
futex_wait_queue
futex_wait
do_futex
__x64_sys_futex
do_syscall_64
entry_SYSCALL_64_after_hwframe
__futex_abstimed_wait_common
__pthread_clockjoin_ex
std::thread::join()::__gthread_join
std::thread::join()::__gthread_join
std::thread::join()
main
__libc_start_call_main
__libc_start_main_alias_2
_start
CPU 1
__schedule
__schedule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,3 @@
std::execute_native_thread_routine
start_thread
__GI___clone
__schedule
__schedule
schedule
do_nanosleep
hrtimer_nanosleep
common_nsleep
__x64_sys_clock_nanosleep
do_syscall_64
entry_SYSCALL_64_after_hwframe
__clock_nanosleep
__GI___nanosleep
void std::this_thread::sleep_for<long, std::ratio<1l, 1000l> >(std::chrono::duration<long, std::ratio<1l, 1000l> > const&)
void std::this_thread::sleep_for<long, std::ratio<1l, 1000l> >(std::chrono::duration<long, std::ratio<1l, 1000l> > const&)
std::__invoke_impl<void, main()::<lambda()> >::operator()
std::__invoke_impl<void, main()::<lambda()> >
std::__invoke<main()::<lambda()> >
std::thread::_Invoker<std::tuple<main()::<lambda()> > >::_M_invoke<0>
std::thread::_Invoker<std::tuple<main()::<lambda()> > >::operator()
std::thread::_State_impl<std::thread::_Invoker<std::tuple<main()::<lambda()> > > >::_M_run
std::execute_native_thread_routine
start_thread
__GI___clone
futex_wait_queue
futex_wait
do_futex
__x64_sys_futex
do_syscall_64
entry_SYSCALL_64_after_hwframe
__futex_abstimed_wait_common
__pthread_clockjoin_ex
std::thread::join()::__gthread_join
std::thread::join()::__gthread_join
std::thread::join()
main
__libc_start_call_main
__libc_start_main_alias_2
_start
Original file line number Diff line number Diff line change
Expand Up @@ -41,43 +41,6 @@
std::execute_native_thread_routine
start_thread
__GI___clone
__schedule
__schedule
schedule
do_nanosleep
hrtimer_nanosleep
common_nsleep
__x64_sys_clock_nanosleep
do_syscall_64
entry_SYSCALL_64_after_hwframe
__clock_nanosleep
__GI___nanosleep
void std::this_thread::sleep_for<long, std::ratio<1l, 1000l> >(std::chrono::duration<long, std::ratio<1l, 1000l> > const&)
void std::this_thread::sleep_for<long, std::ratio<1l, 1000l> >(std::chrono::duration<long, std::ratio<1l, 1000l> > const&)
std::__invoke_impl<void, main()::<lambda()> >::operator()
std::__invoke_impl<void, main()::<lambda()> >
std::__invoke<main()::<lambda()> >
std::thread::_Invoker<std::tuple<main()::<lambda()> > >::_M_invoke<0>
std::thread::_Invoker<std::tuple<main()::<lambda()> > >::operator()
std::thread::_State_impl<std::thread::_Invoker<std::tuple<main()::<lambda()> > > >::_M_run
std::execute_native_thread_routine
start_thread
__GI___clone
futex_wait_queue
futex_wait
do_futex
__x64_sys_futex
do_syscall_64
entry_SYSCALL_64_after_hwframe
__futex_abstimed_wait_common
__pthread_clockjoin_ex
std::thread::join()::__gthread_join
std::thread::join()::__gthread_join
std::thread::join()
main
__libc_start_call_main
__libc_start_main_alias_2
_start
threadname1
__schedule
__schedule
Expand Down
63 changes: 42 additions & 21 deletions tests/integrationtests/tst_perfparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ QString findExe(const QString& name)
return exe.canonicalFilePath();
}

void dump(const Data::BottomUp& bottomUp, QTextStream& stream, const QByteArray& prefix)
{
stream << prefix << bottomUp.symbol.symbol << '\n';

for (const auto& child : bottomUp.children) {
dump(child, stream, prefix + '\t');
}
}

class TestPerfParser : public QObject
{
Q_OBJECT
Expand All @@ -176,6 +185,9 @@ private slots:
m_callerCalleeData = {};
m_summaryData = {};
m_perfCommand.clear();
m_cpuArchitecture = QSysInfo::currentCpuArchitecture();
m_linuxKernelVersion = QSysInfo::kernelVersion();
m_machineHostName = QSysInfo::machineHostName();
}

void testCppInliningNoOptions()
Expand Down Expand Up @@ -598,15 +610,6 @@ private slots:
}
}

void dump(const Data::BottomUp& bottomUp, QTextStream& stream, const QString& prefix)
{
stream << prefix << bottomUp.symbol.symbol << QLatin1Char('\n');

for (const auto& child : bottomUp.children) {
dump(child, stream, prefix + QLatin1Char('\t'));
}
}

void testCustomCostAggregation_data()
{
QTest::addColumn<Settings::CostAggregation>("aggregation");
Expand All @@ -623,27 +626,42 @@ private slots:
QFETCH(Settings::CostAggregation, aggregation);
QFETCH(QString, filename);

const auto actualBinaryFile = QFINDTESTDATA("custom_cost_aggregation_testfiles/" + filename);
QFile expectedData(QFINDTESTDATA("custom_cost_aggregation_testfiles/" + filename));
QVERIFY(expectedData.open(QIODevice::ReadOnly | QIODevice::Text));
const auto expected = expectedData.readAll();

Settings::instance()->setCostAggregation(aggregation);
m_perfCommand = "perf record --call-graph dwarf --sample-cpu --switch-events --event sched:sched_switch -c "
"1000000 /tmp/cpp-threadnames";
m_cpuArchitecture = "x86_64";
m_linuxKernelVersion = "5.17.5-arch1-1";
m_machineHostName = "Sparrow";

QFile perfData(QFINDTESTDATA("custom_cost_aggregation_testfiles/custom_cost_aggregation.perfparser"));
const auto perfData = QFINDTESTDATA("custom_cost_aggregation_testfiles/custom_cost_aggregation.perfparser");
QVERIFY(!perfData.isEmpty() && QFile::exists(perfData));

try {
testPerfData({}, {}, perfData.fileName(), false);
testPerfData({}, {}, perfData, false);
} catch (...) {
}

QFile file(actualBinaryFile);
file.open(QIODevice::WriteOnly);
QByteArray actual;
{
QTextStream stream(&actual);
dump(m_bottomUpData.root, stream, {});
}

QString actual;
QTextStream stream(&actual);
dump(m_bottomUpData.root, stream, "");
if (expected != actual) {
QFile actualData(expectedData.fileName() + ".actual");
QVERIFY(actualData.open(QIODevice::WriteOnly | QIODevice::Text));
actualData.write(actual);

Q_ASSERT(file.readAll() == actual);
const auto diff = QStandardPaths::findExecutable("diff");
if (!diff.isEmpty()) {
QProcess::execute(diff, {"-u", expectedData.fileName(), actualData.fileName()});
}
}
QCOMPARE(actual, expected);
}

#if KF5Archive_FOUND
Expand Down Expand Up @@ -690,6 +708,9 @@ private slots:
Data::CallerCalleeResults m_callerCalleeData;
Data::EventResults m_eventData;
QString m_perfCommand;
QString m_cpuArchitecture;
QString m_linuxKernelVersion;
QString m_machineHostName;

void perfRecord(const QStringList& perfOptions, const QString& exePath, const QStringList& exeOptions,
const QString& fileName)
Expand Down Expand Up @@ -767,9 +788,9 @@ private slots:
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, QSysInfo::currentCpuArchitecture());
COMPARE_OR_THROW(m_summaryData.linuxKernelVersion, QSysInfo::kernelVersion());
COMPARE_OR_THROW(m_summaryData.hostName, QSysInfo::machineHostName());
COMPARE_OR_THROW(m_summaryData.cpuArchitecture, m_cpuArchitecture);
COMPARE_OR_THROW(m_summaryData.linuxKernelVersion, m_linuxKernelVersion);
COMPARE_OR_THROW(m_summaryData.hostName, m_machineHostName);

if (checkFrequency) {
// Verify the sample frequency is acceptable, greater than 500Hz
Expand Down

0 comments on commit 8482895

Please sign in to comment.