forked from OpenXiangShan/XiangShan
-
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: add example of chiseltest's unit-test and generating verilog fo…
…r xs' module (OpenXiangShan#1890) * test: add example to genenrate verilog for a small module Just use Parameters from DefaultConfig(& Argparser) like XSTop/SimTop * test: add DecodeUnitTest as an example for xs' chiseltest * ctrlblock: <> usage has changed, unidirection should use := * bump huancun * makefile: mv new makefile cmd into Makefile.test
- Loading branch information
Showing
9 changed files
with
122 additions
and
14 deletions.
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
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,12 @@ | ||
# only generate a small module: example | ||
verilog-decode: | ||
mill -i XiangShan.test.runMain xiangshan.DecodeMain -td build --output-file DecodeUnit.v | ||
|
||
# chiseltest | ||
# autorun all the chiselTest case | ||
test: | ||
mill -i XiangShan.test.test | ||
|
||
# only run DecodeUnitTest | ||
test-DecodeUnit: | ||
mill -i XiangShan.test.testOnly xiangshan.DecodeUnitTest |
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
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
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,56 @@ | ||
package xiangshan | ||
|
||
import chisel3._ | ||
import chisel3.stage._ | ||
import chiseltest._ | ||
import chiseltest.ChiselScalatestTester | ||
import chiseltest.VerilatorBackendAnnotation | ||
import chiseltest.simulator.{VerilatorFlags, VerilatorCFlags} | ||
import freechips.rocketchip.util.{ElaborationArtefacts, HasRocketChipStageUtils} | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.must.Matchers | ||
import firrtl.stage.RunFirrtlTransformAnnotation | ||
import xstransforms.PrintModuleName | ||
|
||
import firrtl.options.TargetDirAnnotation | ||
|
||
import top.ArgParser | ||
import xiangshan.backend.decode.DecodeUnit | ||
|
||
object DecodeMain extends App with HasRocketChipStageUtils { | ||
override def main(args: Array[String]): Unit = { | ||
val (config, firrtlOpts, firrtlComplier) = ArgParser.parse(args) | ||
// //val soc = DisableMonitors(p => LazyModule(new XSTop()(p)))(config) | ||
// If Complex Params are needed, wrap it with a Top Module to do dirty works, | ||
// and use "chisel3.aop.Select.collectDeep[ModuleWanted](WrapperModule){case a: ModuleWanted => a}.head.Params" | ||
val defaultConfig = config.alterPartial({ | ||
// Get XSCoreParams and pass it to the "small module" | ||
case XSCoreParamsKey => config(XSTileKey).head.copy( | ||
// Example of how to change params | ||
IssQueSize = 12 | ||
) | ||
}) | ||
(new ChiselStage).execute(args, Seq( | ||
ChiselGeneratorAnnotation(() => new DecodeUnit()(defaultConfig) | ||
))) | ||
// // Generate files when compiling. Used by ChiselDB. | ||
// ElaborationArtefacts.files.foreach{ case (extension, contents) => | ||
// writeOutputFile("./build", s"DecodeUnit.${extension}", contents()) | ||
// } | ||
} | ||
} | ||
|
||
class DecodeUnitTest extends XSTester { | ||
behavior of "DecodeUnit" | ||
it should "pass" in { | ||
test(new DecodeUnit()(config)).withAnnotations(Seq( | ||
VerilatorBackendAnnotation, | ||
VerilatorFlags(Seq()), | ||
WriteVcdAnnotation, | ||
TargetDirAnnotation("./build"), | ||
RunFirrtlTransformAnnotation(new PrintModuleName) | ||
)){ dut => | ||
dut.clock.step(10) | ||
} | ||
} | ||
} |
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,37 @@ | ||
package xiangshan | ||
|
||
import chisel3._ | ||
import chipsalliance.rocketchip.config.Config | ||
import chiseltest._ | ||
import chiseltest.{VerilatorBackendAnnotation, WriteVcdAnnotation} | ||
import chiseltest.simulator.{VerilatorCFlags, VerilatorFlags} | ||
import firrtl.AnnotationSeq | ||
import firrtl.stage.RunFirrtlTransformAnnotation | ||
import org.scalatest.flatspec._ | ||
import org.scalatest.matchers.should._ | ||
|
||
import top.{ArgParser, DefaultConfig} | ||
|
||
abstract class XSTester extends AnyFlatSpec with ChiselScalatestTester with Matchers with HasTestAnnos { | ||
behavior of "XiangShan Module" | ||
val defaultConfig = (new DefaultConfig) | ||
implicit val config = defaultConfig.alterPartial({ | ||
// Get XSCoreParams and pass it to the "small module" | ||
case XSCoreParamsKey => defaultConfig(XSTileKey).head.copy( | ||
// Example of how to change params | ||
IssQueSize = 12 | ||
) | ||
}) | ||
} | ||
|
||
trait HasTestAnnos { | ||
var testAnnos: AnnotationSeq = Seq() | ||
} | ||
|
||
trait DumpVCD { this: HasTestAnnos => | ||
testAnnos = testAnnos :+ WriteVcdAnnotation | ||
} | ||
|
||
trait UseVerilatorBackend { this: HasTestAnnos => | ||
testAnnos = testAnnos ++ Seq(VerilatorBackendAnnotation) | ||
} |