From 9285de5124a336ecd9ab26aea1acb7c79aa2f02c Mon Sep 17 00:00:00 2001 From: Tyler Dauwalder Date: Thu, 18 Jul 2002 05:32:00 +0000 Subject: [PATCH] + 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 --- Jamrules | 18 +++- headers/tools/cppunit/ThreadManager.h | 5 +- headers/tools/cppunit/ThreadedTestCaller.h | 2 + headers/tools/cppunit/ThreadedTestCase.h | 2 +- src/tests/kits/storage/Jamfile | 1 + src/tests/kits/support/Jamfile | 13 ++- .../kits/support/SupportKitTestAddon.cpp | 14 +++ .../blocker/BenaphoreLockCountTest1.cpp | 98 ++++++++++++------- .../support/blocker/BenaphoreLockCountTest1.h | 25 +++-- .../kits/support/blocker/ConcurrencyTest1.cpp | 78 ++++++++------- .../kits/support/blocker/ConcurrencyTest1.h | 16 +-- .../kits/support/blocker/ConcurrencyTest2.cpp | 89 +++++++++-------- .../kits/support/blocker/ConcurrencyTest2.h | 17 ++-- .../support/blocker/ConstructionTest1.cpp | 76 +++++++------- .../kits/support/blocker/ConstructionTest1.h | 22 ++--- .../kits/support/blocker/DestructionTest1.cpp | 76 +++++++------- .../kits/support/blocker/DestructionTest1.h | 17 ++-- .../kits/support/blocker/DestructionTest2.cpp | 77 ++++++++------- .../kits/support/blocker/DestructionTest2.h | 25 ++--- src/tests/kits/support/blocker/Jamfile | 27 +++-- src/tests/kits/support/blocker/LockerTest.cpp | 50 ++++++++++ src/tests/kits/support/blocker/LockerTest.h | 8 ++ .../kits/support/blocker/LockerTestCase.cpp | 29 +++--- .../kits/support/blocker/LockerTestCase.h | 29 +++--- .../blocker/SemaphoreLockCountTest1.cpp | 81 ++++++++------- .../support/blocker/SemaphoreLockCountTest1.h | 20 ++-- 26 files changed, 536 insertions(+), 379 deletions(-) create mode 100644 src/tests/kits/support/SupportKitTestAddon.cpp create mode 100644 src/tests/kits/support/blocker/LockerTest.cpp create mode 100644 src/tests/kits/support/blocker/LockerTest.h diff --git a/Jamrules b/Jamrules index ac102ee252..71be810666 100644 --- a/Jamrules +++ b/Jamrules @@ -223,7 +223,7 @@ NOTFILE r5tests ; rule CommonTestLib { # CommonUnitTest : : - # : : ; + # : : : ; # Builds a unit test for both OBOS and R5 modules. # The name of the target. # The list of sources. @@ -231,13 +231,16 @@ rule CommonTestLib # to LinkSharedOSLibs). # A list of link libraries for the R5 tests (as passed # to LinkSharedOSLibs). + # 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). # 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 ; + # 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 : : diff --git a/headers/tools/cppunit/ThreadManager.h b/headers/tools/cppunit/ThreadManager.h index 7e38468bc3..be1a362860 100644 --- a/headers/tools/cppunit/ThreadManager.h +++ b/headers/tools/cppunit/ThreadManager.h @@ -3,13 +3,10 @@ #include #include -#include +#include #include #include -//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. diff --git a/headers/tools/cppunit/ThreadedTestCaller.h b/headers/tools/cppunit/ThreadedTestCaller.h index be50f4540c..10a963f323 100644 --- a/headers/tools/cppunit/ThreadedTestCaller.h +++ b/headers/tools/cppunit/ThreadedTestCaller.h @@ -8,6 +8,8 @@ #include #include #include +#include +#include class TestResult; diff --git a/headers/tools/cppunit/ThreadedTestCase.h b/headers/tools/cppunit/ThreadedTestCase.h index 5ada956a54..5a61f900b8 100644 --- a/headers/tools/cppunit/ThreadedTestCase.h +++ b/headers/tools/cppunit/ThreadedTestCase.h @@ -2,7 +2,7 @@ #define _beos_threaded_test_case_h_ #include -#include +#include #include #include #include diff --git a/src/tests/kits/storage/Jamfile b/src/tests/kits/storage/Jamfile index 5cdfa2619c..48cac28b13 100644 --- a/src/tests/kits/storage/Jamfile +++ b/src/tests/kits/storage/Jamfile @@ -18,6 +18,7 @@ CommonTestLib libstoragetest.so SymLinkTest.cpp : <$(SOURCE_GRIST)>libstorage.so be stdc++.r4 : be stdc++.r4 + : : storage ; diff --git a/src/tests/kits/support/Jamfile b/src/tests/kits/support/Jamfile index 70fd5f1af9..0f1bb389df 100644 --- a/src/tests/kits/support/Jamfile +++ b/src/tests/kits/support/Jamfile @@ -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 + : 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 ; diff --git a/src/tests/kits/support/SupportKitTestAddon.cpp b/src/tests/kits/support/SupportKitTestAddon.cpp new file mode 100644 index 0000000000..0618045e5a --- /dev/null +++ b/src/tests/kits/support/SupportKitTestAddon.cpp @@ -0,0 +1,14 @@ +#include +#include + +// ##### 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; +} diff --git a/src/tests/kits/support/blocker/BenaphoreLockCountTest1.cpp b/src/tests/kits/support/blocker/BenaphoreLockCountTest1.cpp index f12c841904..7464f2e48f 100644 --- a/src/tests/kits/support/blocker/BenaphoreLockCountTest1.cpp +++ b/src/tests/kits/support/blocker/BenaphoreLockCountTest1.cpp @@ -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 #include "BenaphoreLockCountTest1.h" -#include "cppunit/TestSuite.h" -#include "ThreadedTestCaller.h" -#include -#include "Locker.h" +#include +#include +#include // This constant is used to determine the number of microseconds to @@ -36,36 +36,36 @@ const bigtime_t SNOOZE_TIME = 100000; /* - * Method: BenaphoreLockCountTest1::BenaphoreLockCountTest1() + * Method: BenaphoreLockCountTest1::BenaphoreLockCountTest1() * Descr: This is the constructor for this test class. */ -template - BenaphoreLockCountTest1::BenaphoreLockCountTest1(std::string name) : - LockerTestCase(name, true) + + BenaphoreLockCountTest1::BenaphoreLockCountTest1(std::string name) : + LockerTestCase(name, true) { } /* - * Method: BenaphoreLockCountTest1::~BenaphoreLockTestCountTest1() + * Method: BenaphoreLockCountTest1::~BenaphoreLockTestCountTest1() * Descr: This is the destructor for this test class. */ -template - BenaphoreLockCountTest1::~BenaphoreLockCountTest1() + + BenaphoreLockCountTest1::~BenaphoreLockCountTest1() { } /* - * Method: BenaphoreLockCountTest1::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 bool BenaphoreLockCountTest1::CheckLockRequests(int expected) +bool BenaphoreLockCountTest1::CheckLockRequests(int expected) { int actual = theLocker->CountLockRequests(); return(actual == expected); @@ -73,7 +73,7 @@ template bool BenaphoreLockCountTest1::CheckLockRequests(i /* - * Method: BenaphoreLockCountTest1::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 bool BenaphoreLockCountTest1::CheckLockRequests(i * the lock count on final time. */ -template void BenaphoreLockCountTest1::TestThread1(void) +void BenaphoreLockCountTest1::TestThread1(void) { - SafetyLock theSafetyLock1(theLocker); - SafetyLock theSafetyLock2(&thread2Lock); - SafetyLock 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::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 void BenaphoreLockCountTest1::TestThread1(void) * acquired, the lock count is checked before finishing this thread. */ -template void BenaphoreLockCountTest1::TestThread2(void) +void BenaphoreLockCountTest1::TestThread2(void) { - SafetyLock 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::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 void BenaphoreLockCountTest1::TestThread2(void) * acquired, the lock count is checked before finishing this thread. */ -template void BenaphoreLockCountTest1::TestThread3(void) +void BenaphoreLockCountTest1::TestThread3(void) { - SafetyLock 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::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 Test *BenaphoreLockCountTest1::suite(void) +CppUnit::Test *BenaphoreLockCountTest1::suite(void) { - BenaphoreLockCountTest1 *theTest = new BenaphoreLockCountTest1(""); - BenaphoreLockCountTest1Caller *threadedTest = new BenaphoreLockCountTest1Caller("", theTest); - threadedTest->addThread(":Thread1", &BenaphoreLockCountTest1::TestThread1); - threadedTest->addThread(":Thread2", &BenaphoreLockCountTest1::TestThread2); - threadedTest->addThread(":Thread3", &BenaphoreLockCountTest1::TestThread3); + BenaphoreLockCountTest1 *theTest = new BenaphoreLockCountTest1(""); + BThreadedTestCaller *threadedTest = + new BThreadedTestCaller("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; -template class BenaphoreLockCountTest1; \ No newline at end of file diff --git a/src/tests/kits/support/blocker/BenaphoreLockCountTest1.h b/src/tests/kits/support/blocker/BenaphoreLockCountTest1.h index e8389b9f88..b2dafd55cd 100644 --- a/src/tests/kits/support/blocker/BenaphoreLockCountTest1.h +++ b/src/tests/kits/support/blocker/BenaphoreLockCountTest1.h @@ -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 +class CppUnit::Test; -template class BenaphoreLockCountTest1 : - public LockerTestCase { - +class BenaphoreLockCountTest1 : public LockerTestCase { private: - typedef ThreadedTestCaller > - 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 \ No newline at end of file +#endif + + + diff --git a/src/tests/kits/support/blocker/ConcurrencyTest1.cpp b/src/tests/kits/support/blocker/ConcurrencyTest1.cpp index 1c9222a27c..fa19c241db 100644 --- a/src/tests/kits/support/blocker/ConcurrencyTest1.cpp +++ b/src/tests/kits/support/blocker/ConcurrencyTest1.cpp @@ -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 #include "ConcurrencyTest1.h" -#include "TestSuite.h" -#include "ThreadedTestCaller.h" -#include -#include "Locker.h" +#include +#include // This constant indicates the number of times the thread should test the @@ -22,32 +21,32 @@ const int32 MAXLOOP = 10000; /* - * Method: ConcurrencyTest1::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 - ConcurrencyTest1::ConcurrencyTest1(std::string name, bool benaphoreFlag) : - LockerTestCase(name, benaphoreFlag), lockTestValue(false) + + ConcurrencyTest1::ConcurrencyTest1(std::string name, bool benaphoreFlag) : + LockerTestCase(name, benaphoreFlag), lockTestValue(false) { } /* - * Method: ConcurrencyTest1::~ConcurrencyTest1() + * Method: ConcurrencyTest1::~ConcurrencyTest1() * Descr: This is the descriptor for this test case. */ -template - ConcurrencyTest1::~ConcurrencyTest1() + + ConcurrencyTest1::~ConcurrencyTest1() { } /* - * Method: ConcurrencyTest1::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 * threads. */ -template void - ConcurrencyTest1::setUp(void) +void + ConcurrencyTest1::setUp(void) { lockTestValue = false; } /* - * Method: ConcurrencyTest1::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 void * ConcurrencyTest1Caller) with three independent threads. */ -template Test *ConcurrencyTest1::suite(void) +CppUnit::Test *ConcurrencyTest1::suite(void) { - TestSuite *testSuite = new TestSuite("ConcurrencyTest1"); + typedef BThreadedTestCaller + 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 *theTest = new ConcurrencyTest1("Benaphore", true); - ConcurrencyTest1Caller *threadedTest1 = new ConcurrencyTest1Caller("", theTest); - threadedTest1->addThread(":Thread1", &ConcurrencyTest1::TestThread); - threadedTest1->addThread(":Thread2", &ConcurrencyTest1::TestThread); - threadedTest1->addThread(":Thread3", &ConcurrencyTest1::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("Semaphore", false); - ConcurrencyTest1Caller *threadedTest2 = new ConcurrencyTest1Caller("", theTest); - threadedTest2->addThread(":Thread1", &ConcurrencyTest1::TestThread); - threadedTest2->addThread(":Thread2", &ConcurrencyTest1::TestThread); - threadedTest2->addThread(":Thread3", &ConcurrencyTest1::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 Test *ConcurrencyTest1::suite(void) /* - * Method: ConcurrencyTest1::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 Test *ConcurrencyTest1::suite(void) * both lock acquisition methods on the BLocker. */ -template bool ConcurrencyTest1::AcquireLock(int lockAttempt, +bool ConcurrencyTest1::AcquireLock(int lockAttempt, bool firstAcquisition) { bool timeoutLock; @@ -129,7 +132,7 @@ template bool ConcurrencyTest1::AcquireLock(int lockAttemp /* - * Method: ConcurrencyTest1::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 bool ConcurrencyTest1::AcquireLock(int lockAttemp * - The thread confirms that the lock is no longer held. */ -template void ConcurrencyTest1::TestThread(void) +void ConcurrencyTest1::TestThread(void) { int i; - SafetyLock 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 void ConcurrencyTest1::TestThread(void) } } -template class ConcurrencyTest1; -template class ConcurrencyTest1; \ No newline at end of file + + + diff --git a/src/tests/kits/support/blocker/ConcurrencyTest1.h b/src/tests/kits/support/blocker/ConcurrencyTest1.h index 05efcfc469..7610f4eb88 100644 --- a/src/tests/kits/support/blocker/ConcurrencyTest1.h +++ b/src/tests/kits/support/blocker/ConcurrencyTest1.h @@ -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 ConcurrencyTest1 : - public LockerTestCase { +class ConcurrencyTest1 : + public LockerTestCase { private: - typedef ThreadedTestCaller > - ConcurrencyTest1Caller; bool lockTestValue; bool AcquireLock(int, bool); @@ -31,6 +28,9 @@ public: void setUp(void); void TestThread(void); static Test *suite(void); - }; +}; -#endif \ No newline at end of file +#endif + + + diff --git a/src/tests/kits/support/blocker/ConcurrencyTest2.cpp b/src/tests/kits/support/blocker/ConcurrencyTest2.cpp index 7d55c9405b..8937ad2fc0 100644 --- a/src/tests/kits/support/blocker/ConcurrencyTest2.cpp +++ b/src/tests/kits/support/blocker/ConcurrencyTest2.cpp @@ -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 +#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::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 - ConcurrencyTest2::ConcurrencyTest2(std::string name, bool benaphoreFlag) : - LockerTestCase(name, benaphoreFlag), lockTestValue(false) + + ConcurrencyTest2::ConcurrencyTest2(std::string name, bool benaphoreFlag) : + LockerTestCase(name, benaphoreFlag), lockTestValue(false) { } /* - * Method: ConcurrencyTest2::~ConcurrencyTest2() + * Method: ConcurrencyTest2::~ConcurrencyTest2() * Descr: This is the descriptor for this test case. */ -template - ConcurrencyTest2::~ConcurrencyTest2() + + ConcurrencyTest2::~ConcurrencyTest2() { } /* - * Method: ConcurrencyTest2::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 * threads. */ -template void - ConcurrencyTest2::setUp(void) +void + ConcurrencyTest2::setUp(void) { lockTestValue = false; } /* - * Method: ConcurrencyTest2::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 void * ConcurrencyTest2Caller) with three independent threads. */ -template Test *ConcurrencyTest2::suite(void) +CppUnit::Test *ConcurrencyTest2::suite(void) { - TestSuite *testSuite = new TestSuite("ConcurrencyTest2"); + typedef BThreadedTestCaller + 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 *theTest = new ConcurrencyTest2("Benaphore", true); - ConcurrencyTest2Caller *threadedTest1 = new ConcurrencyTest2Caller("", theTest); - threadedTest1->addThread(":Thread1", &ConcurrencyTest2::AcquireThread); - threadedTest1->addThread(":Thread2", &ConcurrencyTest2::TimeoutThread); - threadedTest1->addThread(":Thread3", &ConcurrencyTest2::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("Semaphore", false); - ConcurrencyTest2Caller *threadedTest2 = new ConcurrencyTest2Caller("", theTest); - threadedTest2->addThread(":Thread1", &ConcurrencyTest2::AcquireThread); - threadedTest2->addThread(":Thread2", &ConcurrencyTest2::TimeoutThread); - threadedTest2->addThread(":Thread3", &ConcurrencyTest2::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 Test *ConcurrencyTest2::suite(void) /* - * Method: ConcurrencyTest2::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 void ConcurrencyTest2::AcquireThread(void) +void ConcurrencyTest2::AcquireThread(void) { - SafetyLock theSafetyLock(theLocker); + SafetyLock theSafetyLock(theLocker); assert(theLocker->Lock()); + NextSubTest(); snooze(SNOOZE_TIME); + NextSubTest(); theLocker->Unlock(); + NextSubTest(); LockingLoop(); + NextSubTest(); } /* - * Method: ConcurrencyTest2::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 void ConcurrencyTest2::AcquireThread(void) * both lock acquisition methods on the BLocker. */ -template bool ConcurrencyTest2::AcquireLock(int lockAttempt, +bool ConcurrencyTest2::AcquireLock(int lockAttempt, bool firstAcquisition) { bool timeoutLock; @@ -154,24 +159,27 @@ template bool ConcurrencyTest2::AcquireLock(int lockAttemp /* - * Method: ConcurrencyTest2::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 void ConcurrencyTest2::TimeoutThread(void) +void ConcurrencyTest2::TimeoutThread(void) { - SafetyLock theSafetyLock(theLocker); + SafetyLock theSafetyLock(theLocker); snooze(SNOOZE_TIME/2); + NextSubTest(); assert(theLocker->LockWithTimeout(SNOOZE_TIME/10) == B_TIMED_OUT); + NextSubTest(); LockingLoop(); + NextSubTest(); } /* - * Method: ConcurrencyTest2::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,12 +202,12 @@ template void ConcurrencyTest2::TimeoutThread(void) * - The thread confirms that the lock is no longer held. */ -template void ConcurrencyTest2::LockingLoop(void) +void ConcurrencyTest2::LockingLoop(void) { int i; - SafetyLock theSafetyLock(theLocker); + SafetyLock theSafetyLock(theLocker); - for (i = 0; i < MAXLOOP; i++) { + for (i = 0; i < MAXLOOP; i++) { CheckLock(0); assert(AcquireLock(i, true)); @@ -221,5 +229,4 @@ template void ConcurrencyTest2::LockingLoop(void) } -template class ConcurrencyTest2; -template class ConcurrencyTest2; \ No newline at end of file + diff --git a/src/tests/kits/support/blocker/ConcurrencyTest2.h b/src/tests/kits/support/blocker/ConcurrencyTest2.h index c75b9a9d4e..b9603db870 100644 --- a/src/tests/kits/support/blocker/ConcurrencyTest2.h +++ b/src/tests/kits/support/blocker/ConcurrencyTest2.h @@ -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" - -template class ConcurrencyTest2 : public LockerTestCase { +class CppUnit::Test; + +class ConcurrencyTest2 : public LockerTestCase { private: - typedef ThreadedTestCaller > - 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 \ No newline at end of file +#endif + + + diff --git a/src/tests/kits/support/blocker/ConstructionTest1.cpp b/src/tests/kits/support/blocker/ConstructionTest1.cpp index a00062e5b1..37cce17855 100644 --- a/src/tests/kits/support/blocker/ConstructionTest1.cpp +++ b/src/tests/kits/support/blocker/ConstructionTest1.cpp @@ -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 -#include -#include "Locker.h" +#include +#include +#include /* - * Method: ConstructionTest1::ConstructionTest1() + * Method: ConstructionTest1::ConstructionTest1() * Descr: This is the constructor for this class. */ -template - ConstructionTest1::ConstructionTest1(std::string name) : - LockerTestCase(name, true) + + ConstructionTest1::ConstructionTest1(std::string name) : + LockerTestCase(name, true) { } /* - * Method: ConstructionTest1::~ConstructionTest1() + * Method: ConstructionTest1::~ConstructionTest1() * Descr: This is the desctructor for this BLocker test class. */ -template - ConstructionTest1::~ConstructionTest1() + + ConstructionTest1::~ConstructionTest1() { } /* - * Method: ConstructionTest1::NameMatches() + * Method: ConstructionTest1::NameMatches() * Descr: This member checks that the semaphore owned by the lock * passed in has the name passed in. */ -template bool - ConstructionTest1::NameMatches(const char *name, - Locker *lockerArg) +bool + ConstructionTest1::NameMatches(const char *name, + BLocker *lockerArg) { sem_info theSemInfo; @@ -58,15 +57,15 @@ template bool /* - * Method: ConstructionTest1::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 bool - ConstructionTest1::IsBenaphore(Locker *lockerArg) +bool + ConstructionTest1::IsBenaphore(BLocker *lockerArg) { int32 semCount; @@ -88,59 +87,60 @@ template bool /* - * Method: ConstructionTest1::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 void ConstructionTest1::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::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 Test *ConstructionTest1::suite(void) +CppUnit::Test *ConstructionTest1::suite(void) { - ConstructionTest1 *theTest = - new ConstructionTest1(""); + typedef CppUnit::TestCaller + ConstructionTest1Caller; - ConstructionTest1Caller *testCaller = - new ConstructionTest1Caller("", theTest); - - testCaller->addThread(":Thread1", - &ConstructionTest1::PerformTest); - return(testCaller); + return new ConstructionTest1Caller("BLocker::Construction Test", &ConstructionTest1::PerformTest); } -template class ConstructionTest1; -template class ConstructionTest1; \ No newline at end of file + + diff --git a/src/tests/kits/support/blocker/ConstructionTest1.h b/src/tests/kits/support/blocker/ConstructionTest1.h index 8f0163b9c4..9a31568e2c 100644 --- a/src/tests/kits/support/blocker/ConstructionTest1.h +++ b/src/tests/kits/support/blocker/ConstructionTest1.h @@ -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 ConstructionTest1 : - public LockerTestCase { +class ConstructionTest1 : + public LockerTestCase { private: - typedef ThreadedTestCaller > - 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 \ No newline at end of file +#endif + + + diff --git a/src/tests/kits/support/blocker/DestructionTest1.cpp b/src/tests/kits/support/blocker/DestructionTest1.cpp index c504b03496..d3c0d297d4 100644 --- a/src/tests/kits/support/blocker/DestructionTest1.cpp +++ b/src/tests/kits/support/blocker/DestructionTest1.cpp @@ -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 -#include "Locker.h" +#include "DestructionTest1.h" +#include "cppunit/TestSuite.h" +#include // 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::DestructionTest1() + * Method: DestructionTest1::DestructionTest1() * Descr: This is the only constructor for this test class. */ -template - DestructionTest1::DestructionTest1(std::string name, + + DestructionTest1::DestructionTest1(std::string name, bool isBenaphore) : - LockerTestCase(name, isBenaphore) + LockerTestCase(name, isBenaphore) { } /* - * Method: DestructionTest1::~DestructionTest1() + * Method: DestructionTest1::~DestructionTest1() * Descr: This is the only destructor for this test class. */ -template - DestructionTest1::~DestructionTest1() + + DestructionTest1::~DestructionTest1() { } /* - * Method: DestructionTest1::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 * deleted the lock. This acquisition should fail. */ -template void DestructionTest1::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::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 void DestructionTest1::TestThread2(void) +void DestructionTest1::TestThread2(void) { - Locker *tmpLock; + BLocker *tmpLock; - snooze(SNOOZE_TIME); - assert(theLocker->Lock()); - snooze(SNOOZE_TIME); 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::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 void DestructionTest1::TestThread2(void) * DestructionTest1Caller) with two independent threads. */ -template Test *DestructionTest1::suite(void) +CppUnit::Test *DestructionTest1::suite(void) { - TestSuite *testSuite = new TestSuite("DestructionTest1"); + typedef BThreadedTestCaller + 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 *theTest = new DestructionTest1("Benaphore", true); - DestructionTest1Caller *threadedTest1 = new DestructionTest1Caller("", theTest); - threadedTest1->addThread(":Thread1", &DestructionTest1::TestThread1); - threadedTest1->addThread(":Thread2", &DestructionTest1::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("Semaphore", false); - DestructionTest1Caller *threadedTest2 = new DestructionTest1Caller("", theTest); - threadedTest2->addThread(":Thread1", &DestructionTest1::TestThread1); - threadedTest2->addThread(":Thread2", &DestructionTest1::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; -template class DestructionTest1; \ No newline at end of file diff --git a/src/tests/kits/support/blocker/DestructionTest1.h b/src/tests/kits/support/blocker/DestructionTest1.h index 5a853e7746..21aa9c8f6c 100644 --- a/src/tests/kits/support/blocker/DestructionTest1.h +++ b/src/tests/kits/support/blocker/DestructionTest1.h @@ -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 -template class DestructionTest1 : public LockerTestCase { +class DestructionTest1 : public LockerTestCase { private: - typedef ThreadedTestCaller > - 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 \ No newline at end of file +#endif + + + diff --git a/src/tests/kits/support/blocker/DestructionTest2.cpp b/src/tests/kits/support/blocker/DestructionTest2.cpp index 735c205d14..275e566ce5 100644 --- a/src/tests/kits/support/blocker/DestructionTest2.cpp +++ b/src/tests/kits/support/blocker/DestructionTest2.cpp @@ -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 #include "DestructionTest2.h" -#include "TestSuite.h" -#include "ThreadedTestCaller.h" -#include -#include "Locker.h" +#include +#include // 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::DestructionTest2() + * Method: DestructionTest2::DestructionTest2() * Descr: This is the only constructor for this test class. */ -template - DestructionTest2::DestructionTest2(std::string name, + + DestructionTest2::DestructionTest2(std::string name, bool isBenaphore) : - LockerTestCase(name, isBenaphore) + LockerTestCase(name, isBenaphore) { } /* - * Method: DestructionTest2::~DestructionTest2() + * Method: DestructionTest2::~DestructionTest2() * Descr: This is the only destructor for this test class. */ -template - DestructionTest2::~DestructionTest2() + + DestructionTest2::~DestructionTest2() { } /* - * Method: DestructionTest2::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 * deleted the lock. This acquisition should fail. */ -template void DestructionTest2::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::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 void DestructionTest2::TestThread1(void) * then deletes the lock. This should wake up the other thread. */ -template void DestructionTest2::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); + 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 void DestructionTest2::TestThread2(void) /* - * Method: DestructionTest2::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 void DestructionTest2::TestThread2(void) * DestructionTest2Caller) with two independent threads. */ -template Test *DestructionTest2::suite(void) +CppUnit::Test *DestructionTest2::suite(void) { - TestSuite *testSuite = new TestSuite("DestructionTest2"); + typedef BThreadedTestCaller 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 *theTest = new DestructionTest2("Benaphore", true); - DestructionTest2Caller *threadedTest1 = new DestructionTest2Caller("", theTest); - threadedTest1->addThread(":Thread1", &DestructionTest2::TestThread1); - threadedTest1->addThread(":Thread2", &DestructionTest2::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("Semaphore", false); - DestructionTest2Caller *threadedTest2 = new DestructionTest2Caller("", theTest); - threadedTest2->addThread(":Thread1", &DestructionTest2::TestThread1); - threadedTest2->addThread(":Thread2", &DestructionTest2::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; -template class DestructionTest2; \ No newline at end of file diff --git a/src/tests/kits/support/blocker/DestructionTest2.h b/src/tests/kits/support/blocker/DestructionTest2.h index 216b26d8fd..2f1ed60e12 100644 --- a/src/tests/kits/support/blocker/DestructionTest2.h +++ b/src/tests/kits/support/blocker/DestructionTest2.h @@ -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" - -template class DestructionTest2 : public LockerTestCase { - -private: - typedef ThreadedTestCaller > - DestructionTest2Caller; - -protected: - +class CppUnit::Test; + +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 \ No newline at end of file +#endif + + + diff --git a/src/tests/kits/support/blocker/Jamfile b/src/tests/kits/support/blocker/Jamfile index c331021356..eb9aa76723 100644 --- a/src/tests/kits/support/blocker/Jamfile +++ b/src/tests/kits/support/blocker/Jamfile @@ -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 : libopenbeos.so be stdc++.r4 : be stdc++.r4 + : : support ; -} # if "" - diff --git a/src/tests/kits/support/blocker/LockerTest.cpp b/src/tests/kits/support/blocker/LockerTest.cpp new file mode 100644 index 0000000000..9a18162aba --- /dev/null +++ b/src/tests/kits/support/blocker/LockerTest.cpp @@ -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; +} + + + + diff --git a/src/tests/kits/support/blocker/LockerTest.h b/src/tests/kits/support/blocker/LockerTest.h new file mode 100644 index 0000000000..00c66beb54 --- /dev/null +++ b/src/tests/kits/support/blocker/LockerTest.h @@ -0,0 +1,8 @@ +#ifndef _locker_test_file_h_ +#define _locker_test_file_h_ + +class CppUnit::Test; + +CppUnit::Test* LockerTestSuite(); + +#endif // _locker_test_h_ diff --git a/src/tests/kits/support/blocker/LockerTestCase.cpp b/src/tests/kits/support/blocker/LockerTestCase.cpp index 061a43de44..eb2a218131 100644 --- a/src/tests/kits/support/blocker/LockerTestCase.cpp +++ b/src/tests/kits/support/blocker/LockerTestCase.cpp @@ -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 -#include "Locker.h" +#include /* - * Method: LockerTestCase::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 - LockerTestCase::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::~LockerTestCase() + * Method: LockerTestCase::~LockerTestCase() * Descr: This method is the destructor for the LockerTestCase class. * It only deallocates the locker allocated in the constructor. */ -template - LockerTestCase::~LockerTestCase() + + LockerTestCase::~LockerTestCase() { delete theLocker; theLocker = NULL; @@ -40,7 +39,7 @@ template /* - * Method: LockerTestCase::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 * raises an assertion. */ -template void LockerTestCase::CheckLock(int expectedCount) +void LockerTestCase::CheckLock(int expectedCount) { bool isLocked = theLocker->IsLocked(); thread_id actualThread = theLocker->LockingThread(); @@ -70,6 +69,6 @@ template void LockerTestCase::CheckLock(int expectedCount) return; } - -template class LockerTestCase; -template class LockerTestCase; \ No newline at end of file + + + diff --git a/src/tests/kits/support/blocker/LockerTestCase.h b/src/tests/kits/support/blocker/LockerTestCase.h index 099cd7cbd0..76973b1fa9 100644 --- a/src/tests/kits/support/blocker/LockerTestCase.h +++ b/src/tests/kits/support/blocker/LockerTestCase.h @@ -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 +#include -#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 void myTestClass::myTestFunc(void) +// void myTestClass::myTestFunc(void) // { -// SafetyLock mySafetyLock(theLocker); +// SafetyLock mySafetyLock(theLocker); // ...perform tests without worrying about holding the lock on assert... // -template 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 LockerTestCase : public TestCase { +class LockerTestCase : public BThreadedTestCase { protected: - Locker *theLocker; + BLocker *theLocker; void CheckLock(int); public: LockerTestCase(std::string name, bool); virtual ~LockerTestCase(); - }; +}; -#endif \ No newline at end of file +#endif + + + diff --git a/src/tests/kits/support/blocker/SemaphoreLockCountTest1.cpp b/src/tests/kits/support/blocker/SemaphoreLockCountTest1.cpp index 96c1a2b6f6..1271bc6a24 100644 --- a/src/tests/kits/support/blocker/SemaphoreLockCountTest1.cpp +++ b/src/tests/kits/support/blocker/SemaphoreLockCountTest1.cpp @@ -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 -#include "Locker.h" +#include "SemaphoreLockCountTest1.h" +#include "cppunit/TestSuite.h" +#include // This constant is used to determine the number of microseconds to @@ -36,36 +35,36 @@ const bigtime_t SNOOZE_TIME = 100000; /* - * Method: SemaphoreLockCountTest1::SemaphoreLockCountTest1() + * Method: SemaphoreLockCountTest1::SemaphoreLockCountTest1() * Descr: This is the constructor for this test class. */ -template - SemaphoreLockCountTest1::SemaphoreLockCountTest1(std::string name) : - LockerTestCase(name, false) + + SemaphoreLockCountTest1::SemaphoreLockCountTest1(std::string name) : + LockerTestCase(name, false) { } /* - * Method: SemaphoreLockCountTest1::~SemaphoreLockCountTest1() + * Method: SemaphoreLockCountTest1::~SemaphoreLockCountTest1() * Descr: This is the destructor for this test class. */ -template - SemaphoreLockCountTest1::~SemaphoreLockCountTest1() + + SemaphoreLockCountTest1::~SemaphoreLockCountTest1() { } /* - * Method: SemaphoreLockCountTest1::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 bool SemaphoreLockCountTest1::CheckLockRequests(int expected) +bool SemaphoreLockCountTest1::CheckLockRequests(int expected) { int actual = theLocker->CountLockRequests(); return(actual == expected); @@ -73,7 +72,7 @@ template bool SemaphoreLockCountTest1::CheckLockRequests(i /* - * Method: SemaphoreLockCountTest1::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 bool SemaphoreLockCountTest1::CheckLockRequests(i * the lock count on final time. */ -template void SemaphoreLockCountTest1::TestThread1(void) +void SemaphoreLockCountTest1::TestThread1(void) { - SafetyLock theSafetyLock1(theLocker); - SafetyLock theSafetyLock2(&thread2Lock); - SafetyLock 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 void SemaphoreLockCountTest1::TestThread1(void) /* - * Method: SemaphoreLockCountTest1::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 void SemaphoreLockCountTest1::TestThread1(void) * acquired, the lock count is checked before finishing this thread. */ -template void SemaphoreLockCountTest1::TestThread2(void) +void SemaphoreLockCountTest1::TestThread2(void) { - SafetyLock 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 void SemaphoreLockCountTest1::TestThread2(void) /* - * Method: SemaphoreLockCountTest1::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 void SemaphoreLockCountTest1::TestThread2(void) * acquired, the lock count is checked before finishing this thread. */ -template void SemaphoreLockCountTest1::TestThread3(void) +void SemaphoreLockCountTest1::TestThread3(void) { - SafetyLock 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 void SemaphoreLockCountTest1::TestThread3(void) /* - * Method: SemaphoreLockCountTest1::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 Test *SemaphoreLockCountTest1::suite(void) +CppUnit::Test *SemaphoreLockCountTest1::suite(void) { - SemaphoreLockCountTest1 *theTest = new SemaphoreLockCountTest1(""); - SemaphoreLockCountTest1Caller *threadedTest = new SemaphoreLockCountTest1Caller("", theTest); - threadedTest->addThread(":Thread1", &SemaphoreLockCountTest1::TestThread1); - threadedTest->addThread(":Thread2", &SemaphoreLockCountTest1::TestThread2); - threadedTest->addThread(":Thread3", &SemaphoreLockCountTest1::TestThread3); + typedef BThreadedTestCaller + 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; -template class SemaphoreLockCountTest1; \ No newline at end of file diff --git a/src/tests/kits/support/blocker/SemaphoreLockCountTest1.h b/src/tests/kits/support/blocker/SemaphoreLockCountTest1.h index 185bede99a..df2d6da146 100644 --- a/src/tests/kits/support/blocker/SemaphoreLockCountTest1.h +++ b/src/tests/kits/support/blocker/SemaphoreLockCountTest1.h @@ -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 -template class SemaphoreLockCountTest1 : - public LockerTestCase { +class SemaphoreLockCountTest1 : + public LockerTestCase { private: - typedef ThreadedTestCaller > - SemaphoreLockCountTest1Caller; - Locker thread2Lock; - Locker thread3Lock; + BLocker thread2Lock; + BLocker thread3Lock; bool CheckLockRequests(int); @@ -38,4 +35,7 @@ public: static Test *suite(void); }; -#endif \ No newline at end of file +#endif + + +