Skip to content

Commit

Permalink
[nix] add coverage option to collect line/toggle coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Clo91eaf <[email protected]>
  • Loading branch information
Clo91eaf committed Jan 8, 2025
1 parent c96be5a commit 3497df8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
3 changes: 2 additions & 1 deletion nix/t1/conversion/sv-to-vcs-simulator.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
, rtl
, vsrc
, enableCover ? false
, coverType ? null
, enableTrace ? false
, vcsLinkLibs ? [ ]
, topModule ? null
Expand Down Expand Up @@ -48,7 +49,7 @@ stdenv.mkDerivation rec {
]
++ lib.optionals enableCover [
"-cm"
"assert"
coverType
"-cm_dir"
"./cm"
"-assert"
Expand Down
4 changes: 2 additions & 2 deletions nix/t1/run/run-vcs-emu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ stdenvNoCC.mkDerivation (rec {
]
++ lib.optionals emulator.enableCover [
"-cm"
"assert"
"line+tgl+assert"
"-assert"
"hier=${testCase}/${testCase.pname}.cover"
]
Expand Down Expand Up @@ -127,7 +127,7 @@ stdenvNoCC.mkDerivation (rec {
fi
${lib.optionalString emulator.enableCover ''
${snps-fhs-env}/bin/snps-fhs-env -c "urg -dir cm.vdb -format text -metric assert -show summary"
${snps-fhs-env}/bin/snps-fhs-env -c "urg -dir cm.vdb -format text -metric line+tgl+assert -show summary"
# TODO: add a flag to specify 'vdb only generated in ci mode'
cp -vr cm.vdb $out/
cp -vr urgReport $out/
Expand Down
6 changes: 6 additions & 0 deletions nix/t1/t1.nix
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,14 @@ forEachTop (topName: generator: self: {
};
vcs-emu-cover = self.vcs-emu.override {
enableCover = true;
coverType = "assert";
mainProgram = "${topName}-vcs-cover-simulator";
};
vcs-emu-cover-full = self.vcs-emu.override {
enableCover = true;
coverType = "line+cond+fsm+tgl+branch+assert";
mainProgram = "${topName}-vcs-cover-full-simulator";
};
vcs-emu-trace = self.vcs-emu.override {
enableTrace = true;
mainProgram = "${topName}-vcs-trace-simulator";
Expand Down
26 changes: 21 additions & 5 deletions script/emu/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ object Main:
short = 'c',
doc = "configuration name"
) config: Option[String],
@arg(
name = "cover-type",
doc = "Type for coverage, only avaliable in vcs-emu-cover-full, Eg. assert+line+tgl"
) coverType: Option[String] = Some("assert"),
@arg(
name = "verbose",
short = 'v',
Expand Down Expand Up @@ -214,8 +218,9 @@ object Main:
s"No cached emulator selection nor --emu argument was provided"
)

val isTrace = finalEmuType.get.contains("-trace")
val isCover = finalEmuType.get.contains("-cover")
val isTrace = finalEmuType.get.endsWith("-trace")
val isCover = finalEmuType.get.endsWith("-cover")
val isCoverFull = finalEmuType.get.endsWith("-cover-full")

val finalConfig = tryRestoreFromCache("config", config)
if finalConfig.isEmpty then
Expand All @@ -227,6 +232,16 @@ object Main:
s"Using config=${BOLD}${finalConfig.get}${RESET} emulator=${BOLD}${finalEmuType.get}${RESET} case=${BOLD}$caseName${RESET}"
)

// check the arguments of coverage
if isCover && !(coverType.isDefined && coverType.get.equals("assert")) then
Logger.fatal(s"coverType should be defined in assert")
if isCoverFull && !coverType.isDefined then
Logger.fatal(s"coverType should be defined")
if isCover || isCoverFull then
Logger.info(
s"Coverage type is ${BOLD}${coverType.get}${RESET}"
)

val caseElfPath = resolveTestElfPath(finalIp.get, finalConfig.get, caseName, forceX86)
val caseCoverPath = resolveTestCoverPath(finalIp.get, finalConfig.get, caseName, forceX86)
val outputPath = prepareOutputDir(outDir.getOrElse("t1-sim-result"))
Expand All @@ -240,7 +255,7 @@ object Main:
)
++ optionals(timeout.isDefined, Seq(s"+t1_timeout=${timeout.getOrElse("unreachable")}"))
++ optionals(isTrace, Seq(s"+t1_wave_path=${outputPath / "wave.fsdb"}"))
++ optionals(isCover, Seq("-cm", "assert", "-assert", s"hier=${caseCoverPath}"))
++ optionals(isCover || isCoverFull, Seq("-cm", s"${coverType.get}", "-assert", s"hier=${caseCoverPath}"))
++ optionals(!leftOverArguments.isEmpty, leftOverArguments)

if dryRun.value then return
Expand Down Expand Up @@ -297,7 +312,8 @@ object Main:

Logger.info("Driver finished")

if isCover then
// check the output of coverage
if isCover || isCoverFull then
if os.exists(os.pwd / "cm.vdb") then
Logger.info(s"Coverage database saved under ${os.pwd}/cm.vdb")

Expand All @@ -315,7 +331,7 @@ object Main:
"-format",
"text",
"-metric",
"assert",
s"${coverType.get}",
"-show",
"summary"
)
Expand Down

0 comments on commit 3497df8

Please sign in to comment.