qt 6.5.1 original

This commit is contained in:
kleuter
2023-10-29 23:33:08 +01:00
parent 71d22ab6b0
commit 85d238dfda
21202 changed files with 5499099 additions and 0 deletions

View File

@ -0,0 +1,6 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(qlocalsocket)
add_subdirectory(qtcpserver)
add_subdirectory(qudpsocket)

View File

@ -0,0 +1,14 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qlocalsocket Binary:
#####################################################################
qt_internal_add_benchmark(tst_bench_qlocalsocket
SOURCES
tst_qlocalsocket.cpp
LIBRARIES
Qt::Network
Qt::Test
)

View File

@ -0,0 +1,212 @@
// Copyright (C) 2021 The Qt Company Ltd.
// Copyright (C) 2021 Alex Trotsenko <alex1973tr@gmail.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <QtTest/qtesteventloop.h>
#include <QtCore/qglobal.h>
#include <QtCore/qthread.h>
#include <QtCore/qsemaphore.h>
#include <QtCore/qbytearray.h>
#include <QtCore/qvector.h>
#include <QtCore/qelapsedtimer.h>
#include <QtNetwork/qlocalsocket.h>
#include <QtNetwork/qlocalserver.h>
class tst_QLocalSocket : public QObject
{
Q_OBJECT
private slots:
void pingPong_data();
void pingPong();
void dataExchange_data();
void dataExchange();
};
class ServerThread : public QThread
{
public:
QSemaphore running;
explicit ServerThread(int chunkSize)
{
buffer.resize(chunkSize);
}
void run() override
{
QLocalServer server;
connect(&server, &QLocalServer::newConnection, [this, &server]() {
auto socket = server.nextPendingConnection();
connect(socket, &QLocalSocket::readyRead, [this, socket]() {
const qint64 bytesAvailable = socket->bytesAvailable();
Q_ASSERT(bytesAvailable <= this->buffer.size());
QCOMPARE(socket->read(this->buffer.data(), bytesAvailable), bytesAvailable);
QCOMPARE(socket->write(this->buffer.data(), bytesAvailable), bytesAvailable);
});
});
// TODO QTBUG-95136: on failure, remove the socket file and retry.
QVERIFY2(server.listen("foo"), qPrintable(server.errorString()));
running.release();
exec();
}
protected:
QByteArray buffer;
};
class SocketFactory : public QObject
{
Q_OBJECT
public:
bool stopped = false;
explicit SocketFactory(int chunkSize, int connections)
{
buffer.resize(chunkSize);
for (int i = 0; i < connections; ++i) {
QLocalSocket *socket = new QLocalSocket(this);
Q_CHECK_PTR(socket);
connect(this, &SocketFactory::start, [this, socket]() {
QCOMPARE(socket->write(this->buffer), this->buffer.size());
});
connect(socket, &QLocalSocket::readyRead, [i, this, socket]() {
const qint64 bytesAvailable = socket->bytesAvailable();
Q_ASSERT(bytesAvailable <= this->buffer.size());
QCOMPARE(socket->read(this->buffer.data(), bytesAvailable), bytesAvailable);
emit this->bytesReceived(i, bytesAvailable);
if (!this->stopped)
QCOMPARE(socket->write(this->buffer.data(), bytesAvailable), bytesAvailable);
});
socket->connectToServer("foo");
QVERIFY2(socket->waitForConnected(), "The system is probably reaching the maximum "
"number of open file descriptors. On Unix, "
"try to increase the limit with 'ulimit -n 32000' "
"and run the test again.");
QCOMPARE(socket->state(), QLocalSocket::ConnectedState);
}
}
signals:
void start();
void bytesReceived(int channel, qint64 bytes);
protected:
QByteArray buffer;
};
void tst_QLocalSocket::pingPong_data()
{
QTest::addColumn<int>("connections");
for (int value : {10, 50, 100, 1000, 5000})
QTest::addRow("connections: %d", value) << value;
}
void tst_QLocalSocket::pingPong()
{
QFETCH(int, connections);
const int iterations = 100000;
Q_ASSERT(iterations >= connections && connections > 0);
ServerThread serverThread(1);
serverThread.start();
// Wait for server to start.
QVERIFY(serverThread.running.tryAcquire(1, 3000));
SocketFactory factory(1, connections);
QTestEventLoop eventLoop;
QVector<qint64> bytesToRead;
QElapsedTimer timer;
bytesToRead.fill(iterations / connections, connections);
connect(&factory, &SocketFactory::bytesReceived,
[&bytesToRead, &connections, &factory, &eventLoop](int channel, qint64 bytes) {
Q_UNUSED(bytes);
if (--bytesToRead[channel] == 0 && --connections == 0) {
factory.stopped = true;
eventLoop.exitLoop();
}
});
timer.start();
emit factory.start();
// QtTestLib's Watchdog defaults to 300 seconds; we want to give up before
// it bites.
eventLoop.enterLoop(290);
if (eventLoop.timeout())
qDebug("Timed out after %.1f s", timer.elapsed() / 1000.0);
else if (!QTest::currentTestFailed())
qDebug("Elapsed time: %.1f s", timer.elapsed() / 1000.0);
serverThread.quit();
serverThread.wait();
}
void tst_QLocalSocket::dataExchange_data()
{
QTest::addColumn<int>("connections");
QTest::addColumn<int>("chunkSize");
for (int connections : {1, 5, 10}) {
for (int chunkSize : {100, 1000, 10000, 100000}) {
QTest::addRow("connections: %d, chunk size: %d",
connections, chunkSize) << connections << chunkSize;
}
}
}
void tst_QLocalSocket::dataExchange()
{
QFETCH(int, connections);
QFETCH(int, chunkSize);
Q_ASSERT(chunkSize > 0 && connections > 0);
const qint64 timeToTest = 5000;
ServerThread serverThread(chunkSize);
serverThread.start();
// Wait for server to start.
QVERIFY(serverThread.running.tryAcquire(1, 3000));
SocketFactory factory(chunkSize, connections);
QTestEventLoop eventLoop;
qint64 totalReceived = 0;
QElapsedTimer timer;
connect(&factory, &SocketFactory::bytesReceived, [&](int channel, qint64 bytes) {
Q_UNUSED(channel);
totalReceived += bytes;
if (timer.elapsed() >= timeToTest) {
factory.stopped = true;
eventLoop.exitLoop();
}
});
timer.start();
emit factory.start();
eventLoop.enterLoopMSecs(timeToTest * 2);
if (!QTest::currentTestFailed())
qDebug("Transfer rate: %.1f MB/s", totalReceived / 1048.576 / timer.elapsed());
serverThread.quit();
serverThread.wait();
}
QTEST_MAIN(tst_QLocalSocket)
#include "tst_qlocalsocket.moc"

View File

@ -0,0 +1,14 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qtcpserver Binary:
#####################################################################
qt_internal_add_benchmark(tst_bench_qtcpserver
SOURCES
tst_qtcpserver.cpp
LIBRARIES
Qt::Network
Qt::Test
)

View File

@ -0,0 +1,241 @@
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <QtCore/QElapsedTimer>
#include <qglobal.h>
#include <qcoreapplication.h>
#include <qtcpsocket.h>
#include <qtcpserver.h>
#include <qhostaddress.h>
#include <qstringlist.h>
#include <qplatformdefs.h>
#include <qhostinfo.h>
#include <QNetworkProxy>
#include "../../../../auto/network-settings.h"
class tst_QTcpServer : public QObject
{
Q_OBJECT
public:
tst_QTcpServer();
virtual ~tst_QTcpServer();
public slots:
void initTestCase_data();
void initTestCase();
void init();
void cleanup();
private slots:
void ipv4LoopbackPerformanceTest();
void ipv6LoopbackPerformanceTest();
void ipv4PerformanceTest();
};
tst_QTcpServer::tst_QTcpServer()
{
}
tst_QTcpServer::~tst_QTcpServer()
{
}
void tst_QTcpServer::initTestCase_data()
{
QTest::addColumn<bool>("setProxy");
QTest::addColumn<int>("proxyType");
QTest::newRow("WithoutProxy") << false << 0;
#ifndef QT_NO_NETWORKPROXY
QTest::newRow("WithSocks5Proxy") << true << int(QNetworkProxy::Socks5Proxy);
#endif
}
void tst_QTcpServer::initTestCase()
{
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
}
void tst_QTcpServer::init()
{
QFETCH_GLOBAL(bool, setProxy);
if (setProxy) {
#ifndef QT_NO_NETWORKPROXY
QFETCH_GLOBAL(int, proxyType);
if (proxyType == QNetworkProxy::Socks5Proxy) {
QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::Socks5Proxy, QtNetworkSettings::serverName(), 1080));
}
#else // !QT_NO_NETWORKPROXY
QSKIP("No proxy support");
#endif // QT_NO_NETWORKPROXY
}
}
void tst_QTcpServer::cleanup()
{
#ifndef QT_NO_NETWORKPROXY
QNetworkProxy::setApplicationProxy(QNetworkProxy::DefaultProxy);
#endif
}
//----------------------------------------------------------------------------------
void tst_QTcpServer::ipv4LoopbackPerformanceTest()
{
QFETCH_GLOBAL(bool, setProxy);
if (setProxy)
return;
QTcpServer server;
QVERIFY(server.listen(QHostAddress::LocalHost));
QVERIFY(server.isListening());
QTcpSocket clientA;
clientA.connectToHost(QHostAddress::LocalHost, server.serverPort());
QVERIFY(clientA.waitForConnected(5000));
QVERIFY(clientA.state() == QAbstractSocket::ConnectedState);
QVERIFY(server.waitForNewConnection());
QTcpSocket *clientB = server.nextPendingConnection();
QVERIFY(clientB);
QByteArray buffer(16384, '@');
QElapsedTimer stopWatch;
stopWatch.start();
qlonglong totalWritten = 0;
while (stopWatch.elapsed() < 5000) {
QVERIFY(clientA.write(buffer.data(), buffer.size()) > 0);
clientA.flush();
totalWritten += buffer.size();
while (clientB->waitForReadyRead(100)) {
if (clientB->bytesAvailable() == 16384)
break;
}
clientB->read(buffer.data(), buffer.size());
clientB->write(buffer.data(), buffer.size());
clientB->flush();
totalWritten += buffer.size();
while (clientA.waitForReadyRead(100)) {
if (clientA.bytesAvailable() == 16384)
break;
}
clientA.read(buffer.data(), buffer.size());
}
qDebug("\t\t%s: %.1fMB/%.1fs: %.1fMB/s",
server.serverAddress().toString().toLatin1().constData(),
totalWritten / (1024.0 * 1024.0),
stopWatch.elapsed() / 1000.0,
(totalWritten / (stopWatch.elapsed() / 1000.0)) / (1024 * 1024));
delete clientB;
}
//----------------------------------------------------------------------------------
void tst_QTcpServer::ipv6LoopbackPerformanceTest()
{
QFETCH_GLOBAL(bool, setProxy);
if (setProxy)
return;
QTcpServer server;
if (!server.listen(QHostAddress::LocalHostIPv6, 0)) {
QVERIFY(server.serverError() == QAbstractSocket::UnsupportedSocketOperationError);
} else {
QTcpSocket clientA;
clientA.connectToHost(server.serverAddress(), server.serverPort());
QVERIFY(clientA.waitForConnected(5000));
QVERIFY(server.waitForNewConnection(5000));
QTcpSocket *clientB = server.nextPendingConnection();
QVERIFY(clientB);
QByteArray buffer(16384, '@');
QElapsedTimer stopWatch;
stopWatch.start();
qlonglong totalWritten = 0;
while (stopWatch.elapsed() < 5000) {
clientA.write(buffer.data(), buffer.size());
clientA.flush();
totalWritten += buffer.size();
while (clientB->waitForReadyRead(100)) {
if (clientB->bytesAvailable() == 16384)
break;
}
clientB->read(buffer.data(), buffer.size());
clientB->write(buffer.data(), buffer.size());
clientB->flush();
totalWritten += buffer.size();
while (clientA.waitForReadyRead(100)) {
if (clientA.bytesAvailable() == 16384)
break;
}
clientA.read(buffer.data(), buffer.size());
}
qDebug("\t\t%s: %.1fMB/%.1fs: %.1fMB/s",
server.serverAddress().toString().toLatin1().constData(),
totalWritten / (1024.0 * 1024.0),
stopWatch.elapsed() / 1000.0,
(totalWritten / (stopWatch.elapsed() / 1000.0)) / (1024 * 1024));
delete clientB;
}
}
//----------------------------------------------------------------------------------
void tst_QTcpServer::ipv4PerformanceTest()
{
QTcpSocket probeSocket;
probeSocket.connectToHost(QtNetworkSettings::serverName(), 143);
QVERIFY(probeSocket.waitForConnected(5000));
QTcpServer server;
QVERIFY(server.listen(probeSocket.localAddress(), 0));
QTcpSocket clientA;
clientA.connectToHost(server.serverAddress(), server.serverPort());
QVERIFY(clientA.waitForConnected(5000));
QVERIFY(server.waitForNewConnection(5000));
QTcpSocket *clientB = server.nextPendingConnection();
QVERIFY(clientB);
QByteArray buffer(16384, '@');
QElapsedTimer stopWatch;
stopWatch.start();
qlonglong totalWritten = 0;
while (stopWatch.elapsed() < 5000) {
qlonglong writtenA = clientA.write(buffer.data(), buffer.size());
clientA.flush();
totalWritten += buffer.size();
while (clientB->waitForReadyRead(100)) {
if (clientB->bytesAvailable() == writtenA)
break;
}
clientB->read(buffer.data(), buffer.size());
qlonglong writtenB = clientB->write(buffer.data(), buffer.size());
clientB->flush();
totalWritten += buffer.size();
while (clientA.waitForReadyRead(100)) {
if (clientA.bytesAvailable() == writtenB)
break;
}
clientA.read(buffer.data(), buffer.size());
}
qDebug("\t\t%s: %.1fMB/%.1fs: %.1fMB/s",
probeSocket.localAddress().toString().toLatin1().constData(),
totalWritten / (1024.0 * 1024.0),
stopWatch.elapsed() / 1000.0,
(totalWritten / (stopWatch.elapsed() / 1000.0)) / (1024 * 1024));
delete clientB;
}
QTEST_MAIN(tst_QTcpServer)
#include "tst_qtcpserver.moc"

View File

@ -0,0 +1,14 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qudpsocket Binary:
#####################################################################
qt_internal_add_benchmark(tst_bench_qudpsocket
SOURCES
tst_qudpsocket.cpp
LIBRARIES
Qt::Network
Qt::Test
)

View File

@ -0,0 +1,55 @@
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <QtCore/qglobal.h>
#include <QtCore/qcoreapplication.h>
#include <QtNetwork/qudpsocket.h>
#include <QtNetwork/qnetworkdatagram.h>
class tst_QUdpSocket : public QObject
{
Q_OBJECT
public:
tst_QUdpSocket();
private slots:
void pendingDatagramSize_data();
void pendingDatagramSize();
};
tst_QUdpSocket::tst_QUdpSocket()
{
}
void tst_QUdpSocket::pendingDatagramSize_data()
{
QTest::addColumn<int>("size");
for (int value : {52, 1024, 2049, 4500, 4098, 8192, 12000, 25000, 32 * 1024, 63 * 1024})
QTest::addRow("%d", value) << value;
}
void tst_QUdpSocket::pendingDatagramSize()
{
QFETCH(int, size);
QUdpSocket socket;
socket.bind();
QNetworkDatagram datagram;
datagram.setData(QByteArray(size, 'a'));
datagram.setDestination(QHostAddress::SpecialAddress::LocalHost, socket.localPort());
auto sent = socket.writeDatagram(datagram);
QCOMPARE(sent, size);
auto res = QTest::qWaitFor([&socket]() { return socket.hasPendingDatagrams(); }, 5000);
QVERIFY(res);
QBENCHMARK {
auto pendingSize = socket.pendingDatagramSize();
Q_UNUSED(pendingSize);
}
}
QTEST_MAIN(tst_QUdpSocket)
#include "tst_qudpsocket.moc"