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

Subversion Repositories xge_mac

[/] [xge_mac/] [trunk/] [tbench/] [systemc/] [sc_testcases.cpp] - Blame information for rev 12

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

Line No. Rev Author Line
1 2 antanguay
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "sc_testcases.cpp"                                ////
4
////                                                              ////
5
////  This file is part of the "10GE MAC" project                 ////
6
////  http://www.opencores.org/cores/xge_mac/                     ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - A. Tanguay (antanguay@opencores.org)                  ////
10
////                                                              ////
11
//////////////////////////////////////////////////////////////////////
12
////                                                              ////
13
//// Copyright (C) 2008 AUTHORS. All rights reserved.             ////
14
////                                                              ////
15
//// This source file may be used and distributed without         ////
16
//// restriction provided that this copyright statement is not    ////
17
//// removed from the file and that any derivative work contains  ////
18
//// the original copyright notice and the associated disclaimer. ////
19
////                                                              ////
20
//// This source file is free software; you can redistribute it   ////
21
//// and/or modify it under the terms of the GNU Lesser General   ////
22
//// Public License as published by the Free Software Foundation; ////
23
//// either version 2.1 of the License, or (at your option) any   ////
24
//// later version.                                               ////
25
////                                                              ////
26
//// This source is distributed in the hope that it will be       ////
27
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
28
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
29
//// PURPOSE.  See the GNU Lesser General Public License for more ////
30
//// details.                                                     ////
31
////                                                              ////
32
//// You should have received a copy of the GNU Lesser General    ////
33
//// Public License along with this source; if not, download it   ////
34
//// from http://www.opencores.org/lgpl.shtml                     ////
35
////                                                              ////
36
//////////////////////////////////////////////////////////////////////
37
 
38
#include "sc_testcases.h"
39
 
40
 
41
void testcases::connect_testbench(testbench* tbptr) {
42
    tb = tbptr;
43
}
44
 
45
void testcases::run_tests(void) {
46
 
47
    //---
48
    // Init
49
 
50
    tb->pkt_if0.init();
51
    tb->xgm_if0.init();
52
    tb->cpu_if0.init();
53
    tb->pif_gen0.init();
54
    tb->xgm_gen0.init();
55
    tb->sb.init();
56
 
57
    wait(300, SC_NS);
58
 
59
    tb->cpu_if0.enable_all_interrupts();
60
 
61
 
62
 
63
 
64
//    done = true;
65
//    return;
66
    //---
67
    // Testcases
68
 
69
    test_packet_size(50, 90, 50);
70
    test_packet_size(9000, 9020, 20);
71
 
72
    test_deficit_idle_count();
73
 
74
    test_crc_errors(50, 90, 300, 2);
75
    test_crc_errors(9000, 9020, 20, 1);
76
 
77
    test_txdfifo_ovflow();
78
    test_rxdfifo_ovflow();
79
 
80
    test_rx_fragments(55, 90, 300, 2);
81
    test_rx_coding_err(400, 4);
82
 
83
    test_rx_local_fault(55, 90, 600, 15);
84
    test_rx_remote_fault(55, 90, 600, 15);
85
 
86
    test_rx_pause(64, 70, 600, 5);
87
 
88
    test_interrupt_mask();
89
 
90
    done = true;
91
 
92
}
93
 
94
 
95
void testcases::test_deficit_idle_count(void) {
96
 
97
    int range;
98
    int size;
99
 
100
    cout << "-----------------------" << endl;
101
    cout << "Deficit IDLE count" << endl;
102
    cout << "-----------------------" << endl;
103
 
104
    for (range = 0; range < 8; range++) {
105
        for (size = 60; size < 68; size++) {
106
            packet_dic(size, size + range);
107
        }
108
    }
109
 
110
}
111
 
112
 
113
void testcases::packet_dic(int minsize, int maxsize) {
114
 
115
    sbStats_t* pif_stats;
116
    sbStats_t* xgm_stats;
117
 
118
    int cnt = 6;
119
    float delta;
120
    float cycletime = 6.4;
121
    float rate;
122
 
123
    //---
124
    // Setup parameters
125
 
126
    tb->sb.clear_stats();
127
 
128
    tb->pif_gen0.set_pkt_size(minsize, maxsize);
129
    tb->xgm_gen0.set_pkt_size(minsize, maxsize);
130
 
131
    //---
132
    // Enable traffic
133
 
134
    tb->pif_gen0.set_tx_bucket(cnt);
135
    tb->xgm_gen0.set_tx_bucket(cnt);
136
 
137
    //---
138
    // Wait for test to complete
139
 
140
    while (tb->pif_gen0.get_tx_bucket() != 0) {
141
        wait(10, SC_NS);
142
    }
143
 
144
    //---
145
    // Check traffic
146
 
147
    wait(1000, SC_NS);
148
 
149
    pif_stats = tb->sb.get_pif_stats();
150
    xgm_stats = tb->sb.get_xgm_stats();
151
 
152
    if (pif_stats->rx_pkt_cnt != cnt || xgm_stats->rx_pkt_cnt != cnt) {
153
        cout << "ERROR: Not all packets received." << endl;
154
        sc_stop();
155
    }
156
 
157
}
158
 
159
 
160
void testcases::test_packet_size(int min, int max, int cnt) {
161
 
162
    sbStats_t* pif_stats;
163
    sbStats_t* xgm_stats;
164
 
165
    cout << "-----------------------" << endl;
166
    cout << "Packet size" << endl;
167
    cout << "-----------------------" << endl;
168
 
169
    //---
170
    // Setup parameters
171
 
172
    tb->sb.clear_stats();
173
 
174
    tb->pif_gen0.set_pkt_size(min, max);
175
    tb->xgm_gen0.set_pkt_size(min, max);
176
 
177
    //---
178
    // Enable traffic
179
 
180
    tb->pif_gen0.set_tx_bucket(cnt);
181
    tb->xgm_gen0.set_tx_bucket(cnt);
182
 
183
    //---
184
    // Wait for test to complete
185
 
186
    while (tb->pif_gen0.get_tx_bucket() != 0) {
187
        wait(10, SC_NS);
188
    }
189
 
190
    //---
191
    // Check traffic
192
 
193
    wait(30000, SC_NS);
194
 
195
    pif_stats = tb->sb.get_pif_stats();
196
    xgm_stats = tb->sb.get_xgm_stats();
197
 
198
    if (pif_stats->rx_pkt_cnt != cnt) {
199
        cout << "ERROR: Not all packets received by PIF." << endl;
200
        cout << pif_stats->rx_pkt_cnt << " " << cnt << endl;
201
        sc_stop();
202
    }
203
 
204
    if (xgm_stats->rx_pkt_cnt != cnt) {
205
        cout << "ERROR: Not all packets received by XGM." << endl;
206
        cout << xgm_stats->rx_pkt_cnt << " " << cnt << endl;
207
        sc_stop();
208
    }
209
}
210
 
211
void testcases::test_crc_errors(int min, int max, int cnt, int interval) {
212
 
213
    sbStats_t* pif_stats;
214
    sbCpuStats_t* cpu_stats;
215
 
216
    cout << "-----------------------" << endl;
217
    cout << "CRC errors" << endl;
218
    cout << "-----------------------" << endl;
219
 
220
    //---
221
    // Setup parameters
222
 
223
    tb->sb.clear_stats();
224
 
225
    tb->xgm_gen0.set_pkt_size(min, max);
226
    tb->xgm_gen0.set_crc_errors(interval);
227
    tb->sb.disable_signal_check = true;
228
 
229
    //---
230
    // Enable traffic
231
 
232
    tb->xgm_gen0.set_tx_bucket(cnt);
233
 
234
    //---
235
    // Wait for test to complete
236
 
237
    while (tb->xgm_gen0.get_tx_bucket() != 0) {
238
        wait(10, SC_NS);
239
    }
240
 
241
    //---
242
    // Check traffic
243
 
244
    wait(30000, SC_NS);
245
 
246
    pif_stats = tb->sb.get_pif_stats();
247
    cpu_stats = tb->sb.get_cpu_stats();
248
 
249
    if (pif_stats->rx_pkt_cnt != cnt) {
250
        cout << "ERROR: Not all packets received by PIF." << endl;
251
        cout << pif_stats->rx_pkt_cnt << " " << cnt << endl;
252
        sc_stop();
253
    }
254
 
255
    if (cpu_stats->crc_error_cnt != pif_stats->crc_error_cnt) {
256
        cout << "ERROR: Not all CRC errors reported to cpu" << endl;
257
        sc_stop();
258
    }
259
 
260
    //---
261
    // Return parameters to default state
262
 
263
    tb->xgm_gen0.set_crc_errors(0);
264
    tb->sb.disable_signal_check = false;
265
}
266
 
267
void testcases::test_txdfifo_ovflow() {
268
 
269
    sbStats_t* xgm_stats;
270
    sbCpuStats_t* cpu_stats;
271
 
272
    cout << "-----------------------" << endl;
273
    cout << "TXD FIFO overflow" << endl;
274
    cout << "-----------------------" << endl;
275
 
276
    //---
277
    // Setup parameters
278
 
279
    tb->sb.clear_stats();
280
 
281
    tb->pif_gen0.set_pkt_size(1000, 1000);
282
 
283
    tb->cpu_if0.set_param(cpu_if::TX_ENABLE, 0);
284
    tb->sb.disable_signal_check = true;
285
 
286
    //---
287
    // Enable traffic
288
 
289
    tb->pif_gen0.set_tx_bucket(2);
290
 
291
    //---
292
    // Wait for packets to be sent
293
 
294
    while (tb->pif_gen0.get_tx_bucket() != 0) {
295
        wait(10, SC_NS);
296
    }
297
 
298
    wait(30000, SC_NS);
299
 
300
    //---
301
    // Check errors reported
302
 
303
    cpu_stats = tb->sb.get_cpu_stats();
304
    cout << "Count: " << cpu_stats->txd_fifo_ovflow_cnt << endl;
305
    sc_assert(cpu_stats->txd_fifo_ovflow_cnt == 1);
306
 
307
    //---
308
    // Flush out bad packets
309
 
310
    tb->xgm_if0.allow_idle_errors = true;
311
    tb->sb.disable_packet_check = true;
312
    tb->cpu_if0.set_param(cpu_if::TX_ENABLE, 1);
313
 
314
    wait(30000, SC_NS);
315
    tb->xgm_if0.allow_idle_errors = false;
316
    tb->sb.disable_packet_check = false;
317
 
318
    //---
319
    // Check errors reported
320
 
321
    cpu_stats = tb->sb.get_cpu_stats();
322 6 antanguay
 
323 2 antanguay
    //---
324
    // Enable traffic
325
 
326
    tb->pif_gen0.set_tx_bucket(2);
327
 
328
    //---
329
    // Wait for packets to be sent
330
 
331
    while (tb->pif_gen0.get_tx_bucket() != 0) {
332
        wait(10, SC_NS);
333
    }
334
 
335
    wait(30000, SC_NS);
336
 
337
    xgm_stats = tb->sb.get_xgm_stats();
338
    sc_assert(xgm_stats->rx_pkt_cnt == 4);
339
 
340
    //---
341
    // Return parameters to default state
342
 
343
    tb->cpu_if0.set_param(cpu_if::TX_ENABLE, 1);
344
    tb->sb.disable_signal_check = false;
345
}
346
 
347
void testcases::test_rxdfifo_ovflow() {
348
 
349
    sbStats_t* pif_stats;
350
    sbCpuStats_t* cpu_stats;
351
 
352
    cout << "-----------------------" << endl;
353
    cout << "RXD FIFO overflow" << endl;
354
    cout << "-----------------------" << endl;
355
 
356
    //---
357
    // Setup parameters
358
 
359
    tb->sb.clear_stats();
360
 
361
    tb->xgm_gen0.set_pkt_size(1000, 1000);
362
 
363
    tb->pkt_if0.disable_rx = true;
364
    tb->pkt_if0.allow_rx_sop_err = true;
365
    tb->sb.disable_flags_check = true;
366
    tb->sb.disable_packet_check = true;
367
    tb->sb.disable_signal_check = true;
368
 
369
    //---
370
    // Enable traffic
371
 
372
    tb->xgm_gen0.set_tx_bucket(3);
373
 
374
    //---
375
    // Wait for packets to be sent
376
 
377
    while (tb->xgm_gen0.get_tx_bucket() != 0) {
378
        wait(10, SC_NS);
379
    }
380
 
381
    wait(30000, SC_NS);
382
 
383
    //---
384
    // Check errors reported
385
 
386
    cpu_stats = tb->sb.get_cpu_stats();
387
    sc_assert(cpu_stats->rxd_fifo_ovflow_cnt == 2);
388
 
389
    //---
390
    // Flush out bad packets
391
 
392
    tb->pkt_if0.disable_rx = false;
393
 
394
    wait(30000, SC_NS);
395
 
396
    //---
397
    // Check errors reported
398
 
399
    cpu_stats = tb->sb.get_cpu_stats();
400
    tb->sb.clear_stats();
401
    tb->sb.disable_flags_check = false;
402
    tb->sb.disable_packet_check = false;
403
 
404
    //---
405
    // Enable traffic
406
 
407
    tb->xgm_gen0.set_tx_bucket(2);
408
 
409
    //---
410
    // Wait for packets to be sent
411
 
412
    while (tb->xgm_gen0.get_tx_bucket() != 0) {
413
        wait(10, SC_NS);
414
    }
415
 
416
    wait(30000, SC_NS);
417
 
418
    pif_stats = tb->sb.get_pif_stats();
419
    sc_assert(pif_stats->rx_pkt_cnt == 2);
420
 
421
    //---
422
    // Return parameters to default state
423
 
424
    tb->pkt_if0.allow_rx_sop_err = false;
425
    tb->sb.disable_signal_check = false;
426
}
427
 
428
void testcases::test_rx_fragments(int min, int max, int cnt, int interval) {
429
 
430
    sbStats_t* pif_stats;
431
    sbCpuStats_t* cpu_stats;
432
 
433
    cout << "-----------------------" << endl;
434
    cout << "Fragments errors" << endl;
435
    cout << "-----------------------" << endl;
436
 
437
    //---
438
    // Setup parameters
439
 
440
    tb->sb.clear_stats();
441
 
442
    tb->xgm_gen0.set_pkt_size(min, max);
443
    tb->xgm_gen0.set_fragment_errors(interval);
444
    tb->sb.disable_signal_check = true;
445
 
446
    //---
447
    // Enable traffic
448
 
449
    tb->xgm_gen0.set_tx_bucket(cnt);
450
 
451
    //---
452
    // Wait for test to complete
453
 
454
    while (tb->xgm_gen0.get_tx_bucket() != 0) {
455
        wait(10, SC_NS);
456
    }
457
 
458
    //---
459
    // Check traffic
460
 
461
    wait(30000, SC_NS);
462
 
463
    pif_stats = tb->sb.get_pif_stats();
464
    cpu_stats = tb->sb.get_cpu_stats();
465
 
466
    if (pif_stats->rx_pkt_cnt != cnt) {
467
        cout << "ERROR: Not all packets received by PIF." << endl;
468
        cout << pif_stats->rx_pkt_cnt << " " << cnt << endl;
469
        sc_stop();
470
    }
471
 
472
    if ((cpu_stats->fragment_error_cnt + cpu_stats->crc_error_cnt)
473
                != pif_stats->fragment_error_cnt) {
474
        cout << "ERROR: Not all fragment errors reported to cpu" << endl;
475
        sc_stop();
476
    }
477
 
478
    //---
479
    // Return parameters to default state
480
 
481
    tb->xgm_gen0.set_fragment_errors(0);
482
    tb->sb.disable_signal_check = false;
483
}
484
 
485
void testcases::test_rx_coding_err(int cnt, int interval) {
486
 
487
    sbStats_t* pif_stats;
488
    sbStats_t* xgm_stats;
489
    sbCpuStats_t* cpu_stats;
490
 
491
    cout << "-----------------------" << endl;
492
    cout << "Coding errors" << endl;
493
    cout << "-----------------------" << endl;
494
 
495
    //---
496
    // Setup parameters
497
 
498
    tb->sb.clear_stats();
499
 
500
    tb->xgm_gen0.set_pkt_size(64, 69);
501
    tb->xgm_gen0.set_coding_errors(interval);
502
    tb->sb.disable_signal_check = true;
503
 
504
    //---
505
    // Enable traffic
506
 
507
    tb->xgm_gen0.set_tx_bucket(cnt);
508
 
509
    //---
510
    // Wait for test to complete
511
 
512
    while (tb->xgm_gen0.get_tx_bucket() != 0) {
513
        wait(10, SC_NS);
514
    }
515
 
516
    //---
517
    // Check traffic
518
 
519
    wait(30000, SC_NS);
520
 
521
    pif_stats = tb->sb.get_pif_stats();
522
    xgm_stats = tb->sb.get_xgm_stats();
523
    cpu_stats = tb->sb.get_cpu_stats();
524
 
525
    if (pif_stats->rx_pkt_cnt != xgm_stats->tx_pkt_cnt) {
526
        cout << "ERROR: Not all packets received by PIF." << endl;
527
        cout << pif_stats->rx_pkt_cnt << " " << xgm_stats->tx_pkt_cnt << endl;
528
        sc_stop();
529
    }
530
 
531
    if (cpu_stats->crc_error_cnt != xgm_stats->crc_error_cnt) {
532
        cout << "ERROR: Not all coding errors reported to cpu" << endl;
533
        sc_stop();
534
    }
535
 
536
    //---
537
    // Return parameters to default state
538
 
539
    tb->xgm_gen0.set_coding_errors(0);
540
    tb->sb.disable_signal_check = false;
541
}
542
 
543
void testcases::test_rx_local_fault(int min, int max, int cnt, int interval) {
544
 
545
    sbStats_t* pif_stats;
546
 
547
    cout << "-----------------------" << endl;
548
    cout << "Local fault" << endl;
549
    cout << "-----------------------" << endl;
550
 
551
    //---
552
    // Setup parameters
553
 
554
    tb->sb.clear_stats();
555
 
556
    tb->pif_gen0.set_pkt_size(min, max);
557
    tb->xgm_gen0.set_pkt_size(min, max);
558
 
559
    tb->xgm_gen0.set_local_fault(interval);
560
    tb->sb.disable_signal_check = true;
561
    tb->xgm_if0.allow_idle_errors = true;
562
    tb->xgm_if0.disable_receive = true;
563
 
564
    //---
565
    // Enable traffic
566
 
567
    tb->pif_gen0.set_tx_bucket(cnt);
568
    tb->xgm_gen0.set_tx_bucket(cnt);
569
 
570
    //---
571
    // Wait for test to complete
572
 
573
    while (tb->xgm_gen0.get_tx_bucket() != 0) {
574
        wait(10, SC_NS);
575
    }
576
 
577
    //---
578
    // Check traffic
579
 
580
    wait(30000, SC_NS);
581
 
582
    pif_stats = tb->sb.get_pif_stats();
583
 
584
    if (pif_stats->rx_pkt_cnt != cnt) {
585
        cout << "ERROR: Not all packets received by PIF." << endl;
586
        cout << pif_stats->rx_pkt_cnt << " " << cnt << endl;
587
        sc_stop();
588
    }
589
 
590
    //---
591
    // Return parameters to default state
592
 
593
    tb->xgm_gen0.set_local_fault(0);
594
    tb->sb.disable_signal_check = false;
595
    tb->xgm_if0.allow_idle_errors = false;
596
    tb->xgm_if0.disable_receive = false;
597
}
598
 
599
void testcases::test_rx_remote_fault(int min, int max, int cnt, int interval) {
600
 
601
    sbStats_t* pif_stats;
602
 
603
    cout << "-----------------------" << endl;
604
    cout << "Remote fault" << endl;
605
    cout << "-----------------------" << endl;
606
 
607
    //---
608
    // Setup parameters
609
 
610
    tb->sb.clear_stats();
611
 
612
    tb->pif_gen0.set_pkt_size(min, max);
613
    tb->xgm_gen0.set_pkt_size(min, max);
614
 
615
    tb->xgm_gen0.set_remote_fault(interval);
616
    tb->sb.disable_signal_check = true;
617
    tb->xgm_if0.allow_idle_errors = true;
618
    tb->xgm_if0.disable_receive = true;
619
 
620
    //---
621
    // Enable traffic
622
 
623
    tb->pif_gen0.set_tx_bucket(cnt);
624
    tb->xgm_gen0.set_tx_bucket(cnt);
625
 
626
    //---
627
    // Wait for test to complete
628
 
629
    while (tb->xgm_gen0.get_tx_bucket() != 0) {
630
        wait(10, SC_NS);
631
    }
632
 
633
    //---
634
    // Check traffic
635
 
636
    wait(30000, SC_NS);
637
 
638
    pif_stats = tb->sb.get_pif_stats();
639
 
640
    if (pif_stats->rx_pkt_cnt != cnt) {
641
        cout << "ERROR: Not all packets received by PIF." << endl;
642
        cout << pif_stats->rx_pkt_cnt << " " << cnt << endl;
643
        sc_stop();
644
    }
645
 
646
    //---
647
    // Return parameters to default state
648
 
649
    tb->xgm_gen0.set_remote_fault(0);
650
    tb->sb.disable_signal_check = false;
651
    tb->xgm_if0.allow_idle_errors = false;
652
    tb->xgm_if0.disable_receive = false;
653
}
654
 
655
void testcases::test_rx_pause(int min, int max, int cnt, int interval) {
656
 
657
    sbCpuStats_t* cpu_stats;
658
 
659
    cout << "-----------------------" << endl;
660
    cout << "Receive Pause" << endl;
661
    cout << "-----------------------" << endl;
662
 
663
    //---
664
    // Setup parameters
665
 
666
    tb->sb.clear_stats();
667
 
668
    tb->xgm_gen0.set_pkt_size(min, max);
669
 
670
    tb->xgm_gen0.set_inject_pause(interval);
671
    tb->sb.disable_signal_check = true;
672
 
673
    //---
674
    // Enable traffic
675
 
676
    tb->xgm_gen0.set_tx_bucket(cnt);
677
 
678
    //---
679
    // Wait for test to complete
680
 
681
    while (tb->xgm_gen0.get_tx_bucket() != 0) {
682
        wait(10, SC_NS);
683
    }
684
 
685
    //---
686
    // Check traffic
687
 
688
    wait(30000, SC_NS);
689
 
690
    cpu_stats = tb->sb.get_cpu_stats();
691
 
692
    if (cpu_stats->rx_pause_frame_cnt == 0) {
693
        cout << "ERROR: No pause frames received." << endl;
694
        sc_stop();
695
    }
696
 
697
    //---
698
    // Return parameters to default state
699
 
700
    tb->xgm_gen0.set_inject_pause(0);
701
    tb->sb.disable_signal_check = false;
702
}
703
 
704
void testcases::test_interrupt_mask() {
705
 
706
    sbCpuStats_t* cpu_stats;
707
 
708
    cout << "-----------------------" << endl;
709
    cout << "Interrupt Mask" << endl;
710
    cout << "-----------------------" << endl;
711
 
712
    //---
713
    // Setup parameters
714
 
715
    tb->sb.clear_stats();
716
    tb->sb.disable_signal_check = true;
717
 
718
 
719
    //---
720
    // Test unmasked
721
 
722
    tb->cpu_if0.set_interrupt(cpu_if::INT_CRC_ERROR);
723
 
724
    wait(300, SC_NS);
725
 
726
    cpu_stats = tb->sb.get_cpu_stats();
727
    sc_assert(cpu_stats->crc_error_cnt == 1);
728
 
729
 
730
    //---
731
    // Test masked
732
 
733
    tb->cpu_if0.set_interrupt_mask(cpu_if::INT_CRC_ERROR, 0);
734
    tb->cpu_if0.set_interrupt(cpu_if::INT_CRC_ERROR);
735
 
736
    wait(300, SC_NS);
737
 
738
    cpu_stats = tb->sb.get_cpu_stats();
739
    sc_assert(cpu_stats->crc_error_cnt == 1);
740
 
741
 
742
    //---
743
    // Return parameters to default state
744
 
745
    tb->sb.disable_signal_check = false;
746
    tb->cpu_if0.set_interrupt_mask(cpu_if::INT_CRC_ERROR, 1);
747
}
748
 

powered by: WebSVN 2.1.0

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