-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFSMTest.scala
More file actions
120 lines (91 loc) · 3.2 KB
/
FSMTest.scala
File metadata and controls
120 lines (91 loc) · 3.2 KB
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
package chiselexamples
package showenum
import chisel3._
import chiseltest._
import chiseltest.iotesters.PeekPokeTester
import org.scalatest.flatspec.AnyFlatSpec
class DetectTwoOnesTester(c: DetectTwoOnes) extends PeekPokeTester(c) {
// Inputs and expected results
val inputs = Seq(0, 0, 1, 0, 1, 1, 0, 1, 1, 1)
val expected = Seq(0, 0, 0, 0, 0, 1, 0, 0, 1, 1)
// Reset
poke(c.io.in, 0)
step(1)
for (i <- inputs.indices) {
poke(c.io.in, inputs(i))
step(1)
// c.clock.getStepCount
expect(c.io.out, expected(i))
// System.out.println(s"In: ${inputs(i)}, out: ${expected(i)}")
}
}
class DetectTwoOnesTesterWrapper(c: DetectTwoOnesWrapper) extends PeekPokeTester(c) {
// Inputs and expected results
val inputs = Seq(0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0)
val expected = Seq(0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0)
// Reset
poke(c.io.in, 0)
step(1)
for (i <- inputs.indices) {
poke(c.io.in, inputs(i))
step(1)
// c.clock.getStepCount
expect(c.io.out, expected(i))
// System.out.println(s"In: ${inputs(i)}, out: ${expected(i)}")
}
}
class DetectTwoOnesWrapper extends DetectTwoOnes {
val stateExposed = IO(Output(State()))
stateExposed := state
}
class FSMTest extends AnyFlatSpec with ChiselScalatestTester {
behavior of "FSM: DetectTwoOnes"
it should "Check States VCD" in {
test(new DetectTwoOnesWrapper())
.withAnnotations(Seq(WriteVcdAnnotation, VerilatorBackendAnnotation))
.runPeekPoke(new DetectTwoOnesTesterWrapper(_))
}
it should "Check States FST" in {
test(new DetectTwoOnesWrapper())
.withAnnotations(Seq(WriteFstAnnotation, VerilatorBackendAnnotation))
.runPeekPoke(new DetectTwoOnesTesterWrapper(_))
}
it should "Check States LXT" in {
test(new DetectTwoOnesWrapper())
.withAnnotations(Seq(WriteLxtAnnotation.apply(), IcarusBackendAnnotation))
.runPeekPoke(new DetectTwoOnesTesterWrapper(_))
}
} // end of class FSMTest
class FSMWaveformTest extends AnyFlatSpec with ChiselScalatestTester {
behavior of "FSMWaveformTest"
it should "dump Treadle VCD" in {
test(new DetectTwoOnes())
.withAnnotations(Seq(WriteVcdAnnotation, TreadleBackendAnnotation))
.runPeekPoke(new DetectTwoOnesTester(_))
}
it should "dump Verilator VCD" in {
test(new DetectTwoOnes())
.withAnnotations(Seq(WriteVcdAnnotation, VerilatorBackendAnnotation))
.runPeekPoke(new DetectTwoOnesTester(_))
}
it should "dump Icarus VCD" in {
test(new DetectTwoOnes())
.withAnnotations(Seq(WriteVcdAnnotation, IcarusBackendAnnotation))
.runPeekPoke(new DetectTwoOnesTester(_))
}
it should "dump Verilator FST" in {
test(new DetectTwoOnes())
.withAnnotations(Seq(WriteFstAnnotation, VerilatorBackendAnnotation))
.runPeekPoke(new DetectTwoOnesTester(_))
}
it should "dump Icarus FST" in {
test(new DetectTwoOnes())
.withAnnotations(Seq(WriteFstAnnotation, IcarusBackendAnnotation))
.runPeekPoke(new DetectTwoOnesTester(_))
}
it should "dump Icarus LXT" in {
test(new DetectTwoOnes())
.withAnnotations(Seq(new WriteLxtAnnotation, IcarusBackendAnnotation))
.runPeekPoke(new DetectTwoOnesTester(_))
}
} // end of class FSMWaveformTest