From 3497df8a11d5987a20891cfa2a37a78d5853f878 Mon Sep 17 00:00:00 2001 From: Clo91eaf Date: Thu, 9 Jan 2025 01:26:50 +0800 Subject: [PATCH] [nix] add coverage option to collect line/toggle coverage Signed-off-by: Clo91eaf --- nix/t1/conversion/sv-to-vcs-simulator.nix | 3 ++- nix/t1/run/run-vcs-emu.nix | 4 ++-- nix/t1/t1.nix | 6 ++++++ script/emu/src/Main.scala | 26 ++++++++++++++++++----- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/nix/t1/conversion/sv-to-vcs-simulator.nix b/nix/t1/conversion/sv-to-vcs-simulator.nix index c679284e91..f52803a355 100644 --- a/nix/t1/conversion/sv-to-vcs-simulator.nix +++ b/nix/t1/conversion/sv-to-vcs-simulator.nix @@ -8,6 +8,7 @@ , rtl , vsrc , enableCover ? false +, coverType ? null , enableTrace ? false , vcsLinkLibs ? [ ] , topModule ? null @@ -48,7 +49,7 @@ stdenv.mkDerivation rec { ] ++ lib.optionals enableCover [ "-cm" - "assert" + coverType "-cm_dir" "./cm" "-assert" diff --git a/nix/t1/run/run-vcs-emu.nix b/nix/t1/run/run-vcs-emu.nix index 58617e28c3..85657152f0 100644 --- a/nix/t1/run/run-vcs-emu.nix +++ b/nix/t1/run/run-vcs-emu.nix @@ -48,7 +48,7 @@ stdenvNoCC.mkDerivation (rec { ] ++ lib.optionals emulator.enableCover [ "-cm" - "assert" + "line+tgl+assert" "-assert" "hier=${testCase}/${testCase.pname}.cover" ] @@ -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/ diff --git a/nix/t1/t1.nix b/nix/t1/t1.nix index 35f4fa3179..e10c91cecb 100644 --- a/nix/t1/t1.nix +++ b/nix/t1/t1.nix @@ -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"; diff --git a/script/emu/src/Main.scala b/script/emu/src/Main.scala index a86175cd1e..d1c5784184 100644 --- a/script/emu/src/Main.scala +++ b/script/emu/src/Main.scala @@ -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', @@ -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 @@ -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")) @@ -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 @@ -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") @@ -315,7 +331,7 @@ object Main: "-format", "text", "-metric", - "assert", + s"${coverType.get}", "-show", "summary" )