bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Test framework; new counter class


From: Albert Strasheim
Subject: Test framework; new counter class
Date: Tue, 31 Dec 2002 02:16:34 +0200
User-agent: Mutt/1.4i

Hello,

Attached is a patch that contains the following:

- some basic code for a test framework for Common C++ based on the 
CppUnit test library,

- a counter class (called UberCounter for now) meant to unify the 
Counter, MutexCounter and AtomicCounter classes,

- minor tweaks to configure.in and some Makefile.am files related to 
gcc compiler flags.

The patch is against commoncpp2 in CVS on Tue Dec 31 02:00:00 GMT+2 2002 
or thereabouts.

Firstly, a few notes about the proposed test framework.

The CppUnit test library seems to be THE way to test any C++ project. 
Since Common C++ doesn't have much in the way of a test suite at the 
moment (which the exception of a few tests and demos), I think it would 
be wise to incorporate this test framework into the project to ensure a 
robust and bug-free library for everyone.

To run the tests, compile Common C++ as usual, and then cd to the tests 
directory. Now run "make check" to build and run the tests.

On Debian unstable, I currently configure Common C++ as follows:

CC=/usr/bin/gcc-3.2 CXX=/usr/bin/g++-3.2 ./configure \
--enable-maintainer-mode --with-cppunit-prefix=/home/fullung/opt

For development purposes, I removed the "default" CppUnit from the 
system, and installed a recompiled (with gcc 3.2) CppUnit in
/home/fullung/opt/{bin,lib,etc.}. This is neccesary due to the 
incompatible ABI changes between gcc 2.9x and gcc 3.2 which prevents 
one from linking code (the tests) compiled with gcc 3.2 against a 
library (default CppUnit) compiled with gcc 2.9x.

This shouldn't be a problem on RedHat 8, which ships with gcc 3.2
compiled libraries by default, or systems that only ship with gcc 
2.9x compiled libraries.

I noticed some weirdness when compiling the UberCounter tests with gcc 
2.95.4, related to the tests for operator!=. If anyone else sees this 
behaviour and/or is able to provide a workaround, I would be most 
interested.

The current tests are by no means complete (or even correct :-)), but it 
should serve as a good example of what can be done. Specifically, I 
still need to spend some time on the Thread tests.

Secondly, some notes about the new counter class, UberCounter.

Common C++ currently has three counter classes,

- a templated Counter<T> class with only a few operators,
- MutexCounter, which is essentially a thread-safe counter, but only 
for the int type,
- AtomicCounter class, a thread-safe counter that utilizes system 
specific support for atomic operations on ints (Linux) or longs (Win32), 
or substitutes a mutex on system with no such features.

There are a few shortcomings with this arrangement, namely, that there 
isn't a templated, thread-safe counter and furthermore, that there is 
much code duplication as regards the various operator methods.

UberCounter is a templated counter class was designed with these 
problems in mind. Using UberCounter as a base class, I have implemented 
UberMutexCounter, which is thread-safe and templated, and 
UberAtomicCounter which makes use of system specific atomic operations 
(Linux code is mostly done, Win32 not).

If you're interested, take a quick look at the patch for an idea of how 
UberCounter works. I still need to write some documentation, but the 
basic design should be easy to understand.

(As an aside, it seems that configure is checking for sys/atomic.h, when 
it should in fact be checking for asm/atomic.h (at least on Linux). I 
added #define HAVE_ATOMIC in the UberCounter code to work around this
problem; this issue should probably be addressed in the configure 
script, as I would imagine that it also affects AtomicCounter.)

So, any chance of me seeing a future version of UberCounter in CVS? :-) 
Comments, suggestions, etc. on improving this class would be much 
appreciated.

Finally, the configure.in tweaks simply fix code related to the compile 
flags for gcc (-Wall, -ansi, and -pedantic), add a check for CppUnit, 
and make corresponding changes to the Makefile.am files.

Phew. That's about it... :-)

Cheers,

Albert

Attachment: tstcntcnf1.patch.gz
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]