@@ -68,11 +68,26 @@ class ProtocolMonitor(bundleType: ProtocolBundle) extends Module {
6868 assert(io.in === io.out, " in === out" )
6969}
7070
71+ @ instantiable
72+ trait HasProtocolInterface extends HasTests { this : RawModule =>
73+ @ public val io : ProtocolBundle
74+
75+ test(" check1" )(ProtocolChecks .check(1 ))
76+ }
77+
78+ object ProtocolChecks {
79+ def check (v : Int )(instance : Instance [RawModule with HasProtocolInterface ]) = {
80+ instance.io.in := v.U
81+ assert(instance.io.out === v.U ): Unit
82+ }
83+ }
84+
7185@ instantiable
7286class ModuleWithTests (ioWidth : Int = 32 , override val resetType : Module .ResetType .Type = Module .ResetType .Synchronous )
7387 extends Module
7488 with HasMonitorSocket
75- with HasTests [ModuleWithTests ] {
89+ with HasTests
90+ with HasProtocolInterface {
7691 @ public val io = IO (new ProtocolBundle (ioWidth))
7792
7893 override val monProbe = makeProbe(io)
@@ -115,10 +130,12 @@ class ModuleWithTests(ioWidth: Int = 32, override val resetType: Module.ResetTyp
115130 assert(instance.io.out =/= 0 .U ): Unit
116131 }
117132 }
133+
134+ test(" check2" )(ProtocolChecks .check(2 ))
118135}
119136
120137@ instantiable
121- class RawModuleWithTests (ioWidth : Int = 32 ) extends RawModule with HasTests [ RawModuleWithTests ] {
138+ class RawModuleWithTests (ioWidth : Int = 32 ) extends RawModule with HasTests {
122139 @ public val io = IO (new ProtocolBundle (ioWidth))
123140 io.out := io.in
124141 test(" foo" ) { instance =>
@@ -134,6 +151,11 @@ class InlineTestSpec extends AnyFlatSpec with FileCheck {
134151 | CHECK: module ModuleWithTests
135152 | CHECK: output monProbe : Probe<{ in : UInt<32>, out : UInt<32>}>
136153 |
154+ | CHECK: public module test_ModuleWithTests_check1
155+ | CHECK-NEXT: input clock : Clock
156+ | CHECK-NEXT: input reset
157+ | CHECK: inst dut of ModuleWithTests
158+ |
137159 | CHECK: public module test_ModuleWithTests_foo
138160 | CHECK-NEXT: input clock : Clock
139161 | CHECK-NEXT: input reset
@@ -159,6 +181,11 @@ class InlineTestSpec extends AnyFlatSpec with FileCheck {
159181 | CHECK-NEXT: connect monitor.reset, reset
160182 | CHECK-NEXT: connect monitor.io.out, read(dut.monProbe).out
161183 | CHECK-NEXT: connect monitor.io.in, read(dut.monProbe).in
184+ |
185+ | CHECK: public module test_ModuleWithTests_check2
186+ | CHECK-NEXT: input clock : Clock
187+ | CHECK-NEXT: input reset
188+ | CHECK: inst dut of ModuleWithTests
162189 """
163190 )
164191 }
@@ -169,10 +196,12 @@ class InlineTestSpec extends AnyFlatSpec with FileCheck {
169196 .fileCheck()(
170197 """
171198 | CHECK: module ModuleWithTests
199+ | CHECK: module test_ModuleWithTests_check1
172200 | CHECK: module test_ModuleWithTests_foo
173201 | CHECK: module test_ModuleWithTests_bar
174202 | CHECK: module test_ModuleWithTests_with_result
175203 | CHECK: module test_ModuleWithTests_with_monitor
204+ | CHECK: module test_ModuleWithTests_check2
176205 """
177206 )
178207 }
@@ -184,6 +213,10 @@ class InlineTestSpec extends AnyFlatSpec with FileCheck {
184213 | CHECK-NEXT: input clock : Clock
185214 | CHECK-NEXT: input reset : ${resetType}
186215 |
216+ | CHECK: public module test_ModuleWithTests_check1
217+ | CHECK-NEXT: input clock : Clock
218+ | CHECK-NEXT: input reset : ${resetType}
219+ |
187220 | CHECK: public module test_ModuleWithTests_foo
188221 | CHECK-NEXT: input clock : Clock
189222 | CHECK-NEXT: input reset : ${resetType}
@@ -199,6 +232,10 @@ class InlineTestSpec extends AnyFlatSpec with FileCheck {
199232 | CHECK: public module test_ModuleWithTests_with_monitor
200233 | CHECK-NEXT: input clock : Clock
201234 | CHECK-NEXT: input reset : ${resetType}
235+ |
236+ | CHECK: public module test_ModuleWithTests_check2
237+ | CHECK-NEXT: input clock : Clock
238+ | CHECK-NEXT: input reset : ${resetType}
202239 """
203240
204241 emitCHIRRTL(new ModuleWithTests (resetType = Module .ResetType .Synchronous )).fileCheck()(
0 commit comments