-
Notifications
You must be signed in to change notification settings - Fork 0
/
counter.cpp
68 lines (56 loc) · 1.47 KB
/
counter.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
#include <cassert>
#include <iostream>
#include "Vcounter.h"
#include "verilated.h"
#include "common.hpp"
#define BITS 2
#define NVALS (1 << BITS)
class CounterTestCase : public TestCase<Vcounter> {
public:
CounterTestCase() : TestCase("counter.cpp.vcd") {}
virtual bool check() {
if (this->time < 2) {
return true;
} else {
return (this->dut->out == (((this->time - 1) / 2)) % NVALS);
}
}
virtual void step(bool& finish) {
if (this->time == 0) {
this->dut->enable = 1;
this->dut->reset = 1;
} else if (this->time == 2) {
this->dut->reset = 0;
}
this->dut->clock = this->clock;
finish = (time == 10);
}
};
int main(int argc, char **argv) {
Verilated::commandArgs(argc, argv);
/* Simple test. */
{
Vcounter *dut = new Vcounter;
dut->enable = 1;
dut->reset = 1;
dut->clock = 0;
dut->eval();
dut->clock = 1;
dut->eval();
assert(dut->out == 0);
dut->reset = 0;
dut->clock = 0;
dut->eval();
dut->clock = 1;
dut->eval();
assert(dut->out == 1);
dut->clock = 0;
dut->eval();
dut->clock = 1;
dut->eval();
assert(dut->out == 2);
dut->final();
delete dut;
}
assert(CounterTestCase().run());
}