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 aa5711c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 20 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
58 changes: 46 additions & 12 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 All @@ -28,6 +29,7 @@ let
"--log-level"
"ERROR"
];
rtlEventOutPath = "${placeholder "out"}/${testCase.pname}-rtl-event.jsonl";

buildPhase = ''
runHook preBuild
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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

0 comments on commit aa5711c

Please sign in to comment.