summaryrefslogtreecommitdiffstats
path: root/tests/auto/perfdata/tst_perfdata.cpp
blob: 22dbcb2a6ff2af64c3284fee782af1086aa90b1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Enterprise Perf Profiler Add-on.
**
** GNU General Public License Usage
** This file may be used under the terms of the GNU General Public License
** version 3 as published by the Free Software Foundation and appearing in
** the file LICENSE.GPLv3 included in the packaging of this file. Please
** review the following information to ensure the GNU General Public License
** requirements will be met: https://www.gnu.org/licenses/gpl.html.
**
** If you have questions regarding the use of this file, please use
** contact form at http://www.qt.io/contact-us
**
****************************************************************************/

#include <QObject>
#include <QTest>
#include <QBuffer>
#include <QSignalSpy>
#include <QDebug>

#include "perfdata.h"
#include "perfunwind.h"

class TestPerfData : public QObject
{
    Q_OBJECT
private slots:
    void testTraceDataHeaderEvent();
    void testContentSize();
};

void TestPerfData::testTraceDataHeaderEvent()
{
    QBuffer output;
    QFile input(":/probe.data.stream");
    QVERIFY(input.open(QIODevice::ReadOnly));
    QVERIFY(output.open(QIODevice::WriteOnly));

    PerfUnwind unwind(&output, QDir::rootPath(), PerfUnwind::defaultDebugInfoPath(), QString(),
                      QString(), true);
    PerfHeader header(&input);
    PerfAttributes attributes;
    PerfData data(&input, &unwind, &header, &attributes);

    QSignalSpy spy(&data, SIGNAL(finished()));
    connect(&header, &PerfHeader::finished, &data, &PerfData::read);

    header.read();
    QCOMPARE(spy.count(), 1);

    unwind.finalize();

    const PerfUnwind::Stats stats = unwind.stats();
    QCOMPARE(stats.numSamples, 1u);
    QCOMPARE(stats.numMmaps, 120u);
    QCOMPARE(stats.numRounds, 2u);
    QCOMPARE(stats.numBufferFlushes, 2u);
    QCOMPARE(stats.numTimeViolatingSamples, 0u);
    QCOMPARE(stats.numTimeViolatingMmaps, 0u);
    QCOMPARE(stats.maxBufferSize, 15488u);
    QCOMPARE(stats.maxTime, 13780586522722ull);
}

void TestPerfData::testContentSize()
{
    QString file(":/contentsize.data");

    QBuffer output;
    QFile input(file);

    QVERIFY(input.open(QIODevice::ReadOnly));
    QVERIFY(output.open(QIODevice::WriteOnly));

    // Don't try to load any system files. They are not the same as the ones we use to report.
    PerfUnwind unwind(&output, ":/", QString(), QString(), QString(), true);
    PerfHeader header(&input);
    PerfAttributes attributes;
    PerfData data(&input, &unwind, &header, &attributes);

    QSignalSpy spy(&data, SIGNAL(finished()));
    connect(&header, &PerfHeader::finished, &data, &PerfData::read);

    header.read();
    QCOMPARE(spy.count(), 1);

    unwind.finalize();

    QObject::connect(&data, &PerfData::error, []() {
        QFAIL("PerfData reported an error");
    });

    QCOMPARE(unwind.stats().numSamples, 69u);
}

QTEST_GUILESS_MAIN(TestPerfData)

#include "tst_perfdata.moc"