citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

lib_livecount.t (718B)


      1 #
      2 # Test that we can count an executing program as its running.
      3 #
      4 use Modern::Perl;
      5 use Time::HiRes qw( time usleep );
      6 use Test::More tests => 23;
      7 
      8 use lib 't';
      9 require mem;
     10 require utils;
     11 
     12 
     13 my $dir = utils::setup_projdir();
     14 
     15 my $child_pid = fork();
     16 if ($child_pid == 0) {
     17 	# Child.
     18 	exec ($dir->workdir . "/program", "45") or die $!;
     19 }
     20 
     21 usleep 500 * 1000;
     22 my $shm = mem->new();
     23 
     24 my %trans_units = %{ $shm->{trans_units} };
     25 
     26 my $last_total = 0;
     27 for (0..20) {
     28 	usleep 30 * 1000;
     29 	my $total = 0;
     30 
     31 	for (keys %trans_units) {
     32 		my $execs = $shm->get_buffers($_);
     33 		$total += $_ for (@$execs);
     34 	}
     35 
     36 	cmp_ok( $total, '>', $last_total, "total line count increasing" );
     37 	$last_total = $total;
     38 }
     39 
     40 kill 'TERM', $child_pid;
     41 wait;