inst_if.t (1684B)
1 # 2 # Check that if statement conditions are instrumented properly. 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( 'if.c', <<EOF ); 15 int main(int argc, char *argv[]) { 16 if (argc == 1) 17 return 1; 18 else 19 return(14); 20 21 if ((argc = 2)) 22 return 5; 23 else 24 return(0); 25 } 26 EOF 27 28 # Known good output. 29 my $inst_good = <<EOF ; 30 int main(int argc, char *argv[]) {++_citrun.data[0]; 31 if ((++_citrun.data[1], (++_citrun.data[1], argc == 1))) 32 return (++_citrun.data[2], 1); 33 else 34 return(++_citrun.data[4], (14)); 35 36 if ((++_citrun.data[6], ((++_citrun.data[6], argc = 2)))) 37 return (++_citrun.data[7], 5); 38 else 39 return(++_citrun.data[9], (0)); 40 } 41 EOF 42 43 my $check_good = <<EOF; 44 >> citrun_inst 45 Compilers path = '' 46 Found source file '' 47 Command line is '' 48 Added clangtool argument '' 49 Instrumentation of '' finished: 50 12 Lines of source code 51 1 Function definitions 52 2 If statements 53 4 Return statement values 54 21 Total statements 55 2 Binary operators 56 Modified source written successfully. 57 EOF 58 59 # Run the command. 60 $inst->run( args => '-c if.c', chdir => $inst->curdir ); 61 62 # This file should have been rewritten in place. 63 my $inst_out; 64 $inst->read(\$inst_out, 'if.c'); 65 66 # Sanitize paths from stdout. 67 my $check_out = utils::clean_citrun_log(scalar $inst->stdout); 68 69 eq_or_diff( $inst_out, $inst_good, 'inst file identical', { context => 3 } ); 70 eq_or_diff( $check_out, $check_good, 'citrun_inst output identical', 71 { context => 3 } ); 72 is( $inst->stderr, '', 'citrun_inst stderr silent' ); 73 is( $? >> 8, 0, 'citrun_inst exit code 0' );