summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks')
-rw-r--r--tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp21
-rw-r--r--tests/benchmarks/corelib/thread/qwaitcondition/qwaitcondition.pro5
-rw-r--r--tests/benchmarks/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp210
3 files changed, 235 insertions, 1 deletions
diff --git a/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp b/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp
index aa4c15a..8b38661 100644
--- a/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp
+++ b/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp
@@ -44,7 +44,26 @@
#include <math.h>
-#ifdef Q_OS_UNIX
+#ifdef Q_OS_SYMBIAN
+# include <e32std.h>
+typedef RMutex NativeMutexType;
+void NativeMutexInitialize(NativeMutexType *mutex)
+{
+ mutex->CreateLocal();
+}
+void NativeMutexDestroy(NativeMutexType *mutex)
+{
+ mutex->Close();
+}
+void NativeMutexLock(NativeMutexType *mutex)
+{
+ mutex->Wait();
+}
+void NativeMutexUnlock(NativeMutexType *mutex)
+{
+ mutex->Signal();
+}
+#elif defined(Q_OS_UNIX)
# include <pthread.h>
# include <errno.h>
typedef pthread_mutex_t NativeMutexType;
diff --git a/tests/benchmarks/corelib/thread/qwaitcondition/qwaitcondition.pro b/tests/benchmarks/corelib/thread/qwaitcondition/qwaitcondition.pro
new file mode 100644
index 0000000..bc7bd58
--- /dev/null
+++ b/tests/benchmarks/corelib/thread/qwaitcondition/qwaitcondition.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_bench_qwaitcondition
+QT -= gui
+SOURCES += tst_qwaitcondition.cpp
diff --git a/tests/benchmarks/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp b/tests/benchmarks/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp
new file mode 100644
index 0000000..1bfc637
--- /dev/null
+++ b/tests/benchmarks/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp
@@ -0,0 +1,210 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QtCore>
+#include <QtTest/QtTest>
+
+#include <math.h>
+
+
+class tst_QWaitCondition : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QWaitCondition()
+ {
+ }
+
+private slots:
+ void oscillate_data();
+ void oscillate();
+
+ void thrash_data();
+ void thrash();
+
+public:
+ static QWaitCondition local, remote;
+ enum Turn {LocalTurn, RemoteTurn};
+ static Turn turn;
+};
+
+QWaitCondition tst_QWaitCondition::local;
+QWaitCondition tst_QWaitCondition::remote;
+tst_QWaitCondition::Turn tst_QWaitCondition::turn = tst_QWaitCondition::LocalTurn;
+
+class OscillateThread : public QThread
+{
+public:
+ bool m_done;
+ bool m_useMutex;
+ unsigned long m_timeout;
+ bool m_wakeOne;
+ int count;
+
+ OscillateThread(bool useMutex, unsigned long timeout, bool wakeOne)
+ : m_done(false), m_useMutex(useMutex), m_timeout(timeout), m_wakeOne(wakeOne)
+ {}
+ void run()
+ {
+ QMutex mtx;
+ QReadWriteLock rwl;
+ count = 0;
+
+ forever {
+ if (m_done)
+ break;
+ if (m_useMutex) {
+ mtx.lock();
+ while (tst_QWaitCondition::turn == tst_QWaitCondition::LocalTurn)
+ tst_QWaitCondition::remote.wait(&mtx, m_timeout);
+ mtx.unlock();
+ } else {
+ rwl.lockForWrite();
+ while (tst_QWaitCondition::turn == tst_QWaitCondition::LocalTurn)
+ tst_QWaitCondition::remote.wait(&rwl, m_timeout);
+ rwl.unlock();
+ }
+ tst_QWaitCondition::turn = tst_QWaitCondition::LocalTurn;
+ if (m_wakeOne)
+ tst_QWaitCondition::local.wakeOne();
+ else
+ tst_QWaitCondition::local.wakeAll();
+ count++;
+ }
+ }
+};
+
+void tst_QWaitCondition::oscillate_data()
+{
+ QTest::addColumn<bool>("useMutex");
+ QTest::addColumn<unsigned long>("timeout");
+ QTest::addColumn<bool>("wakeOne");
+
+ QTest::newRow("mutex, timeout, one") << true << 1000ul << true;
+ QTest::newRow("readWriteLock, timeout, one") << false << 1000ul << true;
+ QTest::newRow("mutex, timeout, all") << true << 1000ul << false;
+ QTest::newRow("readWriteLock, timeout, all") << false << 1000ul << false;
+ QTest::newRow("mutex, forever, one") << true << ULONG_MAX << true;
+ QTest::newRow("readWriteLock, forever, one") << false << ULONG_MAX << true;
+ QTest::newRow("mutex, forever, all") << true << ULONG_MAX << false;
+ QTest::newRow("readWriteLock, forever, all") << false << ULONG_MAX << false;
+}
+
+void tst_QWaitCondition::oscillate()
+{
+ QMutex mtx;
+ QReadWriteLock rwl;
+
+ QFETCH(bool, useMutex);
+ QFETCH(unsigned long, timeout);
+ QFETCH(bool, wakeOne);
+
+ turn = LocalTurn;
+ OscillateThread thrd(useMutex, timeout, wakeOne);
+ thrd.start();
+
+ QBENCHMARK {
+ if (useMutex)
+ mtx.lock();
+ else
+ rwl.lockForWrite();
+ turn = RemoteTurn;
+ if (wakeOne)
+ remote.wakeOne();
+ else
+ remote.wakeAll();
+ if (useMutex) {
+ while (turn == RemoteTurn)
+ local.wait(&mtx, timeout);
+ mtx.unlock();
+ } else {
+ while (turn == RemoteTurn)
+ local.wait(&rwl, timeout);
+ rwl.unlock();
+ }
+ }
+
+ thrd.m_done = true;
+ remote.wakeAll();
+ thrd.wait();
+
+ QCOMPARE(0, 0);
+}
+
+void tst_QWaitCondition::thrash_data()
+{
+ oscillate_data();
+}
+
+void tst_QWaitCondition::thrash()
+{
+ QMutex mtx;
+ mtx.lock();
+
+ QFETCH(bool, useMutex);
+ QFETCH(unsigned long, timeout);
+ QFETCH(bool, wakeOne);
+
+ turn = LocalTurn;
+ OscillateThread thrd(useMutex, timeout, wakeOne);
+ thrd.start();
+ local.wait(&mtx, 1000ul);
+ mtx.unlock();
+
+ QBENCHMARK {
+ turn = RemoteTurn;
+ if (wakeOne)
+ remote.wakeOne();
+ else
+ remote.wakeAll();
+ }
+
+ thrd.m_done = true;
+ turn = RemoteTurn;
+ remote.wakeAll();
+ thrd.wait();
+
+ QCOMPARE(0, 0);
+}
+
+QTEST_MAIN(tst_QWaitCondition)
+#include "tst_qwaitcondition.moc"