summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/BitwiseOps.scala
diff options
context:
space:
mode:
authorHenry Cook2015-08-14 01:51:39 -0700
committerHenry Cook2015-08-14 01:51:39 -0700
commitc23943b41de55de9af249a3b231558ad23fc8087 (patch)
tree0d042d64c6b3e794bbdcae7241c79f83c721b917 /src/test/scala/chiselTests/BitwiseOps.scala
parent5e9be183f98d32164332fa0548fe80686f50c851 (diff)
Add Vec tests. Do a better job of generating widths.
Diffstat (limited to 'src/test/scala/chiselTests/BitwiseOps.scala')
-rw-r--r--src/test/scala/chiselTests/BitwiseOps.scala36
1 files changed, 10 insertions, 26 deletions
diff --git a/src/test/scala/chiselTests/BitwiseOps.scala b/src/test/scala/chiselTests/BitwiseOps.scala
index 5a1f1de8..1d668ebd 100644
--- a/src/test/scala/chiselTests/BitwiseOps.scala
+++ b/src/test/scala/chiselTests/BitwiseOps.scala
@@ -35,38 +35,22 @@ import org.scalatest._
import org.scalatest.prop._
import Chisel.testers.BasicTester
-class BitwiseOps(w: Int) extends Module {
- val io = new Bundle {
- val a = Bits(INPUT, w)
- val b = Bits(INPUT, w)
- val not = Bits(OUTPUT, w)
- val and = Bits(OUTPUT, w)
- val or = Bits(OUTPUT, w)
- val xor = Bits(OUTPUT, w)
- }
- io.not := ~io.a
- io.and := io.a & io.b
- io.or := io.a | io.b
- io.xor := io.a ^ io.b
-}
-
class BitwiseOpsSpec extends ChiselPropSpec {
- class BitwiseOpsTester(w: Int, a: Int, b: Int) extends BasicTester {
- val mask = (1 << w) - 1
- val dut = Module(new BitwiseOps(w))
+ class BitwiseOpsTester(w: Int, _a: Int, _b: Int) extends BasicTester {
io.done := Bool(true)
- dut.io.a := UInt(a)
- dut.io.b := UInt(b)
- when(dut.io.not != UInt(mask & ~a)) { io.error := UInt(1) }
- when(dut.io.and != UInt(mask & (a & b))) { io.error := UInt(2) }
- when(dut.io.or != UInt(mask & (a | b))) { io.error := UInt(3) }
- when(dut.io.xor != UInt(mask & (a ^ b))) { io.error := UInt(4) }
+ val mask = (1 << w) - 1
+ val a = UInt(_a)
+ val b = UInt(_b)
+ when(~a != UInt(mask & ~_a)) { io.error := UInt(1) }
+ when((a & b) != UInt(mask & (_a & _b))) { io.error := UInt(2) }
+ when((a | b) != UInt(mask & (_a | _b))) { io.error := UInt(3) }
+ when((a ^ b) != UInt(mask & (_a ^ _b))) { io.error := UInt(4) }
}
property("All bit-wise ops should return the correct result") {
- forAll(safeUInts, safeUInts) { (a: Int, b: Int) =>
- assert(execute{ new BitwiseOpsTester(32, a, b) })
+ forAll(safeUIntPair) { case(w: Int, a: Int, b: Int) =>
+ assert(execute{ new BitwiseOpsTester(w, a, b) })
}
}
}