-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.hpp
54 lines (50 loc) · 1.35 KB
/
common.hpp
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
#ifndef COMMON_H
#define COMMON_H
#include <cstdint>
#include <string>
#include "verilated_vcd_c.h"
template<class Vdut>
class TestCase {
protected:
Vdut *dut;
std::string vcdPath;
uint64_t clock;
uint64_t time;
public:
TestCase(std::string vcdPath) {
this->dut = new Vdut;
this->vcdPath = vcdPath;
this->clock = 0;
this->time = 0;
}
~TestCase() {
this->dut->final();
delete this->dut;
}
virtual bool check() { return true; }
virtual void step(bool& finish) = 0;
bool run() {
bool finish, pass;
Verilated::traceEverOn(true);
VerilatedVcdC *vcd = new VerilatedVcdC;
this->dut->trace(vcd, 99);
vcd->open(vcdPath.c_str());
pass = true;
do {
this->step(finish);
this->dut->eval();
vcd->dump(this->time);
pass = this->check();
this->time++;
this->clock = !this->clock;
if (!pass || Verilated::gotFinish()) {
finish = true;
}
} while(!finish);
vcd->dump(this->time);
vcd->close();
delete vcd;
return pass;
}
};
#endif