Skip to content

Commit

Permalink
Add BundleLiteralsSpec (#37)
Browse files Browse the repository at this point in the history
* Add BundleLiteralsSpec
Three simple tests showing syntax and usage
Third tests showing peeking currently expects an exception

* Add BundleLiteralsSpec
Use `chiselTypeOf` instead of `cloneType`.
Fix name of putative test of peeking Bundles

* Change last BundleLiterals test to be an ignore
peeking bundles is not supported yet
  • Loading branch information
chick committed May 15, 2019
1 parent 5381a7d commit 331c16b
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions src/test/scala/chisel3/tests/BundleLiteralsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,14 @@ import org.scalatest._

import chisel3._
import chisel3.tester._
import chisel3.experimental.BundleLiterals._

class BundleLiteralSpec extends FlatSpec with ChiselScalatestTester {
class BundleLiteralsSpec extends FlatSpec with ChiselScalatestTester with Matchers {
behavior of "Testers2"

class DoubleElements extends Bundle {
val a = UInt(8.W)
val b = UInt(8.W)

// IGNORE THIS - this is some boilerplate Bundle Literals code
// and would be auto-generated by an upcoming feature
def Lit(aVal: UInt, bVal: UInt) = {
import chisel3.core.BundleLitBinding
val clone = cloneType
clone.selfBind(BundleLitBinding(Map(
clone.a -> litArgOfBits(aVal),
clone.b -> litArgOfBits(bVal)
)))
clone
}
}

it should "poke Bundle literals" in {
Expand All @@ -36,35 +25,45 @@ class BundleLiteralSpec extends FlatSpec with ChiselScalatestTester {
io.aOut := io.in.a
io.bOut := io.in.b
}) { c =>
c.io.in.poke(c.io.in.Lit(0.U, 1.U))
c.io.in.poke(chiselTypeOf(c.io.in).Lit(_.a -> 0.U, _.b -> 1.U))
c.io.aOut.expect(0.U)
c.io.bOut.expect(1.U)

c.io.in.poke(c.io.in.Lit(2.U, 5.U))
c.io.in.poke(chiselTypeOf(c.io.in).Lit(_.a -> 2.U, _.b -> 5.U))
c.io.aOut.expect(2.U)
c.io.bOut.expect(5.U)
}
}

it should "expect Bundle literals" in {
test(new PassthroughModule(new DoubleElements)) { c =>
c.in.poke(c.in.Lit(0.U, 1.U))
c.out.expect(c.in.Lit(0.U, 1.U))
c.in.poke(c.in.Lit(2.U, 5.U))
c.out.expect(c.in.Lit(2.U, 5.U))
c.in.poke(chiselTypeOf(c.in).Lit(_.a -> 0.U, _.b -> 1.U))
c.out.expect(chiselTypeOf(c.in).Lit(_.a -> 0.U, _.b -> 1.U))
c.in.poke(chiselTypeOf(c.in).Lit(_.a -> 2.U, _.b -> 5.U))
c.out.expect(chiselTypeOf(c.in).Lit(_.a -> 2.U, _.b -> 5.U))
}
}

it should "fail on expect mismatch" in {
assertThrows[exceptions.TestFailedException] {
test(new PassthroughModule(new DoubleElements)) { c =>
c.in.poke(c.in.Lit(0.U, 1.U))
c.out.expect(c.in.Lit(0.U, 2.U))
c.in.poke(chiselTypeOf(c.in).Lit(_.a -> 0.U, _.b -> 1.U))
c.out.expect(chiselTypeOf(c.in).Lit(_.a -> 0.U, _.b -> 2.U))
}
}
}

ignore should "peek Bundle literals" in {
// TODO to be written
// peek on bundle not supported yet, this test will fail and should
// be altered when BundleLiteral peeking works
// it is not altogether what the use case is for peeking a bundle
// possibly to poke that value somewhere else
// this should be considered when peeking Bundles is supported
ignore should "return a BundleLiteral when peeking" in {
test(new PassthroughModule(new DoubleElements)) { c =>
c.in.poke(chiselTypeOf(c.in).Lit(_.a -> 0.U, _.b -> 1.U))
val output = c.out.peek()
output.a === 0.U should be(true.B)
output.a === 1.U should be(true.B)
}
}
}

0 comments on commit 331c16b

Please sign in to comment.