[Avocado-devel] handling segfault of test process

Lukáš Doktor ldoktor at redhat.com
Sun Nov 18 08:24:13 UTC 2018


Dne 16. 11. 18 v 15:17 Brian J. Murrell napsal(a):
> On Thu, 2018-11-15 at 10:17 -0500, Brian J. Murrell wrote:
>> If I have a test class with a setUp(), test*() function(s) and a
>> tearDown(), is it true that if some operation in a test*() function
>> causes a segfault, tearDown() won't get run?
> 
> This certainly seems to be the case.  A quick test does reveal that
> those three functions are all run in the same process.
> 
>> If this is true, what is the advise for writing/structuring tests
>> that
>> are testing, say, a library (through python bindings to such a
>> library)
>> that is in development and as such could segfault?
> 
> I did a quick test of using multiprocessing to farm out a separate
> function in a test*() to a subprocess which seems to work.  Of course
> communication between the function being run and test*() is limited but
> I wonder if this kind of technique can/should be formalized in avocado.
> 
> That all aside, is there any facility in avocado to process the core
> file from a test process segfaulting?  Any suggestions on how such a
> thing could be done, to say, at least get a backtrace of segfaulted
> process?
> 
> Cheers,
> b.
> 
> 

Hello Brian,

currently we don't support anything like that, but we do have a support to cleanup resources after the testing called `func_at_exit` https://avocado-framework.readthedocs.io/en/latest/ReferenceGuide.html?highlight=func_at_exit#job-cleanup which is used by Avocado-vt to cleanup job-related results (eg. vms that can live across multiple tests). It's slightly controversial and we mean to improve it in the future (especially to unpickle the passed objects in a different process to avoid crashing Avocado in case of malicious argument/function), but in general the philosophy should be applicable to your case as well.

You can see `self.runner_queue.put({"func_at_exit": function, ...})` can be used to register a cleanup function to be executed by the main thread after the testing and we might consider adding `func_at_test_exit` function to do the same treatment after test finishes. It's just a matter of +1 supported message and +1 CallbackRegister instance to handle those.

Obviously you could do similar thing yourself without the support of the framework, but it'd be better to have it as first-class-citizen in order to other people to be able to reuse, maintain and improve it. I'd suggest basing it on the already existing `func_at_exit, which is implemented in `avocado.utils.data_structures.CallbackRegister`. Obviously there are some limitation when passing objects to a different process like you can only pass global-level functions, you need to pass the whole environment etc, but you get what you need...

Lukáš

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/avocado-devel/attachments/20181118/5b92e613/attachment.sig>


More information about the Avocado-devel mailing list