citrun

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

commit 5b7cfb202c78dcfa2fc779190b73946ddf7847cf
parent 7eb6f3214cafefcde9e2c48435374e9fbb43a65c
Author: Kyle Milz <kyle@windows.krwm.net>
Date:   Mon,  2 Jan 2017 22:44:32 -0800

t: convert inst_two_src to perl and fix bug on windows

Diffstat:
Minst_action.cc | 2+-
Dt/inst_two_src.sh | 35-----------------------------------
At/inst_two_src.t | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 67 insertions(+), 36 deletions(-)

diff --git a/inst_action.cc b/inst_action.cc @@ -89,7 +89,7 @@ InstrumentAction::EndSourceFileAction() << " __pragma(comment(linker,\"/include:\" p #f \"_\")) \\\n" << " static void f(void)\n" << "#define INITIALIZER(f) INITIALIZER2_(f,\"_\")\n"; - preamble << "INITIALIZER( init)\n" + preamble << "INITIALIZER( init_" << m_compiler_file_name.substr(0, m_compiler_file_name.find(".")) << ")\n" << "{\n" << " citrun_node_add(citrun_major, citrun_minor, &_citrun);\n" << "}\n"; diff --git a/t/inst_two_src.sh b/t/inst_two_src.sh @@ -1,35 +0,0 @@ -#!/bin/sh -u -# -# Check that two source files given on the same command line both get -# instrumented fully. -# -. t/utils.subr -plan 4 - -empty_main - -cat <<EOF > other.c -int other(void) { - return 0; -} -EOF - -cat <<EOF > check.good -Summary: - 2 Source files used as input - 1 Application link commands - 1 Rewrite successes - 1 Rewritten source compile successes - -Totals: - 10 Lines of source code - 2 Function definitions - 2 Return statement values - 6 Total statements -EOF - -ok "is instrumented compile successful" cc -o main main.c other.c -ok "citrun_check" citrun_check -o check.out - -strip_millis check.out -ok "citrun_check diff" diff -u check.good check.out diff --git a/t/inst_two_src.t b/t/inst_two_src.t @@ -0,0 +1,66 @@ +# +# Check that two source files given on the same command line both get +# instrumented fully. +# +use strict; +use warnings; +use Test::Cmd; +use Test::Differences; +use Test::More tests => 3; +unified_diff; + + +my $wrap = Test::Cmd->new( prog => 'citrun_wrap', workdir => '' ); + +$wrap->write( 'main.c', 'int main(void) { return 0; }' ); +$wrap->write( 'other.c', <<EOF ); +int other(void) { + return 0; +} +EOF + +if ($^O eq "MSWin32") { + $wrap->run( args => 'cl /nologo main.c other.c', chdir => $wrap->curdir ); +} else { + $wrap->run( args => 'cc -o main main.c other.c', chdir => $wrap->curdir ); +} + +my $log_good = <<EOF; +>> citrun_inst +CITRUN_SHARE = '' +PATH='' +Found source file '' +Found source file '' +Link detected, adding '' to command line. +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. +Instrumentation of '' finished: + 4 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 '' +Restored '' +EOF + +my $citrun_log; +$wrap->read( \$citrun_log, 'citrun.log' ); +$citrun_log =~ s/^.* citrun_inst.*\n/>> citrun_inst\n/gm; +$citrun_log =~ s/^.*Milliseconds spent.*\n//gm; +$citrun_log =~ s/'.*'/''/gm; +$citrun_log =~ s/^[0-9]+: //gm; + +eq_or_diff( $citrun_log, $log_good, 'is citrun.log identical', { context => 3 } ); +print $wrap->stdout; +is( $wrap->stderr, '', 'is citrun_wrap stderr silent' ); +is( $? >> 8, 0, 'is citrun_wrap exit code 0' );