summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks
diff options
context:
space:
mode:
authormread <qt-info@nokia.com>2011-02-08 14:05:37 (GMT)
committermread <qt-info@nokia.com>2011-03-09 12:44:25 (GMT)
commitf351340d328a896829779794e8810f0d913161fb (patch)
treeef0ec70eca99d0979f5048c0e6c2784223cd38f3 /tests/benchmarks
parent44298c848ac254fe1942eb32eed7651dec5bf0e3 (diff)
downloadQt-f351340d328a896829779794e8810f0d913161fb.zip
Qt-f351340d328a896829779794e8810f0d913161fb.tar.gz
Qt-f351340d328a896829779794e8810f0d913161fb.tar.bz2
Starting a benchmark test for QWaitCondition
This new test is added in anticipation of a native implementation of QWaitCondition for Symbian. Task-number: QTBUG-13990 Reviewed-by: Shane Kearns
Diffstat (limited to 'tests/benchmarks')
-rw-r--r--tests/benchmarks/corelib/thread/qwaitcondition/qwaitcondition.pro5
-rw-r--r--tests/benchmarks/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp197
2 files changed, 202 insertions, 0 deletions
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..ae5b48e
--- /dev/null
+++ b/tests/benchmarks/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp
@@ -0,0 +1,197 @@
+/****************************************************************************
+**
+** 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;
+};
+
+QWaitCondition tst_QWaitCondition::local;
+QWaitCondition tst_QWaitCondition::remote;
+
+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_wakeOne)
+ tst_QWaitCondition::local.wakeOne();
+ else
+ tst_QWaitCondition::local.wakeAll();
+ if (m_useMutex) {
+ mtx.lock();
+ tst_QWaitCondition::remote.wait(&mtx, m_timeout);
+ mtx.unlock();
+ } else {
+ rwl.lockForWrite();
+ tst_QWaitCondition::remote.wait(&rwl, m_timeout);
+ rwl.unlock();
+ }
+ 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);
+
+ OscillateThread thrd(useMutex, timeout, wakeOne);
+ thrd.start();
+
+ QBENCHMARK {
+ if (useMutex)
+ mtx.lock();
+ else
+ rwl.lockForWrite();
+ if (wakeOne)
+ remote.wakeOne();
+ else
+ remote.wakeAll();
+ if (useMutex) {
+ local.wait(&mtx, timeout);
+ mtx.unlock();
+ } else {
+ 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);
+
+ OscillateThread thrd(useMutex, timeout, wakeOne);
+ thrd.start();
+ local.wait(&mtx, 1000ul);
+ mtx.unlock();
+
+ QBENCHMARK {
+ if (wakeOne)
+ remote.wakeOne();
+ else
+ remote.wakeAll();
+ }
+
+ thrd.m_done = true;
+ remote.wakeAll();
+ thrd.wait();
+
+ QCOMPARE(0, 0);
+}
+
+QTEST_MAIN(tst_QWaitCondition)
+#include "tst_qwaitcondition.moc"