blob: dbd353a0c801a421dcf3c6d6850f45df130f5d28 (
plain)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
// SPDX-License-Identifier: Apache-2.0
package chiselTests
import chisel3._
import chisel3.stage.{ChiselGeneratorAnnotation, ChiselStage}
import chisel3.util.Counter
import firrtl.passes.CheckInitialization.RefNotInitializedException
import firrtl.util.BackendCompilationUtilities
import org.scalatest._
import org.scalatest.matchers.should.Matchers
class InvalidateAPISpec extends ChiselPropSpec with Matchers with BackendCompilationUtilities with Utils {
def myGenerateFirrtl(t: => Module): String = ChiselStage.emitChirrtl(t)
def compileFirrtl(t: => Module): Unit = {
val testDir = createTestDirectory(this.getClass.getSimpleName)
(new ChiselStage).execute(
Array[String]("-td", testDir.getAbsolutePath, "--compiler", "verilog"),
Seq(ChiselGeneratorAnnotation(() => t))
)
}
class TrivialInterface extends Bundle {
val in = Input(Bool())
val out = Output(Bool())
}
property("an output connected to DontCare should emit a Firrtl \"is invalid\" with Strict CompileOptions") {
import chisel3.ExplicitCompileOptions.Strict
class ModuleWithDontCare extends Module {
val io = IO(new TrivialInterface)
io.out := DontCare
io.out := io.in
}
val firrtlOutput = myGenerateFirrtl(new ModuleWithDontCare)
firrtlOutput should include("io.out is invalid")
}
property("an output without a DontCare should NOT emit a Firrtl \"is invalid\" with Strict CompileOptions") {
import chisel3.ExplicitCompileOptions.Strict
class ModuleWithoutDontCare extends Module {
val io = IO(new TrivialInterface)
io.out := io.in
}
val firrtlOutput = myGenerateFirrtl(new ModuleWithoutDontCare)
(firrtlOutput should not).include("is invalid")
}
property("an output without a DontCare should emit a Firrtl \"is invalid\" with NotStrict CompileOptions") {
import chisel3.ExplicitCompileOptions.NotStrict
class ModuleWithoutDontCare extends Module {
val io = IO(new TrivialInterface)
io.out := io.in
}
val firrtlOutput = myGenerateFirrtl(new ModuleWithoutDontCare)
firrtlOutput should include("io is invalid")
}
property("a bundle with a DontCare should emit a Firrtl \"is invalid\" with Strict CompileOptions") {
import chisel3.ExplicitCompileOptions.Strict
class ModuleWithoutDontCare extends Module {
val io = IO(new TrivialInterface)
io <> DontCare
}
val firrtlOutput = myGenerateFirrtl(new ModuleWithoutDontCare)
firrtlOutput should include("io.out is invalid")
firrtlOutput should include("io.in is invalid")
}
property("a Vec with a DontCare should emit a Firrtl \"is invalid\" with Strict CompileOptions and bulk connect") {
import chisel3.ExplicitCompileOptions.Strict
val nElements = 5
class ModuleWithoutDontCare extends Module {
val io = IO(new Bundle {
val outs = Output(Vec(nElements, Bool()))
})
io.outs <> DontCare
}
val firrtlOutput = myGenerateFirrtl(new ModuleWithoutDontCare)
for (i <- 0 until nElements)
firrtlOutput should include(s"io.outs[$i] is invalid")
}
property("a Vec with a DontCare should emit a Firrtl \"is invalid\" with Strict CompileOptions and mono connect") {
import chisel3.ExplicitCompileOptions.Strict
val nElements = 5
class ModuleWithoutDontCare extends Module {
val io = IO(new Bundle {
val ins = Input(Vec(nElements, Bool()))
})
io.ins := DontCare
}
val firrtlOutput = myGenerateFirrtl(new ModuleWithoutDontCare)
for (i <- 0 until nElements)
firrtlOutput should include(s"io.ins[$i] is invalid")
}
property("a DontCare cannot be a connection sink (LHS) for := ") {
import chisel3.ExplicitCompileOptions.Strict
class ModuleWithDontCareSink extends Module {
val io = IO(new TrivialInterface)
DontCare := io.in
}
val exception = intercept[ChiselException] {
extractCause[ChiselException] {
ChiselStage.elaborate(new ModuleWithDontCareSink)
}
}
exception.getMessage should include("DontCare cannot be a connection sink")
}
property("a DontCare cannot be a connection sink (LHS) for <>") {
import chisel3.ExplicitCompileOptions.Strict
class ModuleWithDontCareSink extends Module {
val io = IO(new TrivialInterface)
DontCare <> io.in
}
val exception = intercept[BiConnectException] {
extractCause[BiConnectException] {
ChiselStage.elaborate(new ModuleWithDontCareSink)
}
}
exception.getMessage should include("DontCare cannot be a connection sink (LHS)")
}
property("FIRRTL should complain about partial initialization with Strict CompileOptions and conditional connect") {
import chisel3.ExplicitCompileOptions.Strict
class ModuleWithIncompleteAssignment extends Module {
val io = IO(new Bundle {
val out = Output(Bool())
})
val counter = Counter(8)
when(counter.inc()) {
io.out := true.B
}
}
val exception = intercept[RefNotInitializedException] {
compileFirrtl(new ModuleWithIncompleteAssignment)
}
exception.getMessage should include("is not fully initialized")
}
property(
"FIRRTL should not complain about partial initialization with Strict CompileOptions and conditional connect after unconditional connect"
) {
import chisel3.ExplicitCompileOptions.Strict
class ModuleWithUnconditionalAssignment extends Module {
val io = IO(new Bundle {
val out = Output(Bool())
})
val counter = Counter(8)
io.out := false.B
when(counter.inc()) {
io.out := true.B
}
}
compileFirrtl(new ModuleWithUnconditionalAssignment)
}
property(
"FIRRTL should not complain about partial initialization with Strict CompileOptions and conditional connect with otherwise clause"
) {
import chisel3.ExplicitCompileOptions.Strict
class ModuleWithConditionalAndOtherwiseAssignment extends Module {
val io = IO(new Bundle {
val out = Output(Bool())
})
val counter = Counter(8)
when(counter.inc()) {
io.out := true.B
}.otherwise {
io.out := false.B
}
}
compileFirrtl(new ModuleWithConditionalAndOtherwiseAssignment)
}
property(
"an output without a DontCare should NOT emit a Firrtl \"is invalid\" with overriden NotStrict CompileOptions"
) {
import chisel3.ExplicitCompileOptions.NotStrict
class ModuleWithoutDontCare extends Module {
override val compileOptions = chisel3.ExplicitCompileOptions.NotStrict.copy(explicitInvalidate = true)
val io = IO(new TrivialInterface)
io.out := io.in
}
val firrtlOutput = myGenerateFirrtl(new ModuleWithoutDontCare)
(firrtlOutput should not).include("is invalid")
}
property(
"an output without a DontCare should NOT emit a Firrtl \"is invalid\" with overriden NotStrict CompileOptions module definition"
) {
import chisel3.ExplicitCompileOptions.NotStrict
abstract class ExplicitInvalidateModule
extends Module()(chisel3.ExplicitCompileOptions.NotStrict.copy(explicitInvalidate = true))
class ModuleWithoutDontCare extends ExplicitInvalidateModule {
val io = IO(new TrivialInterface)
io.out := io.in
}
val firrtlOutput = myGenerateFirrtl(new ModuleWithoutDontCare)
(firrtlOutput should not).include("is invalid")
}
property("an output without a DontCare should emit a Firrtl \"is invalid\" with overriden Strict CompileOptions") {
import chisel3.ExplicitCompileOptions.Strict
class ModuleWithoutDontCare extends Module {
override val compileOptions = chisel3.ExplicitCompileOptions.Strict.copy(explicitInvalidate = false)
val io = IO(new TrivialInterface)
io.out := io.in
}
val firrtlOutput = myGenerateFirrtl(new ModuleWithoutDontCare)
firrtlOutput should include("is invalid")
}
property(
"an output without a DontCare should emit a Firrtl \"is invalid\" with overriden Strict CompileOptions module definition"
) {
import chisel3.ExplicitCompileOptions.Strict
abstract class ImplicitInvalidateModule
extends Module()(chisel3.ExplicitCompileOptions.NotStrict.copy(explicitInvalidate = false))
class ModuleWithoutDontCare extends ImplicitInvalidateModule {
val io = IO(new TrivialInterface)
io.out := io.in
}
val firrtlOutput = myGenerateFirrtl(new ModuleWithoutDontCare)
firrtlOutput should include("is invalid")
}
property("a clock should be able to be connected to a DontCare") {
class ClockConnectedToDontCare extends Module {
val foo = IO(Output(Clock()))
foo := DontCare
}
myGenerateFirrtl(new ClockConnectedToDontCare) should include("foo is invalid")
}
}
|