citrun

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

commit 4ed9e8cf3e39630828ece1384e2fe3960951ca37
parent 502b644fc423f50c25b0fb04064a599d7875a953
Author: Kyle Milz <kyle@0x30.net>
Date:   Wed, 10 Aug 2016 01:27:23 -0600

Test: remove ability to provide custom src

Diffstat:
MTest/Project.pm | 88+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
Mt/rt_dynamic.t | 57+++++----------------------------------------------------
Mt/rt_reconnect.t | 20+++++++-------------
Mt/rt_static.t | 23+++++++++--------------
Mt/term_basic.t | 14++------------
5 files changed, 78 insertions(+), 124 deletions(-)

diff --git a/Test/Project.pm b/Test/Project.pm @@ -12,57 +12,79 @@ sub new { bless ($self, $class); # Make new temporary directory, clean it up at exit - $self->{tmp_dir} = tempdir( CLEANUP => 1 ); - $self->{src_files} = []; - $self->{prog_name} = "program"; + my $tmp_dir = tempdir( CLEANUP => 1 ); - my $tmp_dir = $self->{tmp_dir}; - $tmp_dir = "/private$self->{tmp_dir}" if ($^O eq 'darwin'); - $ENV{CITRUN_SOCKET} = "$tmp_dir/test.socket"; + # Use the tools in this source tree + $ENV{PATH} = cwd . "/src:$ENV{PATH}"; + $ENV{CITRUN_SOCKET} = "test.socket"; + chdir $tmp_dir; - return $self; -} + open( my $src_fh, ">", "one.c" ); + print $src_fh <<EOF; +#include <err.h> +#include <stdlib.h> + +long long fib(long long); +void print_output(long long); -sub add_src { - my ($self, $source) = @_; - my $num_src_files = scalar(@{ $self->{src_files} }); +int +main(int argc, char *argv[]) +{ + long long n; - # Create temporary file name - my $src_name = "source_$num_src_files.c"; + if (argc != 2) + errx(1, "argc != 2"); - # Write source code to temp directory - open( my $src_fh, ">", "$self->{tmp_dir}/$src_name" ); - syswrite( $src_fh, $source ); + n = atoi(argv[1]); + + print_output(fib(n)); + return 0; +} +EOF close( $src_fh ); - push @{ $self->{src_files} }, $src_name; + open( my $src_fh, ">", "two.c" ); + print $src_fh <<EOF; +long long +fib(long long n) +{ + if (n == 0) + return 0; + else if (n == 1) + return 1; + + return fib(n - 1) + fib(n - 2); } +EOF + close( $src_fh ); -sub compile { - my ($self) = @_; - my $tmp_dir = $self->{tmp_dir}; - my $src_files = join(" ", @{ $self->{src_files} }); + open( my $src_fh, ">", "three.c" ); + print $src_fh <<EOF; +#include <stdio.h> - my $jamfile = <<EOF; -Main $self->{prog_name} : $src_files ; +void +print_output(long long n) +{ + fprintf(stderr, "%lli", n); + return; +} EOF - # Write Jamfile to temp directory - open( my $jamfile_fh, ">", "$tmp_dir/Jamfile" ); - syswrite( $jamfile_fh, $jamfile ); - close( $jamfile_fh ); + close( $src_fh ); - # Use the tools in this source tree - $ENV{PATH} = cwd . "/src:$ENV{PATH}"; + open( my $src_fh, ">", "Jamfile" ); + print $src_fh <<EOF; +Main program : one.c two.c three.c ; +EOF - my $ret = system( "cd $tmp_dir && jam" ); + my $ret = system( "jam" ); die "jam failed: $ret\n" if ($ret); + + return $self; } sub run { my ($self, @args) = @_; - - my $tmp_dir = $self->{tmp_dir}; - $self->{pid} = open2(\*CHLD_OUT, undef, "$tmp_dir/$self->{prog_name}", @args); + $self->{pid} = open2(\*CHLD_OUT, undef, "program", @args); } sub kill { diff --git a/t/rt_dynamic.t b/t/rt_dynamic.t @@ -7,60 +7,13 @@ use Time::HiRes qw( usleep ); my $project = Test::Project->new(); my $viewer = Test::Viewer->new(); -$project->add_src(<<EOF); -#include <err.h> -#include <stdlib.h> - -long long fib(long long); -void print_output(long long); - -int -main(int argc, char *argv[]) -{ - long long n; - - if (argc != 2) - errx(1, "argc != 2"); - - n = atoi(argv[1]); - - print_output(fib(n)); - return 0; -} -EOF - -$project->add_src(<<EOF); -long long -fib(long long n) -{ - if (n == 0) - return 0; - else if (n == 1) - return 1; - - return fib(n - 1) + fib(n - 2); -} -EOF - -$project->add_src(<<EOF); -#include <stdio.h> - -void -print_output(long long n) -{ - fprintf(stderr, "%lli", n); - return; -} -EOF - -$project->compile(); $project->run(45); $viewer->accept(); $viewer->cmp_static_data([ - [ "source_0.c", 20 ], - [ "source_1.c", 11 ], - [ "source_2.c", 9 ], + [ "one.c", 20 ], + [ "three.c", 9 ], + [ "two.c", 11 ], ]); # Check initial execution counts @@ -79,14 +32,14 @@ is( $lines[15], 0, "src 0 line 15 check" ); is( $lines[16], 2, "src 0 line 16 check" ); is( $lines[$_], 0, "src 0 line $_ check" ) for (17..18); -my @lines = @{ $data->{$s1} }; +my @lines = @{ $data->{$s2} }; cmp_ok ( $lines[$_], ">", 1, "src 1 line $_ check" ) for (0..2); cmp_ok ( $lines[$_], ">", 10, "src 1 line $_ check" ) for (3..6); is( $lines[7], 0, "src 1 line 7 check" ); cmp_ok( $lines[8], ">", 10, "src 1 line 8 check" ); is( $lines[9], 0, "src 1 line 9 check" ); -my @lines = @{ $data->{$s2} }; +my @lines = @{ $data->{$s1} }; is( $lines[$_], 0, "src 2 line $_ check" ) for (0..8); for (1..60) { diff --git a/t/rt_reconnect.t b/t/rt_reconnect.t @@ -1,28 +1,22 @@ use strict; -use Test::More tests => 5; +use Test::More tests => 9; use Test::Project; use Test::Viewer; my $project = Test::Project->new(); -$project->add_src(<<EOF); -int -main(void) -{ - while (1); - return 0; -} -EOF - -$project->compile(); -$project->run(); +$project->run(45); # Give the runtime a chance to reconnect sleep(1); my $viewer = Test::Viewer->new(); $viewer->accept(); -$viewer->cmp_static_data([ [ "source_0.c", 7 ] ]); +$viewer->cmp_static_data([ + [ "one.c", 20 ], + [ "three.c", 9 ], + [ "two.c", 11 ], +]); $project->kill(); my ($ret, $err) = $project->wait(); diff --git a/t/rt_static.t b/t/rt_static.t @@ -1,28 +1,19 @@ use strict; use Cwd; -use Test::More tests => 18; +use Test::More tests => 22; use Test::Project; use Test::Viewer; my $project = Test::Project->new(); my $viewer = Test::Viewer->new(); -$project->add_src(<<EOF); -int -main(void) -{ - while (1); - return 0; -} -EOF -$project->compile(); -$project->run(); +$project->run(45); $viewer->accept(); is( $viewer->{maj}, 0, "protocol major version" ); is( $viewer->{min}, 0, "protocol minor version" ); -is( $viewer->{ntus}, 1, "translation unit count" ); -is( $viewer->{nlines}, 7, "total program lines" ); +is( $viewer->{ntus}, 3, "translation unit count" ); +is( $viewer->{nlines}, 40, "total program lines" ); is( $viewer->{progname}, "program", "program name" ); is( $viewer->{cwd}, getcwd, "current working dir" ); is( @{ $viewer->{pids} }, 3, "number of pids" ); @@ -33,7 +24,11 @@ cmp_ok( $viewer->{pids}->[1], "<", 100000, "ppid check upper" ); cmp_ok( $viewer->{pids}->[2], ">", 1, "pgrp check lower" ); cmp_ok( $viewer->{pids}->[2], "<", 100000, "pgrp check upper" ); -$viewer->cmp_static_data([ [ "source_0.c", 7 ] ]); +$viewer->cmp_static_data([ + [ "one.c", 20 ], + [ "three.c", 9 ], + [ "two.c", 11 ], +]); $project->kill(); my ($ret, $err) = $project->wait(); diff --git a/t/term_basic.t b/t/term_basic.t @@ -5,21 +5,11 @@ use Test::Project; my $project = Test::Project->new(); -$project->add_src(<<EOF); -int -main(void) -{ - while (1); - return 0; -} -EOF -$project->compile(); - -my $exp = Expect->spawn("src/citrun-term"); +my $exp = Expect->spawn("citrun-term"); my $waiting = "Waiting for connection on $ENV{CITRUN_SOCKET}"; ok(1) if (defined $exp->expect(undef, ($waiting))); -$project->run(); +$project->run(45); $exp->expect(undef, ("program")); $project->kill();