diff options
Diffstat (limited to 'tests/benchmarks')
15 files changed, 767 insertions, 333 deletions
diff --git a/tests/benchmarks/corelib/io/qdiriterator/main.cpp b/tests/benchmarks/corelib/io/qdiriterator/main.cpp index eae752d99a..0bbe755f4e 100644 --- a/tests/benchmarks/corelib/io/qdiriterator/main.cpp +++ b/tests/benchmarks/corelib/io/qdiriterator/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -57,24 +57,23 @@ private slots: void data(); }; - void tst_qdiriterator::data() { -#if defined(Q_OS_WIN) - const char *qtdir = "C:\\depot\\qt\\main"; -#else - const char *qtdir = ::getenv("QTDIR"); -#endif - if (!qtdir) { - fprintf(stderr, "QTDIR not set\n"); - exit(1); - } + const char hereRelative[] = "tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro"; + QString proname = QTest::qFindTestData(QStringLiteral("qdiriterator.pro")); + // qDebug("Source pro: %s", proname.toLocal8Bit().constData()); + // Size chopped counts the '\0', making up for the omitted leading '/': + QByteArray dir(QStringRef(&proname).chopped(sizeof(hereRelative)).toLocal8Bit()); + // qDebug("Root dir: %s", dir.constData()); QTest::addColumn<QByteArray>("dirpath"); - QByteArray ba = QByteArray(qtdir) + "/src/corelib"; - QByteArray ba1 = ba + "/io"; - QTest::newRow(ba) << ba; - //QTest::newRow(ba1) << ba1; + const QByteArray ba = dir + "/src/corelib"; + + if (!QFileInfo(QString::fromLocal8Bit(ba)).isDir()) + QSKIP("Missing Qt directory"); + + QTest::newRow("corelib") << ba; + QTest::newRow("corelib/io") << (ba + "/io"); } #ifdef Q_OS_WIN diff --git a/tests/benchmarks/corelib/io/qfile/main.cpp b/tests/benchmarks/corelib/io/qfile/main.cpp index 1966b30773..eca2f642b1 100644 --- a/tests/benchmarks/corelib/io/qfile/main.cpp +++ b/tests/benchmarks/corelib/io/qfile/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -108,72 +108,110 @@ private slots: void readBigFile_Win32(); private: - void readBigFile_data(BenchmarkType type, QIODevice::OpenModeFlag t, QIODevice::OpenModeFlag b); + void readFile_data(BenchmarkType type, QIODevice::OpenModeFlag t, QIODevice::OpenModeFlag b); void readBigFile(); - void readSmallFiles_data(BenchmarkType type, QIODevice::OpenModeFlag t, QIODevice::OpenModeFlag b); void readSmallFiles(); - void createFile(); - void fillFile(int factor=FACTOR); - void removeFile(); - void createSmallFiles(); - void removeSmallFiles(); - QString filename; - QString tmpDirName; + + class TestDataDir : public QTemporaryDir + { + void createFile(); + void createSmallFiles(); + public: + TestDataDir() : QTemporaryDir(), fail(errorString().toLocal8Bit()) + { + if (fail.isEmpty() && !QTemporaryDir::isValid()) + fail = "Failed to create temporary directory for data"; + if (isValid()) + createSmallFiles(); + if (isValid()) + createFile(); + if (isValid()) + QTest::qSleep(2000); // let IO settle + } + bool isValid() { return QTemporaryDir::isValid() && fail.isEmpty(); } + QByteArray fail; + QString filename; + } tempDir; }; Q_DECLARE_METATYPE(tst_qfile::BenchmarkType) Q_DECLARE_METATYPE(QIODevice::OpenMode) Q_DECLARE_METATYPE(QIODevice::OpenModeFlag) -void tst_qfile::createFile() +/* None of the tests modify the test data in tempDir, so it's OK to only create + * and tear down the directory once. + */ +void tst_qfile::TestDataDir::createFile() { - removeFile(); // Cleanup in case previous test case aborted before cleaning up - - QTemporaryFile tmpFile; - tmpFile.setAutoRemove(false); - if (!tmpFile.open()) - ::exit(1); + QFile tmpFile(filePath("testFile")); + if (!tmpFile.open(QIODevice::WriteOnly)) { + fail = "Unable to prepare files for test"; + return; + } +#if 0 // Varied data, rather than filling with '\0' bytes: + for (int row = 0; row < FACTOR; ++row) { + tmpFile.write(QByteArray().fill('0' + row % ('0' - 'z'), 80)); + tmpFile.write("\n"); + } +#else + tmpFile.seek(FACTOR * 80); + tmpFile.putChar('\n'); +#endif filename = tmpFile.fileName(); tmpFile.close(); } -void tst_qfile::removeFile() +void tst_qfile::TestDataDir::createSmallFiles() { - if (!filename.isEmpty()) - QFile::remove(filename); + for (int i = 0; i < 1000; ++i) { + QFile f(filePath(QString::number(i))); + if (!f.open(QIODevice::WriteOnly)) { + fail = "Unable to prepare small files for test"; + return; + } + f.seek(511); + f.putChar('\n'); + f.close(); + } } -void tst_qfile::fillFile(int factor) +void tst_qfile::initTestCase() { - QFile tmpFile(filename); - tmpFile.open(QIODevice::WriteOnly); - //for (int row=0; row<factor; ++row) { - // tmpFile.write(QByteArray().fill('0'+row%('0'-'z'), 80)); - // tmpFile.write("\n"); - //} - tmpFile.seek(factor*80); - tmpFile.putChar('\n'); - tmpFile.close(); - // let IO settle - QTest::qSleep(2000); + QVERIFY2(tempDir.isValid(), tempDir.fail.constData()); } -void tst_qfile::initTestCase() +void tst_qfile::cleanupTestCase() { } -void tst_qfile::cleanupTestCase() +void tst_qfile::readFile_data(BenchmarkType type, QIODevice::OpenModeFlag t, + QIODevice::OpenModeFlag b) { + QTest::addColumn<tst_qfile::BenchmarkType>("testType"); + QTest::addColumn<int>("blockSize"); + QTest::addColumn<QFile::OpenModeFlag>("textMode"); + QTest::addColumn<QFile::OpenModeFlag>("bufferedMode"); + + QByteArray flagstring; + if (t & QIODevice::Text) + flagstring += "textMode "; + if (b & QIODevice::Unbuffered) + flagstring += "unbuffered "; + if (flagstring.isEmpty()) + flagstring = "none"; + + const int kbs[] = {1, 2, 8, 16, 32, 512}; + for (int kb : kbs) { + const int size = 1024 * kb; + QTest::addRow("BS: %d, Flags: %s", size, flagstring.constData()) + << type << size << t << b; + } } void tst_qfile::readBigFile_QFile() { readBigFile(); } void tst_qfile::readBigFile_QFSFileEngine() { -#ifdef QT_BUILD_INTERNAL readBigFile(); -#else - QSKIP("This test requires -developer-build."); -#endif } void tst_qfile::readBigFile_posix() { @@ -183,54 +221,36 @@ void tst_qfile::readBigFile_Win32() { readBigFile(); } void tst_qfile::readBigFile_QFile_data() { - readBigFile_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::NotOpen); - readBigFile_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered); - readBigFile_data(QFileBenchmark, QIODevice::Text, QIODevice::NotOpen); - readBigFile_data(QFileBenchmark, QIODevice::Text, QIODevice::Unbuffered); + readFile_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::NotOpen); + readFile_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered); + readFile_data(QFileBenchmark, QIODevice::Text, QIODevice::NotOpen); + readFile_data(QFileBenchmark, QIODevice::Text, QIODevice::Unbuffered); } void tst_qfile::readBigFile_QFSFileEngine_data() { #ifdef QT_BUILD_INTERNAL - readBigFile_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::NotOpen); - readBigFile_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered); - readBigFile_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::NotOpen); - readBigFile_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::Unbuffered); + // Support for buffering dropped at 5.10, so only test Unbuffered + readFile_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered); + readFile_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::Unbuffered); #else - QTest::addColumn<int>("dummy"); - QTest::newRow("Test will be skipped") << -1; + QSKIP("This test requires -developer-build."); #endif } void tst_qfile::readBigFile_posix_data() { - readBigFile_data(PosixBenchmark, QIODevice::NotOpen, QIODevice::NotOpen); + readFile_data(PosixBenchmark, QIODevice::NotOpen, QIODevice::NotOpen); } void tst_qfile::readBigFile_Win32_data() { - readBigFile_data(Win32Benchmark, QIODevice::NotOpen, QIODevice::NotOpen); -} - - -void tst_qfile::readBigFile_data(BenchmarkType type, QIODevice::OpenModeFlag t, QIODevice::OpenModeFlag b) -{ - QTest::addColumn<tst_qfile::BenchmarkType>("testType"); - QTest::addColumn<int>("blockSize"); - QTest::addColumn<QFile::OpenModeFlag>("textMode"); - QTest::addColumn<QFile::OpenModeFlag>("bufferedMode"); - - const int bs[] = {1024, 1024*2, 1024*8, 1024*16, 1024*32,1024*512}; - int bs_entries = sizeof(bs)/sizeof(const int); - - QString flagstring; - if (t & QIODevice::Text) flagstring += "textMode "; - if (b & QIODevice::Unbuffered) flagstring += "unbuffered "; - if (flagstring.isEmpty()) flagstring = "none"; - - for (int i=0; i<bs_entries; ++i) - QTest::newRow((QString("BS: %1, Flags: %2" )).arg(bs[i]).arg(flagstring).toLatin1().constData()) << type << bs[i] << t << b; +#ifdef Q_OS_WIN + readFile_data(Win32Benchmark, QIODevice::NotOpen, QIODevice::NotOpen); +#else + QSKIP("This is Windows only benchmark."); +#endif } void tst_qfile::readBigFile() @@ -240,18 +260,10 @@ void tst_qfile::readBigFile() QFETCH(QFile::OpenModeFlag, textMode); QFETCH(QFile::OpenModeFlag, bufferedMode); -#ifndef Q_OS_WIN - if (testType == Win32Benchmark) - QSKIP("This is Windows only benchmark."); -#endif - - char *buffer = new char[BUFSIZE]; - createFile(); - fillFile(); - + char buffer[BUFSIZE]; switch (testType) { case(QFileBenchmark): { - QFile file(filename); + QFile file(tempDir.filename); file.open(QIODevice::ReadOnly|textMode|bufferedMode); QBENCHMARK { while(!file.atEnd()) @@ -263,7 +275,7 @@ void tst_qfile::readBigFile() break; #ifdef QT_BUILD_INTERNAL case(QFSFileEngineBenchmark): { - QFSFileEngine fse(filename); + QFSFileEngine fse(tempDir.filename); fse.open(QIODevice::ReadOnly|textMode|bufferedMode); QBENCHMARK { //qWarning() << fse.supportsExtension(QAbstractFileEngine::AtEndExtension); @@ -275,7 +287,7 @@ void tst_qfile::readBigFile() break; #endif case(PosixBenchmark): { - QByteArray data = filename.toLocal8Bit(); + QByteArray data = tempDir.filename.toLocal8Bit(); const char* cfilename = data.constData(); FILE* cfile = ::fopen(cfilename, "rb"); QBENCHMARK { @@ -295,7 +307,7 @@ void tst_qfile::readBigFile() HANDLE hndl; // ensure we don't account string conversion - wchar_t* cfilename = (wchar_t*)filename.utf16(); + const wchar_t *cfilename = reinterpret_cast<const wchar_t *>(tempDir.filename.utf16()); #ifndef Q_OS_WINRT hndl = CreateFile(cfilename, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); @@ -325,9 +337,6 @@ void tst_qfile::readBigFile() } break; } - - removeFile(); - delete[] buffer; } void tst_qfile::seek_data() @@ -348,12 +357,9 @@ void tst_qfile::seek() QFETCH(tst_qfile::BenchmarkType, testType); int i = 0; - createFile(); - fillFile(); - switch (testType) { case(QFileBenchmark): { - QFile file(filename); + QFile file(tempDir.filename); file.open(QIODevice::ReadOnly); QBENCHMARK { i=(i+1)%sp_size; @@ -364,8 +370,8 @@ void tst_qfile::seek() break; #ifdef QT_BUILD_INTERNAL case(QFSFileEngineBenchmark): { - QFSFileEngine fse(filename); - fse.open(QIODevice::ReadOnly); + QFSFileEngine fse(tempDir.filename); + fse.open(QIODevice::ReadOnly | QIODevice::Unbuffered); QBENCHMARK { i=(i+1)%sp_size; fse.seek(seekpos[i]); @@ -375,7 +381,7 @@ void tst_qfile::seek() break; #endif case(PosixBenchmark): { - QByteArray data = filename.toLocal8Bit(); + QByteArray data = tempDir.filename.toLocal8Bit(); const char* cfilename = data.constData(); FILE* cfile = ::fopen(cfilename, "rb"); QBENCHMARK { @@ -394,7 +400,7 @@ void tst_qfile::seek() HANDLE hndl; // ensure we don't account string conversion - wchar_t* cfilename = (wchar_t*)filename.utf16(); + const wchar_t *cfilename = reinterpret_cast<const wchar_t *>(tempDir.filename.utf16()); #ifndef Q_OS_WINRT hndl = CreateFile(cfilename, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); @@ -413,13 +419,11 @@ void tst_qfile::seek() } CloseHandle(hndl); #else - QFAIL("Not running on a Windows plattform!"); + QFAIL("Not running on a Windows platform!"); #endif } break; } - - removeFile(); } void tst_qfile::open_data() @@ -440,13 +444,11 @@ void tst_qfile::open() { QFETCH(tst_qfile::BenchmarkType, testType); - createFile(); - switch (testType) { case(QFileBenchmark): { QBENCHMARK { - QFile file( filename ); - file.open( QIODevice::ReadOnly ); + QFile file(tempDir.filename); + file.open(QIODevice::ReadOnly); file.close(); } } @@ -454,8 +456,8 @@ void tst_qfile::open() #ifdef QT_BUILD_INTERNAL case(QFSFileEngineBenchmark): { QBENCHMARK { - QFSFileEngine fse(filename); - fse.open(QIODevice::ReadOnly); + QFSFileEngine fse(tempDir.filename); + fse.open(QIODevice::ReadOnly | QIODevice::Unbuffered); fse.close(); } } @@ -463,7 +465,7 @@ void tst_qfile::open() #endif case(PosixBenchmark): { // ensure we don't account toLocal8Bit() - QByteArray data = filename.toLocal8Bit(); + QByteArray data = tempDir.filename.toLocal8Bit(); const char* cfilename = data.constData(); QBENCHMARK { @@ -474,7 +476,7 @@ void tst_qfile::open() break; case(QFileFromPosixBenchmark): { // ensure we don't account toLocal8Bit() - QByteArray data = filename.toLocal8Bit(); + QByteArray data = tempDir.filename.toLocal8Bit(); const char* cfilename = data.constData(); FILE* cfile = ::fopen(cfilename, "rb"); @@ -491,7 +493,7 @@ void tst_qfile::open() HANDLE hndl; // ensure we don't account string conversion - wchar_t* cfilename = (wchar_t*)filename.utf16(); + const wchar_t *cfilename = reinterpret_cast<const wchar_t *>(tempDir.filename.utf16()); QBENCHMARK { #ifndef Q_OS_WINRT @@ -508,19 +510,13 @@ void tst_qfile::open() } break; } - - removeFile(); } void tst_qfile::readSmallFiles_QFile() { readSmallFiles(); } void tst_qfile::readSmallFiles_QFSFileEngine() { -#ifdef QT_BUILD_INTERNAL readSmallFiles(); -#else - QSKIP("This test requires -developer-build."); -#endif } void tst_qfile::readSmallFiles_posix() { @@ -533,82 +529,39 @@ void tst_qfile::readSmallFiles_Win32() void tst_qfile::readSmallFiles_QFile_data() { - readSmallFiles_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::NotOpen); - readSmallFiles_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered); - readSmallFiles_data(QFileBenchmark, QIODevice::Text, QIODevice::NotOpen); - readSmallFiles_data(QFileBenchmark, QIODevice::Text, QIODevice::Unbuffered); + readFile_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::NotOpen); + readFile_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered); + readFile_data(QFileBenchmark, QIODevice::Text, QIODevice::NotOpen); + readFile_data(QFileBenchmark, QIODevice::Text, QIODevice::Unbuffered); } void tst_qfile::readSmallFiles_QFSFileEngine_data() { #ifdef QT_BUILD_INTERNAL - readSmallFiles_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::NotOpen); - readSmallFiles_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered); - readSmallFiles_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::NotOpen); - readSmallFiles_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::Unbuffered); + // Support for buffering dropped at 5.10, so only test Unbuffered + readFile_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered); + readFile_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::Unbuffered); #else - QTest::addColumn<int>("dummy"); - QTest::newRow("Test will be skipped") << -1; + QSKIP("This test requires -developer-build."); #endif } void tst_qfile::readSmallFiles_posix_data() { - readSmallFiles_data(PosixBenchmark, QIODevice::NotOpen, QIODevice::NotOpen); + readFile_data(PosixBenchmark, QIODevice::NotOpen, QIODevice::NotOpen); } void tst_qfile::readSmallFiles_Win32_data() { - readSmallFiles_data(Win32Benchmark, QIODevice::NotOpen, QIODevice::NotOpen); -} - - -void tst_qfile::readSmallFiles_data(BenchmarkType type, QIODevice::OpenModeFlag t, QIODevice::OpenModeFlag b) -{ - QTest::addColumn<tst_qfile::BenchmarkType>("testType"); - QTest::addColumn<int>("blockSize"); - QTest::addColumn<QFile::OpenModeFlag>("textMode"); - QTest::addColumn<QFile::OpenModeFlag>("bufferedMode"); - - const int bs[] = {1024, 1024*2, 1024*8, 1024*16, 1024*32,1024*512}; - int bs_entries = sizeof(bs)/sizeof(const int); - - QString flagstring; - if (t & QIODevice::Text) flagstring += "textMode "; - if (b & QIODevice::Unbuffered) flagstring += "unbuffered "; - if (flagstring.isEmpty()) flagstring = "none"; - - for (int i=0; i<bs_entries; ++i) - QTest::newRow((QString("BS: %1, Flags: %2" )).arg(bs[i]).arg(flagstring).toLatin1().constData()) << type << bs[i] << t << b; - -} - -void tst_qfile::createSmallFiles() -{ - QDir dir = QDir::temp(); - dir.mkdir("tst"); - dir.cd("tst"); - tmpDirName = dir.absolutePath(); - - for (int i = 0; i < 1000; ++i) { - QFile f(tmpDirName + QLatin1Char('/') + QString::number(i)); - f.open(QIODevice::WriteOnly); - f.seek(511); - f.putChar('\n'); - f.close(); - } -} -void tst_qfile::removeSmallFiles() -{ - QDirIterator it(tmpDirName, QDirIterator::FollowSymlinks); - while (it.hasNext()) - QFile::remove(it.next()); - QDir::temp().rmdir("tst"); +#ifdef Q_OS_WIN + readFile_data(Win32Benchmark, QIODevice::NotOpen, QIODevice::NotOpen); +#else + QSKIP("This is Windows only benchmark."); +#endif } - void tst_qfile::readSmallFiles() { QFETCH(tst_qfile::BenchmarkType, testType); @@ -616,22 +569,15 @@ void tst_qfile::readSmallFiles() QFETCH(QFile::OpenModeFlag, textMode); QFETCH(QFile::OpenModeFlag, bufferedMode); -#ifndef Q_OS_WIN - if (testType == Win32Benchmark) - QSKIP("This is Windows only benchmark."); -#endif - - createSmallFiles(); - - QDir dir(tmpDirName); + QDir dir(tempDir.path()); const QStringList files = dir.entryList(QDir::NoDotAndDotDot|QDir::NoSymLinks|QDir::Files); - char *buffer = new char[BUFSIZE]; + char buffer[BUFSIZE]; switch (testType) { case(QFileBenchmark): { QList<QFile*> fileList; Q_FOREACH(QString file, files) { - QFile *f = new QFile(tmpDirName + QLatin1Char('/') + file); + QFile *f = new QFile(tempDir.filePath(file)); f->open(QIODevice::ReadOnly|textMode|bufferedMode); fileList.append(f); } @@ -654,7 +600,7 @@ void tst_qfile::readSmallFiles() case(QFSFileEngineBenchmark): { QList<QFSFileEngine*> fileList; Q_FOREACH(QString file, files) { - QFSFileEngine *fse = new QFSFileEngine(tmpDirName + QLatin1Char('/') + file); + QFSFileEngine *fse = new QFSFileEngine(tempDir.filePath(file)); fse->open(QIODevice::ReadOnly|textMode|bufferedMode); fileList.append(fse); } @@ -675,7 +621,7 @@ void tst_qfile::readSmallFiles() case(PosixBenchmark): { QList<FILE*> fileList; Q_FOREACH(QString file, files) { - fileList.append(::fopen(QFile::encodeName(tmpDirName + QLatin1Char('/') + file).constData(), "rb")); + fileList.append(::fopen(QFile::encodeName(tempDir.filePath(file)).constData(), "rb")); } QBENCHMARK { @@ -700,7 +646,7 @@ void tst_qfile::readSmallFiles() HANDLE hndl; // ensure we don't account string conversion - wchar_t* cfilename = (wchar_t*)filename.utf16(); + const wchar_t *cfilename = reinterpret_cast<const wchar_t *>(tempDir.filename.utf16()); #ifndef Q_OS_WINRT hndl = CreateFile(cfilename, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); @@ -723,9 +669,6 @@ void tst_qfile::readSmallFiles() } break; } - - removeSmallFiles(); - delete[] buffer; } QTEST_MAIN(tst_qfile) diff --git a/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/testProcessLoopback.pro b/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/testProcessLoopback.pro index 1f56ad6ee6..89fea90d90 100644 --- a/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/testProcessLoopback.pro +++ b/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/testProcessLoopback.pro @@ -1,4 +1,3 @@ -CONFIG += benchmark CONFIG -= qt CONFIG += cmdline winrt: QMAKE_LFLAGS += /ENTRY:mainCRTStartup diff --git a/tests/benchmarks/corelib/io/qprocess/tst_bench_qprocess.cpp b/tests/benchmarks/corelib/io/qprocess/tst_bench_qprocess.cpp index 1fd3b9d5da..6cf7529d55 100644 --- a/tests/benchmarks/corelib/io/qprocess/tst_bench_qprocess.cpp +++ b/tests/benchmarks/corelib/io/qprocess/tst_bench_qprocess.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -39,10 +39,16 @@ private slots: void echoTest_performance(); }; +#ifdef Q_OS_WIN +# define EXE ".exe" +#else +# define EXE "" +#endif + void tst_QProcess::echoTest_performance() { QProcess process; - process.start("testProcessLoopback/testProcessLoopback"); + process.start(QFINDTESTDATA("testProcessLoopback/testProcessLoopback" EXE), QStringList()); QByteArray array; array.resize(1024 * 1024); diff --git a/tests/benchmarks/corelib/kernel/qmetaobject/main.cpp b/tests/benchmarks/corelib/kernel/qmetaobject/main.cpp index 80bad7977b..262dca7d52 100644 --- a/tests/benchmarks/corelib/kernel/qmetaobject/main.cpp +++ b/tests/benchmarks/corelib/kernel/qmetaobject/main.cpp @@ -237,11 +237,12 @@ void tst_qmetaobject::unconnected() { LotsOfSignals *obj = new LotsOfSignals; QFETCH(int, signal_index); - QVERIFY(obj->metaObject()->methodCount() == 73); + // 74: 70 signals in LotsOfSignals, 2 signals, 1 slot + 1 invokable in QObject + QCOMPARE(obj->metaObject()->methodCount(), 74); void *v; QBENCHMARK { - //+1 because QObject has one slot - QMetaObject::metacall(obj, QMetaObject::InvokeMetaMethod, signal_index+1, &v); + // Add two because QObject has one slot and one invokable + QMetaObject::metacall(obj, QMetaObject::InvokeMetaMethod, signal_index + 2, &v); } delete obj; } diff --git a/tests/benchmarks/corelib/text/qlocale/main.cpp b/tests/benchmarks/corelib/text/qlocale/main.cpp index 38d94af143..c7bd37a2d3 100644 --- a/tests/benchmarks/corelib/text/qlocale/main.cpp +++ b/tests/benchmarks/corelib/text/qlocale/main.cpp @@ -28,6 +28,7 @@ #include <QLocale> #include <QTest> +#include <limits> class tst_QLocale : public QObject { @@ -37,6 +38,12 @@ private Q_SLOTS: void toUpper_QLocale_1(); void toUpper_QLocale_2(); void toUpper_QString(); + void toLongLong_data(); + void toLongLong(); + void toULongLong_data(); + void toULongLong(); + void toDouble_data(); + void toDouble(); }; static QString data() @@ -65,6 +72,271 @@ void tst_QLocale::toUpper_QString() QBENCHMARK { LOOP(s.toUpper()) } } +template <typename Integer> +void toWholeCommon_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<QString>("locale"); + QTest::addColumn<bool>("good"); + QTest::addColumn<Integer>("expected"); + + QTest::newRow("C: empty") + << QStringLiteral("") << QStringLiteral("C") << false << Integer(0ull); + QTest::newRow("C: 0") << QStringLiteral("0") << QStringLiteral("C") << true << Integer(0ull); + QTest::newRow("C: 1234") + << QStringLiteral("1234") << QStringLiteral("C") << true << Integer(1234ull); + // C locale omits grouping, but doesn't reject it. + QTest::newRow("C: 1,234") + << QStringLiteral("1,234") << QStringLiteral("C") << true << Integer(1234ull); + QTest::newRow("C: 123456789") + << QStringLiteral("123456789") << QStringLiteral("C") << true << Integer(123456789ull); + QTest::newRow("C: 123,456,789") + << QStringLiteral("123,456,789") + << QStringLiteral("C") << true << Integer(123456789ull); + + QTest::newRow("en: empty") + << QStringLiteral("") << QStringLiteral("en") << false << Integer(0ull); + QTest::newRow("en: 0") + << QStringLiteral("0") << QStringLiteral("en") << true << Integer(0ull); + QTest::newRow("en: 1234") + << QStringLiteral("1234") << QStringLiteral("en") << true << Integer(1234ull); + QTest::newRow("en: 1,234") + << QStringLiteral("1,234") << QStringLiteral("en") << true << Integer(1234ull); + QTest::newRow("en: 123,456,789") + << QStringLiteral("123,456,789") + << QStringLiteral("en") << true << Integer(123456789ull); + QTest::newRow("en: 123456789") + << QStringLiteral("123456789") << QStringLiteral("en") << true << Integer(123456789ull); + + QTest::newRow("de: empty") + << QStringLiteral("") << QStringLiteral("de") << false << Integer(0ull); + QTest::newRow("de: 0") << QStringLiteral("0") << QStringLiteral("de") << true << Integer(0ull); + QTest::newRow("de: 1234") + << QStringLiteral("1234") << QStringLiteral("de") << true << Integer(1234ull); + QTest::newRow("de: 1.234") + << QStringLiteral("1.234") << QStringLiteral("de") << true << Integer(1234ull); + QTest::newRow("de: 123.456.789") + << QStringLiteral("123.456.789") + << QStringLiteral("de") << true << Integer(123456789ull); + QTest::newRow("de: 123456789") + << QStringLiteral("123456789") << QStringLiteral("de") << true << Integer(123456789ull); + + // Locales with non-single-character signs: + QTest::newRow("ar_EG: +403") // Arabic, Egypt + << QStringLiteral("\u061c+\u0664\u0660\u0663") + << QStringLiteral("ar_EG") << true << Integer(403ull); + QTest::newRow("ar_EG: !403") // Only first character of the sign + << QStringLiteral("\u061c\u0664\u0660\u0663") + << QStringLiteral("ar_EG") << false << Integer(0ull); + QTest::newRow("fa_IR: +403") // Farsi, Iran + << QStringLiteral("\u200e+\u06f4\u06f0\u06f3") + << QStringLiteral("fa_IR") << true << Integer(403ull); + QTest::newRow("fa_IR: !403") // Only first character of sign + << QStringLiteral("\u200e\u06f4\u06f0\u06f3") + << QStringLiteral("fa_IR") << false << Integer(0ull); +} + +void tst_QLocale::toLongLong_data() +{ + toWholeCommon_data<qlonglong>(); + + QTest::newRow("C: -1234") << QStringLiteral("-1234") << QStringLiteral("C") << true << -1234ll; + QTest::newRow("C: -123456789") + << QStringLiteral("-123456789") << QStringLiteral("C") << true << -123456789ll; + QTest::newRow("C: qlonglong-max") + << QStringLiteral("9223372036854775807") << QStringLiteral("C") << true + << std::numeric_limits<qlonglong>::max(); + QTest::newRow("C: qlonglong-min") + << QStringLiteral("-9223372036854775808") << QStringLiteral("C") << true + << std::numeric_limits<qlonglong>::min(); + + // Locales with multi-character signs: + QTest::newRow("ar_EG: -403") // Arabic, Egypt + << QStringLiteral("\u061c-\u0664\u0660\u0663") + << QStringLiteral("ar_EG") << true << -403ll; + QTest::newRow("fa_IR: -403") // Farsi, Iran + << QStringLiteral("\u200e\u2212\u06f4\u06f0\u06f3") + << QStringLiteral("fa_IR") << true << -403ll; +} + +void tst_QLocale::toLongLong() +{ + QFETCH(QString, text); + QFETCH(QString, locale); + QFETCH(bool, good); + QFETCH(qlonglong, expected); + + const QLocale loc(locale); + qlonglong actual = expected; + bool ok = false; + QBENCHMARK { + actual = loc.toLongLong(text, &ok); + } + QEXPECT_FAIL("ar_EG: +403", "Code wrongly assumes single character, QTBUG-107801", Abort); + QEXPECT_FAIL("ar_EG: -403", "Code wrongly assumes single character, QTBUG-107801", Abort); + QEXPECT_FAIL("fa_IR: +403", "Code wrongly assumes single character, QTBUG-107801", Abort); + QEXPECT_FAIL("fa_IR: -403", "Code wrongly assumes single character, QTBUG-107801", Abort); + QCOMPARE(ok, good); + QCOMPARE(actual, expected); +} + +void tst_QLocale::toULongLong_data() +{ + toWholeCommon_data<qulonglong>(); + + QTest::newRow("C: qlonglong-max + 1") + << QStringLiteral("9223372036854775808") << QStringLiteral("C") << true + << (qulonglong(std::numeric_limits<qlonglong>::max()) + 1); + QTest::newRow("C: qulonglong-max") + << QStringLiteral("18446744073709551615") << QStringLiteral("C") << true + << std::numeric_limits<qulonglong>::max(); +} + +void tst_QLocale::toULongLong() +{ + QFETCH(QString, text); + QFETCH(QString, locale); + QFETCH(bool, good); + QFETCH(qulonglong, expected); + + const QLocale loc(locale); + qulonglong actual = expected; + bool ok = false; + QBENCHMARK { + actual = loc.toULongLong(text, &ok); + } + QEXPECT_FAIL("ar_EG: +403", "Code wrongly assumes single character, QTBUG-107801", Abort); + QEXPECT_FAIL("fa_IR: +403", "Code wrongly assumes single character, QTBUG-107801", Abort); + QCOMPARE(ok, good); + QCOMPARE(actual, expected); +} + + +void tst_QLocale::toDouble_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<QString>("locale"); + QTest::addColumn<bool>("good"); + QTest::addColumn<double>("expected"); + + QTest::newRow("C: empty") << QStringLiteral("") << QStringLiteral("C") << false << 0.0; + QTest::newRow("C: 0") << QStringLiteral("0") << QStringLiteral("C") << true << 0.0; + QTest::newRow("C: 0.12340") + << QStringLiteral("0.12340") << QStringLiteral("C") << true << 0.12340; + QTest::newRow("C: -0.12340") + << QStringLiteral("-0.12340") << QStringLiteral("C") << true << -0.12340; + QTest::newRow("C: −0.12340") + << QStringLiteral("\u2212" "0.12340") << QStringLiteral("C") << true << -0.12340; + QTest::newRow("C: 1.0e-4") << QStringLiteral("1.0e-4") << QStringLiteral("C") << true << 1.0e-4; + QTest::newRow("C: 1.0e−4") + << QStringLiteral("1.0e\u2212" "4") << QStringLiteral("C") << true << 1.0e-4; + QTest::newRow("C: 1.0e+4") << QStringLiteral("1.0e+4") << QStringLiteral("C") << true << 1.0e+4; + QTest::newRow("C: 10.e+3") << QStringLiteral("10.e+3") << QStringLiteral("C") << true << 1.0e+4; + QTest::newRow("C: 10e+3.") + << QStringLiteral("10e+3.") << QStringLiteral("C") << false << 0.0; // exp...dot + QTest::newRow("C: 1e4") << QStringLiteral("1e4") << QStringLiteral("C") << true << 1.0e+4; + + // NaN and infinity: + QTest::newRow("C: nan") << QStringLiteral("nan") << QStringLiteral("C") << true << qQNaN(); + QTest::newRow("C: NaN") << QStringLiteral("NaN") << QStringLiteral("C") << true << qQNaN(); + QTest::newRow("C: -nan") << QStringLiteral("-nan") << QStringLiteral("C") << false << 0.0; + QTest::newRow("C: +nan") << QStringLiteral("+nan") << QStringLiteral("C") << false << 0.0; + QTest::newRow("C: inf") << QStringLiteral("inf") << QStringLiteral("C") << true << qInf(); + QTest::newRow("C: Inf") << QStringLiteral("Inf") << QStringLiteral("C") << true << qInf(); + QTest::newRow("C: +inf") << QStringLiteral("+inf") << QStringLiteral("C") << true << qInf(); + QTest::newRow("C: -inf") << QStringLiteral("-inf") << QStringLiteral("C") << true << -qInf(); + + // Wantonly long-form representations, with trailing and leading zeros: + QTest::newRow("C: 1e-64 long-form") + << (QStringLiteral("0.") + QString(63, u'0') + u'1' + QString(962, u'0')) + << QStringLiteral("C") << true << 1e-64; + QTest::newRow("C: 1e+64 long-form") + << (QString(961, u'0') + u'1' + QString(64, u'0') + QStringLiteral(".0")) + << QStringLiteral("C") << true << 1e+64; + QTest::newRow("C: long-form 1 via e+64") + << (QStringLiteral("0.") + QString(63, u'0') + u'1' + QString(962, u'0') + + QStringLiteral("e+64")) + << QStringLiteral("C") << true << 1.0; + QTest::newRow("C: long-form 1 via e-64") + << (QString(961, u'0') + u'1' + QString(64, u'0') + QStringLiteral(".0e-64")) + << QStringLiteral("C") << true << 1.0; + QTest::newRow("C: 12345678.9") + << QStringLiteral("12345678.9") << QStringLiteral("C") << true << 12345678.9; + + // With and without grouping, en vs de for flipped separators: + QTest::newRow("en: 12345678.9") + << QStringLiteral("12345678.9") << QStringLiteral("en") << true << 12345678.9; + QTest::newRow("en: 12,345,678.9") + << QStringLiteral("12,345,678.9") << QStringLiteral("en") << true << 12345678.9; + QTest::newRow("de: 12345678,9") + << QStringLiteral("12345678,9") << QStringLiteral("de") << true << 12345678.9; + QTest::newRow("de: 12.345.678,9") + << QStringLiteral("12.345.678,9") << QStringLiteral("de") << true << 12345678.9; + + // NaN and infinity are locale-independent (for now - QTBUG-95460) + QTest::newRow("cy: nan") << QStringLiteral("nan") << QStringLiteral("cy") << true << qQNaN(); + QTest::newRow("cy: NaN") << QStringLiteral("NaN") << QStringLiteral("cy") << true << qQNaN(); + QTest::newRow("cy: -nan") << QStringLiteral("-nan") << QStringLiteral("cy") << false << 0.0; + QTest::newRow("cy: +nan") << QStringLiteral("+nan") << QStringLiteral("cy") << false << 0.0; + QTest::newRow("cy: inf") << QStringLiteral("inf") << QStringLiteral("cy") << true << qInf(); + QTest::newRow("cy: Inf") << QStringLiteral("Inf") << QStringLiteral("cy") << true << qInf(); + QTest::newRow("cy: +inf") << QStringLiteral("+inf") << QStringLiteral("cy") << true << qInf(); + QTest::newRow("cy: -inf") << QStringLiteral("-inf") << QStringLiteral("cy") << true << -qInf(); + // Samples ready for QTBUG-95460: + QTest::newRow("en: ∞") + << QStringLiteral("\u221e") << QStringLiteral("en") << true << qInf(); + QTest::newRow("ga: Nuimh") + << QStringLiteral("Nuimh") << QStringLiteral("ga") << true << qQNaN(); + + // Locales with multi-character exponents: + QTest::newRow("sv_SE: 4e-3") // Swedish, Sweden + << QStringLiteral("4\u00d7" "10^\u2212" "03") + << QStringLiteral("sv_SE") << true << 4e-3; + QTest::newRow("sv_SE: 4x-3") // Only first character of exponent + << QStringLiteral("4\u00d7\u2212" "03") + << QStringLiteral("sv_SE") << false << 0.0; + QTest::newRow("se_NO: 4e-3") // Northern Sami, Norway + << QStringLiteral("4\u00b7" "10^\u2212" "03") + << QStringLiteral("se_NO") << true << 4e-3; + QTest::newRow("se_NO: 4x-3") // Only first character of exponent + << QStringLiteral("4\u00b7\u2212" "03") + << QStringLiteral("se_NO") << false << 0.0; + QTest::newRow("ar_EG: 4e-3") // Arabic, Egypt + << QStringLiteral("\u0664\u0627\u0633\u061c-\u0660\u0663") + << QStringLiteral("ar_EG") << true << 4e-3; + QTest::newRow("ar_EG: 4x-3") // Only first character of exponent + << QStringLiteral("\u0664\u0627\u061c-\u0660\u0663") + << QStringLiteral("ar_EG") << false << 0.0; + QTest::newRow("ar_EG: 4e!3") // Only first character of sign + << QStringLiteral("\u0664\u0627\u0633\u061c\u0660\u0663") + << QStringLiteral("ar_EG") << false << 0.0; + QTest::newRow("ar_EG: 4x!3") // Only first character of sign and exponent + << QStringLiteral("\u0664\u0627\u061c\u0660\u0663") + << QStringLiteral("ar_EG") << false << 0.0; +} + +void tst_QLocale::toDouble() +{ + QFETCH(QString, text); + QFETCH(QString, locale); + QFETCH(bool, good); + QFETCH(double, expected); + + const QLocale loc(locale); + double actual = expected; + bool ok = false; + QBENCHMARK { + actual = loc.toDouble(text, &ok); + } + QEXPECT_FAIL("sv_SE: 4e-3", "Code wrongly assumes single character, QTBUG-107801", Abort); + QEXPECT_FAIL("se_NO: 4e-3", "Code wrongly assumes single character, QTBUG-107801", Abort); + QEXPECT_FAIL("ar_EG: 4e-3", "Code wrongly assumes single character, QTBUG-107801", Abort); + QEXPECT_FAIL("en: ∞", "Localized infinity support missing: QTBUG-95460", Abort); + QEXPECT_FAIL("ga: Nuimh", "Localized NaN support missing: QTBUG-95460", Abort); + QCOMPARE(ok, good); + QCOMPARE(actual, expected); +} + QTEST_MAIN(tst_QLocale) #include "main.moc" diff --git a/tests/benchmarks/corelib/text/qstring/main.cpp b/tests/benchmarks/corelib/text/qstring/main.cpp index 826a843c10..1c7c3d690e 100644 --- a/tests/benchmarks/corelib/text/qstring/main.cpp +++ b/tests/benchmarks/corelib/text/qstring/main.cpp @@ -28,6 +28,7 @@ #include <QStringList> #include <QFile> #include <QtTest/QtTest> +#include <limits> class tst_QString: public QObject { @@ -49,6 +50,14 @@ private slots: void toCaseFolded_data(); void toCaseFolded(); + // Parsing: + void toLongLong_data(); + void toLongLong(); + void toULongLong_data(); + void toULongLong(); + void toDouble_data(); + void toDouble(); + private: void section_data_impl(bool includeRegExOnly = true); template <typename RX> void section_impl(); @@ -188,6 +197,155 @@ void tst_QString::toCaseFolded() } } +template <typename Integer> +void toWholeCommon_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<int>("base"); + QTest::addColumn<bool>("good"); + QTest::addColumn<Integer>("expected"); + + QTest::newRow("empty") << QStringLiteral("") << 10 << false << Integer(0ull); + QTest::newRow("0") << QStringLiteral("0") << 10 << true << Integer(0ull); + QTest::newRow("1234") << QStringLiteral("1234") << 10 << true << Integer(1234ull); + QTest::newRow("1,234") << QStringLiteral("1,234") << 10 << false << Integer(0ull); + QTest::newRow("123456789") + << QStringLiteral("123456789") << 10 << true << Integer(123456789ull); + QTest::newRow("bad1dea, base 16") + << QStringLiteral("bad1dea") << 16 << true << Integer(0xBAD1DEAull); + QTest::newRow("bad1dea, base 10") << QStringLiteral("bad1dea") << 10 << false << Integer(0ull); + QTest::newRow("42, base 13") << QStringLiteral("42") << 13 << true << Integer(6ull * 9ull); + QTest::newRow("242, base 8") << QStringLiteral("242") << 8 << true << Integer(0242ull); + QTest::newRow("495, base 8") << QStringLiteral("495") << 8 << false << Integer(0ull); + QTest::newRow("101101, base 2") + << QStringLiteral("101101") << 2 << true << Integer(0b101101ull); + QTest::newRow("ad, base 30") << QStringLiteral("ad") << 30 << true << Integer(313ull); +} + +void tst_QString::toLongLong_data() +{ + toWholeCommon_data<qlonglong>(); + + QTest::newRow("-1234") << QStringLiteral("-1234") << 10 << true << -1234ll; + QTest::newRow("-123456789") << QStringLiteral("-123456789") << 10 << true << -123456789ll; + QTest::newRow("-bad1dea, base 16") << QStringLiteral("-bad1dea") << 16 << true << -0xBAD1DEAll; + QTest::newRow("-242, base 8") << QStringLiteral("-242") << 8 << true << -0242ll; + QTest::newRow("-101101, base 2") << QStringLiteral("-101101") << 2 << true << -0b101101ll; + QTest::newRow("-ad, base 30") << QStringLiteral("-ad") << 30 << true << -313ll; + + QTest::newRow("qlonglong-max") + << QStringLiteral("9223372036854775807") << 10 << true + << std::numeric_limits<qlonglong>::max(); + QTest::newRow("qlonglong-min") + << QStringLiteral("-9223372036854775808") << 10 << true + << std::numeric_limits<qlonglong>::min(); + QTest::newRow("qlonglong-max, base 2") + << QString(63, u'1') << 2 << true << std::numeric_limits<qlonglong>::max(); + QTest::newRow("qlonglong-min, base 2") + << (QStringLiteral("-1") + QString(63, u'0')) << 2 << true + << std::numeric_limits<qlonglong>::min(); + QTest::newRow("qlonglong-max, base 16") + << (QChar(u'7') + QString(15, u'f')) << 16 << true + << std::numeric_limits<qlonglong>::max(); + QTest::newRow("qlonglong-min, base 16") + << (QStringLiteral("-8") + QString(15, u'0')) << 16 << true + << std::numeric_limits<qlonglong>::min(); +} + +void tst_QString::toLongLong() +{ + QFETCH(QString, text); + QFETCH(int, base); + QFETCH(bool, good); + QFETCH(qlonglong, expected); + + qlonglong actual = expected; + bool ok = false; + QBENCHMARK { + actual = text.toLongLong(&ok, base); + } + QCOMPARE(ok, good); + QCOMPARE(actual, expected); +} + +void tst_QString::toULongLong_data() +{ + toWholeCommon_data<qulonglong>(); + + QTest::newRow("qlonglong-max + 1") + << QStringLiteral("9223372036854775808") << 10 << true + << (qulonglong(std::numeric_limits<qlonglong>::max()) + 1); + QTest::newRow("qulonglong-max") + << QStringLiteral("18446744073709551615") << 10 << true + << std::numeric_limits<qulonglong>::max(); + QTest::newRow("qulonglong-max, base 2") + << QString(64, u'1') << 2 << true << std::numeric_limits<qulonglong>::max(); + QTest::newRow("qulonglong-max, base 16") + << QString(16, u'f') << 16 << true << std::numeric_limits<qulonglong>::max(); +} + +void tst_QString::toULongLong() +{ + QFETCH(QString, text); + QFETCH(int, base); + QFETCH(bool, good); + QFETCH(qulonglong, expected); + + qulonglong actual = expected; + bool ok = false; + QBENCHMARK { + actual = text.toULongLong(&ok, base); + } + QCOMPARE(ok, good); + QCOMPARE(actual, expected); +} + +void tst_QString::toDouble_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<bool>("good"); + QTest::addColumn<double>("expected"); + + QTest::newRow("empty") << QStringLiteral("") << false << 0.0; + QTest::newRow("0") << QStringLiteral("0") << true << 0.0; + QTest::newRow("0.12340") << QStringLiteral("0.12340") << true << 0.12340; + QTest::newRow("-0.12340") << QStringLiteral("-0.12340") << true << -0.12340; + QTest::newRow("epsilon") + << QStringLiteral("2.220446049e-16") << true << std::numeric_limits<double>::epsilon(); + QTest::newRow("1.0e-4") << QStringLiteral("1.0e-4") << true << 1.0e-4; + QTest::newRow("1.0e+4") << QStringLiteral("1.0e+4") << true << 1.0e+4; + QTest::newRow("10.e+3") << QStringLiteral("10.e+3") << true << 1.0e+4; + QTest::newRow("10e+3.") << QStringLiteral("10e+3.") << false << 0.0; + QTest::newRow("1e4") << QStringLiteral("1e4") << true << 1.0e+4; + QTest::newRow("1.0e-8") << QStringLiteral("1.0e-8") << true << 1.0e-8; + QTest::newRow("1.0e+8") << QStringLiteral("1.0e+8") << true << 1.0e+8; + + // NaN and infinity: + QTest::newRow("nan") << QStringLiteral("nan") << true << qQNaN(); + QTest::newRow("NaN") << QStringLiteral("NaN") << true << qQNaN(); + QTest::newRow("-nan") << QStringLiteral("-nan") << false << 0.0; + QTest::newRow("+nan") << QStringLiteral("+nan") << false << 0.0; + QTest::newRow("inf") << QStringLiteral("inf") << true << qInf(); + QTest::newRow("Inf") << QStringLiteral("Inf") << true << qInf(); + QTest::newRow("+inf") << QStringLiteral("+inf") << true << qInf(); + QTest::newRow("-inf") << QStringLiteral("-inf") << true << -qInf(); +} + +void tst_QString::toDouble() +{ + QFETCH(QString, text); + QFETCH(bool, good); + QFETCH(double, expected); + + double actual = expected; + bool ok = false; + QBENCHMARK { + actual = text.toDouble(&ok); + } + QCOMPARE(ok, good); + QCOMPARE(actual, expected); +} + QTEST_APPLESS_MAIN(tst_QString) #include "main.moc" diff --git a/tests/benchmarks/corelib/time/qdatetime/main.cpp b/tests/benchmarks/corelib/time/qdatetime/main.cpp index 740e08cc46..14e7c43a99 100644 --- a/tests/benchmarks/corelib/time/qdatetime/main.cpp +++ b/tests/benchmarks/corelib/time/qdatetime/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -36,24 +36,12 @@ class tst_QDateTime : public QObject { Q_OBJECT - enum : qint64 - { - SECS_PER_DAY = 86400, - MSECS_PER_DAY = 86400000, - JULIAN_DAY_1950 = 2433283, - JULIAN_DAY_1960 = 2436935, - JULIAN_DAY_1970 = 2440588, // Epoch - JULIAN_DAY_2010 = 2455198, - JULIAN_DAY_2011 = 2455563, - JULIAN_DAY_2020 = 2458850, - JULIAN_DAY_2050 = 2469808, - JULIAN_DAY_2060 = 2473460 - }; - static QVector<QDateTime> daily(qint64 start, qint64 end); static QVector<QDateTime> norse(qint64 start, qint64 end); + void decade_data(); private Q_SLOTS: + void create_data() { decade_data(); } void create(); void isNull(); void isValid(); @@ -62,12 +50,10 @@ private Q_SLOTS: void timeSpec(); void offsetFromUtc(); void timeZoneAbbreviation(); + void toMSecsSinceEpoch_data() { decade_data(); } void toMSecsSinceEpoch(); - void toMSecsSinceEpoch1950(); - void toMSecsSinceEpoch2050(); + void toMSecsSinceEpochTz_data() { decade_data(); } void toMSecsSinceEpochTz(); - void toMSecsSinceEpoch1950Tz(); - void toMSecsSinceEpoch2050Tz(); void setDate(); void setTime(); void setTimeSpec(); @@ -102,6 +88,33 @@ private Q_SLOTS: void fromMSecsSinceEpochTz(); }; +constexpr qint64 SECS_PER_DAY = 86400; +constexpr qint64 MSECS_PER_DAY = 86400000; +constexpr qint64 JULIAN_DAY_1 = 1721426; +constexpr qint64 JULIAN_DAY_11 = 1725078; +constexpr qint64 JULIAN_DAY_1890 = 2411369; +constexpr qint64 JULIAN_DAY_1900 = 2415021; +constexpr qint64 JULIAN_DAY_1950 = 2433283; +constexpr qint64 JULIAN_DAY_1960 = 2436935; +constexpr qint64 JULIAN_DAY_1970 = 2440588; // Epoch +constexpr qint64 JULIAN_DAY_2010 = 2455198; +constexpr qint64 JULIAN_DAY_2011 = 2455563; +constexpr qint64 JULIAN_DAY_2020 = 2458850; +constexpr qint64 JULIAN_DAY_2050 = 2469808; +constexpr qint64 JULIAN_DAY_2060 = 2473460; + +void tst_QDateTime::decade_data() +{ + QTest::addColumn<qint64>("startJd"); + QTest::addColumn<qint64>("stopJd"); + + QTest::newRow("first-decade-CE") << JULIAN_DAY_1 << JULIAN_DAY_11; + QTest::newRow("1890s") << JULIAN_DAY_1890 << JULIAN_DAY_1900; + QTest::newRow("1950s") << JULIAN_DAY_1950 << JULIAN_DAY_1960; + QTest::newRow("2010s") << JULIAN_DAY_2010 << JULIAN_DAY_2020; + QTest::newRow("2050s") << JULIAN_DAY_2050 << JULIAN_DAY_2060; +} + QVector<QDateTime> tst_QDateTime::daily(qint64 start, qint64 end) { QVector<QDateTime> list; @@ -123,9 +136,12 @@ QVector<QDateTime> tst_QDateTime::norse(qint64 start, qint64 end) void tst_QDateTime::create() { + QFETCH(const qint64, startJd); + QFETCH(const qint64, stopJd); + const QTime noon = QTime::fromMSecsSinceStartOfDay(43200); QBENCHMARK { - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) { - QDateTime test(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)); + for (int jd = startJd; jd < stopJd; ++jd) { + QDateTime test(QDate::fromJulianDay(jd), noon); Q_UNUSED(test) } } @@ -196,25 +212,9 @@ void tst_QDateTime::timeZoneAbbreviation() void tst_QDateTime::toMSecsSinceEpoch() { - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - test.toMSecsSinceEpoch(); - } -} - -void tst_QDateTime::toMSecsSinceEpoch1950() -{ - const auto list = daily(JULIAN_DAY_1950, JULIAN_DAY_1960); - QBENCHMARK { - for (const QDateTime &test : list) - test.toMSecsSinceEpoch(); - } -} - -void tst_QDateTime::toMSecsSinceEpoch2050() -{ - const auto list = daily(JULIAN_DAY_2050, JULIAN_DAY_2060); + QFETCH(const qint64, startJd); + QFETCH(const qint64, stopJd); + const auto list = daily(startJd, stopJd); QBENCHMARK { for (const QDateTime &test : list) test.toMSecsSinceEpoch(); @@ -223,30 +223,11 @@ void tst_QDateTime::toMSecsSinceEpoch2050() void tst_QDateTime::toMSecsSinceEpochTz() { - qint64 result; - const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - result = test.toMSecsSinceEpoch(); - } - Q_UNUSED(result); -} - -void tst_QDateTime::toMSecsSinceEpoch1950Tz() -{ - qint64 result; - const auto list = norse(JULIAN_DAY_1950, JULIAN_DAY_1960); - QBENCHMARK { - for (const QDateTime &test : list) - result = test.toMSecsSinceEpoch(); - } - Q_UNUSED(result); -} + QFETCH(const qint64, startJd); + QFETCH(const qint64, stopJd); + const auto list = norse(startJd, stopJd); -void tst_QDateTime::toMSecsSinceEpoch2050Tz() -{ qint64 result; - const auto list = norse(JULIAN_DAY_2050, JULIAN_DAY_2060); QBENCHMARK { for (const QDateTime &test : list) result = test.toMSecsSinceEpoch(); diff --git a/tests/benchmarks/corelib/tools/qcryptographichash/main.cpp b/tests/benchmarks/corelib/tools/qcryptographichash/main.cpp index 1d414161d1..a29c409a44 100644 --- a/tests/benchmarks/corelib/tools/qcryptographichash/main.cpp +++ b/tests/benchmarks/corelib/tools/qcryptographichash/main.cpp @@ -1,5 +1,6 @@ /**************************************************************************** ** +** Copyright (C) 2023 The Qt Company Ltd. ** Copyright (C) 2017 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** @@ -29,10 +30,15 @@ #include <QByteArray> #include <QCryptographicHash> #include <QFile> +#include <QMetaEnum> +#include <QMessageAuthenticationCode> #include <QRandomGenerator> #include <QString> #include <QtTest> +#include <functional> +#include <numeric> + #include <time.h> class tst_bench_QCryptographicHash : public QObject @@ -40,6 +46,8 @@ class tst_bench_QCryptographicHash : public QObject Q_OBJECT QByteArray blockOfData; + using Algorithm = QCryptographicHash::Algorithm; + public: tst_bench_QCryptographicHash(); @@ -50,47 +58,25 @@ private Q_SLOTS: void addData(); void addDataChunked_data() { hash_data(); } void addDataChunked(); + + // QMessageAuthenticationCode: + void hmac_hash_data() { hash_data(); } + void hmac_hash(); + void hmac_addData_data() { hash_data(); } + void hmac_addData(); + void hmac_setKey_data(); + void hmac_setKey(); }; -const int MaxCryptoAlgorithm = QCryptographicHash::Sha3_512; const int MaxBlockSize = 65536; -const char *algoname(int i) +static void for_each_algorithm(std::function<void(QCryptographicHash::Algorithm, const char*)> f) { - switch (QCryptographicHash::Algorithm(i)) { - case QCryptographicHash::Md4: - return "md4-"; - case QCryptographicHash::Md5: - return "md5-"; - case QCryptographicHash::Sha1: - return "sha1-"; - case QCryptographicHash::Sha224: - return "sha2_224-"; - case QCryptographicHash::Sha256: - return "sha2_256-"; - case QCryptographicHash::Sha384: - return "sha2_384-"; - case QCryptographicHash::Sha512: - return "sha2_512-"; - case QCryptographicHash::Sha3_224: - return "sha3_224-"; - case QCryptographicHash::Sha3_256: - return "sha3_256-"; - case QCryptographicHash::Sha3_384: - return "sha3_384-"; - case QCryptographicHash::Sha3_512: - return "sha3_512-"; - case QCryptographicHash::Keccak_224: - return "keccak_224-"; - case QCryptographicHash::Keccak_256: - return "keccak_256-"; - case QCryptographicHash::Keccak_384: - return "keccak_384-"; - case QCryptographicHash::Keccak_512: - return "keccak_512-"; - } - Q_UNREACHABLE(); - return 0; + Q_ASSERT(f); + using A = QCryptographicHash::Algorithm; + static const auto metaEnum = QMetaEnum::fromType<A>(); + for (int i = 0, value = metaEnum.value(i); value != -1; value = metaEnum.value(++i)) + f(A(value), metaEnum.key(i)); } tst_bench_QCryptographicHash::tst_bench_QCryptographicHash() @@ -110,7 +96,7 @@ tst_bench_QCryptographicHash::tst_bench_QCryptographicHash() void tst_bench_QCryptographicHash::hash_data() { - QTest::addColumn<int>("algorithm"); + QTest::addColumn<Algorithm>("algo"); QTest::addColumn<QByteArray>("data"); static const int datasizes[] = { 0, 1, 64, 65, 512, 4095, 4096, 4097, 65536 }; @@ -118,17 +104,17 @@ void tst_bench_QCryptographicHash::hash_data() Q_ASSERT(datasizes[i] < MaxBlockSize); QByteArray data = QByteArray::fromRawData(blockOfData.constData(), datasizes[i]); - for (int algo = QCryptographicHash::Md4; algo <= MaxCryptoAlgorithm; ++algo) - QTest::newRow(algoname(algo) + QByteArray::number(datasizes[i])) << algo << data; + for_each_algorithm([&] (Algorithm algo, const char *name) { + QTest::addRow("%s-%d", name, datasizes[i]) << algo << data; + }); } } void tst_bench_QCryptographicHash::hash() { - QFETCH(int, algorithm); + QFETCH(const Algorithm, algo); QFETCH(QByteArray, data); - QCryptographicHash::Algorithm algo = QCryptographicHash::Algorithm(algorithm); QBENCHMARK { QCryptographicHash::hash(data, algo); } @@ -136,10 +122,9 @@ void tst_bench_QCryptographicHash::hash() void tst_bench_QCryptographicHash::addData() { - QFETCH(int, algorithm); + QFETCH(const Algorithm, algo); QFETCH(QByteArray, data); - QCryptographicHash::Algorithm algo = QCryptographicHash::Algorithm(algorithm); QCryptographicHash hash(algo); QBENCHMARK { hash.reset(); @@ -150,10 +135,9 @@ void tst_bench_QCryptographicHash::addData() void tst_bench_QCryptographicHash::addDataChunked() { - QFETCH(int, algorithm); + QFETCH(const Algorithm, algo); QFETCH(QByteArray, data); - QCryptographicHash::Algorithm algo = QCryptographicHash::Algorithm(algorithm); QCryptographicHash hash(algo); QBENCHMARK { hash.reset(); @@ -167,6 +151,73 @@ void tst_bench_QCryptographicHash::addDataChunked() } } +static QByteArray hmacKey() { + static QByteArray key = [] { + QByteArray result(277, Qt::Uninitialized); + std::iota(result.begin(), result.end(), uchar(0)); // uchar so wraps after UCHAR_MAX + return result; + }(); + return key; +} + +void tst_bench_QCryptographicHash::hmac_hash() +{ + QFETCH(const Algorithm, algo); + QFETCH(const QByteArray, data); + + const auto key = hmacKey(); + QBENCHMARK { + auto r = QMessageAuthenticationCode::hash(data, key, algo); + Q_UNUSED(r); + } +} + +void tst_bench_QCryptographicHash::hmac_addData() +{ + QFETCH(const Algorithm, algo); + QFETCH(const QByteArray, data); + + const auto key = hmacKey(); + QMessageAuthenticationCode mac(algo, key); + QBENCHMARK { + mac.reset(); + mac.addData(data); + auto r = mac.result(); + Q_UNUSED(r); + } +} + +void tst_bench_QCryptographicHash::hmac_setKey_data() +{ + QTest::addColumn<Algorithm>("algo"); + for_each_algorithm([] (Algorithm algo, const char *name) { + QTest::addRow("%s", name) << algo; + }); +} + +void tst_bench_QCryptographicHash::hmac_setKey() +{ + QFETCH(const Algorithm, algo); + + const QByteArrayList keys = [] { + QByteArrayList result; + const auto fullKey = hmacKey(); + result.reserve(fullKey.size()); + for (auto i = fullKey.size(); i > 0; --i) + result.push_back(fullKey.mid(i)); + return result; + }(); + + QMessageAuthenticationCode mac(algo); + QBENCHMARK { + for (const auto &key : keys) { + mac.setKey(key); + mac.addData("abc", 3); // avoid lazy setKey() + } + } +} + + QTEST_APPLESS_MAIN(tst_bench_QCryptographicHash) #include "main.moc" diff --git a/tests/benchmarks/dbus/qdbusperformance/test/test.pro b/tests/benchmarks/dbus/qdbusperformance/test/test.pro index ddc5410759..faa2fe81ba 100644 --- a/tests/benchmarks/dbus/qdbusperformance/test/test.pro +++ b/tests/benchmarks/dbus/qdbusperformance/test/test.pro @@ -1,3 +1,4 @@ +CONFIG += benchmark SOURCES += ../tst_qdbusperformance.cpp HEADERS += ../serverobject.h TARGET = ../tst_qdbusperformance diff --git a/tests/benchmarks/dbus/qdbusperformance/tst_qdbusperformance.cpp b/tests/benchmarks/dbus/qdbusperformance/tst_qdbusperformance.cpp index 39c9129456..4bb71c4775 100644 --- a/tests/benchmarks/dbus/qdbusperformance/tst_qdbusperformance.cpp +++ b/tests/benchmarks/dbus/qdbusperformance/tst_qdbusperformance.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -79,7 +79,7 @@ void tst_QDBusPerformance::initTestCase() #else # define EXE "" #endif - proc.start(QFINDTESTDATA("server/server" EXE)); + proc.start(QFINDTESTDATA("server/server" EXE), QStringList()); QVERIFY2(proc.waitForStarted(), qPrintable(proc.errorString())); QVERIFY(proc.waitForReadyRead()); diff --git a/tests/benchmarks/gui/kernel/qguimetatype/tst_qguimetatype.cpp b/tests/benchmarks/gui/kernel/qguimetatype/tst_qguimetatype.cpp index 7d6c1ef86d..7b50b3e51a 100644 --- a/tests/benchmarks/gui/kernel/qguimetatype/tst_qguimetatype.cpp +++ b/tests/benchmarks/gui/kernel/qguimetatype/tst_qguimetatype.cpp @@ -28,6 +28,7 @@ #include <qtest.h> #include <QtCore/qmetatype.h> +#include <QScopeGuard> class tst_QGuiMetaType : public QObject { @@ -59,17 +60,20 @@ void tst_QGuiMetaType::constructInPlace_data() void tst_QGuiMetaType::constructInPlace() { QFETCH(int, typeId); - int size = QMetaType::sizeOf(typeId); + QMetaType type(typeId); + int size = type.sizeOf(); void *storage = qMallocAligned(size, 2 * sizeof(qlonglong)); - QCOMPARE(QMetaType::construct(typeId, storage, /*copy=*/0), storage); - QMetaType::destruct(typeId, storage); + auto cleanUp = qScopeGuard([&]() { + qFreeAligned(storage); + }); + QCOMPARE(type.construct(storage, /*copy=*/0), storage); + type.destruct(storage); QBENCHMARK { for (int i = 0; i < 100000; ++i) { - QMetaType::construct(typeId, storage, /*copy=*/0); - QMetaType::destruct(typeId, storage); + type.construct(storage, /*copy=*/0); + type.destruct(storage); } } - qFreeAligned(storage); } void tst_QGuiMetaType::constructInPlaceCopy_data() @@ -80,19 +84,22 @@ void tst_QGuiMetaType::constructInPlaceCopy_data() void tst_QGuiMetaType::constructInPlaceCopy() { QFETCH(int, typeId); - int size = QMetaType::sizeOf(typeId); + QMetaType type(typeId); + int size = type.sizeOf(); void *storage = qMallocAligned(size, 2 * sizeof(qlonglong)); - void *other = QMetaType::create(typeId); - QCOMPARE(QMetaType::construct(typeId, storage, other), storage); - QMetaType::destruct(typeId, storage); + void *other = type.create(); + auto cleanUp = qScopeGuard([&]() { + type.destroy(other); + qFreeAligned(storage); + }); + QCOMPARE(type.construct(storage, other), storage); + type.destruct(storage); QBENCHMARK { for (int i = 0; i < 100000; ++i) { - QMetaType::construct(typeId, storage, other); - QMetaType::destruct(typeId, storage); + type.construct(storage, other); + type.destruct(storage); } } - QMetaType::destroy(typeId, other); - qFreeAligned(storage); } QTEST_MAIN(tst_QGuiMetaType) diff --git a/tests/benchmarks/gui/painting/qtransform/tst_qtransform.cpp b/tests/benchmarks/gui/painting/qtransform/tst_qtransform.cpp index d28f9502d7..9c3cef0e6d 100644 --- a/tests/benchmarks/gui/painting/qtransform/tst_qtransform.cpp +++ b/tests/benchmarks/gui/painting/qtransform/tst_qtransform.cpp @@ -335,7 +335,7 @@ void tst_QTransform::operatorMultiplyEqualScalar() QFETCH(QTransform, transform); QTransform x = transform; QBENCHMARK { - x * 3; + x *= 3; } } diff --git a/tests/benchmarks/sql/kernel/qsqlrecord/tst_qsqlrecord.cpp b/tests/benchmarks/sql/kernel/qsqlrecord/tst_qsqlrecord.cpp index 8d7e70f8c9..6a5d353324 100644 --- a/tests/benchmarks/sql/kernel/qsqlrecord/tst_qsqlrecord.cpp +++ b/tests/benchmarks/sql/kernel/qsqlrecord/tst_qsqlrecord.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** - ** Copyright (C) 2018 The Qt Company Ltd. + ** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -178,15 +178,18 @@ void tst_QSqlRecord::benchmarkRecord() const auto tableName = qTableName("record", __FILE__, db); { QSqlQuery qry(db); - QVERIFY_SQL(qry, exec("create table " + tableName + " (id int NOT NULL, t_varchar varchar(20), " + QVERIFY_SQL(qry, exec("create table " + tableName + + " (id int NOT NULL, t_varchar varchar(20), " "t_char char(20), primary key(id))")); - for (int i = 0; i < 1000; i++) + // Limit to 500: at 600, the set-up takes nearly 5 minutes + for (int i = 0; i < 500; i++) QVERIFY_SQL(qry, exec(QString("INSERT INTO " + tableName + " VALUES (%1, 'VarChar%1', 'Char%1')").arg(i))); QVERIFY_SQL(qry, exec(QString("SELECT * from ") + tableName)); QBENCHMARK { while (qry.next()) qry.record(); + QVERIFY(qry.seek(0)); } } tst_Databases::safeDropTables(db, QStringList() << tableName); @@ -202,6 +205,7 @@ void tst_QSqlRecord::benchFieldName() QBENCHMARK { while (qry.next()) qry.value("r"); + QVERIFY(qry.seek(0)); } } } @@ -217,6 +221,7 @@ void tst_QSqlRecord::benchFieldIndex() QBENCHMARK { while (qry.next()) qry.value(0); + QVERIFY(qry.seek(0)); } } } diff --git a/tests/benchmarks/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/benchmarks/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 56b34fff2a..b9bbda766b 100644 --- a/tests/benchmarks/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/benchmarks/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -57,6 +57,7 @@ private slots: void scale(); void shear(); void translate(); + void createTextItem(); }; tst_QGraphicsItem::tst_QGraphicsItem() @@ -230,5 +231,15 @@ void tst_QGraphicsItem::translate() } } +void tst_QGraphicsItem::createTextItem() +{ + // Ensure QFontDatabase loaded the font beforehand + QFontInfo(qApp->font()).family(); + const QString text = "This is some text"; + QBENCHMARK { + QGraphicsTextItem item(text); + } +} + QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" |