77#include < QTest>
88
99#include " ../../src/parsers/perf/perfparser.h"
10- #include " ../../src/perfrecord.h"
11- #include " ../../src/recordhost.h"
1210#include " ../testutils.h"
1311#include " data.h"
1412
1513class TestCallgraphGenerator : public QObject
1614{
1715 Q_OBJECT
1816private slots:
19- void initTestCase ()
20- {
21- const QStringList perfOptions = {QStringLiteral (" --call-graph" ), QStringLiteral (" dwarf" )};
22- QStringList exeOptions;
23-
24- const QString exePath = findExe (QStringLiteral (" callgraph" ));
25- m_file.open ();
26-
27- perfRecord (perfOptions, exePath, exeOptions, m_file.fileName ());
28- }
29-
3017 void testParent ()
3118 {
32- auto results = callerCalleeResults (m_file. fileName () );
19+ auto results = callerCalleeResults (s_fileName );
3320
34- QVERIFY (callerCalleeResults (m_file. fileName ()) .entries .size () > 0 );
21+ QVERIFY (! callerCalleeResults (s_fileName) .entries .empty () );
3522
3623 auto key = Data::Symbol ();
3724 for (auto it = results.entries .cbegin (); it != results.entries .cend (); it++) {
@@ -51,14 +38,15 @@ private slots:
5138 int parent1Pos = test.indexOf (QLatin1String (" parent1" ));
5239
5340 QVERIFY (parent3Pos < parent2Pos);
41+
5442 QVERIFY (parent2Pos < parent1Pos);
5543 }
5644
5745 void testChild ()
5846 {
59- auto results = callerCalleeResults (m_file. fileName () );
47+ auto results = callerCalleeResults (s_fileName );
6048
61- QVERIFY (callerCalleeResults (m_file. fileName ()) .entries .size () > 0 );
49+ QVERIFY (! callerCalleeResults (s_fileName) .entries .empty () );
6250
6351 auto key = Data::Symbol ();
6452 for (auto it = results.entries .cbegin (); it != results.entries .cend (); it++) {
@@ -82,10 +70,11 @@ private slots:
8270private:
8371 Data::CallerCalleeResults callerCalleeResults (const QString& filename)
8472 {
85- qputenv ( " HOTSPOT_PERFPARSER " ,
86- QCoreApplication::applicationDirPath ().toUtf8 () + QByteArrayLiteral (" /perfparser" ) );
87- PerfParser parser ( this );
73+ const QByteArray perfparserPath =
74+ QCoreApplication::applicationDirPath ().toUtf8 () + QByteArrayLiteral (" /perfparser" );
75+ qputenv ( " HOTSPOT_PERFPARSER " , perfparserPath );
8876
77+ PerfParser parser (this );
8978 QSignalSpy parsingFinishedSpy (&parser, &PerfParser::parsingFinished);
9079 QSignalSpy parsingFailedSpy (&parser, &PerfParser::parsingFailed);
9180
@@ -97,28 +86,7 @@ private slots:
9786 return parser.callerCalleeResults ();
9887 }
9988
100- void perfRecord (const QStringList& perfOptions, const QString& exePath, const QStringList& exeOptions,
101- const QString& fileName)
102- {
103- RecordHost host;
104- PerfRecord perf (&host);
105- QSignalSpy recordingFinishedSpy (&perf, &PerfRecord::recordingFinished);
106- QSignalSpy recordingFailedSpy (&perf, &PerfRecord::recordingFailed);
107-
108- // always add `-c 1000000`, as perf's frequency mode is too unreliable for testing purposes
109- perf.record (
110- perfOptions
111- + QStringList {QStringLiteral (" -c" ), QStringLiteral (" 1000000" ), QStringLiteral (" --no-buildid-cache" )},
112- fileName, false , exePath, exeOptions);
113-
114- VERIFY_OR_THROW (recordingFinishedSpy.wait (10000 ));
115-
116- COMPARE_OR_THROW (recordingFailedSpy.count (), 0 );
117- COMPARE_OR_THROW (recordingFinishedSpy.count (), 1 );
118- COMPARE_OR_THROW (QFileInfo::exists (fileName), true );
119- }
120-
121- QTemporaryFile m_file;
89+ const QString s_fileName = QFINDTESTDATA(" callgraph.perfparser" );
12290};
12391
12492QTEST_GUILESS_MAIN (TestCallgraphGenerator)
0 commit comments