@@ -10,6 +10,8 @@ import circt.stage.ChiselStage
1010import org .scalatest .flatspec .AnyFlatSpec
1111import org .scalatest .matchers .should .Matchers
1212
13+ import circt .stage .ChiselStage .emitCHIRRTL
14+
1315class TestResultBundle extends Bundle {
1416 val finish = Output (Bool ())
1517 val code = Output (UInt (8 .W ))
@@ -67,7 +69,10 @@ class ProtocolMonitor(bundleType: ProtocolBundle) extends Module {
6769}
6870
6971@ instantiable
70- class ModuleWithTests (ioWidth : Int = 32 ) extends Module with HasMonitorSocket with HasTests [ModuleWithTests ] {
72+ class ModuleWithTests (ioWidth : Int = 32 , override val resetType : Module .ResetType .Type = Module .ResetType .Synchronous )
73+ extends Module
74+ with HasMonitorSocket
75+ with HasTests [ModuleWithTests ] {
7176 @ public val io = IO (new ProtocolBundle (ioWidth))
7277
7378 override val monProbe = makeProbe(io)
@@ -112,42 +117,50 @@ class ModuleWithTests(ioWidth: Int = 32) extends Module with HasMonitorSocket wi
112117 }
113118}
114119
115- class InlineTestSpec extends AnyFlatSpec with Matchers with FileCheck {
120+ @ instantiable
121+ class RawModuleWithTests (ioWidth : Int = 32 ) extends RawModule with HasTests [RawModuleWithTests ] {
122+ @ public val io = IO (new ProtocolBundle (ioWidth))
123+ io.out := io.in
124+ test(" foo" ) { instance =>
125+ instance.io.in := 3 .U (ioWidth.W )
126+ assert(instance.io.out === 3 .U ): Unit
127+ }
128+ }
129+
130+ class InlineTestSpec extends AnyFlatSpec with FileCheck {
116131 it should " generate a public module for each test" in {
117- ChiselStage
118- .emitCHIRRTL(new ModuleWithTests )
119- .fileCheck()(
120- """
132+ emitCHIRRTL(new ModuleWithTests ).fileCheck()(
133+ """
121134 | CHECK: module ModuleWithTests
122135 | CHECK: output monProbe : Probe<{ in : UInt<32>, out : UInt<32>}>
123136 |
124137 | CHECK: public module test_ModuleWithTests_foo
125138 | CHECK-NEXT: input clock : Clock
126- | CHECK-NEXT: input reset : UInt<1>
139+ | CHECK-NEXT: input reset
127140 | CHECK: inst dut of ModuleWithTests
128141 |
129142 | CHECK: public module test_ModuleWithTests_bar
130143 | CHECK-NEXT: input clock : Clock
131- | CHECK-NEXT: input reset : UInt<1>
144+ | CHECK-NEXT: input reset
132145 | CHECK: inst dut of ModuleWithTests
133146 |
134147 | CHECK: public module test_ModuleWithTests_with_result
135148 | CHECK-NEXT: input clock : Clock
136- | CHECK-NEXT: input reset : UInt<1>
149+ | CHECK-NEXT: input reset
137150 | CHECK-NEXT: output result : { finish : UInt<1>, code : UInt<8>}
138151 | CHECK: inst dut of ModuleWithTests
139152 |
140153 | CHECK: public module test_ModuleWithTests_with_monitor
141154 | CHECK-NEXT: input clock : Clock
142- | CHECK-NEXT: input reset : UInt<1>
155+ | CHECK-NEXT: input reset
143156 | CHECK: inst dut of ModuleWithTests
144157 | CHECK: inst monitor of ProtocolMonitor
145158 | CHECK-NEXT: connect monitor.clock, clock
146159 | CHECK-NEXT: connect monitor.reset, reset
147160 | CHECK-NEXT: connect monitor.io.out, read(dut.monProbe).out
148161 | CHECK-NEXT: connect monitor.io.in, read(dut.monProbe).in
149162 """
150- )
163+ )
151164 }
152165
153166 it should " compile to verilog" in {
@@ -163,4 +176,50 @@ class InlineTestSpec extends AnyFlatSpec with Matchers with FileCheck {
163176 """
164177 )
165178 }
179+
180+ it should " emit the correct reset types" in {
181+ def fileCheckString (resetType : String ) =
182+ s """
183+ | CHECK: module ModuleWithTests
184+ | CHECK-NEXT: input clock : Clock
185+ | CHECK-NEXT: input reset : ${resetType}
186+ |
187+ | CHECK: public module test_ModuleWithTests_foo
188+ | CHECK-NEXT: input clock : Clock
189+ | CHECK-NEXT: input reset : ${resetType}
190+ |
191+ | CHECK: public module test_ModuleWithTests_bar
192+ | CHECK-NEXT: input clock : Clock
193+ | CHECK-NEXT: input reset : ${resetType}
194+ |
195+ | CHECK: public module test_ModuleWithTests_with_result
196+ | CHECK-NEXT: input clock : Clock
197+ | CHECK-NEXT: input reset : ${resetType}
198+ |
199+ | CHECK: public module test_ModuleWithTests_with_monitor
200+ | CHECK-NEXT: input clock : Clock
201+ | CHECK-NEXT: input reset : ${resetType}
202+ """
203+
204+ emitCHIRRTL(new ModuleWithTests (resetType = Module .ResetType .Synchronous )).fileCheck()(
205+ fileCheckString(" UInt<1>" )
206+ )
207+ emitCHIRRTL(new ModuleWithTests (resetType = Module .ResetType .Asynchronous )).fileCheck()(
208+ fileCheckString(" AsyncReset" )
209+ )
210+ emitCHIRRTL(new ModuleWithTests (resetType = Module .ResetType .Default )).fileCheck()(
211+ fileCheckString(" UInt<1>" )
212+ )
213+
214+ emitCHIRRTL(new RawModuleWithTests ()).fileCheck()(
215+ """
216+ | CHECK: module RawModuleWithTests
217+ | CHECK-NEXT: output io
218+ |
219+ | CHECK: public module test_RawModuleWithTests_foo
220+ | CHECK-NEXT: input clock : Clock
221+ | CHECK-NEXT: input reset : UInt<1>
222+ """
223+ )
224+ }
166225}
0 commit comments