+ Started migrating Support Kit to new testing framework

+ Migrated BLocker tests.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@301 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2002-07-18 05:32:00 +00:00
parent 24b5aaa2fe
commit 9285de5124
26 changed files with 536 additions and 379 deletions
+15 -3
View File
@@ -223,7 +223,7 @@ NOTFILE r5tests ;
rule CommonTestLib rule CommonTestLib
{ {
# CommonUnitTest <target> : <sources> : <obos libraries> # CommonUnitTest <target> : <sources> : <obos libraries>
# : <r5 libraries> : <public headers>; # : <r5 libraries> : <test libraries> : <public headers>;
# Builds a unit test for both OBOS and R5 modules. # Builds a unit test for both OBOS and R5 modules.
# <target> The name of the target. # <target> The name of the target.
# <sources> The list of sources. # <sources> The list of sources.
@@ -231,13 +231,16 @@ rule CommonTestLib
# to LinkSharedOSLibs). # to LinkSharedOSLibs).
# <r5 libraries> A list of link libraries for the R5 tests (as passed # <r5 libraries> A list of link libraries for the R5 tests (as passed
# to LinkSharedOSLibs). # to LinkSharedOSLibs).
# <test libraries> A list of link libraries for both OBOS tests and R5 tests
# that have a common name (i.e. specify libx.so and the OBOS tests will link
# to libx.so and the R5 tests will link to libx_r5.so).
# <public headers> A list of public header dirs (as passed to # <public headers> A list of public header dirs (as passed to
# UsePublicHeaders). # UsePublicHeaders).
local testlibdir = [ FDirName $(OBOS_TEST_DIR) lib ] ; #/boot/home/config/lib/obos_tests ; local testlibdir = [ FDirName $(OBOS_TEST_DIR) lib ] ; #/boot/home/config/lib/obos_tests ;
TestLib $(1) : $(2) : $(testlibdir) : $(3) : $(5) ; TestLib $(1) : $(2) : $(testlibdir) : $(3) $(5) : $(6) ;
R5TestLib $(1) : $(2) : $(testlibdir) : $(4) ; R5TestLib $(1) : $(2) : $(testlibdir) : $(4) [ R5SharedLibraryNames $(5) ] ;
} }
rule TestLib rule TestLib
@@ -448,6 +451,15 @@ rule R5ObjectNames
return [ FGristFiles $(objects:S=$(SUFOBJ)) ] ; return [ FGristFiles $(objects:S=$(SUFOBJ)) ] ;
} }
rule R5SharedLibraryNames
{
# R5SharedLibraryNames <sources> ;
# Returns a list of shared library names given a list of file names. NO
# GRISTING IS PERFORMED :-) However, each library names gets "_r5" inserted
# before the shared lib suffix.
return $(1:S=)_r5.so ;
}
rule SimpleTest rule SimpleTest
{ {
# UnitTest <target> : <sources> : <libraries> # UnitTest <target> : <sources> : <libraries>
+1 -4
View File
@@ -3,13 +3,10 @@
#include <cppunit/Exception.h> #include <cppunit/Exception.h>
#include <cppunit/TestResult.h> #include <cppunit/TestResult.h>
#include <kernel/OS.h> #include <OS.h>
#include <signal.h> #include <signal.h>
#include <string> #include <string>
//class ThreadedTestCase;
class CppUnit::TestResult;
// Pointer to a function that takes no parameters and // Pointer to a function that takes no parameters and
// returns no result. All threads must be implemented // returns no result. All threads must be implemented
// in a function of this type. // in a function of this type.
@@ -8,6 +8,8 @@
#include <TestShell.h> #include <TestShell.h>
#include <ThreadManager.h> #include <ThreadManager.h>
#include <map> #include <map>
#include <vector>
#include <stdio.h>
class TestResult; class TestResult;
+1 -1
View File
@@ -2,7 +2,7 @@
#define _beos_threaded_test_case_h_ #define _beos_threaded_test_case_h_
#include <Locker.h> #include <Locker.h>
#include <kernel/OS.h> #include <OS.h>
#include <TestCase.h> #include <TestCase.h>
#include <map> #include <map>
#include <string> #include <string>
+1
View File
@@ -18,6 +18,7 @@ CommonTestLib libstoragetest.so
SymLinkTest.cpp SymLinkTest.cpp
: <$(SOURCE_GRIST)>libstorage.so be stdc++.r4 : <$(SOURCE_GRIST)>libstorage.so be stdc++.r4
: be stdc++.r4 : be stdc++.r4
:
: storage : storage
; ;
+11 -2
View File
@@ -1,6 +1,15 @@
SubDir OBOS_TOP src tests kits support ; SubDir OBOS_TOP src tests kits support ;
SubInclude OBOS_TOP src tests kits support barchivable ; CommonTestLib libsupporttest.so
SubInclude OBOS_TOP src tests kits support bautolock ; : SupportKitTestAddon.cpp
: <boot!home!config!lib>libopenbeos.so
be stdc++.r4
: be stdc++.r4
: libsupporttest_blocker.so
: support
;
#SubInclude OBOS_TOP src tests kits support barchivable ;
#SubInclude OBOS_TOP src tests kits support bautolock ;
SubInclude OBOS_TOP src tests kits support blocker ; SubInclude OBOS_TOP src tests kits support blocker ;
@@ -0,0 +1,14 @@
#include <TestSuite.h>
#include <TestSuiteAddon.h>
// ##### Include headers for your tests here #####
#include "blocker/LockerTest.h"
BTestSuite* getTestSuite() {
BTestSuite *suite = new BTestSuite("Support");
// ##### Add test suites here #####
suite->addTest("BLocker", LockerTestSuite());
return suite;
}
@@ -1,5 +1,5 @@
/* /*
$Id: BenaphoreLockCountTest1.cpp,v 1.2 2002/07/13 22:45:21 bonefish Exp $ $Id: BenaphoreLockCountTest1.cpp,v 1.3 2002/07/18 05:32:00 tylerdauwalder Exp $
This file implements a test class for testing BLocker functionality. This file implements a test class for testing BLocker functionality.
It tests use cases "Count Lock Requests" for a benaphore style BLocker. It tests use cases "Count Lock Requests" for a benaphore style BLocker.
@@ -22,11 +22,11 @@
*/ */
#include <ThreadedTestCaller.h>
#include "BenaphoreLockCountTest1.h" #include "BenaphoreLockCountTest1.h"
#include "cppunit/TestSuite.h" #include <cppunit/Test.h>
#include "ThreadedTestCaller.h" #include <cppunit/TestSuite.h>
#include <be/support/Locker.h> #include <Locker.h>
#include "Locker.h"
// This constant is used to determine the number of microseconds to // This constant is used to determine the number of microseconds to
@@ -36,36 +36,36 @@ const bigtime_t SNOOZE_TIME = 100000;
/* /*
* Method: BenaphoreLockCountTest1<Locker>::BenaphoreLockCountTest1() * Method: BenaphoreLockCountTest1::BenaphoreLockCountTest1()
* Descr: This is the constructor for this test class. * Descr: This is the constructor for this test class.
*/ */
template<class Locker>
BenaphoreLockCountTest1<Locker>::BenaphoreLockCountTest1(std::string name) : BenaphoreLockCountTest1::BenaphoreLockCountTest1(std::string name) :
LockerTestCase<Locker>(name, true) LockerTestCase(name, true)
{ {
} }
/* /*
* Method: BenaphoreLockCountTest1<Locker>::~BenaphoreLockTestCountTest1() * Method: BenaphoreLockCountTest1::~BenaphoreLockTestCountTest1()
* Descr: This is the destructor for this test class. * Descr: This is the destructor for this test class.
*/ */
template<class Locker>
BenaphoreLockCountTest1<Locker>::~BenaphoreLockCountTest1() BenaphoreLockCountTest1::~BenaphoreLockCountTest1()
{ {
} }
/* /*
* Method: BenaphoreLockCountTest1<Locker>::CheckLockRequests() * Method: BenaphoreLockCountTest1::CheckLockRequests()
* Descr: This member function checks the actual number of lock requests * Descr: This member function checks the actual number of lock requests
* that the BLocker thinks are outstanding versus the number * that the BLocker thinks are outstanding versus the number
* passed in. If they match, true is returned. * passed in. If they match, true is returned.
*/ */
template<class Locker> bool BenaphoreLockCountTest1<Locker>::CheckLockRequests(int expected) bool BenaphoreLockCountTest1::CheckLockRequests(int expected)
{ {
int actual = theLocker->CountLockRequests(); int actual = theLocker->CountLockRequests();
return(actual == expected); return(actual == expected);
@@ -73,7 +73,7 @@ template<class Locker> bool BenaphoreLockCountTest1<Locker>::CheckLockRequests(i
/* /*
* Method: BenaphoreLockCountTest1<Locker>::TestThread1() * Method: BenaphoreLockCountTest1::TestThread1()
* Descr: This member function performs the main portion of the test. * Descr: This member function performs the main portion of the test.
* It first acquires thread2Lock and thread3Lock. This ensures * It first acquires thread2Lock and thread3Lock. This ensures
* that thread2 and thread3 will block until this thread wants * that thread2 and thread3 will block until this thread wants
@@ -85,36 +85,50 @@ template<class Locker> bool BenaphoreLockCountTest1<Locker>::CheckLockRequests(i
* the lock count on final time. * the lock count on final time.
*/ */
template<class Locker> void BenaphoreLockCountTest1<Locker>::TestThread1(void) void BenaphoreLockCountTest1::TestThread1(void)
{ {
SafetyLock<Locker> theSafetyLock1(theLocker); SafetyLock theSafetyLock1(theLocker);
SafetyLock<Locker> theSafetyLock2(&thread2Lock); SafetyLock theSafetyLock2(&thread2Lock);
SafetyLock<Locker> theSafetyLock3(&thread3Lock); SafetyLock theSafetyLock3(&thread3Lock);
assert(thread2Lock.Lock()); assert(thread2Lock.Lock());
NextSubTest();
assert(thread3Lock.Lock()); assert(thread3Lock.Lock());
NextSubTest();
assert(CheckLockRequests(0)); assert(CheckLockRequests(0));
NextSubTest();
assert(theLocker->Lock()); assert(theLocker->Lock());
NextSubTest();
assert(CheckLockRequests(1)); assert(CheckLockRequests(1));
NextSubTest();
thread2Lock.Unlock(); thread2Lock.Unlock();
NextSubTest();
snooze(SNOOZE_TIME); snooze(SNOOZE_TIME);
NextSubTest();
assert(CheckLockRequests(3)); assert(CheckLockRequests(3));
NextSubTest();
thread3Lock.Unlock(); thread3Lock.Unlock();
NextSubTest();
snooze(SNOOZE_TIME); snooze(SNOOZE_TIME);
NextSubTest();
assert(CheckLockRequests(5)); assert(CheckLockRequests(5));
NextSubTest();
theLocker->Unlock(); theLocker->Unlock();
NextSubTest();
snooze(SNOOZE_TIME); snooze(SNOOZE_TIME);
NextSubTest();
assert(CheckLockRequests(2)); assert(CheckLockRequests(2));
NextSubTest();
} }
/* /*
* Method: BenaphoreLockCountTest1<Locker>::TestThread2() * Method: BenaphoreLockCountTest1::TestThread2()
* Descr: This member function defines the actions of the second thread of * Descr: This member function defines the actions of the second thread of
* the test. First it sleeps for a short while and then blocks on * the test. First it sleeps for a short while and then blocks on
* the thread2Lock. When the first thread releases it, this thread * the thread2Lock. When the first thread releases it, this thread
@@ -123,23 +137,30 @@ template<class Locker> void BenaphoreLockCountTest1<Locker>::TestThread1(void)
* acquired, the lock count is checked before finishing this thread. * acquired, the lock count is checked before finishing this thread.
*/ */
template<class Locker> void BenaphoreLockCountTest1<Locker>::TestThread2(void) void BenaphoreLockCountTest1::TestThread2(void)
{ {
SafetyLock<Locker> theSafetyLock1(theLocker); SafetyLock theSafetyLock1(theLocker);
snooze(SNOOZE_TIME / 10); snooze(SNOOZE_TIME / 10);
NextSubTest();
assert(thread2Lock.Lock()); assert(thread2Lock.Lock());
NextSubTest();
assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT); assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
NextSubTest();
assert(theLocker->Lock()); assert(theLocker->Lock());
NextSubTest();
int actual = theLocker->CountLockRequests(); int actual = theLocker->CountLockRequests();
NextSubTest();
assert((actual == 3) || (actual == 4)); assert((actual == 3) || (actual == 4));
NextSubTest();
theLocker->Unlock(); theLocker->Unlock();
NextSubTest();
} }
/* /*
* Method: BenaphoreLockCountTest1<Locker>::TestThread3() * Method: BenaphoreLockCountTest1::TestThread3()
* Descr: This member function defines the actions of the second thread of * Descr: This member function defines the actions of the second thread of
* the test. First it sleeps for a short while and then blocks on * the test. First it sleeps for a short while and then blocks on
* the thread3Lock. When the first thread releases it, this thread * the thread3Lock. When the first thread releases it, this thread
@@ -148,39 +169,44 @@ template<class Locker> void BenaphoreLockCountTest1<Locker>::TestThread2(void)
* acquired, the lock count is checked before finishing this thread. * acquired, the lock count is checked before finishing this thread.
*/ */
template<class Locker> void BenaphoreLockCountTest1<Locker>::TestThread3(void) void BenaphoreLockCountTest1::TestThread3(void)
{ {
SafetyLock<Locker> theSafetyLock1(theLocker); SafetyLock theSafetyLock1(theLocker);
snooze(SNOOZE_TIME / 10); snooze(SNOOZE_TIME / 10);
NextSubTest();
assert(thread3Lock.Lock()); assert(thread3Lock.Lock());
NextSubTest();
assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT); assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
NextSubTest();
assert(theLocker->Lock()); assert(theLocker->Lock());
NextSubTest();
int actual = theLocker->CountLockRequests(); int actual = theLocker->CountLockRequests();
NextSubTest();
assert((actual == 3) || (actual == 4)); assert((actual == 3) || (actual == 4));
NextSubTest();
theLocker->Unlock(); theLocker->Unlock();
NextSubTest();
} }
/* /*
* Method: BenaphoreLockCountTest1<Locker>::suite() * Method: BenaphoreLockCountTest1::suite()
* Descr: This static member function returns a test caller for performing * Descr: This static member function returns a test caller for performing
* the "BenaphoreLockCountTest1" test. The test caller * the "BenaphoreLockCountTest1" test. The test caller
* is created as a ThreadedTestCaller (typedef'd as * is created as a ThreadedTestCaller (typedef'd as
* BenaphoreLockCountTest1Caller) with three independent threads. * BenaphoreLockCountTest1Caller) with three independent threads.
*/ */
template<class Locker> Test *BenaphoreLockCountTest1<Locker>::suite(void) CppUnit::Test *BenaphoreLockCountTest1::suite(void)
{ {
BenaphoreLockCountTest1<Locker> *theTest = new BenaphoreLockCountTest1<Locker>(""); BenaphoreLockCountTest1 *theTest = new BenaphoreLockCountTest1("");
BenaphoreLockCountTest1Caller *threadedTest = new BenaphoreLockCountTest1Caller("", theTest); BThreadedTestCaller<BenaphoreLockCountTest1> *threadedTest =
threadedTest->addThread(":Thread1", &BenaphoreLockCountTest1<Locker>::TestThread1); new BThreadedTestCaller<BenaphoreLockCountTest1>("BLocker::Benaphore Lock Count Test #1", theTest);
threadedTest->addThread(":Thread2", &BenaphoreLockCountTest1<Locker>::TestThread2); threadedTest->addThread("A", &BenaphoreLockCountTest1::TestThread1);
threadedTest->addThread(":Thread3", &BenaphoreLockCountTest1<Locker>::TestThread3); threadedTest->addThread("B", &BenaphoreLockCountTest1::TestThread2);
threadedTest->addThread("C", &BenaphoreLockCountTest1::TestThread3);
return(threadedTest); return(threadedTest);
} }
template class BenaphoreLockCountTest1<BLocker>;
template class BenaphoreLockCountTest1<OpenBeOS::BLocker>;
@@ -1,5 +1,5 @@
/* /*
$Id: BenaphoreLockCountTest1.h,v 1.1 2002/07/09 12:24:58 ejakowatz Exp $ $Id: BenaphoreLockCountTest1.h,v 1.2 2002/07/18 05:32:00 tylerdauwalder Exp $
This file defines a classes for performing one test of BLocker This file defines a classes for performing one test of BLocker
functionality. functionality.
@@ -12,18 +12,14 @@
#include "LockerTestCase.h" #include "LockerTestCase.h"
#include "ThreadedTestCaller.h" #include <string>
class CppUnit::Test;
template<class Locker> class BenaphoreLockCountTest1 : class BenaphoreLockCountTest1 : public LockerTestCase {
public LockerTestCase<Locker> {
private: private:
typedef ThreadedTestCaller <BenaphoreLockCountTest1<Locker> > BLocker thread2Lock;
BenaphoreLockCountTest1Caller; BLocker thread3Lock;
Locker thread2Lock;
Locker thread3Lock;
bool CheckLockRequests(int); bool CheckLockRequests(int);
@@ -35,7 +31,10 @@ public:
void TestThread3(void); void TestThread3(void);
BenaphoreLockCountTest1(std::string); BenaphoreLockCountTest1(std::string);
virtual ~BenaphoreLockCountTest1(); virtual ~BenaphoreLockCountTest1();
static Test *suite(void); static CppUnit::Test *suite(void);
}; };
#endif #endif
@@ -1,5 +1,5 @@
/* /*
$Id: ConcurrencyTest1.cpp,v 1.1 2002/07/09 12:24:58 ejakowatz Exp $ $Id: ConcurrencyTest1.cpp,v 1.2 2002/07/18 05:32:00 tylerdauwalder Exp $
This file implements a test class for testing BLocker functionality. This file implements a test class for testing BLocker functionality.
It tests use cases "Locking 1", "Locking 2", "Unlocking", "Is Locked", It tests use cases "Locking 1", "Locking 2", "Unlocking", "Is Locked",
@@ -8,11 +8,10 @@
*/ */
#include <ThreadedTestCaller.h>
#include "ConcurrencyTest1.h" #include "ConcurrencyTest1.h"
#include "TestSuite.h" #include <cppunit/TestSuite.h>
#include "ThreadedTestCaller.h" #include <Locker.h>
#include <be/support/Locker.h>
#include "Locker.h"
// This constant indicates the number of times the thread should test the // This constant indicates the number of times the thread should test the
@@ -22,32 +21,32 @@ const int32 MAXLOOP = 10000;
/* /*
* Method: ConcurrencyTest1<Locker>::ConcurrencyTest1() * Method: ConcurrencyTest1::ConcurrencyTest1()
* Descr: This is the only constructor for this test case. It takes a * Descr: This is the only constructor for this test case. It takes a
* test name and a flag to indicate whether to test a benaphore * test name and a flag to indicate whether to test a benaphore
* or semaphore type BLocker. * or semaphore type BLocker.
*/ */
template<class Locker>
ConcurrencyTest1<Locker>::ConcurrencyTest1(std::string name, bool benaphoreFlag) : ConcurrencyTest1::ConcurrencyTest1(std::string name, bool benaphoreFlag) :
LockerTestCase<Locker>(name, benaphoreFlag), lockTestValue(false) LockerTestCase(name, benaphoreFlag), lockTestValue(false)
{ {
} }
/* /*
* Method: ConcurrencyTest1<Locker>::~ConcurrencyTest1() * Method: ConcurrencyTest1::~ConcurrencyTest1()
* Descr: This is the descriptor for this test case. * Descr: This is the descriptor for this test case.
*/ */
template<class Locker>
ConcurrencyTest1<Locker>::~ConcurrencyTest1() ConcurrencyTest1::~ConcurrencyTest1()
{ {
} }
/* /*
* Method: ConcurrencyTest1<Locker>::setUp() * Method: ConcurrencyTest1::setUp()
* Descr: This member is called before starting the actual test threads * Descr: This member is called before starting the actual test threads
* and is used to ensure that the class is initialized for the * and is used to ensure that the class is initialized for the
* testing. It just sets the "lockTestValue" flag to false. This * testing. It just sets the "lockTestValue" flag to false. This
@@ -55,15 +54,15 @@ template<class Locker>
* threads. * threads.
*/ */
template<class Locker> void void
ConcurrencyTest1<Locker>::setUp(void) ConcurrencyTest1::setUp(void)
{ {
lockTestValue = false; lockTestValue = false;
} }
/* /*
* Method: ConcurrencyTest1<Locker>::suite() * Method: ConcurrencyTest1::suite()
* Descr: This static member function returns a test suite for performing * Descr: This static member function returns a test suite for performing
* all combinations of "ConcurrencyTest1". The test suite contains * all combinations of "ConcurrencyTest1". The test suite contains
* two instances of the test. One is performed on a benaphore, * two instances of the test. One is performed on a benaphore,
@@ -72,25 +71,29 @@ template<class Locker> void
* ConcurrencyTest1Caller) with three independent threads. * ConcurrencyTest1Caller) with three independent threads.
*/ */
template<class Locker> Test *ConcurrencyTest1<Locker>::suite(void) CppUnit::Test *ConcurrencyTest1::suite(void)
{ {
TestSuite *testSuite = new TestSuite("ConcurrencyTest1"); typedef BThreadedTestCaller<ConcurrencyTest1>
ConcurrencyTest1Caller;
CppUnit::TestSuite *testSuite = new CppUnit::TestSuite("ConcurrencyTest1");
// Make a benaphore based test object, create a ThreadedTestCase for it and add // Make a benaphore based test object, create a ThreadedTestCase for it and add
// three threads to it. // three threads to it.
ConcurrencyTest1<Locker> *theTest = new ConcurrencyTest1<Locker>("Benaphore", true); ConcurrencyTest1 *theTest = new ConcurrencyTest1("Benaphore", true);
ConcurrencyTest1Caller *threadedTest1 = new ConcurrencyTest1Caller("", theTest); ConcurrencyTest1Caller *threadedTest1 = new ConcurrencyTest1Caller("BLocker::Concurrency Test #1 (benaphore)", theTest);
threadedTest1->addThread(":Thread1", &ConcurrencyTest1<Locker>::TestThread); threadedTest1->addThread("A", &ConcurrencyTest1::TestThread);
threadedTest1->addThread(":Thread2", &ConcurrencyTest1<Locker>::TestThread); threadedTest1->addThread("B", &ConcurrencyTest1::TestThread);
threadedTest1->addThread(":Thread3", &ConcurrencyTest1<Locker>::TestThread); threadedTest1->addThread("C", &ConcurrencyTest1::TestThread);
// Make a semaphore based test object, create a ThreadedTestCase for it and add // Make a semaphore based test object, create a ThreadedTestCase for it and add
// three threads to it. // three threads to it.
theTest = new ConcurrencyTest1<Locker>("Semaphore", false); theTest = new ConcurrencyTest1("Semaphore", false);
ConcurrencyTest1Caller *threadedTest2 = new ConcurrencyTest1Caller("", theTest); ConcurrencyTest1Caller *threadedTest2 = new ConcurrencyTest1Caller("BLocker::Concurrency Test #1 (semaphore)", theTest);
threadedTest2->addThread(":Thread1", &ConcurrencyTest1<Locker>::TestThread); threadedTest2->addThread("A", &ConcurrencyTest1::TestThread);
threadedTest2->addThread(":Thread2", &ConcurrencyTest1<Locker>::TestThread); threadedTest2->addThread("B", &ConcurrencyTest1::TestThread);
threadedTest2->addThread(":Thread3", &ConcurrencyTest1<Locker>::TestThread); threadedTest2->addThread("C", &ConcurrencyTest1::TestThread);
testSuite->addTest(threadedTest1); testSuite->addTest(threadedTest1);
testSuite->addTest(threadedTest2); testSuite->addTest(threadedTest2);
@@ -99,7 +102,7 @@ template<class Locker> Test *ConcurrencyTest1<Locker>::suite(void)
/* /*
* Method: ConcurrencyTest1<Locker>::AcquireLock() * Method: ConcurrencyTest1::AcquireLock()
* Descr: This member function is passed the number of times through the * Descr: This member function is passed the number of times through the
* acquisition loop (lockAttempt) and whether or not this is * acquisition loop (lockAttempt) and whether or not this is
* the first acquisition of the lock within this iteration. * the first acquisition of the lock within this iteration.
@@ -108,7 +111,7 @@ template<class Locker> Test *ConcurrencyTest1<Locker>::suite(void)
* both lock acquisition methods on the BLocker. * both lock acquisition methods on the BLocker.
*/ */
template<class Locker> bool ConcurrencyTest1<Locker>::AcquireLock(int lockAttempt, bool ConcurrencyTest1::AcquireLock(int lockAttempt,
bool firstAcquisition) bool firstAcquisition)
{ {
bool timeoutLock; bool timeoutLock;
@@ -129,7 +132,7 @@ template<class Locker> bool ConcurrencyTest1<Locker>::AcquireLock(int lockAttemp
/* /*
* Method: ConcurrencyTest1<Locker>::TestThread() * Method: ConcurrencyTest1::TestThread()
* Descr: This method is the core of the test. Each of the three threads * Descr: This method is the core of the test. Each of the three threads
* run this method to perform the concurrency test. First, the * run this method to perform the concurrency test. First, the
* SafetyLock class (see LockerTestCase.h) is used to make sure that * SafetyLock class (see LockerTestCase.h) is used to make sure that
@@ -152,12 +155,16 @@ template<class Locker> bool ConcurrencyTest1<Locker>::AcquireLock(int lockAttemp
* - The thread confirms that the lock is no longer held. * - The thread confirms that the lock is no longer held.
*/ */
template<class Locker> void ConcurrencyTest1<Locker>::TestThread(void) void ConcurrencyTest1::TestThread(void)
{ {
int i; int i;
SafetyLock<Locker> theSafetyLock(theLocker); SafetyLock theSafetyLock(theLocker);
for (i = 0; i < MAXLOOP; i++) { for (i = 0; i < MAXLOOP; i++) {
// Print out 10 sub test markers per thread
if (i % (MAXLOOP / 10) == 0)
NextSubTest();
CheckLock(0); CheckLock(0);
assert(AcquireLock(i, true)); assert(AcquireLock(i, true));
@@ -178,5 +185,6 @@ template<class Locker> void ConcurrencyTest1<Locker>::TestThread(void)
} }
} }
template class ConcurrencyTest1<BLocker>;
template class ConcurrencyTest1<OpenBeOS::BLocker>;
@@ -1,5 +1,5 @@
/* /*
$Id: ConcurrencyTest1.h,v 1.1 2002/07/09 12:24:58 ejakowatz Exp $ $Id: ConcurrencyTest1.h,v 1.2 2002/07/18 05:32:00 tylerdauwalder Exp $
This file defines a class for performing one test of BLocker This file defines a class for performing one test of BLocker
functionality. functionality.
@@ -12,15 +12,12 @@
#include "LockerTestCase.h" #include "LockerTestCase.h"
#include "ThreadedTestCaller.h"
template<class Locker> class ConcurrencyTest1 : class ConcurrencyTest1 :
public LockerTestCase<Locker> { public LockerTestCase {
private: private:
typedef ThreadedTestCaller <ConcurrencyTest1<Locker> >
ConcurrencyTest1Caller;
bool lockTestValue; bool lockTestValue;
bool AcquireLock(int, bool); bool AcquireLock(int, bool);
@@ -31,6 +28,9 @@ public:
void setUp(void); void setUp(void);
void TestThread(void); void TestThread(void);
static Test *suite(void); static Test *suite(void);
}; };
#endif #endif
@@ -1,5 +1,5 @@
/* /*
$Id: ConcurrencyTest2.cpp,v 1.1 2002/07/09 12:24:58 ejakowatz Exp $ $Id: ConcurrencyTest2.cpp,v 1.2 2002/07/18 05:32:00 tylerdauwalder Exp $
This file implements a test class for testing BLocker functionality. This file implements a test class for testing BLocker functionality.
It tests use cases "Locking 1", "Locking 2", "Unlocking", "Is Locked", It tests use cases "Locking 1", "Locking 2", "Unlocking", "Is Locked",
@@ -12,10 +12,9 @@
*/ */
#include "ConcurrencyTest2.h"
#include "TestSuite.h"
#include "ThreadedTestCaller.h" #include "ThreadedTestCaller.h"
#include <be/support/Locker.h> #include "ConcurrencyTest2.h"
#include "cppunit/TestSuite.h"
#include "Locker.h" #include "Locker.h"
@@ -30,32 +29,32 @@ const int32 MAXLOOP = 10000;
const bigtime_t SNOOZE_TIME = 200000; const bigtime_t SNOOZE_TIME = 200000;
/* /*
* Method: ConcurrencyTest2<Locker>::ConcurrencyTest2() * Method: ConcurrencyTest2::ConcurrencyTest2()
* Descr: This is the only constructor for this test case. It takes a * Descr: This is the only constructor for this test case. It takes a
* test name and a flag to indicate whether to test a benaphore * test name and a flag to indicate whether to test a benaphore
* or semaphore type BLocker. * or semaphore type BLocker.
*/ */
template<class Locker>
ConcurrencyTest2<Locker>::ConcurrencyTest2(std::string name, bool benaphoreFlag) : ConcurrencyTest2::ConcurrencyTest2(std::string name, bool benaphoreFlag) :
LockerTestCase<Locker>(name, benaphoreFlag), lockTestValue(false) LockerTestCase(name, benaphoreFlag), lockTestValue(false)
{ {
} }
/* /*
* Method: ConcurrencyTest2<Locker>::~ConcurrencyTest2() * Method: ConcurrencyTest2::~ConcurrencyTest2()
* Descr: This is the descriptor for this test case. * Descr: This is the descriptor for this test case.
*/ */
template<class Locker>
ConcurrencyTest2<Locker>::~ConcurrencyTest2() ConcurrencyTest2::~ConcurrencyTest2()
{ {
} }
/* /*
* Method: ConcurrencyTest2<Locker>::setUp() * Method: ConcurrencyTest2::setUp()
* Descr: This member is called before starting the actual test threads * Descr: This member is called before starting the actual test threads
* and is used to ensure that the class is initialized for the * and is used to ensure that the class is initialized for the
* testing. It just sets the "lockTestValue" flag to false. This * testing. It just sets the "lockTestValue" flag to false. This
@@ -63,15 +62,15 @@ template<class Locker>
* threads. * threads.
*/ */
template<class Locker> void void
ConcurrencyTest2<Locker>::setUp(void) ConcurrencyTest2::setUp(void)
{ {
lockTestValue = false; lockTestValue = false;
} }
/* /*
* Method: ConcurrencyTest2<Locker>::suite() * Method: ConcurrencyTest2::suite()
* Descr: This static member function returns a test suite for performing * Descr: This static member function returns a test suite for performing
* all combinations of "ConcurrencyTest2". The test suite contains * all combinations of "ConcurrencyTest2". The test suite contains
* two instances of the test. One is performed on a benaphore, * two instances of the test. One is performed on a benaphore,
@@ -80,25 +79,27 @@ template<class Locker> void
* ConcurrencyTest2Caller) with three independent threads. * ConcurrencyTest2Caller) with three independent threads.
*/ */
template<class Locker> Test *ConcurrencyTest2<Locker>::suite(void) CppUnit::Test *ConcurrencyTest2::suite(void)
{ {
TestSuite *testSuite = new TestSuite("ConcurrencyTest2"); typedef BThreadedTestCaller <ConcurrencyTest2 >
ConcurrencyTest2Caller;
CppUnit::TestSuite *testSuite = new CppUnit::TestSuite("ConcurrencyTest2");
// Make a benaphore based test object, create a ThreadedTestCase for it and add // Make a benaphore based test object, create a ThreadedTestCase for it and add
// three threads to it. // three threads to it.
ConcurrencyTest2<Locker> *theTest = new ConcurrencyTest2<Locker>("Benaphore", true); ConcurrencyTest2 *theTest = new ConcurrencyTest2("Benaphore", true);
ConcurrencyTest2Caller *threadedTest1 = new ConcurrencyTest2Caller("", theTest); ConcurrencyTest2Caller *threadedTest1 = new ConcurrencyTest2Caller("BLocker::Concurrency Test #2 (benaphore)", theTest);
threadedTest1->addThread(":Thread1", &ConcurrencyTest2<Locker>::AcquireThread); threadedTest1->addThread("Acquire", &ConcurrencyTest2::AcquireThread);
threadedTest1->addThread(":Thread2", &ConcurrencyTest2<Locker>::TimeoutThread); threadedTest1->addThread("Timeout1", &ConcurrencyTest2::TimeoutThread);
threadedTest1->addThread(":Thread3", &ConcurrencyTest2<Locker>::TimeoutThread); threadedTest1->addThread("Timeout2", &ConcurrencyTest2::TimeoutThread);
// Make a semaphore based test object, create a ThreadedTestCase for it and add // Make a semaphore based test object, create a ThreadedTestCase for it and add
// three threads to it. // three threads to it.
theTest = new ConcurrencyTest2<Locker>("Semaphore", false); theTest = new ConcurrencyTest2("Semaphore", false);
ConcurrencyTest2Caller *threadedTest2 = new ConcurrencyTest2Caller("", theTest); ConcurrencyTest2Caller *threadedTest2 = new ConcurrencyTest2Caller("BLocker::Concurrency Test #2 (semaphore)", theTest);
threadedTest2->addThread(":Thread1", &ConcurrencyTest2<Locker>::AcquireThread); threadedTest2->addThread("Acquire", &ConcurrencyTest2::AcquireThread);
threadedTest2->addThread(":Thread2", &ConcurrencyTest2<Locker>::TimeoutThread); threadedTest2->addThread("Timeout1", &ConcurrencyTest2::TimeoutThread);
threadedTest2->addThread(":Thread3", &ConcurrencyTest2<Locker>::TimeoutThread); threadedTest2->addThread("Timeout2", &ConcurrencyTest2::TimeoutThread);
testSuite->addTest(threadedTest1); testSuite->addTest(threadedTest1);
testSuite->addTest(threadedTest2); testSuite->addTest(threadedTest2);
@@ -107,24 +108,28 @@ template<class Locker> Test *ConcurrencyTest2<Locker>::suite(void)
/* /*
* Method: ConcurrencyTest2<Locker>::AcquireThread() * Method: ConcurrencyTest2::AcquireThread()
* Descr: This member function acquires the lock, sleeps for SNOOZE_TIME, * Descr: This member function acquires the lock, sleeps for SNOOZE_TIME,
* releases the lock and then launches into the lock loop test. * releases the lock and then launches into the lock loop test.
*/ */
template<class Locker> void ConcurrencyTest2<Locker>::AcquireThread(void) void ConcurrencyTest2::AcquireThread(void)
{ {
SafetyLock<Locker> theSafetyLock(theLocker); SafetyLock theSafetyLock(theLocker);
assert(theLocker->Lock()); assert(theLocker->Lock());
NextSubTest();
snooze(SNOOZE_TIME); snooze(SNOOZE_TIME);
NextSubTest();
theLocker->Unlock(); theLocker->Unlock();
NextSubTest();
LockingLoop(); LockingLoop();
NextSubTest();
} }
/* /*
* Method: ConcurrencyTest2<Locker>::AcquireLock() * Method: ConcurrencyTest2::AcquireLock()
* Descr: This member function is passed the number of times through the * Descr: This member function is passed the number of times through the
* acquisition loop (lockAttempt) and whether or not this is * acquisition loop (lockAttempt) and whether or not this is
* the first acquisition of the lock within this iteration. * the first acquisition of the lock within this iteration.
@@ -133,7 +138,7 @@ template<class Locker> void ConcurrencyTest2<Locker>::AcquireThread(void)
* both lock acquisition methods on the BLocker. * both lock acquisition methods on the BLocker.
*/ */
template<class Locker> bool ConcurrencyTest2<Locker>::AcquireLock(int lockAttempt, bool ConcurrencyTest2::AcquireLock(int lockAttempt,
bool firstAcquisition) bool firstAcquisition)
{ {
bool timeoutLock; bool timeoutLock;
@@ -154,24 +159,27 @@ template<class Locker> bool ConcurrencyTest2<Locker>::AcquireLock(int lockAttemp
/* /*
* Method: ConcurrencyTest2<Locker>::TimeoutThread() * Method: ConcurrencyTest2::TimeoutThread()
* Descr: This member function sleeps for a short time and then attempts to * Descr: This member function sleeps for a short time and then attempts to
* acquire the lock for SNOOZE_TIME/10 seconds. This acquisition * acquire the lock for SNOOZE_TIME/10 seconds. This acquisition
* should timeout. Then the locking loop is started. * should timeout. Then the locking loop is started.
*/ */
template<class Locker> void ConcurrencyTest2<Locker>::TimeoutThread(void) void ConcurrencyTest2::TimeoutThread(void)
{ {
SafetyLock<Locker> theSafetyLock(theLocker); SafetyLock theSafetyLock(theLocker);
snooze(SNOOZE_TIME/2); snooze(SNOOZE_TIME/2);
NextSubTest();
assert(theLocker->LockWithTimeout(SNOOZE_TIME/10) == B_TIMED_OUT); assert(theLocker->LockWithTimeout(SNOOZE_TIME/10) == B_TIMED_OUT);
NextSubTest();
LockingLoop(); LockingLoop();
NextSubTest();
} }
/* /*
* Method: ConcurrencyTest2<Locker>::TestThread() * Method: ConcurrencyTest2::TestThread()
* Descr: This method is the core of the test. Each of the three threads * Descr: This method is the core of the test. Each of the three threads
* run this method to perform the concurrency test. First, the * run this method to perform the concurrency test. First, the
* SafetyLock class (see LockerTestCase.h) is used to make sure that * SafetyLock class (see LockerTestCase.h) is used to make sure that
@@ -194,12 +202,12 @@ template<class Locker> void ConcurrencyTest2<Locker>::TimeoutThread(void)
* - The thread confirms that the lock is no longer held. * - The thread confirms that the lock is no longer held.
*/ */
template<class Locker> void ConcurrencyTest2<Locker>::LockingLoop(void) void ConcurrencyTest2::LockingLoop(void)
{ {
int i; int i;
SafetyLock<Locker> theSafetyLock(theLocker); SafetyLock theSafetyLock(theLocker);
for (i = 0; i < MAXLOOP; i++) { for (i = 0; i < MAXLOOP; i++) {
CheckLock(0); CheckLock(0);
assert(AcquireLock(i, true)); assert(AcquireLock(i, true));
@@ -221,5 +229,4 @@ template<class Locker> void ConcurrencyTest2<Locker>::LockingLoop(void)
} }
template class ConcurrencyTest2<BLocker>;
template class ConcurrencyTest2<OpenBeOS::BLocker>;
@@ -1,5 +1,5 @@
/* /*
$Id: ConcurrencyTest2.h,v 1.1 2002/07/09 12:24:58 ejakowatz Exp $ $Id: ConcurrencyTest2.h,v 1.2 2002/07/18 05:32:00 tylerdauwalder Exp $
This file defines a classes for performing one test of BLocker This file defines a classes for performing one test of BLocker
functionality. functionality.
@@ -12,14 +12,12 @@
#include "LockerTestCase.h" #include "LockerTestCase.h"
#include "ThreadedTestCaller.h"
class CppUnit::Test;
template<class Locker> class ConcurrencyTest2 : public LockerTestCase<Locker> {
class ConcurrencyTest2 : public LockerTestCase {
private: private:
typedef ThreadedTestCaller <ConcurrencyTest2<Locker> >
ConcurrencyTest2Caller;
bool lockTestValue; bool lockTestValue;
void TestThread(void); void TestThread(void);
@@ -32,7 +30,10 @@ public:
void setUp(void); void setUp(void);
void AcquireThread(void); void AcquireThread(void);
void TimeoutThread(void); void TimeoutThread(void);
static Test *suite(void); static CppUnit::Test *suite(void);
}; };
#endif #endif
@@ -1,5 +1,5 @@
/* /*
$Id: ConstructionTest1.cpp,v 1.1 2002/07/09 12:24:58 ejakowatz Exp $ $Id: ConstructionTest1.cpp,v 1.2 2002/07/18 05:32:00 tylerdauwalder Exp $
This file implements a test class for testing BLocker construction This file implements a test class for testing BLocker construction
functionality. It checks the "Construction 1", "Construction 2" and functionality. It checks the "Construction 1", "Construction 2" and
@@ -11,44 +11,43 @@
#include "ConstructionTest1.h" #include "ConstructionTest1.h"
#include "TestCaller.h" #include <cppunit/TestCaller.h>
#include <be/kernel/OS.h> #include <OS.h>
#include <be/support/Locker.h> #include <Locker.h>
#include "Locker.h"
/* /*
* Method: ConstructionTest1<Locker>::ConstructionTest1() * Method: ConstructionTest1::ConstructionTest1()
* Descr: This is the constructor for this class. * Descr: This is the constructor for this class.
*/ */
template<class Locker>
ConstructionTest1<Locker>::ConstructionTest1(std::string name) : ConstructionTest1::ConstructionTest1(std::string name) :
LockerTestCase<Locker>(name, true) LockerTestCase(name, true)
{ {
} }
/* /*
* Method: ConstructionTest1<Locker>::~ConstructionTest1() * Method: ConstructionTest1::~ConstructionTest1()
* Descr: This is the desctructor for this BLocker test class. * Descr: This is the desctructor for this BLocker test class.
*/ */
template<class Locker>
ConstructionTest1<Locker>::~ConstructionTest1() ConstructionTest1::~ConstructionTest1()
{ {
} }
/* /*
* Method: ConstructionTest1<Locker>::NameMatches() * Method: ConstructionTest1::NameMatches()
* Descr: This member checks that the semaphore owned by the lock * Descr: This member checks that the semaphore owned by the lock
* passed in has the name passed in. * passed in has the name passed in.
*/ */
template<class Locker> bool bool
ConstructionTest1<Locker>::NameMatches(const char *name, ConstructionTest1::NameMatches(const char *name,
Locker *lockerArg) BLocker *lockerArg)
{ {
sem_info theSemInfo; sem_info theSemInfo;
@@ -58,15 +57,15 @@ template<class Locker> bool
/* /*
* Method: ConstructionTest1<Locker>::IsBenaphore() * Method: ConstructionTest1::IsBenaphore()
* Descr: This member attempts to confirm that the BLocker passed in * Descr: This member attempts to confirm that the BLocker passed in
* is a benaphore or a semaphore style locker. It returns true * is a benaphore or a semaphore style locker. It returns true
* if it is a benaphore, false if it is a semaphore. An * if it is a benaphore, false if it is a semaphore. An
* assertion is raised if an error occurs. * assertion is raised if an error occurs.
*/ */
template<class Locker> bool bool
ConstructionTest1<Locker>::IsBenaphore(Locker *lockerArg) ConstructionTest1::IsBenaphore(BLocker *lockerArg)
{ {
int32 semCount; int32 semCount;
@@ -88,59 +87,60 @@ template<class Locker> bool
/* /*
* Method: ConstructionTest1<Locker>::PerformTest() * Method: ConstructionTest1::PerformTest()
* Descr: This member function is used to test each of the constructors * Descr: This member function is used to test each of the constructors
* for the BLocker. The resulting BLocker is tested to show * for the BLocker. The resulting BLocker is tested to show
* that the BLocker was constructed correctly. * that the BLocker was constructed correctly.
*/ */
template<class Locker> void ConstructionTest1<Locker>::PerformTest(void) void ConstructionTest1::PerformTest(void)
{ {
NextSubTest();
assert(NameMatches("some BLocker", theLocker)); assert(NameMatches("some BLocker", theLocker));
assert(IsBenaphore(theLocker)); assert(IsBenaphore(theLocker));
Locker locker1("test string"); NextSubTest();
BLocker locker1("test string");
assert(NameMatches("test string", &locker1)); assert(NameMatches("test string", &locker1));
assert(IsBenaphore(&locker1)); assert(IsBenaphore(&locker1));
Locker locker2(false); NextSubTest();
BLocker locker2(false);
assert(NameMatches("some BLocker", &locker2)); assert(NameMatches("some BLocker", &locker2));
assert(!IsBenaphore(&locker2)); assert(!IsBenaphore(&locker2));
Locker locker3(true); NextSubTest();
BLocker locker3(true);
assert(NameMatches("some BLocker", &locker3)); assert(NameMatches("some BLocker", &locker3));
assert(IsBenaphore(&locker3)); assert(IsBenaphore(&locker3));
Locker locker4("test string", false); NextSubTest();
BLocker locker4("test string", false);
assert(NameMatches("test string", &locker4)); assert(NameMatches("test string", &locker4));
assert(!IsBenaphore(&locker4)); assert(!IsBenaphore(&locker4));
Locker locker5("test string", true); NextSubTest();
BLocker locker5("test string", true);
assert(NameMatches("test string", &locker5)); assert(NameMatches("test string", &locker5));
assert(IsBenaphore(&locker5)); assert(IsBenaphore(&locker5));
} }
/* /*
* Method: ConstructionTest1<Locker>::suite() * Method: ConstructionTest1::suite()
* Descr: This static member function returns a threaded test caller for * Descr: This static member function returns a threaded test caller for
* performing "ConstructionTest1". The threaded test caller * performing "ConstructionTest1". The threaded test caller
* only has a single thread pointint to the PerformTest() member * only has a single thread pointint to the PerformTest() member
* function of this class. * function of this class.
*/ */
template<class Locker> Test *ConstructionTest1<Locker>::suite(void) CppUnit::Test *ConstructionTest1::suite(void)
{ {
ConstructionTest1<Locker> *theTest = typedef CppUnit::TestCaller <ConstructionTest1 >
new ConstructionTest1<Locker>(""); ConstructionTest1Caller;
ConstructionTest1Caller *testCaller = return new ConstructionTest1Caller("BLocker::Construction Test", &ConstructionTest1::PerformTest);
new ConstructionTest1Caller("", theTest);
testCaller->addThread(":Thread1",
&ConstructionTest1<Locker>::PerformTest);
return(testCaller);
} }
template class ConstructionTest1<BLocker>;
template class ConstructionTest1<OpenBeOS::BLocker>;
@@ -1,5 +1,5 @@
/* /*
$Id: ConstructionTest1.h,v 1.1 2002/07/09 12:24:58 ejakowatz Exp $ $Id: ConstructionTest1.h,v 1.2 2002/07/18 05:32:00 tylerdauwalder Exp $
This file defines a class for performing one test of BLocker This file defines a class for performing one test of BLocker
functionality. functionality.
@@ -12,25 +12,25 @@
#include "LockerTestCase.h" #include "LockerTestCase.h"
#include "ThreadedTestCaller.h"
template<class Locker> class ConstructionTest1 : class ConstructionTest1 :
public LockerTestCase<Locker> { public LockerTestCase {
private: private:
typedef ThreadedTestCaller <ConstructionTest1<Locker> > bool NameMatches(const char *, BLocker *);
ConstructionTest1Caller; bool IsBenaphore(BLocker *);
bool NameMatches(const char *, Locker *);
bool IsBenaphore(Locker *);
protected: protected:
public: public:
void PerformTest(void); void PerformTest(void);
ConstructionTest1(std::string name); ConstructionTest1(std::string name = "");
virtual ~ConstructionTest1(); virtual ~ConstructionTest1();
static Test *suite(void); static CppUnit::Test *suite(void);
}; };
#endif #endif
@@ -1,5 +1,5 @@
/* /*
$Id: DestructionTest1.cpp,v 1.1 2002/07/09 12:24:58 ejakowatz Exp $ $Id: DestructionTest1.cpp,v 1.2 2002/07/18 05:32:00 tylerdauwalder Exp $
This file implements a test class for testing BLocker functionality. This file implements a test class for testing BLocker functionality.
It tests use cases "Destruction" and "Locking 3". It tests use cases "Destruction" and "Locking 3".
@@ -17,11 +17,10 @@
*/ */
#include "DestructionTest1.h"
#include "TestSuite.h"
#include "ThreadedTestCaller.h" #include "ThreadedTestCaller.h"
#include <be/support/Locker.h> #include "DestructionTest1.h"
#include "Locker.h" #include "cppunit/TestSuite.h"
#include <Locker.h>
// This constant is used to determine the number of microseconds to // This constant is used to determine the number of microseconds to
// sleep during major steps of the test. // sleep during major steps of the test.
@@ -30,31 +29,31 @@ const bigtime_t SNOOZE_TIME = 200000;
/* /*
* Method: DestructionTest1<Locker>::DestructionTest1() * Method: DestructionTest1::DestructionTest1()
* Descr: This is the only constructor for this test class. * Descr: This is the only constructor for this test class.
*/ */
template<class Locker>
DestructionTest1<Locker>::DestructionTest1(std::string name, DestructionTest1::DestructionTest1(std::string name,
bool isBenaphore) : bool isBenaphore) :
LockerTestCase<Locker>(name, isBenaphore) LockerTestCase(name, isBenaphore)
{ {
} }
/* /*
* Method: DestructionTest1<Locker>::~DestructionTest1() * Method: DestructionTest1::~DestructionTest1()
* Descr: This is the only destructor for this test class. * Descr: This is the only destructor for this test class.
*/ */
template<class Locker>
DestructionTest1<Locker>::~DestructionTest1() DestructionTest1::~DestructionTest1()
{ {
} }
/* /*
* Method: DestructionTest1<Locker>::TestThread1() * Method: DestructionTest1::TestThread1()
* Descr: This method immediately acquires the lock, sleeps * Descr: This method immediately acquires the lock, sleeps
* for SNOOZE_TIME and then releases the lock. It sleeps * for SNOOZE_TIME and then releases the lock. It sleeps
* again for SNOOZE_TIME and then tries to re-acquire the * again for SNOOZE_TIME and then tries to re-acquire the
@@ -62,39 +61,50 @@ template<class Locker>
* deleted the lock. This acquisition should fail. * deleted the lock. This acquisition should fail.
*/ */
template<class Locker> void DestructionTest1<Locker>::TestThread1(void) void DestructionTest1::TestThread1(void)
{ {
assert(theLocker->Lock()); assert(theLocker->Lock());
NextSubTest();
snooze(SNOOZE_TIME); snooze(SNOOZE_TIME);
NextSubTest();
theLocker->Unlock(); theLocker->Unlock();
NextSubTest();
snooze(SNOOZE_TIME); snooze(SNOOZE_TIME);
NextSubTest();
assert(!theLocker->Lock()); assert(!theLocker->Lock());
NextSubTest();
} }
/* /*
* Method: DestructionTest1<Locker>::TestThread2() * Method: DestructionTest1::TestThread2()
* Descr: This method sleeps for SNOOZE_TIME and then acquires the lock. * Descr: This method sleeps for SNOOZE_TIME and then acquires the lock.
* It sleeps again for 2*SNOOZE_TIME and then deletes the lock. * It sleeps again for 2*SNOOZE_TIME and then deletes the lock.
* This should wake up the other thread. * This should wake up the other thread.
*/ */
template<class Locker> void DestructionTest1<Locker>::TestThread2(void) void DestructionTest1::TestThread2(void)
{ {
Locker *tmpLock; BLocker *tmpLock;
snooze(SNOOZE_TIME);
assert(theLocker->Lock());
snooze(SNOOZE_TIME);
snooze(SNOOZE_TIME); snooze(SNOOZE_TIME);
NextSubTest();
assert(theLocker->Lock());
NextSubTest();
snooze(SNOOZE_TIME);
NextSubTest();
snooze(SNOOZE_TIME);
NextSubTest();
tmpLock = theLocker; tmpLock = theLocker;
NextSubTest();
theLocker = NULL; theLocker = NULL;
NextSubTest();
delete tmpLock; delete tmpLock;
} }
/* /*
* Method: DestructionTest1<Locker>::suite() * Method: DestructionTest1::suite()
* Descr: This static member function returns a test suite for performing * Descr: This static member function returns a test suite for performing
* all combinations of "DestructionTest1". The test suite contains * all combinations of "DestructionTest1". The test suite contains
* two instances of the test. One is performed on a benaphore, * two instances of the test. One is performed on a benaphore,
@@ -103,28 +113,28 @@ template<class Locker> void DestructionTest1<Locker>::TestThread2(void)
* DestructionTest1Caller) with two independent threads. * DestructionTest1Caller) with two independent threads.
*/ */
template<class Locker> Test *DestructionTest1<Locker>::suite(void) CppUnit::Test *DestructionTest1::suite(void)
{ {
TestSuite *testSuite = new TestSuite("DestructionTest1"); typedef BThreadedTestCaller <DestructionTest1 >
DestructionTest1Caller;
CppUnit::TestSuite *testSuite = new CppUnit::TestSuite("DestructionTest1");
// Make a benaphore based test object, create a ThreadedTestCase for it and add // Make a benaphore based test object, create a ThreadedTestCase for it and add
// two threads to it. // two threads to it.
DestructionTest1<Locker> *theTest = new DestructionTest1<Locker>("Benaphore", true); DestructionTest1 *theTest = new DestructionTest1("Benaphore", true);
DestructionTest1Caller *threadedTest1 = new DestructionTest1Caller("", theTest); DestructionTest1Caller *threadedTest1 = new DestructionTest1Caller("BLocker::Destruction Test #1 (benaphore)", theTest);
threadedTest1->addThread(":Thread1", &DestructionTest1<Locker>::TestThread1); threadedTest1->addThread("A", &DestructionTest1::TestThread1);
threadedTest1->addThread(":Thread2", &DestructionTest1<Locker>::TestThread2); threadedTest1->addThread("B", &DestructionTest1::TestThread2);
// Make a semaphore based test object, create a ThreadedTestCase for it and add // Make a semaphore based test object, create a ThreadedTestCase for it and add
// three threads to it. // three threads to it.
theTest = new DestructionTest1<Locker>("Semaphore", false); theTest = new DestructionTest1("Semaphore", false);
DestructionTest1Caller *threadedTest2 = new DestructionTest1Caller("", theTest); DestructionTest1Caller *threadedTest2 = new DestructionTest1Caller("BLocker::Destruction Test #1 (semaphore)", theTest);
threadedTest2->addThread(":Thread1", &DestructionTest1<Locker>::TestThread1); threadedTest2->addThread("A", &DestructionTest1::TestThread1);
threadedTest2->addThread(":Thread2", &DestructionTest1<Locker>::TestThread2); threadedTest2->addThread("B", &DestructionTest1::TestThread2);
testSuite->addTest(threadedTest1); testSuite->addTest(threadedTest1);
testSuite->addTest(threadedTest2); testSuite->addTest(threadedTest2);
return(testSuite); return(testSuite);
} }
template class DestructionTest1<BLocker>;
template class DestructionTest1<OpenBeOS::BLocker>;
@@ -1,5 +1,5 @@
/* /*
$Id: DestructionTest1.h,v 1.1 2002/07/09 12:24:58 ejakowatz Exp $ $Id: DestructionTest1.h,v 1.2 2002/07/18 05:32:00 tylerdauwalder Exp $
This file defines a class for performing one test of BLocker This file defines a class for performing one test of BLocker
functionality. functionality.
@@ -10,16 +10,12 @@
#ifndef DestructionTest1_H #ifndef DestructionTest1_H
#define DestructionTest1_H #define DestructionTest1_H
#include "LockerTestCase.h" #include "LockerTestCase.h"
#include "ThreadedTestCaller.h" #include <string>
template<class Locker> class DestructionTest1 : public LockerTestCase<Locker> { class DestructionTest1 : public LockerTestCase {
private: private:
typedef ThreadedTestCaller <DestructionTest1<Locker> >
DestructionTest1Caller;
protected: protected:
@@ -28,7 +24,10 @@ public:
void TestThread2(void); void TestThread2(void);
DestructionTest1(std::string name, bool isBenaphore); DestructionTest1(std::string name, bool isBenaphore);
virtual ~DestructionTest1(); virtual ~DestructionTest1();
static Test *suite(void); static CppUnit::Test *suite(void);
}; };
#endif #endif
@@ -1,5 +1,5 @@
/* /*
$Id: DestructionTest2.cpp,v 1.1 2002/07/09 12:24:58 ejakowatz Exp $ $Id: DestructionTest2.cpp,v 1.2 2002/07/18 05:32:00 tylerdauwalder Exp $
This file implements a test class for testing BLocker functionality. This file implements a test class for testing BLocker functionality.
It tests use cases "Destruction" and "Locking 4". It tests use cases "Destruction" and "Locking 4".
@@ -19,11 +19,10 @@
*/ */
#include <ThreadedTestCaller.h>
#include "DestructionTest2.h" #include "DestructionTest2.h"
#include "TestSuite.h" #include <cppunit/TestSuite.h>
#include "ThreadedTestCaller.h" #include <Locker.h>
#include <be/support/Locker.h>
#include "Locker.h"
// This constant is used to determine the number of microseconds to // This constant is used to determine the number of microseconds to
// sleep during major steps of the test. // sleep during major steps of the test.
@@ -32,31 +31,31 @@ const bigtime_t SNOOZE_TIME = 200000;
/* /*
* Method: DestructionTest2<Locker>::DestructionTest2() * Method: DestructionTest2::DestructionTest2()
* Descr: This is the only constructor for this test class. * Descr: This is the only constructor for this test class.
*/ */
template<class Locker>
DestructionTest2<Locker>::DestructionTest2(std::string name, DestructionTest2::DestructionTest2(std::string name,
bool isBenaphore) : bool isBenaphore) :
LockerTestCase<Locker>(name, isBenaphore) LockerTestCase(name, isBenaphore)
{ {
} }
/* /*
* Method: DestructionTest2<Locker>::~DestructionTest2() * Method: DestructionTest2::~DestructionTest2()
* Descr: This is the only destructor for this test class. * Descr: This is the only destructor for this test class.
*/ */
template<class Locker>
DestructionTest2<Locker>::~DestructionTest2() DestructionTest2::~DestructionTest2()
{ {
} }
/* /*
* Method: DestructionTest2<Locker>::TestThread1() * Method: DestructionTest2::TestThread1()
* Descr: This method immediately acquires the lock, sleeps * Descr: This method immediately acquires the lock, sleeps
* for SNOOZE_TIME and then releases the lock. It sleeps * for SNOOZE_TIME and then releases the lock. It sleeps
* again for SNOOZE_TIME and then tries to re-acquire the * again for SNOOZE_TIME and then tries to re-acquire the
@@ -64,18 +63,23 @@ template<class Locker>
* deleted the lock. This acquisition should fail. * deleted the lock. This acquisition should fail.
*/ */
template<class Locker> void DestructionTest2<Locker>::TestThread1(void) void DestructionTest2::TestThread1(void)
{ {
assert(theLocker->LockWithTimeout(SNOOZE_TIME) == B_OK); assert(theLocker->LockWithTimeout(SNOOZE_TIME) == B_OK);
NextSubTest();
snooze(SNOOZE_TIME); snooze(SNOOZE_TIME);
NextSubTest();
theLocker->Unlock(); theLocker->Unlock();
NextSubTest();
snooze(SNOOZE_TIME); snooze(SNOOZE_TIME);
NextSubTest();
assert(theLocker->LockWithTimeout(SNOOZE_TIME * 10) == B_BAD_SEM_ID); assert(theLocker->LockWithTimeout(SNOOZE_TIME * 10) == B_BAD_SEM_ID);
} NextSubTest();
}
/* /*
* Method: DestructionTest2<Locker>::TestThread2() * Method: DestructionTest2::TestThread2()
* Descr: This method sleeps for SNOOZE_TIME/10 and then attempts to acquire * Descr: This method sleeps for SNOOZE_TIME/10 and then attempts to acquire
* the lock for SNOOZE_TIME/10 seconds. This acquisition will timeout * the lock for SNOOZE_TIME/10 seconds. This acquisition will timeout
* because the other thread is holding the lock. Then it acquires the * because the other thread is holding the lock. Then it acquires the
@@ -83,15 +87,20 @@ template<class Locker> void DestructionTest2<Locker>::TestThread1(void)
* then deletes the lock. This should wake up the other thread. * then deletes the lock. This should wake up the other thread.
*/ */
template<class Locker> void DestructionTest2<Locker>::TestThread2(void) void DestructionTest2::TestThread2(void)
{ {
Locker *tmpLock; BLocker *tmpLock;
snooze(SNOOZE_TIME/10); snooze(SNOOZE_TIME/10);
NextSubTest();
assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT); assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
NextSubTest();
assert(theLocker->LockWithTimeout(SNOOZE_TIME * 10) == B_OK); assert(theLocker->LockWithTimeout(SNOOZE_TIME * 10) == B_OK);
NextSubTest();
snooze(SNOOZE_TIME); snooze(SNOOZE_TIME);
NextSubTest();
snooze(SNOOZE_TIME); snooze(SNOOZE_TIME);
NextSubTest();
tmpLock = theLocker; tmpLock = theLocker;
theLocker = NULL; theLocker = NULL;
delete tmpLock; delete tmpLock;
@@ -99,7 +108,7 @@ template<class Locker> void DestructionTest2<Locker>::TestThread2(void)
/* /*
* Method: DestructionTest2<Locker>::suite() * Method: DestructionTest2::suite()
* Descr: This static member function returns a test suite for performing * Descr: This static member function returns a test suite for performing
* all combinations of "DestructionTest2". The test suite contains * all combinations of "DestructionTest2". The test suite contains
* two instances of the test. One is performed on a benaphore, * two instances of the test. One is performed on a benaphore,
@@ -108,28 +117,30 @@ template<class Locker> void DestructionTest2<Locker>::TestThread2(void)
* DestructionTest2Caller) with two independent threads. * DestructionTest2Caller) with two independent threads.
*/ */
template<class Locker> Test *DestructionTest2<Locker>::suite(void) CppUnit::Test *DestructionTest2::suite(void)
{ {
TestSuite *testSuite = new TestSuite("DestructionTest2"); typedef BThreadedTestCaller<DestructionTest2> DestructionTest2Caller;
CppUnit::TestSuite *testSuite = new CppUnit::TestSuite("DestructionTest2");
// Make a benaphore based test object, create a ThreadedTestCase for it and add // Make a benaphore based test object, create a ThreadedTestCase for it and add
// two threads to it. // two threads to it.
DestructionTest2<Locker> *theTest = new DestructionTest2<Locker>("Benaphore", true); DestructionTest2 *theTest = new DestructionTest2("Benaphore", true);
DestructionTest2Caller *threadedTest1 = new DestructionTest2Caller("", theTest); DestructionTest2Caller *threadedTest1 = new DestructionTest2Caller("BLocker::Destruction Test #2 (benaphore)", theTest);
threadedTest1->addThread(":Thread1", &DestructionTest2<Locker>::TestThread1); threadedTest1->addThread("A", &DestructionTest2::TestThread1);
threadedTest1->addThread(":Thread2", &DestructionTest2<Locker>::TestThread2); threadedTest1->addThread("B", &DestructionTest2::TestThread2);
// Make a semaphore based test object, create a ThreadedTestCase for it and add // Make a semaphore based test object, create a ThreadedTestCase for it and add
// three threads to it. // three threads to it.
theTest = new DestructionTest2<Locker>("Semaphore", false); theTest = new DestructionTest2("Semaphore", false);
DestructionTest2Caller *threadedTest2 = new DestructionTest2Caller("", theTest); DestructionTest2Caller *threadedTest2 = new DestructionTest2Caller("BLocker::Destruction Test #2 (semaphore)", theTest);
threadedTest2->addThread(":Thread1", &DestructionTest2<Locker>::TestThread1); threadedTest2->addThread("A", &DestructionTest2::TestThread1);
threadedTest2->addThread(":Thread2", &DestructionTest2<Locker>::TestThread2); threadedTest2->addThread("B", &DestructionTest2::TestThread2);
testSuite->addTest(threadedTest1); testSuite->addTest(threadedTest1);
testSuite->addTest(threadedTest2); testSuite->addTest(threadedTest2);
return(testSuite); return(testSuite);
} }
template class DestructionTest2<BLocker>;
template class DestructionTest2<OpenBeOS::BLocker>;
@@ -1,5 +1,5 @@
/* /*
$Id: DestructionTest2.h,v 1.1 2002/07/09 12:24:58 ejakowatz Exp $ $Id: DestructionTest2.h,v 1.2 2002/07/18 05:32:00 tylerdauwalder Exp $
This file defines a class for performing one test of BLocker This file defines a class for performing one test of BLocker
functionality. functionality.
@@ -10,25 +10,20 @@
#ifndef DestructionTest2_H #ifndef DestructionTest2_H
#define DestructionTest2_H #define DestructionTest2_H
#include "LockerTestCase.h" #include "LockerTestCase.h"
#include "ThreadedTestCaller.h"
class CppUnit::Test;
template<class Locker> class DestructionTest2 : public LockerTestCase<Locker> {
class DestructionTest2 : public LockerTestCase {
private:
typedef ThreadedTestCaller <DestructionTest2<Locker> >
DestructionTest2Caller;
protected:
public: public:
void TestThread1(void); void TestThread1(void);
void TestThread2(void); void TestThread2(void);
DestructionTest2(std::string name, bool isBenaphore); DestructionTest2(std::string name, bool isBenaphore);
virtual ~DestructionTest2(); virtual ~DestructionTest2();
static Test *suite(void); static CppUnit::Test *suite(void);
}; };
#endif #endif
+11 -16
View File
@@ -1,23 +1,18 @@
SubDir OBOS_TOP src tests kits support blocker ; SubDir OBOS_TOP src tests kits support blocker ;
# Fails to compile. Remove the "if" when it does. CommonTestLib libsupporttest_blocker.so
if "" { : LockerTest.cpp
BenaphoreLockCountTest1.cpp
CommonUnitTest BLockerTester ConcurrencyTest1.cpp
: BenaphoreLockCountTest1.cpp ConcurrencyTest2.cpp
ConcurrencyTest1.cpp ConstructionTest1.cpp
ConcurrencyTest2.cpp DestructionTest1.cpp
ConstructionTest1.cpp DestructionTest2.cpp
DestructionTest1.cpp LockerTestCase.cpp
DestructionTest2.cpp SemaphoreLockCountTest1.cpp
LockerTestAddon.cpp
LockerTestCase.cpp
SemaphoreLockCountTest1.cpp
: kits support
: <boot!home!config!lib>libopenbeos.so be stdc++.r4 : <boot!home!config!lib>libopenbeos.so be stdc++.r4
: be stdc++.r4 : be stdc++.r4
:
: support : support
; ;
} # if ""
@@ -0,0 +1,50 @@
/*
$Id: LockerTest.cpp,v 1.1 2002/07/18 05:32:00 tylerdauwalder Exp $
This file declares the addonTestName string and addonTestFunc
function for the BLocker tests. These symbols will be used
when the addon is loaded.
*/
#include "ConstructionTest1.h"
#include "ConcurrencyTest1.h"
#include "ConcurrencyTest2.h"
#include "DestructionTest1.h"
#include "DestructionTest2.h"
#include "BenaphoreLockCountTest1.h"
#include "SemaphoreLockCountTest1.h"
#include "LockerTest.h"
#include "cppunit/Test.h"
#include "cppunit/TestSuite.h"
/*
* Function: addonTestFunc()
* Descr: This function is called by the test application to
* get a pointer to the test to run. The BLocker test
* is a test suite. A series of tests are added to
* the suite. Each test appears twice, once for
* the Be implementation of BLocker, once for the
* OpenBeOS implementation.
*/
CppUnit::Test* LockerTestSuite()
{
CppUnit::TestSuite *testSuite = new CppUnit::TestSuite();
testSuite->addTest(ConstructionTest1::suite());
testSuite->addTest(ConcurrencyTest1::suite());
testSuite->addTest(ConcurrencyTest2::suite());
testSuite->addTest(DestructionTest1::suite());
testSuite->addTest(DestructionTest2::suite());
testSuite->addTest(BenaphoreLockCountTest1::suite());
testSuite->addTest(SemaphoreLockCountTest1::suite());
return testSuite;
}
@@ -0,0 +1,8 @@
#ifndef _locker_test_file_h_
#define _locker_test_file_h_
class CppUnit::Test;
CppUnit::Test* LockerTestSuite();
#endif // _locker_test_h_
@@ -1,5 +1,5 @@
/* /*
$Id: LockerTestCase.cpp,v 1.1 2002/07/09 12:24:58 ejakowatz Exp $ $Id: LockerTestCase.cpp,v 1.2 2002/07/18 05:32:00 tylerdauwalder Exp $
This file implements a base class for testing BLocker functionality. This file implements a base class for testing BLocker functionality.
@@ -7,32 +7,31 @@
#include "LockerTestCase.h" #include "LockerTestCase.h"
#include <be/support/Locker.h> #include <Locker.h>
#include "Locker.h"
/* /*
* Method: LockerTestCase<Locker>::LockerTestCase() * Method: LockerTestCase::LockerTestCase()
* Descr: This method is the only constructore for the LockerTestCase * Descr: This method is the only constructore for the LockerTestCase
* class. It takes a test name and a flag to indicate whether * class. It takes a test name and a flag to indicate whether
* the locker should be a benaphore or a semaphore. * the locker should be a benaphore or a semaphore.
*/ */
template<class Locker>
LockerTestCase<Locker>::LockerTestCase(std::string name, bool isBenaphore) : LockerTestCase::LockerTestCase(std::string name, bool isBenaphore) :
TestCase(name), theLocker(new Locker(isBenaphore)) BThreadedTestCase(name), theLocker(new BLocker(isBenaphore))
{ {
} }
/* /*
* Method: LockerTestCase<Locker>::~LockerTestCase() * Method: LockerTestCase::~LockerTestCase()
* Descr: This method is the destructor for the LockerTestCase class. * Descr: This method is the destructor for the LockerTestCase class.
* It only deallocates the locker allocated in the constructor. * It only deallocates the locker allocated in the constructor.
*/ */
template<class Locker>
LockerTestCase<Locker>::~LockerTestCase() LockerTestCase::~LockerTestCase()
{ {
delete theLocker; delete theLocker;
theLocker = NULL; theLocker = NULL;
@@ -40,7 +39,7 @@ template<class Locker>
/* /*
* Method: LockerTestCase<Locker>::CheckLock() * Method: LockerTestCase::CheckLock()
* Descr: This method confirms that the lock is currently in a sane * Descr: This method confirms that the lock is currently in a sane
* state. If the lock is not sane, then an assertion is * state. If the lock is not sane, then an assertion is
* raised. The caller provides the number of times the * raised. The caller provides the number of times the
@@ -53,7 +52,7 @@ template<class Locker>
* raises an assertion. * raises an assertion.
*/ */
template<class Locker> void LockerTestCase<Locker>::CheckLock(int expectedCount) void LockerTestCase::CheckLock(int expectedCount)
{ {
bool isLocked = theLocker->IsLocked(); bool isLocked = theLocker->IsLocked();
thread_id actualThread = theLocker->LockingThread(); thread_id actualThread = theLocker->LockingThread();
@@ -70,6 +69,6 @@ template<class Locker> void LockerTestCase<Locker>::CheckLock(int expectedCount)
return; return;
} }
template class LockerTestCase<BLocker>;
template class LockerTestCase<OpenBeOS::BLocker>;
+17 -12
View File
@@ -1,5 +1,5 @@
/* /*
$Id: LockerTestCase.h,v 1.1 2002/07/09 12:24:58 ejakowatz Exp $ $Id: LockerTestCase.h,v 1.2 2002/07/18 05:32:00 tylerdauwalder Exp $
This file defines a couple of common classes for testing BLocker This file defines a couple of common classes for testing BLocker
functionality. functionality.
@@ -10,8 +10,10 @@
#ifndef LockerTestCase_H #ifndef LockerTestCase_H
#define LockerTestCase_H #define LockerTestCase_H
#include <ThreadedTestCase.h>
#include <string>
#include "TestCase.h" class BLocker;
// //
// The SafetyLock class is a utility class for use in actual tests // The SafetyLock class is a utility class for use in actual tests
@@ -21,20 +23,20 @@
// deadlocks if one thread in a test has a failure while holding the // deadlocks if one thread in a test has a failure while holding the
// lock. It should be used like so: // lock. It should be used like so:
// //
// template<class Locker> void myTestClass<Locker>::myTestFunc(void) // void myTestClass::myTestFunc(void)
// { // {
// SafetyLock<Locker> mySafetyLock(theLocker); // SafetyLock mySafetyLock(theLocker);
// ...perform tests without worrying about holding the lock on assert... // ...perform tests without worrying about holding the lock on assert...
// //
template<class Locker> class SafetyLock { class SafetyLock {
private: private:
Locker *theLocker; BLocker *theLocker;
public: public:
SafetyLock(Locker *aLock) {theLocker = aLock;} SafetyLock(BLocker *aLock) {theLocker = aLock;};
virtual ~SafetyLock() {if (theLocker != NULL) theLocker->Unlock(); }; virtual ~SafetyLock() {if (theLocker != NULL) theLocker->Unlock(); };
}; };
// //
@@ -45,16 +47,19 @@ public:
// the lock is sane. // the lock is sane.
// //
template<class Locker> class LockerTestCase : public TestCase { class LockerTestCase : public BThreadedTestCase {
protected: protected:
Locker *theLocker; BLocker *theLocker;
void CheckLock(int); void CheckLock(int);
public: public:
LockerTestCase(std::string name, bool); LockerTestCase(std::string name, bool);
virtual ~LockerTestCase(); virtual ~LockerTestCase();
}; };
#endif #endif
@@ -1,5 +1,5 @@
/* /*
$Id: SemaphoreLockCountTest1.cpp,v 1.1 2002/07/09 12:24:58 ejakowatz Exp $ $Id: SemaphoreLockCountTest1.cpp,v 1.2 2002/07/18 05:32:00 tylerdauwalder Exp $
This file implements a test class for testing BLocker functionality. This file implements a test class for testing BLocker functionality.
It tests use cases "Count Lock Requests" for a semaphore style BLocker. It tests use cases "Count Lock Requests" for a semaphore style BLocker.
@@ -22,11 +22,10 @@
*/ */
#include "SemaphoreLockCountTest1.h"
#include "TestSuite.h"
#include "ThreadedTestCaller.h" #include "ThreadedTestCaller.h"
#include <be/support/Locker.h> #include "SemaphoreLockCountTest1.h"
#include "Locker.h" #include "cppunit/TestSuite.h"
#include <Locker.h>
// This constant is used to determine the number of microseconds to // This constant is used to determine the number of microseconds to
@@ -36,36 +35,36 @@ const bigtime_t SNOOZE_TIME = 100000;
/* /*
* Method: SemaphoreLockCountTest1<Locker>::SemaphoreLockCountTest1() * Method: SemaphoreLockCountTest1::SemaphoreLockCountTest1()
* Descr: This is the constructor for this test class. * Descr: This is the constructor for this test class.
*/ */
template<class Locker>
SemaphoreLockCountTest1<Locker>::SemaphoreLockCountTest1(std::string name) : SemaphoreLockCountTest1::SemaphoreLockCountTest1(std::string name) :
LockerTestCase<Locker>(name, false) LockerTestCase(name, false)
{ {
} }
/* /*
* Method: SemaphoreLockCountTest1<Locker>::~SemaphoreLockCountTest1() * Method: SemaphoreLockCountTest1::~SemaphoreLockCountTest1()
* Descr: This is the destructor for this test class. * Descr: This is the destructor for this test class.
*/ */
template<class Locker>
SemaphoreLockCountTest1<Locker>::~SemaphoreLockCountTest1() SemaphoreLockCountTest1::~SemaphoreLockCountTest1()
{ {
} }
/* /*
* Method: SemaphoreLockCountTest1<Locker>::CheckLockRequests() * Method: SemaphoreLockCountTest1::CheckLockRequests()
* Descr: This member function checks the actual number of lock requests * Descr: This member function checks the actual number of lock requests
* that the BLocker thinks are outstanding versus the number * that the BLocker thinks are outstanding versus the number
* passed in. If they match, true is returned. * passed in. If they match, true is returned.
*/ */
template<class Locker> bool SemaphoreLockCountTest1<Locker>::CheckLockRequests(int expected) bool SemaphoreLockCountTest1::CheckLockRequests(int expected)
{ {
int actual = theLocker->CountLockRequests(); int actual = theLocker->CountLockRequests();
return(actual == expected); return(actual == expected);
@@ -73,7 +72,7 @@ template<class Locker> bool SemaphoreLockCountTest1<Locker>::CheckLockRequests(i
/* /*
* Method: SemaphoreLockCountTest1<Locker>::TestThread1() * Method: SemaphoreLockCountTest1::TestThread1()
* Descr: This member function performs the main portion of the test. * Descr: This member function performs the main portion of the test.
* It first acquires thread2Lock and thread3Lock. This ensures * It first acquires thread2Lock and thread3Lock. This ensures
* that thread2 and thread3 will block until this thread wants * that thread2 and thread3 will block until this thread wants
@@ -85,28 +84,34 @@ template<class Locker> bool SemaphoreLockCountTest1<Locker>::CheckLockRequests(i
* the lock count on final time. * the lock count on final time.
*/ */
template<class Locker> void SemaphoreLockCountTest1<Locker>::TestThread1(void) void SemaphoreLockCountTest1::TestThread1(void)
{ {
SafetyLock<Locker> theSafetyLock1(theLocker); SafetyLock theSafetyLock1(theLocker);
SafetyLock<Locker> theSafetyLock2(&thread2Lock); SafetyLock theSafetyLock2(&thread2Lock);
SafetyLock<Locker> theSafetyLock3(&thread3Lock); SafetyLock theSafetyLock3(&thread3Lock);
NextSubTest();
assert(thread2Lock.Lock()); assert(thread2Lock.Lock());
assert(thread3Lock.Lock()); assert(thread3Lock.Lock());
NextSubTest();
assert(CheckLockRequests(1)); assert(CheckLockRequests(1));
assert(theLocker->Lock()); assert(theLocker->Lock());
NextSubTest();
assert(CheckLockRequests(2)); assert(CheckLockRequests(2));
NextSubTest();
thread2Lock.Unlock(); thread2Lock.Unlock();
snooze(SNOOZE_TIME); snooze(SNOOZE_TIME);
assert(CheckLockRequests(4)); assert(CheckLockRequests(4));
NextSubTest();
thread3Lock.Unlock(); thread3Lock.Unlock();
snooze(SNOOZE_TIME); snooze(SNOOZE_TIME);
assert(CheckLockRequests(6)); assert(CheckLockRequests(6));
NextSubTest();
theLocker->Unlock(); theLocker->Unlock();
snooze(SNOOZE_TIME); snooze(SNOOZE_TIME);
assert(CheckLockRequests(3)); assert(CheckLockRequests(3));
@@ -114,7 +119,7 @@ template<class Locker> void SemaphoreLockCountTest1<Locker>::TestThread1(void)
/* /*
* Method: SemaphoreLockCountTest1<Locker>::TestThread2() * Method: SemaphoreLockCountTest1::TestThread2()
* Descr: This member function defines the actions of the second thread of * Descr: This member function defines the actions of the second thread of
* the test. First it sleeps for a short while and then blocks on * the test. First it sleeps for a short while and then blocks on
* the thread2Lock. When the first thread releases it, this thread * the thread2Lock. When the first thread releases it, this thread
@@ -123,13 +128,15 @@ template<class Locker> void SemaphoreLockCountTest1<Locker>::TestThread1(void)
* acquired, the lock count is checked before finishing this thread. * acquired, the lock count is checked before finishing this thread.
*/ */
template<class Locker> void SemaphoreLockCountTest1<Locker>::TestThread2(void) void SemaphoreLockCountTest1::TestThread2(void)
{ {
SafetyLock<Locker> theSafetyLock1(theLocker); SafetyLock theSafetyLock1(theLocker);
NextSubTest();
snooze(SNOOZE_TIME / 10); snooze(SNOOZE_TIME / 10);
assert(thread2Lock.Lock()); assert(thread2Lock.Lock());
NextSubTest();
assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT); assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
assert(theLocker->Lock()); assert(theLocker->Lock());
int actual = theLocker->CountLockRequests(); int actual = theLocker->CountLockRequests();
@@ -139,7 +146,7 @@ template<class Locker> void SemaphoreLockCountTest1<Locker>::TestThread2(void)
/* /*
* Method: SemaphoreLockCountTest1<Locker>::TestThread3() * Method: SemaphoreLockCountTest1::TestThread3()
* Descr: This member function defines the actions of the second thread of * Descr: This member function defines the actions of the second thread of
* the test. First it sleeps for a short while and then blocks on * the test. First it sleeps for a short while and then blocks on
* the thread3Lock. When the first thread releases it, this thread * the thread3Lock. When the first thread releases it, this thread
@@ -148,13 +155,15 @@ template<class Locker> void SemaphoreLockCountTest1<Locker>::TestThread2(void)
* acquired, the lock count is checked before finishing this thread. * acquired, the lock count is checked before finishing this thread.
*/ */
template<class Locker> void SemaphoreLockCountTest1<Locker>::TestThread3(void) void SemaphoreLockCountTest1::TestThread3(void)
{ {
SafetyLock<Locker> theSafetyLock1(theLocker); SafetyLock theSafetyLock1(theLocker);
NextSubTest();
snooze(SNOOZE_TIME / 10); snooze(SNOOZE_TIME / 10);
assert(thread3Lock.Lock()); assert(thread3Lock.Lock());
NextSubTest();
assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT); assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
assert(theLocker->Lock()); assert(theLocker->Lock());
int actual = theLocker->CountLockRequests(); int actual = theLocker->CountLockRequests();
@@ -164,23 +173,23 @@ template<class Locker> void SemaphoreLockCountTest1<Locker>::TestThread3(void)
/* /*
* Method: SemaphoreLockCountTest1<Locker>::suite() * Method: SemaphoreLockCountTest1::suite()
* Descr: This static member function returns a test caller for performing * Descr: This static member function returns a test caller for performing
* the "SemaphoreLockCountTest1" test. The test caller * the "SemaphoreLockCountTest1" test. The test caller
* is created as a ThreadedTestCaller (typedef'd as * is created as a ThreadedTestCaller (typedef'd as
* SemaphoreLockCountTest1Caller) with three independent threads. * SemaphoreLockCountTest1Caller) with three independent threads.
*/ */
template<class Locker> Test *SemaphoreLockCountTest1<Locker>::suite(void) CppUnit::Test *SemaphoreLockCountTest1::suite(void)
{ {
SemaphoreLockCountTest1<Locker> *theTest = new SemaphoreLockCountTest1<Locker>(""); typedef BThreadedTestCaller <SemaphoreLockCountTest1 >
SemaphoreLockCountTest1Caller *threadedTest = new SemaphoreLockCountTest1Caller("", theTest); SemaphoreLockCountTest1Caller;
threadedTest->addThread(":Thread1", &SemaphoreLockCountTest1<Locker>::TestThread1);
threadedTest->addThread(":Thread2", &SemaphoreLockCountTest1<Locker>::TestThread2); SemaphoreLockCountTest1 *theTest = new SemaphoreLockCountTest1("");
threadedTest->addThread(":Thread3", &SemaphoreLockCountTest1<Locker>::TestThread3); SemaphoreLockCountTest1Caller *threadedTest = new SemaphoreLockCountTest1Caller("BLocker::Semaphore Lock Count Test", theTest);
threadedTest->addThread("A", &SemaphoreLockCountTest1::TestThread1);
threadedTest->addThread("B", &SemaphoreLockCountTest1::TestThread2);
threadedTest->addThread("C", &SemaphoreLockCountTest1::TestThread3);
return(threadedTest); return(threadedTest);
} }
template class SemaphoreLockCountTest1<BLocker>;
template class SemaphoreLockCountTest1<OpenBeOS::BLocker>;
@@ -1,5 +1,5 @@
/* /*
$Id: SemaphoreLockCountTest1.h,v 1.1 2002/07/09 12:24:58 ejakowatz Exp $ $Id: SemaphoreLockCountTest1.h,v 1.2 2002/07/18 05:32:00 tylerdauwalder Exp $
This file defines a classes for performing one test of BLocker This file defines a classes for performing one test of BLocker
functionality. functionality.
@@ -12,18 +12,15 @@
#include "LockerTestCase.h" #include "LockerTestCase.h"
#include "ThreadedTestCaller.h" #include <string>
template<class Locker> class SemaphoreLockCountTest1 : class SemaphoreLockCountTest1 :
public LockerTestCase<Locker> { public LockerTestCase {
private: private:
typedef ThreadedTestCaller <SemaphoreLockCountTest1<Locker> >
SemaphoreLockCountTest1Caller;
Locker thread2Lock; BLocker thread2Lock;
Locker thread3Lock; BLocker thread3Lock;
bool CheckLockRequests(int); bool CheckLockRequests(int);
@@ -38,4 +35,7 @@ public:
static Test *suite(void); static Test *suite(void);
}; };
#endif #endif