-
Notifications
You must be signed in to change notification settings - Fork 0
/
tb_intregreg.cpp
71 lines (59 loc) · 1.41 KB
/
tb_intregreg.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
#include "Vcpp_cpu_top.h"
#include "util.hpp"
#include <cstdio>
#include <fstream>
#include <iostream>
#include <limits>
#include <vector>
#include <verilated.h>
// max cycle is actually 1000
static constexpr std::size_t max_cycle = 10'000;
int main() {
Vcpp_cpu_top top;
top.clk = 0;
top.eval();
top.rstn = 0;
top.eval();
top.clk = 1;
top.eval();
top.clk = 0;
top.eval();
top.rstn = 1;
top.eval();
for (std::size_t cycle = 0; cycle < max_cycle; ++cycle) {
top.clk = 0;
top.eval();
top.clk = 1;
top.eval();
}
auto prepc = top.pc;
top.clk = 0;
top.eval();
top.clk = 1;
top.eval();
if (top.pc != prepc) {
eprintf("Error: simulation is not finished.\n");
return 1;
}
std::string xml = to_xml(top.pc, top.regfile);
std::string ref_xml;
auto path = std::string(BASEPATH) + "/tests/IntRegReg/cfg.xml";
ref_xml =
std::string(std::istreambuf_iterator<char>(std::ifstream(path).rdbuf()),
std::istreambuf_iterator<char>());
if (xml != ref_xml) {
auto diffstr =
"zsh -c \"diff <(echo '" + xml + "') <(echo '" + ref_xml + "')\"";
// std::printf("%s\n", diffstr.c_str());
// std command diff
auto err = std::system(diffstr.c_str());
if (err != 0) {
eprintf("Error: result is not matched with cfg.xml.\n");
eprintf("%s\n", diffstr.c_str());
return 1;
}
return 1;
} else {
return 0;
}
}