citrun

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

e2e_intent.t (2209B)


      1 #
      2 # Make sure the intention of a program isn't altered by instrumentation.
      3 # Show this by getting correct results from an instrumented program.
      4 #
      5 use Modern::Perl;
      6 use Test::Cmd;
      7 use Test::Differences;
      8 use Test::More tests => 11;
      9 
     10 use lib 't';
     11 require utils;
     12 
     13 
     14 my $e2e = Test::Cmd->new( prog => 'bin/citrun_wrap', workdir => '' );
     15 
     16 $e2e->write( 'fib.c', <<EOF );
     17 #include <stdio.h>
     18 #include <stdlib.h>
     19 
     20 int fibonacci(int n) {
     21 	if (n == 0)
     22 		return 0;
     23 	else if (n == 1)
     24 		return 1;
     25 
     26 	return fibonacci(n - 1) + fibonacci(n - 2);
     27 }
     28 
     29 int main(int argc, char *argv[]) {
     30 	int n;
     31 
     32 	if (argc != 2)
     33 		return 1;
     34 
     35 	n = atoi(argv[1]);
     36 	printf("%i", fibonacci(n));
     37 
     38 	return 0;
     39 }
     40 EOF
     41 
     42 $e2e->run( args => utils::os_compiler() . 'fib fib.c', chdir => $e2e->curdir );
     43 
     44 my $log;
     45 $e2e->read( \$log, 'citrun.log' );
     46 $log = utils::clean_citrun_log( $log );
     47 
     48 my $log_good = <<EOF;
     49 >> citrun_inst
     50 Compilers path = ''
     51 PATH = ''
     52 Found source file ''
     53 Link detected, adding '' to command line.
     54 Command line is ''
     55 Added clangtool argument ''
     56 Instrumentation of '' finished:
     57     24 Lines of source code
     58     2 Function definitions
     59     3 If statements
     60     5 Return statement values
     61     5 Call expressions
     62     64 Total statements
     63     7 Binary operators
     64 Modified source written successfully.
     65 Forked compiler ''
     66 Rewritten source compile successful
     67 Restored ''
     68 EOF
     69 
     70 print $e2e->stdout;
     71 is( $e2e->stderr,	'',		'citrun_wrap compile stderr silent' );
     72 is( $? >> 8,		0,		'citrun_wrap compile exit code 0' );
     73 eq_or_diff( $log,	$log_good,	'citrun_wrap log file identical' );
     74 
     75 $e2e->run( prog => $e2e->workdir . "/fib", chdir => $e2e->curdir );
     76 isnt( $e2e->stderr,	'',	'fib stderr not silent' );
     77 is( $? >> 8,		1,	'fib with no args exit 1' );
     78 unlink "/tmp/citrun.out";
     79 
     80 $e2e->run( prog => $e2e->workdir . "/fib", args => '10', chdir => $e2e->curdir );
     81 is( $e2e->stdout,	'55',	'fib 10 = 55' );
     82 isnt( $e2e->stderr,	'',	'fib 10 stderr not silent' );
     83 is( $? >> 8,		0,	'fib 10 exit 0' );
     84 unlink "/tmp/citrun.out";
     85 
     86 $e2e->run( prog => $e2e->workdir . "/fib", args => '20', chdir => $e2e->curdir );
     87 is( $e2e->stdout,	'6765',	'fib 20 = 6765' );
     88 isnt( $e2e->stderr,	'',	'fib 20 stderr not silent' );
     89 is( $? >> 8,		0,	'fib 20 exit 0' );
     90 unlink "/tmp/citrun.out";