Add tests for --partial-loads-ok= flag.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5038 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am
index 89a287f..3adf252 100644
--- a/memcheck/tests/Makefile.am
+++ b/memcheck/tests/Makefile.am
@@ -63,6 +63,8 @@
oset_test.stderr.exp oset_test.stdout.exp oset_test.vgtest \
partiallydefinedeq.vgtest partiallydefinedeq.stderr.exp \
partiallydefinedeq.stdout.exp \
+ partial_load_ok.vgtest partial_load_ok.stderr.exp \
+ partial_load_dflt.vgtest partial_load_dflt.stderr.exp \
pipe.stderr.exp pipe.vgtest \
pointer-trace.vgtest \
pointer-trace.stderr.exp pointer-trace.stderr.exp64 \
@@ -109,6 +111,7 @@
nanoleak new_nothrow \
null_socket oset_test overlap \
partiallydefinedeq \
+ partial_load \
pipe pointer-trace \
post-syscall \
realloc1 realloc2 realloc3 \
diff --git a/memcheck/tests/partial_load.c b/memcheck/tests/partial_load.c
new file mode 100644
index 0000000..0b2f10b
--- /dev/null
+++ b/memcheck/tests/partial_load.c
@@ -0,0 +1,45 @@
+
+#include <stdlib.h>
+#include <assert.h>
+
+int main ( void )
+{
+ long w;
+ int i;
+ char* p;
+
+ assert(sizeof(long) == sizeof(void*));
+
+ /* partial load, which --partial-loads-ok=yes should suppress */
+ p = calloc( sizeof(long)-1, 1 );
+ assert(p);
+ w = *(long*)p;
+ free(p);
+
+ /* partial but misaligned, cannot be suppressed */
+ p = calloc( sizeof(long), 1 );
+ assert(p);
+ p++;
+ w += *(long*)p;
+ p--;
+ free(p);
+
+ /* partial but not word sized, cannot be suppressed */
+ p = calloc( sizeof(short)-1, 1 );
+ assert(p);
+ w += (long)( *(short*)p );
+ free(p);
+
+ /* aligned, word sized, but completely invalid - cannot be suppressed */
+ p = calloc( sizeof(long), 1 );
+ assert(p);
+ free(p);
+ w += *(long*)p;
+
+ /* dump result in a way gcc can't understand */
+ for (i = 0; i < 64; i++)
+ w <<= 1;
+
+ return (int)w;
+}
+
diff --git a/memcheck/tests/partial_load_dflt.stderr.exp b/memcheck/tests/partial_load_dflt.stderr.exp
new file mode 100644
index 0000000..aa14bac
--- /dev/null
+++ b/memcheck/tests/partial_load_dflt.stderr.exp
@@ -0,0 +1,30 @@
+
+Invalid read of size 4
+ at 0x........: main (partial_load.c:16)
+ Address 0x........ is 0 bytes inside a block of size 3 alloc'd
+ at 0x........: calloc (vg_replace_malloc.c:...)
+ by 0x........: main (partial_load.c:14)
+
+Invalid read of size 4
+ at 0x........: main (partial_load.c:23)
+ Address 0x........ is 1 bytes inside a block of size 4 alloc'd
+ at 0x........: calloc (vg_replace_malloc.c:...)
+ by 0x........: main (partial_load.c:20)
+
+Invalid read of size 2
+ at 0x........: main (partial_load.c:30)
+ Address 0x........ is 0 bytes inside a block of size 1 alloc'd
+ at 0x........: calloc (vg_replace_malloc.c:...)
+ by 0x........: main (partial_load.c:28)
+
+Invalid read of size 4
+ at 0x........: main (partial_load.c:37)
+ Address 0x........ is 0 bytes inside a block of size 4 free'd
+ at 0x........: free (vg_replace_malloc.c:...)
+ by 0x........: main (partial_load.c:36)
+
+ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)
+malloc/free: in use at exit: 0 bytes in 0 blocks.
+malloc/free: 4 allocs, 4 frees, 12 bytes allocated.
+For a detailed leak analysis, rerun with: --leak-check=yes
+For counts of detected errors, rerun with: -v
diff --git a/memcheck/tests/partial_load_dflt.vgtest b/memcheck/tests/partial_load_dflt.vgtest
new file mode 100644
index 0000000..5a18789
--- /dev/null
+++ b/memcheck/tests/partial_load_dflt.vgtest
@@ -0,0 +1 @@
+prog: partial_load
diff --git a/memcheck/tests/partial_load_ok.stderr.exp b/memcheck/tests/partial_load_ok.stderr.exp
new file mode 100644
index 0000000..0a2e2f5
--- /dev/null
+++ b/memcheck/tests/partial_load_ok.stderr.exp
@@ -0,0 +1,24 @@
+
+Invalid read of size 4
+ at 0x........: main (partial_load.c:23)
+ Address 0x........ is 1 bytes inside a block of size 4 alloc'd
+ at 0x........: calloc (vg_replace_malloc.c:...)
+ by 0x........: main (partial_load.c:20)
+
+Invalid read of size 2
+ at 0x........: main (partial_load.c:30)
+ Address 0x........ is 0 bytes inside a block of size 1 alloc'd
+ at 0x........: calloc (vg_replace_malloc.c:...)
+ by 0x........: main (partial_load.c:28)
+
+Invalid read of size 4
+ at 0x........: main (partial_load.c:37)
+ Address 0x........ is 0 bytes inside a block of size 4 free'd
+ at 0x........: free (vg_replace_malloc.c:...)
+ by 0x........: main (partial_load.c:36)
+
+ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)
+malloc/free: in use at exit: 0 bytes in 0 blocks.
+malloc/free: 4 allocs, 4 frees, 12 bytes allocated.
+For a detailed leak analysis, rerun with: --leak-check=yes
+For counts of detected errors, rerun with: -v
diff --git a/memcheck/tests/partial_load_ok.vgtest b/memcheck/tests/partial_load_ok.vgtest
new file mode 100644
index 0000000..1602c0e
--- /dev/null
+++ b/memcheck/tests/partial_load_ok.vgtest
@@ -0,0 +1,2 @@
+prog: partial_load
+vgopts: --partial-loads-ok=yes