-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nix] expose 'with-offline-trace-log' attr for debugging
Signed-off-by: Avimitin <[email protected]>
- Loading branch information
Showing
4 changed files
with
303 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,92 @@ | ||
{ lib, runCommand, zstd, jq }: | ||
{ lib, zstd, jq, stdenvNoCC }: | ||
emulator: | ||
testCase: | ||
|
||
runCommand "run-${emulator.name}-for-${testCase.pname}" | ||
{ | ||
stdenvNoCC.mkDerivation (finalAttr: { | ||
name = "${testCase.pname}-emu-result" + (lib.optionalString emulator.enable-trace "-trace"); | ||
nativeBuildInputs = [ zstd jq ]; | ||
} '' | ||
mkdir -p "$out" | ||
|
||
emuDriverArgsArray=( | ||
"--elf-file" | ||
"${testCase}/bin/${testCase.pname}.elf" | ||
"--log-file" | ||
"$out/emu.log" | ||
"--log-level" | ||
"ERROR" | ||
${lib.optionalString emulator.enable-trace "--wave-path"} | ||
${lib.optionalString emulator.enable-trace "$out/wave.fst"} | ||
) | ||
emuDriverArgs="''${emuDriverArgsArray[@]}" | ||
emuDriver="${emulator}/bin/online_drive" | ||
offlineLogLevel = "ERROR"; | ||
passthru.with-offline-trace-log = finalAttr.finalPackage.overrideAttrs { offlineLogLevel = "TRACE"; }; | ||
|
||
rtlEventOutPath="$out/${testCase.pname}-rtl-event.jsonl" | ||
buildCommand = '' | ||
mkdir -p "$out" | ||
echo "[nix] Running test case ${testCase.pname} with args $emuDriverArgs" | ||
emuDriverArgsArray=( | ||
"--elf-file" | ||
"${testCase}/bin/${testCase.pname}.elf" | ||
"--log-file" | ||
"$out/emu.log" | ||
"--log-level" | ||
"ERROR" | ||
${lib.optionalString emulator.enable-trace "--wave-path"} | ||
${lib.optionalString emulator.enable-trace "$out/wave.fst"} | ||
) | ||
emuDriverArgs="''${emuDriverArgsArray[@]}" | ||
emuDriver="${emulator}/bin/online_drive" | ||
export RUST_BACKTRACE=full | ||
if ! "$emuDriver" $emuDriverArgs 2> "$rtlEventOutPath"; then | ||
echo -e "\033[0;31m[nix]\033[0m: online driver run failed" | ||
cat $rtlEventOutPath | ||
echo -e "\033[0;31m[nix]\033[0m: Try rerun with '\033[0;34m$emuDriver $emuDriverArgs\033[0m'" | ||
exit 1 | ||
fi | ||
rtlEventOutPath="$out/${testCase.pname}-rtl-event.jsonl" | ||
echo "[nix] online driver run done" | ||
echo -e "[nix] Running test case ${testCase.pname} with args \033[0;34m$emuDriverArgs\033[0m" | ||
if [ ! -r "$rtlEventOutPath" ]; then | ||
echo -e "[nix] \033[0;31mInternal Error\033[0m: no $rtlEventOutPath found in output" | ||
exit 1 | ||
fi | ||
export RUST_BACKTRACE=full | ||
if ! "$emuDriver" $emuDriverArgs 2> "$rtlEventOutPath"; then | ||
echo -e "\033[0;31m[nix]\033[0m: online driver run failed" | ||
cat $rtlEventOutPath | ||
echo -e "\033[0;31m[nix]\033[0m: Try rerun with '\033[0;34m$emuDriver $emuDriverArgs\033[0m'" | ||
exit 1 | ||
fi | ||
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 $rtlEventOutPath | ||
echo "--------------------------------------------" | ||
exit 1 | ||
fi | ||
echo "[nix] online driver run done" | ||
set +e | ||
"${emulator}/bin/offline" \ | ||
--elf-file ${testCase}/bin/${testCase.pname}.elf \ | ||
--log-file $rtlEventOutPath \ | ||
--log-level ERROR &> $out/offline-check-journal | ||
printf "$?" > $out/offline-check-status | ||
if [ "$(cat $out/offline-check-status)" != "0" ]; then | ||
echo "[nix] Offline check FAIL" | ||
else | ||
echo "[nix] Offline check PASS" | ||
fi | ||
set -e | ||
if [ ! -r "$rtlEventOutPath" ]; then | ||
echo -e "[nix] \033[0;31mInternal Error\033[0m: no $rtlEventOutPath found in output" | ||
exit 1 | ||
fi | ||
echo "[nix] compressing event log" | ||
zstd $rtlEventOutPath -o $rtlEventOutPath.zstd | ||
rm $rtlEventOutPath | ||
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 $rtlEventOutPath | ||
echo "--------------------------------------------" | ||
exit 1 | ||
fi | ||
if [ -r perf.txt ]; then | ||
mv perf.txt $out/ | ||
fi | ||
set +e | ||
offlineCheckArgsArray=( | ||
"--elf-file" | ||
"${testCase}/bin/${testCase.pname}.elf" | ||
"--log-file" | ||
"$rtlEventOutPath" | ||
"--log-level" | ||
"$offlineLogLevel" | ||
) | ||
offlineCheckArgs="''${offlineCheckArgsArray[@]}" | ||
echo -e "[nix] running offline check: \033[0;34m${emulator}/bin/offline $offlineCheckArgs\033[0m" | ||
"${emulator}/bin/offline" $offlineCheckArgs &> $TMPDIR/offline-check-journal | ||
tail -n1000 $TMPDIR/offline-check-journal > $out/offline-check-journal | ||
${lib.optionalString emulator.enable-trace '' | ||
if [ ! -r "$out/wave.fst" ]; then | ||
echo -e "[nix] \033[0;31mInternal Error\033[0m: waveform not found in output" | ||
exit 1 | ||
printf "$?" > $out/offline-check-status | ||
if [ "$(cat $out/offline-check-status)" != "0" ]; then | ||
echo "[nix] Offline check FAIL" | ||
else | ||
echo "[nix] Offline check PASS" | ||
fi | ||
''} | ||
'' | ||
set -e | ||
echo "[nix] compressing event log" | ||
zstd $rtlEventOutPath -o $rtlEventOutPath.zstd | ||
rm $rtlEventOutPath | ||
if [ -r perf.txt ]; then | ||
mv perf.txt $out/ | ||
fi | ||
${lib.optionalString emulator.enable-trace '' | ||
if [ ! -r "$out/wave.fst" ]; then | ||
echo -e "[nix] \033[0;31mInternal Error\033[0m: waveform not found in output" | ||
exit 1 | ||
fi | ||
''} | ||
''; | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,89 @@ | ||
# FIXME: we should have offline check for VCS, importing offline check from verilator-emu is weird | ||
{ lib, runCommand, zstd, jq, verilator-emu }: | ||
{ lib, stdenvNoCC, zstd, jq, verilator-emu }: | ||
emulator: | ||
testCase: | ||
|
||
runCommand "run-${emulator.name}-for-${testCase.pname}" | ||
{ | ||
stdenvNoCC.mkDerivation (finalAttr: { | ||
|
||
name = "${testCase.pname}-vcs-result" + (lib.optionalString emulator.enable-trace "-trace"); | ||
nativeBuildInputs = [ zstd jq ]; | ||
__noChroot = true; | ||
} '' | ||
mkdir -p "$out" | ||
emuDriverArgsArray=( | ||
"--elf-file" | ||
"${testCase}/bin/${testCase.pname}.elf" | ||
${lib.optionalString emulator.enable-trace "--wave-path"} | ||
${lib.optionalString emulator.enable-trace "${testCase.pname}.fsdb"} | ||
) | ||
emuDriverArgs="''${emuDriverArgsArray[@]}" | ||
emuDriver="${emulator}/bin/t1-vcs-simulator" | ||
rtlEventOutPath="$out/${testCase.pname}-rtl-event.jsonl" | ||
echo "[nix] Running VCS ${testCase.pname} with args $emuDriverArgs" | ||
export RUST_BACKTRACE=full | ||
if ! "$emuDriver" $emuDriverArgs >/dev/null 2>"$rtlEventOutPath"; then | ||
echo -e "\033[0;31m[nix]\033[0m: online driver run failed" | ||
cat $rtlEventOutPath | ||
echo -e "\033[0;31m[nix]\033[0m: Try rerun with '\033[0;34m$emuDriver $emuDriverArgs\033[0m'" | ||
exit 1 | ||
fi | ||
echo "[nix] VCS run done" | ||
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 '.[]' "$rtlEventOutPath" >/dev/null 2>&1; then | ||
echo -e "[nix] \033[0;31mInternal Error\033[0m: invalid JSON file $rtlEventOutPath, showing original file:" | ||
echo "--------------------------------------------" | ||
cat $rtlEventOutPath | ||
echo "--------------------------------------------" | ||
exit 1 | ||
fi | ||
set +e | ||
"${verilator-emu}/bin/offline" \ | ||
--elf-file ${testCase}/bin/${testCase.pname}.elf \ | ||
--log-file $rtlEventOutPath \ | ||
--log-level ERROR &> $out/offline-check-journal | ||
printf "$?" > $out/offline-check-status | ||
if [ "$(cat $out/offline-check-status)" != "0" ]; then | ||
echo "[nix] Offline check FAIL" | ||
else | ||
echo "[nix] Offline check PASS" | ||
fi | ||
set -e | ||
echo "[nix] compressing event log" | ||
zstd $rtlEventOutPath -o $rtlEventOutPath.zstd | ||
rm $rtlEventOutPath | ||
if [ -r perf.txt ]; then | ||
mv perf.txt $out/ | ||
fi | ||
${lib.optionalString emulator.enable-trace '' | ||
cp -v ${testCase.pname}.fsdb "$out" | ||
cp -vr ${emulator}/lib/t1-vcs-simulator.daidir "$out" | ||
''} | ||
'' | ||
|
||
offlineLogLevel = "ERROR"; | ||
passthru.with-offline-trace-log = finalAttr.finalPackage.overrideAttrs { offlineLogLevel = "TRACE"; }; | ||
|
||
buildCommand = '' | ||
mkdir -p "$out" | ||
emuDriverArgsArray=( | ||
"--elf-file" | ||
"${testCase}/bin/${testCase.pname}.elf" | ||
${lib.optionalString emulator.enable-trace "--wave-path"} | ||
${lib.optionalString emulator.enable-trace "${testCase.pname}.fsdb"} | ||
) | ||
emuDriverArgs="''${emuDriverArgsArray[@]}" | ||
emuDriver="${emulator}/bin/t1-vcs-simulator" | ||
rtlEventOutPath="$out/${testCase.pname}-rtl-event.jsonl" | ||
echo "[nix] Running VCS ${testCase.pname} with args $emuDriverArgs" | ||
export RUST_BACKTRACE=full | ||
if ! "$emuDriver" $emuDriverArgs >/dev/null 2>"$rtlEventOutPath"; then | ||
echo -e "\033[0;31m[nix]\033[0m: online driver run failed" | ||
cat $rtlEventOutPath | ||
echo -e "\033[0;31m[nix]\033[0m: Try rerun with '\033[0;34m$emuDriver $emuDriverArgs\033[0m'" | ||
exit 1 | ||
fi | ||
echo "[nix] VCS run done" | ||
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 '.[]' "$rtlEventOutPath" >/dev/null 2>&1; then | ||
echo -e "[nix] \033[0;31mInternal Error\033[0m: invalid JSON file $rtlEventOutPath, showing original file:" | ||
echo "--------------------------------------------" | ||
cat $rtlEventOutPath | ||
echo "--------------------------------------------" | ||
exit 1 | ||
fi | ||
set +e | ||
offlineCheckArgsArray=( | ||
"--elf-file" | ||
"${testCase}/bin/${testCase.pname}.elf" | ||
"--log-file" | ||
"$rtlEventOutPath" | ||
"--log-level" | ||
"$offlineLogLevel" | ||
) | ||
offlineCheckArgs="''${offlineCheckArgsArray[@]}" | ||
echo -e "[nix] running offline check: \033[0;34m${emulator}/bin/offline $offlineCheckArgs\033[0m" | ||
"${verilator-emu}/bin/offline" $offlineCheckArgs &> $TMPDIR/offline-check-journal | ||
tail -n1000 $TMPDIR/offline-check-journal > $out/offline-check-journal | ||
printf "$?" > $out/offline-check-status | ||
if [ "$(cat $out/offline-check-status)" != "0" ]; then | ||
echo "[nix] Offline check FAIL" | ||
else | ||
echo "[nix] Offline check PASS" | ||
fi | ||
set -e | ||
echo "[nix] compressing event log" | ||
zstd $rtlEventOutPath -o $rtlEventOutPath.zstd | ||
rm $rtlEventOutPath | ||
if [ -r perf.txt ]; then | ||
mv perf.txt $out/ | ||
fi | ||
${lib.optionalString emulator.enable-trace '' | ||
cp -v ${testCase.pname}.fsdb "$out" | ||
cp -vr ${emulator}/lib/t1-vcs-simulator.daidir "$out" | ||
''} | ||
''; | ||
}) |
Oops, something went wrong.