commit 360d417300421ddf958c476165d01cce4b694da9
parent bfc444bf94a1495d35256ab6301bae877c4674bd
Author: Kyle Milz <kyle@windows.krwm.net>
Date: Thu, 5 Jan 2017 00:03:17 -0800
t: convert e2e_basic.sh to perl
Diffstat:
D | t/e2e_basic.sh | | | 60 | ------------------------------------------------------------ |
A | t/e2e_intent.t | | | 88 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 88 insertions(+), 60 deletions(-)
diff --git a/t/e2e_basic.sh b/t/e2e_basic.sh
@@ -1,60 +0,0 @@
-#!/bin/sh -u
-#
-# Check that a simple program can execute successfully with instrumentation.
-#
-. t/utils.subr
-plan 7
-
-
-cat <<EOF > fib.c
-#include <stdio.h>
-#include <stdlib.h>
-
-int fibonacci(int n) {
- if (n == 0)
- return 0;
- else if (n == 1)
- return 1;
-
- return fibonacci(n - 1) + fibonacci(n - 2);
-}
-
-int main(int argc, char *argv[]) {
- int n;
-
- if (argc != 2)
- return 1;
-
- n = atoi(argv[1]);
- printf("%i", fibonacci(n));
-
- return 0;
-}
-EOF
-
-cat <<EOF > check.good
-Summary:
- 1 Source files used as input
- 1 Application link commands
- 1 Rewrite successes
- 1 Rewritten source compile successes
-
-Totals:
- 24 Lines of source code
- 2 Function definitions
- 3 If statements
- 5 Return statement values
- 5 Call expressions
- 64 Total statements
- 7 Binary operators
-EOF
-
-ok "is instrumented compile successful" cc -o fib fib.c
-ok "running citrun_check" citrun_check -o check.out
-
-strip_millis check.out
-ok "citrun_check diff" diff -u check.good check.out
-
-ok_program "fib with no args" 1 "" ./fib
-ok_program "fib of 10" 0 "55" ./fib 10
-ok_program "fib of 20" 0 "6765" ./fib 20
diff --git a/t/e2e_intent.t b/t/e2e_intent.t
@@ -0,0 +1,88 @@
+#
+# Make sure the intention of a program isn't altered by instrumentation.
+# Show this by getting correct results from an instrumented program.
+#
+use strict;
+use warnings;
+use t::utils;
+plan tests => 11;
+
+my $e2e = Test::Cmd->new( prog => 'citrun_wrap', workdir => '' );
+
+$e2e->write( 'fib.c', <<EOF );
+#include <stdio.h>
+#include <stdlib.h>
+
+int fibonacci(int n) {
+ if (n == 0)
+ return 0;
+ else if (n == 1)
+ return 1;
+
+ return fibonacci(n - 1) + fibonacci(n - 2);
+}
+
+int main(int argc, char *argv[]) {
+ int n;
+
+ if (argc != 2)
+ return 1;
+
+ n = atoi(argv[1]);
+ printf("%i", fibonacci(n));
+
+ return 0;
+}
+EOF
+
+if ($^O eq "MSWin32") {
+ $e2e->run( args => 'cl /nologo fib.c', chdir => $e2e->curdir );
+} else {
+ $e2e->run( args => 'cc -o fib fib.c', chdir => $e2e->curdir );
+}
+
+my $log;
+$e2e->read( \$log, 'citrun.log' );
+$log = clean_citrun_log( $log );
+
+my $log_good = <<EOF;
+>> citrun_inst
+CITRUN_COMPILERS = ''
+PATH=''
+Found source file ''
+Link detected, adding '' to command line.
+Modified command line is ''
+Added clangtool argument ''
+Instrumentation of '' finished:
+ 24 Lines of source code
+ 2 Function definitions
+ 3 If statements
+ 5 Return statement values
+ 5 Call expressions
+ 64 Total statements
+ 7 Binary operators
+Modified source written successfully.
+Rewriting successful.
+Forked compiler ''
+Rewritten source compile successful
+Restored ''
+EOF
+
+print $e2e->stdout;
+is( $e2e->stderr, '', 'is citrun_wrap compile stderr silent' );
+is( $? >> 8, 0, 'is citrun_wrap compile exit code 0' );
+eq_or_diff( $log, $log_good, 'is citrun_wrap log file identical' );
+
+$e2e->run( prog => $e2e->workdir . "/fib", chdir => $e2e->curdir );
+is( $e2e->stderr, '', 'is fib stderr silent' );
+is( $? >> 8, 1, 'is fib with no args exit 1' );
+
+$e2e->run( prog => $e2e->workdir . "/fib", args => '10', chdir => $e2e->curdir );
+is( $e2e->stdout, '55', 'is fib 10 equal to 55' );
+is( $e2e->stderr, '', 'is fib 10 stderr silent' );
+is( $? >> 8, 0, 'is fib 10 exit 0' );
+
+$e2e->run( prog => $e2e->workdir . "/fib", args => '20', chdir => $e2e->curdir );
+is( $e2e->stdout, '6765', 'is fib 20 equal to 6765' );
+is( $e2e->stderr, '', 'is fib 20 stderr silent' );
+is( $? >> 8, 0, 'is fib 20 exit 0' );