Add a test for origin tracking through large floating point arrays.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8008
This commit is contained in:
Julian Seward 2008-05-06 08:14:57 +00:00
parent 79c14a0983
commit b012d72856
5 changed files with 117 additions and 1 deletions

View File

@ -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

104
memcheck/tests/origin6-fp.c Normal file
View File

@ -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 <assert.h>
#include <stdio.h>
#include <stdlib.h>
#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;
}

View File

@ -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.

View File

View File

@ -0,0 +1,2 @@
prog: origin6-fp
vgopts: -q --track-origins=yes