* Build fix for GCC4.
* Use CPPUNIT_ASSERT() instead of assert() in unit tests. * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39673 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,18 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2004, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2004-2010, Axel Dörfler, [email protected].
|
||||||
** Distributed under the terms of the Haiku License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "TestCase.h"
|
|
||||||
#include "ByteOrderTest.h"
|
#include "ByteOrderTest.h"
|
||||||
#include <TestUtils.h>
|
|
||||||
#include <cppunit/TestCaller.h>
|
#include <math.h>
|
||||||
#include <cppunit/TestSuite.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <ByteOrder.h>
|
#include <ByteOrder.h>
|
||||||
|
|
||||||
#include <math.h>
|
#include <cppunit/TestCaller.h>
|
||||||
|
#include <cppunit/TestSuite.h>
|
||||||
|
|
||||||
|
#include <TestUtils.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace CppUnit;
|
using namespace CppUnit;
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2004-2010, Axel Dörfler, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
#ifndef _BYTE_ORDER_TEST_H_
|
#ifndef _BYTE_ORDER_TEST_H_
|
||||||
#define _BYTE_ORDER_TEST_H_
|
#define _BYTE_ORDER_TEST_H_
|
||||||
|
|
||||||
class CppUnit::Test;
|
|
||||||
|
#include "TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test *ByteOrderTestSuite();
|
CppUnit::Test *ByteOrderTestSuite();
|
||||||
|
|
||||||
|
|
||||||
#endif // _BYTE_ORDER_TEST_H_
|
#endif // _BYTE_ORDER_TEST_H_
|
||||||
|
|||||||
@@ -12,9 +12,12 @@
|
|||||||
*/
|
*/
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "InstantiateObjectTester.h"
|
||||||
|
|
||||||
// Standard Includes -----------------------------------------------------------
|
// Standard Includes -----------------------------------------------------------
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
// System Includes -------------------------------------------------------------
|
// System Includes -------------------------------------------------------------
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
@@ -27,9 +30,10 @@
|
|||||||
|
|
||||||
// Local Includes --------------------------------------------------------------
|
// Local Includes --------------------------------------------------------------
|
||||||
#include "remoteobjectdef/RemoteTestObject.h"
|
#include "remoteobjectdef/RemoteTestObject.h"
|
||||||
#include "InstantiateObjectTester.h"
|
|
||||||
#include "LocalTestObject.h"
|
#include "LocalTestObject.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
// Local Defines ---------------------------------------------------------------
|
// Local Defines ---------------------------------------------------------------
|
||||||
#define FORMAT_AND_THROW(MSG, ERR) \
|
#define FORMAT_AND_THROW(MSG, ERR) \
|
||||||
FormatAndThrow(__LINE__, __FILE__, MSG, ERR)
|
FormatAndThrow(__LINE__, __FILE__, MSG, ERR)
|
||||||
|
|||||||
@@ -1,65 +1,42 @@
|
|||||||
//------------------------------------------------------------------------------
|
#ifndef INSTANTIATE_OBJECT_TESTER_H
|
||||||
// InstantiateObjectTester.h
|
#define INSTANTIATE_OBJECT_TESTER_H
|
||||||
//
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifndef INSTANTIATEOBJECTTESTER_H
|
|
||||||
#define INSTANTIATEOBJECTTESTER_H
|
|
||||||
|
|
||||||
// Standard Includes -----------------------------------------------------------
|
|
||||||
|
|
||||||
// System Includes -------------------------------------------------------------
|
|
||||||
|
|
||||||
// Project Includes ------------------------------------------------------------
|
|
||||||
|
|
||||||
// Local Includes --------------------------------------------------------------
|
|
||||||
#include "LocalCommon.h"
|
#include "LocalCommon.h"
|
||||||
|
|
||||||
// Local Defines ---------------------------------------------------------------
|
|
||||||
|
|
||||||
// Globals ---------------------------------------------------------------------
|
class TInstantiateObjectTester : public BTestCase {
|
||||||
|
public:
|
||||||
|
TInstantiateObjectTester(
|
||||||
|
std::string name = "");
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
void Case1();
|
||||||
class TInstantiateObjectTester : public BTestCase
|
void Case2();
|
||||||
{
|
void Case3();
|
||||||
public:
|
void Case4();
|
||||||
TInstantiateObjectTester(std::string name = "");
|
void Case5();
|
||||||
|
void Case6();
|
||||||
void Case1();
|
void Case7();
|
||||||
void Case2();
|
void Case8();
|
||||||
void Case3();
|
void Case9();
|
||||||
void Case4();
|
void Case10();
|
||||||
void Case5();
|
void Case11();
|
||||||
void Case6();
|
void Case12();
|
||||||
void Case7();
|
void Case13();
|
||||||
void Case8();
|
void Case14();
|
||||||
void Case9();
|
|
||||||
void Case10();
|
|
||||||
void Case11();
|
|
||||||
void Case12();
|
|
||||||
void Case13();
|
|
||||||
void Case14();
|
|
||||||
|
|
||||||
void RunTests();
|
void RunTests();
|
||||||
|
|
||||||
static CppUnit::Test* Suite();
|
static CppUnit::Test* Suite();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void LoadAddon();
|
void LoadAddon();
|
||||||
void UnloadAddon();
|
void UnloadAddon();
|
||||||
std::string GetLocalSignature();
|
std::string GetLocalSignature();
|
||||||
|
|
||||||
image_id fAddonId;
|
private:
|
||||||
|
image_id fAddonId;
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif //INSTANTIATEOBJECTTESTER_H
|
|
||||||
|
|
||||||
/*
|
|
||||||
* $Log $
|
|
||||||
*
|
|
||||||
* $Id $
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // INSTANTIATE_OBJECT_TESTER_H
|
||||||
|
|||||||
@@ -1,46 +1,44 @@
|
|||||||
/*
|
/*
|
||||||
$Id: BlockCacheConcurrencyTest.cpp 10124 2004-11-21 18:37:49Z shatty $
|
|
||||||
|
|
||||||
This file tests BBlockCache from multiple threads to ensure there are
|
This file tests BBlockCache from multiple threads to ensure there are
|
||||||
no concurrency problems.
|
no concurrency problems.
|
||||||
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "BlockCacheConcurrencyTest.h"
|
#include "BlockCacheConcurrencyTest.h"
|
||||||
#include "ThreadedTestCaller.h"
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <BlockCache.h>
|
#include <BlockCache.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
|
|
||||||
|
#include "ThreadedTestCaller.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method: BlockCacheConcurrencyTest::BlockCacheConcurrencyTest()
|
* Method: BlockCacheConcurrencyTest::BlockCacheConcurrencyTest()
|
||||||
* Descr: This method is the only constructor for the BlockCacheConcurrencyTest
|
* Descr: This method is the only constructor for the BlockCacheConcurrencyTest
|
||||||
* class.
|
* class.
|
||||||
*/
|
*/
|
||||||
|
BlockCacheConcurrencyTest::BlockCacheConcurrencyTest(std::string name)
|
||||||
|
:
|
||||||
BlockCacheConcurrencyTest::BlockCacheConcurrencyTest(std::string name) :
|
BThreadedTestCase(name),
|
||||||
BThreadedTestCase(name),
|
theObjCache(NULL),
|
||||||
theObjCache(NULL),
|
theMallocCache(NULL),
|
||||||
theMallocCache(NULL),
|
numBlocksInCache(128),
|
||||||
numBlocksInCache(128),
|
sizeOfBlocksInCache(23),
|
||||||
sizeOfBlocksInCache(23),
|
sizeOfNonCacheBlocks(29)
|
||||||
sizeOfNonCacheBlocks(29)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method: BlockCacheConcurrencyTest::~BlockCacheConcurrencyTest()
|
* Method: BlockCacheConcurrencyTest::~BlockCacheConcurrencyTest()
|
||||||
* Descr: This method is the destructor for the BlockCacheConcurrencyTest class.
|
* Descr: This method is the destructor for the BlockCacheConcurrencyTest class.
|
||||||
*/
|
*/
|
||||||
|
BlockCacheConcurrencyTest::~BlockCacheConcurrencyTest()
|
||||||
|
|
||||||
BlockCacheConcurrencyTest::~BlockCacheConcurrencyTest()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method: BlockCacheConcurrencyTest::setUp()
|
* Method: BlockCacheConcurrencyTest::setUp()
|
||||||
@@ -48,24 +46,22 @@
|
|||||||
* tests on. One uses new/delete and the other uses malloc/free
|
* tests on. One uses new/delete and the other uses malloc/free
|
||||||
* on its blocks.
|
* on its blocks.
|
||||||
*/
|
*/
|
||||||
|
void
|
||||||
|
BlockCacheConcurrencyTest::setUp()
|
||||||
void BlockCacheConcurrencyTest::setUp(void)
|
|
||||||
{
|
{
|
||||||
theObjCache = new BBlockCache(numBlocksInCache, sizeOfBlocksInCache,
|
theObjCache = new BBlockCache(numBlocksInCache, sizeOfBlocksInCache,
|
||||||
B_OBJECT_CACHE);
|
B_OBJECT_CACHE);
|
||||||
theMallocCache = new BBlockCache(numBlocksInCache, sizeOfBlocksInCache,
|
theMallocCache = new BBlockCache(numBlocksInCache, sizeOfBlocksInCache,
|
||||||
B_MALLOC_CACHE);
|
B_MALLOC_CACHE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method: BlockCacheConcurrencyTest::tearDown()
|
* Method: BlockCacheConcurrencyTest::tearDown()
|
||||||
* Descr: This method cleans up the BBlockCache instances which were tested.
|
* Descr: This method cleans up the BBlockCache instances which were tested.
|
||||||
*/
|
*/
|
||||||
|
void
|
||||||
|
BlockCacheConcurrencyTest::tearDown()
|
||||||
void BlockCacheConcurrencyTest::tearDown(void)
|
|
||||||
{
|
{
|
||||||
delete theObjCache;
|
delete theObjCache;
|
||||||
delete theMallocCache;
|
delete theMallocCache;
|
||||||
@@ -77,27 +73,23 @@
|
|||||||
* Descr: This method returns a pointer from the BBlockCache, checking
|
* Descr: This method returns a pointer from the BBlockCache, checking
|
||||||
* the value before passing it to the caller.
|
* the value before passing it to the caller.
|
||||||
*/
|
*/
|
||||||
|
void *
|
||||||
|
BlockCacheConcurrencyTest::GetBlock(BBlockCache *theCache, size_t blockSize,
|
||||||
void *BlockCacheConcurrencyTest::GetBlock(BBlockCache *theCache,
|
thread_id theThread, BList *cacheList, BList *nonCacheList)
|
||||||
size_t blockSize,
|
|
||||||
thread_id theThread,
|
|
||||||
BList *cacheList,
|
|
||||||
BList *nonCacheList)
|
|
||||||
{
|
{
|
||||||
void *thePtr = theCache->Get(blockSize);
|
void *thePtr = theCache->Get(blockSize);
|
||||||
|
|
||||||
// The new block should not already be used by this thread.
|
// The new block should not already be used by this thread.
|
||||||
assert(!cacheList->HasItem(thePtr));
|
CPPUNIT_ASSERT(!cacheList->HasItem(thePtr));
|
||||||
assert(!nonCacheList->HasItem(thePtr));
|
CPPUNIT_ASSERT(!nonCacheList->HasItem(thePtr));
|
||||||
|
|
||||||
// Add the block to the list of blocks used by this thread.
|
// Add the block to the list of blocks used by this thread.
|
||||||
if (blockSize == sizeOfBlocksInCache) {
|
if (blockSize == sizeOfBlocksInCache) {
|
||||||
assert(cacheList->AddItem(thePtr));
|
CPPUNIT_ASSERT(cacheList->AddItem(thePtr));
|
||||||
} else {
|
} else {
|
||||||
assert(nonCacheList->AddItem(thePtr));
|
CPPUNIT_ASSERT(nonCacheList->AddItem(thePtr));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the thread id at the start of the block for future
|
// Store the thread id at the start of the block for future
|
||||||
// reference.
|
// reference.
|
||||||
*((thread_id *)thePtr) = theThread;
|
*((thread_id *)thePtr) = theThread;
|
||||||
@@ -110,29 +102,25 @@
|
|||||||
* Descr: This method passes the pointer back to the BBlockCache
|
* Descr: This method passes the pointer back to the BBlockCache
|
||||||
* and checks the sanity of the lists.
|
* and checks the sanity of the lists.
|
||||||
*/
|
*/
|
||||||
|
void
|
||||||
|
BlockCacheConcurrencyTest::SaveBlock(BBlockCache *theCache, void *thePtr,
|
||||||
void BlockCacheConcurrencyTest::SaveBlock(BBlockCache *theCache,
|
size_t blockSize, thread_id theThread, BList *cacheList,
|
||||||
void *thePtr,
|
BList *nonCacheList)
|
||||||
size_t blockSize,
|
|
||||||
thread_id theThread,
|
|
||||||
BList *cacheList,
|
|
||||||
BList *nonCacheList)
|
|
||||||
{
|
{
|
||||||
// The block being returned to the cache should still have
|
// The block being returned to the cache should still have
|
||||||
// the thread id of this thread in it, or some other thread has
|
// the thread id of this thread in it, or some other thread has
|
||||||
// perhaps manipulated this block which would indicate a
|
// perhaps manipulated this block which would indicate a
|
||||||
// concurrency problem.
|
// concurrency problem.
|
||||||
assert(*((thread_id *)thePtr) == theThread);
|
CPPUNIT_ASSERT(*((thread_id *)thePtr) == theThread);
|
||||||
|
|
||||||
// Remove the item from the appropriate list and confirm it isn't
|
// Remove the item from the appropriate list and confirm it isn't
|
||||||
// on the other list for some reason.
|
// on the other list for some reason.
|
||||||
if (blockSize == sizeOfBlocksInCache) {
|
if (blockSize == sizeOfBlocksInCache) {
|
||||||
assert(cacheList->RemoveItem(thePtr));
|
CPPUNIT_ASSERT(cacheList->RemoveItem(thePtr));
|
||||||
assert(!nonCacheList->HasItem(thePtr));
|
CPPUNIT_ASSERT(!nonCacheList->HasItem(thePtr));
|
||||||
} else {
|
} else {
|
||||||
assert(!cacheList->HasItem(thePtr));
|
CPPUNIT_ASSERT(!cacheList->HasItem(thePtr));
|
||||||
assert(nonCacheList->RemoveItem(thePtr));
|
CPPUNIT_ASSERT(nonCacheList->RemoveItem(thePtr));
|
||||||
}
|
}
|
||||||
theCache->Save(thePtr, blockSize);
|
theCache->Save(thePtr, blockSize);
|
||||||
}
|
}
|
||||||
@@ -143,29 +131,25 @@
|
|||||||
* Descr: This method frees the block directly using delete[] or free(),
|
* Descr: This method frees the block directly using delete[] or free(),
|
||||||
* checking the sanity of the lists as it does the operation.
|
* checking the sanity of the lists as it does the operation.
|
||||||
*/
|
*/
|
||||||
|
void
|
||||||
|
BlockCacheConcurrencyTest::FreeBlock(void *thePtr, size_t blockSize,
|
||||||
void BlockCacheConcurrencyTest::FreeBlock(void *thePtr,
|
bool isMallocTest, thread_id theThread, BList *cacheList,
|
||||||
size_t blockSize,
|
BList *nonCacheList)
|
||||||
bool isMallocTest,
|
|
||||||
thread_id theThread,
|
|
||||||
BList *cacheList,
|
|
||||||
BList *nonCacheList)
|
|
||||||
{
|
{
|
||||||
// The block being returned to the cache should still have
|
// The block being returned to the cache should still have
|
||||||
// the thread id of this thread in it, or some other thread has
|
// the thread id of this thread in it, or some other thread has
|
||||||
// perhaps manipulated this block which would indicate a
|
// perhaps manipulated this block which would indicate a
|
||||||
// concurrency problem.
|
// concurrency problem.
|
||||||
assert(*((thread_id *)thePtr) == theThread);
|
CPPUNIT_ASSERT(*((thread_id *)thePtr) == theThread);
|
||||||
|
|
||||||
// Remove the item from the appropriate list and confirm it isn't
|
// Remove the item from the appropriate list and confirm it isn't
|
||||||
// on the other list for some reason.
|
// on the other list for some reason.
|
||||||
if (blockSize == sizeOfBlocksInCache) {
|
if (blockSize == sizeOfBlocksInCache) {
|
||||||
assert(cacheList->RemoveItem(thePtr));
|
CPPUNIT_ASSERT(cacheList->RemoveItem(thePtr));
|
||||||
assert(!nonCacheList->HasItem(thePtr));
|
CPPUNIT_ASSERT(!nonCacheList->HasItem(thePtr));
|
||||||
} else {
|
} else {
|
||||||
assert(!cacheList->HasItem(thePtr));
|
CPPUNIT_ASSERT(!cacheList->HasItem(thePtr));
|
||||||
assert(nonCacheList->RemoveItem(thePtr));
|
CPPUNIT_ASSERT(nonCacheList->RemoveItem(thePtr));
|
||||||
}
|
}
|
||||||
if (isMallocTest) {
|
if (isMallocTest) {
|
||||||
free(thePtr);
|
free(thePtr);
|
||||||
@@ -189,10 +173,9 @@
|
|||||||
* end of this method, all blocks unfreed by this method are
|
* end of this method, all blocks unfreed by this method are
|
||||||
* freed to avoid a memory leak.
|
* freed to avoid a memory leak.
|
||||||
*/
|
*/
|
||||||
|
void
|
||||||
|
BlockCacheConcurrencyTest::TestBlockCache(BBlockCache *theCache,
|
||||||
void BlockCacheConcurrencyTest::TestBlockCache(BBlockCache *theCache,
|
bool isMallocTest)
|
||||||
bool isMallocTest)
|
|
||||||
{
|
{
|
||||||
BList cacheList;
|
BList cacheList;
|
||||||
BList nonCacheList;
|
BList nonCacheList;
|
||||||
@@ -207,17 +190,17 @@
|
|||||||
GetBlock(theCache, sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList);
|
GetBlock(theCache, sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList);
|
||||||
GetBlock(theCache, sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList);
|
GetBlock(theCache, sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList);
|
||||||
GetBlock(theCache, sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList);
|
GetBlock(theCache, sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList);
|
||||||
|
|
||||||
SaveBlock(theCache, cacheList.ItemAt(cacheList.CountItems() / 2),
|
SaveBlock(theCache, cacheList.ItemAt(cacheList.CountItems() / 2),
|
||||||
sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList);
|
sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList);
|
||||||
SaveBlock(theCache, nonCacheList.ItemAt(nonCacheList.CountItems() / 2),
|
SaveBlock(theCache, nonCacheList.ItemAt(nonCacheList.CountItems() / 2),
|
||||||
sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList);
|
sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList);
|
||||||
|
|
||||||
GetBlock(theCache, sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList);
|
GetBlock(theCache, sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList);
|
||||||
GetBlock(theCache, sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList);
|
GetBlock(theCache, sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList);
|
||||||
GetBlock(theCache, sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList);
|
GetBlock(theCache, sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList);
|
||||||
GetBlock(theCache, sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList);
|
GetBlock(theCache, sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList);
|
||||||
|
|
||||||
FreeBlock(cacheList.ItemAt(cacheList.CountItems() / 2),
|
FreeBlock(cacheList.ItemAt(cacheList.CountItems() / 2),
|
||||||
sizeOfBlocksInCache, isMallocTest, theThread, &cacheList, &nonCacheList);
|
sizeOfBlocksInCache, isMallocTest, theThread, &cacheList, &nonCacheList);
|
||||||
FreeBlock(nonCacheList.ItemAt(nonCacheList.CountItems() / 2),
|
FreeBlock(nonCacheList.ItemAt(nonCacheList.CountItems() / 2),
|
||||||
@@ -248,29 +231,27 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method: BlockCacheConcurrencyTest::TestThreadMalloc()
|
* Method: BlockCacheConcurrencyTest::TestThreadMalloc()
|
||||||
* Descr: This method passes the BBlockCache instance to TestBlockCache()
|
* Descr: This method passes the BBlockCache instance to TestBlockCache()
|
||||||
* where the instance will be tested.
|
* where the instance will be tested.
|
||||||
*/
|
*/
|
||||||
|
void
|
||||||
|
BlockCacheConcurrencyTest::TestThreadMalloc()
|
||||||
void BlockCacheConcurrencyTest::TestThreadMalloc(void)
|
|
||||||
{
|
{
|
||||||
TestBlockCache(theMallocCache, true);
|
TestBlockCache(theMallocCache, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method: BlockCacheConcurrencyTest::TestThreadObj()
|
* Method: BlockCacheConcurrencyTest::TestThreadObj()
|
||||||
* Descr: This method passes the BBlockCache instance to TestBlockCache()
|
* Descr: This method passes the BBlockCache instance to TestBlockCache()
|
||||||
* where the instance will be tested.
|
* where the instance will be tested.
|
||||||
*/
|
*/
|
||||||
|
void
|
||||||
|
BlockCacheConcurrencyTest::TestThreadObj()
|
||||||
void BlockCacheConcurrencyTest::TestThreadObj(void)
|
|
||||||
{
|
{
|
||||||
TestBlockCache(theObjCache, false);
|
TestBlockCache(theObjCache, false);
|
||||||
}
|
}
|
||||||
@@ -278,14 +259,12 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Method: BlockCacheConcurrencyTest::suite()
|
* Method: BlockCacheConcurrencyTest::suite()
|
||||||
* Descr: This static member function returns a test caller for performing
|
* Descr: This static member function returns a test caller for performing
|
||||||
* the "BlockCacheConcurrencyTest" test. The test caller
|
* the "BlockCacheConcurrencyTest" test. The test caller
|
||||||
* is created as a ThreadedTestCaller with six independent threads.
|
* is created as a ThreadedTestCaller with six independent threads.
|
||||||
*/
|
*/
|
||||||
|
CppUnit::Test *BlockCacheConcurrencyTest::suite()
|
||||||
|
{
|
||||||
CppUnit::Test *BlockCacheConcurrencyTest::suite(void)
|
|
||||||
{
|
|
||||||
typedef BThreadedTestCaller <BlockCacheConcurrencyTest >
|
typedef BThreadedTestCaller <BlockCacheConcurrencyTest >
|
||||||
BlockCacheConcurrencyTestCaller;
|
BlockCacheConcurrencyTestCaller;
|
||||||
|
|
||||||
|
|||||||
@@ -1,44 +1,42 @@
|
|||||||
/*
|
/*
|
||||||
$Id: BlockCacheExerciseTest.cpp 10124 2004-11-21 18:37:49Z shatty $
|
|
||||||
|
|
||||||
This file tests basic functionality of BBlockCache.
|
This file tests basic functionality of BBlockCache.
|
||||||
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "BlockCacheExerciseTest.h"
|
#include "BlockCacheExerciseTest.h"
|
||||||
#include "cppunit/TestCaller.h"
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <BlockCache.h>
|
#include <BlockCache.h>
|
||||||
|
|
||||||
|
#include "cppunit/TestCaller.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method: BlockCacheExerciseTest::BlockCacheExerciseTest()
|
* Method: BlockCacheExerciseTest::BlockCacheExerciseTest()
|
||||||
* Descr: This method is the only constructor for the BlockCacheExerciseTest
|
* Descr: This method is the only constructor for the BlockCacheExerciseTest
|
||||||
* class.
|
* class.
|
||||||
*/
|
*/
|
||||||
|
BlockCacheExerciseTest::BlockCacheExerciseTest(std::string name)
|
||||||
|
:
|
||||||
BlockCacheExerciseTest::BlockCacheExerciseTest(std::string name) :
|
TestCase(name),
|
||||||
TestCase(name),
|
theCache(NULL),
|
||||||
theCache(NULL),
|
numBlocksInCache(0),
|
||||||
numBlocksInCache(0),
|
sizeOfBlocksInCache(0),
|
||||||
sizeOfBlocksInCache(0),
|
sizeOfNonCacheBlocks(0),
|
||||||
sizeOfNonCacheBlocks(0),
|
isMallocTest(false)
|
||||||
isMallocTest(false)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method: BlockCacheExerciseTest::~BlockCacheExerciseTest()
|
* Method: BlockCacheExerciseTest::~BlockCacheExerciseTest()
|
||||||
* Descr: This method is the destructor for the BlockCacheExerciseTest class.
|
* Descr: This method is the destructor for the BlockCacheExerciseTest class.
|
||||||
*/
|
*/
|
||||||
|
BlockCacheExerciseTest::~BlockCacheExerciseTest()
|
||||||
|
|
||||||
BlockCacheExerciseTest::~BlockCacheExerciseTest()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method: BlockCacheExerciseTest::TestBlockCache()
|
* Method: BlockCacheExerciseTest::TestBlockCache()
|
||||||
@@ -88,9 +86,8 @@
|
|||||||
*
|
*
|
||||||
* The sum total of these actions test the BBlockCache.
|
* The sum total of these actions test the BBlockCache.
|
||||||
*/
|
*/
|
||||||
|
void
|
||||||
|
BlockCacheExerciseTest::TestBlockCache(void)
|
||||||
void BlockCacheExerciseTest::TestBlockCache(void)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
// First get all items from the cache plus ten more
|
// First get all items from the cache plus ten more
|
||||||
@@ -146,10 +143,10 @@
|
|||||||
sizeOfBlocksInCache);
|
sizeOfBlocksInCache);
|
||||||
FreeBlock(nonCacheList.ItemAt(nonCacheList.CountItems() / 3),
|
FreeBlock(nonCacheList.ItemAt(nonCacheList.CountItems() / 3),
|
||||||
sizeOfNonCacheBlocks);
|
sizeOfNonCacheBlocks);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Method: BlockCacheExerciseTest::BuildLists()
|
* Method: BlockCacheExerciseTest::BuildLists()
|
||||||
* Descr: This method gets all of the blocks from the cache in order to
|
* Descr: This method gets all of the blocks from the cache in order to
|
||||||
@@ -159,9 +156,8 @@
|
|||||||
* access allocated memory without resorting to malloc()'s or new's,
|
* access allocated memory without resorting to malloc()'s or new's,
|
||||||
* this should be a fair assumption.
|
* this should be a fair assumption.
|
||||||
*/
|
*/
|
||||||
|
void
|
||||||
|
BlockCacheExerciseTest::BuildLists()
|
||||||
void BlockCacheExerciseTest::BuildLists(void)
|
|
||||||
{
|
{
|
||||||
freeList.MakeEmpty();
|
freeList.MakeEmpty();
|
||||||
usedList.MakeEmpty();
|
usedList.MakeEmpty();
|
||||||
@@ -181,31 +177,30 @@
|
|||||||
* Descr: This method returns a pointer from the BBlockCache, checking
|
* Descr: This method returns a pointer from the BBlockCache, checking
|
||||||
* the value before passing it to the caller.
|
* the value before passing it to the caller.
|
||||||
*/
|
*/
|
||||||
|
void *
|
||||||
|
BlockCacheExerciseTest::GetBlock(size_t blockSize)
|
||||||
void *BlockCacheExerciseTest::GetBlock(size_t blockSize)
|
|
||||||
{
|
{
|
||||||
void *thePtr = theCache->Get(blockSize);
|
void *thePtr = theCache->Get(blockSize);
|
||||||
|
|
||||||
// This new pointer should not be one which we already
|
// This new pointer should not be one which we already
|
||||||
// have from the BBlockCache which we haven't given back
|
// have from the BBlockCache which we haven't given back
|
||||||
// yet.
|
// yet.
|
||||||
assert(!usedList.HasItem(thePtr));
|
CPPUNIT_ASSERT(!usedList.HasItem(thePtr));
|
||||||
assert(!nonCacheList.HasItem(thePtr));
|
CPPUNIT_ASSERT(!nonCacheList.HasItem(thePtr));
|
||||||
|
|
||||||
if (blockSize == sizeOfBlocksInCache) {
|
if (blockSize == sizeOfBlocksInCache) {
|
||||||
// If this block was one which could have come from the
|
// If this block was one which could have come from the
|
||||||
// cache and there are free items on the cache, it
|
// cache and there are free items on the cache, it
|
||||||
// should be one of those free blocks.
|
// should be one of those free blocks.
|
||||||
if (freeList.CountItems() > 0) {
|
if (freeList.CountItems() > 0) {
|
||||||
assert(freeList.RemoveItem(thePtr));
|
CPPUNIT_ASSERT(freeList.RemoveItem(thePtr));
|
||||||
}
|
}
|
||||||
assert(usedList.AddItem(thePtr));
|
CPPUNIT_ASSERT(usedList.AddItem(thePtr));
|
||||||
} else {
|
} else {
|
||||||
// A "non-cache sized" block should never come from the
|
// A "non-cache sized" block should never come from the
|
||||||
// free list.
|
// free list.
|
||||||
assert(!freeList.HasItem(thePtr));
|
CPPUNIT_ASSERT(!freeList.HasItem(thePtr));
|
||||||
assert(nonCacheList.AddItem(thePtr));
|
CPPUNIT_ASSERT(nonCacheList.AddItem(thePtr));
|
||||||
}
|
}
|
||||||
return(thePtr);
|
return(thePtr);
|
||||||
}
|
}
|
||||||
@@ -216,13 +211,12 @@
|
|||||||
* Descr: This method passes the pointer back to the BBlockCache
|
* Descr: This method passes the pointer back to the BBlockCache
|
||||||
* and checks the sanity of the lists.
|
* and checks the sanity of the lists.
|
||||||
*/
|
*/
|
||||||
|
void
|
||||||
|
BlockCacheExerciseTest::SaveBlock(void *thePtr, size_t blockSize)
|
||||||
void BlockCacheExerciseTest::SaveBlock(void *thePtr, size_t blockSize)
|
|
||||||
{
|
{
|
||||||
// The memory block being returned to the cache should
|
// The memory block being returned to the cache should
|
||||||
// not already be free.
|
// not already be free.
|
||||||
assert(!freeList.HasItem(thePtr));
|
CPPUNIT_ASSERT(!freeList.HasItem(thePtr));
|
||||||
|
|
||||||
if (blockSize == sizeOfBlocksInCache) {
|
if (blockSize == sizeOfBlocksInCache) {
|
||||||
// If there is room on the free list, when this block
|
// If there is room on the free list, when this block
|
||||||
@@ -230,18 +224,18 @@
|
|||||||
// free list. Therefore we will also track it as
|
// free list. Therefore we will also track it as
|
||||||
// a free block on the cache.
|
// a free block on the cache.
|
||||||
if (freeList.CountItems() < numBlocksInCache) {
|
if (freeList.CountItems() < numBlocksInCache) {
|
||||||
assert(freeList.AddItem(thePtr));
|
CPPUNIT_ASSERT(freeList.AddItem(thePtr));
|
||||||
}
|
}
|
||||||
|
|
||||||
// This block should not be on the non-cache list but it
|
// This block should not be on the non-cache list but it
|
||||||
// should be on the used list.
|
// should be on the used list.
|
||||||
assert(!nonCacheList.HasItem(thePtr));
|
CPPUNIT_ASSERT(!nonCacheList.HasItem(thePtr));
|
||||||
assert(usedList.RemoveItem(thePtr));
|
CPPUNIT_ASSERT(usedList.RemoveItem(thePtr));
|
||||||
} else {
|
} else {
|
||||||
// This block should not be on the used list but it should
|
// This block should not be on the used list but it should
|
||||||
// be on the non-cache list.
|
// be on the non-cache list.
|
||||||
assert(!usedList.HasItem(thePtr));
|
CPPUNIT_ASSERT(!usedList.HasItem(thePtr));
|
||||||
assert(nonCacheList.RemoveItem(thePtr));
|
CPPUNIT_ASSERT(nonCacheList.RemoveItem(thePtr));
|
||||||
}
|
}
|
||||||
theCache->Save(thePtr, blockSize);
|
theCache->Save(thePtr, blockSize);
|
||||||
}
|
}
|
||||||
@@ -252,24 +246,23 @@
|
|||||||
* Descr: This method frees the block directly using delete[] or free(),
|
* Descr: This method frees the block directly using delete[] or free(),
|
||||||
* checking the sanity of the lists as it does the operation.
|
* checking the sanity of the lists as it does the operation.
|
||||||
*/
|
*/
|
||||||
|
void
|
||||||
|
BlockCacheExerciseTest::FreeBlock(void *thePtr, size_t blockSize)
|
||||||
void BlockCacheExerciseTest::FreeBlock(void *thePtr, size_t blockSize)
|
|
||||||
{
|
{
|
||||||
// The block being freed should not already have been
|
// The block being freed should not already have been
|
||||||
// returned to the cache.
|
// returned to the cache.
|
||||||
assert(!freeList.HasItem(thePtr));
|
CPPUNIT_ASSERT(!freeList.HasItem(thePtr));
|
||||||
|
|
||||||
if (blockSize == sizeOfBlocksInCache) {
|
if (blockSize == sizeOfBlocksInCache) {
|
||||||
// This block should not be on the non-cache list but it
|
// This block should not be on the non-cache list but it
|
||||||
// should be on the used list.
|
// should be on the used list.
|
||||||
assert(!nonCacheList.HasItem(thePtr));
|
CPPUNIT_ASSERT(!nonCacheList.HasItem(thePtr));
|
||||||
assert(usedList.RemoveItem(thePtr));
|
CPPUNIT_ASSERT(usedList.RemoveItem(thePtr));
|
||||||
} else {
|
} else {
|
||||||
// This block should not be on the used list but it should
|
// This block should not be on the used list but it should
|
||||||
// be on the non-cache list.
|
// be on the non-cache list.
|
||||||
assert(!usedList.HasItem(thePtr));
|
CPPUNIT_ASSERT(!usedList.HasItem(thePtr));
|
||||||
assert(nonCacheList.RemoveItem(thePtr));
|
CPPUNIT_ASSERT(nonCacheList.RemoveItem(thePtr));
|
||||||
}
|
}
|
||||||
if (isMallocTest) {
|
if (isMallocTest) {
|
||||||
free(thePtr);
|
free(thePtr);
|
||||||
@@ -292,9 +285,8 @@
|
|||||||
* 3. Frees all blocks left after the test to prevent
|
* 3. Frees all blocks left after the test to prevent
|
||||||
* memory leaks.
|
* memory leaks.
|
||||||
*/
|
*/
|
||||||
|
void
|
||||||
|
BlockCacheExerciseTest::PerformTest(void)
|
||||||
void BlockCacheExerciseTest::PerformTest(void)
|
|
||||||
{
|
{
|
||||||
for (numBlocksInCache = 8; numBlocksInCache < 513; numBlocksInCache *= 2) {
|
for (numBlocksInCache = 8; numBlocksInCache < 513; numBlocksInCache *= 2) {
|
||||||
for (sizeOfBlocksInCache = 13; sizeOfBlocksInCache < 9478; sizeOfBlocksInCache *= 3) {
|
for (sizeOfBlocksInCache = 13; sizeOfBlocksInCache < 9478; sizeOfBlocksInCache *= 3) {
|
||||||
@@ -306,7 +298,7 @@
|
|||||||
|
|
||||||
isMallocTest = false;
|
isMallocTest = false;
|
||||||
theCache = new BBlockCache(numBlocksInCache, sizeOfBlocksInCache, B_OBJECT_CACHE);
|
theCache = new BBlockCache(numBlocksInCache, sizeOfBlocksInCache, B_OBJECT_CACHE);
|
||||||
assert(theCache != NULL);
|
CPPUNIT_ASSERT(theCache != NULL);
|
||||||
|
|
||||||
// Query the cache and determine the blocks in it.
|
// Query the cache and determine the blocks in it.
|
||||||
BuildLists();
|
BuildLists();
|
||||||
@@ -323,7 +315,7 @@
|
|||||||
|
|
||||||
isMallocTest = true;
|
isMallocTest = true;
|
||||||
theCache = new BBlockCache(numBlocksInCache, sizeOfBlocksInCache, B_MALLOC_CACHE);
|
theCache = new BBlockCache(numBlocksInCache, sizeOfBlocksInCache, B_MALLOC_CACHE);
|
||||||
assert(theCache != NULL);
|
CPPUNIT_ASSERT(theCache != NULL);
|
||||||
|
|
||||||
// Query the cache and determine the blocks in it.
|
// Query the cache and determine the blocks in it.
|
||||||
BuildLists();
|
BuildLists();
|
||||||
@@ -347,9 +339,7 @@
|
|||||||
* Descr: This static member function returns a test caller for performing
|
* Descr: This static member function returns a test caller for performing
|
||||||
* the "BlockCacheExerciseTest" test.
|
* the "BlockCacheExerciseTest" test.
|
||||||
*/
|
*/
|
||||||
|
CppUnit::Test *BlockCacheExerciseTest::suite()
|
||||||
|
|
||||||
CppUnit::Test *BlockCacheExerciseTest::suite(void)
|
|
||||||
{
|
{
|
||||||
typedef CppUnit::TestCaller<BlockCacheExerciseTest>
|
typedef CppUnit::TestCaller<BlockCacheExerciseTest>
|
||||||
BlockCacheExerciseTestCaller;
|
BlockCacheExerciseTestCaller;
|
||||||
|
|||||||
@@ -22,12 +22,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <ThreadedTestCaller.h>
|
|
||||||
#include "BenaphoreLockCountTest1.h"
|
#include "BenaphoreLockCountTest1.h"
|
||||||
|
|
||||||
#include <cppunit/Test.h>
|
#include <cppunit/Test.h>
|
||||||
#include <cppunit/TestSuite.h>
|
#include <cppunit/TestSuite.h>
|
||||||
|
|
||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
|
|
||||||
|
#include <ThreadedTestCaller.h>
|
||||||
|
|
||||||
|
|
||||||
// This constant is used to determine the number of microseconds to
|
// This constant is used to determine the number of microseconds to
|
||||||
// sleep during major steps of the test.
|
// sleep during major steps of the test.
|
||||||
@@ -91,38 +94,38 @@ void BenaphoreLockCountTest1::TestThread1(void)
|
|||||||
SafetyLock theSafetyLock2(&thread2Lock);
|
SafetyLock theSafetyLock2(&thread2Lock);
|
||||||
SafetyLock theSafetyLock3(&thread3Lock);
|
SafetyLock theSafetyLock3(&thread3Lock);
|
||||||
|
|
||||||
assert(thread2Lock.Lock());
|
CPPUNIT_ASSERT(thread2Lock.Lock());
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(thread3Lock.Lock());
|
CPPUNIT_ASSERT(thread3Lock.Lock());
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
|
|
||||||
assert(CheckLockRequests(0));
|
CPPUNIT_ASSERT(CheckLockRequests(0));
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(theLocker->Lock());
|
CPPUNIT_ASSERT(theLocker->Lock());
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
|
|
||||||
assert(CheckLockRequests(1));
|
CPPUNIT_ASSERT(CheckLockRequests(1));
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
|
|
||||||
thread2Lock.Unlock();
|
thread2Lock.Unlock();
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
snooze(SNOOZE_TIME);
|
snooze(SNOOZE_TIME);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(CheckLockRequests(3));
|
CPPUNIT_ASSERT(CheckLockRequests(3));
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
|
|
||||||
thread3Lock.Unlock();
|
thread3Lock.Unlock();
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
snooze(SNOOZE_TIME);
|
snooze(SNOOZE_TIME);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(CheckLockRequests(5));
|
CPPUNIT_ASSERT(CheckLockRequests(5));
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
|
|
||||||
theLocker->Unlock();
|
theLocker->Unlock();
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
snooze(SNOOZE_TIME);
|
snooze(SNOOZE_TIME);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(CheckLockRequests(2));
|
CPPUNIT_ASSERT(CheckLockRequests(2));
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,16 +146,16 @@ void BenaphoreLockCountTest1::TestThread2(void)
|
|||||||
|
|
||||||
snooze(SNOOZE_TIME / 10);
|
snooze(SNOOZE_TIME / 10);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(thread2Lock.Lock());
|
CPPUNIT_ASSERT(thread2Lock.Lock());
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
|
|
||||||
assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
|
CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(theLocker->Lock());
|
CPPUNIT_ASSERT(theLocker->Lock());
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
int actual = theLocker->CountLockRequests();
|
int actual = theLocker->CountLockRequests();
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert((actual == 3) || (actual == 4));
|
CPPUNIT_ASSERT((actual == 3) || (actual == 4));
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
theLocker->Unlock();
|
theLocker->Unlock();
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
@@ -175,16 +178,16 @@ void BenaphoreLockCountTest1::TestThread3(void)
|
|||||||
|
|
||||||
snooze(SNOOZE_TIME / 10);
|
snooze(SNOOZE_TIME / 10);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(thread3Lock.Lock());
|
CPPUNIT_ASSERT(thread3Lock.Lock());
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
|
|
||||||
assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
|
CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(theLocker->Lock());
|
CPPUNIT_ASSERT(theLocker->Lock());
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
int actual = theLocker->CountLockRequests();
|
int actual = theLocker->CountLockRequests();
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert((actual == 3) || (actual == 4));
|
CPPUNIT_ASSERT((actual == 3) || (actual == 4));
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
theLocker->Unlock();
|
theLocker->Unlock();
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
|
|||||||
@@ -11,10 +11,10 @@
|
|||||||
#define BenaphoreLockCountTest1_H
|
#define BenaphoreLockCountTest1_H
|
||||||
|
|
||||||
|
|
||||||
#include "LockerTestCase.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class CppUnit::Test;
|
#include "LockerTestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class BenaphoreLockCountTest1 : public LockerTestCase {
|
class BenaphoreLockCountTest1 : public LockerTestCase {
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -166,19 +166,19 @@ void ConcurrencyTest1::TestThread(void)
|
|||||||
NextSubTest();
|
NextSubTest();
|
||||||
|
|
||||||
CheckLock(0);
|
CheckLock(0);
|
||||||
assert(AcquireLock(i, true));
|
CPPUNIT_ASSERT(AcquireLock(i, true));
|
||||||
|
|
||||||
assert(!lockTestValue);
|
CPPUNIT_ASSERT(!lockTestValue);
|
||||||
lockTestValue = true;
|
lockTestValue = true;
|
||||||
CheckLock(1);
|
CheckLock(1);
|
||||||
|
|
||||||
assert(AcquireLock(i, false));
|
CPPUNIT_ASSERT(AcquireLock(i, false));
|
||||||
CheckLock(2);
|
CheckLock(2);
|
||||||
|
|
||||||
theLocker->Unlock();
|
theLocker->Unlock();
|
||||||
CheckLock(1);
|
CheckLock(1);
|
||||||
|
|
||||||
assert(lockTestValue);
|
CPPUNIT_ASSERT(lockTestValue);
|
||||||
lockTestValue = false;
|
lockTestValue = false;
|
||||||
theLocker->Unlock();
|
theLocker->Unlock();
|
||||||
CheckLock(0);
|
CheckLock(0);
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ void ConcurrencyTest2::AcquireThread(void)
|
|||||||
{
|
{
|
||||||
SafetyLock theSafetyLock(theLocker);
|
SafetyLock theSafetyLock(theLocker);
|
||||||
|
|
||||||
assert(theLocker->Lock());
|
CPPUNIT_ASSERT(theLocker->Lock());
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
snooze(SNOOZE_TIME);
|
snooze(SNOOZE_TIME);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
@@ -171,7 +171,7 @@ void ConcurrencyTest2::TimeoutThread(void)
|
|||||||
|
|
||||||
snooze(SNOOZE_TIME/2);
|
snooze(SNOOZE_TIME/2);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(theLocker->LockWithTimeout(SNOOZE_TIME/10) == B_TIMED_OUT);
|
CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME/10) == B_TIMED_OUT);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
LockingLoop();
|
LockingLoop();
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
@@ -209,19 +209,19 @@ void ConcurrencyTest2::LockingLoop(void)
|
|||||||
|
|
||||||
for (i = 0; i < MAXLOOP; i++) {
|
for (i = 0; i < MAXLOOP; i++) {
|
||||||
CheckLock(0);
|
CheckLock(0);
|
||||||
assert(AcquireLock(i, true));
|
CPPUNIT_ASSERT(AcquireLock(i, true));
|
||||||
|
|
||||||
assert(!lockTestValue);
|
CPPUNIT_ASSERT(!lockTestValue);
|
||||||
lockTestValue = true;
|
lockTestValue = true;
|
||||||
CheckLock(1);
|
CheckLock(1);
|
||||||
|
|
||||||
assert(AcquireLock(i, false));
|
CPPUNIT_ASSERT(AcquireLock(i, false));
|
||||||
CheckLock(2);
|
CheckLock(2);
|
||||||
|
|
||||||
theLocker->Unlock();
|
theLocker->Unlock();
|
||||||
CheckLock(1);
|
CheckLock(1);
|
||||||
|
|
||||||
assert(lockTestValue);
|
CPPUNIT_ASSERT(lockTestValue);
|
||||||
lockTestValue = false;
|
lockTestValue = false;
|
||||||
theLocker->Unlock();
|
theLocker->Unlock();
|
||||||
CheckLock(0);
|
CheckLock(0);
|
||||||
|
|||||||
@@ -13,10 +13,8 @@
|
|||||||
|
|
||||||
#include "LockerTestCase.h"
|
#include "LockerTestCase.h"
|
||||||
|
|
||||||
class CppUnit::Test;
|
|
||||||
|
|
||||||
class ConcurrencyTest2 : public LockerTestCase {
|
class ConcurrencyTest2 : public LockerTestCase {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool lockTestValue;
|
bool lockTestValue;
|
||||||
|
|
||||||
@@ -31,9 +29,7 @@ public:
|
|||||||
void AcquireThread(void);
|
void AcquireThread(void);
|
||||||
void TimeoutThread(void);
|
void TimeoutThread(void);
|
||||||
static CppUnit::Test *suite(void);
|
static CppUnit::Test *suite(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,13 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "ConstructionTest1.h"
|
#include "ConstructionTest1.h"
|
||||||
#include <cppunit/TestCaller.h>
|
|
||||||
#include <OS.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
|
#include <OS.h>
|
||||||
|
|
||||||
|
#include <cppunit/TestCaller.h>
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -51,7 +55,7 @@ bool
|
|||||||
{
|
{
|
||||||
sem_info theSemInfo;
|
sem_info theSemInfo;
|
||||||
|
|
||||||
assert(get_sem_info(lockerArg->Sem(), &theSemInfo) == B_OK);
|
CPPUNIT_ASSERT(get_sem_info(lockerArg->Sem(), &theSemInfo) == B_OK);
|
||||||
return(strcmp(name, theSemInfo.name) == 0);
|
return(strcmp(name, theSemInfo.name) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +73,7 @@ bool
|
|||||||
{
|
{
|
||||||
int32 semCount;
|
int32 semCount;
|
||||||
|
|
||||||
assert(get_sem_count(lockerArg->Sem(), &semCount) == B_OK);
|
CPPUNIT_ASSERT(get_sem_count(lockerArg->Sem(), &semCount) == B_OK);
|
||||||
switch (semCount) {
|
switch (semCount) {
|
||||||
case 0: return(true);
|
case 0: return(true);
|
||||||
break;
|
break;
|
||||||
@@ -79,7 +83,7 @@ bool
|
|||||||
// This should not happen. The semaphore count should be
|
// This should not happen. The semaphore count should be
|
||||||
// 0 for a benaphore, 1 for a semaphore. No other value
|
// 0 for a benaphore, 1 for a semaphore. No other value
|
||||||
// is legal in this case.
|
// is legal in this case.
|
||||||
assert(false);
|
CPPUNIT_ASSERT(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return(false);
|
return(false);
|
||||||
@@ -96,33 +100,33 @@ bool
|
|||||||
void ConstructionTest1::PerformTest(void)
|
void ConstructionTest1::PerformTest(void)
|
||||||
{
|
{
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(NameMatches("some BLocker", theLocker));
|
CPPUNIT_ASSERT(NameMatches("some BLocker", theLocker));
|
||||||
assert(IsBenaphore(theLocker));
|
CPPUNIT_ASSERT(IsBenaphore(theLocker));
|
||||||
|
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
BLocker locker1("test string");
|
BLocker locker1("test string");
|
||||||
assert(NameMatches("test string", &locker1));
|
CPPUNIT_ASSERT(NameMatches("test string", &locker1));
|
||||||
assert(IsBenaphore(&locker1));
|
CPPUNIT_ASSERT(IsBenaphore(&locker1));
|
||||||
|
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
BLocker locker2(false);
|
BLocker locker2(false);
|
||||||
assert(NameMatches("some BLocker", &locker2));
|
CPPUNIT_ASSERT(NameMatches("some BLocker", &locker2));
|
||||||
assert(!IsBenaphore(&locker2));
|
CPPUNIT_ASSERT(!IsBenaphore(&locker2));
|
||||||
|
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
BLocker locker3(true);
|
BLocker locker3(true);
|
||||||
assert(NameMatches("some BLocker", &locker3));
|
CPPUNIT_ASSERT(NameMatches("some BLocker", &locker3));
|
||||||
assert(IsBenaphore(&locker3));
|
CPPUNIT_ASSERT(IsBenaphore(&locker3));
|
||||||
|
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
BLocker locker4("test string", false);
|
BLocker locker4("test string", false);
|
||||||
assert(NameMatches("test string", &locker4));
|
CPPUNIT_ASSERT(NameMatches("test string", &locker4));
|
||||||
assert(!IsBenaphore(&locker4));
|
CPPUNIT_ASSERT(!IsBenaphore(&locker4));
|
||||||
|
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
BLocker locker5("test string", true);
|
BLocker locker5("test string", true);
|
||||||
assert(NameMatches("test string", &locker5));
|
CPPUNIT_ASSERT(NameMatches("test string", &locker5));
|
||||||
assert(IsBenaphore(&locker5));
|
CPPUNIT_ASSERT(IsBenaphore(&locker5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ const bigtime_t SNOOZE_TIME = 200000;
|
|||||||
|
|
||||||
void DestructionTest1::TestThread1(void)
|
void DestructionTest1::TestThread1(void)
|
||||||
{
|
{
|
||||||
assert(theLocker->Lock());
|
CPPUNIT_ASSERT(theLocker->Lock());
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
snooze(SNOOZE_TIME);
|
snooze(SNOOZE_TIME);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
@@ -71,7 +71,7 @@ void DestructionTest1::TestThread1(void)
|
|||||||
NextSubTest();
|
NextSubTest();
|
||||||
snooze(SNOOZE_TIME);
|
snooze(SNOOZE_TIME);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(!theLocker->Lock());
|
CPPUNIT_ASSERT(!theLocker->Lock());
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ void DestructionTest1::TestThread2(void)
|
|||||||
|
|
||||||
snooze(SNOOZE_TIME);
|
snooze(SNOOZE_TIME);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(theLocker->Lock());
|
CPPUNIT_ASSERT(theLocker->Lock());
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
snooze(SNOOZE_TIME);
|
snooze(SNOOZE_TIME);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ const bigtime_t SNOOZE_TIME = 200000;
|
|||||||
|
|
||||||
void DestructionTest2::TestThread1(void)
|
void DestructionTest2::TestThread1(void)
|
||||||
{
|
{
|
||||||
assert(theLocker->LockWithTimeout(SNOOZE_TIME) == B_OK);
|
CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME) == B_OK);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
snooze(SNOOZE_TIME);
|
snooze(SNOOZE_TIME);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
@@ -73,7 +73,7 @@ void DestructionTest2::TestThread1(void)
|
|||||||
NextSubTest();
|
NextSubTest();
|
||||||
snooze(SNOOZE_TIME);
|
snooze(SNOOZE_TIME);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(theLocker->LockWithTimeout(SNOOZE_TIME * 10) == B_BAD_SEM_ID);
|
CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME * 10) == B_BAD_SEM_ID);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,9 +93,9 @@ void DestructionTest2::TestThread2(void)
|
|||||||
|
|
||||||
snooze(SNOOZE_TIME/10);
|
snooze(SNOOZE_TIME/10);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
|
CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(theLocker->LockWithTimeout(SNOOZE_TIME * 10) == B_OK);
|
CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME * 10) == B_OK);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
snooze(SNOOZE_TIME);
|
snooze(SNOOZE_TIME);
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
|
|||||||
@@ -60,11 +60,11 @@ void LockerTestCase::CheckLock(int expectedCount)
|
|||||||
int32 actualCount = theLocker->CountLocks();
|
int32 actualCount = theLocker->CountLocks();
|
||||||
|
|
||||||
if (expectedCount > 0) {
|
if (expectedCount > 0) {
|
||||||
assert(isLocked);
|
CPPUNIT_ASSERT(isLocked);
|
||||||
assert(expectedThread == actualThread);
|
CPPUNIT_ASSERT(expectedThread == actualThread);
|
||||||
assert(expectedCount == actualCount);
|
CPPUNIT_ASSERT(expectedCount == actualCount);
|
||||||
} else {
|
} else {
|
||||||
assert(!((isLocked) && (actualThread == expectedThread)));
|
CPPUNIT_ASSERT(!((isLocked) && (actualThread == expectedThread)));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,30 +91,30 @@ void SemaphoreLockCountTest1::TestThread1(void)
|
|||||||
SafetyLock theSafetyLock3(&thread3Lock);
|
SafetyLock theSafetyLock3(&thread3Lock);
|
||||||
|
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(thread2Lock.Lock());
|
CPPUNIT_ASSERT(thread2Lock.Lock());
|
||||||
assert(thread3Lock.Lock());
|
CPPUNIT_ASSERT(thread3Lock.Lock());
|
||||||
|
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(CheckLockRequests(1));
|
CPPUNIT_ASSERT(CheckLockRequests(1));
|
||||||
assert(theLocker->Lock());
|
CPPUNIT_ASSERT(theLocker->Lock());
|
||||||
|
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(CheckLockRequests(2));
|
CPPUNIT_ASSERT(CheckLockRequests(2));
|
||||||
|
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
thread2Lock.Unlock();
|
thread2Lock.Unlock();
|
||||||
snooze(SNOOZE_TIME);
|
snooze(SNOOZE_TIME);
|
||||||
assert(CheckLockRequests(4));
|
CPPUNIT_ASSERT(CheckLockRequests(4));
|
||||||
|
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
thread3Lock.Unlock();
|
thread3Lock.Unlock();
|
||||||
snooze(SNOOZE_TIME);
|
snooze(SNOOZE_TIME);
|
||||||
assert(CheckLockRequests(6));
|
CPPUNIT_ASSERT(CheckLockRequests(6));
|
||||||
|
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
theLocker->Unlock();
|
theLocker->Unlock();
|
||||||
snooze(SNOOZE_TIME);
|
snooze(SNOOZE_TIME);
|
||||||
assert(CheckLockRequests(3));
|
CPPUNIT_ASSERT(CheckLockRequests(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -134,13 +134,13 @@ void SemaphoreLockCountTest1::TestThread2(void)
|
|||||||
|
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
snooze(SNOOZE_TIME / 10);
|
snooze(SNOOZE_TIME / 10);
|
||||||
assert(thread2Lock.Lock());
|
CPPUNIT_ASSERT(thread2Lock.Lock());
|
||||||
|
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
|
CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
|
||||||
assert(theLocker->Lock());
|
CPPUNIT_ASSERT(theLocker->Lock());
|
||||||
int actual = theLocker->CountLockRequests();
|
int actual = theLocker->CountLockRequests();
|
||||||
assert((actual == 4) || (actual == 5));
|
CPPUNIT_ASSERT((actual == 4) || (actual == 5));
|
||||||
theLocker->Unlock();
|
theLocker->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,13 +161,13 @@ void SemaphoreLockCountTest1::TestThread3(void)
|
|||||||
|
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
snooze(SNOOZE_TIME / 10);
|
snooze(SNOOZE_TIME / 10);
|
||||||
assert(thread3Lock.Lock());
|
CPPUNIT_ASSERT(thread3Lock.Lock());
|
||||||
|
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
|
CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT);
|
||||||
assert(theLocker->Lock());
|
CPPUNIT_ASSERT(theLocker->Lock());
|
||||||
int actual = theLocker->CountLockRequests();
|
int actual = theLocker->CountLockRequests();
|
||||||
assert((actual == 4) || (actual == 5));
|
CPPUNIT_ASSERT((actual == 4) || (actual == 5));
|
||||||
theLocker->Unlock();
|
theLocker->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user