rsp_bp.c
4.45 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
#include <sys/types.h>
#include <sys/sbd.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/sema.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <getopt.h>
#include <sys/u64driver.h>
#include <rsp.h>
/*
* From $ROOT/usr/include/ide, which is installed from $ROOT/PR/diags/include
*/
#include "diag.h"
#define RSP_TEST_BASE 10
static int rsptest(TEST_REF *test_ref);
/*
* Create an array of tests, each of which corresponds to a separate menu
* item callable from the master ide menu.
*/
static TEST_REF TestRefs[] = {
{"RSP test", RSP_TEST_BASE+0, rsptest},
{"",0,0}
};
static char *TestName, *addr, *mask, *count;
static int NumFailures = 0;
static int ShortMsg = 0;
static int DebugLevel = 0;
static int rsp_bpInit();
static int rsp_bpDo(TEST_REF *test_ref);
int debug;
/*
* diagnostic entry point:
*
* Each separately invokable ide diagnostic command corresponds to an
* independent ".c" module; the entry point herein must match
* the test name as specified in the rspcmd.awk script. These command
* names correspond to the names you see from the ide menu. For this
* module, there will be an ide command "rsp_bp" (until this
* silly module is retired, that is).
*/
int rsp_bp(struct diagcomm *pcomm)
{
int c;
debug = 0;
/*
* Sample of how to parse command line args received from ide
*/
while ((c = getopt(pcomm->argc, pcomm->argv, "d")) != EOF) {
switch(c) {
case 'd':
debug = 1;
break;
default:
printf("weird option character %c = 0x%x\n", c, c);
break;
}
}
TestName = pcomm->argv[0];
/*
* IDE will call our one-time initialization function rsp_bpInit(),
* then invoke rsp_bpDo() for as many tests as we've put into the
* global test array "TestRefs", declared at the top of this module.
*/
diaginit(TestRefs, rsp_bpInit, rsp_bpDo);
if (NumFailures) {
errlog(INFO_END, 0, 0, "... test %s FAILED, %d failures.",
TestName, NumFailures);
} else {
errlog(INFO_END, 0, 0, "... test %s PASSED", TestName);
}
}
static int rsp_bpInit()
{
char *env;
if (env = getenv("IDE_DEBUG_LEVEL")) DebugLevel = atoi(env);
if (env = getenv("IDE_SHORT_MSG")) ShortMsg = atoi(env);
errlog(INFO_START, 0, 0, "Starting test %s ... ", TestName);
NumFailures = 0;
/*
* Setup the diagnostic communication link to the target system.
*
* For now, this can only be done with the TARGET indy environment.
*/
if (debug)
dgInitComm();
return(0);
}
static int rsp_bpDo(TEST_REF *test_ref)
{
int rc;
if (!ShortMsg)
errlog(INFO_START, test_ref->num, 0,
"%s: starting subtest %s (%d) ...",
TestName, test_ref->name, test_ref->num);
/*
* Invoke the actual test from the "TEST_REF" array statically declared
* as a global within this test module.
*/
if (rc = test_ref->fnc(test_ref)) NumFailures++;
if (!ShortMsg) {
if (rc == 0) errlog(INFO_END, test_ref->num, 0, "... PASSED");
else errlog(INFO_END, test_ref->num, 0, "... FAILED");
}
return(NumFailures);
}
/*
* Return value: number of errors encountered. "Zero" indicates success.
*/
int
rsptest(TEST_REF *test_ref)
{
int ret_len;
int len = 4; /* hardwired to four bytes for simple test */
int id = 0; /* use a thread id of zero, seems to work with dbgif */
unsigned char buf[256];
int *pBuf;
/*
* If the debug flag is set, try writing, then reading back some values
* to a safe memory location on the TARGET indy.
*/
if (debug) {
pBuf = (int *)buf;
*pBuf = 0xdeadbeef;
ret_len = dgWriteMem (id, RSP_DMEM_BASE, len, pBuf);
if (ret_len < 0) {
errlog(ERR_SEVERE, test_ref->num, 0,
"%s: error: dgWriteMem() call failed.\n", TestName);
return(1);
}
ret_len = dgReadMem (id, RSP_DMEM_BASE, len, pBuf);
if (ret_len < 0) {
errlog(ERR_SEVERE, test_ref->num, 0,
"%s: error: dgReadMem() call failed.\n", TestName);
return(1);
}
if (ret_len < len) {
errlog(ERR_SIMPLE, test_ref->num, 0,
"%s: warning: %d bytes requested, could only read %d bytes.\n",
TestName, len, ret_len);
}
if (*pBuf != 0xdeadbeef) {
errlog(ERR_SIMPLE, test_ref->num, 0,
"0x%08x: read 0x%x, exp 0x%x, rd^exp = 0x%x\n",
RSP_DMEM_BASE, *pBuf, 0xdeadbeef, (*pBuf ^ 0xdeadbeef));
} else {
errlog(INFO, test_ref->num, 0, "0x%08x: 0x%x\n", RSP_DMEM_BASE, *pBuf);
}
}
return(0);
}