Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nix] add coverage flow for chisel-nix #34

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
ref: ${{ github.event.pull_request.head.sha }}
- name: "Run VCS"
run: |
nix build '.#gcd.vcs.tests.simple-sim' --impure -L
nix build '.#gcd.vcs.tests.simple-sim' --impure -L && cat result/urgReport/asserts.txt

run-verilator:
name: "Run Verilator"
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ It's build script is in `nix/gcd` folder, providing the below attributes:
* [{tb,formal}-]rtl: SystemVerilog generated from the lowered MLIR bytecode
* tb-dpi-lib: DPI library written in Rust for both Verilator and VCS
* verilated[-trace]: C++ simulation executable and libaray generated by Verilator with/without `fst` waveform trace
* vcs[-trace]: C simulation executable compiled by VCS with/without `fsdb` waveform trace
* 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/`
* jg-fpv: Formal Property Verification report generated by JasperGold

To get the corresponding output, developers can use:
Expand Down
22 changes: 15 additions & 7 deletions templates/chisel/nix/gcd/scripts/vcs-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ if ((${VERBOSE:-0})); then
set -x
fi

_LIB=@lib@
_DATE_BIN=@dateBin@
_VCS_SIM_BIN=@vcsSimBin@
_VCS_SIM_DAIDIR=@vcsSimDaidir@
_VCS_FHS_ENV=@vcsFhsEnv@
_VCS_COV_DIR=@vcsCovDir@

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

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

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

_emu_name=$(basename "$_VCS_SIM_BIN")
_daidir=$(basename "$_VCS_SIM_DAIDIR")

export LD_LIBRARY_PATH="$PWD/$_daidir:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="$_CURRENT/$_daidir:$LD_LIBRARY_PATH"

"$_VCS_FHS_ENV" -c "./$_emu_name $_EXTRA_ARGS" &> >(tee vcs-emu-journal.log)
"$_VCS_FHS_ENV" -c "$_CURRENT/$_emu_name $_CM_ARG $_EXTRA_ARGS" &> >(tee $_CURRENT/vcs-emu-journal.log)

if [ -n "$_VCS_COV_DIR" ]; then
"$_VCS_FHS_ENV" -c "urg -dir "$_CURRENT/$_VCS_COV_DIR" -format text"
cp -vr ./urgReport "$_CURRENT/"
fi

if ((${DATA_ONLY:-0})); then
rm -f "./$_emu_name"
rm -f "$_CURRENT/$_emu_name"
fi

set -e _emu_name _daidir

popd >/dev/null

echo "VCS emulator finished, result saved in $_GCD_SIM_RESULT_DIR/result"
18 changes: 16 additions & 2 deletions templates/chisel/nix/gcd/vcs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
, dpi-lib
, vcs-fhs-env
, runCommand
, enableCover ? true
}:

let
binName = "gcd-vcs-simulator";
coverageName = "coverage.vdb";
in
stdenv.mkDerivation (finalAttr: {
name = "vcs";
Expand Down Expand Up @@ -41,10 +43,15 @@ stdenv.mkDerivation (finalAttr: {
${
lib.optionalString dpi-lib.enable-trace ''
-debug_access+pp+dmptf+thread \
-kdb=common_elab,hgldd_all''
-kdb=common_elab,hgldd_all \
-assert enable_diag ''
} \
${
lib.optionalString enableCover ''
-cm line+cond+fsm+tgl+branch+assert \
-cm_dir ${coverageName} ''
} \
-file filelist.f \
-assert enable_diag \
${dpi-lib}/lib/${dpi-lib.libOutName} \
-o ${binName}

Expand Down Expand Up @@ -79,11 +86,18 @@ stdenv.mkDerivation (finalAttr: {
cp ${binName} $out/lib
cp -r ${binName}.daidir $out/lib

${
lib.optionalString enableCover ''
cp -r ${coverageName} $out/lib''
} \

substitute ${./scripts/vcs-wrapper.sh} $out/bin/${binName} \
--subst-var-by lib "$out/lib" \
--subst-var-by shell "${bash}/bin/bash" \
--subst-var-by dateBin "$(command -v date)" \
--subst-var-by vcsSimBin "$out/lib/${binName}" \
--subst-var-by vcsSimDaidir "$out/lib/${binName}.daidir" \
--subst-var-by vcsCovDir "${lib.optionalString enableCover "${coverageName}"}" \
--subst-var-by vcsFhsEnv "${vcs-fhs-env}/bin/vcs-fhs-env"
chmod +x $out/bin/${binName}

Expand Down