Skip to content

Commit ce608a2

Browse files
authored
Add coverage flow (#34)
* [nix] add coverage flow * [ci] output urg report in vcs flow * [readme] update coverage report in readme
1 parent 413b8c0 commit ce608a2

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
ref: ${{ github.event.pull_request.head.sha }}
5757
- name: "Run VCS"
5858
run: |
59-
nix build '.#gcd.vcs.tests.simple-sim' --impure -L
59+
nix build '.#gcd.vcs.tests.simple-sim' --impure -L && cat result/urgReport/asserts.txt
6060
6161
run-verilator:
6262
name: "Run Verilator"

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ It's build script is in `nix/gcd` folder, providing the below attributes:
3737
* [{tb,formal}-]rtl: SystemVerilog generated from the lowered MLIR bytecode
3838
* tb-dpi-lib: DPI library written in Rust for both Verilator and VCS
3939
* verilated[-trace]: C++ simulation executable and libaray generated by Verilator with/without `fst` waveform trace
40-
* vcs[-trace]: C simulation executable compiled by VCS with/without `fsdb` waveform trace
40+
* vcs[-trace]: C simulation executable compiled by VCS with/without `fsdb` waveform trace and `urgReport` (coverage report) would be generated under `gcd-sim-result/result/`
4141
* jg-fpv: Formal Property Verification report generated by JasperGold
4242

4343
To get the corresponding output, developers can use:

templates/chisel/nix/gcd/scripts/vcs-wrapper.sh

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ if ((${VERBOSE:-0})); then
66
set -x
77
fi
88

9+
_LIB=@lib@
910
_DATE_BIN=@dateBin@
1011
_VCS_SIM_BIN=@vcsSimBin@
1112
_VCS_SIM_DAIDIR=@vcsSimDaidir@
1213
_VCS_FHS_ENV=@vcsFhsEnv@
14+
_VCS_COV_DIR=@vcsCovDir@
1315

1416
_NOW=$("$_DATE_BIN" "+%Y-%m-%d-%H-%M-%S")
1517
_GCD_SIM_RESULT_DIR=${GCD_SIM_RESULT_DIR:-"gcd-sim-result"}
@@ -20,23 +22,29 @@ ln -sfn "all/$_NOW" "$_GCD_SIM_RESULT_DIR/result"
2022
cp "$_VCS_SIM_BIN" "$_CURRENT/"
2123
cp -r "$_VCS_SIM_DAIDIR" "$_CURRENT/"
2224

23-
chmod -R +w "$_CURRENT"
25+
if [ -n "$_VCS_COV_DIR" ]; then
26+
cp -vr "$_LIB/$_VCS_COV_DIR" "$_CURRENT/"
27+
_CM_ARG="-cm assert -cm_dir $_CURRENT/$_VCS_COV_DIR"
28+
fi
2429

25-
pushd "$_CURRENT" >/dev/null
30+
chmod -R +w "$_CURRENT"
2631

2732
_emu_name=$(basename "$_VCS_SIM_BIN")
2833
_daidir=$(basename "$_VCS_SIM_DAIDIR")
2934

30-
export LD_LIBRARY_PATH="$PWD/$_daidir:$LD_LIBRARY_PATH"
35+
export LD_LIBRARY_PATH="$_CURRENT/$_daidir:$LD_LIBRARY_PATH"
3136

32-
"$_VCS_FHS_ENV" -c "./$_emu_name $_EXTRA_ARGS" &> >(tee vcs-emu-journal.log)
37+
"$_VCS_FHS_ENV" -c "$_CURRENT/$_emu_name $_CM_ARG $_EXTRA_ARGS" &> >(tee $_CURRENT/vcs-emu-journal.log)
38+
39+
if [ -n "$_VCS_COV_DIR" ]; then
40+
"$_VCS_FHS_ENV" -c "urg -dir "$_CURRENT/$_VCS_COV_DIR" -format text"
41+
cp -vr ./urgReport "$_CURRENT/"
42+
fi
3343

3444
if ((${DATA_ONLY:-0})); then
35-
rm -f "./$_emu_name"
45+
rm -f "$_CURRENT/$_emu_name"
3646
fi
3747

3848
set -e _emu_name _daidir
3949

40-
popd >/dev/null
41-
4250
echo "VCS emulator finished, result saved in $_GCD_SIM_RESULT_DIR/result"

templates/chisel/nix/gcd/vcs.nix

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
, dpi-lib
99
, vcs-fhs-env
1010
, runCommand
11+
, enableCover ? true
1112
}:
1213

1314
let
1415
binName = "gcd-vcs-simulator";
16+
coverageName = "coverage.vdb";
1517
in
1618
stdenv.mkDerivation (finalAttr: {
1719
name = "vcs";
@@ -41,10 +43,15 @@ stdenv.mkDerivation (finalAttr: {
4143
${
4244
lib.optionalString dpi-lib.enable-trace ''
4345
-debug_access+pp+dmptf+thread \
44-
-kdb=common_elab,hgldd_all''
46+
-kdb=common_elab,hgldd_all \
47+
-assert enable_diag ''
48+
} \
49+
${
50+
lib.optionalString enableCover ''
51+
-cm line+cond+fsm+tgl+branch+assert \
52+
-cm_dir ${coverageName} ''
4553
} \
4654
-file filelist.f \
47-
-assert enable_diag \
4855
${dpi-lib}/lib/${dpi-lib.libOutName} \
4956
-o ${binName}
5057
@@ -79,11 +86,18 @@ stdenv.mkDerivation (finalAttr: {
7986
cp ${binName} $out/lib
8087
cp -r ${binName}.daidir $out/lib
8188
89+
${
90+
lib.optionalString enableCover ''
91+
cp -r ${coverageName} $out/lib''
92+
} \
93+
8294
substitute ${./scripts/vcs-wrapper.sh} $out/bin/${binName} \
95+
--subst-var-by lib "$out/lib" \
8396
--subst-var-by shell "${bash}/bin/bash" \
8497
--subst-var-by dateBin "$(command -v date)" \
8598
--subst-var-by vcsSimBin "$out/lib/${binName}" \
8699
--subst-var-by vcsSimDaidir "$out/lib/${binName}.daidir" \
100+
--subst-var-by vcsCovDir "${lib.optionalString enableCover "${coverageName}"}" \
87101
--subst-var-by vcsFhsEnv "${vcs-fhs-env}/bin/vcs-fhs-env"
88102
chmod +x $out/bin/${binName}
89103

0 commit comments

Comments
 (0)