Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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,

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.


      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.

      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?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2020-10-20 15:34 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (210 votes). Check out past polls.