OpenCores
URL https://opencores.org/ocsvn/wbddr3/wbddr3/trunk

Subversion Repositories wbddr3

[/] [wbddr3/] [trunk/] [bench/] [cpp/] [ddrsdram_tb.cpp] - Blame information for rev 9

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    ddrsdram_tb.cpp
4
//
5
// Project:     A wishbone controlled DDR3 SDRAM memory controller.
6
//
7
// Purpose:     To determine whether or not the wbddrsdram Verilog module works.
8
//              Run this program with no arguments.  If the last line output
9
//      is "SUCCESS", you will know it works.
10
//
11
// Creator:     Dan Gisselquist, Ph.D.
12
//              Gisselquist Technology, LLC
13
//
14
////////////////////////////////////////////////////////////////////////////////
15
//
16
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
17
//
18
// This program is free software (firmware): you can redistribute it and/or
19
// modify it under the terms of  the GNU General Public License as published
20
// by the Free Software Foundation, either version 3 of the License, or (at
21
// your option) any later version.
22
//
23
// This program is distributed in the hope that it will be useful, but WITHOUT
24
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
25
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26
// for more details.
27
//
28
// You should have received a copy of the GNU General Public License along
29
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
30
// target there if the PDF file isn't present.)  If not, see
31
// <http://www.gnu.org/licenses/> for a copy.
32
//
33
// License:     GPL, v3, as defined and found on www.gnu.org,
34
//              http://www.gnu.org/licenses/gpl.html
35
//
36
//
37
////////////////////////////////////////////////////////////////////////////////
38
//
39
//
40
#include <stdio.h>
41
 
42
#include "verilated.h"
43
#include "Vwbddrsdram.h"
44
#include "ddrsdramsim.h"
45
 
46
const int       BOMBCOUNT = 2048,
47
                SDRAMMASK = 0x3ffffff,
48
                LGMEMSIZE = 28;
49
 
50
class   DDRSDRAM_TB {
51
        long            m_tickcount;
52
        Vwbddrsdram     *m_core;
53
        DDRSDRAMSIM     *m_sdram;
54
        bool            m_bomb;
55
public:
56
 
57
        DDRSDRAM_TB(void) {
58
                m_core = new Vwbddrsdram;
59
                m_sdram= new DDRSDRAMSIM(LGMEMSIZE);
60
        }
61
 
62
        unsigned &operator[](const int index) { return (*m_sdram)[index]; }
63
        void    set(unsigned addr, unsigned v) {
64
                (*m_sdram)[addr] = v;
65
        }
66
 
67
        void    tick(void) {
68
                m_core->i_clk = 1;
69
 
70
                m_core->i_ddr_data = (*m_sdram)(
71
                        m_core->o_ddr_reset_n,
72
                        m_core->o_ddr_cke,
73
                        m_core->o_ddr_cs_n,
74
                        m_core->o_ddr_ras_n,
75
                        m_core->o_ddr_cas_n,
76
                        m_core->o_ddr_we_n,
77
                        m_core->o_ddr_dqs,
78
                        m_core->o_ddr_dm,
79
                        m_core->o_ddr_odt,
80
                        m_core->o_ddr_bus_oe,
81
                        m_core->o_ddr_addr,
82
                        m_core->o_ddr_ba,
83
                        m_core->o_ddr_data);
84
 
85 6 dgisselq
                bool    writeout = (!m_core->v__DOT__reset_override);
86 4 dgisselq
 
87 6 dgisselq
                if (writeout) {
88
                        int cmd;
89
                        cmd = (m_core->o_ddr_reset_n?0:32)
90
                                |(m_core->o_ddr_cke?0:16)
91
                                |(m_core->o_ddr_cs_n?8:0)
92
                                |(m_core->o_ddr_ras_n?4:0)
93
                                |(m_core->o_ddr_cas_n?2:0)
94
                                |(m_core->o_ddr_we_n?1:0);
95
                        printf("%08lx-WB: %s/%s %s%s%s %s@0x%08x[%08x/%08x] -- ",
96
                                m_tickcount,
97
                                (m_core->i_wb_cyc)?"CYC":"   ",
98
                                (m_core->i_wb_stb)?"STB":"   ",
99
                                (m_core->o_wb_stall)?"STALL":"     ",
100
                                (m_core->o_wb_ack)?"ACK":"   ",
101
                                (m_core->o_cmd_accepted)?"BUS":"   ",
102
                                (m_core->i_wb_we)?"W":"R",
103
                                (m_core->i_wb_addr),
104
                                (m_core->i_wb_data),
105
                                (m_core->o_wb_data));
106 4 dgisselq
 
107 6 dgisselq
                        printf("%s%s %d%d%d%d %s%s%s%s B[%d]@%04x %08x %08x",
108
                                (m_core->o_ddr_reset_n)?" ":"R",
109
                                (m_core->o_ddr_cke)?"CK":"  ",
110
                                (m_core->o_ddr_cs_n),
111
                                (m_core->o_ddr_ras_n),
112
                                (m_core->o_ddr_cas_n),
113
                                (m_core->o_ddr_we_n),
114
                                //
115
                                (m_core->o_ddr_dqs)?"D":" ",
116
                                (m_core->o_ddr_dm)?"M":" ",
117
                                (m_core->o_ddr_odt)?"O":" ",
118
                                (m_core->o_ddr_bus_oe)?"E":" ",
119
                                //
120
                                (m_core->o_ddr_ba),
121
                                (m_core->o_ddr_addr),
122
                                (m_core->i_ddr_data),
123
                                (m_core->o_ddr_data));
124 4 dgisselq
 
125 9 dgisselq
                        printf(" FIFO[%x,%x](%s,%d,%08x)",
126 7 dgisselq
                                m_core->v__DOT__bus_fifo_head,
127
                                m_core->v__DOT__bus_fifo_tail,
128 9 dgisselq
                                (m_core->v__DOT__bus_fifo_new[m_core->v__DOT__bus_fifo_tail])?"N":"o",
129 7 dgisselq
                                m_core->v__DOT__bus_fifo_sub[m_core->v__DOT__bus_fifo_tail],
130
                                m_core->v__DOT__bus_fifo_data[m_core->v__DOT__bus_fifo_tail]);
131
 
132
                        printf(" BUS[%03x/%03x/%03x/%d]",
133
                                (m_core->v__DOT__bus_active),
134
                                (m_core->v__DOT__bus_read),
135
                                (m_core->v__DOT__bus_new),
136
                                (m_core->v__DOT__bus_subaddr[8]));
137
 
138 8 dgisselq
                        /*
139 6 dgisselq
                        // Reset logic
140
                        printf(" RST(%06x%s[%d] - %08x->%08x)",
141
                                m_core->v__DOT__reset_timer,
142
                                (m_core->v__DOT__reset_ztimer)?"Z":" ",
143
                                (m_core->v__DOT__reset_address),
144
                                (m_core->v__DOT__reset_instruction),
145
                                (m_core->v__DOT__reset_cmd));
146 8 dgisselq
                        */
147 4 dgisselq
 
148 9 dgisselq
                        printf(" R_%s%03x[%d]%04x:%d/%08x",
149
                                (!m_core->v__DOT__r_pending)?"_"
150
                                        :(m_core->v__DOT__r_we)?"W":"R",
151 6 dgisselq
                                (m_core->v__DOT__r_row),
152
                                (m_core->v__DOT__r_bank),
153 9 dgisselq
                                (m_core->v__DOT__r_col),
154
                                (m_core->v__DOT__r_sub),
155
                                (m_core->v__DOT__r_data));
156
 
157
                        printf(" S_%s%03x[%d]%04x:%d/%08x%s%s%s",
158
                                (!m_core->v__DOT__s_pending)?"_"
159
                                        :(m_core->v__DOT__s_we)?"W":"R",
160
                                (m_core->v__DOT__s_row),
161
                                (m_core->v__DOT__s_bank),
162
                                (m_core->v__DOT__s_col),
163
                                (m_core->v__DOT__s_sub),
164
                                (m_core->v__DOT__s_data),
165
                                (m_core->v__DOT__s_match)?"M":" ",
166
                                (m_core->v__DOT__pipe_stall)?"P":" ",
167
                                "-"
168
                                //(m_core->v__DOT__s_stall)?"S":" "
169
                                );
170
 
171
 
172 6 dgisselq
                        printf(" %s%s%s",
173 7 dgisselq
                                "B",
174
                                // (m_core->v__DOT__all_banks_closed)?"b":"B",
175 6 dgisselq
                                (m_core->v__DOT__need_close_bank)?"C":"N",
176
                                //:(m_core->v__DOT__maybe_close_next_bank)?"c":"N",
177
                                (m_core->v__DOT__need_open_bank)?"O":"K");
178
                                // :(m_core->v__DOT__maybe_open_next_bank)?"o":"K");
179
                        for(int i=0; i<8; i++) {
180 7 dgisselq
                                printf("%s%x@%x%s",
181 6 dgisselq
                                        (m_core->v__DOT__r_bank==i)?"R":"[",
182
                                        m_core->v__DOT__bank_status[i],
183
                                        m_core->v__DOT__bank_address[i],
184
                                        (m_core->v__DOT__r_nxt_bank==i)?"N":"]");
185
                        }
186
 
187 4 dgisselq
 
188 6 dgisselq
                        extern int gbl_state, gbl_counts;
189
                        printf(" %2d:%08x ", gbl_state, gbl_counts);
190
 
191 9 dgisselq
                        printf(" %s%s%s%s%s%s:%08x:%08x",
192 6 dgisselq
                                (m_core->v__DOT__reset_override)?"R":" ",
193
                                (m_core->v__DOT__need_refresh)?"N":" ",
194
                                (m_core->v__DOT__need_close_bank)?"C":" ",
195
                                (m_core->v__DOT__need_open_bank)?"O":" ",
196
                                (m_core->v__DOT__valid_bank)?"V":" ",
197 7 dgisselq
                                (m_core->v__DOT__r_move)?"R":" ",
198 6 dgisselq
                                m_core->v__DOT__activate_bank_cmd,
199
                                m_core->v__DOT__cmd);
200
 
201 7 dgisselq
                        printf(" F%s%05x:%x/%s",
202
                                (m_core->v__DOT__refresh_ztimer)?"Z":" ",
203
                                m_core->v__DOT__refresh_counter,
204
                                m_core->v__DOT__refresh_addr,
205
                                (m_core->v__DOT__need_refresh)?"N":" ");
206 6 dgisselq
 
207
                        if (m_core->v__DOT__reset_override)
208
                                printf(" OVERRIDE");
209
                        //if(m_core->v__DOT__last_open_bank)printf(" LST-OPEN");
210
                        switch(cmd) {
211
                        case DDR_MRSET:     printf(" MRSET"); break;
212
                        case DDR_REFRESH:   printf(" REFRESH"); break;
213
                        case DDR_PRECHARGE: printf(" PRECHARGE%s", (m_core->o_ddr_addr&0x400)?"-ALL":""); break;
214
                        case DDR_ACTIVATE:  printf(" ACTIVATE"); break;
215
                        case DDR_WRITE:     printf(" WRITE"); break;
216
                        case DDR_READ:      printf(" READ"); break;
217
                        case DDR_ZQS:       printf(" ZQS"); break;
218
                        case DDR_NOOP:      printf(" NOOP"); break;
219
                        default: printf(" Unknown-CMD(%02x)", cmd); break;
220
                        }
221
 
222
                        // Decode the command
223
 
224
                        printf("\n");
225
                }
226
 
227 4 dgisselq
                m_core->eval();
228
                m_core->i_clk = 0;
229
                m_core->eval();
230
 
231
                m_tickcount++;
232
 
233
                /*
234
                if ((m_core->o_wb_ack)&&(!m_core->i_wb_cyc)) {
235
                        printf("SETTING ERR TO TRUE!!!!!  ACK w/ no CYC\n");
236
                        // m_bomb = true;
237
                }
238
                */
239
        }
240
 
241
        void reset(void) {
242
                m_core->i_reset  = 1;
243
                m_core->i_wb_cyc = 0;
244
                m_core->i_wb_stb = 0;
245
                tick();
246
                m_core->i_reset  = 0;
247
        }
248
 
249
        void wb_tick(void) {
250
                m_core->i_wb_cyc   = 0;
251
                m_core->i_wb_stb = 0;
252
                tick();
253
        }
254
 
255
        unsigned wb_read(unsigned a) {
256
                int             errcount = 0;
257
                unsigned        result;
258
 
259
                printf("WB-READ(%08x)\n", a);
260
 
261
                m_core->i_wb_cyc = 1;
262
                m_core->i_wb_stb = 1;
263
                m_core->i_wb_we  = 0;
264
                m_core->i_wb_addr= a & SDRAMMASK;
265
 
266
                if (m_core->o_wb_stall) {
267
                        while((errcount++ < BOMBCOUNT)&&(m_core->o_wb_stall))
268
                                tick();
269 9 dgisselq
                } tick();
270 4 dgisselq
 
271
                m_core->i_wb_stb = 0;
272
 
273
                while((errcount++ <  BOMBCOUNT)&&(!m_core->o_wb_ack))
274
                        tick();
275
 
276
 
277
                result = m_core->o_wb_data;
278
 
279
                // Release the bus?
280
                m_core->i_wb_cyc = 0;
281
                m_core->i_wb_stb = 0;
282
 
283
                if(errcount >= BOMBCOUNT) {
284
                        printf("SETTING ERR TO TRUE!!!!!\n");
285
                        m_bomb = true;
286
                } else if (!m_core->o_wb_ack) {
287
                        printf("SETTING ERR TO TRUE--NO ACK, NO TIMEOUT\n");
288
                        m_bomb = true;
289
                }
290
                tick();
291
 
292
                return result;
293
        }
294
 
295
        void    wb_read(unsigned a, int len, unsigned *buf) {
296
                int             errcount = 0;
297
                int             THISBOMBCOUNT = BOMBCOUNT * len;
298
                int             cnt, rdidx, inc;
299
 
300
                printf("WB-READ(%08x, %d)\n", a, len);
301
 
302
                while((errcount++ < BOMBCOUNT)&&(m_core->o_wb_stall))
303
                        wb_tick();
304
 
305
                if (errcount >= BOMBCOUNT) {
306
                        m_bomb = true;
307
                        return;
308
                }
309
 
310
                errcount = 0;
311
 
312
                m_core->i_wb_cyc = 1;
313
                m_core->i_wb_stb = 1;
314
                m_core->i_wb_we  = 0;
315
                m_core->i_wb_addr= a & SDRAMMASK;
316
 
317
                rdidx =0; cnt = 0;
318
                inc = 1;
319
 
320
                do {
321
                        int     s;
322
                        s = (m_core->o_wb_stall==0)?0:1;
323
                        tick();
324
                        if (!s)
325
                                m_core->i_wb_addr += inc;
326
                        cnt += (s==0)?1:0;
327
                        if (m_core->o_wb_ack)
328
                                buf[rdidx++] = m_core->o_wb_data;
329
                } while((cnt < len)&&(errcount++ < THISBOMBCOUNT));
330
 
331
                m_core->i_wb_stb = 0;
332
 
333
                while((rdidx < len)&&(errcount++ < THISBOMBCOUNT)) {
334
                        tick();
335
                        if (m_core->o_wb_ack)
336
                                buf[rdidx++] = m_core->o_wb_data;
337
                }
338
 
339
                // Release the bus?
340
                m_core->i_wb_cyc = 0;
341
 
342
                if(errcount >= THISBOMBCOUNT) {
343
                        printf("SETTING ERR TO TRUE!!!!! (errcount=%08x, THISBOMBCOUNT=%08x)\n", errcount, THISBOMBCOUNT);
344
                        m_bomb = true;
345
                } else if (!m_core->o_wb_ack) {
346
                        printf("SETTING ERR TO TRUE--NO ACK, NO TIMEOUT\n");
347
                        m_bomb = true;
348
                }
349
                tick();
350
        }
351
 
352
        void    wb_write(unsigned a, unsigned int v) {
353
                int errcount = 0;
354
 
355
                printf("WB-WRITE(%08x) = %08x\n", a, v);
356
                m_core->i_wb_cyc = 1;
357
                m_core->i_wb_stb = 1;
358
                m_core->i_wb_we  = 1;
359
                m_core->i_wb_addr= a & SDRAMMASK;
360
                m_core->i_wb_data= v;
361
 
362
                if (m_core->o_wb_stall)
363
                        while((errcount++ < BOMBCOUNT)&&(m_core->o_wb_stall))
364
                                tick();
365
                tick();
366
 
367
                m_core->i_wb_stb = 0;
368
 
369
                while((errcount++ <  BOMBCOUNT)&&(!m_core->o_wb_ack))
370
                        tick();
371
 
372
                // Release the bus?
373
                m_core->i_wb_cyc = 0;
374
                m_core->i_wb_stb = 0;
375
 
376
                if(errcount >= BOMBCOUNT) {
377
                        printf("SETTING ERR TO TRUE!!!!!\n");
378
                        m_bomb = true;
379
                } tick();
380
        }
381
 
382
        void    wb_write(unsigned a, unsigned int ln, unsigned int *buf) {
383
                unsigned errcount = 0, nacks = 0;
384
 
385
                m_core->i_wb_cyc = 1;
386
                m_core->i_wb_stb = 1;
387
                for(unsigned stbcnt=0; stbcnt<ln; stbcnt++) {
388
                        m_core->i_wb_we  = 1;
389
                        m_core->i_wb_addr= (a+stbcnt) & SDRAMMASK;
390
                        m_core->i_wb_data= buf[stbcnt];
391
                        errcount = 0;
392
 
393
                        while((errcount++ < BOMBCOUNT)&&(m_core->o_wb_stall)) {
394
                                tick(); if (m_core->o_wb_ack) nacks++;
395
                        }
396
                        // Tick, now that we're not stalled.  This is the tick
397
                        // that gets accepted.
398
                        tick(); if (m_core->o_wb_ack) nacks++;
399
                }
400
 
401
                m_core->i_wb_stb = 0;
402
 
403
                errcount = 0;
404
                while((nacks < ln)&&(errcount++ < BOMBCOUNT)) {
405
                        tick();
406
                        if (m_core->o_wb_ack) {
407
                                nacks++;
408
                                errcount = 0;
409
                        }
410
                }
411
 
412
                // Release the bus
413
                m_core->i_wb_cyc = 0;
414
                m_core->i_wb_stb = 0;
415
 
416
                if(errcount >= BOMBCOUNT) {
417
                        printf("SETTING ERR TO TRUE!!!!!\n");
418
                        m_bomb = true;
419
                } tick();
420
        }
421
 
422
        bool    bombed(void) const { return m_bomb; }
423
 
424
};
425
 
426
void    uload(unsigned len, unsigned *buf) {
427
        FILE    *fp = fopen("/dev/urandom", "r");
428
 
429
        if ((NULL == fp)||(len != fread(buf, sizeof(unsigned), len, fp))) {
430
                for(int i=0; i<(int)len; i++)
431
                        buf[i] = rand();
432
        } if (NULL == fp)
433
                fclose(fp);
434
}
435
 
436
int main(int  argc, char **argv) {
437
        Verilated::commandArgs(argc, argv);
438
        DDRSDRAM_TB     *tb = new DDRSDRAM_TB;
439
        unsigned        *rdbuf, *mbuf;
440
        unsigned        mlen = (1<<(LGMEMSIZE-2));
441
 
442
        printf("Giving the core 140k cycles to start up\n");
443
        // Before testing, let's give the unit time enough to warm up
444
        tb->reset();
445 7 dgisselq
        for(int i=0; i<141195; i++)
446 4 dgisselq
                tb->wb_tick();
447
 
448 8 dgisselq
        // Let's short circuit the test, and only test *some* of the memory
449
        // space.  It'll probably be good enough, and it'll finish while I'm
450
        // waiting ...
451
        mlen = 1<<16;
452
 
453 4 dgisselq
        printf("Getting some memory ...\n");
454
        rdbuf = new unsigned[mlen];
455
        mbuf  = new unsigned[mlen]; // Match buffer
456
        printf("Charging my memory with random values\n");
457
        uload(mlen, rdbuf);
458
 
459 9 dgisselq
#define SINGULAR_WRITE
460
#define SINGULAR_READ
461
#define BIGPIPELINE_WRITE
462
#define BIGPIPELINE_READ
463
#define PRIMEVEC_WRITE
464
#define PRIMEVEC_READ
465
#define SKIP_WRITE
466
#define SKIP_READ
467
 
468
#ifdef  SINGULAR_WRITE
469 4 dgisselq
        // First test: singular reads through the memory, followed by
470
        // singular  writes
471
        printf("Starting the single-read test\n");
472
        for(int i=0; i<(int)mlen; i++) {
473
                tb->wb_write(i, rdbuf[i]);
474
                tb->wb_tick();
475
                if ((*tb)[i] != rdbuf[i]) {
476
                        printf("WRITE[%06x] = %08x (Expecting %08x) FAILED\n",
477
                                i, (*tb)[i], rdbuf[i]);
478
                        goto test_failure;
479
                } if (tb->bombed())
480
                        goto test_failure;
481
 
482 9 dgisselq
        }
483
#else
484
#ifdef  SINGULAR_READ
485
        // If we aren't doing the write test, we still need to charge
486
        // the memory for the read test.  Here we do it manually.
487
        for(int i=0; i<(int)mlen; i++)
488
                (*tb)[i] = rdbuf[i];
489
#endif // !SINGULAR_WRITE && SINGULAR_READ
490
#endif // SINGULAR_WRITE
491
#ifdef  SINGULAR_READ
492
        for(int i=0; i<(int)mlen; i++) {
493 4 dgisselq
                unsigned        v;
494
                if (rdbuf[i] != (v=tb->wb_read(i))) {
495
                        printf("READ[%06x] = %08x (Expecting %08x)\n",
496
                                i, v, rdbuf[i]);
497
                        goto test_failure;
498
                } if (tb->bombed())
499
                        goto test_failure;
500
                tb->wb_tick();
501
        }
502 9 dgisselq
#endif
503 4 dgisselq
 
504 9 dgisselq
#ifdef  BIGPIPELINE_WRITE
505 4 dgisselq
        // Second test: Vector writes going through all memory, followed a
506
        // massive vector read
507
        uload(mlen, rdbuf); // Get some new values
508
        tb->wb_write(0, mlen, rdbuf);
509
        if (tb->bombed())
510
                goto test_failure;
511
        for(int i=0; i<(int)mlen; i++) {
512
                unsigned        v;
513
                if (rdbuf[i] != (v=(*tb)[i])) {
514
                        printf("V-WRITE[%06x] = %08x (Expecting %08x)\n",
515
                                i, v, rdbuf[i]);
516
                        goto test_failure;
517
                }
518
        }
519 9 dgisselq
#else
520
#ifdef  BIGPIPELINE_READ
521
        uload(mlen, rdbuf); // Get some new values
522
        // If we aren't doing the write test, we still need to charge
523
        // the memory for the read test.  Here we do it manually.
524
        for(int i=0; i<(int)mlen; i++)
525
                (*tb)[i] = rdbuf[i];
526
#endif // BIGPIPELINE_WRITE && BIGPIPELINE_READ
527
#endif
528
#ifdef  BIGPIPELINE_READ
529 4 dgisselq
        tb->wb_read( 0, mlen, mbuf);
530
        if (tb->bombed())
531
                goto test_failure;
532
        for(int i=0; i<(int)mlen; i++) {
533
                if (rdbuf[i] != mbuf[i]) {
534
                        printf("V-READ[%06x] = %08x (Expecting %08x)\n",
535
                                i, mbuf[i], rdbuf[i]);
536
                        goto test_failure;
537
                }
538
        }
539 9 dgisselq
#endif
540 4 dgisselq
 
541 9 dgisselq
#ifdef  PRIMEVEC_WRITE
542 8 dgisselq
        // Third test: Vector writes going through all memory, in prime numbers
543 4 dgisselq
        // of values at a time, followed by reads via a different prime number
544 8 dgisselq
        uload(mlen, rdbuf); // Get some new values
545 9 dgisselq
        {
546
                int     nw = 3;
547
                for(int i=0; i<(int)mlen; i+=nw) {
548
                        int     ln = ((int)mlen-i>nw)?nw:mlen-i;
549
                        tb->wb_write(i, nw, &rdbuf[i]);
550
                        for(int j=0; j<ln; j++) {
551
                                if ((*tb)[i+j] != rdbuf[i+j]) {
552
                                        printf("P-WRITE[%06x] = %08x (Expecting %08x) FAILED\n",
553
                                                i, (*tb)[i], rdbuf[i]);
554
                                        goto test_failure;
555
                                }
556
                        } if (tb->bombed())
557 4 dgisselq
                                goto test_failure;
558 9 dgisselq
                }
559
        }
560
#else
561
#ifdef  PRIMEVEC_READ
562
        uload(mlen, rdbuf); // Get some new values
563
        // If we aren't doing the write test, we still need to charge
564
        // the memory for the read test.  Here we do it manually.
565
        for(int i=0; i<(int)mlen; i++)
566
                (*tb)[i] = rdbuf[i];
567
#endif
568
#endif
569
#ifdef  PRIMEVEC_READ
570
        {
571
                int     nr = 13;
572
                for(int i=0; i<(int)mlen; i+=nr) {
573
                        int     ln = ((int)mlen-i>nr)?nr:mlen-i;
574
                        tb->wb_read(i, nr, &mbuf[i]);
575
                        for(int j=0; j<ln; j++) {
576
                                if (mbuf[i+j] != rdbuf[i+j]) {
577
                                        printf("P-READ[%06x] = %08x (Expecting %08x) FAILED\n",
578
                                                i, mbuf[i], rdbuf[i]);
579
                                        goto test_failure;
580
                                }
581
                        } if (tb->bombed())
582 4 dgisselq
                                goto test_failure;
583 9 dgisselq
                }
584 4 dgisselq
        }
585 9 dgisselq
#endif
586 4 dgisselq
 
587 9 dgisselq
#ifdef  SKIP_WRITE
588 8 dgisselq
        // Fourth test: Singular writes though all of memory, skipping by some
589
        // prime address increment each time, followed by reads via a different
590
        // prime numbered increment.
591
        uload(mlen, rdbuf); // Get some new values
592
        for(int i=0; i<(int)mlen; i++) {
593 9 dgisselq
                int     loc = (i*3889)&(mlen-1);
594 8 dgisselq
                tb->wb_write(loc, rdbuf[loc]);
595
                if ((*tb)[loc] != rdbuf[loc]) {
596
                        printf("R-WRITE[%06x] = %08x (Expecting %08x) FAILED\n",
597
                                i, (*tb)[loc], rdbuf[loc]);
598
                        goto test_failure;
599
                } if (tb->bombed())
600
                        goto test_failure;
601 9 dgisselq
        }
602
#else
603
#ifdef  SKIP_READ
604
        uload(mlen, rdbuf); // Get some new values
605
        for(int i=0; i<(int)mlen; i++)
606
                (*tb)[i] = rdbuf[i];
607
#endif // !SKIP_WRITE && SKIP_READ
608
#endif
609
#ifdef  SKIP_READ
610
        for(int i=0; i<(int)mlen; i++) {
611
                int     loc = (i*7477)&(mlen-1);
612 8 dgisselq
                mbuf[loc] = tb->wb_read(loc);
613
                if (mbuf[loc] != rdbuf[loc]) {
614
                        printf("R-READ[%06x] = %08x (Expecting %08x) FAILED\n",
615
                                loc, mbuf[loc], rdbuf[loc]);
616
                        goto test_failure;
617
                } if (tb->bombed())
618
                        goto test_failure;
619
        }
620 9 dgisselq
#endif
621 4 dgisselq
 
622 8 dgisselq
 
623 4 dgisselq
        printf("SUCCESS!!\n");
624
        exit(0);
625
test_failure:
626
        printf("FAIL-HERE\n");
627
        for(int i=0; i<64; i++)
628
                tb->tick();
629
        printf("TEST FAILED\n");
630
        exit(-1);
631
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.