citrun

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

commit 8526d7cea27e9f2435874bb221f529ca66c7b184
parent 7008417beb741576eaf916bd0045a03b6a703897
Author: Kyle Milz <kyle@0x30.net>
Date:   Sun,  8 Jan 2017 02:44:11 -0700

t: replace wrap_ninja.sh with perl

Diffstat:
Dt/wrap_ninja.sh | 44--------------------------------------------
At/wrap_ninja.t | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+), 44 deletions(-)

diff --git a/t/wrap_ninja.sh b/t/wrap_ninja.sh @@ -1,44 +0,0 @@ -#!/bin/sh -u -# -# Test that wrapping the 'ninja' build system produces instrumented binaries. -# -. t/utils.subr -type ninja || skip_all "ninja not found" -plan 6 - -empty_main - -# Quote the here-doc so that '$' does not get substituted. -cat <<'EOF' > build.ninja -rule cc - command = gcc $cflags -c $in -o $out - -rule link - command = gcc $in -o $out - -build main.o: cc main.c -build program: link main.o -EOF - -ok "is instrumented ninja successful" ninja -ok "is citrun_check successful" citrun_check -o check.out - -cat <<EOF > check.good -Summary: - 1 Source files used as input - 1 Application link commands - 1 Rewrite successes - 1 Rewritten source compile successes - -Totals: - 6 Lines of source code - 1 Function definitions - 1 Return statement values - 3 Total statements -EOF - -strip_millis check.out -ok "is citrun_check output identical" diff -u check.good check.out - -ok "does compiled program run" ./program -ok "is runtime shared memory file created" test -f procdir/program_* diff --git a/t/wrap_ninja.t b/t/wrap_ninja.t @@ -0,0 +1,68 @@ +# +# Test that wrapping the 'ninja' build system produces instrumented binaries. +# +use strict; +use warnings; +use File::Which; +use t::utils; + +unless (which 'ninja') { + plan skip_all => 'ninja not found'; +} +plan tests => 6; + + +my $wrap = Test::Cmd->new( prog => 'citrun_wrap', workdir => '' ); + +$wrap->write( 'main.c', 'int main(void) { return 0; }' ); +$wrap->write( 'build.ninja', <<'EOF' ); +rule cc + command = gcc $cflags -c $in -o $out + +rule link + command = gcc $in -o $out + +build main.o: cc main.c +build program: link main.o +EOF + +$wrap->run( args => 'ninja', chdir => $wrap->curdir ); +print $wrap->stdout; +is( $wrap->stderr, '', 'is citrun_wrap ninja stderr silent' ); +is( $? >> 8, 0, 'is citrun_wrap ninja exit code 0' ); + +my $citrun_log; +my $log_good = <<EOF; +>> citrun_inst +CITRUN_COMPILERS = '' +PATH='' +Found source file '' +Modified command line is '' +Added clangtool argument '' +Instrumentation of '' finished: + 1 Lines of source code + 1 Function definitions + 1 Return statement values + 3 Total statements +Modified source written successfully. +Rewriting successful. +Forked compiler '' +Rewritten source compile successful +Restored '' +>> citrun_inst +CITRUN_COMPILERS = '' +PATH='' +Link detected, adding '' to command line. +Modified command line is '' +No source files found on command line. +EOF + +$wrap->read( \$citrun_log, 'citrun.log' ); +$citrun_log = clean_citrun_log( $citrun_log ); + +eq_or_diff( $citrun_log, $log_good, 'is citrun_wrap log file identical', { context => 3 } ); + +$wrap->run( prog => $wrap->workdir . '/program', chdir => $wrap->curdir ); +is( $wrap->stdout, '', 'is instrumented program stdout silent' ); +is( $wrap->stderr, '', 'is instrumented program stderr silent' ); +is( $? >> 8, 0, 'is instrumented program exit code 0' );