-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata_mem_tb.cpp
104 lines (77 loc) · 1.96 KB
/
data_mem_tb.cpp
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
/*
* Verifies that the data memory reads and writes correctly
* Author: Kevin Lau <khl22@ic.ac.uk>
*/
#include "sync_testbench.h"
#define NAME "data_mem"
class DataMemTestbench : public SyncTestbench
{
protected:
void initializeInputs() override
{
top->A = 0;
top->WD = 0;
top->WE = 0;
}
};
TEST_F(DataMemTestbench, WriteAndReadTest)
{
top->A = 1;
top->WD = 0x12345678;
top->WE = 1;
runSimulation(10);
top->WE = 0;
runSimulation(10);
EXPECT_EQ(top->RD, 0x12345678);
std::cout << "top->RD (hex): "
<< std::setw(8) << std::setfill('0')
<< std::hex << top->RD
<< std::endl;
}
TEST_F(DataMemTestbench, ReloadDataTest)
{
top->A = 1;
top->WD = 0x12345678;
top->WE = 1;
runSimulation(10);
top->WE = 0;
runSimulation(10);
EXPECT_EQ(top->RD, 0x12345678);
std::cout << "top->RD (hex): "
<< std::setw(8) << std::setfill('0')
<< std::hex << top->RD
<< std::endl;
top->A = 1;
top->WD = 0x87654321;
top->WE = 1;
runSimulation(10);
top->WE = 0;
runSimulation(10);
EXPECT_EQ(top->RD, 0x87654321);
std::cout << "top->RD (hex): "
<< std::setw(8) << std::setfill('0')
<< std::hex << top->RD
<< std::endl;
}
TEST_F(DataMemTestbench, MemoryInitTest)
{
top->A = 2;
runSimulation(10);
EXPECT_EQ(top->RD, 0x00000000);
std::cout << "top->RD (hex): "
<< std::setw(8) << std::setfill('0')
<< std::hex << top->RD
<< std::endl;
}
int main(int argc, char **argv)
{
Verilated::commandArgs(argc, argv);
testing::InitGoogleTest(&argc, argv);
Verilated::mkdir("logs");
auto res = RUN_ALL_TESTS();
// Problem with segmentation faults. No solution yet
// VerilatedCov::write(
// ("logs/coverage_" + std::string(NAME) + ".dat").c_str()
// );
return res;
}