|
From: <sv...@va...> - 2009-05-17 22:43:47
|
Author: sewardj
Date: 2009-05-17 23:43:39 +0100 (Sun, 17 May 2009)
New Revision: 9873
Log:
A simple test to demonstrate heap, stack, and global overrun
detection, with XML output.
Added:
branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/hsg.c
branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/hsg.stderr.exp
branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/hsg.stdout.exp
branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/hsg.vgtest
Modified:
branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/Makefile.am
Modified: branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/Makefile.am
===================================================================
--- branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/Makefile.am 2009-05-17 21:45:01 UTC (rev 9872)
+++ branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/Makefile.am 2009-05-17 22:43:39 UTC (rev 9873)
@@ -29,6 +29,7 @@
hackedbz2.stderr.exp-glibc28-amd64 \
hp_bounds.vgtest hp_bounds.stderr.exp \
hp_dangle.vgtest hp_dangle.stderr.exp \
+ hsg.vgtest hsg.stdout.exp hsg.stderr.exp \
idiv.vgtest-disabled idiv.stderr.exp \
imul.vgtest-disabled imul.stderr.exp \
justify.vgtest justify.stderr.exp \
@@ -67,7 +68,7 @@
check_PROGRAMS = \
add and arith bad_percentify base ccc cmp fp \
globalerr hackedbz2 \
- hp_bounds hp_dangle idiv imul \
+ hp_bounds hp_dangle hsg idiv imul \
justify mm not neg or partial \
preen_invars preen_invars_so.so \
pth_create pth_specific realloc \
Added: branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/hsg.c
===================================================================
--- branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/hsg.c (rev 0)
+++ branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/hsg.c 2009-05-17 22:43:39 UTC (rev 9873)
@@ -0,0 +1,48 @@
+
+/* A simple test to demonstrate heap, stack, and global overrun
+ detection. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+short ga[100];
+
+__attribute__((noinline))
+int addup_wrongly ( short* arr )
+{
+ int sum = 0, i;
+ for (i = 0; i <= 100; i++)
+ sum += (int)arr[i];
+ return sum;
+}
+
+__attribute__((noinline))
+int do_other_stuff ( void )
+{
+ short la[100];
+ return 123 + addup_wrongly(la);
+}
+
+__attribute__((noinline))
+int do_stupid_malloc_stuff ( void )
+{
+ int sum = 0;
+ unsigned char* duh = malloc(100 * sizeof(char));
+ sum += duh[-1];
+ free(duh);
+ sum += duh[50];
+ return sum;
+}
+
+int main ( void )
+{
+ long s = addup_wrongly(ga);
+ s += do_other_stuff();
+ s += do_stupid_malloc_stuff();
+ if (s == 123456789) {
+ fprintf(stdout, "well, i never!\n");
+ } else {
+ fprintf(stdout, "boringly as expected\n");
+ }
+ return 0;
+}
Added: branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/hsg.stderr.exp
===================================================================
--- branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/hsg.stderr.exp (rev 0)
+++ branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/hsg.stderr.exp 2009-05-17 22:43:39 UTC (rev 9873)
@@ -0,0 +1,231 @@
+<?xml version="1.0"?>
+
+<valgrindoutput>
+
+<protocolversion>4</protocolversion>
+<protocoltool>exp-ptrcheck</protocoltool>
+
+<preamble>
+ <line>...</line>
+ <line>...</line>
+ <line>...</line>
+ <line>...</line>
+ <line>...</line>
+ <line>...</line>
+ <line>...</line>
+</preamble>
+
+<pid>...</pid>
+<ppid>...</ppid>
+<tool>exp-ptrcheck</tool>
+
+<args>
+ <vargv>...</vargv>
+ <argv>
+ <exe>./hsg</exe>
+ </argv>
+</args>
+
+<status>
+ <state>RUNNING</state>
+ <time>...</time>
+</status>
+
+<error>
+ <unique>0x........</unique>
+ <tid>...</tid>
+ <kind>SorG</kind>
+ <what>Invalid read of size 2</what>
+ <stack>
+ <frame>
+ <ip>0x........</ip>
+ <obj>...</obj>
+ <fn>addup_wrongly</fn>
+ <dir>...</dir>
+ <file>hsg.c</file>
+ <line>...</line>
+ </frame>
+ <frame>
+ <ip>0x........</ip>
+ <obj>...</obj>
+ <fn>main</fn>
+ <dir>...</dir>
+ <file>hsg.c</file>
+ <line>...</line>
+ </frame>
+ </stack>
+ <auxwhat>Address 0x........ expected vs actual:</auxwhat>
+ <auxwhat>Expected: global array "ga" in object with soname "NONE"</auxwhat>
+ <auxwhat>Actual: unknown</auxwhat>
+</error>
+
+<error>
+ <unique>0x........</unique>
+ <tid>...</tid>
+ <kind>SorG</kind>
+ <what>Invalid read of size 2</what>
+ <stack>
+ <frame>
+ <ip>0x........</ip>
+ <obj>...</obj>
+ <fn>addup_wrongly</fn>
+ <dir>...</dir>
+ <file>hsg.c</file>
+ <line>...</line>
+ </frame>
+ <frame>
+ <ip>0x........</ip>
+ <obj>...</obj>
+ <fn>do_other_stuff</fn>
+ <dir>...</dir>
+ <file>hsg.c</file>
+ <line>...</line>
+ </frame>
+ <frame>
+ <ip>0x........</ip>
+ <obj>...</obj>
+ <fn>main</fn>
+ <dir>...</dir>
+ <file>hsg.c</file>
+ <line>...</line>
+ </frame>
+ </stack>
+ <auxwhat>Address 0x........ expected vs actual:</auxwhat>
+ <auxwhat>Expected: stack array "la" in frame 1 back from here</auxwhat>
+ <auxwhat>Actual: unknown</auxwhat>
+</error>
+
+<error>
+ <unique>0x........</unique>
+ <tid>...</tid>
+ <kind>Heap</kind>
+ <what>Invalid read of size 1</what>
+ <stack>
+ <frame>
+ <ip>0x........</ip>
+ <obj>...</obj>
+ <fn>do_stupid_malloc_stuff</fn>
+ <dir>...</dir>
+ <file>hsg.c</file>
+ <line>...</line>
+ </frame>
+ <frame>
+ <ip>0x........</ip>
+ <obj>...</obj>
+ <fn>main</fn>
+ <dir>...</dir>
+ <file>hsg.c</file>
+ <line>...</line>
+ </frame>
+ </stack>
+ <auxwhat>Address 0x........ is 1 bytes before the accessing pointer's</auxwhat>
+ <auxwhat>legitimate range, a block of size 100 alloc'd</auxwhat>
+ <stack>
+ <frame>
+ <ip>0x........</ip>
+ <obj>...</obj>
+ <fn>malloc</fn>
+ <dir>...</dir>
+ <file>vg_replace_malloc.c</file>
+ <line>...</line>
+ </frame>
+ <frame>
+ <ip>0x........</ip>
+ <obj>...</obj>
+ <fn>do_stupid_malloc_stuff</fn>
+ <dir>...</dir>
+ <file>hsg.c</file>
+ <line>...</line>
+ </frame>
+ <frame>
+ <ip>0x........</ip>
+ <obj>...</obj>
+ <fn>main</fn>
+ <dir>...</dir>
+ <file>hsg.c</file>
+ <line>...</line>
+ </frame>
+ </stack>
+</error>
+
+<error>
+ <unique>0x........</unique>
+ <tid>...</tid>
+ <kind>Heap</kind>
+ <what>Invalid read of size 1</what>
+ <stack>
+ <frame>
+ <ip>0x........</ip>
+ <obj>...</obj>
+ <fn>do_stupid_malloc_stuff</fn>
+ <dir>...</dir>
+ <file>hsg.c</file>
+ <line>...</line>
+ </frame>
+ <frame>
+ <ip>0x........</ip>
+ <obj>...</obj>
+ <fn>main</fn>
+ <dir>...</dir>
+ <file>hsg.c</file>
+ <line>...</line>
+ </frame>
+ </stack>
+ <auxwhat>Address 0x........ is 50 bytes inside the accessing pointer's</auxwhat>
+ <auxwhat>once-legitimate range, a block of size 100 free'd</auxwhat>
+ <stack>
+ <frame>
+ <ip>0x........</ip>
+ <obj>...</obj>
+ <fn>free</fn>
+ <dir>...</dir>
+ <file>vg_replace_malloc.c</file>
+ <line>...</line>
+ </frame>
+ <frame>
+ <ip>0x........</ip>
+ <obj>...</obj>
+ <fn>do_stupid_malloc_stuff</fn>
+ <dir>...</dir>
+ <file>hsg.c</file>
+ <line>...</line>
+ </frame>
+ <frame>
+ <ip>0x........</ip>
+ <obj>...</obj>
+ <fn>main</fn>
+ <dir>...</dir>
+ <file>hsg.c</file>
+ <line>...</line>
+ </frame>
+ </stack>
+</error>
+
+<status>
+ <state>FINISHED</state>
+ <time>...</time>
+</status>
+
+<errorcounts>
+ <pair>
+ <count>...</count>
+ <unique>0x........</unique>
+ </pair>
+ <pair>
+ <count>...</count>
+ <unique>0x........</unique>
+ </pair>
+ <pair>
+ <count>...</count>
+ <unique>0x........</unique>
+ </pair>
+ <pair>
+ <count>...</count>
+ <unique>0x........</unique>
+ </pair>
+</errorcounts>
+
+<suppcounts>...</suppcounts>
+
+</valgrindoutput>
+
Added: branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/hsg.stdout.exp
===================================================================
--- branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/hsg.stdout.exp (rev 0)
+++ branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/hsg.stdout.exp 2009-05-17 22:43:39 UTC (rev 9873)
@@ -0,0 +1 @@
+boringly as expected
Added: branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/hsg.vgtest
===================================================================
--- branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/hsg.vgtest (rev 0)
+++ branches/MESSAGING_TIDYUP/exp-ptrcheck/tests/hsg.vgtest 2009-05-17 22:43:39 UTC (rev 9873)
@@ -0,0 +1,3 @@
+prog: hsg
+vgopts: --xml=yes --xml-fd=2 --log-file=/dev/null
+stderr_filter: ../../memcheck/tests/filter_xml
|