|
From: <sv...@va...> - 2006-01-20 14:21:36
|
Author: sewardj
Date: 2006-01-20 14:21:28 +0000 (Fri, 20 Jan 2006)
New Revision: 5568
Log:
More function wrapping tests.
Added:
trunk/memcheck/tests/wrap7.c
trunk/memcheck/tests/wrap7.stderr.exp
trunk/memcheck/tests/wrap7.stdout.exp
trunk/memcheck/tests/wrap7.vgtest
trunk/memcheck/tests/wrap7so.c
trunk/memcheck/tests/wrap8.c
trunk/memcheck/tests/wrap8.stderr.exp
trunk/memcheck/tests/wrap8.stdout.exp
trunk/memcheck/tests/wrap8.vgtest
Modified:
trunk/memcheck/tests/Makefile.am
Modified: trunk/memcheck/tests/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/Makefile.am 2006-01-19 17:44:38 UTC (rev 5567)
+++ trunk/memcheck/tests/Makefile.am 2006-01-20 14:21:28 UTC (rev 5568)
@@ -114,6 +114,8 @@
wrap4.vgtest wrap4.stdout.exp wrap4.stderr.exp \
wrap5.vgtest wrap5.stdout.exp wrap5.stderr.exp \
wrap6.vgtest wrap6.stdout.exp wrap6.stderr.exp \
+ wrap7.vgtest wrap7.stdout.exp wrap7.stderr.exp \
+ wrap8.vgtest wrap8.stdout.exp wrap8.stderr.exp \
writev.stderr.exp writev.stderr.exp2 writev.stderr.exp3 writev.vgtest \
xml1.stderr.exp xml1.stderr.exp2 xml1.stderr.exp3 \
xml1.stderr.exp64 xml1.stderr.exp64_2 xml1.stdout.exp \
@@ -147,7 +149,7 @@
trivialleak \
mismatches new_override metadata \
xml1 \
- wrap1 wrap2 wrap3 wrap4 wrap5 wrap6 \
+ wrap1 wrap2 wrap3 wrap4 wrap5 wrap6 wrap7 wrap7so.so wrap8 \
writev zeropage
=20
=20
@@ -162,6 +164,7 @@
oset_test_CFLAGS =3D $(AM_FLAG_M3264_PRI) \
-DVGA_$(VG_ARCH)=3D1 -DVGO_$(VG_OS)=3D1 \
-DVGP_$(VG_ARCH)_$(VG_OS)=3D1
+
# Don't allow GCC to inline memcpy(), because then we can't intercept it
overlap_CFLAGS =3D $(AM_CFLAGS) -fno-builtin-memcpy
stack_switch_LDADD =3D -lpthread
@@ -175,6 +178,19 @@
new_nothrow_SOURCES =3D new_nothrow.cpp
new_override_SOURCES =3D new_override.cpp
=20
+# Build shared object for wrap7
+wrap7_SOURCES =3D wrap7.c
+wrap7_DEPENDENCIES =3D wrap7so.so
+wrap7_LDFLAGS =3D $(AM_FLAG_M3264_PRI) \
+ -Wl,-rpath,$(top_builddir)/memcheck/tests
+wrap7_LDADD =3D wrap7so.so
+wrap7so_so_SOURCES =3D wrap7so.c
+wrap7so_so_LDADD =3D=20
+wrap7so_so_DEPENDENCIES =3D=20
+wrap7so_so_LDFLAGS =3D -fpic $(AM_FLAG_M3264_PRI) \
+ -Wl,-soname -Wl,wrap7so.so -shared
+wrap7so_so_CFLAGS =3D -fpic $(AM_FLAG_M3264_PRI)
+
# Valgrind unit self-tests
#hello_LDFLAGS =3D -Wl,-defsym,valt_load_address=3D0x50000000 \
# -Wl,-T,$(top_builddir)/valt_load_address.lds
Added: trunk/memcheck/tests/wrap7.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/wrap7.c (rev 0)
+++ trunk/memcheck/tests/wrap7.c 2006-01-20 14:21:28 UTC (rev 5568)
@@ -0,0 +1,30 @@
+
+#include <stdio.h>
+#include "valgrind.h"
+
+/* The simplest possible wrapping test: just call a wrapped function
+ and check we run the wrapper instead. Except: the wrapped
+ function is in a different shared object. This causes some
+ additional complications on ppc64-linux, hence another test. */
+
+extern void actual ( void );
+
+/* The wrapper. The function being wrapped is in a .so with soname
+ "wrap7so.so". */
+void I_WRAP_SONAME_FNNAME_ZU(wrap7soZdso,actual) ( void )
+{
+ OrigFn orig;
+ VALGRIND_GET_ORIG_FN(orig);
+ printf("wrapper-pre\n");
+ CALL_FN_v_v(orig);
+ printf("wrapper-post\n");
+}
+
+/* --------------- */
+
+int main ( void )
+{
+ printf("starting\n");
+ actual();
+ return 0;
+}
Added: trunk/memcheck/tests/wrap7.stderr.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Added: trunk/memcheck/tests/wrap7.stdout.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/wrap7.stdout.exp (rev 0)
+++ trunk/memcheck/tests/wrap7.stdout.exp 2006-01-20 14:21:28 UTC (rev 55=
68)
@@ -0,0 +1,4 @@
+starting
+wrapper-pre
+in actual-so
+wrapper-post
Added: trunk/memcheck/tests/wrap7.vgtest
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/wrap7.vgtest (rev 0)
+++ trunk/memcheck/tests/wrap7.vgtest 2006-01-20 14:21:28 UTC (rev 5568)
@@ -0,0 +1,2 @@
+prog: wrap7
+vgopts: -q
Added: trunk/memcheck/tests/wrap7so.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/wrap7so.c (rev 0)
+++ trunk/memcheck/tests/wrap7so.c 2006-01-20 14:21:28 UTC (rev 5568)
@@ -0,0 +1,10 @@
+
+#include <stdio.h>
+#include <unistd.h>
+/* The "original" function */
+
+void actual ( void )
+{
+ printf("in actual-so\n");
+}
+
Added: trunk/memcheck/tests/wrap8.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/wrap8.c (rev 0)
+++ trunk/memcheck/tests/wrap8.c 2006-01-20 14:21:28 UTC (rev 5568)
@@ -0,0 +1,102 @@
+
+#include <stdio.h>
+#include <malloc.h>
+#include "valgrind.h"
+
+/* This is the same as wrap5.c, except that the recursion depth is 16.
+ This is intended to check that on ppc64-linux, which uses a
+ 16-entry per-thread stack, the resulting stack overflow is caught.
+ (Undetected overflows in redirection stacks are very bad news; they
+ cause guest code to fail in all sorts of strange ways.)
+
+ Hence this test has two expected outcomes:
+ - on ppc64-linux, a stack overflow is caught, and V aborts.
+ - on everything else, it runs successfully to completion.
+*/
+
+typedef=20
+ struct _Lard {
+ struct _Lard* next;=20
+ char stuff[999];=20
+ }
+ Lard;
+
+Lard* lard =3D NULL;
+static int ctr =3D 0;
+
+void addMoreLard ( void )
+{
+ Lard* p;
+ ctr++;
+ if ((ctr % 3) =3D=3D 1) {
+ p =3D malloc(sizeof(Lard));
+ p->next =3D lard;
+ lard =3D p;
+ }
+}
+
+
+static int fact1 ( int n );
+static int fact2 ( int n );
+
+/* This is needed to stop gcc4 turning 'fact' into a loop */
+__attribute__((noinline))
+int mul ( int x, int y ) { return x * y; }
+
+int fact1 ( int n )
+{
+ addMoreLard();
+ if (n =3D=3D 0) return 1; else return mul(n, fact2(n-1));
+}
+int fact2 ( int n )
+{
+ addMoreLard();
+ if (n =3D=3D 0) return 1; else return mul(n, fact1(n-1));
+}
+
+
+int I_WRAP_SONAME_FNNAME_ZU(NONE,fact1) ( int n )
+{
+ int r;
+ OrigFn fn;
+ VALGRIND_GET_ORIG_FN(fn);
+ printf("in wrapper1-pre: fact(%d)\n", n); fflush(stdout);
+ addMoreLard();
+ CALL_FN_W_W(r, fn, n);
+ addMoreLard();
+ printf("in wrapper1-post: fact(%d) =3D %d\n", n, r); fflush(stdout);
+ if (n >=3D 3) r +=3D fact2(2);
+ return r;
+}
+
+int I_WRAP_SONAME_FNNAME_ZU(NONE,fact2) ( int n )
+{
+ int r;
+ OrigFn fn;
+ VALGRIND_GET_ORIG_FN(fn);
+ printf("in wrapper2-pre: fact(%d)\n", n); fflush(stdout);
+ addMoreLard();
+ CALL_FN_W_W(r, fn, n);
+ addMoreLard();
+ printf("in wrapper2-post: fact(%d) =3D %d\n", n, r); fflush(stdout);
+ return r;
+}
+
+/* --------------- */
+
+int main ( void )
+{
+ int r, n =3D 15; /* 14 succeeds on ppc64-linux, >=3D 15 fails */
+ Lard *p, *p_next;
+ printf("computing fact1(%d)\n", n); fflush(stdout);
+ r =3D fact1(n);
+ printf("fact1(%d) =3D %d\n", n, r); fflush(stdout);
+
+ printf("allocated %d Lards\n", ctr); fflush(stdout);
+ for (p =3D lard; p; p =3D p_next) {
+ p_next =3D p->next;
+ free(p);
+ }
+
+ return 0;
+}
Added: trunk/memcheck/tests/wrap8.stderr.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/wrap8.stderr.exp (rev 0)
+++ trunk/memcheck/tests/wrap8.stderr.exp 2006-01-20 14:21:28 UTC (rev 55=
68)
@@ -0,0 +1,17 @@
+Emulation fatal error -- Valgrind cannot continue:
+ PPC64 function redirection stack overflow
+ at 0x........: ???
+ by 0x........: fact2 (wrap8.c:78)
+ by 0x........: ...
+ by 0x........: fact1 (wrap8.c:65)
+ by 0x........: ...
+ by 0x........: fact2 (wrap8.c:79)
+ by 0x........: ...
+ by 0x........: fact1 (wrap8.c:65)
+ by 0x........: ...
+ by 0x........: fact2 (wrap8.c:79)
+ by 0x........: ...
+ by 0x........: fact1 (wrap8.c:65)
+
+Valgrind has to exit now. Sorry.
+
Added: trunk/memcheck/tests/wrap8.stdout.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/wrap8.stdout.exp (rev 0)
+++ trunk/memcheck/tests/wrap8.stdout.exp 2006-01-20 14:21:28 UTC (rev 55=
68)
@@ -0,0 +1,17 @@
+computing fact1(15)
+in wrapper1-pre: fact(15)
+in wrapper2-pre: fact(14)
+in wrapper1-pre: fact(13)
+in wrapper2-pre: fact(12)
+in wrapper1-pre: fact(11)
+in wrapper2-pre: fact(10)
+in wrapper1-pre: fact(9)
+in wrapper2-pre: fact(8)
+in wrapper1-pre: fact(7)
+in wrapper2-pre: fact(6)
+in wrapper1-pre: fact(5)
+in wrapper2-pre: fact(4)
+in wrapper1-pre: fact(3)
+in wrapper2-pre: fact(2)
+in wrapper1-pre: fact(1)
+in wrapper2-pre: fact(0)
Added: trunk/memcheck/tests/wrap8.vgtest
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/wrap8.vgtest (rev 0)
+++ trunk/memcheck/tests/wrap8.vgtest 2006-01-20 14:21:28 UTC (rev 5568)
@@ -0,0 +1,2 @@
+prog: wrap8
+vgopts: -q
|