summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/thread
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2016-03-10 16:39:05 +0100
committerLiang Qi <liang.qi@theqtcompany.com>2016-03-11 20:08:50 +0100
commit50d0f57b77b8088875d7185c5906b5f57985d5fb (patch)
tree16d21bb5f558461511258f493159658ccecc696a /tests/auto/corelib/thread
parent713282dfe41fbad1c1c940cec54227cd7c267831 (diff)
parent45dc347a95fd674cefcf5d1ac63b01557fcb2fef (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
This change partially reverts 1bfc7f68 about QT_HAS_BUILTIN define and undef in src/corelib/tools/qsimd_p.h. This change is also squashed with "Fall back to c++11 standard compiler flag for host builds" which is done by Peter Seiderer. Conflicts: mkspecs/features/default_post.prf src/3rdparty/sqlite/0001-Fixing-the-SQLite3-build-for-WEC2013-again.patch src/3rdparty/sqlite/sqlite3.c src/corelib/tools/qsimd_p.h src/gui/kernel/qevent.cpp src/gui/kernel/qwindowsysteminterface.cpp src/gui/kernel/qwindowsysteminterface_p.h src/plugins/bearer/blackberry/blackberry.pro src/plugins/platforms/cocoa/qcocoasystemsettings.mm src/plugins/platformthemes/gtk2/gtk2.pro src/plugins/styles/bb10style/bb10style.pro src/sql/drivers/sqlite2/qsql_sqlite2.cpp tools/configure/configureapp.cpp Task-number: QTBUG-51644 Done-with: Peter Seiderer <ps.report@gmx.net> Change-Id: I6100d6ace31b2e8d41a95f0b5d5ebf8f1fd88b44
Diffstat (limited to 'tests/auto/corelib/thread')
-rw-r--r--tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp88
1 files changed, 80 insertions, 8 deletions
diff --git a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp
index 3bed64a76a..fe465df395 100644
--- a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp
+++ b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp
@@ -357,28 +357,46 @@ void tst_QAtomicIntegerXX::loadAcquireStoreRelease()
void tst_QAtomicIntegerXX::refDeref()
{
QFETCH(LargeInt, value);
- T nextValue = T(value + 1);
- T prevValue = T(value - 1);
+ const bool needToPreventOverflow = TypeIsSigned && value == std::numeric_limits<T>::max();
+ const bool needToPreventUnderflow = TypeIsSigned && value == std::numeric_limits<T>::min();
+ T nextValue = T(value);
+ if (!needToPreventOverflow)
+ ++nextValue;
+ T prevValue = T(value);
+ if (!needToPreventUnderflow)
+ --prevValue;
QAtomicInteger<T> atomic(value);
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.ref(), (nextValue != 0));
QCOMPARE(atomic.load(), nextValue);
QCOMPARE(atomic.deref(), (value != 0));
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.deref(), (prevValue != 0));
QCOMPARE(atomic.load(), prevValue);
QCOMPARE(atomic.ref(), (value != 0));
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventOverflow) {
QCOMPARE(++atomic, nextValue);
QCOMPARE(--atomic, T(value));
+ }
+ if (!needToPreventUnderflow) {
QCOMPARE(--atomic, prevValue);
QCOMPARE(++atomic, T(value));
+ }
+ if (!needToPreventOverflow) {
QCOMPARE(atomic++, T(value));
QCOMPARE(atomic--, nextValue);
+ }
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic--, T(value));
QCOMPARE(atomic++, prevValue);
+ }
QCOMPARE(atomic.load(), T(value));
}
@@ -481,53 +499,80 @@ void tst_QAtomicIntegerXX::fetchAndAdd()
QFETCH(LargeInt, value);
QAtomicInteger<T> atomic(value);
- // note: this test has undefined behavior for signed max and min
T parcel1 = 42;
T parcel2 = T(0-parcel1);
- T newValue1 = T(value) + parcel1;
- T newValue2 = T(value) + parcel2;
+ const bool needToPreventOverflow = TypeIsSigned && value > std::numeric_limits<T>::max() + parcel2;
+ const bool needToPreventUnderflow = TypeIsSigned && value < std::numeric_limits<T>::min() + parcel1;
+
+ T newValue1 = T(value);
+ if (!needToPreventOverflow)
+ newValue1 += parcel1;
+ T newValue2 = T(value);
+ if (!needToPreventUnderflow)
+ newValue2 += parcel2;
+
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.fetchAndAddRelaxed(parcel1), T(value));
QCOMPARE(atomic.load(), newValue1);
QCOMPARE(atomic.fetchAndAddRelaxed(parcel2), newValue1);
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.fetchAndAddRelaxed(parcel2), T(value));
QCOMPARE(atomic.load(), newValue2);
QCOMPARE(atomic.fetchAndAddRelaxed(parcel1), newValue2);
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.fetchAndAddAcquire(parcel1), T(value));
QCOMPARE(atomic.load(), newValue1);
QCOMPARE(atomic.fetchAndAddAcquire(parcel2), newValue1);
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.fetchAndAddAcquire(parcel2), T(value));
QCOMPARE(atomic.load(), newValue2);
QCOMPARE(atomic.fetchAndAddAcquire(parcel1), newValue2);
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.fetchAndAddRelease(parcel1), T(value));
QCOMPARE(atomic.loadAcquire(), newValue1);
QCOMPARE(atomic.fetchAndAddRelease(parcel2), newValue1);
+ }
QCOMPARE(atomic.loadAcquire(), T(value));
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.fetchAndAddRelease(parcel2), T(value));
QCOMPARE(atomic.loadAcquire(), newValue2);
QCOMPARE(atomic.fetchAndAddRelease(parcel1), newValue2);
+ }
QCOMPARE(atomic.loadAcquire(), T(value));
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.fetchAndAddOrdered(parcel1), T(value));
QCOMPARE(atomic.loadAcquire(), newValue1);
QCOMPARE(atomic.fetchAndAddOrdered(parcel2), newValue1);
+ }
QCOMPARE(atomic.loadAcquire(), T(value));
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.fetchAndAddOrdered(parcel2), T(value));
QCOMPARE(atomic.loadAcquire(), newValue2);
QCOMPARE(atomic.fetchAndAddOrdered(parcel1), newValue2);
+ }
QCOMPARE(atomic.loadAcquire(), T(value));
// operator+=
+ if (!needToPreventOverflow) {
QCOMPARE(atomic += parcel1, newValue1);
QCOMPARE(atomic += parcel2, T(value));
+ }
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic += parcel2, newValue2);
QCOMPARE(atomic += parcel1, T(value));
+ }
}
void tst_QAtomicIntegerXX::fetchAndSub()
@@ -535,53 +580,80 @@ void tst_QAtomicIntegerXX::fetchAndSub()
QFETCH(LargeInt, value);
QAtomicInteger<T> atomic(value);
- // note: this test has undefined behavior for signed max and min
T parcel1 = 42;
T parcel2 = T(0-parcel1);
- T newValue1 = T(value) - parcel1;
- T newValue2 = T(value) - parcel2;
+ const bool needToPreventOverflow = TypeIsSigned && value > std::numeric_limits<T>::max() - parcel1;
+ const bool needToPreventUnderflow = TypeIsSigned && value < std::numeric_limits<T>::min() - parcel2;
+
+ T newValue1 = T(value);
+ if (!needToPreventUnderflow)
+ newValue1 -= parcel1;
+ T newValue2 = T(value);
+ if (!needToPreventOverflow)
+ newValue2 -= parcel2;
+
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.fetchAndSubRelaxed(parcel1), T(value));
QCOMPARE(atomic.load(), newValue1);
QCOMPARE(atomic.fetchAndSubRelaxed(parcel2), newValue1);
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.fetchAndSubRelaxed(parcel2), T(value));
QCOMPARE(atomic.load(), newValue2);
QCOMPARE(atomic.fetchAndSubRelaxed(parcel1), newValue2);
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.fetchAndSubAcquire(parcel1), T(value));
QCOMPARE(atomic.load(), newValue1);
QCOMPARE(atomic.fetchAndSubAcquire(parcel2), newValue1);
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.fetchAndSubAcquire(parcel2), T(value));
QCOMPARE(atomic.load(), newValue2);
QCOMPARE(atomic.fetchAndSubAcquire(parcel1), newValue2);
+ }
QCOMPARE(atomic.load(), T(value));
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.fetchAndSubRelease(parcel1), T(value));
QCOMPARE(atomic.loadAcquire(), newValue1);
QCOMPARE(atomic.fetchAndSubRelease(parcel2), newValue1);
+ }
QCOMPARE(atomic.loadAcquire(), T(value));
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.fetchAndSubRelease(parcel2), T(value));
QCOMPARE(atomic.loadAcquire(), newValue2);
QCOMPARE(atomic.fetchAndSubRelease(parcel1), newValue2);
+ }
QCOMPARE(atomic.loadAcquire(), T(value));
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic.fetchAndSubOrdered(parcel1), T(value));
QCOMPARE(atomic.loadAcquire(), newValue1);
QCOMPARE(atomic.fetchAndSubOrdered(parcel2), newValue1);
+ }
QCOMPARE(atomic.loadAcquire(), T(value));
+ if (!needToPreventOverflow) {
QCOMPARE(atomic.fetchAndSubOrdered(parcel2), T(value));
QCOMPARE(atomic.loadAcquire(), newValue2);
QCOMPARE(atomic.fetchAndSubOrdered(parcel1), newValue2);
+ }
QCOMPARE(atomic.loadAcquire(), T(value));
// operator-=
+ if (!needToPreventUnderflow) {
QCOMPARE(atomic -= parcel1, newValue1);
QCOMPARE(atomic -= parcel2, T(value));
+ }
+ if (!needToPreventOverflow) {
QCOMPARE(atomic -= parcel2, newValue2);
QCOMPARE(atomic -= parcel1, T(value));
+ }
}
void tst_QAtomicIntegerXX::addSub()