[tests] Signals not well covered in unit tests (in contrast to exceptions)?
Hi, I have the following problem with a C++ project on Linux using the Boost.test framework: I use the "resource acquisition is initialization" technique to ensure that all resources I allocate are properly released. That's why I have helper classes with a resource allocation in the constructor and deallocation in the destructor. One example of such a helper class is an indentation for my logging code: LOG("blabla"); { LogIndendation indent; // start indentation of output LOG("a message"); divide_by_zero(); LOG("a further message"); } // reset indentation LOG("blabla"); The output is normally: blabla a message a further message blabla Please note that divide_by_zero (which perform an integer division by zero) causes a SIGFPE fatal arithmetic error and the signal handler of Boost.test detects this. Nevertheless the destructor of LogIndendation is *not* called and all further tests I have create wrong indented output (which I compare with the expected output as another test too). So I get: test1 blabla a message unknown location(0): fatal error in "Test1": signal: SIGFPE (arithmetic exception) test2 blabla If I do not generate a signal but throw an exception instead, the destructor is called so this is fine. (Please note that g++ does normally not call a destructor with such a technique if the exception is not catched at all (probably because all resources are expected to be cleaned up, once the process terminates???), but Boost.test catchs all exceptions - good.) I also tried to write my own SIGFPE signal handler which just throws an exception. But this handler is not called, probably it's overwritten by Boost's one. Probably Boost doesn't call the previous handler because it normally terminates the application. But maybe it's possible for Boost to save the initial handler in main() and later to compare the current handler with the initial one. If they are equal handle signals as usual (output an error) otherwise do nothing and call the previous handler? Has anyone a good solution for me, or is there a problem with Boost.test and signals? How to solve this? Jens
participants (1)
-
Jens Seidel