File indexing completed on 2024-05-12 04:38:09

0001 /*
0002     SPDX-FileCopyrightText: 2012 Milian Wolff <mail@milianw.de>
0003     SPDX-FileCopyrightText: 2012 Morten Danielsen Volden <mvolden2@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "test_outputmodel.h"
0009 #include "testlinebuilderfunctions.h"
0010 #include "../outputmodel.h"
0011 
0012 #include <QTest>
0013 #include <QStandardPaths>
0014 
0015 QTEST_MAIN(KDevelop::TestOutputModel)
0016 
0017 namespace KDevelop
0018 {
0019 
0020 TestOutputModel::TestOutputModel(QObject* parent): QObject(parent)
0021 {
0022     QStandardPaths::setTestModeEnabled(true);
0023 }
0024 
0025 QStringList generateLines()
0026 {
0027     const int numLines = 10000;
0028     QStringList outputlines;
0029     do {
0030         outputlines << buildCompilerActionLine();
0031         outputlines << buildCppCheckInformationLine();
0032         for (TestPathType pathType :
0033 #ifdef Q_OS_WIN
0034             {WindowsFilePathNoSpaces, WindowsFilePathWithSpaces}
0035 #else
0036             {UnixFilePathNoSpaces, UnixFilePathWithSpaces}
0037 #endif
0038         ) {
0039             outputlines << buildCompilerErrorLine(pathType);
0040             outputlines << buildCompilerLine(pathType);
0041             outputlines << buildCppCheckErrorLine(pathType);
0042             outputlines << buildPythonErrorLine(pathType);
0043         }
0044     }
0045     while(outputlines.size() < numLines ); // gives us numLines (-ish)
0046     return outputlines;
0047 }
0048 
0049 QStringList generateLongLine()
0050 {
0051     const int objects = 100; // *.o files
0052     const int libs = 20; // -l...
0053     const int libPaths = 20; // -L...
0054     QString line = QStringLiteral("g++ -m64 -Wl,-rpath,/home/gabo/md/qt/lib -o bin/flap_ui");
0055     for(int i = 0; i < objects; ++i) {
0056         line += QStringLiteral(" .obj/file%1.o").arg(i);
0057     }
0058     for(int i = 0; i < libPaths; ++i) {
0059         line += QStringLiteral(" -Lsome/path/to/lib%1").arg(i);
0060     }
0061     for(int i = 0; i < libs; ++i) {
0062         line += QStringLiteral(" -lsomelib%1").arg(i);
0063     }
0064     return QStringList() << line;
0065 }
0066 
0067 void TestOutputModel::bench()
0068 {
0069     QFETCH(KDevelop::OutputModel::OutputFilterStrategy, strategy);
0070     QFETCH(QStringList, lines);
0071 
0072     OutputModel testee(QUrl::fromLocalFile(QStringLiteral("/tmp/build-foo")));
0073     testee.setFilteringStrategy(strategy);
0074 
0075     quint64 processEventsCounter = 1;
0076     QElapsedTimer totalTime;
0077     totalTime.start();
0078 
0079     testee.appendLines(lines);
0080     while(testee.rowCount() != lines.count()) {
0081         QCoreApplication::instance()->processEvents();
0082         processEventsCounter++;
0083     }
0084 
0085     QVERIFY(testee.rowCount() == lines.count());
0086     const qint64 elapsed = totalTime.elapsed();
0087 
0088     qDebug() << "ms elapsed to add lines: " << elapsed;
0089     qDebug() << "total number of added lines: " << lines.count();
0090     const double avgUiLockup = double(elapsed) / processEventsCounter;
0091     qDebug() << "average UI lockup in ms: " << avgUiLockup;
0092     QVERIFY(avgUiLockup < 200);
0093 }
0094 
0095 void TestOutputModel::bench_data()
0096 {
0097     QTest::addColumn<KDevelop::OutputModel::OutputFilterStrategy>("strategy");
0098     QTest::addColumn<QStringList>("lines");
0099 
0100     const QStringList lines = generateLines();
0101     const QStringList longLine = generateLongLine();
0102 
0103     QTest::newRow("no-filter") << OutputModel::NoFilter << lines;
0104     QTest::newRow("no-filter-longline") << OutputModel::NoFilter << longLine;
0105 
0106     QTest::newRow("compiler-filter") << OutputModel::CompilerFilter << lines;
0107     QTest::newRow("compiler-filter-longline") << OutputModel::CompilerFilter << longLine;
0108 
0109     QTest::newRow("script-error-filter") << OutputModel::ScriptErrorFilter << lines;
0110     QTest::newRow("script-error-filter-longline") << OutputModel::ScriptErrorFilter << longLine;
0111 
0112     QTest::newRow("static-analysis-filter") << OutputModel::StaticAnalysisFilter << lines;
0113     QTest::newRow("static-analysis-filter-longline") << OutputModel::StaticAnalysisFilter << longLine;
0114 }
0115 
0116 }
0117 
0118 #include "moc_test_outputmodel.cpp"