wrap_ninja.t (1787B)
1 # 2 # Test that wrapping the 'ninja' 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 => 'ninja not found' unless (which 'ninja'); 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( 'build.ninja', <<'EOF' ); 21 rule cc 22 command = cc $cflags -c $in -o $out 23 24 rule link 25 command = cc $in -o $out 26 27 build main.o: cc main.c 28 build program: link main.o 29 EOF 30 31 $wrap->run( args => 'ninja', chdir => $wrap->curdir ); 32 print $wrap->stdout; 33 is( $wrap->stderr, '', 'is citrun_wrap ninja stderr silent' ); 34 is( $? >> 8, 0, 'is citrun_wrap ninja exit code 0' ); 35 36 my $citrun_log; 37 my $log_good = <<EOF; 38 >> citrun_inst 39 Compilers path = '' 40 PATH = '' 41 Found source file '' 42 Command line is '' 43 Added clangtool argument '' 44 Instrumentation of '' finished: 45 1 Lines of source code 46 1 Function definitions 47 1 Return statement values 48 3 Total statements 49 Modified source written successfully. 50 Forked compiler '' 51 Rewritten source compile successful 52 Restored '' 53 >> citrun_inst 54 Compilers path = '' 55 PATH = '' 56 Link detected, adding '' to command line. 57 Command line is '' 58 No source files found on command line. 59 EOF 60 61 $wrap->read( \$citrun_log, 'citrun.log' ); 62 $citrun_log = utils::clean_citrun_log( $citrun_log ); 63 64 eq_or_diff( $citrun_log, $log_good, 'citrun_wrap log file identical', 65 { context => 3 } ); 66 67 $wrap->run( prog => $wrap->workdir . '/program', chdir => $wrap->curdir ); 68 is( $wrap->stdout, '', 'instr program stdout silent' ); 69 isnt( $wrap->stderr, '', 'instr program stderr not silent' ); 70 is( $? >> 8, 0, 'instr program exit code 0' ); 71 unlink "/tmp/citrun.out";