From 6633830cfd2019db4e0e4618390c1f9ad9a2b764 Mon Sep 17 00:00:00 2001 From: Avimitin Date: Mon, 19 Aug 2024 22:58:28 +0800 Subject: [PATCH] [nix] allow user pass offline log from outside Signed-off-by: Avimitin --- nix/impure.nix | 4 ++++ t1rocketemu/nix/run-emulator.nix | 20 ++++++++++++++++---- t1rocketemu/nix/run-vcs-emulation.nix | 19 +++++++++++++++---- 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 nix/impure.nix diff --git a/nix/impure.nix b/nix/impure.nix new file mode 100644 index 0000000000..019528e1a6 --- /dev/null +++ b/nix/impure.nix @@ -0,0 +1,4 @@ +rec { + t1OfflineLogLevelEnv = builtins.getEnv "T1_OFFLINE_LOG_LEVEL"; + t1OfflineLogLevel = if t1OfflineLogLevelEnv != "" then t1OfflineLogLevelEnv else "ERROR"; +} diff --git a/t1rocketemu/nix/run-emulator.nix b/t1rocketemu/nix/run-emulator.nix index cd2fdfc3ac..ce0ce73fee 100644 --- a/t1rocketemu/nix/run-emulator.nix +++ b/t1rocketemu/nix/run-emulator.nix @@ -2,6 +2,9 @@ emulator: testCase: +let + impureEnvs = import (../../nix/impure.nix); +in runCommand ("${emulator.name}-${testCase.pname}-emu-result" + lib.optionalString emulator.enable-trace "-trace") { nativeBuildInputs = [ zstd jq ]; @@ -49,10 +52,19 @@ runCommand ("${emulator.name}-${testCase.pname}-emu-result" + lib.optionalString fi set +e - "${emulator}/bin/offline" \ - --elf-file ${testCase}/bin/${testCase.pname}.elf \ - --log-file $rtlEventOutPath \ - --log-level ERROR &> $out/offline-check-journal + offlineCheckArgsArray=( + "--elf-file" + "${testCase}/bin/${testCase.pname}.elf" + "--log-file" + "$rtlEventOutPath" + "--log-level" + "${impureEnvs.t1OfflineLogLevel}" + ) + offlineCheckArgs="''${offlineCheckArgsArray[@]}" + + echo "[nix] running ${emulator}/bin/offline $offlineCheckArgs" + "${emulator}/bin/offline" $offlineCheckArgs &> $out/offline-check-journal + printf "$?" > $out/offline-check-status if [ "$(cat $out/offline-check-status)" != "0" ]; then echo "[nix] Offline check FAIL" diff --git a/t1rocketemu/nix/run-vcs-emulation.nix b/t1rocketemu/nix/run-vcs-emulation.nix index d4df55cb08..7b7f2a106b 100644 --- a/t1rocketemu/nix/run-vcs-emulation.nix +++ b/t1rocketemu/nix/run-vcs-emulation.nix @@ -3,6 +3,9 @@ emulator: testCase: +let + impureEnvs = import (../../nix/impure.nix); +in runCommand "run-${emulator.name}-for-${testCase.pname}" { name = "${testCase.pname}-vcs-result" + (lib.optionalString emulator.enable-trace "-trace"); @@ -48,10 +51,18 @@ runCommand "run-${emulator.name}-for-${testCase.pname}" fi set +e - "${verilator-emu}/bin/offline" \ - --elf-file ${testCase}/bin/${testCase.pname}.elf \ - --log-file $rtlEventOutPath \ - --log-level ERROR &> $out/offline-check-journal + offlineCheckArgsArray=( + "--elf-file" + "${testCase}/bin/${testCase.pname}.elf" + "--log-file" + "$rtlEventOutPath" + "--log-level" + "${impureEnvs.t1OfflineLogLevel}" + ) + offlineCheckArgs="''${offlineCheckArgsArray[@]}" + + echo "[nix] running ${emulator}/bin/offline $offlineCheckArgs" + "${emulator}/bin/offline" $offlineCheckArgs &> $out/offline-check-journal printf "$?" > $out/offline-check-status if [ "$(cat $out/offline-check-status)" != "0" ]; then echo "[nix] Offline check FAIL"