-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathalu_main.cpp
110 lines (70 loc) · 1.48 KB
/
alu_main.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
#include <iostream>
#include <ctime>
#include <cstdlib>
#include "Valu.h"
#include "verilated.h"
using namespace std;
void test_and_out(int argc, char** argv) {
Verilated::commandArgs(argc, argv);
Valu* top = new Valu;
top->eval();
top->op_select = 1;
top->in0 = 1;
top->in1 = 0;
top->eval();
assert(top->out == 0);
top->in1 = 1;
top->eval();
assert(top->out == 1);
top->final();
}
void test_or_out(int argc, char** argv) {
Verilated::commandArgs(argc, argv);
Valu* top = new Valu;
top->eval();
top->eval();
top->in0 = 1;
top->in1 = 0;
top->eval();
assert(top->out == 1);
top->in0 = 0;
top->in1 = 0;
top->eval();
assert(top->out == 0);
top->final();
}
void test_xor_out(int argc, char** argv) {
Verilated::commandArgs(argc, argv);
Valu* top = new Valu;
top->in0 = 1;
top->in1 = 0;
top->op_select = 2;
top->eval();
assert(top->out == 1);
top->in0 = 1;
top->in1 = 1;
top->eval();
assert(top->out == 0);
top->final();
}
void test_neq_out(int argc, char** argv) {
Verilated::commandArgs(argc, argv);
Valu* top = new Valu;
top->in0 = 1;
top->in1 = 0;
top->op_select = 6;
top->eval();
assert(top->out == 1);
top->in0 = 101;
top->in1 = 101;
top->eval();
assert(top->out == 0);
top->final();
}
int main(int argc, char** argv) {
test_and_out(argc, argv);
test_or_out(argc, argv);
test_xor_out(argc, argv);
test_neq_out(argc, argv);
cout << "$$$$ ALU tests pass" << endl;
}