Re: [Cppunit-devel] Signal handling in Linux
Brought to you by:
blep
From: Baptiste L. <gai...@fr...> - 2002-04-15 23:26:59
|
So If I understood thing well, the only hope that remains would compiler specific. VC++ has such a thing, have you found anything like that on gcc ? (I guess not, but...) In the meantime, I think I'll add a VerboseTestProgressListener: startTest(): print test name failure(): print ':' and 'E' or 'F' endTest(): new line Baptiste. ----- Original Message ----- From: "Robert Wenner" <ro...@po...> To: "Baptiste Lepilleur" <gai...@fr...>; <cpp...@li...> Sent: Monday, April 15, 2002 8:33 AM Subject: Re: [Cppunit-devel] Signal handling in Linux > On Saturday 13 April 2002 11:28, Baptiste Lepilleur wrote: > > Is it possible to wrap the signal logic into a class (even if it use > > global variable) ? I'm planning to add a feature to add 'custom' > > exception support (export not based on std::exception) to CppUnit. > > As far as I found something on the web on the topic of signal handling > and C++: don't do it. > Std C++ sticks to the old C behaviour of signal handling. > That means use of C++ features will result in undefined behaviour; > especially use of RTTI, member variables and exceptions. > IMHO the best way to solve the signal problems is to set a global > variable in the signal handler and return. The calling program (in > case of CppUnit) the framework has to check that variable. > Having the signal wrapper class use a list of received signals would > also be possible to throw multiple exceptions (if desired). > Ignoring some signals (such as SIG_SEGV) is considered dangerous > as the program may be left in an undefined state (e.g. what is the > result from a divide by zero?). This may be no problem with some > short test cases, though. > > > To do that, I just call a must on a class with the Test to run and > > the TestResult which 'protect ' the test run. In your case, that > > would means trapping the signal, and throwing adding a failure to > > TestResult. > I tried a little with setting the signal handler in setUp and checking > the global variable in tearDown, but signals behaved really strange > on my machine (examples for a SEGV by wrong pointer access). > - Ignoring (SIG_IGN setting ) the signal (or using no handler) crashes > the program (the default behaviour for unhandled signals) > - Catching the signal causes the handler to execute and after that > crash the program > - Catching the signal and re-installing the signal handler (it is > uninstalled by default according to the man page) or not using the > ONESHOT option in sa_flags results in endless signals received -> > program hangs. > > > I'm really interessed into this, because VC++ does this automatically > > for us in debug mode. This is not the case on Unix, and as such does > > not provide a consistent behavior across plateform. As a consequence, > > on Unix, you would need a TestListener that print the test name > > before running the test, just to now which test failed... > IMHO the C++ std is somewhat lazy / minimalistic here. :-( > By time C++ should drop these old C garbage. > Anyway I would be really interestedin a soultion, too. > > Robert > |