inst_dowhile.t (1498B)
1 # 2 # Make sure that do while loop condition instrumentation works. 3 # 4 use Modern::Perl; 5 use Test::Cmd; 6 use Test::Differences; 7 use Test::More tests => 4; 8 9 use lib 't'; 10 require utils; 11 12 13 my $inst = Test::Cmd->new( prog => 'inst/citrun_inst', workdir => '' ); 14 $inst->write( 'dowhile.c', <<EOF ); 15 int main(int argc, char *argv[]) { 16 do { 17 argc++; 18 } while (argc != 10); 19 return 0; 20 } 21 EOF 22 23 # Known good output. 24 my $inst_good = <<EOF ; 25 int main(int argc, char *argv[]) {++_citrun.data[0]; 26 do { 27 argc++; 28 } while ((++_citrun.data[3], (++_citrun.data[3], argc != 10))); 29 return (++_citrun.data[4], 0); 30 } 31 EOF 32 33 my $check_good = <<EOF; 34 >> citrun_inst 35 Compilers path = '' 36 Found source file '' 37 Command line is '' 38 Added clangtool argument '' 39 Instrumentation of '' finished: 40 7 Lines of source code 41 1 Function definitions 42 1 Do while loops 43 1 Return statement values 44 11 Total statements 45 1 Binary operators 46 Modified source written successfully. 47 EOF 48 49 # Run the command. 50 $inst->run( args => '-c dowhile.c', chdir => $inst->curdir ); 51 52 # This file should have been rewritten in place. 53 my $inst_out; 54 $inst->read(\$inst_out, 'dowhile.c'); 55 56 # Sanitize paths from stdout. 57 my $check_out = utils::clean_citrun_log(scalar $inst->stdout); 58 59 eq_or_diff( $inst_out, $inst_good, 'inst file identical', { context => 3 } ); 60 eq_or_diff($check_out, $check_good, 'citrun_inst output identical', { context => 3 } ); 61 is( $inst->stderr, '', 'citrun_inst stderr silent' ); 62 is( $? >> 8, 0, 'citrun_inst exit code 0' );