-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtests.cpp
129 lines (100 loc) · 2.13 KB
/
tests.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
#include "global.h"
#include <iostream>
#include <cassert>
#include "design.h"
#include "parser.h"
#include "logicsim.h"
using namespace std;
void test_design()
{
Design *aDesign;
aDesign = parseThatShit("test.v");
}
void test_gates()
{
Net *i1 = new Net("i1");
Net *i2 = new Net("i2");
Net *o = new Net("output");
Gate *g = new And("uut", 5);
i1->addLoad(g);
i2->addLoad(g);
o->addDriver(g);
i1->printDriversLoads();
i2->printDriversLoads();
o->printDriversLoads();
g->addInput(i1);
g->addInput(i2);
g->addOutput(o);
g->dump(cout);
}
void test_net()
{
Net n("test");
assert(n.name() == "test");
assert(n.getVal() == 'X');
n.setVal('0');
assert(n.getVal() == '0');
n.setVal('X');
}
void test_parser()
{
}
void test_delay()
{
/*
i1-\
| g1 )---o1--\
i2-/ - | g3 )---output
i3-\ /
| g2 )---o2--/
i4-/
*/
Net *i1 = new Net("i1");
Net *i2 = new Net("i2");
Net *i3 = new Net("i3");
Net *i4 = new Net("i4");
Net *o1 = new Net("o1");
Net *o2 = new Net("o2");
Net *output = new Net("output");
Gate *g1 = new And("and", 5);
Gate *g2 = new Or("or", 10);
Gate *g3 = new Xor("xor", 3);
i1->addLoad(g1);
i2->addLoad(g1);
i3->addLoad(g2);
i4->addLoad(g2);
o1->addLoad(g3);
o1->addDriver(g1);
o2->addLoad(g3);
o2->addDriver(g2);
output->addDriver(g3);
g1->addInput(i1);
g1->addInput(i2);
g1->addOutput(o1);
g2->addInput(i3);
g2->addInput(i4);
g2->addOutput(o2);
g3->addInput(o1);
g3->addInput(o2);
g3->addOutput(output);
cout << "o1 " << o1->computeDelay() << endl;
cout << "o2 " << o2->computeDelay() << endl;
cout << "output " << output->computeDelay() << endl;
}
void test_simulation()
{
Design *design = parseThatShit("test.v");
LogicSim sim("test.sim", design);
design->toposort();
sim.runSimulation(design->get_toposortedList());
sim.outputTheFile("test.out", design);
}
int main (int argc, char const *argv[])
{
//test_net();
// test_gates();
// test_delay();
test_simulation();
cout << GREEN << "Tests completed." << RESET << endl;
return 0;
}