TestBase Class Reference

TestBase is the common base for all Fennel tests. More...

#include <TestBase.h>

Inheritance diagram for TestBase:

TraceTarget BacktraceTest CacheTestBase CalcAssemblerTest CalcCastTest CalcExtCastTest CalcExtContextTest CalcExtDateTimeTest CalcExtDynamicVariableTest CalcExtMathTest CalcExtRegExpTest CalcExtStringTest CalcExtWinAggFuncTest CalcInstFactoryTest CalcMiscTest DatabaseTest LocalConditionTest PseudoUuidTest RandomAccessFileDeviceTest ResourceTest SparseBitmapTest SqlDateTest SqlRegExpTest SqlStringAsciiTest SqlStringTest SqlStringTest StandardTypeTest TestOptionsTest ThreadedTestBase TupleTest List of all members.

Public Member Functions

 TestBase ()
virtual ~TestBase ()
TestSuitereleaseTestSuite ()
void beforeTestCase (std::string testCaseName)
void afterTestCase (std::string testCaseName)
virtual void testCaseSetUp ()
 Equivalent to JUnit TestCase.setUp; this is called before each test case method is invoked.
virtual void testCaseTearDown ()
 Equivalent to JUnit TestCase.tearDown; this is called after each test case method is invoked.
virtual void notifyTrace (std::string source, TraceLevel level, std::string message)
 Receives notification when a trace event occurs.
virtual TraceLevel getSourceTraceLevel (std::string source)
 Gets the level at which a particular source should be traced.

Static Public Member Functions

static void readParams (int argc, char **argv)
 Parses the command line.

Static Public Attributes

static ParamName paramTestSuiteName
static ParamName paramTraceFileName
static ParamName paramDictionaryFileName
static ParamName paramTraceLevel
static ParamName paramStatsFileName
static ParamName paramTraceStdout
static ParamName paramDegreeOfParallelism
static ConfigMap configMap
 Configuration parameters.

Protected Member Functions

void snooze (uint nSeconds)

Protected Attributes

TestSuitepTestSuite
 Boost test suite.
boost::shared_ptr< TestBasepTestObj
std::ofstream traceStream
 Output file stream for tracing.
StrictMutex traceMutex
 Protects traceStream.
std::string testName
 Name of test.
TraceLevel traceLevel
 Level at which to trace test execution.
FileStatsTarget statsTarget
 Output for stats.
StatsTimer statsTimer
 Timer for stats collection.
bool traceStdout
 Copy trace output to stdout.
bool traceFile
 Copy trace output to file.
TestCaseGroup defaultTests
TestCaseGroup extraTests

Static Protected Attributes

static bool runAll
 Run all test cases, including the extra tests.
static std::string runSingle
 Run only the test case of this name.

Classes

class  TestCaseGroup
 Collects a group of named test-case definitions. More...

Detailed Description

TestBase is the common base for all Fennel tests.

Definition at line 50 of file TestBase.h.


Constructor & Destructor Documentation

TestBase::TestBase (  )  [explicit]

Definition at line 45 of file TestBase.cpp.

References configMap, ConfigMap::getIntParam(), ConfigMap::getStringParam(), TraceSource::initTraceSource(), paramTestSuiteName, paramTraceFileName, paramTraceLevel, paramTraceStdout, pTestObj, testName, TRACE_CONFIG, traceFile, traceLevel, traceStdout, and traceStream.

00046     : statsTarget(
00047         configMap.getStringParam(paramStatsFileName,"/tmp/fennel.stats")),
00048       statsTimer(statsTarget,500),
00049       defaultTests(),
00050       extraTests()
00051 {
00052     pTestObj.reset(this);
00053     testName = configMap.getStringParam(paramTestSuiteName);
00054     traceLevel = static_cast<TraceLevel>(
00055         configMap.getIntParam(paramTraceLevel,TRACE_CONFIG));
00056     std::string traceStdoutParam =
00057         configMap.getStringParam(paramTraceStdout,"");
00058     traceStdout = ((traceStdoutParam.length() == 0) ? false : true);
00059 
00060     std::string defaultTraceFileName;
00061     const char *fennelHome = getenv("FENNEL_HOME");
00062     if (fennelHome) {
00063         defaultTraceFileName += fennelHome;
00064         defaultTraceFileName += "/trace/";
00065     }
00066     defaultTraceFileName += testName + "_trace.log";
00067     std::string traceFileName =
00068         configMap.getStringParam(
00069             paramTraceFileName,
00070             defaultTraceFileName);
00071 
00072     traceFile = false;
00073     if (traceFileName == "-") {
00074         traceStdout = true;
00075     } else if (traceFileName != "none") {
00076         if (!traceFileName.empty()) {
00077             traceStream.open(traceFileName.c_str());
00078             if (traceStream.good()) {
00079                 traceFile = true;
00080             }
00081         }
00082     }
00083 
00084     // NOTE jvs 25-Nov-2008:  This is to make sure we trace any
00085     // configuration access in the derived class constructor.
00086     // There's a matching call to disableTracing in
00087     // the definition for FENNEL_UNIT_TEST_SUITE after
00088     // the constructor returns.
00089     configMap.initTraceSource(shared_from_this(), "testConfig");
00090 }

TestBase::~TestBase (  )  [virtual]

Definition at line 92 of file TestBase.cpp.

References ConfigMap::clear(), configMap, and traceStream.

00093 {
00094     traceStream.close();
00095     configMap.clear();
00096 }


Member Function Documentation

void TestBase::snooze ( uint  nSeconds  )  [protected]

Definition at line 263 of file TestBase.cpp.

Referenced by DatabaseTest::executeForceTxn(), ThreadedTestBase::runThreadedTestCase(), PagingTestBase::testCacheResize(), BTreeTxnTest::testCheckpoint(), PagingTestBase::testCheckpointGuarded(), PagingTestBase::testPrefetch(), and PagingTestBase::testPrefetchBatch().

00264 {
00265 #ifdef __MSVC__
00266     ::_sleep(nSeconds*1000);
00267 #else
00268     ::sleep(nSeconds);
00269 #endif
00270 }

void TestBase::readParams ( int  argc,
char **  argv 
) [static]

Parses the command line.

format: [-v] [-t TEST | -all] {param=val}* [CONFIGFILE | -] Normally, the test program runs the default test cases. With the option "-all", runs the extra test cases as well. With the option "-t TEST", runs only the single test case named TEST. CONFIGFILE is read to load configuration parameters. Configuration parameters can also be set ad hoc, from the command line, as pairs name=val. These take precedence.

Definition at line 108 of file TestBase.cpp.

References configMap, ConfigMap::dumpParams(), ConfigMap::isParamSet(), ConfigMap::mergeFrom(), paramDictionaryFileName, ConfigMap::readParams(), runAll, runSingle, ConfigMap::setStringParam(), and verbose.

00109 {
00110     bool verbose = false;
00111     ConfigMap adhocMap;
00112 
00113     for (int i = 1; i < argc; ++i) {
00114         std::string arg = argv[i];
00115         if (argv[i][0] == '-') {
00116             if (arg == "-v") {
00117                 verbose = true;
00118             } else if (arg == "-") {
00119                 configMap.readParams(std::cin);
00120             } else if (arg == "-all") {
00121                 runAll = true;
00122             } else if (arg == "-t") {   // -t TEST
00123                 permAssert(i + 1 < argc);
00124                 runSingle = argv[++i];
00125             } else if (arg[1] == 't') { // allow -tTEST
00126                 runSingle = arg.substr(2);
00127             }
00128         } else {
00129             int i = arg.find("=");
00130             if ((0 < i) && (i < arg.size())) {
00131                 // an ad hoc parameter
00132                 std::string key = arg.substr(0,i);
00133                 std::string val = arg.substr(i + 1);
00134                 adhocMap.setStringParam(key,val);
00135             } else {
00136                 // a config file name
00137                 std::ifstream configFile(arg.c_str());
00138                 assert(configFile.good());
00139                 configMap.readParams(configFile);
00140             }
00141         }
00142     }
00143     configMap.mergeFrom(adhocMap);
00144 
00145     // set a default dictionary file location for use by tests that need a
00146     // small non-random sorted data set
00147     if (!configMap.isParamSet(paramDictionaryFileName)) {
00148         std::string dictFileName = "dictWords";
00149         configMap.setStringParam(paramDictionaryFileName,dictFileName);
00150     }
00151 
00152     if (verbose) {
00153         configMap.dumpParams(std::cout);
00154     }
00155 }

TestSuite * TestBase::releaseTestSuite (  ) 

Definition at line 157 of file TestBase.cpp.

References TestBase::TestCaseGroup::addAllToTestSuite(), defaultTests, extraTests, TestBase::TestCaseGroup::findTest(), pTestObj, pTestSuite, runAll, runSingle, and testName.

00158 {
00159     assert(pTestObj);
00160     assert(pTestObj.use_count() > 1);
00161 
00162     // release self-reference now that all test cases have been registered
00163     pTestObj.reset();
00164 
00165     TestSuite* pTestSuite = BOOST_TEST_SUITE(testName.c_str());
00166 
00167     if (runSingle.size()) {
00168         test_unit *p =  defaultTests.findTest(runSingle);
00169         if (!p) {
00170             p = extraTests.findTest(runSingle);
00171         }
00172         if (!p) {
00173             std::cerr << "test " << runSingle << " not found\n";
00174             exit(2);
00175         }
00176         pTestSuite->add(p);
00177     } else {
00178         defaultTests.addAllToTestSuite(pTestSuite);
00179         if (runAll) {
00180             extraTests.addAllToTestSuite(pTestSuite);
00181         }
00182     }
00183     return pTestSuite;
00184 }

void TestBase::beforeTestCase ( std::string  testCaseName  ) 

Definition at line 214 of file TestBase.cpp.

References configMap, TraceSource::initTraceSource(), AutoBacktrace::install(), notifyTrace(), AutoBacktrace::setOutputStream(), AutoBacktrace::setTraceTarget(), testName, and TRACE_INFO.

00215 {
00216     notifyTrace(testName,TRACE_INFO,"ENTER:  " + testCaseName);
00217 
00218     // Install the AutoBacktrace signal handler now, after
00219     // boost::execution_monitor::catch_signals() has installed its own, so that
00220     // on SIGABRT AutoBacktrace goes first, prints the backtrace, then chains
00221     // to boost, which handles the error.
00222     AutoBacktrace::setOutputStream();
00223     AutoBacktrace::setTraceTarget(shared_from_this());
00224     AutoBacktrace::install();
00225     configMap.initTraceSource(shared_from_this(), "testConfig");
00226 }

void TestBase::afterTestCase ( std::string  testCaseName  ) 

Definition at line 228 of file TestBase.cpp.

References configMap, TraceSource::disableTracing(), notifyTrace(), AutoBacktrace::setTraceTarget(), testName, and TRACE_INFO.

00229 {
00230     AutoBacktrace::setTraceTarget();
00231     configMap.disableTracing();
00232     notifyTrace(testName,TRACE_INFO,"LEAVE:  " + testCaseName);
00233 }

void TestBase::testCaseSetUp (  )  [virtual]

Equivalent to JUnit TestCase.setUp; this is called before each test case method is invoked.

Default is no-op.

Reimplemented in LbmEntryTest, LbmExecStreamTestBase, LbmLoadBitmapTest, LbmSearchTest, LbmSplicerExecStreamTest, LcsClusterAppendExecStreamTest, LcsClusterReplaceExecStreamTest, LcsMultiClusterAppendTest, LcsRowScanExecStreamTest, BTreeReadersTest, BTreeTest, BTreeTxnTest, ExecStreamGovernorTest, ExecStreamTestBase, ExecStreamUnitTestBase, ExternalSortExecStreamTest, LhxHashTableTest, LogicalTxnTest, and SnapshotSegmentTestBase.

Definition at line 235 of file TestBase.cpp.

Referenced by ExecStreamTestBase::testCaseSetUp().

00236 {
00237 }

void TestBase::testCaseTearDown (  )  [virtual]

Equivalent to JUnit TestCase.tearDown; this is called after each test case method is invoked.

Default is no-op.

Reimplemented in LbmEntryTest, LbmLoadBitmapTest, LbmSearchTest, LcsClusterAppendExecStreamTest, LcsClusterReplaceExecStreamTest, LcsMultiClusterAppendTest, LcsRowScanExecStreamTest, BTreeReadersTest, BTreeTest, BTreeTxnTest, CacheTestBase, DatabaseTest, ExecStreamTestBase, LhxHashTableTest, RandomAccessFileDeviceTest, and SparseBitmapTest.

Definition at line 239 of file TestBase.cpp.

Referenced by SparseBitmapTest::testCaseTearDown().

00240 {
00241 }

void TestBase::notifyTrace ( std::string  source,
TraceLevel  level,
std::string  message 
) [virtual]

Receives notification when a trace event occurs.

Parameters:
source the facility from which the message originated
level the trace event severity level
message the text of the message

Implements TraceTarget.

Definition at line 243 of file TestBase.cpp.

References traceFile, traceMutex, traceStdout, and traceStream.

Referenced by afterTestCase(), and beforeTestCase().

00244 {
00245     if (traceFile || traceStdout) {
00246         StrictMutexGuard traceMutexGuard(traceMutex);
00247         if (traceFile) {
00248             traceStream << "[" << source << "] " << message << std::endl;
00249             traceStream.flush();
00250         }
00251         if (traceStdout) {
00252             std::cout << "[" << source << "] " << message << std::endl;
00253             std::cout.flush();
00254         }
00255     }
00256 }

TraceLevel TestBase::getSourceTraceLevel ( std::string  source  )  [virtual]

Gets the level at which a particular source should be traced.

Parameters:
source name of source to be traced
Returns:
minimum severity level which should be traced

Implements TraceTarget.

Definition at line 258 of file TestBase.cpp.

References traceLevel.

Referenced by LbmExecStreamTestBase::generateBitmaps().

00259 {
00260     return traceLevel;
00261 }


Member Data Documentation

TestSuite* TestBase::pTestSuite [protected]

Boost test suite.

Definition at line 59 of file TestBase.h.

Referenced by releaseTestSuite().

boost::shared_ptr<TestBase> TestBase::pTestObj [protected]

Definition at line 61 of file TestBase.h.

Referenced by releaseTestSuite(), and TestBase().

std::ofstream TestBase::traceStream [protected]

Output file stream for tracing.

Definition at line 66 of file TestBase.h.

Referenced by notifyTrace(), TestBase(), and ~TestBase().

StrictMutex TestBase::traceMutex [protected]

Protects traceStream.

Definition at line 71 of file TestBase.h.

Referenced by notifyTrace().

std::string TestBase::testName [protected]

Name of test.

Definition at line 76 of file TestBase.h.

Referenced by afterTestCase(), beforeTestCase(), releaseTestSuite(), TestBase(), LhxHashTableTest::testInsert1Ka(), and LhxHashTableTest::testInsert1Kb().

TraceLevel TestBase::traceLevel [protected]

Level at which to trace test execution.

Definition at line 81 of file TestBase.h.

Referenced by getSourceTraceLevel(), and TestBase().

FileStatsTarget TestBase::statsTarget [protected]

Output for stats.

Definition at line 86 of file TestBase.h.

StatsTimer TestBase::statsTimer [protected]

Timer for stats collection.

Definition at line 91 of file TestBase.h.

Referenced by CacheTestBase::closeStorage(), CacheTestBase::openStorage(), BTreeTxnTest::testCaseSetUp(), BTreeTxnTest::testCaseTearDown(), and BTreeTxnTest::testTxns().

bool TestBase::traceStdout [protected]

Copy trace output to stdout.

Definition at line 99 of file TestBase.h.

Referenced by notifyTrace(), and TestBase().

bool TestBase::traceFile [protected]

Copy trace output to file.

Definition at line 104 of file TestBase.h.

Referenced by notifyTrace(), and TestBase().

bool TestBase::runAll [static, protected]

Run all test cases, including the extra tests.

(static, since set by readParams())

Definition at line 110 of file TestBase.h.

Referenced by readParams(), and releaseTestSuite().

std::string TestBase::runSingle [static, protected]

Run only the test case of this name.

(static, since set by readParams())

Definition at line 116 of file TestBase.h.

Referenced by readParams(), and releaseTestSuite().

TestCaseGroup TestBase::defaultTests [protected]

Definition at line 139 of file TestBase.h.

Referenced by releaseTestSuite().

TestCaseGroup TestBase::extraTests [protected]

Definition at line 140 of file TestBase.h.

Referenced by releaseTestSuite().

ParamName TestBase::paramTestSuiteName [static]

Definition at line 143 of file TestBase.h.

Referenced by TestBase().

ParamName TestBase::paramTraceFileName [static]

Definition at line 144 of file TestBase.h.

Referenced by TestBase().

ParamName TestBase::paramDictionaryFileName [static]

Definition at line 145 of file TestBase.h.

Referenced by readParams(), SegStreamTest::testRead(), and SegStreamTest::testWrite().

ParamName TestBase::paramTraceLevel [static]

Definition at line 146 of file TestBase.h.

Referenced by TestBase().

ParamName TestBase::paramStatsFileName [static]

Definition at line 147 of file TestBase.h.

ParamName TestBase::paramTraceStdout [static]

Definition at line 148 of file TestBase.h.

Referenced by TestBase().

ParamName TestBase::paramDegreeOfParallelism [static]

Definition at line 149 of file TestBase.h.

Referenced by ParallelExecStreamSchedulerTest::ParallelExecStreamSchedulerTest().

ConfigMap TestBase::configMap [static]

Configuration parameters.

The reason this is static is so that no constructor parameters (which burden virtual bases) are needed.

Definition at line 155 of file TestBase.h.

Referenced by afterTestCase(), beforeTestCase(), BTreeTxnTest::BTreeTxnTest(), CacheTestBase::CacheTestBase(), BackupRestoreTest::createSnapshotData(), DatabaseTest::DatabaseTest(), TestOptionsTest::extra(), DatabaseTest::loadDatabase(), SparseBitmapTest::openStorage(), PagingTestBase::PagingTestBase(), ParallelExecStreamSchedulerTest::ParallelExecStreamSchedulerTest(), RandomAccessFileDeviceTest::RandomAccessFileDeviceTest(), readParams(), SegStorageTestBase::SegStorageTestBase(), TestOptionsTest::test1(), TestOptionsTest::test2(), BackupRestoreTest::testBackupCleanup(), TestBase(), BTreeTxnTest::testCaseSetUp(), BTreeTxnTest::testCheckpoint(), DatabaseTest::testCreateEmpty(), DatabaseTest::testForceTxns(), BackupRestoreTest::testHeaderBackupRestore(), SegPageEntryIterTest::testIter(), SegStreamTest::testRead(), BTreeTxnTest::testTxns(), SegStreamTest::testWrite(), ThreadedTestBase::ThreadedTestBase(), and ~TestBase().


The documentation for this class was generated from the following files:
Generated on Mon Jun 22 04:00:48 2009 for Fennel by  doxygen 1.5.1