/[svn]/linuxsampler/trunk/src/testcases/MutexTest.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/testcases/MutexTest.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3548 - (show annotations) (download) (as text)
Wed Jul 31 09:35:10 2019 UTC (15 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 1918 byte(s)
* Fixed compiler error in Pool.h.
* Fixed compiler errors in test cases.
* Updated README for how to compile & run test cases.
* Updated test case
  MutexTest::testDoubleLockStillBlocksConcurrentThread() to latest
  expected behaviour of the Mutex class implementation (recursive
  mutex type).
* Bumped version (2.1.1.svn1).

1 #ifndef __LS_MUTEXTEST_H__
2 #define __LS_MUTEXTEST_H__
3
4 #include <cppunit/TestFixture.h>
5 #include <cppunit/extensions/HelperMacros.h>
6
7 // needed for sleep() and usleep() calls
8 #include <unistd.h>
9
10 // the Mutex class we want to test
11 #include "../common/Mutex.h"
12
13 // we need an additional thread to test the Mutex class
14 #include "../common/Thread.h"
15
16 using namespace LinuxSampler;
17
18 class MutexTest : public CppUnit::TestFixture {
19
20 CPPUNIT_TEST_SUITE(MutexTest);
21 CPPUNIT_TEST(printTestSuiteName);
22 CPPUNIT_TEST(testLockAndUnlockBySingleThread);
23 CPPUNIT_TEST(testLock);
24 CPPUNIT_TEST(testUnlock);
25 CPPUNIT_TEST(testDoubleLock);
26 CPPUNIT_TEST(testDoubleLockStillBlocksConcurrentThread);
27 CPPUNIT_TEST_SUITE_END();
28
29 private:
30 // dummy thread to simulate usage of a shared resource
31 class ConcurrentThread : public Thread {
32 public:
33 int resource;
34 Mutex mutex;
35
36 ConcurrentThread();
37 int Main();
38 using Thread::SignalStartThread; // make method public
39 };
40
41 // dummy thread we use to check if the Mutex falsely blcoks if we do a double lock and to avoid that our unit test main thread gets blocked
42 class DummyThread : public Thread {
43 public:
44 int resource;
45
46 DummyThread();
47 int Main();
48 using Thread::SignalStartThread; // make method public
49 private:
50 Mutex mutex;
51 };
52
53 bool doubleLockSucceeded; // true if testDoubleLock() was successful
54 public:
55 void setUp();
56 void tearDown();
57
58 void printTestSuiteName();
59
60 void testLockAndUnlockBySingleThread();
61 void testLock();
62 void testUnlock();
63 void testDoubleLock();
64 void testDoubleLockStillBlocksConcurrentThread();
65 };
66
67 #endif // __LS_MUTEXTEST_H__

  ViewVC Help
Powered by ViewVC