iotest.c
9.14 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
/*************************************************************************
*
* File: iotest.c
*
* This file contains the main test loop driver. This loop reads test
* input data from a text file, parses each input line for valid data,
* and executes the corresponding test routine.
*
* $Header: /root/leakn64/depot/rf/sw/n64os20l/iosim/src/iotest.c,v 1.2 2002/05/30 05:52:49 whs Exp $
*
*/
#include <stdio.h>
#include <string.h>
#ifdef __sgi__
#include <bstring.h>
#endif
#include "trace.h"
#include "iomap.h"
#include "iotest.h"
#include "simipc.h"
#define REQ_LOG REQ_CONFIG_RDRAM
/***********************************************************************
* Global definitions
*/
FILE *dumpFp = NULL;
/***********************************************************************
* Extern declarations
*/
extern int MemoryLoad;
/***********************************************************************
* Local static definitions
*/
static IpcPkt req, rsp;
static unsigned long tstBuf[4];
IpcPkt *
SendConfirmReqPkt(char *buf, int len)
{
IpcPkt *pkt;
bzero((char *)&rsp, sizeof(IpcPkt));
if (IpcFd != -1)
IpcClose(IpcFd);
if ((IpcFd = IpcOpen(IPC_CLIENT)) < 0) {
return(NULL);
}
if (IpcConnect(IpcFd) < 0) {
return(NULL);
}
if (IpcSend(IpcFd, (char *)buf, len) < 0) {
IpcClose(IpcFd); IpcFd = -1;
return(NULL);
}
if (IpcReceive(IpcFd, (char *)&rsp, sizeof(IpcPkt)) < 0) {
IpcClose(IpcFd); IpcFd = -1;
return(NULL);
}
IpcClose(IpcFd);
IpcFd = -1;
return(&rsp);
} /* SendConfirmReqPkt */
int
IoCmd(int code, int data)
{
IpcPkt *pkt;
bzero(&req, sizeof(IpcPkt));
#ifdef __sgi__
req.length = sizeof(IpcPkt);
req.code = code;
req.data[0] = data;
#else
req.length = htonl(sizeof(IpcPkt));
req.code = htonl(code);
req.data[0] = htonl(data);
#endif
if ((pkt = SendConfirmReqPkt((char *)&req, sizeof(IpcPkt))) == NULL) {
return(-1);
}
if (pkt->code != RSP_OK) {
return(-1);
}
return(0);
} /* IoCmd */
int
IoSend(int code, unsigned int *data)
{
IpcPkt *pkt;
int i;
bzero(&req, sizeof(IpcPkt));
req.length = sizeof(IpcPkt);
req.code = code;
for (i = 0; i < PKT_DATA_WORD; i++)
req.data[i] = data[i];
if ((pkt = SendConfirmReqPkt((char *)&req, sizeof(IpcPkt))) == NULL) {
return(-1);
}
if (pkt->code != RSP_OK) {
return(-1);
}
return(0);
} /* IoSend */
static int
parseSize(unsigned int *size, int nbytes)
{
if (nbytes <= 0 || nbytes > 32)
return(-1);
switch (nbytes) {
case 1: *size = SIZE_1BYTE; break;
case 2: *size = SIZE_2BYTE; break;
case 3: *size = SIZE_3BYTE; break;
case 4: *size = SIZE_4BYTE; break;
case 8: *size = SIZE_2WORD; break;
case 16: *size = SIZE_4WORD; break;
case 32: *size = SIZE_8WORD; break;
default: return(-1);
}
return(0);
} /* parseSize */
int
IoRead(unsigned int address, int nbytes, unsigned int *data)
{
IpcPkt *pkt;
bzero(&req, sizeof(IpcPkt));
if (parseSize(&req.size, nbytes) < 0)
return(-1);
req.code = (nbytes <= 4) ? REQ_SINGLE_READ: REQ_BLOCK_READ;
req.length = sizeof(IpcPkt);
req.address = address;
if ((pkt = SendConfirmReqPkt((char *)&req, sizeof(IpcPkt))) == NULL) {
return(-1);
}
if (pkt->code != RSP_DATA) {
return(-1);
}
bcopy((void *)pkt->data, (void *)data, nbytes);
return(0);
} /* IoRead */
int
IoWrite(unsigned int address, int nbytes, unsigned int *data)
{
int i;
IpcPkt *pkt;
bzero(&req, sizeof(IpcPkt));
if (parseSize(&req.size, nbytes) < 0)
return(-1);
req.code = (nbytes <= 4) ? REQ_SINGLE_WRITE: REQ_BLOCK_WRITE;
req.length = sizeof(IpcPkt);
req.address = address;
req.data[0] = data[0];
if (req.code == REQ_BLOCK_WRITE) {
for (i=1; i < (2 << req.size); i++)
req.data[i] = data[i];
}
if ((pkt = SendConfirmReqPkt((char *)&req, sizeof(IpcPkt))) == NULL) {
return(-1);
}
if (pkt->code != RSP_OK) {
return(-1);
}
return(0);
} /* IoWrite */
/***********************************************************************
*
* Main test driver
* - Read each line from test command file
* - Execute test based on id
*/
/*
* Perform lexical scan on input buffer by breaking input buffer into
* tokens
*/
static int
lexScan(char *inBuf, char **argv)
{
return(0);
}
static TstCmd *
lookupCmd(TstCmd *CmdTbl, int id)
{
TstCmd *ct;
/* Search through TstCmdTable to see if id exists
* If found, return pointer to TstCmd structure, otherwise return NULL
*/
for (ct = CmdTbl; ct->id != -1; ct++) {
if (ct->id == id)
return(ct);
}
return(NULL);
} /* lookupCmd */
/***********************************************************************
*/
int
IoProcessTestFile(char *testFile)
{
FILE *fp;
char line[BUF_SIZE], dumpFile[BUF_SIZE], fileName[BUF_SIZE];
int ret, size, cycles, tid;
unsigned int address, data[PKT_DATA_WORD];
unsigned int a1, a2, a3, a4;
TstCmd *cmd;
fp = (FILE *)NULL;
line[0] = '\0';
dumpFile[0] = '\0';
/* Load test file */
if ((fp = fopen(testFile, "r")) == NULL) {
fprintf(LogFp, "ERROR: Unable to open file '%s'\n", testFile);
return(-1);
}
/*
* line format (size= # of bytes)
* ===========
* f <filename> // dump file name
* s <cycles> // stall for n clock cycles
* r <size> <address> // read from <address> of <size>
* w <size> <address> <data> // write <size><data> to <address>
* l <file> <address> <size> // load <file> <address> <size>
* u <file> <address> <size> // unload <file> <address> <size>
* v <id> // execute verilog test <id>
* t <id> <a1> <a2> ... <a4> // execute test <id>
* q // quit
*
*/
while (fgets(line, BUF_SIZE, fp)) {
if (line[0] == 's' || line[0] == 'S') {
sscanf(line, "%*s %d", &cycles);
_TRACE(DLOG, fprintf(LogFp,
"\ts c=%d\n", cycles));
ret = IoCmd(REQ_STALL, cycles);
continue;
}
else if (line[0] == 'r' || line[0] == 'R') {
sscanf(line, "%*s %d %x", &size, &address);
_TRACE(DLOG, fprintf(LogFp,
"\tr s=%d addr=0x%08x\n", size, address));
bzero((char *)data, PKT_DATA_BYTES);
ret = IoRead(address, size, data);
if (ret < 0) {
_TRACE(DERROR, fprintf(LogFp, MSG_RD_ERR,
address, size));
}
fprintf(FP_SET(dumpFp),
MSG_DATAOUT, address,
data[0], data[1], data[2], data[3],
data[4], data[5], data[6], data[7]);
continue;
}
else if (line[0] == 'w' || line[0] == 'W') {
sscanf(line, "%*s %d %x %x %x %x %x %x %x %x %x",
&size, &address,
&data[0], &data[1], &data[2], &data[3],
&data[4], &data[5], &data[6], &data[7]);
_TRACE(DLOG, fprintf(LogFp,
"\tw s=%d addr=0x%08x data=0x%08x\n",
size, address, data[0]));
ret = IoWrite(address, size, data);
if (ret < 0) {
_TRACE(DERROR, fprintf(LogFp,
MSG_WR_ERR, address, size,
data[0], data[1], data[2], data[3]));
}
continue;
}
else if (line[0] == 'v') {
sscanf(line, "%*s %d %x %x %x %x",
&data[0], &data[1], &data[2], &data[3], &data[4]);
_TRACE(DLOG, fprintf( LogFp,
"v %3d 0x%08x 0x%08x 0x%08x 0x%08x\n",
data[0], data[1], data[2], data[3], data[4]));
if (IoSend(REQ_LOG, data) < 0) {
_TRACE(DERROR, fprintf(LogFp,
"ERROR: v %3d 0x%08x 0x%08x 0x%08x 0x%08x\n",
data[0], data[1], data[2], data[3],
data[4]));
}
continue;
}
else if (line[0] == 't') {
sscanf(line, "%*s %d %x %x %x %x",
&tid, &a1, &a2, &a3, &a4);
printf("t %3d 0x%08x 0x%08x 0x%08x 0x%08x\n",
tid, a1, a2, a3, a4);
if ((cmd = lookupCmd(TstCmdTbl, tid)) != NULL) {
fprintf(LogFp, TST_MSG_RES_STR,
cmd->id, cmd->name,
a1, a2, a3, a4);
ret = (*cmd->handler)(a1, a2, a3, a4);
if (ret == 0)
fprintf(LogFp, "-> %s\n", PASS_STR);
else if (ret == -1)
fprintf(LogFp, "-> %s\n", FAIL_STR);
else fprintf(LogFp, "\n");
}
else {
fprintf(LogFp, "ERROR: illegal test cmd=%d\n",
tid);
}
continue;
}
else if ((line[0] == 'l' || line[0] == 'L') && MemoryLoad) {
sscanf(line, "%*s %s %x %d", fileName, &address, &size);
fprintf(LogFp,
"LoadFile name=%s addr=0x%08x size=%d\n",
fileName, address, size);
if (LoadFile(fileName, address, size) != 0) {
_TRACE(DERROR, fprintf(LogFp,
"ERROR: Fail to load %s!\n", fileName));
}
continue;
}
else if ((line[0] == 'u' || line[0] == 'U') && MemoryLoad) {
sscanf(line, "%*s %s %x %d", fileName, &address, &size);
fprintf(LogFp,
"UnloadFile name=%s addr=0x%08x size=%d\n",
fileName, address, size);
if (UnloadFile(fileName, address, size)!= 0) {
_TRACE(DERROR, fprintf(LogFp,
"ERROR: Fail to unload %s!\n", fileName));
}
continue;
}
else if (line[0] == 'q' || line[0] == 'Q') {
ret = IoCmd(REQ_QUIT, 0);
break;
}
else if (line[0] == 'f' || line[0] == 'F') {
sscanf(line, "%*s %s", dumpFile);
if ((dumpFp = fopen(dumpFile, "w+")) == NULL) {
fprintf(LogFp,
"Unable to open %s\n", dumpFile);
}
continue;
} /* else */
} /* while */
fclose(fp);
fprintf(LogFp,
"\n***** End of IO verification (total error = %d) ****\n",
errorTotal);
if (dumpFp)
fclose(dumpFp);
return(0);
} /* IoProcessTestFile */
int
IoTest(void)
{
return(IoProcessTestFile(CmdFile));
} /* IoTest */