-
Notifications
You must be signed in to change notification settings - Fork 40
/
module-port_test.cpp
150 lines (127 loc) · 3.6 KB
/
module-port_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
149
150
// -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
#include <iostream>
#include "gtest/gtest.h"
#include "uhdm/uhdm.h"
#include "uhdm/vpi_visitor.h"
#include "test_util.h"
using namespace UHDM;
// TODO: These tests are 'too big', i.e. they don't test a particular aspect
// of serialization.
class MyPayLoad : public ClientData {
public:
MyPayLoad(int32_t f) { foo_ = f; }
private:
int32_t foo_;
};
static std::vector<vpiHandle> buildModulePortDesign(Serializer* s) {
std::vector<vpiHandle> designs;
// Design building
design* d = s->MakeDesign();
d->VpiName("design1");
// Module
module_inst* m1 = s->MakeModule_inst();
m1->VpiTopModule(true);
m1->VpiDefName("M1");
m1->VpiFullName("top::M1");
m1->VpiParent(d);
m1->VpiFile("fake1.sv");
m1->VpiLineNo(10);
auto vars = s->MakeVariablesVec();
m1->Variables(vars);
logic_var* lvar = s->MakeLogic_var();
vars->push_back(lvar);
lvar->VpiFullName("top::M1::v1");
// Module
module_inst* m2 = s->MakeModule_inst();
m2->VpiDefName("M2");
m2->VpiName("u1");
m2->VpiParent(m1);
m2->VpiFile("fake2.sv");
m2->VpiLineNo(20);
// Ports
VectorOfport* vp = s->MakePortVec();
port* p = s->MakePort();
p->VpiName("i1");
p->VpiDirection(vpiInput);
vp->push_back(p);
p = s->MakePort();
p->VpiName("o1");
p->VpiDirection(vpiOutput);
vp->push_back(p);
m2->Ports(vp);
// Module
module_inst* m3 = s->MakeModule_inst();
m3->VpiDefName("M3");
m3->VpiName("u2");
m3->VpiParent(m1);
m3->VpiFile("fake3.sv");
m3->VpiLineNo(30);
// Instance
module_inst* m4 = s->MakeModule_inst();
m4->VpiDefName("M4");
m4->VpiName("u3");
m4->Ports(vp);
m4->VpiParent(m3);
m4->Instance(m3);
VectorOfmodule_inst* v1 = s->MakeModule_instVec();
v1->push_back(m1);
d->AllModules(v1);
VectorOfmodule_inst* v2 = s->MakeModule_instVec();
v2->push_back(m2);
v2->push_back(m3);
m1->Modules(v2);
// Package
package* p1 = s->MakePackage();
p1->VpiName("P1");
p1->VpiDefName("P0");
VectorOfpackage* v3 = s->MakePackageVec();
v3->push_back(p1);
d->AllPackages(v3);
// Function
function* f1 = s->MakeFunction();
f1->VpiName("MyFunc1");
f1->VpiSize(100);
function* f2 = s->MakeFunction();
f2->VpiName("MyFunc2");
f2->VpiSize(200);
VectorOftask_func* v4 = s->MakeTask_funcVec();
v4->push_back(f1);
v4->push_back(f2);
p1->Task_funcs(v4);
// Instance items, illustrates the use of groups
program* pr1 = s->MakeProgram();
pr1->VpiDefName("PR1");
pr1->VpiParent(m1);
VectorOfany* inst_items = s->MakeAnyVec();
inst_items->push_back(pr1);
function* f3 = s->MakeFunction();
f3->VpiName("MyFunc3");
f3->VpiSize(300);
f3->VpiParent(m1);
inst_items->push_back(f3);
m1->Instance_items(inst_items);
MyPayLoad* pl = new MyPayLoad(10);
m1->Data(pl);
vpiHandle dh = s->MakeUhdmHandle(uhdmdesign, d);
designs.push_back(dh);
{
char name[]{"P1"};
vpiHandle obj_h = vpi_handle_by_name(name, dh);
EXPECT_NE(obj_h, nullptr);
char name1[]{"MyFunc1"};
vpiHandle obj_h1 = vpi_handle_by_name(name1, obj_h);
EXPECT_NE(obj_h1, nullptr);
}
return designs;
}
TEST(Serialization, SerializeModulePortDesign_e2e) {
Serializer serializer;
const std::vector<vpiHandle>& designs = buildModulePortDesign(&serializer);
const std::string orig = designs_to_string(designs);
const std::string filename =
testing::TempDir() + "/serialize-module-port-roundrip.uhdm";
serializer.Save(filename);
const std::vector<vpiHandle>& restoredDesigns = serializer.Restore(filename);
const std::string restored = designs_to_string(restoredDesigns);
EXPECT_EQ(orig, restored);
}