citrun

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

wrap_cmake.t (2330B)


      1 #
      2 # Test that wrapping the 'cmake' build system produces instrumented binaries.
      3 #
      4 use File::Which;
      5 use Modern::Perl;
      6 use Test::Cmd;
      7 use Test::Differences;
      8 use Test::More;
      9 
     10 plan skip_all => 'cmake not found' unless (which 'cmake');
     11 plan tests => 8;
     12 
     13 use lib 't';
     14 require utils;
     15 
     16 
     17 my $wrap = Test::Cmd->new( prog => 'bin/citrun_wrap', workdir => '' );
     18 
     19 $wrap->write( 'CMakeLists.txt', <<'EOF' );
     20 cmake_minimum_required (VERSION 2.9)
     21 project (program)
     22 add_executable(program main.c)
     23 EOF
     24 
     25 # Log file after make is ran on Makefile generated by CMake.
     26 my $log_good = <<EOF;
     27 >> citrun_inst
     28 Compilers path = ''
     29 PATH = ''
     30 Found source file ''
     31 Command line is ''
     32 Added clangtool argument ''
     33 Instrumentation of '' finished:
     34     6 Lines of source code
     35     1 Function definitions
     36     1 Return statement values
     37     3 Total statements
     38 Modified source written successfully.
     39 Forked compiler ''
     40 Rewritten source compile successful
     41 Restored ''
     42 >> citrun_inst
     43 Compilers path = ''
     44 PATH = ''
     45 Link detected, adding '' to command line.
     46 Command line is ''
     47 No source files found on command line.
     48 EOF
     49 
     50 $wrap->write( 'main.c', <<'EOF' );
     51 int
     52 main(void)
     53 {
     54 	return 0;
     55 }
     56 EOF
     57 
     58 # Run CMake.
     59 $wrap->run( args => 'cmake .', chdir => $wrap->curdir );
     60 
     61 print $wrap->stdout;
     62 is( $wrap->stderr,	'',	'citrun_wrap cmake stderr empty');
     63 is( $? >> 8,		0,	'citrun_wrap cmake exit code 0');
     64 
     65 # Now run whatever platform specific-ish files CMake decided to give us.
     66 if ($^O eq "MSWin32") {
     67 	# MSBuild currently does not work.
     68 	$wrap->run( args => 'devenv /useenv program.sln /Build', chdir => $wrap->curdir );
     69 } else {
     70 	$wrap->run( args => 'make', chdir => $wrap->curdir );
     71 }
     72 
     73 my $log_out;
     74 $wrap->read( \$log_out, 'citrun.log' );
     75 $log_out = utils::clean_citrun_log($log_out);
     76 
     77 eq_or_diff( $log_out, $log_good, 'citrun.log identical', { context => 3 } );
     78 print $wrap->stdout;
     79 is( $wrap->stderr,	'',	'citrun_wrap make stderr empty');
     80 is( $? >> 8,		0,	'citrun_wrap make exit code 0');
     81 
     82 # Check the instrumented program runs.
     83 $wrap->run( prog => $wrap->workdir . "/program", chdir => $wrap->curdir );
     84 
     85 is( $wrap->stdout,	'',	'instrumented program stdout empty');
     86 isnt( $wrap->stderr,	'',	'instrumented program stderr not empty');
     87 is( $? >> 8,		0,	'instrumented program exit code 0');
     88 unlink "/tmp/citrun.out";
     89 #ok "is runtime shared memory file created" test -f procdir/program_*