From 027fbd643667378c0d6c69ea40d18c60f38ce8eb 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 | 38 +++++++++++++++++++++++++++++++++++--- 5 files changed, 45 insertions(+), 11 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..f380a36e07 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 }: @@ -70,14 +71,17 @@ let zstd $out/rtl-event.jsonl -o $out/rtl-event.jsonl.zstd rm $out/rtl-event.jsonl - 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,6 +91,7 @@ let }); passthru.with-offline = self.overrideAttrs (old: { + name = old.name + "-with-offline"; preInstall = '' set +e "${verilator-emu}/bin/offline" \ @@ -97,6 +102,33 @@ let 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 $out/${testCase.pname}.fsdb \ + 1> /dev/null \ + 2> $out/rtl-event.jsonl + + echo "[nix] VCS emu done" + + runHook postBuild + ''; + + postInstall = '' + mkdir -p "$out"/share + cp -r ${vcs-emu-trace}/lib/t1-vcs-simulator.daidir "$out"/share/ + ''; + }); }; in self