commit 3fcb6f90bb230d7d653055f0d793c4f33a32731f
parent 84a441ada2c7d1da04eaa8f9a26af2c2412a1fe9
Author: Kyle Milz <milz@imac.0x30.net>
Date: Wed, 3 Mar 2021 23:32:45 -0800
t: add shared lib test
Diffstat:
A | t/e2e_shlib.t | | | 88 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 88 insertions(+), 0 deletions(-)
diff --git a/t/e2e_shlib.t b/t/e2e_shlib.t
@@ -0,0 +1,88 @@
+#
+# Check that instrumenting and loading a shared library works.
+#
+use File::Which;
+use Modern::Perl;
+use t::utils;
+
+plan skip_all => '.so platforms only' if ($^O eq 'MSWin32');
+plan tests => 15;
+
+my $wrap = Test::Cmd->new( prog => 'bin/citrun_wrap', workdir => '' );
+
+$wrap->write( 'main.c', <<EOF );
+#include "lib.h"
+
+int
+main(void)
+{
+ libfunc();
+ return 0;
+}
+EOF
+
+$wrap->write( 'lib.h', <<EOF );
+int libfunc(void);
+EOF
+
+$wrap->write( 'lib.c', <<EOF );
+#include <stdio.h>
+
+int
+libfunc(void)
+{
+ printf("lib called");
+ return 0;
+}
+EOF
+
+$wrap->run( args => 'cc -c -fpic lib.c', chdir => $wrap->curdir );
+is( $wrap->stdout, '', 'is citrun_wrap cc -c stdout silent' );
+is( $wrap->stderr, '', 'is citrun_wrap cc -c stderr silent' );
+is( $? >> 8, 0, 'is citrun_wrap cc -c exit code 0' );
+
+$wrap->run( args => 'cc -shared -o liblib.so lib.o', chdir => $wrap->curdir );
+is( $wrap->stdout, '', 'is citrun_wrap cc -shared stdout silent' );
+is( $wrap->stderr, '', 'is citrun_wrap cc -shared stderr silent' );
+is( $? >> 8, 0, 'is citrun_wrap cc -shared exit code 0' );
+
+# Don't instrument main to make sure the library can stand on its own.
+my ($compiler) = which 'cc';
+$wrap->run( prog => $compiler, args => '-L. -o main main.c -llib', chdir => $wrap->curdir );
+is( $wrap->stdout, '', 'is cc -o main -llib stdout silent' );
+is( $wrap->stderr, '', 'is cc -o main -llib stderr silent' );
+is( $? >> 8, 0, 'is citrun_wrap cc -o exit code 0' );
+
+my $log_good = <<EOF;
+Summary:
+ 2 Rewrite tool runs
+ 1 Source files used as input
+ 1 Application link commands
+ 1 Successful modified source compiles
+
+Totals:
+ 9 Lines of source code
+ 1 Function definitions
+ 1 Return statement values
+ 1 Call expressions
+ 9 Total statements
+EOF
+
+$wrap->run( prog => 'bin/citrun_report', args => 'citrun.log',
+ chdir => $wrap->curdir );
+my $wrap_stdout = $wrap->stdout;
+$wrap_stdout =~ s/.*Milliseconds spent.*\n//;
+eq_or_diff( $wrap_stdout, $log_good, 'is citrun_report output identical', { context => 3 } );
+is( $wrap->stderr, '', 'is citrun_report stderr silent' );
+is( $? >> 8, 0, 'is citrun_report exit code 0' );
+
+$ENV{LD_LIBRARY_PATH} = $wrap->workdir;
+$ENV{CITRUN_PROCDIR} = $wrap->workdir;
+$wrap->write( 'citrun_gl.lock', '' );
+
+$wrap->run( prog => $wrap->workdir . '/main', chdir => $wrap->curdir );
+is( $wrap->stdout, 'lib called', 'is instrumented program stdout silent' );
+is( $wrap->stderr, '', 'is instrumented program stderr silent' );
+is( $? >> 8, 0, 'is instrumented program exit code 0' );
+
+#my $file = get_one_shmfile( $wrap->workdir );