citrun

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

inst_for.t (1454B)


      1 #
      2 # Test that for loop condition instrumenting 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( 'for.c', <<EOF );
     15 int main(int argc, char *argv[]) {
     16 	for (;;);
     17 
     18 	for (argc = 0; argc < 10; argc++)
     19 		argv++;
     20 }
     21 EOF
     22 
     23 # Known good output.
     24 my $inst_good = <<EOF ;
     25 int main(int argc, char *argv[]) {++_citrun.data[0];
     26 	for (;;);
     27 
     28 	for ((++_citrun.data[3], argc = 0); (++_citrun.data[3], (++_citrun.data[3], argc < 10)); argc++)
     29 		argv++;
     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 For loops
     43     15 Total statements
     44     2 Binary operators
     45 Modified source written successfully.
     46 EOF
     47 
     48 # Run the command.
     49 $inst->run( args => '-c for.c', chdir => $inst->curdir );
     50 
     51 # This file should have been rewritten in place.
     52 my $inst_out;
     53 $inst->read(\$inst_out, 'for.c');
     54 
     55 # Sanitize paths from stdout.
     56 my $check_out = utils::clean_citrun_log(scalar $inst->stdout);
     57 
     58 eq_or_diff( $inst_out, $inst_good, 'inst file identical', { context => 3 } );
     59 eq_or_diff($check_out, $check_good, 'citrun_inst output identical',
     60 	{ context => 3 } );
     61 is( $inst->stderr,	'',	'citrun_inst stderr silent' );
     62 is( $? >> 8,		0,	'citrun_inst exit code 0' );