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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1221 - (show annotations) (download) (as text)
Wed Jun 6 18:50:03 2007 UTC (16 years, 10 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 2561 byte(s)
* fixed several issues in fundamental "Thread" class: set scheduling
  policy and priority on thread level, set a minimum stack size for
  thread (TODO: a reasonable value yet to be tested), bugfix: non-RT
  threads simply inherited properties of starting thread instead of
  setting their own policy and priority
* updated and fixed test cases (haven't been touched in a while, but
  are now all running successfully through all cases)

1 #ifndef __LS_THREADTEST_H__
2 #define __LS_THREADTEST_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 Thread class we want to test
11 #include "../common/Thread.h"
12
13 // we need that to check if our thread is killable even if waiting for a condition
14 #include "../common/Condition.h"
15
16 class ThreadTest : public CppUnit::TestFixture {
17
18 CPPUNIT_TEST_SUITE(ThreadTest);
19 CPPUNIT_TEST(printTestSuiteName);
20 CPPUNIT_TEST(testThreadRunning);
21 CPPUNIT_TEST(testSignalStopThread);
22 CPPUNIT_TEST(testRelaunchThread);
23 CPPUNIT_TEST(testStopThread);
24 CPPUNIT_TEST(testThreadKillableWhenWaiting);
25 CPPUNIT_TEST_SUITE_END();
26
27 public:
28 // this is our test implementation of the abstract base class Thread which we will use to test class Thread
29 class DummyThread : public LinuxSampler::Thread {
30 public:
31 bool wasRunning; // this variable is false on startup and will be switched to true by the thread, so we can check if the thread actually runs
32 volatile int someVariable; // we constantly set this variable to -1 in the DummyThread Main() loop, so we can check in our main test thread if the DummyThread is still running by changing that value to something else than -1
33
34 DummyThread();
35 int Main();
36 };
37
38 private:
39 // this is only a helper thread to avoid that the entire test case run hangs when we try to stop the dummy thread
40 class HelperThread : public LinuxSampler::Thread {
41 private:
42 DummyThread* pDummyThread;
43 public:
44 bool returnedFromDummyStop;
45
46 HelperThread(DummyThread* pDummyThread);
47 int Main();
48 bool dummyThreadWasNotRunningAnymoreAfter_StopThread_call();
49 };
50
51 // this simulates a thread that is waiting for a condition (thus sleeping til then)
52 class WaitingThread : public LinuxSampler::Thread {
53 public:
54 WaitingThread();
55 int Main();
56 private:
57 LinuxSampler::Condition condition;
58 };
59 public:
60 void setUp() {
61 }
62
63 void tearDown() {
64 }
65
66 void printTestSuiteName();
67
68 void testThreadRunning();
69 void testSignalStopThread();
70 void testRelaunchThread();
71 void testStopThread();
72 void testThreadKillableWhenWaiting();
73 };
74
75 #endif // __LS_THREADTEST_H__

  ViewVC Help
Powered by ViewVC