Skip to content

Commit

Permalink
Test all cases in ParameterizedOneHotTesters
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryz123 committed Aug 26, 2020
1 parent c4f4071 commit 3ccb639
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/test/scala/chiselTests/OneHotMuxSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class OneHotMuxSpec extends AnyFreeSpec with Matchers with ChiselRunners {
assertTesterPasses(new AllSameFixedPointOneHotTester)
}
"simple one hot mux with all same parameterized sint values should work" in {
val values: Seq[SInt] = Seq((-3).S, (-5).S, (-7).S, (-11).S)
assertTesterPasses(new ParameterizedOneHotTester(values, SInt(8.W), -5.S(8.W)))
assertTesterPasses(new ParameterizedOneHotTester)
}
"simple one hot mux with all same parameterized aggregates containing fixed values should work" in {
assertTesterPasses(new ParameterizedAggregateOneHotTester)
Expand Down Expand Up @@ -121,14 +120,14 @@ class AllSameFixedPointOneHotTester extends BasicTester {
stop()
}

class ParameterizedOneHotTester[T <: Data](values: Seq[T], outGen: T, expected: T) extends BasicTester {
val dut = Module(new ParameterizedOneHot(values, outGen))
dut.io.selectors(0) := false.B
dut.io.selectors(1) := true.B
dut.io.selectors(2) := false.B
dut.io.selectors(3) := false.B
class ParameterizedOneHotTester extends BasicTester {
val values: Seq[Int] = Seq(-3, -5, -7, -11)
for ((v, i) <- values.zipWithIndex) {
val dut = Module(new ParameterizedOneHot(values.map(_.S), SInt(8.W)))
dut.io.selectors := (1 << i).U(4.W).asBools

assert(dut.io.out.asUInt() === expected.asUInt())
assert(dut.io.out.asUInt() === v.S(8.W).asUInt())
}

stop()
}
Expand Down Expand Up @@ -178,14 +177,12 @@ object Agg2 extends HasMakeLit[Agg2] {

class ParameterizedAggregateOneHotTester extends BasicTester {
val values = (0 until 4).map { n => Agg1.makeLit(n) }
for ((v, i) <- values.zipWithIndex) {
val dut = Module(new ParameterizedAggregateOneHot(Agg1, new Agg1))
dut.io.selectors := (1 << i).U(4.W).asBools

val dut = Module(new ParameterizedAggregateOneHot(Agg1, new Agg1))
dut.io.selectors(0) := false.B
dut.io.selectors(1) := true.B
dut.io.selectors(2) := false.B
dut.io.selectors(3) := false.B

assert(dut.io.out.asUInt() === values(1).asUInt())
assert(dut.io.out.asUInt() === values(i).asUInt())
}

stop()
}
Expand Down

0 comments on commit 3ccb639

Please sign in to comment.