File: 101.c

package info (click to toggle)
storm-lang 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,028 kB
  • sloc: ansic: 261,471; cpp: 140,432; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (172 lines) | stat: -rw-r--r-- 3,946 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* 
TEST_HEADER
 id = $Id$
 summary = MVFF allocate and free
 language = c
 link = testlib.o
END_HEADER
*/

#include <time.h>
#include "testlib.h"
#include "mpscmvff.h"

#define MAXNUMBER 1000000

mps_arena_t arena;

static struct {mps_addr_t addr; size_t size;} queue[MAXNUMBER];

enum {SEQ=0, RAN=1, SEQGAP=2, RANGAP=3, DUMMY=4};
static char *tdesc[] = {"sequential", "random",
                        "sequential gap", "random gap", "dummy"};

static void setobj(mps_addr_t a, size_t size, unsigned char val)
{
 unsigned char *b;
 b = a;

 while (size>0)
 {
  *b=val;
 /* comment("%p = %i", b, (int) val);
 */
  b++;
  size--;
 }
}

static int chkobj(mps_addr_t a, size_t size, unsigned char val)
{
 unsigned char *b;
 b = a;

 while (size>0)
 {
 /* comment("%p == %i", b, (int) val);
 */
  if (*b != val) return 0;
  b++;
  size--;
 }
 return 1;
}

static void dt(int kind,
   size_t extendBy, size_t avgSize,
   size_t mins, size_t maxs, int number, int iter)
{
 mps_pool_t pool;
 int i, hd;
 clock_t time0, time1;
 size_t size;
 double secs;

 asserts(number <= MAXNUMBER, "number too big");

 time0 = clock();
 asserts(time0 != -1, "processor time not available");

 MPS_ARGS_BEGIN(args) {
   MPS_ARGS_ADD(args, MPS_KEY_EXTEND_BY, extendBy);
   MPS_ARGS_ADD(args, MPS_KEY_MEAN_SIZE, avgSize);
   cdie(mps_pool_create_k(&pool, arena, mps_class_mvff(), args), "pool");
 } MPS_ARGS_END(args);

 for(hd=0; hd<number; hd++)
 {
  size = ranrange((unsigned long)mins, (unsigned long)maxs);
  if ((ranint(2) && (kind & 2)) || (kind==DUMMY))
  {
   queue[hd].addr=NULL;
  }
  else
  {
   die(mps_alloc(&queue[hd].addr, pool, size), "alloc");
   setobj(queue[hd].addr, size, hd%256);
   queue[hd].size = size;
  }
 };

 hd=-1;

 for(i=0; i<iter; i++)
 {
   if (kind & 1) hd = ranint(number);
   else {ranint(number); hd=(hd+1)%number;} /* call raninit anyway
                                               to use same time */

   if (queue[hd].addr != NULL)
   {
    asserts(chkobj(queue[hd].addr, queue[hd].size, hd%256),
      "corrupt at %x (%s: %x, %x, %x, %x, %i, %i)",
      queue[hd].addr,
      tdesc[kind], (int) extendBy, (int) avgSize,
      (int) mins, (int) maxs, number, iter);
    mps_free(pool, queue[hd].addr, queue[hd].size);
   }
   size = ranrange((unsigned long)mins, (unsigned long)maxs);

   if ((ranint(2) && (kind & 2)) || (kind==DUMMY))
   {
    queue[hd].addr=NULL;
   }
   else
   {
    die(mps_alloc(&queue[hd].addr, pool, size),"alloc");
    setobj(queue[hd].addr, size, hd%256);
    queue[hd].size = size;
   }
 }

 mps_pool_destroy(pool);

 time1=clock();
 secs=(time1-time0)/(double)CLOCKS_PER_SEC;

 comment("%s test (%x, %x, %x, %x, %i, %i) in %.2f s",
  tdesc[kind], (int) extendBy, (int) avgSize,
  (int) mins, (int) maxs, number, iter, secs);
}

static void test(void *stack_pointer)
{
 mps_thr_t thread;
 size_t mins;

 cdie(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE), "create arena");
 cdie(mps_thread_reg(&thread, arena), "register thread");

 mins = sizeof(int);

 dt(SEQ, 4096, 32, 8, 9, 5, 10);
 dt(RANGAP, 64, 64, 8, 128, 100, 1000);

 dt(DUMMY, 4096, 32, 8, 64, 1000, 10000);
 dt(SEQ, 4096, 32, 8, 64, 1000, 10000);
 dt(RAN, 4096, 32, 8, 64, 1000, 10000);
 dt(SEQGAP, 4096, 32, 8, 64, 1000, 10000);
 dt(RANGAP, 4096, 32, 8, 64, 1000, 10000);

 dt(DUMMY, 4096, 1024, 100, 132, 1000, 10000);
 dt(SEQ, 4096, 1024, 100, 132, 1000, 10000);
 dt(RAN, 4096, 1024, 100, 132, 1000, 10000);
 dt(SEQGAP, 4096, 1024, 100, 132, 1000, 10000);
 dt(RANGAP, 4096, 1024, 100, 132, 1000, 10000);

 dt(DUMMY, 128*1024, 64*1024, mins, 128*1024, 100, 10000);
 dt(SEQ, 128*1024, 64*1024, mins, 128*1024, 100, 10000);
 dt(RAN, 128*1024, 64*1024, mins, 128*1024, 100, 10000);
 dt(SEQGAP, 128*1024, 64*1024, mins, 128*1024, 100, 10000);
 dt(RANGAP, 128*1024, 64*1024, mins, 128*1024, 100, 10000);

 mps_thread_dereg(thread);
 mps_arena_destroy(arena);
}

int main(void)
{
 run_test(test);
 pass();
 return 0;
}