sp_tests.v
4.17 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
// sp_tests.v v1 Frank Berndt
// sp tests;
// :set tabstop=4
`define SP_NA_DMEM 12 // # of sp dmem address bits;
`define SP_NA_IMEM 12 // # of sp imem address bits;
// spin on sp io full;
task sp_spin_iofull;
reg [31:0] rdata; // read data;
begin
sread(`SP_STATUS, `CPU_SIZE_4, rdata);
while(rdata[4] === 1)
sread(`SP_STATUS, `CPU_SIZE_4, rdata);
//XXX timeout;
end
endtask
// targeted test for single requests to sp memories;
task sp_mem_sglwalk;
input [31:0] space; // address space;
input [5:0] nabits; // # of address bits;
input reqspc; // use random request spacing;
reg [31:0] addr; // address;
reg [31:0] amask; // address mask;
reg [31:0] saddr [2:29]; // single address;
reg [31:0] sdata [2:29]; // single data;
integer n;
begin
// test writes;
$display("test: %M: space 0x%h, spacing %b", space, reqspc);
amask = 32'hffff_ffff >> (32 - nabits);
amask[1:0] = 2'b00;
// walk one address bit;
// randomize request spacing and data;
$display("test: %M: write, addr walking 1");
for(n = 2; n < nabits; n = n + 1) begin
addr = space | (1 << n);
addr[1:0] = 2'b00;
saddr[n] = addr;
sdata[n] = $random;
if(reqspc)
req_spacing($random);
swrite(addr, `CPU_SIZE_4, sdata[n]);
sp_spin_iofull;
end
$display("test: %M: write, addr walking 0");
for(n = 2; n < nabits; n = n + 1) begin
addr = saddr[n];
addr = addr ^ amask;
if(reqspc)
req_spacing($random);
swrite(addr, `CPU_SIZE_4, ~sdata[n]);
sp_spin_iofull;
end
// read back single data and check;
$display("test: %M: compare, addr walking 1");
for(n = 2; n < nabits; n = n + 1) begin
addr = saddr[n];
if(reqspc)
req_spacing($random);
sread(addr, `CPU_SIZE_4, data[0]);
rd_check(0, sdata[n], 32'hffff_ffff, 0);
end
$display("test: %M: compare, addr walking 0");
for(n = 2; n < nabits; n = n + 1) begin
addr = saddr[n];
addr = addr ^ amask;
if(reqspc)
req_spacing($random);
sread(addr, `CPU_SIZE_4, data[0]);
rd_check(0, ~sdata[n], 32'hffff_ffff, 0);
end
end
endtask
// fill sp memory with pattern;
// increasing number of 1s in address;
task sp_mem_fill_pat;
input [31:0] addr; // address space;
input [5:0] nabits; // # of address bits;
input [31:0] pxor; // patterrn xor;
integer n;
begin
$display("test: %M: space 0x%h", addr);
addr = addr & (32'hffff_ffff << nabits);
for(n = 2; n <= nabits; n = n + 1) begin
req_spacing($random);
swrite(addr, `CPU_SIZE_4, addr ^ pxor);
sp_spin_iofull;
addr = addr | (1 << n);
pxor = { pxor[30:0], pxor[31] };
end
end
endtask
// compare memory with pattern;
// increasing number of 1s in address;
// read d-cache size with random sub-block order;
// used for touch test;
task sp_mem_cmp_pat;
input [31:0] addr; // address space;
input [5:0] nabits; // # of address bits;
input [31:0] pxor; // patterrn xor;
reg [31:0] rdata; // read data;
integer n;
begin
$display("test: %M: space 0x%h", addr);
addr = addr & (32'hffff_ffff << nabits);
for(n = 2; n <= nabits; n = n + 1) begin
req_spacing($random);
sread(addr, `CPU_SIZE_4, rdata);
rd_check(0, addr ^ pxor, 32'hffff_ffff, 0);
addr = addr | (1 << n);
pxor = { pxor[30:0], pxor[31] };
end
end
endtask
// check that memory pattern is 0;
// test dmem;
task sp_dmem;
begin
sp_mem_sglwalk(`SP_DMEM, `SP_NA_DMEM, 0);
sp_mem_sglwalk(`SP_DMEM, `SP_NA_DMEM, 1);
end
endtask
// test imem;
task sp_imem;
begin
sp_mem_sglwalk(`SP_IMEM, `SP_NA_IMEM, 0);
sp_mem_sglwalk(`SP_IMEM, `SP_NA_IMEM, 1);
end
endtask
// run all sp tests;
task test_sp;
reg [31:0] pxor; // test pattern xor;
begin
// run register related tests;
// XXX
// test sp internal memories;
// since they are on the cbus, single requests only;
sp_dmem; // test dmem;
sp_imem; // test imem;
// fill all sp internal memories with address pattern;
// then read all back and compare;
// this tests read/write interference among those memories;
pxor = $random;
sp_mem_fill_pat(`SP_DMEM, `SP_NA_DMEM, pxor);
sp_mem_fill_pat(`SP_IMEM, `SP_NA_IMEM, pxor);
sp_mem_cmp_pat(`SP_DMEM, `SP_NA_DMEM, pxor);
sp_mem_cmp_pat(`SP_IMEM, `SP_NA_IMEM, pxor);
// XXX need a lot more here;
end
endtask