rgtest.c
11.4 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
/*
* Module: rgtest.c
*
* $Revision: 1.1.1.2 $
* $Date: 2002/10/29 08:05:59 $
* $Source: /root/leakn64/depot/rf/sw/n64os20l/apps/rgtest/rgtest.c,v $
*
* Description:
* This program generates test cases for all the basic paths for the
* region routine in libultra.
*
*/
#include "rgtest.h"
#ifdef _STANDALONE
#include <stdio.h>
#include <stdlib.h>
#define OPTARG "v"
#define rmonPrintf printf
int verbose = 0;
#endif /* _STANDALONE */
#define _PRINT_REGION_HEADER(rp) { \
if (verbose) \
rmonPrintf("\t (rp=0x%x, sdata=0x%x, bufsz=%d, bufcnt=%d, free=%d, align=%d)\n", \
rp, RP(startBufferAddress), \
RP(bufferSize), RP(bufferCount), RP(freeList), RP(alignSize)); \
}
char bootStack[STACKSIZE];
static void idle(void *);
static OSThread idleThread;
static char idleThreadStack[STACKSIZE];
static OSThread mainThread;
static char mainThreadStack[STACKSIZE];
static OSThread rmonThread;
static char rmonThreadStack[RMON_STACKSIZE];
static int directedTests(void);
static int rangeTests(void);
static u32 doAlign(u32, int);
static int isAlign(void *, int);
#ifndef _STANDALONE
static void main(void *);
boot(void)
{
osInitialize();
parse();
osCreateThread(&mainThread, 1, main, (void *)0,
mainThreadStack+STACKSIZE, 10);
osStartThread(&mainThread);
}
static void
main(void *arg)
{
int numFailures = 0;
/*
* Create idle thread
*/
osCreateThread(&idleThread, 3, idle, (void *)0,
idleThreadStack+STACKSIZE, 0);
osStartThread(&idleThread);
/*
* Create rmon thread
*/
osCreateThread(&rmonThread, 0, rmonMain, (void *)0,
rmonThreadStack+RMON_STACKSIZE, OS_PRIORITY_RMON);
osStartThread(&rmonThread);
#else
void
main(int argc, char **argv)
{
int numFailures = 0;
int c;
while ((c = getopt(argc, argv, OPTARG)) != EOF) {
switch (c) {
case 'v': { /* Verbose */
verbose = 1;
break;
}
default: {
rmonPrintf("usage: %s [-v]\n", argv[0]);
exit(0);
}
}
}
#endif /* _STANDALONE */
rmonPrintf("Region tests begin\n");
numFailures = directedTests();
numFailures += rangeTests();
rmonPrintf("\nRegion tests complete, total failures = %d\n", numFailures);
}
/*
* Target specific behavior
*/
static int
directedTests(void)
{
OSRegion *rp;
char *bp;
u16 freeList;
s32 i;
int numFailures = 0;
u32 alignSize = 8;
rmonPrintf("Directed region tests begin\n");
/*
* Test #1: osCreateRegion(x,50,50)
*/
rmonPrintf("\nTest #%2d: osCreateRegion(x,50,50,%d) = NULL -> ",
1, alignSize);
rp = (OSRegion *)osCreateRegion(memory, 50, 50, alignSize);
if (rp == NULL) {
rmonPrintf("passed\n");
} else {
rmonPrintf("failed\n");
numFailures++;
}
/*
* Test #2: osCreateRegion(x,15,13)
*/
rmonPrintf("\nTest #%2d: osCreateRegion(x,15,13,%d) = NULL -> ",
2, alignSize);
rp = (OSRegion *)osCreateRegion(memory, 15, 13, alignSize);
if (rp == NULL) {
rmonPrintf("passed\n");
} else {
rmonPrintf("failed\n");
numFailures++;
}
/*
* Test #3: osCreateRegion(x,40,11)
*/
rmonPrintf("\nTest #%2d: osCreateRegion(x,40,11,%d) != NULL --> ",
3, alignSize);
rp = (OSRegion *)osCreateRegion(memory, 40, 11, alignSize);
if (rp != NULL) {
rmonPrintf("passed\n");
_PRINT_REGION_HEADER(rp);
} else {
rmonPrintf("failed\n");
numFailures++;
}
/*
* Test #4: osCreateRegion(x,40,12)
*/
rmonPrintf("\nTest #%2d: osCreateRegion(x,40,12,%d) != NULL --> ",
4, alignSize);
rp = (OSRegion *)osCreateRegion(memory, 40, 12, alignSize);
if (rp != NULL) {
rmonPrintf("passed\n");
_PRINT_REGION_HEADER(rp);
} else {
rmonPrintf("failed\n");
numFailures++;
}
/*
* Test #5: osCreateRegion(x,41,11)
*/
rmonPrintf("\nTest #%2d: osCreateRegion(x,41,11,%d) != NULL --> ",
5, alignSize);
rp = (OSRegion *)osCreateRegion(memory, 41, 11, alignSize);
if (rp != NULL) {
rmonPrintf("passed\n");
_PRINT_REGION_HEADER(rp);
} else {
rmonPrintf("failed\n");
numFailures++;
}
/*
* Test #6: osCreateRegion(x,41,16)
*/
rmonPrintf("\nTest #%2d: osCreateRegion(x,41,16,%d) != NULL --> ",
6, alignSize);
rp = (OSRegion *)osCreateRegion(memory, 41, 16, alignSize);
if (rp != NULL) {
rmonPrintf("passed\n");
_PRINT_REGION_HEADER(rp);
} else {
rmonPrintf("failed\n");
numFailures++;
}
/*
* Test #7: osCreateRegion(x, (35K*8), 3)
* Test for count > 32K
*/
rmonPrintf("\nTest #%2d: osCreateRegion(x,(35K*8),3,%d) != NULL --> ",
7, alignSize);
rp = (OSRegion *)osCreateRegion(memory, (35*1024*8), 3, alignSize);
if (rp != NULL) {
rmonPrintf("passed\n");
_PRINT_REGION_HEADER(rp);
} else {
rmonPrintf("failed\n");
numFailures++;
}
/*
* Test #8: osCreateRegion(x,41,16)
*/
rmonPrintf("\nTest #%2d: osCreateRegion(x,40,10,%d) != NULL --> ",
8, alignSize);
rp = (OSRegion *)osCreateRegion(memory, 40, 10, alignSize);
if (rp == NULL) {
rmonPrintf("failed\n");
numFailures++;
} else {
rmonPrintf("passed\n");
_PRINT_REGION_HEADER(rp);
/*
* Test #9: osMalloc(rp) (one buffer)
*/
rmonPrintf("\nTest #%2d: osMalloc(rp) {one buffer} != NULL ", 9);
bp = (char *)osMalloc((void *)rp);
if (bp != NULL) {
if (verbose)
rmonPrintf("\n\t (1st buffer address =0x%x)\n", bp);
_PRINT_REGION_HEADER(rp);
bp = (char *)osMalloc((void *)rp);
if (bp == NULL) {
rmonPrintf("--> passed\n");
} else {
if (verbose)
rmonPrintf("\t (2nd buffer is NULL)\n");
rmonPrintf("--> failed\n");
numFailures++;
}
} else {
rmonPrintf("--> failed\n");
numFailures++;
}
_PRINT_REGION_HEADER(rp);
}
/*
* Test #10: osCreateRegion(x,60,12)
*/
rmonPrintf("\nTest #%2d: osCreateRegion(x,60,12,%d) != NULL --> ",
10, alignSize);
rp = (OSRegion *)osCreateRegion(memory, 60, 12, alignSize);
if (rp == NULL) {
rmonPrintf("failed\n");
numFailures++;
} else {
rmonPrintf("passed\n");
_PRINT_REGION_HEADER(rp);
/*
* Test #11: osMalloc(rp) (one buffer)
*/
rmonPrintf("\nTest #%2d: osMalloc(rp) {one buffer} != NULL --> ", 11);
bp = (char *)osMalloc((void *)rp);
if (bp == NULL) {
rmonPrintf("failed\n");
numFailures++;
} else {
rmonPrintf("passed\n");
freeList = RP(freeList);
/*
* Test #12: osFree(rp,x)
*/
rmonPrintf("\nTest #%2d: osFree(rp,x) ", 12);
osFree((void *)rp, bp);
if (RP(freeList) != freeList) {
rmonPrintf("--> passed\n");
} else {
rmonPrintf("--> failed\n");
numFailures++;
}
_PRINT_REGION_HEADER(rp);
/*
* Test #13: osGetRegionBufCount(rp)
*/
rmonPrintf("\nTest #%2d: osGetRegionBufCount(rp) = count ", 13);
i = osGetRegionBufCount((void *)rp);
if (i == 2) {
rmonPrintf("--> passed\n");
} else {
rmonPrintf("--> failed\n");
numFailures++;
}
_PRINT_REGION_HEADER(rp);
/*
* Test #14: osGetRegionBufSize(rp)
*/
rmonPrintf("\nTest #%2d: osGetRegionBufSize(rp) = count ", 14);
i = osGetRegionBufSize((void *)rp);
if (i == 16) {
rmonPrintf("--> passed\n");
} else {
rmonPrintf("--> failed\n");
numFailures++;
}
_PRINT_REGION_HEADER(rp);
}
}
return(numFailures);
}
/*
* Vary parameters and call all of the API
*/
static int
rangeTests(void)
{
OSRegion *rp;
char *m1;
char *buf[MEMSIZE/BUFSIZE];
char *bp;
u32 bufferSize, memorySize, alignSize;
int i, j, k, numOfBuf, dataFail;
int numFailures = 0;
u32 alignTable[] = {
0, OS_RG_ALIGN_2B, OS_RG_ALIGN_4B, OS_RG_ALIGN_8B, OS_RG_ALIGN_16B
};
u32 alignTableSize = sizeof(alignTable)/sizeof(alignTable[0]);
rmonPrintf("Range region tests begin\n");
for (k = 0; k < alignTableSize; k++) {
alignSize = alignTable[k];
for (m1 = memory-1; m1 <= memory; m1++) {
for (memorySize = MEMSIZE-1; memorySize <= MEMSIZE; memorySize++) {
for (bufferSize = BUFSIZE-1; bufferSize <= BUFSIZE; bufferSize++) {
/*
* Test #30: osCreateRegion(x,x,x)
*/
rmonPrintf("\nTest #%2d: osCreateRegion(0x%x,0x%x,0x%x,%d) != NULL --> ",
30, m1, memorySize, bufferSize, alignSize);
rp = (OSRegion *)osCreateRegion(m1, memorySize, bufferSize, alignSize);
if (rp == NULL) {
rmonPrintf("failed\n");
numFailures++;
} else {
rmonPrintf("passed\n");
_PRINT_REGION_HEADER(rp);
i = 0;
while ((buf[i] = (char *)osMalloc((void *)rp)) != (char *)NULL) {
/*
* Test #31: osGetRegionBufCount(rp)
*/
rmonPrintf("\nTest #%2d: check alignment (%d) of osMalloc buffer %d",
31, alignSize, i);
if (isAlign(buf[i],
(alignSize == 0) ? OS_RG_ALIGN_DEFAULT : alignSize)) {
rmonPrintf("--> passed\n");
} else {
rmonPrintf("--> failed\n");
numFailures++;
}
_PRINT_REGION_HEADER(rp);
if (verbose)
rmonPrintf("\tinitializing buffer[%d] (0x%x) data...\n ",
i, buf[i]);
for (j = 0; j < bufferSize; j++)
buf[i][j] = i;
i++;
}
_PRINT_REGION_HEADER(rp);
numOfBuf = i;
if (verbose) {
rmonPrintf("\n\tTotal # of buffers malloced = %d\n", numOfBuf);
rmonPrintf("\n\tDumping buffer memory:\n");
for (i = 0; i < numOfBuf; i++) {
unsigned long addr;
addr=(unsigned long)(RP(startBufferAddress)+(RP(bufferSize)*i));
rmonPrintf("\t[%d]. 0x%x: ", i, addr);
for (j = 0; j < RP(bufferSize); j++)
rmonPrintf("%2x ", *(u8 *)(addr+j));
rmonPrintf("\n");
}
}
/*
* Test #32: check data of osMalloc buffer
*/
rmonPrintf("\nTest #%2d: check data of osMalloc buffer ",
32);
dataFail = 0;
for (i = 0; i < numOfBuf; i++) {
for (j = 0; j < bufferSize; j++) {
if (buf[i][j] != i) {
dataFail = 1;
break;
}
}
}
if (dataFail == 0) {
rmonPrintf("--> passed\n");
} else {
rmonPrintf("--> failed\n");
numFailures++;
}
for (i = 0; i < numOfBuf; i++) {
if (verbose)
rmonPrintf("\n\tcalling osFree: rp=0x%x, buf=0x%x\n ",
rp, buf[i]);
osFree((void *)rp, (void *)buf[i]);
_PRINT_REGION_HEADER(rp);
}
/*
* Test #33: osGetRegionBufCount(rp)
*/
rmonPrintf("\nTest #%2d: osGetRegionBufCount(rp) = %d ",
33, numOfBuf);
if (osGetRegionBufCount((void *)rp) == numOfBuf) {
rmonPrintf("--> passed\n");
} else {
rmonPrintf("--> failed\n");
numFailures++;
}
/*
* Test #34: osGetRegionBufSize(rp)
*/
rmonPrintf("\nTest #%2d: osGetRegionBufSize(rp) = 0x%x ",
34, doAlign(bufferSize,
(alignSize == 0) ? OS_RG_ALIGN_DEFAULT : alignSize));
if (osGetRegionBufSize((void *)rp) == doAlign(bufferSize,
(alignSize == 0) ? OS_RG_ALIGN_DEFAULT : alignSize)) {
rmonPrintf("--> passed\n");
} else {
rmonPrintf("--> failed\n");
numFailures++;
}
} /* if (rp == NULL) */
} /* for (m1 = memory; ...; ...) */
} /* for (memorySize = MEMSIZE; ...; ...) */
} /* for (bufferSize = BUFSIZE; ...; ...) */
} /* for (alignSize = OS_RG_ALIGN_2B; ...; ...) */
return(numFailures);
}
static void
idle(void *arg)
{
for (;;);
}
static u32
doAlign(u32 count, int size)
{
return((((count + size -1)) / size) * size);
}
static int
isAlign(void *addr, int size)
{
return(!((u32)addr & (size-1)));
}