citrun

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

commit a4a265e04e561bc18dcf8e40c0be05ef1788d7d7
parent 295836ec7e84f13f1d4e21895f311f0c1bd76caf
Author: Kyle Milz <kyle@windows.krwm.net>
Date:   Fri,  6 Jan 2017 19:09:55 -0800

t: simplify walking memory file for translation units

Diffstat:
Mt/lib_transunit.t | 22++++++++++++++--------
Mt/utils.pm | 35+++++++++++++++--------------------
2 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/t/lib_transunit.t b/t/lib_transunit.t @@ -4,7 +4,7 @@ use strict; use warnings; use t::utils; -plan tests => 11; +plan tests => 14; my $dir = setup_projdir(); @@ -16,11 +16,17 @@ 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 ($tu1, $tu2, $tu3) = @{ $shm->{translation_units} }; -is $tu1->{size}, 9, "is translation unit 1 9 lines"; -is $tu1->{comp_file_name}, 'print.c', 'is compiler file name right'; -like $tu1->{abs_file_path}, qr/.*print.c/, 'is absolute file path believable'; +my %tus = %{ $shm->{trans_units} }; +my ($tu1, $tu2, $tu3) = sort keys %tus; -is $tu2->{size}, 11, "is translation unit 2 9 lines"; -is $tu2->{comp_file_name}, 'fib.c', 'is compiler file name right'; -like $tu2->{abs_file_path}, qr/.*fib.c/, 'is absolute file path believable'; +like( $tu1, qr/.*ib.c/, 'is end of absolute file path fib.c' ); +is( $tus{$tu1}->{size}, 11, "is fib.c the correct length" ); +is( $tus{$tu1}->{comp_file_name}, 'fib.c', 'is compiler file name right' ); + +like( $tu2, qr/.*main.c/, 'is end of absolute file path main.c' ); +is( $tus{$tu2}->{size}, 22, "is main.c the correct length" ); +is( $tus{$tu2}->{comp_file_name}, 'main.c', 'is compiler file name main.c' ); + +like( $tu3, qr/.*print.c/, 'is end of absolute file path print.c' ); +is( $tus{$tu3}->{size}, 9, "is print.c the correct length" ); +is( $tus{$tu3}->{comp_file_name}, 'print.c', 'is compiler file name print.c' ); diff --git a/t/utils.pm b/t/utils.pm @@ -134,38 +134,33 @@ sub new { ) = unpack("Z4I8Z1024Z1024", xread($fh, $aligned_size)); my $node_fixed_size = citrun_node_size(); - my @translation_units; + my %trans_units; - while (tell $fh < $self->stat_procfile()) { - my %tu; + #while (tell $fh < $self->stat_procfile()) { + while (not eof $fh) { - ( - $tu{size}, - $tu{comp_file_name}, - $tu{abs_file_path} - ) = unpack("IZ1024Z1024", xread($fh, $node_fixed_size)); + my @struct_fields = unpack("IZ1024Z1024", xread($fh, $node_fixed_size)); + my $buf_pos = tell $fh; + my $buf_size = $struct_fields[0]; - $tu{exec_buf_pos} = tell $fh; + my %tu; + $trans_units{ $struct_fields[2] } = { + size => $buf_size, + comp_file_name => $struct_fields[1], + exec_buf_pos => $buf_pos + }; - my $node_end = $tu{exec_buf_pos} + ($tu{size} * 8); + my $node_end = $buf_pos + ($buf_size * 8); my $node_end_aligned = get_aligned_size($node_end); seek $self->{fh}, $node_end_aligned, 0; - - push @translation_units, (\%tu); + $self->{size} = $node_end_aligned; } - $self->{translation_units} = \@translation_units; + $self->{trans_units} = \%trans_units; return $self; } -sub stat_procfile { - my ($self) = @_; - - $self->{size} = (stat $self->{fh})[7]; - return $self->{size}; -} - sub get_aligned_size { my ($unaligned_size) = @_;