This repository has been archived by the owner on Aug 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace getDataNames with DataMirror.fullModulePorts (#662)
* Replace getDataNames with DataMirror.fullModulePorts Remove getDataNames. Add test with Record extending OpaqueType. * Add license header
- Loading branch information
Showing
2 changed files
with
42 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package chiseltest.tests | ||
|
||
import chisel3.experimental.BundleLiterals.AddBundleLiteralConstructor | ||
import chisel3.experimental.OpaqueType | ||
import chisel3._ | ||
import chiseltest._ | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
|
||
import scala.collection.immutable.SeqMap | ||
|
||
class OpaqueTypeTest extends AnyFlatSpec with ChiselScalatestTester { | ||
|
||
class OpaqueRecord[T <: Data](val data: T) extends Record with OpaqueType { | ||
val elements: SeqMap[String, T] = SeqMap("" -> data) | ||
} | ||
|
||
class OpaquePassthrough[T <: Data](data: T) extends Module { | ||
val in: OpaqueRecord[T] = IO(Input(new OpaqueRecord(data))) | ||
val out: OpaqueRecord[T] = IO(Output(new OpaqueRecord(data))) | ||
out := in | ||
} | ||
|
||
def rec[T <: Data](_val: => T): OpaqueRecord[T] = new OpaqueRecord(_val.cloneType: T).Lit(_.data -> _val) | ||
|
||
def testPokeExpect[T <: Data](_val: => T): TestResult = | ||
test(new OpaquePassthrough(_val.cloneType)) { dut => | ||
dut.in.poke(rec(_val)) | ||
dut.out.expect(rec(_val)) | ||
} | ||
|
||
behavior of "OpaqueType" | ||
|
||
it should "poke and expect successfully" in { | ||
testPokeExpect(4.U(6.W)) | ||
testPokeExpect(-4.S(8.W)) | ||
testPokeExpect(rec(5.U(3.W))) | ||
} | ||
|
||
} |