summaryrefslogtreecommitdiffstats
path: root/tests/auto/qsystemreadwritelock/tst_qsystemreadwritelock.cpp
blob: 23221cf7797389b117d55024a70a5303b4cbe59f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** 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.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

//TESTED_COMPONENT=src/publishsubscribe

#include <QtTest/QtTest>
#include "qsystemreadwritelock_p.h"
#include <QThread>
#include <QDebug>

QTM_USE_NAMESPACE
bool volatile readThreadDone;
bool volatile writeThreadDone;
bool volatile readThreadStarted;
bool volatile writeThreadStarted;
bool volatile release;

const QString BeforeLockForRead("ReadThread: About to lock for reading");
const QString AfterLockForRead("ReadThread: After lock for reading");
const QString AfterUnlockForRead("ReadThread: After unlock(read)");

const QString BeforeLockForWrite("WriteThread: About to lock for writing");
const QString AfterLockForWrite("WriteThread: After lock for writing");
const QString AfterUnlockForWrite("WriteThread: After unlock(write)");

/*
    set readThreadStarted
    read-lock
    unlock
    set readThreadDone
*/
class ReadLockThread : public QThread
{
public:
    bool print;
    inline ReadLockThread(bool print=false)
        :print(print)
    {}
    void run()
    {
        QSystemReadWriteLock testRwLock("Viper");
        readThreadStarted = true;
        if (print)
            qDebug() << qPrintable(BeforeLockForRead);
        testRwLock.lockForRead();
        if (print)
            qDebug() << qPrintable(AfterLockForRead);
        testRwLock.unlock();
        if (print)
            qDebug() << qPrintable(AfterUnlockForRead);
        readThreadDone = true;
    }
};

/*
    set writeThreadStarted
    write-lock
    lock
    set writeThreadDone
*/
class WriteLockThread : public QThread
{
public:
    bool print;
    inline WriteLockThread(bool print = false)
        :print(print)
    {}
    void run()
    {
        QSystemReadWriteLock testRwLock("Viper");
        writeThreadStarted = true;
        if (print)
            qDebug() << qPrintable(BeforeLockForWrite);
        testRwLock.lockForWrite();
        if (print)
            qDebug() << qPrintable(AfterLockForWrite);
        testRwLock.unlock();
        if (print)
            qDebug() << qPrintable(AfterUnlockForWrite);
        writeThreadDone = true;
    }
};

/*
   read-lock
   wait for release==true
   unlock
*/
class ReadLockReleaseableThread : public QThread
{
public:
    bool print;
    inline ReadLockReleaseableThread(bool print = false)
        :print(print)
    {}
    void run()
    {
        QSystemReadWriteLock testRwLock("Viper");
    if (print)
            qDebug() << qPrintable(BeforeLockForRead);
        testRwLock.lockForRead();
        if (print)
            qDebug() << qPrintable(AfterLockForRead);
        while (release == false) {
            usleep(1);
        }
        testRwLock.unlock();
        if (print)
            qDebug() << qPrintable(AfterUnlockForRead);
    }
};

/*
    write-lock
    wait for release == true
    unlock
*/
class WriteLockReleaseableThread : public QThread
{
public:
    bool print;
    inline WriteLockReleaseableThread(bool print = false)
        :print(print)
    {}
    void run()
    {
        QSystemReadWriteLock testRwLock("Viper");
        writeThreadStarted = true;
        if (print)
            qDebug() << BeforeLockForWrite;
        testRwLock.lockForWrite();
        if (print)
            qDebug() << AfterLockForWrite;
        while(release == false) {
            usleep(1);
        }
        testRwLock.unlock();
        if (print)
            qDebug() << AfterUnlockForWrite;
        writeThreadDone = true;
    }
};

/*
    for(runTime msecs)
    read-lock
    msleep(holdTime msecs)
    release lock
    msleep(waitTime msecs)
*/
class ReadLockLoopThread : public QThread
{
public:
    int runTime;
    int holdTime;
    int waitTime;
    bool print;
    QTime t;
    inline ReadLockLoopThread(int runTime, int holdTime=0, int waitTime=0, bool print=false)
        : runTime(runTime)
         ,holdTime(holdTime)
         ,waitTime(waitTime)
         ,print(print)
    { }
    void run()
    {
        QSystemReadWriteLock testRwLock("Viper");
        t.start();
        while (t.elapsed()<runTime)  {
            testRwLock.lockForRead();
            //if (print) printf("reading\n");
            if (holdTime) msleep(holdTime);
            testRwLock.unlock();
            if (waitTime) msleep(waitTime);
        }
    }
};

/*
   for(runTime msecs)
   write-lock
   msleep(holdTime msecs)
   release lock
   msleep(waitTime msecs)
*/
class WriteLockLoopThread : public QThread
{
public:
    int runTime;
    int holdTime;
    int waitTime;
    bool print;
    QTime t;
    inline WriteLockLoopThread(int runTime, int holdTime=0, int waitTime=0, bool print=false)
        : runTime(runTime)
         ,holdTime(holdTime)
         ,waitTime(waitTime)
         ,print(print)
    { }
    void run()
    {
        QSystemReadWriteLock testRwLock("Viper");
        t.start();
        while (t.elapsed() < runTime)  {
            if (print) qDebug() << "About to lock for write";
            testRwLock.lockForWrite();
            if (print) qDebug() << "Locked for Write";
            if (holdTime) msleep(holdTime);
            testRwLock.unlock();
            if (print) qDebug() << "unlocked";
            if (waitTime) msleep(waitTime);
        }
    }
};

volatile int count=0;

/*
   for(runTime msecs)
   write-lock
   count to maxval
   set count to 0
   release lock
   msleep (waitTime)
*/
class WriteLockCountThread : public QThread
{
public:
    int runTime;
    int waitTime;
    int maxval;
    QTime t;
    inline WriteLockCountThread(int runTime, int waitTime, int maxval)
        : runTime(runTime)
         ,waitTime(waitTime)
         ,maxval(maxval)
    { }

    void run()
    {
        QSystemReadWriteLock testRwLock("Viper");
        t.start();
        while (t.elapsed() < runTime)  {
            testRwLock.lockForWrite();
            if(count)
                qFatal("Non-zero count at start of write! (%d)",count );
            for(int i = 0; i < maxval; ++i) {
                volatile int lc=count;
                ++lc;
                count=lc;
            }
            count=0;
            testRwLock.unlock();
            msleep(waitTime);
        }
    }
};

/*
   for(runTime msecs)
   read-lock
   verify count==0
   release lock
   msleep(waitTime)
*/
class ReadLockCountThread : public QThread
{
public:
    int runTime;
    int waitTime;
    QTime t;
    inline ReadLockCountThread(int runTime, int waitTime)
        : runTime(runTime)
         ,waitTime(waitTime)
    { }

    void run()
    {
        QSystemReadWriteLock testRwLock("Viper");
        t.start();
        while (t.elapsed() < runTime)  {
            testRwLock.lockForRead();
            if(count)
                qFatal("Non-zero count at Read! (%d)",count );
            testRwLock.unlock();
            msleep(waitTime);
        }
    }
};

class tst_QSystemReadWriteLock : public QObject {
    Q_OBJECT

private slots:
    void constructDestruct();
    void readLockUnlock();
    void writeLockUnlock();
    void readLockUnlockLoop();
    void writeLockUnlockLoop();
    void readLockLoop();
    void readWriteLockUnlockLoop();
    void readLockBlockRelease();
    void writeLockBlockRelease();
    void multipleReadersBlockRelease();
    void multipleReadersLoop();
    void multipleWritersLoop();
    void multipleReadersWritersLoop();
    void countingTest();
    void uncontendedLocks();
    void writerPrecedence();
    void errorCheck();
};

void tst_QSystemReadWriteLock::constructDestruct()
{
    {
        QSystemReadWriteLock rwlock("Viper");
        QCOMPARE(rwlock.key(), QLatin1String("Viper"));
    }
}

void tst_QSystemReadWriteLock::readLockUnlock()
{
    QSystemReadWriteLock rwlock("Viper");
    rwlock.lockForRead();
    rwlock.unlock();
}

void tst_QSystemReadWriteLock::writeLockUnlock()
{
    QSystemReadWriteLock rwlock("Viper");
    rwlock.lockForWrite();
    rwlock.unlock();
}

void tst_QSystemReadWriteLock::readLockUnlockLoop()
{
    QSystemReadWriteLock rwlock("Viper");
    int runs = 10000;
    for (int i=0; i < runs; ++i) {
        rwlock.lockForRead();
        rwlock.unlock();
    }
}

void tst_QSystemReadWriteLock::writeLockUnlockLoop()
{
    QSystemReadWriteLock rwlock("Viper");
    int runs = 100000;
    for (int i = 0; i < runs; ++i) {
        rwlock.lockForWrite();
        rwlock.unlock();
    }
}

void tst_QSystemReadWriteLock::readLockLoop()
{
    QSystemReadWriteLock rwlock("Viper");
    int runs = 10000;
    for (int i = 0; i < runs; ++i) {
        rwlock.lockForRead();
    }
    for (int i=0; i < runs; ++i) {
        rwlock.unlock();
    }
}

void tst_QSystemReadWriteLock::readWriteLockUnlockLoop()
{
    QSystemReadWriteLock rwlock("Viper");
    int runs = 10000;
    for (int i = 0; i < runs; ++i) {
        rwlock.lockForRead();
        rwlock.unlock();
        rwlock.lockForWrite();
        rwlock.unlock();
    }
}

/*
    A writer acquires a write-lock, a reader tries to lock.
    the writer releases the lock, the reader gets the lock
*/
void tst_QSystemReadWriteLock::readLockBlockRelease()
{
    bool print = false;
    QSystemReadWriteLock testLock("Viper", QSystemReadWriteLock::Create);
    if (print)
        qDebug() << "Main Thread: About to lock for writing";
    testLock.lockForWrite();
    if (print)
        qDebug() << "Main Thread: After lock for writing";
    readThreadStarted = false;
    readThreadDone = false;

    ReadLockThread rlt(print);
    rlt.start();
    QTest::qSleep(1000);
    QVERIFY(readThreadStarted);
    QVERIFY(!readThreadDone);

    testLock.unlock();
    if (print)
        qDebug() << "Main Thread:  After unlock(write)";
    rlt.wait();
    QVERIFY(readThreadDone);
}

/*
    writer1 acquires a write-lock, writer 2 blocks,
    writer1 releases the lock, writer 2 gets the lock
*/
void tst_QSystemReadWriteLock::writeLockBlockRelease()
{
    bool print = false;
    QSystemReadWriteLock testLock("Viper");
    if (print)
        qDebug() << "Main Thread:  About to lock for writing"; 
    testLock.lockForWrite();
    if (print)
        qDebug() << "Main Thread: After lock for writing";
    writeThreadStarted = false;
    writeThreadDone = false;

    WriteLockThread wlt(print);
    wlt.start();
    QTest::qSleep(1000);
    QVERIFY(writeThreadStarted);
    QVERIFY(!writeThreadDone);

    testLock.unlock();
    if (print)
        qDebug() << "MainThread: After unlock(write)";
    QVERIFY(wlt.wait(5000));
    QVERIFY(writeThreadDone);
}

/*
    Two readers aquire a read-lock, one writer attempts a write block,
    the readers release their locks, the writer gets the lock.
*/
void tst_QSystemReadWriteLock::multipleReadersBlockRelease()
{
    bool print = false;
    QSystemReadWriteLock testLock("Viper", QSystemReadWriteLock::Create);
    release = false;
    writeThreadStarted = false;
    writeThreadDone = false;

    ReadLockReleaseableThread rlt1(print);
    ReadLockReleaseableThread rlt2(print);
    rlt1.start();
    rlt2.start();
    QTest::qSleep(1000);
    WriteLockThread wlt(print);
    wlt.start();
    QTest::qSleep(1000);
    QVERIFY(writeThreadStarted);
    QVERIFY(!writeThreadDone);
    QVERIFY(wlt.isRunning());
    QVERIFY(rlt1.isRunning());
    QVERIFY(rlt2.isRunning());
    release = true;
    QVERIFY(wlt.wait());
    QVERIFY(rlt1.wait(2000));
    QVERIFY(rlt2.wait(2000));
    QVERIFY(writeThreadDone);
}

/*
    Multiple readers locks and unlocks a lock.
*/
void tst_QSystemReadWriteLock::multipleReadersLoop()
{
    QSystemReadWriteLock testLock("Viper", QSystemReadWriteLock::Create);
    int time=500;
    int hold=250;
    int wait=0;
#if defined (Q_OS_HPUX)
    const int numthreads=50;
#else
    const int numthreads=75;
#endif
    ReadLockLoopThread *threads[numthreads];
    int i;
    for (i=0; i < numthreads; ++i)
        threads[i] = new ReadLockLoopThread(time, hold, wait,false);
    for (i=0; i<numthreads; ++i)
        threads[i]->start();
    for (i=0; i<numthreads; ++i)
        QVERIFY(threads[i]->wait());
    for (i=0; i<numthreads; ++i)
        delete threads[i];
}

/*
   Multiple writers locks and unlocks a lock.
*/
void tst_QSystemReadWriteLock::multipleWritersLoop()
{
    QSystemReadWriteLock testLock("Viper", QSystemReadWriteLock::Create);
    int time=500;
    int wait=0;
    int hold=0;
    const int numthreads=2;
    WriteLockLoopThread *threads[numthreads];
    int i;
    for (i = 0; i < numthreads; ++i)
        threads[i] = new WriteLockLoopThread(time, hold, wait,false);
    for (i = 0; i < numthreads; ++i)
        threads[i]->start();
    for (i = 0; i < numthreads; ++i)
        QVERIFY(threads[i]->wait(5000));
    for (i = 0; i < numthreads; ++i)
        delete threads[i];
}


typedef ReadLockLoopThread* ReadLockLoopThreadPtr;
typedef WriteLockLoopThread* WriteLockLoopThreadPtr;

/*
    Multiple readers and writers locks and unlocks a lock.
*/
void tst_QSystemReadWriteLock::multipleReadersWritersLoop()
{
    QSystemReadWriteLock testLock("Viper", QSystemReadWriteLock::Create);
    int time=10000;
    int numReaders=20;
    int readerWait=0;
    int readerHold=1;

    int numWriters=3;
    int writerWait=500;
    int writerHold=50;

    ReadLockLoopThreadPtr *readers = new ReadLockLoopThreadPtr[numReaders];
    WriteLockLoopThreadPtr *writers = new WriteLockLoopThreadPtr[numWriters];

    int i;

    for (i = 0; i < numReaders; ++i)
        readers[i] = new ReadLockLoopThread(time, readerHold, readerWait, false);
    for (i = 0; i < numWriters; ++i)
        writers[i] = new WriteLockLoopThread(time, writerHold, writerWait, false);

    for (i = 0; i < numReaders; ++i)
        readers[i]->start(QThread::NormalPriority);
    for (i = 0; i < numWriters; ++i)
        writers[i]->start(QThread::IdlePriority);

    for (i = 0; i < numReaders; ++i)
        QVERIFY(readers[i]->wait(time*2));
    for (i = 0; i < numWriters; ++i)
        QVERIFY(writers[i]->wait(time*2));

    for (i = 0; i < numReaders; ++i)
        delete readers[i];
    for (i = 0; i < numWriters; ++i)
        delete writers[i];
    delete[] readers;
    delete[] writers;
}


typedef ReadLockCountThread* ReadLockCountThreadPtr;
typedef WriteLockCountThread* WriteLockCountThreadPtr;
/*
   Writers increment a variable from 0 to maxval, then reset it to 0.
   Readers verify that the variable remains at 0.
*/
void tst_QSystemReadWriteLock::countingTest()
{
    QSystemReadWriteLock testLock("Viper", QSystemReadWriteLock::Create);
    //int time=INT_MAX;
    int time=10000;
    int numReaders=20;
    int readerWait=1;

    int numWriters=3;
    int writerWait=150;
    int maxval=10000;

    ReadLockCountThreadPtr  *readers = new ReadLockCountThreadPtr[numReaders];
    WriteLockCountThreadPtr *writers= new WriteLockCountThreadPtr[numWriters];
    int i;

    for (i = 0; i < numReaders; ++i)
        readers[i] = new ReadLockCountThread(time,  readerWait);
    for (i = 0; i < numWriters; ++i)
        writers[i] = new WriteLockCountThread(time,  writerWait, maxval);

    for (i = 0; i < numReaders; ++i)
        readers[i]->start(QThread::NormalPriority);
    for (i = 0; i < numWriters; ++i)
        writers[i]->start(QThread::LowestPriority);

    for (i = 0; i < numReaders; ++i)
        QVERIFY(readers[i]->wait(2 * time));
    for (i = 0; i < numWriters; ++i)
        QVERIFY(writers[i]->wait(2 * time));
    for (i = 0; i < numReaders; ++i)
        delete readers[i];
    for (i = 0; i < numWriters; ++i)
        delete writers[i];
    delete [] readers;
    delete [] writers;
}

/*
    Performance test to see how many uncontended
    locks and unlocks can be performed in a given
    timeframe.
*/
void tst_QSystemReadWriteLock::uncontendedLocks()
{
    uint read=0;
    uint write=0;
    uint count=0;
    int millisecs=1000;
    {
        QTime t;
        t.start();
        while(t.elapsed() <millisecs)
        {
            ++count;
        }
    }
    {
        QSystemReadWriteLock rwLock("Viper", QSystemReadWriteLock::Create);
        QTime t;
        t.start();
        while(t.elapsed() <millisecs)
        {
            rwLock.lockForRead();
            rwLock.unlock();
            ++read;
        }
    }
    {
        QSystemReadWriteLock rwLock("Viper", QSystemReadWriteLock::Create);
        QTime t;
        t.start();
        while(t.elapsed() <millisecs)
        {
            rwLock.lockForWrite();
            rwLock.unlock();
            ++write;
        }
    }

    qDebug("during %d millisecs:", millisecs);
    qDebug("counted to %u", count);
    qDebug("%u uncontended read locks/unlocks", read);
    qDebug("%u uncontended write locks/unlocks", write);
}

/*
   Writer1 acquires a write-lock
   Readers try to acquire read-locks but are blocked
   Writer2 tries to acquire a write-lock, but is blocked
   Writer1 releases the lock, writer2 gets the lock, readers still blocked
   Writer2 releases the lock, readers are unblocked and get their read-locks
*/
void tst_QSystemReadWriteLock::writerPrecedence()
{
    bool print = false;
    writeThreadStarted = false;
    writeThreadDone = false;
    release = false;

    QSystemReadWriteLock testRwLock("Viper", QSystemReadWriteLock::Create);
    if (print)
        qDebug() << "Main Thread: About to lock for writing";
    testRwLock.lockForWrite();
    if (print)
        qDebug() << "Main Thread: After lock for writing";

    const int numReaders = 5;
    ReadLockThread *readers[numReaders];
    for (int i = 0; i < numReaders; ++i) {
        readers[i] = new ReadLockThread(print);
        readers[i]->start();
    }

    //check that the readers are still running
    //and so are likely to be correctly blocking
    QTest::qSleep(1000);
    for (int i = 0; i < numReaders; ++i) {
        QVERIFY(!readers[i]->isFinished());
    }

    // Start the writer2 thread and ensure it blocks
    WriteLockReleaseableThread *writer = new WriteLockReleaseableThread(print);
    writer->start();
    QTest::qSleep(1000);
    QVERIFY(writeThreadStarted == true);
    QVERIFY(writeThreadDone == false);
    QVERIFY(!writer->isFinished());

    // Unlock writer1 and verify the readers are still blocked
    testRwLock.unlock();
    if (print)
        qDebug() << "Main Thread: After unlock(write)";
    QTest::qSleep(1000);
    for (int i = 0; i < numReaders; ++i) {
        QVERIFY(!readers[i]->isFinished());
    }

    //Release writer2 and verify that it and the readers
    //finish executing.
    QVERIFY(!writer->isFinished());
    release = true;
    QTest::qSleep(1000);
    QVERIFY(writeThreadDone == true);
    QVERIFY(writer->isFinished());
    for (int i = 0; i < numReaders; ++i ) {
        QVERIFY(readers[i]->isFinished());
        delete readers[i];
    }
    delete writer;
}

/*
    Completeness error test - need to replace with proper error-inducing code
*/
void tst_QSystemReadWriteLock::errorCheck()
{
    QSystemReadWriteLock testLock("Viper");
    QVERIFY(testLock.error() == 0);
    QCOMPARE(testLock.errorString(), QString(""));
}

QTEST_MAIN(tst_QSystemReadWriteLock)
#include "tst_qsystemreadwritelock.moc"