-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBuffer_tb.cc
More file actions
86 lines (60 loc) · 1.66 KB
/
Copy pathBuffer_tb.cc
File metadata and controls
86 lines (60 loc) · 1.66 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
#include <systemc.h>
#include <verilated.h>
#include <verilated_vcd_sc.h>
#include "VBuffer.h"
#include <iostream>
int sc_main(int argc, char** argv) {
Verilated::commandArgs(argc, argv);
Verilated::traceEverOn(true);
// get vcd file path from command line arguments
std::string vcd_file_path;
if(argc == 2) {
vcd_file_path = std::string(argv[1]);
}
// signals
sc_clock clk_i{"clk", 1, SC_NS, 0.5, 0, SC_NS, true};
sc_signal<bool> reset_n_i;
// input
sc_signal<uint32_t> data_i;
// output
sc_signal<uint32_t> data_o;
const std::unique_ptr<VBuffer> buffer{new VBuffer{"buffer"}};
buffer->clk_i(clk_i);
buffer->reset_n_i(reset_n_i);
buffer->data_i(data_i);
buffer->data_o(data_o);
// start simulation and trace
std::cout << "VBuffer start!" << std::endl;
sc_start(0, SC_NS);
VerilatedVcdSc* trace = new VerilatedVcdSc();
buffer->trace(trace, 99);
if(vcd_file_path.empty()) {
trace->open("VBuffer_tb.vcd");
} else {
trace->open(vcd_file_path.c_str());
}
// reset
sc_start(1, SC_NS);
reset_n_i.write(0);
sc_start(1, SC_NS);
reset_n_i.write(1);
sc_start(1, SC_NS);
assert(data_o.read() == 0);
sc_start(1, SC_NS);
data_i.write(42);
sc_start(1, SC_NS);
data_i.write(0);
sc_start(1, SC_NS);
// check if output is 42
assert(data_o.read() == 42);
sc_start(1, SC_NS);
// check if output is 0
assert(data_o.read() == 0);
sc_start(10, SC_NS);
buffer->final();
trace->flush();
trace->close();
delete trace;
std::cout << "VBuffer done!" << std::endl;
return 0;
}