From: Julian Seward Date: Tue, 6 May 2008 08:14:57 +0000 (+0000) Subject: Add a test for origin tracking through large floating point arrays. X-Git-Tag: svn/VALGRIND_3_4_0~629 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b012d72856db92aa2ebd2e3e36a7a41c11692c15;p=thirdparty%2Fvalgrind.git Add a test for origin tracking through large floating point arrays. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8008 --- diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index 06320b959c..d1be4974e8 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -111,6 +111,8 @@ EXTRA_DIST = $(noinst_SCRIPTS) \ origin5-bz2.stderr.exp-glibc25-x86 \ origin5-bz2.stderr.exp-glibc25-amd64 \ origin5-bz2.stderr.exp-glibc27-ppc64 \ + origin6-fp.vgtest origin6-fp.stdout.exp \ + origin6-fp.stderr.exp \ oset_test.stderr.exp oset_test.stdout.exp oset_test.vgtest \ overlap.stderr.exp overlap.stdout.exp overlap.vgtest \ partiallydefinedeq.vgtest partiallydefinedeq.stderr.exp \ @@ -199,7 +201,8 @@ check_PROGRAMS = \ nanoleak nanoleak2 new_nothrow \ noisy_child \ null_socket oset_test \ - origin1-yes origin2-not-quite origin3-no origin4-many origin5-bz2 \ + origin1-yes origin2-not-quite origin3-no \ + origin4-many origin5-bz2 origin6-fp \ overlap \ partiallydefinedeq \ partial_load pdb-realloc pdb-realloc2 \ @@ -257,6 +260,7 @@ varinfo6_CFLAGS = $(AM_FLAG_M3264_PRI) $(AM_CFLAGS) -O -g origin4_many_CFLAGS = $(AM_FLAG_M3264_PRI) $(AM_CFLAGS) -O -g # Apply -O so as to run in reasonable time origin5_bz2_CFLAGS = $(AM_FLAG_M3264_PRI) $(AM_CFLAGS) -O -g +origin6_fp_CFLAGS = $(AM_FLAG_M3264_PRI) $(AM_CFLAGS) -O -g # C++ tests mismatches_SOURCES = mismatches.cpp diff --git a/memcheck/tests/origin6-fp.c b/memcheck/tests/origin6-fp.c new file mode 100644 index 0000000000..79b8cc83d9 --- /dev/null +++ b/memcheck/tests/origin6-fp.c @@ -0,0 +1,104 @@ + +/* Test of origin tracking through floating point code and in the case + where there are large amounts of uninitialised data floating + around. This program creates 3 matrices of 2300x2300 doubles, + makes one value in them undefined, does arithmetic, and tests the + result, which is then undefined. + + This also tests the secondary otag cache (ocacheL2), since the + amount of uninitialised data is somewhat over 43MB and it appears + that quite a lot of non-zero-otag lines are pushed into ocacheL2. + + This program needs to be compiled with -O. +*/ + +#include +#include +#include +#include "../memcheck.h" + + +double** alloc_square_array ( int nArr ) +{ + int i; + double** vec; + assert(nArr >= 1); + vec = malloc(nArr * sizeof(double*)); + assert(vec); + for (i = 0; i < nArr; i++) { + vec[i] = malloc(nArr * sizeof(double)); + assert(vec); + } + return vec; +} + +double** do3x3smooth ( double** arr, int nArr ) +{ + int i, j; + double** out; + assert(nArr >= 3); + out = alloc_square_array(nArr - 2); + assert(out); + for (i = 1; i < nArr-1; i++) { + for (j = 1; j < nArr-1; j++) { + double s = arr[i-1][j-1] + arr[i-1][j ] + arr[i-1][j+1] + + arr[i ][j-1] + arr[i ][j ] + arr[i ][j+1] + + arr[i+1][j-1] + arr[i+1][j ] + arr[i+1][j+1]; + out[i-1][j-1] = s / 9.0; + } + } + return out; +} + +double sum ( double** arr, int nArr ) +{ + int i, j; + double s = 0.0; + assert(nArr >= 1); + for (i = 0; i < nArr; i++) { + for (j = 0; j < nArr; j++) { + s += arr[i][j]; + } + } + return s; +} + +void setup_arr ( /*OUT*/double** arr, int nArr ) +{ + int i, j; + assert(nArr >= 1); + for (i = 0; i < nArr; i++) { + for (j = 0; j < nArr; j++) { + arr[i][j] = (double)(i * j); + if (i == nArr/2 && j == nArr/2) { + unsigned char* p = (unsigned char*)&arr[i][j]; + VALGRIND_MAKE_MEM_UNDEFINED(p, 1); + } + } + } +} + +int main ( void ) +{ + int nArr = 2300; + int ri; + double r, **arr, **arr2, **arr3; + arr = alloc_square_array(nArr); + setup_arr( arr, nArr ); + arr2 = do3x3smooth( arr, nArr ); + arr3 = do3x3smooth( arr2, nArr-2 ); + r = sum( arr3, nArr-4 ); + /* Convert answer to int before testing it, so as to + guarantee there's only one conditional branch. */ + if (0) fprintf(stderr, "r = %g\n", r ); + r /= 10000.0; + ri = (int)r; + if (0) fprintf(stderr, "ri = %d\n", ri); + if (ri == 696565111) { + fprintf(stderr, "Test succeeded.\n"); + } else { + fprintf(stderr, "Test FAILED !\n"); + assert(0); + } + return 0; +} diff --git a/memcheck/tests/origin6-fp.stderr.exp b/memcheck/tests/origin6-fp.stderr.exp new file mode 100644 index 0000000000..a5f521abe6 --- /dev/null +++ b/memcheck/tests/origin6-fp.stderr.exp @@ -0,0 +1,6 @@ +Conditional jump or move depends on uninitialised value(s) + at 0x........: main (origin6-fp.c:97) + Uninitialised value was created by a client request + at 0x........: setup_arr (origin6-fp.c:75) + by 0x........: main (origin6-fp.c:87) +Test succeeded. diff --git a/memcheck/tests/origin6-fp.stdout.exp b/memcheck/tests/origin6-fp.stdout.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/memcheck/tests/origin6-fp.vgtest b/memcheck/tests/origin6-fp.vgtest new file mode 100644 index 0000000000..09ccfa5b84 --- /dev/null +++ b/memcheck/tests/origin6-fp.vgtest @@ -0,0 +1,2 @@ +prog: origin6-fp +vgopts: -q --track-origins=yes