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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3548 - (hide annotations) (download) (as text)
Wed Jul 31 09:35:10 2019 UTC (4 years, 9 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 schoenebeck 57 #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 schoenebeck 1221 using namespace LinuxSampler;
17    
18 schoenebeck 57 class MutexTest : public CppUnit::TestFixture {
19    
20     CPPUNIT_TEST_SUITE(MutexTest);
21 schoenebeck 211 CPPUNIT_TEST(printTestSuiteName);
22 schoenebeck 57 CPPUNIT_TEST(testLockAndUnlockBySingleThread);
23     CPPUNIT_TEST(testLock);
24     CPPUNIT_TEST(testUnlock);
25     CPPUNIT_TEST(testDoubleLock);
26 schoenebeck 63 CPPUNIT_TEST(testDoubleLockStillBlocksConcurrentThread);
27 schoenebeck 57 CPPUNIT_TEST_SUITE_END();
28    
29     private:
30 schoenebeck 63 // dummy thread to simulate usage of a shared resource
31 schoenebeck 57 class ConcurrentThread : public Thread {
32     public:
33     int resource;
34     Mutex mutex;
35    
36     ConcurrentThread();
37     int Main();
38 schoenebeck 3548 using Thread::SignalStartThread; // make method public
39 schoenebeck 57 };
40 schoenebeck 63
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 schoenebeck 3548 using Thread::SignalStartThread; // make method public
49 schoenebeck 63 private:
50     Mutex mutex;
51     };
52    
53     bool doubleLockSucceeded; // true if testDoubleLock() was successful
54 schoenebeck 57 public:
55     void setUp();
56     void tearDown();
57    
58 schoenebeck 211 void printTestSuiteName();
59    
60 schoenebeck 57 void testLockAndUnlockBySingleThread();
61     void testLock();
62     void testUnlock();
63     void testDoubleLock();
64 schoenebeck 63 void testDoubleLockStillBlocksConcurrentThread();
65 schoenebeck 57 };
66    
67     #endif // __LS_MUTEXTEST_H__

  ViewVC Help
Powered by ViewVC