Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Code coverage of forked code

by britterm (Initiate)
on May 25, 2016 at 15:46 UTC ( #1164092=perlquestion: print w/replies, xml ) Need Help??

britterm has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I have a module which forks several times to set up a few workers. I'm using Test::More and Devel::Cover to do unit testing of my code and generate code coverage. I have unit tests that stress the workers, but the coverage report shows that the forked code didn't execute even though it did.

I considered putting the child code into separate functions that can be tested independently of forking, but the code relies on piped handles to communicate with the parent, which AFAIK do not function without forking (can't write/read to a pipe in the same process). I would have to do a significant amount of coding in my unit tests to attempt to work around this, and I'm looking for a more straightforward solution if there is one.

Does anyone know how to configure Devel::Cover to detect coverage in the child process when the program forks? Is this even possible? (perhaps with a different coverage tool?)

Thanks in advance,
Brian

Replies are listed 'Best First'.
Re: Code coverage of forked code
by britterm (Initiate) on May 25, 2016 at 16:21 UTC
    I've resolved the issue -- I was forcibly killing the children as they operated with a while(1) loop, this killed coverage as well. When I changed the while(1) loop to something I could cancel without killing, my coverage appeared.

    FYI

      Thanks for updating everyone on this progress. This is useful information to have.

      The author of Devel::Cover has a Github repository for it complete with a bug tracker. I'd imagine Mr. Johnson would appreciate a docs patch if you're willing to write one. https://github.com/pjcj/Devel--Cover

      Can you (or someone else) please explain what do you mean? I'm facing the same situation and having trouble getting coverage of a forked code.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1164092]
Front-paged by GotToBTru
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2019-12-14 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?