chisel-tutorial
chisel-tutorial copied to clipboard
AdderTest.scala get a wrong testing
trafficstars
for (t <- 0 until 4) {
val rnd0 = rnd.nextInt(c.n)
val rnd1 = rnd.nextInt(c.n)
val rnd2 = rnd.nextInt(1)
poke(c.io.A, rnd0)
poke(c.io.B, rnd1)
poke(c.io.Cin, rnd2)
step(1)
val rsum = rnd0 + rnd1 + rnd2
val mask = BigInt("1"*c.n, 2)
expect(c.io.Sum, rsum & mask)
expect(c.io.Cout, rsum % 1)
}
rnd0, rnd1, rnd2 got a wrong number
rnd0 and rnd1 should be a random int with c.n bit, but this give 0 < x < c.n
rnd2 using val rnd2 = rnd.nextInt(1) always give 0
and the except io.Cout using rsum % 1 get always 0
because the rnd0 and rnd1 is too small, so the test always success
I suggest using
for (t <- 0 until 4) {
val rnd0 = rnd.nextInt(1<<c.n)
val rnd1 = rnd.nextInt(1<<c.n)
val rnd2 = rnd.nextInt(2)
poke(c.io.A, rnd0)
poke(c.io.B, rnd1)
poke(c.io.Cin, rnd2)
step(1)
val rsum = rnd0 + rnd1 + rnd2
val mask = BigInt("1"*c.n, 2)
expect(c.io.Sum, rsum & mask)
expect(c.io.Cout, ((1 << c.n) & rsum) >> c.n)
}
That's a good catch @WindProphet, thanks. I have submitted PR #118 which implements your suggestion. Please feel free to submit a PR for this sort of thing. We welcome contributions.