tst2c.c
5.09 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
/*************************************************************************
*
* File: tst2c.c
*
* This file converts test file to actual C calling routines.
*
* $Header: /root/leakn64/depot/rf/sw/n64os20l/iosim/src/tst2c.c,v 1.1.1.1 2002/05/30 05:41:20 whs Exp $
*
*/
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include "iomap.h"
#include "iotest.h"
#include "sim.h"
#include "simipc.h"
/***********************************************************************
* Extern definitions
*/
extern TstCmd TstCmdTbl[];
/***********************************************************************
* Macro definitions
*/
#define PROC_INC1_MSG "#include <stdio.h>\n#include \"trace.h\"\n"
#define PROC_INC2_MSG "#include \"iomap.h\"\n#include \"iotest.h\"\n"
#define PROC_BEGIN_MSG "\nvoid IoTestAll(void)\n{\n"
#define PROC_END_MSG "}\n"
#define PROC_VAR_MSG "\tint i, ret, errCount;\n\tint (*handler)(int, int, int, int);\n\n\ti = errCount = 0;\n"
#define PROC1_MSG "\ti++;\n\tret = %s(0x%x, 0x%x, 0x%x, 0x%x);\n"
#define PROC2_MSG "\tif (ret == -1) errCount++;\n"
#define TRACE_RES_MSG "\t_TRACE(DALL, fprintf(LogFp, \n\t\"\\n***** THE END (total test = %%d, error count = %%d) *****\\n\", \n\t\ti, errCount));\n\n"
#define TRACE_LOG_MSG "\t_TRACE(DALL, fprintf(LogFp, \n\t\t\"%%3d. %s(0x%x, 0x%x, 0x%x, 0x%x) -> %%s\\n\\n\", \n\t\ti, (ret == -1) ? \"Failed\":\"Passed\"));\n\n"
#define TEST_CMD_FILE "all.tst"
#define OPTARG "f:o:h"
/***********************************************************************
* Global definitions
*/
int IpcFd = -1;
unsigned long Dflags;
char *CmdFile = TEST_CMD_FILE;
FILE *LogFp, *CmdFp;
int ConfigRdramV = 0;
int NumberStallCycles = 0;
/***********************************************************************
* Local static definitions
*/
static void usage(void);
static void convertTst2C(char *);
static void dumpCmdTbl(TstCmd *);
main(int argc, char **argv)
{
int c, testId;
char *file;
FILE *fp = NULL;
extern char *optarg;
extern int optind, opterr, optopt;
optind = 1;
Dflags = 0;
LogFp = stderr;
while ((c = getopt(argc, argv, OPTARG)) != EOF) {
switch (c) {
case 'f': { /* Command file */
CmdFile = optarg;
printf("Command file = %s\n", CmdFile);
break;
}
case 'o': { /* Output log file */
file = optarg;
printf("Output file = %s\n", file);
if ((fp = fopen(file, "w+")) == NULL) {
printf("Unable to open log: %s\n",
file);
}
else
LogFp = fp;
break;
}
case 'h': { /* Help */
usage();
exit(0);
}
default:
usage();
exit(0);
}
} /* while */
convertTst2C(CmdFile);
/*
printf("TstCmdTbl = 0x%08x\n", TstCmdTbl);
dumpCmdTbl(TstCmdTbl);
*/
if (fp)
fclose(fp);
exit(0);
}
static void
usage(void)
{
printf("Usage: tst2c \n");
printf(" -o <output file>\n");
printf(" -f <test_file>\n");
}
/***********************************************************************
*
* - Read each line from test command file
* - Execute test based on id
*/
void
dumpCmdTbl(TstCmd *CmdTbl)
{
TstCmd *ct;
int i;
i = 0;
printf("Command Table:\n");
for (ct = CmdTbl, i = 0; ct->id != -1; ct++, i++) {
printf("%3d. Id=%3d, Handler=0x%08x, Cmd=0x%08x\n",
i, ct->id, ct->handler, ct);
}
} /* dumpCmdTbl */
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 */
/***********************************************************************
*/
void
convertTst2C(char *testFile)
{
FILE *fp;
char line[BUF_SIZE], dumpFile[BUF_SIZE];
int i, ret, 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, "Unable to open %s\n", testFile);
return;
}
/* Write out routine declaration */
fprintf(LogFp, PROC_INC1_MSG);
fprintf(LogFp, PROC_INC2_MSG);
fprintf(LogFp, PROC_BEGIN_MSG);
fprintf(LogFp, PROC_VAR_MSG);
/*
* line format (size= # of bytes)
* ===========
* t <id> <a1> <a2> ... <a4> // execute test <id>
* q // quit
*
*/
while (fgets(line, BUF_SIZE, fp)) {
if (line[0] == 't') {
sscanf(line, "%*s %d %x %x %x %x",
&tid, &a1, &a2, &a3, &a4);
printf("t %d %x %x %x %x\n", tid, a1, a2, a3, a4);
if ((cmd = lookupCmd(TstCmdTbl, tid)) != NULL) {
fprintf(LogFp, PROC1_MSG, cmd->name,
a1, a2, a3, a4);
fprintf(LogFp, PROC2_MSG);
fprintf(LogFp, TRACE_LOG_MSG, cmd->name,
a1, a2, a3, a4);
}
else {
fprintf(stderr, "ERROR: illegal test cmd=%d\n",
tid);
}
continue;
}
else if (line[0] == 'q' || line[0] == 'Q') {
break;
} /* else */
} /* while */
fclose(fp);
fprintf(LogFp, TRACE_RES_MSG);
fprintf(LogFp, PROC_END_MSG);
} /* convertTst2C */