-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nix] add checkPhase for emu-result derivation
This commit add jq as dependencies to check each line of the rtl event is valid JSON or not. Signed-off-by: Avimitin <[email protected]>
- Loading branch information
Showing
1 changed file
with
79 additions
and
39 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,48 +1,88 @@ | ||
# CallPackage args | ||
{ runCommand | ||
{ stdenvNoCC | ||
, jq | ||
, zstd | ||
, t1-helper | ||
, ip-emu | ||
, difftest | ||
, elaborateConfigJson | ||
}: | ||
|
||
# makeEmuResult arg | ||
testCase: | ||
|
||
runCommand "get-${testCase.pname}-emu-result" { nativeBuildInputs = [ zstd ]; } '' | ||
echo "[nix] Running test case ${testCase.pname}" | ||
mkdir -p "$out" | ||
set +e | ||
${t1-helper}/bin/t1-helper \ | ||
"ipemu" \ | ||
--emulator-path ${ip-emu}/bin/emulator \ | ||
--config ${elaborateConfigJson} \ | ||
--case ${testCase}/bin/${testCase.pname}.elf \ | ||
--no-console-logging \ | ||
--with-file-logging \ | ||
--emulator-log-level "FATAL" \ | ||
--emulator-log-file-path "$out/emu.log" \ | ||
--out-dir $out &> $out/emu-wrapper.journal | ||
if (( $? )); then | ||
printf "0" > $out/emu-success | ||
else | ||
printf "1" > $out/emu-success | ||
fi | ||
if [ ! -r $out/rtl-event.log ]; then | ||
echo "[nix] no rtl-event.log found in output" | ||
echo "[nix] showing helper journal and exit" | ||
echo | ||
cat $out/emu-wrapper.journal | ||
exit 1 | ||
fi | ||
echo "[nix] compressing event log" | ||
zstd $out/rtl-event.log -o $out/rtl-event.log.zstd | ||
rm $out/rtl-event.log | ||
echo "[nix] emu done" | ||
'' | ||
stdenvNoCC.mkDerivation { | ||
name = "${testCase.pname}-emu-result"; | ||
|
||
nativeBuildInputs = [ zstd jq ]; | ||
|
||
dontUnpack = true; | ||
|
||
buildPhase = '' | ||
runHook preBuild | ||
mkdir -p "$out" | ||
echo "[nix] Running test case ${testCase.pname}" | ||
set +e | ||
${t1-helper}/bin/t1-helper \ | ||
"ipemu" \ | ||
--emulator-path ${difftest}/bin/online_drive \ | ||
--config ${elaborateConfigJson} \ | ||
--case ${testCase}/bin/${testCase.pname}.elf \ | ||
--emulator-log-level "ERROR" \ | ||
--emulator-log-file-path "$out/emu.log" \ | ||
--out-dir $out &> $out/emu.journal | ||
if (( $? )); then | ||
printf "0" > $out/emu-success | ||
else | ||
printf "1" > $out/emu-success | ||
fi | ||
set -e | ||
echo "[nix] emu done" | ||
runHook postBuild | ||
''; | ||
|
||
doCheck = true; | ||
checkPhase = '' | ||
runHook preCheck | ||
if [ ! -r $out/rtl-event.jsonl ]; then | ||
echo -e "[nix] \033[0;31mInternal Error\033[0m: Internal Error: no rtl-event.jsonl found in output" | ||
echo | ||
cat $out/emu.journal | ||
exit 1 | ||
fi | ||
lineNum=1 | ||
while IFS= read -r rawJson; do | ||
if ! echo "$rawJson" | jq -e . >/dev/null 2>&1; then | ||
echo -e "[nix] \033[0;31mInternal Error\033[0m: invalid JSON on line $lineNum in file rtl-event.jsonl" | ||
echo "--------------------------------------------" | ||
echo -e "[nix] \033[0;31mInternal Error\033[0m: Showing original rtl-event.jsonl file:" | ||
cat $out/rtl-event.jsonl | ||
echo "--------------------------------------------" | ||
echo -e "[nix] \033[0;31mInternal Error\033[0m: Showing build log" | ||
cat $out/emu.journal | ||
echo "--------------------------------------------" | ||
exit 1 | ||
fi | ||
lineNum=$((lineNum + 1)) | ||
done < "$out/rtl-event.jsonl" | ||
runHook postCheck | ||
''; | ||
|
||
installPhase = '' | ||
runHook preInstall | ||
echo "[nix] compressing event log" | ||
zstd $out/rtl-event.jsonl -o $out/rtl-event.jsonl.zstd | ||
rm $out/rtl-event.jsonl | ||
runHook postInstall | ||
''; | ||
} |