Merge branch 'dev' of https://github.com/smartxworks/fio
[fio.git] / t / stest.c
CommitLineData
fbc2792b
JA
1#include <stdio.h>
2#include <stdlib.h>
3#include <assert.h>
4
5#include "../smalloc.h"
6#include "../flist.h"
71471cb1 7#include "../arch/arch.h"
9077ee4a 8#include "debug.h"
fbc2792b
JA
9
10#define MAGIC1 0xa9b1c8d2
11#define MAGIC2 0xf0a1e9b3
12
13#define LOOPS 32
14
15struct elem {
16 unsigned int magic1;
17 struct flist_head list;
18 unsigned int magic2;
19};
20
ca0a0b52 21static FLIST_HEAD(list);
fbc2792b
JA
22
23static int do_rand_allocs(void)
24{
25 unsigned int size, nr, rounds = 0;
26 unsigned long total;
27 struct elem *e;
28
29 while (rounds++ < LOOPS) {
30#ifdef STEST_SEED
31 srand(MAGIC1);
32#endif
33 nr = total = 0;
3fb1aa30 34 while (total < 120*1024*1024UL) {
fbc2792b
JA
35 size = 8 * sizeof(struct elem) + (int) (999.0 * (rand() / (RAND_MAX + 1.0)));
36 e = smalloc(size);
37 if (!e) {
38 printf("fail at %lu, size %u\n", total, size);
39 break;
40 }
41 e->magic1 = MAGIC1;
42 e->magic2 = MAGIC2;
43 total += size;
44 flist_add_tail(&e->list, &list);
45 nr++;
46 }
47
48 printf("Got items: %u\n", nr);
49
50 while (!flist_empty(&list)) {
51 e = flist_entry(list.next, struct elem, list);
52 assert(e->magic1 == MAGIC1);
53 assert(e->magic2 == MAGIC2);
54 flist_del(&e->list);
55 sfree(e);
56 }
57 }
58
59 return 0;
60}
61
fbc2792b
JA
62int main(int argc, char *argv[])
63{
71471cb1 64 arch_init(argv);
fbc2792b 65 sinit();
9077ee4a 66 debug_init();
fbc2792b
JA
67
68 do_rand_allocs();
69
fbc2792b
JA
70 scleanup();
71 return 0;
72}