diff options
| author | Schuyler Eldridge | 2020-02-11 18:00:50 -0500 |
|---|---|---|
| committer | Schuyler Eldridge | 2020-02-11 22:53:14 -0500 |
| commit | ba28e5d922ce853cd6ff74178dcc38b7e07af864 (patch) | |
| tree | fd6f69a7187f204cb44cfd405ffb00eb61067d01 /src | |
| parent | 55cb667f048e685d1a67588fa30b2c0e4f7ec21f (diff) | |
Add InstanceGraph.staticInstanceCount tests
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/scala/firrtlTests/analyses/InstanceGraphTests.scala | 49 |
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) + } } |
