Skip to content

Commit

Permalink
[nix] add derivation for vcs artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
Avimitin committed Jul 29, 2024
1 parent 071779c commit 027fbd6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
4 changes: 2 additions & 2 deletions nix/pkgs/vcs-fhs-env.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions nix/t1/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions nix/t1/vcs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ stdenv.mkDerivation {

passthru = {
inherit (vcs-dpi-lib) enable-trace;
inherit vcs-fhs-env;
};

shellHook = ''
Expand Down
5 changes: 2 additions & 3 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
, runCommand
, verilator-emu
, verilator-emu-trace
, vcs-emu-trace
}:

let
Expand All @@ -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 { };

Expand Down Expand Up @@ -48,8 +49,6 @@ let

stdenv = rv32-stdenv;

inherit xLen vLen isFp;

mlir = casesSelf.callPackage ./mlir { };
intrinsic = casesSelf.callPackage ./intrinsic { };
asm = casesSelf.callPackage ./asm { };
Expand Down
38 changes: 35 additions & 3 deletions tests/make-emu-result.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
, zstd
, verilator-emu
, verilator-emu-trace
, vcs-emu-trace
, elaborateConfigJson
}:

Expand Down Expand Up @@ -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"
Expand All @@ -87,6 +91,7 @@ let
});

passthru.with-offline = self.overrideAttrs (old: {
name = old.name + "-with-offline";
preInstall = ''
set +e
"${verilator-emu}/bin/offline" \
Expand All @@ -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

0 comments on commit 027fbd6

Please sign in to comment.