-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(countcomb): add chiseltest-based tests with vcd output (#5)
- Loading branch information
1 parent
f560b0b
commit 4e583d8
Showing
5 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
scala_2_12 | ||
circt | ||
verible | ||
gtkwave | ||
] | ||
++ (with pkgs.python3Packages; [ apycula ]); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
target/ | ||
generated/ | ||
project/ | ||
test_run_dir/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
projects/chisel-practice/src/test/scala/projects/CountCombinations.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package projects.tests | ||
|
||
import projects.CountCombinations | ||
import chisel3._ | ||
import chiseltest._ | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
|
||
class CountCombinationsTester extends AnyFlatSpec with ChiselScalatestTester { | ||
"CountCombinations of 0b11 in 0b11111111" should "be equal to 7" in { | ||
test(new CountCombinations(8)) { dut => | ||
dut.io.value.poke("b11111111".U) | ||
dut.io.count.expect(7.U) | ||
} | ||
} | ||
|
||
"CountCombinations of 0b11 in 0b00000000" should "be equal to 0" in { | ||
test(new CountCombinations(8)) { dut => | ||
dut.io.value.poke("b00000000".U) | ||
dut.io.count.expect(0.U) | ||
} | ||
} | ||
} | ||
|
||
class CountCombinationsTestbench( | ||
numBits: Int, | ||
countMax: Int | ||
) extends Module { | ||
val io = IO(new Bundle { | ||
val value = Output(UInt(util.log2Up(countMax).W)) | ||
val count = Output(UInt(util.log2Up(numBits).W)) | ||
}) | ||
|
||
val dut = Module(new CountCombinations(numBits)) | ||
val (value, _) = util.Counter(true.B, countMax) | ||
|
||
dut.io.value := value | ||
io.value <> value | ||
io.count := dut.io.count | ||
} | ||
|
||
class CountCombinationsTopTester | ||
extends AnyFlatSpec | ||
with ChiselScalatestTester { | ||
"CountCombinations" should "output 0, 0, 0, 1" in { | ||
test(new CountCombinationsTestbench(8, 4)) | ||
.withAnnotations(Seq(WriteVcdAnnotation)) { dut => | ||
dut.io.value.expect(0.U) | ||
dut.io.count.expect(0.U) | ||
dut.clock.step(1) | ||
dut.io.value.expect(1.U) | ||
dut.io.count.expect(0.U) | ||
dut.clock.step(1) | ||
dut.io.value.expect(2.U) | ||
dut.io.count.expect(0.U) | ||
dut.clock.step(1) | ||
dut.io.value.expect(3.U) | ||
dut.io.count.expect(1.U) | ||
dut.clock.step(1) | ||
} | ||
} | ||
|
||
"CountCombinations" should "work for all 8-bit numbers" in { | ||
test(new CountCombinationsTestbench(8, 256)) | ||
.withAnnotations(Seq(WriteVcdAnnotation)) { dut => | ||
dut.clock.step(256) | ||
} | ||
} | ||
} |