+ 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
{
# 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.
# <target> The name of the target.
# <sources> The list of sources.
@@ -231,13 +231,16 @@ rule CommonTestLib
# to LinkSharedOSLibs).
# <r5 libraries> A list of link libraries for the R5 tests (as passed
# 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
# UsePublicHeaders).
local testlibdir = [ FDirName $(OBOS_TEST_DIR) lib ] ; #/boot/home/config/lib/obos_tests ;
TestLib $(1) : $(2) : $(testlibdir) : $(3) : $(5) ;
R5TestLib $(1) : $(2) : $(testlibdir) : $(4) ;
TestLib $(1) : $(2) : $(testlibdir) : $(3) $(5) : $(6) ;
R5TestLib $(1) : $(2) : $(testlibdir) : $(4) [ R5SharedLibraryNames $(5) ] ;
}
rule TestLib
@@ -448,6 +451,15 @@ rule R5ObjectNames
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
{
# UnitTest <target> : <sources> : <libraries>
+1 -4
View File
@@ -3,13 +3,10 @@
#include <cppunit/Exception.h>
#include <cppunit/TestResult.h>
#include <kernel/OS.h>
#include <OS.h>
#include <signal.h>
#include <string>
//class ThreadedTestCase;
class CppUnit::TestResult;
// Pointer to a function that takes no parameters and
// returns no result. All threads must be implemented
// in a function of this type.
@@ -8,6 +8,8 @@
#include <TestShell.h>
#include <ThreadManager.h>
#include <map>
#include <vector>
#include <stdio.h>
class TestResult;
+1 -1
View File
@@ -2,7 +2,7 @@
#define _beos_threaded_test_case_h_
#include <Locker.h>
#include <kernel/OS.h>
#include <OS.h>
#include <TestCase.h>
#include <map>
#include <string>
+1
View File
@@ -18,6 +18,7 @@ CommonTestLib libstoragetest.so
SymLinkTest.cpp
: <$(SOURCE_GRIST)>libstorage.so be stdc++.r4
: be stdc++.r4
:
: storage
;
+11 -2
View File
@@ -1,6 +1,15 @@
SubDir OBOS_TOP src tests kits support ;
SubInclude OBOS_TOP src tests kits support barchivable ;
SubInclude OBOS_TOP src tests kits support bautolock ;
CommonTestLib libsupporttest.so
: 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 ;
@@ -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.
It tests use cases "Count Lock Requests" for a benaphore style BLocker.
@@ -22,11 +22,11 @@
*/
#include <ThreadedTestCaller.h>
#include "BenaphoreLockCountTest1.h"
#include "cppunit/TestSuite.h"
#include "ThreadedTestCaller.h"
#include <be/support/Locker.h>
#include "Locker.h"
#include <cppunit/Test.h>
#include <cppunit/TestSuite.h>
#include <Locker.h>
// 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.
*/
template<class Locker>
BenaphoreLockCountTest1<Locker>::BenaphoreLockCountTest1(std::string name) :
LockerTestCase<Locker>(name, true)
BenaphoreLockCountTest1::BenaphoreLockCountTest1(std::string name) :
LockerTestCase(name, true)
{
}
/*
* Method: BenaphoreLockCountTest1<Locker>::~BenaphoreLockTestCountTest1()
* Method: BenaphoreLockCountTest1::~BenaphoreLockTestCountTest1()
* 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
* that the BLocker thinks are outstanding versus the number
* 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();
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.
* It first acquires thread2Lock and thread3Lock. This ensures
* 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.
*/
template<class Locker> void BenaphoreLockCountTest1<Locker>::TestThread1(void)
void BenaphoreLockCountTest1::TestThread1(void)
{
SafetyLock<Locker> theSafetyLock1(theLocker);
SafetyLock<Locker> theSafetyLock2(&thread2Lock);
SafetyLock<Locker> theSafetyLock3(&thread3Lock);
SafetyLock theSafetyLock1(theLocker);
SafetyLock theSafetyLock2(&thread2Lock);
SafetyLock theSafetyLock3(&thread3Lock);
assert(thread2Lock.Lock());
NextSubTest();
assert(thread3Lock.Lock());
NextSubTest();
assert(CheckLockRequests(0));
NextSubTest();
assert(theLocker->Lock());
NextSubTest();
assert(CheckLockRequests(1));
NextSubTest();
thread2Lock.Unlock();
NextSubTest();
snooze(SNOOZE_TIME);
NextSubTest();
assert(CheckLockRequests(3));
NextSubTest();
thread3Lock.Unlock();
NextSubTest();
snooze(SNOOZE_TIME);
NextSubTest();
assert(CheckLockRequests(5));
NextSubTest();
theLocker->Unlock();
NextSubTest();
snooze(SNOOZE_TIME);
NextSubTest();
assert(CheckLockRequests(2));
NextSubTest();
}
/*
* Method: BenaphoreLockCountTest1<Locker>::TestThread2()
* Method: BenaphoreLockCountTest1::TestThread2()
* 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 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.
*/
template<class Locker> void BenaphoreLockCountTest1<Locker>::TestThread2(void)
void BenaphoreLockCountTest1::TestThread2(void)
{
SafetyLock<Locker> theSafetyLock1(theLocker);
SafetyLock theSafetyLock1(theLocker);
snooze(SNOOZE_TIME / 10);
NextSubTest();
assert(thread2Lock.Lock());
NextSubTest();
assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
NextSubTest();
assert(theLocker->Lock());
NextSubTest();
int actual = theLocker->CountLockRequests();
NextSubTest();
assert((actual == 3) || (actual == 4));
NextSubTest();
theLocker->Unlock();
NextSubTest();
}
/*
* Method: BenaphoreLockCountTest1<Locker>::TestThread3()
* Method: BenaphoreLockCountTest1::TestThread3()
* 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 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.
*/
template<class Locker> void BenaphoreLockCountTest1<Locker>::TestThread3(void)
void BenaphoreLockCountTest1::TestThread3(void)
{
SafetyLock<Locker> theSafetyLock1(theLocker);
SafetyLock theSafetyLock1(theLocker);
snooze(SNOOZE_TIME / 10);
NextSubTest();
assert(thread3Lock.Lock());
NextSubTest();
assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
NextSubTest();
assert(theLocker->Lock());
NextSubTest();
int actual = theLocker->CountLockRequests();
NextSubTest();
assert((actual == 3) || (actual == 4));
NextSubTest();
theLocker->Unlock();
NextSubTest();
}
/*
* Method: BenaphoreLockCountTest1<Locker>::suite()
* Method: BenaphoreLockCountTest1::suite()
* Descr: This static member function returns a test caller for performing
* the "BenaphoreLockCountTest1" test. The test caller
* is created as a ThreadedTestCaller (typedef'd as
* BenaphoreLockCountTest1Caller) with three independent threads.
*/
template<class Locker> Test *BenaphoreLockCountTest1<Locker>::suite(void)
CppUnit::Test *BenaphoreLockCountTest1::suite(void)
{
BenaphoreLockCountTest1<Locker> *theTest = new BenaphoreLockCountTest1<Locker>("");
BenaphoreLockCountTest1Caller *threadedTest = new BenaphoreLockCountTest1Caller("", theTest);
threadedTest->addThread(":Thread1", &BenaphoreLockCountTest1<Locker>::TestThread1);
threadedTest->addThread(":Thread2", &BenaphoreLockCountTest1<Locker>::TestThread2);
threadedTest->addThread(":Thread3", &BenaphoreLockCountTest1<Locker>::TestThread3);
BenaphoreLockCountTest1 *theTest = new BenaphoreLockCountTest1("");
BThreadedTestCaller<BenaphoreLockCountTest1> *threadedTest =
new BThreadedTestCaller<BenaphoreLockCountTest1>("BLocker::Benaphore Lock Count Test #1", theTest);
threadedTest->addThread("A", &BenaphoreLockCountTest1::TestThread1);
threadedTest->addThread("B", &BenaphoreLockCountTest1::TestThread2);
threadedTest->addThread("C", &BenaphoreLockCountTest1::TestThread3);
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
functionality.
@@ -12,18 +12,14 @@
#include "LockerTestCase.h"
#include "ThreadedTestCaller.h"
#include <string>
class CppUnit::Test;
template<class Locker> class BenaphoreLockCountTest1 :
public LockerTestCase<Locker> {
class BenaphoreLockCountTest1 : public LockerTestCase {
private:
typedef ThreadedTestCaller <BenaphoreLockCountTest1<Locker> >
BenaphoreLockCountTest1Caller;
Locker thread2Lock;
Locker thread3Lock;
BLocker thread2Lock;
BLocker thread3Lock;
bool CheckLockRequests(int);
@@ -35,7 +31,10 @@ public:
void TestThread3(void);
BenaphoreLockCountTest1(std::string);
virtual ~BenaphoreLockCountTest1();
static Test *suite(void);
};
static CppUnit::Test *suite(void);
};
#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.
It tests use cases "Locking 1", "Locking 2", "Unlocking", "Is Locked",
@@ -8,11 +8,10 @@
*/
#include <ThreadedTestCaller.h>
#include "ConcurrencyTest1.h"
#include "TestSuite.h"
#include "ThreadedTestCaller.h"
#include <be/support/Locker.h>
#include "Locker.h"
#include <cppunit/TestSuite.h>
#include <Locker.h>
// 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
* test name and a flag to indicate whether to test a benaphore
* or semaphore type BLocker.
*/
template<class Locker>
ConcurrencyTest1<Locker>::ConcurrencyTest1(std::string name, bool benaphoreFlag) :
LockerTestCase<Locker>(name, benaphoreFlag), lockTestValue(false)
ConcurrencyTest1::ConcurrencyTest1(std::string name, bool benaphoreFlag) :
LockerTestCase(name, benaphoreFlag), lockTestValue(false)
{
}
/*
* Method: ConcurrencyTest1<Locker>::~ConcurrencyTest1()
* Method: ConcurrencyTest1::~ConcurrencyTest1()
* 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
* and is used to ensure that the class is initialized for the
* testing. It just sets the "lockTestValue" flag to false. This
@@ -55,15 +54,15 @@ template<class Locker>
* threads.
*/
template<class Locker> void
ConcurrencyTest1<Locker>::setUp(void)
void
ConcurrencyTest1::setUp(void)
{
lockTestValue = false;
}
/*
* Method: ConcurrencyTest1<Locker>::suite()
* Method: ConcurrencyTest1::suite()
* Descr: This static member function returns a test suite for performing
* all combinations of "ConcurrencyTest1". The test suite contains
* two instances of the test. One is performed on a benaphore,
@@ -72,25 +71,29 @@ template<class Locker> void
* 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
// three threads to it.
ConcurrencyTest1<Locker> *theTest = new ConcurrencyTest1<Locker>("Benaphore", true);
ConcurrencyTest1Caller *threadedTest1 = new ConcurrencyTest1Caller("", theTest);
threadedTest1->addThread(":Thread1", &ConcurrencyTest1<Locker>::TestThread);
threadedTest1->addThread(":Thread2", &ConcurrencyTest1<Locker>::TestThread);
threadedTest1->addThread(":Thread3", &ConcurrencyTest1<Locker>::TestThread);
ConcurrencyTest1 *theTest = new ConcurrencyTest1("Benaphore", true);
ConcurrencyTest1Caller *threadedTest1 = new ConcurrencyTest1Caller("BLocker::Concurrency Test #1 (benaphore)", theTest);
threadedTest1->addThread("A", &ConcurrencyTest1::TestThread);
threadedTest1->addThread("B", &ConcurrencyTest1::TestThread);
threadedTest1->addThread("C", &ConcurrencyTest1::TestThread);
// Make a semaphore based test object, create a ThreadedTestCase for it and add
// three threads to it.
theTest = new ConcurrencyTest1<Locker>("Semaphore", false);
ConcurrencyTest1Caller *threadedTest2 = new ConcurrencyTest1Caller("", theTest);
threadedTest2->addThread(":Thread1", &ConcurrencyTest1<Locker>::TestThread);
threadedTest2->addThread(":Thread2", &ConcurrencyTest1<Locker>::TestThread);
threadedTest2->addThread(":Thread3", &ConcurrencyTest1<Locker>::TestThread);
theTest = new ConcurrencyTest1("Semaphore", false);
ConcurrencyTest1Caller *threadedTest2 = new ConcurrencyTest1Caller("BLocker::Concurrency Test #1 (semaphore)", theTest);
threadedTest2->addThread("A", &ConcurrencyTest1::TestThread);
threadedTest2->addThread("B", &ConcurrencyTest1::TestThread);
threadedTest2->addThread("C", &ConcurrencyTest1::TestThread);
testSuite->addTest(threadedTest1);
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
* acquisition loop (lockAttempt) and whether or not this is
* 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.
*/
template<class Locker> bool ConcurrencyTest1<Locker>::AcquireLock(int lockAttempt,
bool ConcurrencyTest1::AcquireLock(int lockAttempt,
bool firstAcquisition)
{
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
* run this method to perform the concurrency test. First, the
* 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.
*/
template<class Locker> void ConcurrencyTest1<Locker>::TestThread(void)
void ConcurrencyTest1::TestThread(void)
{
int i;
SafetyLock<Locker> theSafetyLock(theLocker);
SafetyLock theSafetyLock(theLocker);
for (i = 0; i < MAXLOOP; i++) {
// Print out 10 sub test markers per thread
if (i % (MAXLOOP / 10) == 0)
NextSubTest();
CheckLock(0);
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
functionality.
@@ -12,15 +12,12 @@
#include "LockerTestCase.h"
#include "ThreadedTestCaller.h"
template<class Locker> class ConcurrencyTest1 :
public LockerTestCase<Locker> {
class ConcurrencyTest1 :
public LockerTestCase {
private:
typedef ThreadedTestCaller <ConcurrencyTest1<Locker> >
ConcurrencyTest1Caller;
bool lockTestValue;
bool AcquireLock(int, bool);
@@ -31,6 +28,9 @@ public:
void setUp(void);
void TestThread(void);
static Test *suite(void);
};
};
#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.
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 <be/support/Locker.h>
#include "ConcurrencyTest2.h"
#include "cppunit/TestSuite.h"
#include "Locker.h"
@@ -30,32 +29,32 @@ const int32 MAXLOOP = 10000;
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
* test name and a flag to indicate whether to test a benaphore
* or semaphore type BLocker.
*/
template<class Locker>
ConcurrencyTest2<Locker>::ConcurrencyTest2(std::string name, bool benaphoreFlag) :
LockerTestCase<Locker>(name, benaphoreFlag), lockTestValue(false)
ConcurrencyTest2::ConcurrencyTest2(std::string name, bool benaphoreFlag) :
LockerTestCase(name, benaphoreFlag), lockTestValue(false)
{
}
/*
* Method: ConcurrencyTest2<Locker>::~ConcurrencyTest2()
* Method: ConcurrencyTest2::~ConcurrencyTest2()
* 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
* and is used to ensure that the class is initialized for the
* testing. It just sets the "lockTestValue" flag to false. This
@@ -63,15 +62,15 @@ template<class Locker>
* threads.
*/
template<class Locker> void
ConcurrencyTest2<Locker>::setUp(void)
void
ConcurrencyTest2::setUp(void)
{
lockTestValue = false;
}
/*
* Method: ConcurrencyTest2<Locker>::suite()
* Method: ConcurrencyTest2::suite()
* Descr: This static member function returns a test suite for performing
* all combinations of "ConcurrencyTest2". The test suite contains
* two instances of the test. One is performed on a benaphore,
@@ -80,25 +79,27 @@ template<class Locker> void
* 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
// three threads to it.
ConcurrencyTest2<Locker> *theTest = new ConcurrencyTest2<Locker>("Benaphore", true);
ConcurrencyTest2Caller *threadedTest1 = new ConcurrencyTest2Caller("", theTest);
threadedTest1->addThread(":Thread1", &ConcurrencyTest2<Locker>::AcquireThread);
threadedTest1->addThread(":Thread2", &ConcurrencyTest2<Locker>::TimeoutThread);
threadedTest1->addThread(":Thread3", &ConcurrencyTest2<Locker>::TimeoutThread);
ConcurrencyTest2 *theTest = new ConcurrencyTest2("Benaphore", true);
ConcurrencyTest2Caller *threadedTest1 = new ConcurrencyTest2Caller("BLocker::Concurrency Test #2 (benaphore)", theTest);
threadedTest1->addThread("Acquire", &ConcurrencyTest2::AcquireThread);
threadedTest1->addThread("Timeout1", &ConcurrencyTest2::TimeoutThread);
threadedTest1->addThread("Timeout2", &ConcurrencyTest2::TimeoutThread);
// Make a semaphore based test object, create a ThreadedTestCase for it and add
// three threads to it.
theTest = new ConcurrencyTest2<Locker>("Semaphore", false);
ConcurrencyTest2Caller *threadedTest2 = new ConcurrencyTest2Caller("", theTest);
threadedTest2->addThread(":Thread1", &ConcurrencyTest2<Locker>::AcquireThread);
threadedTest2->addThread(":Thread2", &ConcurrencyTest2<Locker>::TimeoutThread);
threadedTest2->addThread(":Thread3", &ConcurrencyTest2<Locker>::TimeoutThread);
theTest = new ConcurrencyTest2("Semaphore", false);
ConcurrencyTest2Caller *threadedTest2 = new ConcurrencyTest2Caller("BLocker::Concurrency Test #2 (semaphore)", theTest);
threadedTest2->addThread("Acquire", &ConcurrencyTest2::AcquireThread);
threadedTest2->addThread("Timeout1", &ConcurrencyTest2::TimeoutThread);
threadedTest2->addThread("Timeout2", &ConcurrencyTest2::TimeoutThread);
testSuite->addTest(threadedTest1);
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,
* 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());
NextSubTest();
snooze(SNOOZE_TIME);
NextSubTest();
theLocker->Unlock();
NextSubTest();
LockingLoop();
NextSubTest();
}
/*
* Method: ConcurrencyTest2<Locker>::AcquireLock()
* Method: ConcurrencyTest2::AcquireLock()
* Descr: This member function is passed the number of times through the
* acquisition loop (lockAttempt) and whether or not this is
* 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.
*/
template<class Locker> bool ConcurrencyTest2<Locker>::AcquireLock(int lockAttempt,
bool ConcurrencyTest2::AcquireLock(int lockAttempt,
bool firstAcquisition)
{
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
* acquire the lock for SNOOZE_TIME/10 seconds. This acquisition
* 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);
NextSubTest();
assert(theLocker->LockWithTimeout(SNOOZE_TIME/10) == B_TIMED_OUT);
NextSubTest();
LockingLoop();
NextSubTest();
}
/*
* Method: ConcurrencyTest2<Locker>::TestThread()
* Method: ConcurrencyTest2::TestThread()
* Descr: This method is the core of the test. Each of the three threads
* run this method to perform the concurrency test. First, the
* SafetyLock class (see LockerTestCase.h) is used to make sure that
@@ -194,10 +202,10 @@ template<class Locker> void ConcurrencyTest2<Locker>::TimeoutThread(void)
* - The thread confirms that the lock is no longer held.
*/
template<class Locker> void ConcurrencyTest2<Locker>::LockingLoop(void)
void ConcurrencyTest2::LockingLoop(void)
{
int i;
SafetyLock<Locker> theSafetyLock(theLocker);
SafetyLock theSafetyLock(theLocker);
for (i = 0; i < MAXLOOP; i++) {
CheckLock(0);
@@ -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
functionality.
@@ -12,14 +12,12 @@
#include "LockerTestCase.h"
#include "ThreadedTestCaller.h"
class CppUnit::Test;
template<class Locker> class ConcurrencyTest2 : public LockerTestCase<Locker> {
class ConcurrencyTest2 : public LockerTestCase {
private:
typedef ThreadedTestCaller <ConcurrencyTest2<Locker> >
ConcurrencyTest2Caller;
bool lockTestValue;
void TestThread(void);
@@ -32,7 +30,10 @@ public:
void setUp(void);
void AcquireThread(void);
void TimeoutThread(void);
static Test *suite(void);
static CppUnit::Test *suite(void);
};
#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
functionality. It checks the "Construction 1", "Construction 2" and
@@ -11,44 +11,43 @@
#include "ConstructionTest1.h"
#include "TestCaller.h"
#include <be/kernel/OS.h>
#include <be/support/Locker.h>
#include "Locker.h"
#include <cppunit/TestCaller.h>
#include <OS.h>
#include <Locker.h>
/*
* Method: ConstructionTest1<Locker>::ConstructionTest1()
* Method: ConstructionTest1::ConstructionTest1()
* Descr: This is the constructor for this class.
*/
template<class Locker>
ConstructionTest1<Locker>::ConstructionTest1(std::string name) :
LockerTestCase<Locker>(name, true)
ConstructionTest1::ConstructionTest1(std::string name) :
LockerTestCase(name, true)
{
}
/*
* Method: ConstructionTest1<Locker>::~ConstructionTest1()
* Method: ConstructionTest1::~ConstructionTest1()
* 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
* passed in has the name passed in.
*/
template<class Locker> bool
ConstructionTest1<Locker>::NameMatches(const char *name,
Locker *lockerArg)
bool
ConstructionTest1::NameMatches(const char *name,
BLocker *lockerArg)
{
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
* is a benaphore or a semaphore style locker. It returns true
* if it is a benaphore, false if it is a semaphore. An
* assertion is raised if an error occurs.
*/
template<class Locker> bool
ConstructionTest1<Locker>::IsBenaphore(Locker *lockerArg)
bool
ConstructionTest1::IsBenaphore(BLocker *lockerArg)
{
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
* for the BLocker. The resulting BLocker is tested to show
* 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(IsBenaphore(theLocker));
Locker locker1("test string");
NextSubTest();
BLocker locker1("test string");
assert(NameMatches("test string", &locker1));
assert(IsBenaphore(&locker1));
Locker locker2(false);
NextSubTest();
BLocker locker2(false);
assert(NameMatches("some BLocker", &locker2));
assert(!IsBenaphore(&locker2));
Locker locker3(true);
NextSubTest();
BLocker locker3(true);
assert(NameMatches("some BLocker", &locker3));
assert(IsBenaphore(&locker3));
Locker locker4("test string", false);
NextSubTest();
BLocker locker4("test string", false);
assert(NameMatches("test string", &locker4));
assert(!IsBenaphore(&locker4));
Locker locker5("test string", true);
NextSubTest();
BLocker locker5("test string", true);
assert(NameMatches("test string", &locker5));
assert(IsBenaphore(&locker5));
}
/*
* Method: ConstructionTest1<Locker>::suite()
* Method: ConstructionTest1::suite()
* Descr: This static member function returns a threaded test caller for
* performing "ConstructionTest1". The threaded test caller
* only has a single thread pointint to the PerformTest() member
* function of this class.
*/
template<class Locker> Test *ConstructionTest1<Locker>::suite(void)
CppUnit::Test *ConstructionTest1::suite(void)
{
ConstructionTest1<Locker> *theTest =
new ConstructionTest1<Locker>("");
typedef CppUnit::TestCaller <ConstructionTest1 >
ConstructionTest1Caller;
ConstructionTest1Caller *testCaller =
new ConstructionTest1Caller("", theTest);
testCaller->addThread(":Thread1",
&ConstructionTest1<Locker>::PerformTest);
return(testCaller);
return new ConstructionTest1Caller("BLocker::Construction Test", &ConstructionTest1::PerformTest);
}
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
functionality.
@@ -12,25 +12,25 @@
#include "LockerTestCase.h"
#include "ThreadedTestCaller.h"
template<class Locker> class ConstructionTest1 :
public LockerTestCase<Locker> {
class ConstructionTest1 :
public LockerTestCase {
private:
typedef ThreadedTestCaller <ConstructionTest1<Locker> >
ConstructionTest1Caller;
bool NameMatches(const char *, Locker *);
bool IsBenaphore(Locker *);
bool NameMatches(const char *, BLocker *);
bool IsBenaphore(BLocker *);
protected:
public:
void PerformTest(void);
ConstructionTest1(std::string name);
ConstructionTest1(std::string name = "");
virtual ~ConstructionTest1();
static Test *suite(void);
static CppUnit::Test *suite(void);
};
#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.
It tests use cases "Destruction" and "Locking 3".
@@ -17,11 +17,10 @@
*/
#include "DestructionTest1.h"
#include "TestSuite.h"
#include "ThreadedTestCaller.h"
#include <be/support/Locker.h>
#include "Locker.h"
#include "DestructionTest1.h"
#include "cppunit/TestSuite.h"
#include <Locker.h>
// This constant is used to determine the number of microseconds to
// 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.
*/
template<class Locker>
DestructionTest1<Locker>::DestructionTest1(std::string name,
DestructionTest1::DestructionTest1(std::string name,
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.
*/
template<class Locker>
DestructionTest1<Locker>::~DestructionTest1()
DestructionTest1::~DestructionTest1()
{
}
/*
* Method: DestructionTest1<Locker>::TestThread1()
* Method: DestructionTest1::TestThread1()
* Descr: This method immediately acquires the lock, sleeps
* for SNOOZE_TIME and then releases the lock. It sleeps
* 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.
*/
template<class Locker> void DestructionTest1<Locker>::TestThread1(void)
void DestructionTest1::TestThread1(void)
{
assert(theLocker->Lock());
NextSubTest();
snooze(SNOOZE_TIME);
NextSubTest();
theLocker->Unlock();
NextSubTest();
snooze(SNOOZE_TIME);
NextSubTest();
assert(!theLocker->Lock());
NextSubTest();
}
/*
* Method: DestructionTest1<Locker>::TestThread2()
* Method: DestructionTest1::TestThread2()
* Descr: This method sleeps for SNOOZE_TIME and then acquires the lock.
* It sleeps again for 2*SNOOZE_TIME and then deletes the lock.
* 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);
NextSubTest();
assert(theLocker->Lock());
NextSubTest();
snooze(SNOOZE_TIME);
NextSubTest();
snooze(SNOOZE_TIME);
NextSubTest();
tmpLock = theLocker;
NextSubTest();
theLocker = NULL;
NextSubTest();
delete tmpLock;
}
/*
* Method: DestructionTest1<Locker>::suite()
* Method: DestructionTest1::suite()
* Descr: This static member function returns a test suite for performing
* all combinations of "DestructionTest1". The test suite contains
* 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.
*/
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
// two threads to it.
DestructionTest1<Locker> *theTest = new DestructionTest1<Locker>("Benaphore", true);
DestructionTest1Caller *threadedTest1 = new DestructionTest1Caller("", theTest);
threadedTest1->addThread(":Thread1", &DestructionTest1<Locker>::TestThread1);
threadedTest1->addThread(":Thread2", &DestructionTest1<Locker>::TestThread2);
DestructionTest1 *theTest = new DestructionTest1("Benaphore", true);
DestructionTest1Caller *threadedTest1 = new DestructionTest1Caller("BLocker::Destruction Test #1 (benaphore)", theTest);
threadedTest1->addThread("A", &DestructionTest1::TestThread1);
threadedTest1->addThread("B", &DestructionTest1::TestThread2);
// Make a semaphore based test object, create a ThreadedTestCase for it and add
// three threads to it.
theTest = new DestructionTest1<Locker>("Semaphore", false);
DestructionTest1Caller *threadedTest2 = new DestructionTest1Caller("", theTest);
threadedTest2->addThread(":Thread1", &DestructionTest1<Locker>::TestThread1);
threadedTest2->addThread(":Thread2", &DestructionTest1<Locker>::TestThread2);
theTest = new DestructionTest1("Semaphore", false);
DestructionTest1Caller *threadedTest2 = new DestructionTest1Caller("BLocker::Destruction Test #1 (semaphore)", theTest);
threadedTest2->addThread("A", &DestructionTest1::TestThread1);
threadedTest2->addThread("B", &DestructionTest1::TestThread2);
testSuite->addTest(threadedTest1);
testSuite->addTest(threadedTest2);
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
functionality.
@@ -10,16 +10,12 @@
#ifndef DestructionTest1_H
#define DestructionTest1_H
#include "LockerTestCase.h"
#include "ThreadedTestCaller.h"
#include <string>
template<class Locker> class DestructionTest1 : public LockerTestCase<Locker> {
class DestructionTest1 : public LockerTestCase {
private:
typedef ThreadedTestCaller <DestructionTest1<Locker> >
DestructionTest1Caller;
protected:
@@ -28,7 +24,10 @@ public:
void TestThread2(void);
DestructionTest1(std::string name, bool isBenaphore);
virtual ~DestructionTest1();
static Test *suite(void);
static CppUnit::Test *suite(void);
};
#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.
It tests use cases "Destruction" and "Locking 4".
@@ -19,11 +19,10 @@
*/
#include <ThreadedTestCaller.h>
#include "DestructionTest2.h"
#include "TestSuite.h"
#include "ThreadedTestCaller.h"
#include <be/support/Locker.h>
#include "Locker.h"
#include <cppunit/TestSuite.h>
#include <Locker.h>
// This constant is used to determine the number of microseconds to
// 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.
*/
template<class Locker>
DestructionTest2<Locker>::DestructionTest2(std::string name,
DestructionTest2::DestructionTest2(std::string name,
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.
*/
template<class Locker>
DestructionTest2<Locker>::~DestructionTest2()
DestructionTest2::~DestructionTest2()
{
}
/*
* Method: DestructionTest2<Locker>::TestThread1()
* Method: DestructionTest2::TestThread1()
* Descr: This method immediately acquires the lock, sleeps
* for SNOOZE_TIME and then releases the lock. It sleeps
* 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.
*/
template<class Locker> void DestructionTest2<Locker>::TestThread1(void)
void DestructionTest2::TestThread1(void)
{
assert(theLocker->LockWithTimeout(SNOOZE_TIME) == B_OK);
NextSubTest();
snooze(SNOOZE_TIME);
NextSubTest();
theLocker->Unlock();
NextSubTest();
snooze(SNOOZE_TIME);
NextSubTest();
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
* the lock for SNOOZE_TIME/10 seconds. This acquisition will timeout
* 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.
*/
template<class Locker> void DestructionTest2<Locker>::TestThread2(void)
void DestructionTest2::TestThread2(void)
{
Locker *tmpLock;
BLocker *tmpLock;
snooze(SNOOZE_TIME/10);
NextSubTest();
assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
NextSubTest();
assert(theLocker->LockWithTimeout(SNOOZE_TIME * 10) == B_OK);
NextSubTest();
snooze(SNOOZE_TIME);
NextSubTest();
snooze(SNOOZE_TIME);
NextSubTest();
tmpLock = theLocker;
theLocker = NULL;
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
* all combinations of "DestructionTest2". The test suite contains
* 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.
*/
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
// two threads to it.
DestructionTest2<Locker> *theTest = new DestructionTest2<Locker>("Benaphore", true);
DestructionTest2Caller *threadedTest1 = new DestructionTest2Caller("", theTest);
threadedTest1->addThread(":Thread1", &DestructionTest2<Locker>::TestThread1);
threadedTest1->addThread(":Thread2", &DestructionTest2<Locker>::TestThread2);
DestructionTest2 *theTest = new DestructionTest2("Benaphore", true);
DestructionTest2Caller *threadedTest1 = new DestructionTest2Caller("BLocker::Destruction Test #2 (benaphore)", theTest);
threadedTest1->addThread("A", &DestructionTest2::TestThread1);
threadedTest1->addThread("B", &DestructionTest2::TestThread2);
// Make a semaphore based test object, create a ThreadedTestCase for it and add
// three threads to it.
theTest = new DestructionTest2<Locker>("Semaphore", false);
DestructionTest2Caller *threadedTest2 = new DestructionTest2Caller("", theTest);
threadedTest2->addThread(":Thread1", &DestructionTest2<Locker>::TestThread1);
threadedTest2->addThread(":Thread2", &DestructionTest2<Locker>::TestThread2);
theTest = new DestructionTest2("Semaphore", false);
DestructionTest2Caller *threadedTest2 = new DestructionTest2Caller("BLocker::Destruction Test #2 (semaphore)", theTest);
threadedTest2->addThread("A", &DestructionTest2::TestThread1);
threadedTest2->addThread("B", &DestructionTest2::TestThread2);
testSuite->addTest(threadedTest1);
testSuite->addTest(threadedTest2);
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
functionality.
@@ -10,25 +10,20 @@
#ifndef DestructionTest2_H
#define DestructionTest2_H
#include "LockerTestCase.h"
#include "ThreadedTestCaller.h"
class CppUnit::Test;
template<class Locker> class DestructionTest2 : public LockerTestCase<Locker> {
private:
typedef ThreadedTestCaller <DestructionTest2<Locker> >
DestructionTest2Caller;
protected:
class DestructionTest2 : public LockerTestCase {
public:
void TestThread1(void);
void TestThread2(void);
DestructionTest2(std::string name, bool isBenaphore);
virtual ~DestructionTest2();
static Test *suite(void);
};
static CppUnit::Test *suite(void);
};
#endif
+11 -16
View File
@@ -1,23 +1,18 @@
SubDir OBOS_TOP src tests kits support blocker ;
# Fails to compile. Remove the "if" when it does.
if "" {
CommonUnitTest BLockerTester
: BenaphoreLockCountTest1.cpp
ConcurrencyTest1.cpp
ConcurrencyTest2.cpp
ConstructionTest1.cpp
DestructionTest1.cpp
DestructionTest2.cpp
LockerTestAddon.cpp
LockerTestCase.cpp
SemaphoreLockCountTest1.cpp
: kits support
CommonTestLib libsupporttest_blocker.so
: LockerTest.cpp
BenaphoreLockCountTest1.cpp
ConcurrencyTest1.cpp
ConcurrencyTest2.cpp
ConstructionTest1.cpp
DestructionTest1.cpp
DestructionTest2.cpp
LockerTestCase.cpp
SemaphoreLockCountTest1.cpp
: <boot!home!config!lib>libopenbeos.so be stdc++.r4
: be stdc++.r4
:
: 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.
@@ -7,32 +7,31 @@
#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
* class. It takes a test name and a flag to indicate whether
* the locker should be a benaphore or a semaphore.
*/
template<class Locker>
LockerTestCase<Locker>::LockerTestCase(std::string name, bool isBenaphore) :
TestCase(name), theLocker(new Locker(isBenaphore))
LockerTestCase::LockerTestCase(std::string name, bool isBenaphore) :
BThreadedTestCase(name), theLocker(new BLocker(isBenaphore))
{
}
/*
* Method: LockerTestCase<Locker>::~LockerTestCase()
* Method: LockerTestCase::~LockerTestCase()
* Descr: This method is the destructor for the LockerTestCase class.
* It only deallocates the locker allocated in the constructor.
*/
template<class Locker>
LockerTestCase<Locker>::~LockerTestCase()
LockerTestCase::~LockerTestCase()
{
delete theLocker;
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
* state. If the lock is not sane, then an assertion is
* raised. The caller provides the number of times the
@@ -53,7 +52,7 @@ template<class Locker>
* raises an assertion.
*/
template<class Locker> void LockerTestCase<Locker>::CheckLock(int expectedCount)
void LockerTestCase::CheckLock(int expectedCount)
{
bool isLocked = theLocker->IsLocked();
thread_id actualThread = theLocker->LockingThread();
@@ -71,5 +70,5 @@ template<class Locker> void LockerTestCase<Locker>::CheckLock(int expectedCount)
}
template class LockerTestCase<BLocker>;
template class LockerTestCase<OpenBeOS::BLocker>;
+16 -11
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
functionality.
@@ -10,8 +10,10 @@
#ifndef 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
@@ -21,20 +23,20 @@
// deadlocks if one thread in a test has a failure while holding the
// 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...
//
template<class Locker> class SafetyLock {
class SafetyLock {
private:
Locker *theLocker;
BLocker *theLocker;
public:
SafetyLock(Locker *aLock) {theLocker = aLock;}
SafetyLock(BLocker *aLock) {theLocker = aLock;};
virtual ~SafetyLock() {if (theLocker != NULL) theLocker->Unlock(); };
};
};
//
@@ -45,16 +47,19 @@ public:
// the lock is sane.
//
template<class Locker> class LockerTestCase : public TestCase {
class LockerTestCase : public BThreadedTestCase {
protected:
Locker *theLocker;
BLocker *theLocker;
void CheckLock(int);
public:
LockerTestCase(std::string name, bool);
virtual ~LockerTestCase();
};
};
#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.
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 <be/support/Locker.h>
#include "Locker.h"
#include "SemaphoreLockCountTest1.h"
#include "cppunit/TestSuite.h"
#include <Locker.h>
// 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.
*/
template<class Locker>
SemaphoreLockCountTest1<Locker>::SemaphoreLockCountTest1(std::string name) :
LockerTestCase<Locker>(name, false)
SemaphoreLockCountTest1::SemaphoreLockCountTest1(std::string name) :
LockerTestCase(name, false)
{
}
/*
* Method: SemaphoreLockCountTest1<Locker>::~SemaphoreLockCountTest1()
* Method: SemaphoreLockCountTest1::~SemaphoreLockCountTest1()
* 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
* that the BLocker thinks are outstanding versus the number
* 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();
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.
* It first acquires thread2Lock and thread3Lock. This ensures
* 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.
*/
template<class Locker> void SemaphoreLockCountTest1<Locker>::TestThread1(void)
void SemaphoreLockCountTest1::TestThread1(void)
{
SafetyLock<Locker> theSafetyLock1(theLocker);
SafetyLock<Locker> theSafetyLock2(&thread2Lock);
SafetyLock<Locker> theSafetyLock3(&thread3Lock);
SafetyLock theSafetyLock1(theLocker);
SafetyLock theSafetyLock2(&thread2Lock);
SafetyLock theSafetyLock3(&thread3Lock);
NextSubTest();
assert(thread2Lock.Lock());
assert(thread3Lock.Lock());
NextSubTest();
assert(CheckLockRequests(1));
assert(theLocker->Lock());
NextSubTest();
assert(CheckLockRequests(2));
NextSubTest();
thread2Lock.Unlock();
snooze(SNOOZE_TIME);
assert(CheckLockRequests(4));
NextSubTest();
thread3Lock.Unlock();
snooze(SNOOZE_TIME);
assert(CheckLockRequests(6));
NextSubTest();
theLocker->Unlock();
snooze(SNOOZE_TIME);
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
* the test. First it sleeps for a short while and then blocks on
* 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.
*/
template<class Locker> void SemaphoreLockCountTest1<Locker>::TestThread2(void)
void SemaphoreLockCountTest1::TestThread2(void)
{
SafetyLock<Locker> theSafetyLock1(theLocker);
SafetyLock theSafetyLock1(theLocker);
NextSubTest();
snooze(SNOOZE_TIME / 10);
assert(thread2Lock.Lock());
NextSubTest();
assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
assert(theLocker->Lock());
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
* the test. First it sleeps for a short while and then blocks on
* 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.
*/
template<class Locker> void SemaphoreLockCountTest1<Locker>::TestThread3(void)
void SemaphoreLockCountTest1::TestThread3(void)
{
SafetyLock<Locker> theSafetyLock1(theLocker);
SafetyLock theSafetyLock1(theLocker);
NextSubTest();
snooze(SNOOZE_TIME / 10);
assert(thread3Lock.Lock());
NextSubTest();
assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
assert(theLocker->Lock());
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
* the "SemaphoreLockCountTest1" test. The test caller
* is created as a ThreadedTestCaller (typedef'd as
* SemaphoreLockCountTest1Caller) with three independent threads.
*/
template<class Locker> Test *SemaphoreLockCountTest1<Locker>::suite(void)
CppUnit::Test *SemaphoreLockCountTest1::suite(void)
{
SemaphoreLockCountTest1<Locker> *theTest = new SemaphoreLockCountTest1<Locker>("");
SemaphoreLockCountTest1Caller *threadedTest = new SemaphoreLockCountTest1Caller("", theTest);
threadedTest->addThread(":Thread1", &SemaphoreLockCountTest1<Locker>::TestThread1);
threadedTest->addThread(":Thread2", &SemaphoreLockCountTest1<Locker>::TestThread2);
threadedTest->addThread(":Thread3", &SemaphoreLockCountTest1<Locker>::TestThread3);
typedef BThreadedTestCaller <SemaphoreLockCountTest1 >
SemaphoreLockCountTest1Caller;
SemaphoreLockCountTest1 *theTest = new SemaphoreLockCountTest1("");
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);
}
}
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
functionality.
@@ -12,18 +12,15 @@
#include "LockerTestCase.h"
#include "ThreadedTestCaller.h"
#include <string>
template<class Locker> class SemaphoreLockCountTest1 :
public LockerTestCase<Locker> {
class SemaphoreLockCountTest1 :
public LockerTestCase {
private:
typedef ThreadedTestCaller <SemaphoreLockCountTest1<Locker> >
SemaphoreLockCountTest1Caller;
Locker thread2Lock;
Locker thread3Lock;
BLocker thread2Lock;
BLocker thread3Lock;
bool CheckLockRequests(int);
@@ -39,3 +36,6 @@ public:
};
#endif