From aa5711ce305304fc91471c459251e72f29385553 Mon Sep 17 00:00:00 2001 From: Avimitin Date: Mon, 29 Jul 2024 18:34:15 +0800 Subject: [PATCH] [nix] add derivation for vcs artifacts --- nix/pkgs/vcs-fhs-env.nix | 4 +-- nix/t1/default.nix | 8 ++++-- nix/t1/vcs.nix | 1 + tests/default.nix | 5 ++-- tests/make-emu-result.nix | 58 +++++++++++++++++++++++++++++++-------- 5 files changed, 56 insertions(+), 20 deletions(-) diff --git a/nix/pkgs/vcs-fhs-env.nix b/nix/pkgs/vcs-fhs-env.nix index cb991aedf3..8176b3696f 100644 --- a/nix/pkgs/vcs-fhs-env.nix +++ b/nix/pkgs/vcs-fhs-env.nix @@ -6,8 +6,8 @@ buildFHSEnv { name = "vcs-fhs-env"; profile = '' - [ ! -d "${vcStaticHome}" ] && echo "VC HOME not set" && exit 1 - [ -z "${snpslmdLicenseFile}" ] && echo "SNPS LICENSE not set" && exit 1 + [ ! -d "${vcStaticHome}" ] && echo "env VC_STATIC_HOME not set" && exit 1 + [ -z "${snpslmdLicenseFile}" ] && echo "env SNPS LICENSE not set" && exit 1 export VC_STATIC_HOME=${vcStaticHome} export TCL_TZ=UTC diff --git a/nix/t1/default.nix b/nix/t1/default.nix index 873db7ac3c..4812c2aa10 100644 --- a/nix/t1/default.nix +++ b/nix/t1/default.nix @@ -51,7 +51,9 @@ lib.makeScope newScope elaborateConfigJson = configPath; elaborateConfig = builtins.fromJSON (lib.readFile configPath); - cases = innerSelf.callPackage ../../tests { verilator-emu = ip.verilator-emu; verilator-emu-trace = ip.verilator-emu-trace; }; + cases = innerSelf.callPackage ../../tests { + inherit (ip) verilator-emu verilator-emu-trace vcs-emu-trace; + }; # for the convenience to use x86 cases on non-x86 machines, avoiding the extra build time cases-x86 = @@ -117,8 +119,8 @@ lib.makeScope newScope }; vcs-dpi-lib = innerSelf.callPackage ../../difftest/online_vcs { }; vcs-dpi-lib-trace = vcs-dpi-lib.override { enable-trace = true; }; - vcs-emu-compiled = innerSelf.callPackage ./vcs.nix { inherit vcs-dpi-lib; rtl = vcs-emu-rtl; }; - vcs-emu-compiled-trace = innerSelf.callPackage ./vcs.nix { vcs-dpi-lib = vcs-dpi-lib-trace; rtl = vcs-emu-rtl; }; + vcs-emu = innerSelf.callPackage ./vcs.nix { inherit vcs-dpi-lib; rtl = vcs-emu-rtl; }; + vcs-emu-trace = innerSelf.callPackage ./vcs.nix { vcs-dpi-lib = vcs-dpi-lib-trace; rtl = vcs-emu-rtl; }; }; subsystem = rec { diff --git a/nix/t1/vcs.nix b/nix/t1/vcs.nix index d348ec9059..c2a681960b 100644 --- a/nix/t1/vcs.nix +++ b/nix/t1/vcs.nix @@ -39,6 +39,7 @@ stdenv.mkDerivation { passthru = { inherit (vcs-dpi-lib) enable-trace; + inherit vcs-fhs-env; }; shellHook = '' diff --git a/tests/default.nix b/tests/default.nix index 009a9be32a..83e5873ce5 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -6,6 +6,7 @@ , runCommand , verilator-emu , verilator-emu-trace +, vcs-emu-trace }: let @@ -20,7 +21,7 @@ let scope = lib.recurseIntoAttrs (lib.makeScope newScope (casesSelf: { recurseForDerivations = true; - inherit verilator-emu verilator-emu-trace; + inherit xLen vLen isFp verilator-emu verilator-emu-trace vcs-emu-trace; makeEmuResult = casesSelf.callPackage ./make-emu-result.nix { }; @@ -48,8 +49,6 @@ let stdenv = rv32-stdenv; - inherit xLen vLen isFp; - mlir = casesSelf.callPackage ./mlir { }; intrinsic = casesSelf.callPackage ./intrinsic { }; asm = casesSelf.callPackage ./asm { }; diff --git a/tests/make-emu-result.nix b/tests/make-emu-result.nix index 129de6c0fa..4ed30552e9 100644 --- a/tests/make-emu-result.nix +++ b/tests/make-emu-result.nix @@ -5,6 +5,7 @@ , zstd , verilator-emu , verilator-emu-trace +, vcs-emu-trace , elaborateConfigJson }: @@ -28,6 +29,7 @@ let "--log-level" "ERROR" ]; + rtlEventOutPath = "${placeholder "out"}/${testCase.pname}-rtl-event.jsonl"; buildPhase = '' runHook preBuild @@ -36,7 +38,7 @@ let echo "[nix] Running test case ${testCase.pname} with args $difftestArgs" - RUST_BACKTRACE=full "$difftestDriver" $difftestArgs 2> $out/rtl-event.jsonl + RUST_BACKTRACE=full "$difftestDriver" $difftestArgs 2> "$rtlEventOutPath" echo "[nix] online driver done" @@ -47,15 +49,15 @@ let checkPhase = '' runHook preCheck - if [ ! -r $out/rtl-event.jsonl ]; then - echo -e "[nix] \033[0;31mInternal Error\033[0m: no rtl-event.jsonl found in output" + if [ ! -r "$rtlEventOutPath" ]; then + echo -e "[nix] \033[0;31mInternal Error\033[0m: no $rtlEventOutPath found in output" exit 1 fi - if ! jq --stream -c -e '.[]' "$out/rtl-event.jsonl" >/dev/null 2>&1; then - echo -e "[nix] \033[0;31mInternal Error\033[0m: invalid JSON file rtl-event.jsonl, showing original file:" + if ! jq --stream -c -e '.[]' "$rtlEventOutPath" >/dev/null 2>&1; then + echo -e "[nix] \033[0;31mInternal Error\033[0m: invalid JSON file $rtlEventOutPath, showing original file:" echo "--------------------------------------------" - cat $out/rtl-event.jsonl + cat $rtlEventOutPath echo "--------------------------------------------" exit 1 fi @@ -67,17 +69,20 @@ let runHook preInstall echo "[nix] compressing event log" - zstd $out/rtl-event.jsonl -o $out/rtl-event.jsonl.zstd - rm $out/rtl-event.jsonl + zstd $rtlEventOutPath -o $rtlEventOutPath.zstd + rm $rtlEventOutPath - mv perf.txt $out/ + if [ -r perf.txt ]; then + mv perf.txt $out/ + fi runHook postInstall ''; passthru.with-trace = self.overrideAttrs (old: { - difftestDriver = "${verilator-emu-trace}/bin/online_drive"; - difftestArgs = old.difftestArgs ++ [ "--wave-path" "${placeholder "out"}/wave.fst" ]; + name = old.name + "-with-trace"; + emuDriver = "${verilator-emu-trace}/bin/online_drive"; + emuDriverArgs = old.emuDriverArgs ++ [ "--wave-path" "${placeholder "out"}/wave.fst" ]; postCheck = '' if [ ! -r "$out/wave.fst" ]; then echo -e "[nix] \033[0;31mInternal Error\033[0m: waveform not found in output" @@ -87,16 +92,45 @@ let }); passthru.with-offline = self.overrideAttrs (old: { + name = old.name + "-with-offline"; preInstall = '' set +e "${verilator-emu}/bin/offline" \ --elf-file ${testCase}/bin/${testCase.pname}.elf \ - --log-file $out/rtl-event.jsonl \ + --log-file $rtlEventOutPath \ --log-level ERROR &> $out/offline-check-journal printf "$?" > $out/offline-check-status set -e ''; }); + + passthru.with-vcs = self.overrideAttrs (old: { + name = old.name + "-with-vcs"; + __noChroot = true; + buildPhase = '' + runHook preBuild + + mkdir -p "$out" + echo "[nix] Running VCS for ${testCase.pname}" + + RUST_BACKTRACE=full "${vcs-emu-trace}/bin/t1-vcs-simulator" \ + --elf-file ${testCase}/bin/${testCase.pname}.elf \ + --wave-path ${testCase.pname}.fsdb \ + 1> /dev/null \ + 2> $rtlEventOutPath + + echo "[nix] VCS emu done" + + runHook postBuild + ''; + + postInstall = '' + # VCS have weird behavior on file creation, it will report read-only filesystem on our output, + # while other tools can mutate file system correctly. + cp ${testCase.pname}.fsdb "$out" + cp -r ${vcs-emu-trace}/lib/t1-vcs-simulator.daidir "$out" + ''; + }); }; in self