citrun

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

wrap_make.t (1674B)


      1 #
      2 # Test that wrapping the 'make' build system produces instrumented binaries.
      3 #
      4 use File::Which;
      5 use Modern::Perl;
      6 use Test::Cmd;
      7 use Test::Differences;
      8 use Test::More;
      9 
     10 plan skip_all => 'make not found' unless (which 'make');
     11 plan tests => 6;
     12 
     13 use lib 't';
     14 require utils;
     15 
     16 
     17 my $wrap = Test::Cmd->new( prog => 'bin/citrun_wrap', workdir => '' );
     18 
     19 $wrap->write( 'main.c', 'int main(void) { return 0; }' );
     20 $wrap->write( 'Makefile', <<'EOF' );
     21 program: main.o
     22 	cc -o program main.o
     23 EOF
     24 
     25 $wrap->run( args => 'make', chdir => $wrap->curdir );
     26 print $wrap->stdout;
     27 is( $wrap->stderr,	'',	'citrun_wrap make stderr silent' );
     28 is( $? >> 8,		0,	'citrun_wrap make exit code 0' );
     29 
     30 my $citrun_log;
     31 my $log_good = <<EOF;
     32 >> citrun_inst
     33 Compilers path = ''
     34 PATH = ''
     35 Found source file ''
     36 Command line is ''
     37 Added clangtool argument ''
     38 Instrumentation of '' finished:
     39     1 Lines of source code
     40     1 Function definitions
     41     1 Return statement values
     42     3 Total statements
     43 Modified source written successfully.
     44 Forked compiler ''
     45 Rewritten source compile successful
     46 Restored ''
     47 >> citrun_inst
     48 Compilers path = ''
     49 PATH = ''
     50 Link detected, adding '' to command line.
     51 Command line is ''
     52 No source files found on command line.
     53 EOF
     54 
     55 $wrap->read( \$citrun_log, 'citrun.log' );
     56 $citrun_log = utils::clean_citrun_log( $citrun_log );
     57 
     58 eq_or_diff( $citrun_log, $log_good, 'citrun_wrap log file identical',
     59 	{ context => 3 } );
     60 
     61 $wrap->run( prog => $wrap->workdir . '/program', chdir => $wrap->curdir );
     62 is( $wrap->stdout,	'',	'instr program stdout silent' );
     63 isnt( $wrap->stderr,	'',	'instr program stderr not silent' );
     64 is( $? >> 8,		0,	'instr program exit code 0' );
     65 unlink "/tmp/citrun.out";