-
Notifications
You must be signed in to change notification settings - Fork 3
/
TestAppendDataStreamTail.bsv
132 lines (109 loc) · 4.53 KB
/
TestAppendDataStreamTail.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
128
129
130
131
import FIFOF :: *;
import Randomizable :: *;
import Ports :: *;
import EthUtils :: *;
import SemiFifo :: *;
import StreamHandler :: *;
import TestUtils :: *;
typedef 16 CYCLE_COUNT_WIDTH;
typedef 16 CASE_COUNT_WIDTH;
typedef 20000 MAX_CYCLE_NUM;
typedef 5 MAX_FRAGMENT_NUM;
typedef TMul#(MAX_FRAGMENT_NUM, DATA_BUS_WIDTH) MAX_RAW_DATA_WIDTH;
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 4 TEST_FRAGMENT_NUM;
typedef TMul#(TEST_FRAGMENT_NUM, DATA_BUS_BYTE_WIDTH) TEST_CASE_NUM;
(* synthesize *)
module mkTestAppendDataStreamTail();
Integer testCaseNum = valueOf(TEST_CASE_NUM);
Integer maxCycleNum = valueOf(MAX_CYCLE_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;
Randomize#(Bit#(CRC32_WIDTH)) randAppendData <- mkGenericRandomizer;
// DUT And Ref Model
FIFOF#(Bit#(MAX_RAW_DATA_WIDTH)) dutRawDataBuf <- mkFIFOF;
FIFOF#(Bit#(MAX_RAW_BYTE_NUM_WIDTH)) dutRawByteNumBuf <- mkFIFOF;
FIFOF#(Bit#(CRC32_WIDTH)) dutAppendDataBuf <- mkFIFOF;
FIFOF#(Bit#(MAX_RAW_BYTE_NUM_WIDTH)) dutStreamLengthBuf <- 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 <- mkAppendDataStreamTail(
HOLD,
HOLD,
dutDataStreamIn,
convertFifoToFifoOut(dutAppendDataBuf),
convertFifoToFifoOut(dutStreamLengthBuf)
);
// Initialize Testbench
rule initTest if (!isInit);
randRawData.cntrl.init;
randAppendData.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 @ mkTestAppendDataStreamTail",
$format("Cycle number overflow %d", maxCycleNum)
);
endrule
rule driveDutInput if (isInit && (inputCaseCount < fromInteger(testCaseNum)));
let rawData <- randRawData.next;
let appendData <- randAppendData.next;
Bit#(MAX_RAW_BYTE_NUM_WIDTH) dutRawByteNum = truncate(inputCaseCount + 1);
Bit#(MAX_RAW_BYTE_NUM) mask = (1 << dutRawByteNum) - 1;
let dutRawData = bitMask(rawData, mask);
Bit#(MAX_RAW_DATA_WIDTH) extAppendData = zeroExtend(appendData);
let refRawData = dutRawData | byteLeftShift(extAppendData, dutRawByteNum);
let refRawByteNum = dutRawByteNum + 4;
dutRawDataBuf.enq(dutRawData);
dutRawByteNumBuf.enq(dutRawByteNum);
dutAppendDataBuf.enq(appendData);
dutStreamLengthBuf.enq(dutRawByteNum);
refRawDataBuf.enq(refRawData);
refRawByteNumBuf.enq(refRawByteNum);
inputCaseCount <= inputCaseCount + 1;
$display("Generate %6d test case:\n dataStream=%x\n appendData=%x\n", inputCaseCount, dutRawData, appendData);
endrule
rule checkDutOutput if (isInit && (outputCaseCount < fromInteger(testCaseNum)));
let dutDataStream = dutDataStreamOut.first;
dutDataStreamOut.deq;
let refDataStream = refDataStreamOut.first;
refDataStreamOut.deq;
$display("Receive %5d case:", outputCaseCount);
$display("REF: ", fshow(refDataStream));
$display("DUT: ", fshow(dutDataStream));
immAssert(
dutDataStream == refDataStream,
"Compare DUT And REF output @ mkTestAppendDataStreamTail",
$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