2015-07-13 23:54:26 +02:00
|
|
|
// See LICENSE for license details.
|
|
|
|
|
|
|
|
package rocketchip
|
|
|
|
|
|
|
|
import Chisel._
|
2016-02-25 00:23:37 +01:00
|
|
|
import scala.collection.mutable.{LinkedHashSet,LinkedHashMap}
|
2015-10-22 03:23:58 +02:00
|
|
|
import cde.{Parameters, ParameterDump, Config}
|
2015-07-13 23:54:26 +02:00
|
|
|
|
|
|
|
abstract class RocketTestSuite {
|
|
|
|
val dir: String
|
|
|
|
val makeTargetName: String
|
2015-09-12 03:36:04 +02:00
|
|
|
val names: LinkedHashSet[String]
|
2016-02-25 00:04:13 +01:00
|
|
|
val envName: String
|
2015-07-13 23:54:26 +02:00
|
|
|
def postScript = s"""
|
|
|
|
|
|
|
|
$$(addprefix $$(output_dir)/, $$(addsuffix .hex, $$($makeTargetName))): $$(output_dir)/%.hex: $dir/%.hex
|
|
|
|
\tmkdir -p $$(output_dir)
|
|
|
|
\tln -fs $$< $$@
|
|
|
|
|
|
|
|
$$(addprefix $$(output_dir)/, $$($makeTargetName)): $$(output_dir)/%: $dir/%
|
|
|
|
\tmkdir -p $$(output_dir)
|
|
|
|
\tln -fs $$< $$@
|
|
|
|
|
|
|
|
run-$makeTargetName: $$(addprefix $$(output_dir)/, $$(addsuffix .out, $$($makeTargetName)))
|
2016-05-18 20:26:50 +02:00
|
|
|
\t@echo; perl -ne 'print " [$$$$1] $$$$ARGV \\t$$$$2\\n" if( /\\*{3}(.{8})\\*{3}(.*)/ || /ASSERTION (FAILED)/i )' $$^ /dev/null | perl -ne 'if(/(.*)/){print "$$$$1\\n\\n"; exit(1) if eof()}'
|
2015-07-13 23:54:26 +02:00
|
|
|
|
|
|
|
run-$makeTargetName-debug: $$(addprefix $$(output_dir)/, $$(addsuffix .vpd, $$($makeTargetName)))
|
2016-05-18 20:26:50 +02:00
|
|
|
\t@echo; perl -ne 'print " [$$$$1] $$$$ARGV \\t$$$$2\\n" if( /\\*{3}(.{8})\\*{3}(.*)/ || /ASSERTION (FAILED)/i )' $$(patsubst %.vpd,%.out,$$^) /dev/null | perl -ne 'if(/(.*)/){print "$$$$1\\n\\n"; exit(1) if eof()}'
|
2015-07-13 23:54:26 +02:00
|
|
|
"""
|
|
|
|
}
|
|
|
|
|
2016-06-23 01:14:02 +02:00
|
|
|
class AssemblyTestSuite(prefix: String, val names: LinkedHashSet[String])(val envName: String) extends RocketTestSuite {
|
2016-02-24 01:05:27 +01:00
|
|
|
val dir = "$(RISCV)/riscv64-unknown-elf/share/riscv-tests/isa"
|
2016-06-23 01:14:02 +02:00
|
|
|
val makeTargetName = prefix + "-" + envName + "-asm-tests"
|
|
|
|
override def toString = s"$makeTargetName = \\\n" + names.map(n => s"\t$prefix-$envName-$n").mkString(" \\\n") + postScript
|
2015-07-13 23:54:26 +02:00
|
|
|
}
|
|
|
|
|
2015-09-12 03:36:04 +02:00
|
|
|
class BenchmarkTestSuite(makePrefix: String, val dir: String, val names: LinkedHashSet[String]) extends RocketTestSuite {
|
2016-02-25 00:04:13 +01:00
|
|
|
val envName = ""
|
2015-07-13 23:54:26 +02:00
|
|
|
val makeTargetName = makePrefix + "-bmark-tests"
|
|
|
|
override def toString = s"$makeTargetName = \\\n" + names.map(n => s"\t$n.riscv").mkString(" \\\n") + postScript
|
|
|
|
}
|
|
|
|
|
2016-08-01 03:04:56 +02:00
|
|
|
object TestGeneration {
|
2015-07-13 23:54:26 +02:00
|
|
|
import scala.collection.mutable.HashMap
|
2016-02-25 00:23:37 +01:00
|
|
|
val asmSuites = new LinkedHashMap[String,AssemblyTestSuite]()
|
2015-07-13 23:54:26 +02:00
|
|
|
val bmarkSuites = new HashMap[String,BenchmarkTestSuite]()
|
|
|
|
|
|
|
|
def addSuite(s: RocketTestSuite) {
|
|
|
|
s match {
|
|
|
|
case a: AssemblyTestSuite => asmSuites += (a.makeTargetName -> a)
|
|
|
|
case b: BenchmarkTestSuite => bmarkSuites += (b.makeTargetName -> b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def addSuites(s: Seq[RocketTestSuite]) { s.foreach(addSuite) }
|
|
|
|
|
2015-10-22 03:23:58 +02:00
|
|
|
def generateMakefrag(topModuleName: String, configClassName: String) {
|
2015-07-13 23:54:26 +02:00
|
|
|
def gen(kind: String, s: Seq[RocketTestSuite]) = {
|
|
|
|
if(s.length > 0) {
|
2016-02-25 00:04:13 +01:00
|
|
|
val envs = s.groupBy(_.envName)
|
|
|
|
val targets = s.map(t => s"$$(${t.makeTargetName})").mkString(" ")
|
|
|
|
s.map(_.toString).mkString("\n") +
|
|
|
|
envs.filterKeys(_ != "").map( {
|
|
|
|
case (env,envsuites) => {
|
|
|
|
val suites = envsuites.map(t => s"$$(${t.makeTargetName})").mkString(" ")
|
|
|
|
s"""
|
|
|
|
run-$kind-$env-tests: $$(addprefix $$(output_dir)/, $$(addsuffix .out, $suites))
|
2016-05-18 20:26:50 +02:00
|
|
|
\t@echo; perl -ne 'print " [$$$$1] $$$$ARGV \\t$$$$2\\n" if( /\\*{3}(.{8})\\*{3}(.*)/ || /ASSERTION (FAILED)/i )' $$^ /dev/null | perl -ne 'if(/(.*)/){print "$$$$1\\n\\n"; exit(1) if eof()}'
|
2016-02-25 00:04:13 +01:00
|
|
|
run-$kind-$env-tests-debug: $$(addprefix $$(output_dir)/, $$(addsuffix .vpd, $suites))
|
2016-05-18 20:26:50 +02:00
|
|
|
\t@echo; perl -ne 'print " [$$$$1] $$$$ARGV \\t$$$$2\\n" if( /\\*{3}(.{8})\\*{3}(.*)/ || /ASSERTION (FAILED)/i )' $$(patsubst %.vpd,%.out,$$^) /dev/null | perl -ne 'if(/(.*)/){print "$$$$1\\n\\n"; exit(1) if eof()}'
|
2016-02-25 00:04:13 +01:00
|
|
|
run-$kind-$env-tests-fast: $$(addprefix $$(output_dir)/, $$(addsuffix .run, $suites))
|
2016-05-18 20:26:50 +02:00
|
|
|
\t@echo; perl -ne 'print " [$$$$1] $$$$ARGV \\t$$$$2\\n" if( /\\*{3}(.{8})\\*{3}(.*)/ || /ASSERTION (FAILED)/i )' $$^ /dev/null | perl -ne 'if(/(.*)/){print "$$$$1\\n\\n"; exit(1) if eof()}'
|
2016-02-25 00:04:13 +01:00
|
|
|
"""} } ).mkString("\n") + s"""
|
2015-07-13 23:54:26 +02:00
|
|
|
run-$kind-tests: $$(addprefix $$(output_dir)/, $$(addsuffix .out, $targets))
|
2016-05-18 20:26:50 +02:00
|
|
|
\t@echo; perl -ne 'print " [$$$$1] $$$$ARGV \\t$$$$2\\n" if( /\\*{3}(.{8})\\*{3}(.*)/ || /ASSERTION (FAILED)/i )' $$^ /dev/null | perl -ne 'if(/(.*)/){print "$$$$1\\n\\n"; exit(1) if eof()}'
|
2015-07-13 23:54:26 +02:00
|
|
|
run-$kind-tests-debug: $$(addprefix $$(output_dir)/, $$(addsuffix .vpd, $targets))
|
2016-05-18 20:26:50 +02:00
|
|
|
\t@echo; perl -ne 'print " [$$$$1] $$$$ARGV \\t$$$$2\\n" if( /\\*{3}(.{8})\\*{3}(.*)/ || /ASSERTION (FAILED)/i )' $$(patsubst %.vpd,%.out,$$^) /dev/null | perl -ne 'if(/(.*)/){print "$$$$1\\n\\n"; exit(1) if eof()}'
|
2015-07-22 20:49:10 +02:00
|
|
|
run-$kind-tests-fast: $$(addprefix $$(output_dir)/, $$(addsuffix .run, $targets))
|
2016-05-18 20:26:50 +02:00
|
|
|
\t@echo; perl -ne 'print " [$$$$1] $$$$ARGV \\t$$$$2\\n" if( /\\*{3}(.{8})\\*{3}(.*)/ || /ASSERTION (FAILED)/i )' $$^ /dev/null | perl -ne 'if(/(.*)/){print "$$$$1\\n\\n"; exit(1) if eof()}'
|
2015-07-13 23:54:26 +02:00
|
|
|
"""
|
|
|
|
} else { "\n" }
|
|
|
|
}
|
|
|
|
|
2015-10-22 03:23:58 +02:00
|
|
|
val f = createOutputFile(s"$topModuleName.$configClassName.d")
|
|
|
|
f.write(
|
|
|
|
List(
|
|
|
|
gen("asm", asmSuites.values.toSeq),
|
|
|
|
gen("bmark", bmarkSuites.values.toSeq)
|
|
|
|
).mkString("\n"))
|
2015-07-13 23:54:26 +02:00
|
|
|
f.close
|
|
|
|
}
|
2016-08-01 03:04:56 +02:00
|
|
|
|
|
|
|
def createOutputFile(name: String) =
|
|
|
|
new java.io.FileWriter(s"${Driver.targetDir}/$name")
|
2015-07-13 23:54:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
object DefaultTestSuites {
|
2015-09-12 03:36:04 +02:00
|
|
|
val rv32uiNames = LinkedHashSet(
|
2015-07-13 23:54:26 +02:00
|
|
|
"simple", "add", "addi", "and", "andi", "auipc", "beq", "bge", "bgeu", "blt", "bltu", "bne", "fence_i",
|
2016-07-15 07:11:19 +02:00
|
|
|
"jal", "jalr", "lb", "lbu", "lh", "lhu", "lui", "lw", "or", "ori", "sb", "sh", "sw", "sll", "slli",
|
2015-07-13 23:54:26 +02:00
|
|
|
"slt", "slti", "sra", "srai", "srl", "srli", "sub", "xor", "xori")
|
2016-06-23 01:14:02 +02:00
|
|
|
val rv32ui = new AssemblyTestSuite("rv32ui", rv32uiNames)(_)
|
2015-07-13 23:54:26 +02:00
|
|
|
|
2016-07-30 01:36:07 +02:00
|
|
|
val rv32ucNames = LinkedHashSet("rvc")
|
|
|
|
val rv32uc = new AssemblyTestSuite("rv32uc", rv32ucNames)(_)
|
|
|
|
|
2015-09-12 03:36:04 +02:00
|
|
|
val rv32umNames = LinkedHashSet("mul", "mulh", "mulhsu", "mulhu", "div", "divu", "rem", "remu")
|
2016-06-23 01:14:02 +02:00
|
|
|
val rv32um = new AssemblyTestSuite("rv32um", rv32umNames)(_)
|
2015-07-13 23:54:26 +02:00
|
|
|
|
2016-05-25 20:08:11 +02:00
|
|
|
val rv32uaNames = LinkedHashSet("lrsc", "amoadd_w", "amoand_w", "amoor_w", "amoxor_w", "amoswap_w", "amomax_w", "amomaxu_w", "amomin_w", "amominu_w")
|
2016-06-23 01:14:02 +02:00
|
|
|
val rv32ua = new AssemblyTestSuite("rv32ua", rv32uaNames)(_)
|
2015-07-13 23:54:26 +02:00
|
|
|
|
2016-07-22 20:36:45 +02:00
|
|
|
val rv32siNames = LinkedHashSet("csr", "ma_fetch", "scall", "sbreak", "wfi", "dirty")
|
2016-06-23 01:14:02 +02:00
|
|
|
val rv32si = new AssemblyTestSuite("rv32si", rv32siNames)(_)
|
2016-03-11 02:40:21 +01:00
|
|
|
|
2016-07-22 20:36:45 +02:00
|
|
|
val rv32miNames = LinkedHashSet("csr", "mcsr", "illegal", "ma_addr", "ma_fetch", "sbreak", "scall")
|
2016-06-23 01:14:02 +02:00
|
|
|
val rv32mi = new AssemblyTestSuite("rv32mi", rv32miNames)(_)
|
2016-03-11 02:40:21 +01:00
|
|
|
|
2016-05-25 20:08:11 +02:00
|
|
|
val rv32u = List(rv32ui, rv32um)
|
2016-03-11 02:40:21 +01:00
|
|
|
val rv32i = List(rv32ui, rv32si, rv32mi)
|
2016-07-22 20:36:45 +02:00
|
|
|
val rv32pi = List(rv32ui, rv32mi)
|
2016-03-11 02:40:21 +01:00
|
|
|
|
2015-09-12 03:36:04 +02:00
|
|
|
val rv64uiNames = LinkedHashSet("addw", "addiw", "ld", "lwu", "sd", "slliw", "sllw", "sltiu", "sltu", "sraiw", "sraw", "srliw", "srlw", "subw")
|
2016-06-23 01:14:02 +02:00
|
|
|
val rv64ui = new AssemblyTestSuite("rv64ui", rv32uiNames ++ rv64uiNames)(_)
|
2015-07-13 23:54:26 +02:00
|
|
|
|
2015-09-12 03:36:04 +02:00
|
|
|
val rv64umNames = LinkedHashSet("divuw", "divw", "mulw", "remuw", "remw")
|
2016-06-23 01:14:02 +02:00
|
|
|
val rv64um = new AssemblyTestSuite("rv64um", rv32umNames ++ rv64umNames)(_)
|
2015-07-13 23:54:26 +02:00
|
|
|
|
|
|
|
val rv64uaNames = rv32uaNames.map(_.replaceAll("_w","_d"))
|
2016-06-23 01:14:02 +02:00
|
|
|
val rv64ua = new AssemblyTestSuite("rv64ua", rv32uaNames ++ rv64uaNames)(_)
|
2015-07-13 23:54:26 +02:00
|
|
|
|
2016-07-30 01:36:07 +02:00
|
|
|
val rv64ucNames = rv32ucNames
|
|
|
|
val rv64uc = new AssemblyTestSuite("rv64uc", rv64ucNames)(_)
|
|
|
|
|
2016-06-23 01:14:02 +02:00
|
|
|
val rv64ufNames = LinkedHashSet("ldst", "move", "fsgnj", "fcmp", "fcvt", "fcvt_w", "fclass", "fadd", "fdiv", "fmin", "fmadd")
|
|
|
|
val rv64uf = new AssemblyTestSuite("rv64uf", rv64ufNames)(_)
|
|
|
|
val rv64ufNoDiv = new AssemblyTestSuite("rv64uf", rv64ufNames - "fdiv")(_)
|
|
|
|
|
|
|
|
val rv64udNames = rv64ufNames + "structural"
|
|
|
|
val rv64ud = new AssemblyTestSuite("rv64ud", rv64udNames)(_)
|
|
|
|
val rv64udNoDiv = new AssemblyTestSuite("rv64ud", rv64udNames - "fdiv")(_)
|
2015-07-13 23:54:26 +02:00
|
|
|
|
2016-03-11 02:40:21 +01:00
|
|
|
val rv64siNames = rv32siNames
|
2016-06-23 01:14:02 +02:00
|
|
|
val rv64si = new AssemblyTestSuite("rv64si", rv64siNames)(_)
|
2015-07-13 23:54:26 +02:00
|
|
|
|
2016-07-22 20:36:45 +02:00
|
|
|
val rv64miNames = rv32miNames + "breakpoint"
|
2016-06-23 01:14:02 +02:00
|
|
|
val rv64mi = new AssemblyTestSuite("rv64mi", rv64miNames)(_)
|
2015-07-13 23:54:26 +02:00
|
|
|
|
2016-05-04 02:11:25 +02:00
|
|
|
val groundtestNames = LinkedHashSet("simple")
|
2016-06-23 01:14:02 +02:00
|
|
|
val groundtest64 = new AssemblyTestSuite("rv64ui", groundtestNames)(_)
|
|
|
|
val groundtest32 = new AssemblyTestSuite("rv32ui", groundtestNames)(_)
|
2016-05-03 03:34:27 +02:00
|
|
|
|
2015-07-13 23:54:26 +02:00
|
|
|
// TODO: "rv64ui-pm-lrsc", "rv64mi-pm-ipi",
|
|
|
|
|
2016-05-25 20:08:11 +02:00
|
|
|
val rv64u = List(rv64ui, rv64um)
|
2015-07-14 03:56:18 +02:00
|
|
|
val rv64i = List(rv64ui, rv64si, rv64mi)
|
2016-07-22 20:36:45 +02:00
|
|
|
val rv64pi = List(rv64ui, rv64mi)
|
2015-07-13 23:54:26 +02:00
|
|
|
|
2016-07-30 01:36:07 +02:00
|
|
|
val benchmarks = new BenchmarkTestSuite("rvi", "$(RISCV)/riscv64-unknown-elf/share/riscv-tests/benchmarks", LinkedHashSet(
|
2016-07-08 04:34:03 +02:00
|
|
|
"median", "multiply", "qsort", "towers", "vvadd", "dhrystone", "mt-matmul"))
|
|
|
|
|
2016-07-30 01:36:07 +02:00
|
|
|
val rv32udBenchmarks = new BenchmarkTestSuite("rvd", "$(RISCV)/riscv64-unknown-elf/share/riscv-tests/benchmarks", LinkedHashSet(
|
2016-07-08 04:34:03 +02:00
|
|
|
"mm", "spmv", "mt-vvadd"))
|
2015-07-13 23:54:26 +02:00
|
|
|
|
2016-05-03 03:34:27 +02:00
|
|
|
val emptyBmarks = new BenchmarkTestSuite("empty",
|
2016-05-04 02:11:25 +02:00
|
|
|
"$(RISCV)/riscv64-unknown-elf/share/riscv-tests/benchmarks", LinkedHashSet.empty)
|
2016-05-03 03:34:27 +02:00
|
|
|
|
2016-02-23 19:57:46 +01:00
|
|
|
val mtBmarks = new BenchmarkTestSuite("mt", "$(RISCV)/riscv64-unknown-elf/share/riscv-tests/mt",
|
2015-09-12 03:36:04 +02:00
|
|
|
LinkedHashSet(((0 to 4).map("vvadd"+_) ++
|
2015-07-13 23:54:26 +02:00
|
|
|
List("ad","ae","af","ag","ai","ak","al","am","an","ap","aq","ar","at","av","ay","az",
|
|
|
|
"bb","bc","bf","bh","bj","bk","bm","bo","br","bs","ce","cf","cg","ci","ck","cl",
|
2015-09-12 03:36:04 +02:00
|
|
|
"cm","cs","cv","cy","dc","df","dm","do","dr","ds","du","dv").map(_+"_matmul")): _*))
|
2015-07-13 23:54:26 +02:00
|
|
|
}
|
2015-07-22 20:49:10 +02:00
|
|
|
|
2016-08-01 03:04:56 +02:00
|
|
|
object TestGenerator extends App {
|
2015-10-22 03:23:58 +02:00
|
|
|
val projectName = args(0)
|
|
|
|
val topModuleName = args(1)
|
|
|
|
val configClassName = args(2)
|
2016-08-01 23:24:16 +02:00
|
|
|
|
|
|
|
val aggregateConfigs = configClassName.split('_').reverse
|
|
|
|
|
|
|
|
var finalConfig = new Config()
|
|
|
|
var ii = 0;
|
|
|
|
for (ii <- 0 to (aggregateConfigs.length - 1)) {
|
|
|
|
val currentConfigName = aggregateConfigs(ii);
|
|
|
|
val currentConfig = try {
|
|
|
|
Class.forName(s"$projectName.$currentConfigName").newInstance.asInstanceOf[Config]
|
2015-10-22 03:23:58 +02:00
|
|
|
} catch {
|
|
|
|
case e: java.lang.ClassNotFoundException =>
|
2016-08-01 23:24:16 +02:00
|
|
|
throwException("Unable to find part \"" + currentConfigName +
|
|
|
|
"\" of configClassName \"" + configClassName +
|
|
|
|
"\", did you misspell it?", e)
|
2015-10-22 03:23:58 +02:00
|
|
|
}
|
2016-08-01 23:24:16 +02:00
|
|
|
finalConfig = currentConfig ++ finalConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
val world = (new Config(finalConfig)).toInstance
|
|
|
|
|
2015-10-23 02:25:38 +02:00
|
|
|
val paramsFromConfig: Parameters = Parameters.root(world)
|
2015-10-22 03:23:58 +02:00
|
|
|
|
|
|
|
val gen = () =>
|
|
|
|
Class.forName(s"$projectName.$topModuleName")
|
|
|
|
.getConstructor(classOf[cde.Parameters])
|
|
|
|
.newInstance(paramsFromConfig)
|
|
|
|
.asInstanceOf[Module]
|
|
|
|
|
|
|
|
chiselMain.run(args.drop(3), gen)
|
|
|
|
//Driver.elaborate(gen, configName = configClassName)
|
|
|
|
|
|
|
|
TestGeneration.generateMakefrag(topModuleName, configClassName)
|
2015-11-03 05:10:10 +01:00
|
|
|
TestBenchGeneration.generateVerilogFragment(
|
2016-05-10 09:27:31 +02:00
|
|
|
topModuleName, configClassName, paramsFromConfig)
|
2015-11-03 05:10:10 +01:00
|
|
|
TestBenchGeneration.generateCPPFragment(
|
2016-05-10 09:27:31 +02:00
|
|
|
topModuleName, configClassName, paramsFromConfig)
|
2015-10-22 03:23:58 +02:00
|
|
|
|
2016-08-01 03:04:56 +02:00
|
|
|
val pdFile = TestGeneration.createOutputFile(s"$topModuleName.$configClassName.prm")
|
2015-10-22 03:23:58 +02:00
|
|
|
pdFile.write(ParameterDump.getDump)
|
|
|
|
pdFile.close
|
2016-08-01 03:04:56 +02:00
|
|
|
val v = TestGeneration.createOutputFile(configClassName + ".knb")
|
2015-10-23 02:25:38 +02:00
|
|
|
v.write(world.getKnobs)
|
|
|
|
v.close
|
2016-03-15 02:03:33 +01:00
|
|
|
val d = new java.io.FileOutputStream(Driver.targetDir + "/" + configClassName + ".cfg")
|
|
|
|
d.write(paramsFromConfig(ConfigString))
|
2015-11-26 06:10:09 +01:00
|
|
|
d.close
|
2016-08-01 03:04:56 +02:00
|
|
|
val w = TestGeneration.createOutputFile(configClassName + ".cst")
|
2015-10-23 02:25:38 +02:00
|
|
|
w.write(world.getConstraints)
|
|
|
|
w.close
|
2015-07-22 20:49:10 +02:00
|
|
|
}
|