aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/test/scala/firrtlTests/analyses/InstanceGraphTests.scala49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/test/scala/firrtlTests/analyses/InstanceGraphTests.scala b/src/test/scala/firrtlTests/analyses/InstanceGraphTests.scala
index eb62c564..ee6ecd5f 100644
--- a/src/test/scala/firrtlTests/analyses/InstanceGraphTests.scala
+++ b/src/test/scala/firrtlTests/analyses/InstanceGraphTests.scala
@@ -1,5 +1,6 @@
package firrtlTests.analyses
+import firrtl.annotations.TargetToken.OfModule
import firrtl.analyses.InstanceGraph
import firrtl.graph.DiGraph
import firrtl.WDefInstance
@@ -195,4 +196,52 @@ circuit Top :
val hier = instGraph.fullHierarchy
hier.keys.toSeq.map(_.name) should equal (Seq("Top", "a", "b", "c", "d", "e"))
}
+
+ behavior of "InstanceGraph.staticInstanceCount"
+
+ it should "report that there is one instance of the top module" in {
+ val input =
+ """|circuit Foo:
+ | module Foo:
+ | skip
+ |""".stripMargin
+ val iGraph = new InstanceGraph(ToWorkingIR.run(parse(input)))
+ val expectedCounts = Map(OfModule("Foo") -> 1)
+ iGraph.staticInstanceCount should be (expectedCounts)
+ }
+
+ it should "report correct number of instances for a sample circuit" in {
+ val input =
+ """|circuit Foo:
+ | module Baz:
+ | skip
+ | module Bar:
+ | inst baz1 of Baz
+ | inst baz2 of Baz
+ | inst baz3 of Baz
+ | skip
+ | module Foo:
+ | inst bar1 of Bar
+ | inst bar2 of Bar
+ |""".stripMargin
+ val iGraph = new InstanceGraph(ToWorkingIR.run(parse(input)))
+ val expectedCounts = Map(OfModule("Foo") -> 1,
+ OfModule("Bar") -> 2,
+ OfModule("Baz") -> 3)
+ iGraph.staticInstanceCount should be (expectedCounts)
+ }
+
+ it should "report zero instances for dead modules" in {
+ val input =
+ """|circuit Foo:
+ | module Bar:
+ | skip
+ | module Foo:
+ | skip
+ |""".stripMargin
+ val iGraph = new InstanceGraph(ToWorkingIR.run(parse(input)))
+ val expectedCounts = Map(OfModule("Foo") -> 1,
+ OfModule("Bar") -> 0)
+ iGraph.staticInstanceCount should be (expectedCounts)
+ }
}