summaryrefslogtreecommitdiffstats
path: root/tests/auto/other/qobjectrace/tst_qobjectrace.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/other/qobjectrace/tst_qobjectrace.cpp')
-rw-r--r--tests/auto/other/qobjectrace/tst_qobjectrace.cpp38
1 files changed, 20 insertions, 18 deletions
diff --git a/tests/auto/other/qobjectrace/tst_qobjectrace.cpp b/tests/auto/other/qobjectrace/tst_qobjectrace.cpp
index 2c28e691d1..af6634f253 100644
--- a/tests/auto/other/qobjectrace/tst_qobjectrace.cpp
+++ b/tests/auto/other/qobjectrace/tst_qobjectrace.cpp
@@ -1,5 +1,5 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore>
@@ -21,12 +21,20 @@ struct Functor
class tst_QObjectRace: public QObject
{
Q_OBJECT
+public:
+ tst_QObjectRace()
+ : ThreadCount(QThread::idealThreadCount())
+ {}
+
private slots:
void moveToThreadRace();
void destroyRace();
void blockingQueuedDestroyRace();
void disconnectRace();
void disconnectRace2();
+
+private:
+ const int ThreadCount;
};
class RaceObject : public QObject
@@ -110,8 +118,7 @@ void tst_QObjectRace::moveToThreadRace()
{
RaceObject *object = new RaceObject;
- enum { ThreadCount = 6 };
- RaceThread *threads[ThreadCount];
+ QVarLengthArray<RaceThread *, 16> threads(ThreadCount);
for (int i = 0; i < ThreadCount; ++i) {
threads[i] = new RaceThread;
threads[i]->setObject(object);
@@ -241,10 +248,10 @@ void tst_QObjectRace::destroyRace()
if (QTestPrivate::isRunningArmOnX86())
QSKIP("Test is too slow to run on emulator");
- enum { ThreadCount = 10, ObjectCountPerThread = 2777,
- ObjectCount = ThreadCount * ObjectCountPerThread };
+ constexpr int ObjectCountPerThread = 2777;
+ const int ObjectCount = ThreadCount * ObjectCountPerThread;
- MyObject *objects[ObjectCount];
+ QVarLengthArray<MyObject *, ObjectCountPerThread * 10> objects(ObjectCount);
for (int i = 0; i < ObjectCount; ++i)
objects[i] = new MyObject;
@@ -261,10 +268,10 @@ void tst_QObjectRace::destroyRace()
objects[((i+5)*79) % ObjectCount], Functor() );
}
- DestroyThread *threads[ThreadCount];
+ QVarLengthArray<DestroyThread *, 16> threads(ThreadCount);
for (int i = 0; i < ThreadCount; ++i) {
threads[i] = new DestroyThread;
- threads[i]->setObjects(objects + i*ObjectCountPerThread, ObjectCountPerThread);
+ threads[i]->setObjects(objects.data() + i*ObjectCountPerThread, ObjectCountPerThread);
}
for (int i = 0; i < ThreadCount; ++i)
@@ -302,8 +309,7 @@ public slots:
break;
}
- Q_UNREACHABLE();
- return false;
+ Q_UNREACHABLE_RETURN(false);
}
private:
@@ -312,9 +318,6 @@ private:
void tst_QObjectRace::blockingQueuedDestroyRace()
{
-#if !QT_CONFIG(cxx11_future)
- QSKIP("This test requires QThread::create");
-#else
enum { MinIterations = 100, MinTime = 3000, WaitTime = 25 };
BlockingQueuedDestroyRaceObject sender;
@@ -360,7 +363,6 @@ void tst_QObjectRace::blockingQueuedDestroyRace()
thread->wait();
}
-#endif
}
static QAtomicInteger<unsigned> countedStructObjectsCount;
@@ -477,7 +479,7 @@ public:
void tst_QObjectRace::disconnectRace()
{
- enum { ThreadCount = 20, TimeLimit = 3000 };
+ enum { TimeLimit = 3000 };
QCOMPARE(countedStructObjectsCount.loadRelaxed(), 0u);
@@ -487,7 +489,7 @@ void tst_QObjectRace::disconnectRace()
senderThread->start();
sender->moveToThread(senderThread.data());
- DisconnectRaceThread *threads[ThreadCount];
+ QVarLengthArray<DisconnectRaceThread *, 16> threads(ThreadCount);
for (int i = 0; i < ThreadCount; ++i) {
threads[i] = new DisconnectRaceThread(sender.data(), !(i % 10));
threads[i]->start();
@@ -513,7 +515,7 @@ void tst_QObjectRace::disconnectRace()
senderThread->start();
sender->moveToThread(senderThread.data());
- DeleteReceiverRaceReceiverThread *threads[ThreadCount];
+ QVarLengthArray<DeleteReceiverRaceReceiverThread *, 16> threads(ThreadCount);
for (int i = 0; i < ThreadCount; ++i) {
threads[i] = new DeleteReceiverRaceReceiverThread(sender.data());
threads[i]->start();