-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTestRemoveICrcFromDataStream.bsv
127 lines (104 loc) · 4.38 KB
/
TestRemoveICrcFromDataStream.bsv
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
import FIFOF :: *;
import Randomizable :: *;
import Ports :: *;
import EthUtils :: *;
import SemiFifo :: *;
import TestUtils :: *;
import EthernetTypes :: *;
import UdpIpLayerForRdma :: *;
typedef 16 CYCLE_COUNT_WIDTH;
typedef 16 CASE_COUNT_WIDTH;
typedef 2000 MAX_CYCLE_NUM;
typedef 3 MAX_FRAGMENT_NUM;
typedef TMul#(MAX_FRAGMENT_NUM, DATA_BUS_WIDTH) MAX_RAW_DATA_WIDTH;
typedef TAdd#(CRC32_BYTE_WIDTH, 1) MIN_RAW_BYTE_NUM;
typedef TMul#(MAX_FRAGMENT_NUM, DATA_BUS_BYTE_WIDTH) MAX_RAW_BYTE_NUM;
typedef TLog#(TAdd#(MAX_RAW_BYTE_NUM, 1)) MAX_RAW_BYTE_NUM_WIDTH;
typedef 2 TEST_FRAGMENT_NUM;
typedef TMul#(TEST_FRAGMENT_NUM, DATA_BUS_BYTE_WIDTH) TEST_CASE_NUM;
(* synthesize *)
module mkTestRemoveICrcFromDataStream();
Integer testCaseNum = valueOf(TEST_CASE_NUM);
Integer maxCycleNum = valueOf(MAX_CYCLE_NUM);
Integer minRawByteNum = valueOf(MIN_RAW_BYTE_NUM);
// Common Signals
Reg#(Bool) isInit <- mkReg(False);
Reg#(Bit#(CASE_COUNT_WIDTH)) inputCaseCount <- mkReg(0);
Reg#(Bit#(CASE_COUNT_WIDTH)) outputCaseCount <- mkReg(0);
Reg#(Bit#(CYCLE_COUNT_WIDTH)) cycleCount <- mkReg(0);
// Random Signals
Randomize#(Bit#(MAX_RAW_DATA_WIDTH)) randRawData <- mkGenericRandomizer;
// DUT And Ref Model
FIFOF#(Bit#(MAX_RAW_DATA_WIDTH)) dutRawDataBuf <- mkFIFOF;
FIFOF#(Bit#(MAX_RAW_BYTE_NUM_WIDTH)) dutRawByteNumBuf <- mkFIFOF;
FIFOF#(UdpLength) dutStreamLenBuf <- mkFIFOF;
FIFOF#(Bit#(MAX_RAW_DATA_WIDTH)) refRawDataBuf <- mkFIFOF;
FIFOF#(Bit#(MAX_RAW_BYTE_NUM_WIDTH)) refRawByteNumBuf <- mkFIFOF;
let refDataStreamOut <- mkDataStreamSender(
"RefDataStreamSender",
convertFifoToFifoOut(refRawByteNumBuf),
convertFifoToFifoOut(refRawDataBuf)
);
let dutDataStreamIn <- mkDataStreamSender(
"DutDataStreamSender",
convertFifoToFifoOut(dutRawByteNumBuf),
convertFifoToFifoOut(dutRawDataBuf)
);
let dutDataStreamOut <- mkRemoveICrcFromDataStream(
convertFifoToFifoOut(dutStreamLenBuf),
dutDataStreamIn
);
// Initialize Testbench
rule initTest if (!isInit);
randRawData.cntrl.init;
isInit <= True;
endrule
// Count Cycle Number
rule doCycleCount if (isInit);
cycleCount <= cycleCount + 1;
$display("\nCycle %d ----------------------------------------", cycleCount);
immAssert(
cycleCount < fromInteger(maxCycleNum),
"Testbench timeout assertion @ mkTestRemoveICrcFromUdpIpStream",
$format("Cycle number overflow %d", maxCycleNum)
);
endrule
rule driveDutInput if (isInit && (inputCaseCount < fromInteger(testCaseNum)));
let rawData <- randRawData.next;
Bit#(MAX_RAW_BYTE_NUM_WIDTH) dutRawByteNum = truncate(inputCaseCount + fromInteger(minRawByteNum));
Bit#(MAX_RAW_BYTE_NUM) dutRawDataMask = (1 << dutRawByteNum) - 1;
let dutRawData = bitMask(rawData, dutRawDataMask);
let refRawByteNum = dutRawByteNum - fromInteger(valueOf(CRC32_BYTE_WIDTH));
Bit#(MAX_RAW_BYTE_NUM) refRawDataMask = (1 << refRawByteNum) - 1;
let refRawData = bitMask(rawData, refRawDataMask);
dutRawDataBuf.enq(dutRawData);
dutRawByteNumBuf.enq(dutRawByteNum);
dutStreamLenBuf.enq(zeroExtend(dutRawByteNum));
refRawDataBuf.enq(refRawData);
refRawByteNumBuf.enq(refRawByteNum);
inputCaseCount <= inputCaseCount + 1;
$display("Generate %6d test case:\n dataStream=%x\n", inputCaseCount, dutRawData);
endrule
rule checkDutOutput if (isInit && (outputCaseCount < fromInteger(testCaseNum)));
let refDataStream = refDataStreamOut.first;
refDataStreamOut.deq;
let dutDataStream = dutDataStreamOut.first;
dutDataStreamOut.deq;
$display("Receive %5d case:", outputCaseCount);
$display("REF: ", fshow(refDataStream));
$display("DUT: ", fshow(dutDataStream));
immAssert(
dutDataStream == refDataStream,
"Compare DUT And REF output @ mkTestRemoveICrcFromUdpIpStream",
$format("Case %5d incorrect", outputCaseCount)
);
if (dutDataStream.isLast) begin
outputCaseCount <= outputCaseCount + 1;
end
endrule
// Finish Testbench
rule finishTest if (outputCaseCount == fromInteger(testCaseNum));
$display("Pass all %d tests", testCaseNum);
$finish;
endrule
endmodule