30 #include <QtCore/QThread>
32 #include <QReadWriteLock>
34 #if defined(Q_OS_UNIX) && !defined(Q_OS_INTEGRITY)
35 #include <sys/resource.h>
38 #include <QtTest/private/qemulationdetector_p.h>
48 void beforeInitialization();
52 void catchExceptionAndRetry();
53 void threadStressTest();
54 void afterDestruction();
59 #if defined(Q_OS_UNIX) && !defined(Q_OS_INTEGRITY)
63 struct rlimit numFiles;
64 if (getrlimit(RLIMIT_NOFILE, &numFiles) == 0 && numFiles.rlim_cur < 1024) {
65 numFiles.rlim_cur = qMin(rlim_t(1024), numFiles.rlim_max);
66 setrlimit(RLIMIT_NOFILE, &numFiles);
83 void tst_QGlobalStatic::beforeInitialization()
85 QVERIFY(!checkedBeforeInitialization.exists());
86 QVERIFY(!checkedBeforeInitialization.isDestroyed());
94 void tst_QGlobalStatic::api()
98 QVERIFY(checkedAfterInitialization());
99 *checkedAfterInitialization =
Type();
100 *checkedAfterInitialization() =
Type();
102 checkedAfterInitialization()->
i = 47;
103 checkedAfterInitialization->
i = 42;
104 QCOMPARE(checkedAfterInitialization()->
i, 42);
105 checkedAfterInitialization()->
i = 47;
106 QCOMPARE(checkedAfterInitialization->
i, 47);
108 QVERIFY(checkedAfterInitialization.exists());
109 QVERIFY(!checkedAfterInitialization.isDestroyed());
112 void tst_QGlobalStatic::constVolatile()
142 void tst_QGlobalStatic::exception()
144 bool exceptionCaught =
false;
148 exceptionCaught =
true;
153 QVERIFY(!throwingGS.isDestroyed());
158 void tst_QGlobalStatic::catchExceptionAndRetry()
161 QSKIP(
"This test cannot be run more than once");
165 bool exceptionCaught =
false;
169 exceptionCaught =
true;
182 void tst_QGlobalStatic::threadStressTest()
184 if (QTestPrivate::isRunningArmOnX86())
185 QSKIP(
"Frequently hangs on QEMU, QTBUG-91423");
187 class ThreadStressTestThread:
public QThread
197 threadStressTestGS();
206 if (expectedConstructionCount <= 0)
207 QSKIP(
"This test cannot be run more than once");
209 #ifdef Q_OS_INTEGRITY
212 const int numThreads = 122;
214 const int numThreads = 200;
216 ThreadStressTestThread
threads[numThreads];
219 for (
int i = 0;
i < numThreads; ++
i) {
228 for (
int i = 0;
i < numThreads; ++
i)
236 void tst_QGlobalStatic::afterDestruction()
244 static struct RunAtExit {
246 int *ptr = checkedAfterDestruction();
248 qFatal(
"Global static is not null as was expected");
253 *checkedAfterDestruction = 42;
258 #include "tst_qglobalstatic.moc"
small capitals from c petite p scientific i
[1]
void storeRelaxed(T newValue) noexcept
T fetchAndAddRelaxed(T valueToAdd) noexcept
T loadRelaxed() const noexcept
The QObject class is the base class of all Qt objects.
The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks f...
The QReadWriteLock class provides read-write locking.
void lockForWrite() noexcept
#define Q_BASIC_ATOMIC_INITIALIZER(a)
#define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
#define QSKIP(statement,...)
#define QVERIFY(statement)
static QBasicAtomicInt destructedCount
static QBasicAtomicInt constructedCount
ThrowingType(QBasicAtomicInt &throwControl)
bool run(const QString &name, QString *errorMessage)
QBasicAtomicInt exceptionControlVar
QBasicAtomicInt threadStressTestControlVar
QTEST_APPLESS_MAIN(tst_QGlobalStatic)
QSet< QThread * > threads