citrun

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

commit 6987bedb4002e844f21e04759a7f58411c6f1303
parent b2a6efb01639702c70766af529b1ec286b12875d
Author: Kyle Milz <kyle@0x30.net>
Date:   Sun, 31 Jul 2016 11:34:45 -0600

src: delete CITRUN_TESTING

Diffstat:
MTest/Project.pm | 33---------------------------------
Msrc/inst_main.cc | 4----
Mt/fibonacci.t | 43+------------------------------------------
Mt/hello_world.t | 23++---------------------
Mt/inst_for.t | 26++------------------------
Mt/inst_if.t | 35++---------------------------------
Dt/inst_preamble.t | 66------------------------------------------------------------------
Mt/inst_return.t | 26++------------------------
Mt/inst_switch.t | 30++----------------------------
Mt/inst_while.t | 28++--------------------------
10 files changed, 13 insertions(+), 301 deletions(-)

diff --git a/Test/Project.pm b/Test/Project.pm @@ -22,9 +22,6 @@ sub add_src { my ($self, $source) = @_; my $num_src_files = scalar(@{ $self->{src_files} }); - # Runtime behavior switch. Usually leaves behind changed files. - $ENV{CITRUN_TESTING} = 1; - # Create temporary file name my $src_name = "source_$num_src_files.c"; @@ -56,36 +53,6 @@ EOF die "make failed: $ret\n" if ($ret); } -sub instrumented_src { - my ($self) = @_; - - open( my $inst_fh, "<", "$self->{tmp_dir}/source_0.c" ); - - # Knock off the instrumentation preamble - my $line = <$inst_fh> for (1..31); - - my $inst_src; - while (my $line = <$inst_fh>) { - $inst_src .= $line; - } - close( $inst_fh ); - return $inst_src; -} - -sub inst_src_preamble { - my ($self) = @_; - - open( my $inst_fh, "<", "$self->{tmp_dir}/source_0.c" ); - - my $preamble; - for (1..31) { - my $line = <$inst_fh>; - $preamble .= $line; - } - close( $inst_fh ); - return $preamble; -} - sub run { my ($self, @args) = @_; diff --git a/src/inst_main.cc b/src/inst_main.cc @@ -115,10 +115,6 @@ CitrunInst::CitrunInst(int argc, char *argv[]) : // Keep track of original source file names m_source_files.push_back(arg); - if (std::getenv("CITRUN_TESTING")) - // Don't copy and restore original source files - continue; - char *dst_fn; if ((dst_fn = std::tmpnam(NULL)) == NULL) err(1, "tmpnam"); diff --git a/t/fibonacci.t b/t/fibonacci.t @@ -1,13 +1,10 @@ use strict; -use Test::More tests => 7; -use Test::Differences; - +use Test::More tests => 5; use Test::Project; use Test::Viewer; my $viewer = Test::Viewer->new(); my $project = Test::Project->new(); -unified_diff; $project->add_src(<<EOF); #include <stdio.h> @@ -44,44 +41,6 @@ EOF $project->compile(); -my $inst_src_good = <<EOF; -#include <stdio.h> -#include <stdlib.h> - -long long -fibonacci(long long n) -{++_citrun_lines[4];++_citrun_lines[5];++_citrun_lines[6]; - if ((++_citrun_lines[7], n == 0)) - return (++_citrun_lines[8], 0); - else if ((++_citrun_lines[9], n == 1)) - return (++_citrun_lines[10], 1); - - return (++_citrun_lines[12], (++_citrun_lines[12], fibonacci(n - 1)) + (++_citrun_lines[12], fibonacci(n - 2))); -} - -int -main(int argc, char *argv[]) -{citrun_start();++_citrun_lines[15];++_citrun_lines[16];++_citrun_lines[17]; - long long n; - - if ((++_citrun_lines[20], argc != 2)) { - (++_citrun_lines[21], printf("usage: %s <N>", argv[0])); - return (++_citrun_lines[22], 1); - } - - n = (++_citrun_lines[25], atoi(argv[1])); - - (++_citrun_lines[27], printf("result: %lli", (++_citrun_lines[27], fibonacci(n)))); - - return (++_citrun_lines[29], 0); -} -EOF - -my $inst_src = $project->instrumented_src(); -ok( $inst_src ); - -eq_or_diff $inst_src, $inst_src_good, "instrumented source comparison"; - $project->run(); my ($ret, $err) = $project->wait(); is($ret, 1, "instrumented program check return code"); diff --git a/t/hello_world.t b/t/hello_world.t @@ -1,13 +1,10 @@ use strict; -use Test::More tests => 4; -use Test::Differences; - +use Test::More tests => 2; use Test::Project; use Test::Viewer; my $viewer = Test::Viewer->new(); my $project = Test::Project->new(); -unified_diff; $project->add_src(<<EOF); #include <stdio.h> @@ -21,24 +18,8 @@ main(void) EOF $project->compile(); - -my $inst_src_good = <<EOF; -#include <stdio.h> - -int -main(void) -{citrun_start();++_citrun_lines[3];++_citrun_lines[4];++_citrun_lines[5]; - (++_citrun_lines[6], printf("hello, world!")); - return (++_citrun_lines[7], 0); -} -EOF - -my $inst_src = $project->instrumented_src(); -ok( $inst_src ); - -eq_or_diff $inst_src, $inst_src_good, "instrumented source comparison"; - $project->run(); + my ($ret, $err) = $project->wait(); is( $ret, 0, "instrumented program check return code" ); is( $err, "hello, world!", "instrumented program check error message" ); diff --git a/t/inst_for.t b/t/inst_for.t @@ -1,13 +1,10 @@ use strict; -use Test::More tests => 3; -use Test::Differences; - +use Test::More tests => 1; use Test::Project; use Test::Viewer; my $viewer = Test::Viewer->new(); my $project = Test::Project->new(); -unified_diff; $project->add_src(<<EOF); int @@ -24,26 +21,7 @@ main(void) EOF $project->compile(); - -my $inst_src_good = <<EOF; -int -main(void) -{citrun_start();++_citrun_lines[1];++_citrun_lines[2];++_citrun_lines[3]; - int i; - - for (i = 0; (++_citrun_lines[6], i < 19); i++) { - i++; - } - - return (++_citrun_lines[10], i); -} -EOF - -my $inst_src = $project->instrumented_src(); -ok( $inst_src ); - -eq_or_diff $inst_src, $inst_src_good, "instrumented source comparison"; - $project->run(); + my ($ret) = $project->wait(); is($ret, 20, "instrumented program check"); diff --git a/t/inst_if.t b/t/inst_if.t @@ -1,12 +1,9 @@ use strict; -use Test::More tests => 3; -use Test::Differences; - +use Test::More tests => 1; use Test::Project; my $project = Test::Project->new(); -unified_diff; $project->add_src(<<EOF); #include <stdlib.h> @@ -32,35 +29,7 @@ main(int argc, char *argv[]) EOF $project->compile(); - -my $inst_src_good = <<EOF; -#include <stdlib.h> - -int -main(int argc, char *argv[]) -{citrun_start();++_citrun_lines[3];++_citrun_lines[4];++_citrun_lines[5]; - if ((++_citrun_lines[6], argc == 1)) - return (++_citrun_lines[7], 1); - else - (++_citrun_lines[9], exit(14)); - - if ((++_citrun_lines[11], argc == 2)) { - return (++_citrun_lines[12], 5); - } - else if ((++_citrun_lines[14], argc == 3)) { - return (++_citrun_lines[15], 0); - } - else { - (++_citrun_lines[18], exit(0)); - } -} -EOF - -my $inst_src = $project->instrumented_src(); -ok( $inst_src ); - -eq_or_diff $inst_src, $inst_src_good, "instrumented source comparison"; - $project->run(); + my ($ret) = $project->wait(); is($ret, 1, "instrumented program check"); diff --git a/t/inst_preamble.t b/t/inst_preamble.t @@ -1,66 +0,0 @@ -use strict; -use Test::More tests => 4; -use Test::Differences; - -use Test::Project; - -my $project = Test::Project->new(); -unified_diff; - -$project->add_src(<<EOF); -int -main(void) -{ - return 0; -} -EOF - -$project->compile(); - -my $tmp_dir = $project->get_tmpdir(); - -$tmp_dir = substr( $tmp_dir, 8 ) if ($^O eq "darwin"); - -my $preamble_good = <<EOF; -#ifdef __cplusplus -extern "C" { -#endif -#include <stdint.h> -struct citrun_node { - uint64_t *lines_ptr; - uint32_t size; - uint32_t inst_sites; - const char *file_name; - struct citrun_node *next; - uint64_t *old_lines; - uint64_t *tmp_lines; - uint32_t *diffs; -}; -void citrun_node_add(struct citrun_node *); -void citrun_start(); - -static uint64_t _citrun_lines[6]; -static struct citrun_node _citrun_node = { - _citrun_lines, - 6, - 1, - "$tmp_dir/source_0.c", -}; -__attribute__((constructor)) -static void citrun_constructor() { - citrun_node_add(&_citrun_node); -} -#ifdef __cplusplus -} -#endif -EOF - -my $preamble = $project->inst_src_preamble(); -ok( $preamble ); - -eq_or_diff $preamble, $preamble_good, "instrumented source comparison"; - -$project->run(); -my ($ret, $err) = $project->wait(); -is($ret, 0, "return code"); -is($err, undef, "stderr empty"); diff --git a/t/inst_return.t b/t/inst_return.t @@ -1,14 +1,11 @@ use strict; -use Test::More tests => 3; -use Test::Differences; - +use Test::More tests => 1; use Test::Project; use Test::Viewer; my $viewer = Test::Viewer->new(); my $project = Test::Project->new(); -unified_diff; $project->add_src(<<EOF); int foo() { @@ -25,26 +22,7 @@ int main(void) { EOF $project->compile(); - -my $inst_src_good = <<EOF; -int foo() {++_citrun_lines[1]; - return (++_citrun_lines[2], 0); -} - -int main(void) {citrun_start();++_citrun_lines[5]; - return (++_citrun_lines[6], 10); - - return (++_citrun_lines[8], 10 + 10); - - return (++_citrun_lines[10], (++_citrun_lines[10], foo())); -} -EOF - -my $inst_src = $project->instrumented_src(); -ok( $inst_src ); - -eq_or_diff $inst_src, $inst_src_good, "instrumented source comparison"; - $project->run(); + my ($ret) = $project->wait(); is($ret, 10, "instrumented program check"); diff --git a/t/inst_switch.t b/t/inst_switch.t @@ -1,14 +1,10 @@ use strict; - -use Test::More tests => 3; -use Test::Differences; - +use Test::More tests => 1; use Test::Project; use Test::Viewer; my $viewer = Test::Viewer->new(); my $project = Test::Project->new(); -unified_diff; $project->add_src(<<EOF); int @@ -28,29 +24,7 @@ main(void) EOF $project->compile(); - -my $inst_src_good = <<EOF; -int -main(void) -{citrun_start();++_citrun_lines[1];++_citrun_lines[2];++_citrun_lines[3]; - int i; - - switch ((++_citrun_lines[6], i)) { - case 0: - break; - case 1: - break; - } - - return (++_citrun_lines[13], 0); -} -EOF - -my $inst_src = $project->instrumented_src(); -ok( $inst_src ); - -eq_or_diff $inst_src, $inst_src_good, "instrumented source comparison"; - $project->run(); + my ($ret) = $project->wait(); is($ret, 0, "instrumented program check"); diff --git a/t/inst_while.t b/t/inst_while.t @@ -1,14 +1,10 @@ use strict; - -use Test::More tests => 3; -use Test::Differences; - +use Test::More tests => 1; use Test::Project; use Test::Viewer; my $viewer = Test::Project->new(); my $project = Test::Project->new(); -unified_diff; $project->add_src(<<EOF); int @@ -26,27 +22,7 @@ main(void) EOF $project->compile(); - -my $inst_src_good = <<EOF; -int -main(void) -{citrun_start();++_citrun_lines[1];++_citrun_lines[2];++_citrun_lines[3]; - int i; - - i = 0; - while ((++_citrun_lines[7], i < 17)) { - i++; - } - - return (++_citrun_lines[11], i); -} -EOF - -my $inst_src = $project->instrumented_src(); -ok( $inst_src ); - -eq_or_diff $inst_src, $inst_src_good, "instrumented source comparison"; - $project->run(); + my ($ret) = $project->wait(); is($ret, 17, "instrumented program check");