blob: 6265ad7245e8f280b4c64410557368d66c640e2d [file] [log] [blame]
njnec0c27a2005-12-10 23:11:28 +00001// This artificial program allocates and deallocates a lot of large objects
2// on the stack. It is a stress test for Memcheck's set_address_range_perms
3// (sarp) function. Pretty much all Valgrind versions up to 3.1.X do very
4// badly on it, ie. a slowdown of at least 100x.
5//
6// It is representative of tsim_arch, the simulator for the University of
7// Texas's TRIPS processor, whose performance under Valgrind is dominated by
8// the handling of one frequently-called function that allocates 8348 bytes
9// on the stack.
10
11#include <assert.h>
12#include <time.h>
13
sewardj57ea0c22005-12-13 17:13:39 +000014#define REPS 1000*1000*10
njnec0c27a2005-12-10 23:11:28 +000015
njn79076e32005-12-14 05:33:17 +000016__attribute__((noinline))
njnec0c27a2005-12-10 23:11:28 +000017int f(int i)
18{
19 // This nonsense is just to ensure that the compiler does not optimise
20 // away the stack allocation.
sewardj57ea0c22005-12-13 17:13:39 +000021 char big_array[500];
njn79076e32005-12-14 05:33:17 +000022 big_array[ 0] = 12;
sewardj57ea0c22005-12-13 17:13:39 +000023 big_array[ 23] = 34;
24 big_array[256] = 56;
25 big_array[434] = 78;
26 assert( 480 == (&big_array[490] - &big_array[10]) );
njnec0c27a2005-12-10 23:11:28 +000027 return big_array[i];
28}
29
30int main(void)
31{
32 int i, sum = 0;
33
34 struct timespec req;
35 req.tv_sec = 0;
36 req.tv_nsec = 100*1000*1000; // 0.1s
37
38 // Pause for a bit so that the native run-time is not 0.00, which leads
39 // to ridiculous slow-down figures.
sewardj57ea0c22005-12-13 17:13:39 +000040 //nanosleep(&req, NULL);
njnec0c27a2005-12-10 23:11:28 +000041
42 for (i = 0; i < REPS; i++) {
43 sum += f(i & 0xff);
44 }
njnc870d182005-12-13 16:38:55 +000045 return ( sum == 0xdeadbeef ? 1 : 0 );
njnec0c27a2005-12-10 23:11:28 +000046}
47