commit bd557dca31d1ffd9da0b0bcfb8c66ef42eb31a58
parent 1e87df9dba1237463211f517815189cb3322dafc
Author: Kyle Milz <kyle@windows.krwm.net>
Date: Fri, 6 Jan 2017 19:38:14 -0800
t: add new lib_deadcount test
Diffstat:
2 files changed, 81 insertions(+), 6 deletions(-)
diff --git a/t/lib_deadcount.t b/t/lib_deadcount.t
@@ -0,0 +1,77 @@
+#
+# Test that a ran program outputs a memory file with correct line execution
+# counts.
+#
+use strict;
+use warnings;
+use t::utils;
+plan tests => 8;
+
+my $dir = setup_projdir();
+
+$dir->run( prog => $dir->workdir . '/program', args => '10', chdir => $dir->curdir );
+is( $dir->stdout, '55', 'is instrumented program stdout correct' );
+is( $dir->stderr, '', 'is instrumented program stderr silent' );
+is( $? >> 8, 0, "is instrumented program exit code 0" );
+
+my $shm_file_path = get_one_shmfile( $ENV{CITRUN_PROCDIR} );
+my $shm = t::shm->new( $shm_file_path );
+
+my %tus = %{ $shm->{trans_units} };
+my ($tu1, $tu2, $tu3) = sort keys %tus;
+
+# Diff format test chosen here because these numbers are related to source code.
+my @fib_good = qw(
+177
+177
+354
+34
+286
+55
+0
+528
+0
+0
+0
+);
+
+my @main_good = qw(
+0
+0
+0
+0
+0
+1
+1
+1
+0
+0
+2
+0
+0
+0
+0
+2
+0
+2
+1
+0
+0
+0
+);
+
+my @print_good = qw(
+0
+1
+1
+1
+1
+0
+0
+0
+0
+);
+
+eq_or_diff( $shm->get_buffers($tu1), \@fib_good, 'is fib count identical', { context => 3 } );
+eq_or_diff( $shm->get_buffers($tu2), \@main_good, 'is main count identical', { context => 3 } );
+eq_or_diff( $shm->get_buffers($tu3), \@print_good, 'is print count identical', { context => 3 } );
diff --git a/t/utils.pm b/t/utils.pm
@@ -136,9 +136,7 @@ sub new {
my $node_fixed_size = citrun_node_size();
my %trans_units;
- #while (tell $fh < $self->stat_procfile()) {
while (not eof $fh) {
-
my @struct_fields = unpack("IZ1024Z1024", xread($fh, $node_fixed_size));
my $buf_pos = tell $fh;
my $buf_size = $struct_fields[0];
@@ -174,13 +172,13 @@ sub get_aligned_size {
return ($unaligned_size + $page_mask) & ~$page_mask;
}
-sub execs_for {
- my ($self, $tu_num) = @_;
+sub get_buffers {
+ my ($self, $tu_key) = @_;
- my $tu = $self->{translation_units}->[$tu_num];
+ my $tu = $self->{trans_units}->{$tu_key};
seek $self->{fh}, $tu->{exec_buf_pos}, 0;
- my @execs = unpack("Q$tu->{size}", xread($self->{fh}, $tu->{size} * 8));
+ my @execs = unpack("Q$tu->{size}", xread($self->{fh}, $tu->{size} * 8));
return \@execs;
}