citrun

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

commit 3af396888bca70c06c9feab02a27a26d5f183546
parent 518d7cbdc4950808395bbdd255676fb0973a2d1a
Author: Kyle Milz <kyle@0x30.net>
Date:   Thu, 29 Dec 2016 17:09:42 -0700

t: replace inst_while.sh with perl

Diffstat:
Dt/inst_while.sh | 50--------------------------------------------------
At/inst_while.t | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+), 50 deletions(-)

diff --git a/t/inst_while.sh b/t/inst_while.sh @@ -1,50 +0,0 @@ -#!/bin/sh -u -# -# Make sure that while loop condition instrumentation works. -# -. t/utils.subr -plan 5 - - -cat <<EOF > while.c -int main(int argc, char *argv[]) { - while (argc < 17) - argc++; - - while ((argc && argv)); - return 0; -} -EOF - -cat <<EOF > while.c.inst_good -int main(int argc, char *argv[]) {++_citrun.data[0]; - while ((++_citrun.data[1], (++_citrun.data[1], argc < 17))) - argc++; - - while ((++_citrun.data[4], ((++_citrun.data[4], argc && argv)))); - return (++_citrun.data[5], 0); -} -EOF - -cat <<EOF > check.good -Summary: - 1 Source files used as input - 1 Rewrite successes - -Totals: - 8 Lines of source code - 1 Function definitions - 2 While loops - 1 Return statement values - 18 Total statements - 2 Binary operators -EOF - -ok "citrun_inst" citrun_inst -c while.c -ok "citrun_check" citrun_check -o check.out - -strip_preamble while.c -strip_millis check.out - -ok "citrun_inst diff" diff -u while.c.inst_good while.c.citrun_nohdr -ok "citrun_check diff" diff -u check.good check.out diff --git a/t/inst_while.t b/t/inst_while.t @@ -0,0 +1,67 @@ +# +# Make sure that while loop condition instrumentation works. +# +use strict; +use warnings; +use File::Slurp; +use Test::Cmd; +use Test::Differences; +use Test::More tests => 4; +unified_diff; # for Test::Differences + + +my $inst = Test::Cmd->new( prog => 'src/citrun_inst', workdir => '' ); +$inst->write( 'while.c', <<EOF ); +int main(int argc, char *argv[]) { + while (argc < 17) + argc++; + + while ((argc && argv)); + return 0; +} +EOF + +# Known good output. +my $inst_good = <<EOF ; +int main(int argc, char *argv[]) {++_citrun.data[0]; + while ((++_citrun.data[1], (++_citrun.data[1], argc < 17))) + argc++; + + while ((++_citrun.data[4], ((++_citrun.data[4], argc && argv)))); + return (++_citrun.data[5], 0); +} +EOF + +my $check_good = <<EOF; +>> citrun_inst v0.0 (OpenBSD-6.0 amd64) +CITRUN_SHARE = '' +Switching argv[0] '' +Found source file '' +Modified command line is '' +Added clangtool argument '' +Instrumentation of '' finished: + 8 Lines of source code + 1 Function definitions + 2 While loops + 1 Return statement values + 18 Total statements + 2 Binary operators +Modified source written successfully. +Rewriting successful. +EOF + +# Run the command. +$inst->run( args => '-c while.c', chdir => $inst->curdir ); + +# This file should have been rewritten in place. +my $inst_out = read_file($inst->workdir . '/while.c'); + +# Sanitize paths from stdout. +my $check_out = $inst->stdout; +$check_out =~ s/^.*Milliseconds spent.*\n//gm; +$check_out =~ s/'.*'/''/gm; + +eq_or_diff( $inst_out, $inst_good, 'is instrumented file identical', { context => 3 } ); +eq_or_diff $check_good, $check_out, 'is citrun_inst output identical'; +is( $inst->stderr, '', 'is citrun_inst stderr silent' ); +is( $? >> 8, 0, 'is citrun_inst exit code 0' );