Skip to content

Commit

Permalink
[nix] add checkPhase for emu-result derivation
Browse files Browse the repository at this point in the history
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
Avimitin committed Jul 8, 2024
1 parent 8da2ff4 commit b190cd1
Showing 1 changed file with 79 additions and 39 deletions.
118 changes: 79 additions & 39 deletions tests/make-emu-result.nix
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
'';
}

0 comments on commit b190cd1

Please sign in to comment.