[interfacekit] CppUnit progress
- From: "Jeremy Rand" <jrand@xxxxxxxx>
- To: interfacekit@xxxxxxxxxxxxx
- Date: Tue, 12 Feb 2002 23:02:05 EST
I have been working on the threaded interface for CppUnit and I think I
now have something pretty good. Here is the rundown:
1. I no longer have a "ThreadedTestSuite" class. Instead, I have made
a "ThreadedTestCaller" class. That way, a threaded class is modelled
as a single test with multiple threads. It seems to work quite well.
Here is an example of a test suite of two tests, each with three
individual threads running concurrently during each test:
TestSuite *testSuite = new TestSuite("Test1");
Test1<Locker> *theTest = new Test1<Locker>("Test1:Benaphore",
true);
Test1Caller *threadedTest1 = new Test1Caller("", theTest);
threadedTest1->addThread(":Thread1", &Test1<Locker>::TestThread);
threadedTest1->addThread(":Thread2", &Test1<Locker>::TestThread);
threadedTest1->addThread(":Thread3", &Test1<Locker>::TestThread);
theTest = new Test1<Locker>("Test1:Semaphore", false);
Test1Caller *threadedTest2 = new Test1Caller("", theTest);
threadedTest2->addThread(":Thread1", &Test1<Locker>::TestThread);
threadedTest2->addThread(":Thread2", &Test1<Locker>::TestThread);
threadedTest2->addThread(":Thread3", &Test1<Locker>::TestThread);
testSuite->addTest(threadedTest1);
testSuite->addTest(threadedTest2);
return(testSuite);
I think this is pretty readable. I have already done the following
typedef to make the code more readable:
typedef ThreadedTestCaller<Test1<Locker> > Test1Caller
This is the downside of C++ templates...
2. I have modified the test based "TestRunner.cpp" included in CppUnit
to include some interesting features. I have changed the output to
make it a bit more readable. Here is an example:
$ ./TestRunner -all
Executing BLockerTests:
Running test: t5Test11Z7BLocker.Test1:Benaphore (998790 us)
Running test: t5Test11Z7BLocker.Test1:Semaphore (1361279 us)
Running test: t5Test11ZQ28OpenBeOS7BLocker.Test1:Benaphore (1023494 us)
Running test: t5Test11ZQ28OpenBeOS7BLocker.Test1:Semaphore (1372284 us)
Unfortunately, the name of the test comes from RTTI inspection of the
class. This is required because there is no easy way to know whether
the test is for "BLocker" or "OpenBeOS::BLocker" because the tests are
just templates of these two classes(ie the same code base). So, I use
RTTI to get that information which results in this slightly mangled
output. Note this is not normal gcc name mangling and I can't decode
it with c++filt for example. I also include running time in
microseconds so that we can confirm that our implementations are
comparable to Be's. If anyone has any suggestions on how to make this
test output a bit more readable, I would appreciate it.
3. Also, the new TestRunner.cpp looks in an add-ons directory and
attempts to load tests from there. You can specify the name of a test
to run or use the -all option to run them all. This is nice because
all the tests for individual classes are modelled as an addon and n0t
compiled right into a test application.
4. To make the threading work right, I had to add locking to the
TestResult class. There was already roughed in locking in CppUnit and
I just added the necessary Be specific code to make that work.
5. Finally, I also had to modify the assert member functions in
TestCase.cpp. They used to take std::string arguments. These
functions are called to just check for an assertion so these
std::string's were being constructed and destructed many times per
second in multiple threads. For some reason that I am not sure of yet,
I was getting seg faults in free attempting to de-allocate buffers
within these strings. Perhaps this is some STL locking issue but I
can't imagine why. For now, I have changed these functions to take
const char *'s. That avoids the constructors and destructors of
std::string's and should also improve the performance of checking for
assertions. I am concerned though that these seg faults are caused by
some memory corruption bug in CppUnit or more likely my modifications
or test code. We will see.
I am going to change the rest of my testcases over to this test
infrastructure and then check it in. Please let me know if I am
stepping on someone else's toes with this work on CppUnit. Also, if
you need this stuff to write tests for something you are working on,
feel free to contact me.
--
Jeremy Rand
jrand@xxxxxxxx
Other related posts:
- » [interfacekit] CppUnit progress