Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / ntp / ElectricFence / tstheap.c
blob5ea370a9ab58235ea924b59cc54adf7684f180f9
1 /* $NetBSD$ */
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <math.h>
6 #include <limits.h>
7 #include "efence.h"
9 /*
10 * This is a simple program to exercise the allocator. It allocates and frees
11 * memory in a pseudo-random fashion. It should run silently, using up time
12 * and resources on your system until you stop it or until it has gone
13 * through TEST_DURATION (or the argument) iterations of the loop.
16 extern C_LINKAGE double drand48(void); /* For pre-ANSI C systems */
18 #define POOL_SIZE 1024
19 #define LARGEST_BUFFER 30000
20 #define TEST_DURATION 1000000
22 void * pool[POOL_SIZE];
24 #ifdef FAKE_DRAND48
26 * Add -DFAKE_DRAND48 to your compile flags if your system doesn't
27 * provide drand48().
30 #ifndef ULONG_MAX
31 #define ULONG_MAX ~(1L)
32 #endif
34 double
35 drand48(void)
37 return (random() / (double)ULONG_MAX);
39 #endif
41 int
42 main(int argc, char * * argv)
44 int count = 0;
45 int duration = TEST_DURATION;
47 if ( argc >= 2 )
48 duration = atoi(argv[1]);
50 for ( ; count < duration; count++ ) {
51 void * * element = &pool[(int)(drand48() * POOL_SIZE)];
52 size_t size = (size_t)(drand48() * (LARGEST_BUFFER + 1));
54 if ( *element ) {
55 free( *element );
56 *element = 0;
58 else if ( size > 0 ) {
59 *element = malloc(size);
62 return 0;