From 502c8dd35e6f27ed6794dad7ae9bcf4d41cc7474 Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Tue, 25 Sep 2018 12:25:05 -0400 Subject: Enforce port uniqueness in Chirrtl/High Checks Signed-off-by: Schuyler Eldridge --- src/test/scala/firrtlTests/CheckSpec.scala | 28 ++++++++++++++++++++++++++++ src/test/scala/firrtlTests/ChirrtlSpec.scala | 11 ++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/test/scala/firrtlTests/CheckSpec.scala b/src/test/scala/firrtlTests/CheckSpec.scala index 3c9894ba..767f2392 100644 --- a/src/test/scala/firrtlTests/CheckSpec.scala +++ b/src/test/scala/firrtlTests/CheckSpec.scala @@ -282,4 +282,32 @@ class CheckSpec extends FlatSpec with Matchers { } } } + + behavior of "Uniqueness" + for ((description, input) <- CheckSpec.nonUniqueExamples) { + it should s"be asserted for $description" in { + assertThrows[CheckHighForm.NotUniqueException] { + Seq(ToWorkingIR, CheckHighForm).foldLeft(Parser.parse(input)){ case (c, tx) => tx.run(c) } + } + } + } } + +object CheckSpec { + val nonUniqueExamples = List( + ("two ports with the same name", + """|circuit Top: + | module Top: + | input a: UInt<1> + | input a: UInt<1>""".stripMargin), + ("two nodes with the same name", + """|circuit Top: + | module Top: + | node a = UInt<1>("h0") + | node a = UInt<1>("h0")""".stripMargin), + ("a port and a node with the same name", + """|circuit Top: + | module Top: + | input a: UInt<1> + | node a = UInt<1>("h0") """.stripMargin) ) + } diff --git a/src/test/scala/firrtlTests/ChirrtlSpec.scala b/src/test/scala/firrtlTests/ChirrtlSpec.scala index fd4374f0..774c352b 100644 --- a/src/test/scala/firrtlTests/ChirrtlSpec.scala +++ b/src/test/scala/firrtlTests/ChirrtlSpec.scala @@ -16,7 +16,7 @@ class ChirrtlSpec extends FirrtlFlatSpec { CInferTypes, CInferMDir, RemoveCHIRRTL, - ToWorkingIR, + ToWorkingIR, CheckHighForm, ResolveKinds, InferTypes, @@ -71,6 +71,15 @@ class ChirrtlSpec extends FirrtlFlatSpec { } } } + + behavior of "Uniqueness" + for ((description, input) <- CheckSpec.nonUniqueExamples) { + it should s"be asserted for $description" in { + assertThrows[CheckChirrtl.NotUniqueException] { + Seq(ToWorkingIR, CheckChirrtl).foldLeft(Parser.parse(input)){ case (c, tx) => tx.run(c) } + } + } + } } class ChirrtlMemsExecutionTest extends ExecutionTest("ChirrtlMems", "/features") -- cgit v1.2.3