This repository was archived by the owner on Aug 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregfile.t.v
More file actions
151 lines (128 loc) · 4.43 KB
/
regfile.t.v
File metadata and controls
151 lines (128 loc) · 4.43 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
//------------------------------------------------------------------------------
// Test harness validates hw4testbench by connecting it to various functional
// or broken register files, and verifying that it correctly identifies each
//------------------------------------------------------------------------------
`include "regfile.v"
module hw4testbenchharness();
wire[31:0] ReadData1; // Data from first register read
wire[31:0] ReadData2; // Data from second register read
wire[31:0] WriteData; // Data to write to register
wire[4:0] ReadRegister1; // Address of first register to read
wire[4:0] ReadRegister2; // Address of second register to read
wire[4:0] WriteRegister; // Address of register to write
wire RegWrite; // Enable writing of register when High
wire Clk; // Clock (Positive Edge Triggered)
reg begintest; // Set High to begin testing register file
wire endtest; // Set High to signal test completion
wire dutpassed; // Indicates whether register file passed tests
// Instantiate the register file being tested. DUT = Device Under Test
regfile DUT
(
.ReadData1(ReadData1),
.ReadData2(ReadData2),
.WriteData(WriteData),
.ReadRegister1(ReadRegister1),
.ReadRegister2(ReadRegister2),
.WriteRegister(WriteRegister),
.RegWrite(RegWrite),
.Clk(Clk)
);
// Instantiate test bench to test the DUT
hw4testbench tester
(
.begintest(begintest),
.endtest(endtest),
.dutpassed(dutpassed),
.ReadData1(ReadData1),
.ReadData2(ReadData2),
.WriteData(WriteData),
.ReadRegister1(ReadRegister1),
.ReadRegister2(ReadRegister2),
.WriteRegister(WriteRegister),
.RegWrite(RegWrite),
.Clk(Clk)
);
// Test harness asserts 'begintest' for 1000 time steps, starting at time 10
initial begin
begintest=0;
#10;
begintest=1;
#1000;
end
// Display test results ('dutpassed' signal) once 'endtest' goes high
always @(posedge endtest) begin
$display("DUT passed?: %b", dutpassed);
end
endmodule
//------------------------------------------------------------------------------
// Your HW4 test bench
// Generates signals to drive register file and passes them back up one
// layer to the test harness. This lets us plug in various working and
// broken register files to test.
//
// Once 'begintest' is asserted, begin testing the register file.
// Once your test is conclusive, set 'dutpassed' appropriately and then
// raise 'endtest'.
//------------------------------------------------------------------------------
module hw4testbench
(
// Test bench driver signal connections
input begintest, // Triggers start of testing
output reg endtest, // Raise once test completes
output reg dutpassed, // Signal test result
// Register File DUT connections
input[31:0] ReadData1,
input[31:0] ReadData2,
output reg[31:0] WriteData,
output reg[4:0] ReadRegister1,
output reg[4:0] ReadRegister2,
output reg[4:0] WriteRegister,
output reg RegWrite,
output reg Clk
);
// Initialize register driver signals
initial begin
WriteData=32'd0;
ReadRegister1=5'd0;
ReadRegister2=5'd0;
WriteRegister=5'd0;
RegWrite=0;
Clk=0;
end
// Once 'begintest' is asserted, start running test cases
always @(posedge begintest) begin
endtest = 0;
dutpassed = 1;
#10
// Test Case 1:
// Write '42' to register 2, verify with Read Ports 1 and 2
// (Passes because example register file is hardwired to return 42)
WriteRegister = 5'd2;
WriteData = 32'd42;
RegWrite = 1;
ReadRegister1 = 5'd2;
ReadRegister2 = 5'd2;
#5 Clk=1; #5 Clk=0; // Generate single clock pulse
// Verify expectations and report test result
if((ReadData1 !== 42) || (ReadData2 !== 42)) begin
dutpassed = 0; // Set to 'false' on failure
$display("Test Case 1 Failed");
end
// Test Case 2:
// Write '15' to register 2, verify with Read Ports 1 and 2
// (Fails with example register file, but should pass with yours)
WriteRegister = 5'd2;
WriteData = 32'd15;
RegWrite = 1;
ReadRegister1 = 5'd2;
ReadRegister2 = 5'd2;
#5 Clk=1; #5 Clk=0;
if((ReadData1 !== 15) || (ReadData2 !== 15)) begin
dutpassed = 0;
$display("Test Case 2 Failed");
end
// All done! Wait a moment and signal test completion.
#5
endtest = 1;
end
endmodule