Skip to content

Commit

Permalink
[nix] abstract emu-result to a function
Browse files Browse the repository at this point in the history
This commit allow sharing same emu logic across multiple test case
builder.

Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Jun 12, 2024
1 parent 73bd18a commit 13f5a84
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 29 deletions.
19 changes: 3 additions & 16 deletions tests/builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
, 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
, makeEmuResult
}:

# args from makeBuilder
Expand Down Expand Up @@ -68,16 +63,8 @@ let

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
'';
passthru.emu-result = makeEmuResult caseDrv;

} // overrides);
in
caseDrv
2 changes: 2 additions & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ let

inherit ip-emu;

makeEmuResult = casesSelf.callPackage ./make-emu-result.nix { };

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

findAndBuild = dir: build:
Expand Down
20 changes: 20 additions & 0 deletions tests/make-emu-result.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# CallPackage args
{ runCommand
, t1-script
, ip-emu
, elaborateConfigJson
}:

# makeEmuResult arg
testCase:

runCommand "get-emu-result" { } ''
${t1-script}/bin/t1-helper \
"ipemu" \
--emulator-path ${ip-emu}/bin/emulator \
--config ${elaborateConfigJson} \
--case ${testCase}/bin/${testCase.pname}.elf \
--no-console-logging \
--no-file-logging \
--out-dir $out
''
33 changes: 20 additions & 13 deletions tests/rvv_bench/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,37 @@
, makeBuilder
, findAndBuild
, t1main
, makeEmuResult
}:

let
include = ./_include;
builder = makeBuilder { casePrefix = "rvv_bench"; };
build = { caseName, sourcePath }:
builder {
inherit caseName;
let
drv = builder
{
inherit caseName;

src = sourcePath;
src = sourcePath;

isFp = lib.pathExists (lib.path.append sourcePath "isFp");
isFp = lib.pathExists (lib.path.append sourcePath "isFp");

buildPhase = ''
runHook preBuild
buildPhase = ''
runHook preBuild
$CC -E -DINC=$PWD/${caseName}.S -E ${include}/template.S -o functions.S
$CC -I${include} ${caseName}.c -T${linkerScript} ${t1main} functions.S -o $pname.elf
$CC -E -DINC=$PWD/${caseName}.S -E ${include}/template.S -o functions.S
$CC -I${include} ${caseName}.c -T${linkerScript} ${t1main} functions.S -o $pname.elf
runHook postBuild
'';
runHook postBuild
'';

meta.description = "test case '${caseName}', written in C intrinsic";
};
meta.description = "test case '${caseName}', written in C intrinsic";

passthru.emu-result = makeEmuResult drv;
};
in
drv;
in
findAndBuild ./. build
findAndBuild ./. build

0 comments on commit 13f5a84

Please sign in to comment.