Skip to content

Commit

Permalink
[nix] add cover flow support, wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Clo91eaf committed Oct 3, 2024
1 parent 0f84e26 commit 6c992ff
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
12 changes: 10 additions & 2 deletions nix/t1/conversion/sv-to-vcs-simulator.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{ mainProgram
, rtl
, enableTrace ? false
, enableCover ? false
, vcsLinkLibs ? [ ]
}:

Expand Down Expand Up @@ -35,9 +36,16 @@ stdenv.mkDerivation rec {
"+define+T1_ENABLE_TRACE"
"-debug_access+pp+dmptf+thread"
"-kdb=common_elab,hgldd_all"
] ++ [
]
++ lib.optionals (enableCover) [
"-cm"
"line+cond+fsm+tgl+branch+assert"
"-cm_dir"
"/tmp/cm"
"./cm"
]
++ lib.optionals (!enableCover) [
"-assert"
"disable_cover"
]
++ vcsLinkLibs;

Expand Down
2 changes: 2 additions & 0 deletions nix/t1/run/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
, verilator-emu-trace
, vcs-emu
, vcs-emu-trace
, vcs-emu-trace-cover
, cases
, configName
}:
Expand All @@ -31,6 +32,7 @@ let
verilator-emu-trace = runVerilatorEmu verilator-emu-trace case;
vcs-emu = runVCSEmu vcs-emu case;
vcs-emu-trace = runVCSEmu vcs-emu-trace case;
vcs-emu-trace-cover = runVCSEmu vcs-emu-trace-cover case;
};
in
# Now we have { caseName = "hello", case = <derivation> }
Expand Down
6 changes: 5 additions & 1 deletion nix/t1/run/run-vcs-emu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ emulator:
testCase:

stdenvNoCC.mkDerivation (finalAttr: {
name = "${testCase.pname}-vcs-result" + (lib.optionalString emulator.enableTrace "-trace");
name = "${testCase.pname}-vcs-result" + (lib.optionalString emulator.enableTrace "-trace") + (lib.optionalString emulator.enableCover "-cover");
nativeBuildInputs = [ zstd jq ];
__noChroot = true;

Expand Down Expand Up @@ -82,5 +82,9 @@ stdenvNoCC.mkDerivation (finalAttr: {
cp -v ${testCase.pname}.fsdb "$out"
cp -vr ${emulator}/lib/${emulator.mainProgram}.daidir "$out"
''}
${lib.optionalString emulator.enableCover ''
cp -vr cm.vdb "$out"
''}
'';
})
7 changes: 7 additions & 0 deletions nix/t1/t1.nix
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ lib.mapAttrs
enableTrace = true;
vcsLinkLibs = [ "${ipScope.vcs-dpi-lib-trace}/lib/libdpi_t1.a" ];
};
vcs-emu-trace-cover = t1Scope.sv-to-vcs-simulator {
mainProgram = "t1-vcs-trace-cover-simulator";
rtl = ipScope.emu-rtl;
enableTrace = true;
enableCover = true;
vcsLinkLibs = [ "${ipScope.vcs-dpi-lib-trace}/lib/libdpi_t1.a" ];
};

run = ipScope.callPackage ./run { };
}); # end of ipScope
Expand Down
13 changes: 11 additions & 2 deletions script/emu/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ object Main:
s"No cached emulator selection nor --emu argument was provided"
)

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

val finalConfig = tryRestoreFromCache("config", config)
if finalConfig.isEmpty then
Expand All @@ -204,6 +205,7 @@ object Main:
s"+t1_elf_file=${caseElfPath}"
)
++ optionals(isTrace, Seq(s"+t1_wave_path=${outputPath / "wave.fsdb"}"))
++ optionals(isCover, Seq(s"-cm line+cond+fsm+tgl+branch+assert"))
++ optionals(!leftOverArguments.isEmpty, leftOverArguments)

if dryRun.value then return
Expand All @@ -225,7 +227,7 @@ object Main:
)

// For vcs trace simulator, we need daidir keep at same directory as the wave.fsdb file
if finalEmuType.get == "vcs-emu-trace" then
if finalEmuType.get == "vcs-emu-trace" || finalEmuType.get == "vcs-emu-trace-cover" then
val libPath = emulator / os.up / os.up / "lib"
val daidirPath =
os.walk(libPath)
Expand Down Expand Up @@ -259,6 +261,13 @@ object Main:

Logger.info("Driver finished")

if isCover then
if os.exists(os.pwd / "cm.vdb") then
os.move(os.pwd / "cm.vdb", outputPath / "cm.vdb", replaceExisting = true)
Logger.info(s"Coverage database saved under ${outputPath}/cm.vdb")
else
Logger.error("No cm.vdb found")

if os.exists(os.pwd / "perf.json") then
os.move(os.pwd / "perf.json", outputPath / "perf.json", replaceExisting = true)

Expand Down

0 comments on commit 6c992ff

Please sign in to comment.