-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathemul_dromajo_test.cpp
148 lines (127 loc) · 4.25 KB
/
emul_dromajo_test.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
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
// This file is distributed under the BSD 3-Clause License. See LICENSE for details.
#include "emul_dromajo.hpp"
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <inttypes.h>
#include <net/if.h>
#include <signal.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include <fstream>
// #define REGRESS_COSIM 1
#ifdef REGRESS_COSIM
#include "dromajo_cosim.h"
#endif
#include "gmock/gmock.h"
#include "gtest/gtest.h"
class Emul_Dromajo_test : public ::testing::Test {
protected:
std::shared_ptr<Emul_dromajo> dromajo_ptr;
void SetUp() override {
std::ofstream file;
file.open("emul_dromajo_test.toml");
file << "[soc]\n";
file << "core = \"c0\"\n";
file << "emul = [\"drom_emu\"]\n";
file << "\n[drom_emu]\n";
file << "num = \"1\"\n";
file << "type = \"dromajo\"\n";
file << "rabbit = 0\n";
file << "detail = 1e6\n";
file << "time = 2e6\n";
file << "bench=\"conf/dhrystone.riscv\"\n";
file.close();
Config::init("emul_dromajo_test.toml");
dromajo_ptr = std::make_shared<Emul_dromajo>();
}
void TearDown() override {
// Graph_library::sync_all();
}
};
TEST_F(Emul_Dromajo_test, dhrystone_test) {
EXPECT_NE(dromajo_ptr, nullptr);
dromajo_ptr->skip_rabbit(0, 606);
Dinst *dinst = dromajo_ptr->peek(0); // c.j
EXPECT_EQ(0x0000000080002c1a, dinst->getPC());
const Instruction *inst = dinst->getInst();
EXPECT_TRUE(inst->isJump());
EXPECT_FALSE(inst->hasSrc1Register());
EXPECT_FALSE(inst->hasDstRegister());
dinst->scrap();
dromajo_ptr->skip_rabbit(0, 55); // c.bnez
dinst = dromajo_ptr->peek(0);
EXPECT_EQ(0x00000000800025d8, dinst->getPC());
inst = dinst->getInst();
EXPECT_EQ(static_cast<RegType>(10), inst->getSrc1());
EXPECT_EQ(0x00000000800025e8, dinst->getAddr());
EXPECT_TRUE(inst->isBranch());
dinst->scrap();
dromajo_ptr->skip_rabbit(0, 3);
dinst = dromajo_ptr->peek(0); // csrr
EXPECT_EQ(0x0000000080002aaa, dinst->getPC());
inst = dinst->getInst();
EXPECT_EQ(static_cast<RegType>(15), inst->getDst1());
dinst->scrap();
dromajo_ptr->skip_rabbit(0, 197);
dinst = dromajo_ptr->peek(0); // bge
EXPECT_EQ(0x0000000080002094, dinst->getPC());
EXPECT_EQ(0x00000000800020a4, dinst->getAddr());
inst = dinst->getInst();
EXPECT_EQ(static_cast<RegType>(0), inst->getSrc1());
EXPECT_EQ(static_cast<RegType>(10), inst->getSrc2());
EXPECT_FALSE(inst->hasDstRegister());
EXPECT_TRUE(inst->isBranch());
dinst->scrap();
dromajo_ptr->skip_rabbit(0, 6); // ret
dinst = dromajo_ptr->peek(0);
EXPECT_EQ(0x00000000800020ae, dinst->getPC());
inst = dinst->getInst();
EXPECT_TRUE(inst->isFuncRet());
dinst->scrap();
dromajo_ptr->skip_rabbit(0, 2); // addi
dinst = dromajo_ptr->peek(0);
EXPECT_EQ(0x0000000080002b38, dinst->getPC());
inst = dinst->getInst();
EXPECT_EQ(static_cast<RegType>(8), inst->getSrc1());
EXPECT_EQ(static_cast<RegType>(12), inst->getDst1());
EXPECT_TRUE(inst->isALU());
dinst->scrap();
dromajo_ptr->skip_rabbit(0, 5); // sw
dinst = dromajo_ptr->peek(0);
EXPECT_EQ(0x0000000080002b46, dinst->getPC());
EXPECT_EQ(0x0000000080025658, dinst->getAddr());
inst = dinst->getInst();
EXPECT_EQ(static_cast<RegType>(8), inst->getSrc1());
EXPECT_EQ(static_cast<RegType>(15), inst->getSrc2());
EXPECT_FALSE(inst->hasDstRegister());
EXPECT_TRUE(inst->isStore());
dinst->scrap();
dromajo_ptr->skip_rabbit(0, 4); // c.sw
dinst = dromajo_ptr->peek(0);
EXPECT_EQ(0x0000000080002004, dinst->getPC());
EXPECT_EQ(0x0000000080025658, dinst->getAddr());
inst = dinst->getInst();
EXPECT_EQ(static_cast<RegType>(12), inst->getSrc1());
EXPECT_EQ(static_cast<RegType>(11), inst->getSrc2());
EXPECT_FALSE(inst->hasDstRegister());
EXPECT_TRUE(inst->isStore());
dinst->scrap();
dromajo_ptr->skip_rabbit(0, 41); // c.sdsp
dinst = dromajo_ptr->peek(0);
EXPECT_EQ(0x000000008000217e, dinst->getPC());
EXPECT_EQ(0x00000000800255b0, dinst->getAddr());
inst = dinst->getInst();
EXPECT_EQ(static_cast<RegType>(2), inst->getSrc1());
EXPECT_EQ(static_cast<RegType>(18), inst->getSrc2());
EXPECT_FALSE(inst->hasDstRegister());
EXPECT_TRUE(inst->isStore());
dinst->scrap();
}