From 66d687d9c7af34e9d7a061feba309ec7a6dbd261 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Fri, 8 Dec 2017 17:06:19 -0800 Subject: Reject negative shift amounts; add tests (#730) Closes #729--- src/test/scala/chiselTests/FixedPointSpec.scala | 3 +++ src/test/scala/chiselTests/SIntOps.scala | 4 ++++ src/test/scala/chiselTests/UIntOps.scala | 9 +++++++++ 3 files changed, 16 insertions(+) (limited to 'src') diff --git a/src/test/scala/chiselTests/FixedPointSpec.scala b/src/test/scala/chiselTests/FixedPointSpec.scala index 8caa7f1e..ff4b42a0 100644 --- a/src/test/scala/chiselTests/FixedPointSpec.scala +++ b/src/test/scala/chiselTests/FixedPointSpec.scala @@ -126,4 +126,7 @@ class FixedPointSpec extends ChiselPropSpec { property("should mux different widths and binary points") { assertTesterPasses { new FixedPointMuxTester } } + property("Negative shift amounts are invalid") { + a [ChiselException] should be thrownBy { elaborate(new NegativeShift(FixedPoint(1.W, 0.BP))) } + } } diff --git a/src/test/scala/chiselTests/SIntOps.scala b/src/test/scala/chiselTests/SIntOps.scala index 900eb074..a9b75446 100644 --- a/src/test/scala/chiselTests/SIntOps.scala +++ b/src/test/scala/chiselTests/SIntOps.scala @@ -89,5 +89,9 @@ class SIntOpsSpec extends ChiselPropSpec { elaborate { new SIntOps } } + property("Negative shift amounts are invalid") { + a [ChiselException] should be thrownBy { elaborate(new NegativeShift(SInt())) } + } + ignore("SIntOpsTester should return the correct result") { } } diff --git a/src/test/scala/chiselTests/UIntOps.scala b/src/test/scala/chiselTests/UIntOps.scala index d31d86a8..490af22b 100644 --- a/src/test/scala/chiselTests/UIntOps.scala +++ b/src/test/scala/chiselTests/UIntOps.scala @@ -91,6 +91,11 @@ class BadBoolConversion extends Module { io.b := io.u.toBool } +class NegativeShift(t: => Bits) extends Module { + val io = IO(new Bundle) + Reg(t) >> -1 +} + class UIntOpsSpec extends ChiselPropSpec with Matchers { // Disable shrinking on error. implicit val noShrinkListVal = Shrink[List[Int]](_ => Stream.empty) @@ -111,5 +116,9 @@ class UIntOpsSpec extends ChiselPropSpec with Matchers { property("UIntOpsTester should return the correct result") { assertTesterPasses { new UIntOpsTester(123, 7) } } + + property("Negative shift amounts are invalid") { + a [ChiselException] should be thrownBy { elaborate(new NegativeShift(UInt())) } + } } -- cgit v1.2.3