Skip to content

Commit

Permalink
[nix] add rtl-event.log derivation
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Jun 10, 2024
1 parent 428518f commit 0ca14c2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 36 deletions.
2 changes: 1 addition & 1 deletion nix/t1/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ lib.makeScope newScope
elaborateConfigJson = configPath;
elaborateConfig = builtins.fromJSON (lib.readFile configPath);

cases = innerSelf.callPackage ../../tests { };
cases = innerSelf.callPackage ../../tests { ip-emu = ip.emu; };

# for the convenience to use x86 cases on non-x86 machines, avoiding the extra build time
cases-x86 =
Expand Down
89 changes: 54 additions & 35 deletions tests/builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
, elaborateConfig
, isFp
, vLen

# ip-emu here is used for running the simulation to get event log for the specific test case.
, ip-emu
# t1-script contains many decent default for running the emulator, I don't want to replicate those simulation argument here.
, t1-script
, runCommand
, elaborateConfigJson
}:

# args from makeBuilder
Expand All @@ -18,47 +25,59 @@
let
# avoid adding jq to buildInputs, since it will make overriding buildInputs more error prone
jqBin = "${jq}/bin/jq";
in

stdenv.mkDerivation (self: rec {
# don't set name directory, since it will be suffixed with target triple
pname = "${casePrefix}.${caseName}";
name = pname;
caseDrv = stdenv.mkDerivation (self: rec {
# don't set name directory, since it will be suffixed with target triple
pname = "${casePrefix}.${caseName}";
name = pname;

CC = "${stdenv.targetPlatform.config}-cc";
CC = "${stdenv.targetPlatform.config}-cc";

NIX_CFLAGS_COMPILE =
let
march = (if isFp then "rv32gc_zve32f" else "rv32gc_zve32x")
NIX_CFLAGS_COMPILE =
let
march = (if isFp then "rv32gc_zve32f" else "rv32gc_zve32x")
+ "_zvl${toString (lib.min 1024 vLen)}b";
in
[
"-mabi=ilp32f"
"-march=${march}"
"-mno-relax"
"-static"
"-mcmodel=medany"
"-fvisibility=hidden"
"-fno-PIC"
"-g"
"-O3"
];
in
[
"-mabi=ilp32f"
"-march=${march}"
"-mno-relax"
"-static"
"-mcmodel=medany"
"-fvisibility=hidden"
"-fno-PIC"
"-g"
"-O3"
];

installPhase = ''
runHook preInstall
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp ${pname}.elf $out/bin
mkdir -p $out/bin
cp ${pname}.elf $out/bin
${jqBin} --null-input \
--arg name ${pname} \
--arg type ${casePrefix} \
--arg elfPath "$out/bin/${pname}.elf" \
'{ "name": $name, "elf": { "path": $elfPath } }' \
> $out/${pname}.json
${jqBin} --null-input \
--arg name ${pname} \
--arg type ${casePrefix} \
--arg elfPath "$out/bin/${pname}.elf" \
'{ "name": $name, "elf": { "path": $elfPath } }' \
> $out/${pname}.json
runHook postInstall
'';
runHook postInstall
'';

dontFixup = true;
} // overrides)
dontFixup = true;

passthru.emu-result = runCommand "get-event-log" { } ''
${t1-script}/bin/t1-helper \
"ipemu" \
--emulator-path ${ip-emu}/bin/emulator \
--config ${elaborateConfigJson} \
--case ${caseDrv}/bin/${pname}.elf \
--no-console-logging \
--no-file-logging \
--out-dir $out
'';
} // overrides);
in
caseDrv
3 changes: 3 additions & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
, newScope
, rv32-stdenv
, runCommand
, ip-emu
}:

let
Expand All @@ -17,6 +18,8 @@ let
scope = lib.recurseIntoAttrs (lib.makeScope newScope (casesSelf: {
recurseForDerivations = true;

inherit ip-emu;

makeBuilder = casesSelf.callPackage ./builder.nix { };

findAndBuild = dir: build:
Expand Down

0 comments on commit 0ca14c2

Please sign in to comment.