Skip to content

Commit

Permalink
[nix] refactor test case to allow t1rocket attr opt-in
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Aug 12, 2024
1 parent 421ed15 commit 065a9c9
Show file tree
Hide file tree
Showing 15 changed files with 278 additions and 230 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/vcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
nix build '.#t1.${{ matrix.config }}.ip.vcs-emu' --impure --no-link --cores 64
- name: "Build all testcases"
run: |
nix build ".#t1.${{ matrix.config }}.ip.cases.all" --max-jobs auto --no-link --cores 64
nix build ".#t1.${{ matrix.config }}.ip.cases._all" --max-jobs auto --no-link --cores 64
gen-matrix:
name: "Prepare for running testcases"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verilator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: "Build all testcases"
run: |
# Build testcases with vlen 1024 and vlen 4096
nix build ".#t1.${{ matrix.config }}.ip.cases.all" --max-jobs auto -L --no-link --cores 64
nix build ".#t1.${{ matrix.config }}.ip.cases._all" --max-jobs auto -L --no-link --cores 64
# In the future, we may choose Verdi for trace, and left verilator trace only for performance evaluation
build-verilator-trace-emulators:
Expand Down
2 changes: 1 addition & 1 deletion script/ci/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ object Main:

import scala.util.chaining._
val testPlans: Seq[String] = emulatorConfigs.flatMap: configName =>
val allCasesPath = nixResolvePath(s".#t1.$configName.ip.cases.all")
val allCasesPath = nixResolvePath(s".#t1.$configName.ip.cases._all")
os.walk(os.Path(allCasesPath) / "configs")
.filter: path =>
path.ext == "json"
Expand Down
67 changes: 9 additions & 58 deletions t1rocketemu/default.nix
Original file line number Diff line number Diff line change
@@ -1,67 +1,18 @@
{ lib
, newScope
, rustPlatform
, zlib
, libspike
, libspike_interfaces
, cmake
, verilator
}:
lib.makeScope newScope (scope: rec {
lib.makeScope newScope (scope: {
mlirbc = scope.callPackage ./nix/mlirbc.nix { };
rtl = scope.callPackage ./nix/rtl.nix { };
verilated-c-lib = scope.callPackage ./nix/verilated-c-lib.nix { };

emu = rustPlatform.buildRustPackage {
name = "t1rocketemu";

src = with lib.fileset; toSource {
root = ./.;
fileset = unions [
./test_common
./spike_rs
./offline
./online_dpi
./online_drive
./online_vcs
./Cargo.lock
./Cargo.toml
];
emu = scope.callPackage ./emu.nix { };
designConfig = with builtins; (fromJSON (readFile ./configs/default.json)).parameter;
cases = scope.callPackage ../tests {
configName = "t1rocket";
t1rocket-emu = scope.emu;
rtlDesignMetadata = {
march = "rv32iafcv_zve32x_zvl1024b";
dlen = scope.designConfig.dLen;
};

buildInputs = [
zlib
libspike_interfaces
verilated-c-lib
];

nativeBuildInputs = [
verilator
cmake
];

# FIXME: can we hack this into derivations, so that we don't need to specify library dir explicitly?
env =
let
toLib = drv: "${drv}/lib";
in
{
SPIKE_LIB_DIR = toLib libspike;
SPIKE_INTERFACES_LIB_DIR = toLib libspike_interfaces;
VERILATED_INC_DIR = "${verilated-c-lib}/include";
VERILATED_LIB_DIR = "${verilated-c-lib}/lib";
};

cargoLock = {
lockFile = ./Cargo.lock;
};

outputs = [ "out" "driver" "offline" ];

postInstall = ''
mkdir -p $driver/bin $offline/bin
ln -s $out/bin/driver $driver/bin/driver
ln -s $out/bin/offline $driver/bin/offline
'';
};
})
61 changes: 61 additions & 0 deletions t1rocketemu/emu.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{ lib
, rustPlatform
, zlib
, libspike
, libspike_interfaces
, cmake
, verilator
, verilated-c-lib
}:
rustPlatform.buildRustPackage {
name = "t1rocketemu";

src = with lib.fileset; toSource {
root = ./.;
fileset = unions [
./test_common
./spike_rs
./offline
./online_dpi
./online_drive
./online_vcs
./Cargo.lock
./Cargo.toml
];
};

buildInputs = [
zlib
libspike_interfaces
verilated-c-lib
];

nativeBuildInputs = [
verilator
cmake
];

# FIXME: can we hack this into derivations, so that we don't need to specify library dir explicitly?
env =
let
toLib = drv: "${drv}/lib";
in
{
SPIKE_LIB_DIR = toLib libspike;
SPIKE_INTERFACES_LIB_DIR = toLib libspike_interfaces;
VERILATED_INC_DIR = "${verilated-c-lib}/include";
VERILATED_LIB_DIR = "${verilated-c-lib}/lib";
};

cargoLock = {
lockFile = ./Cargo.lock;
};

outputs = [ "out" "driver" "offline" ];

postInstall = ''
mkdir -p $driver/bin $offline/bin
ln -s $out/bin/driver $driver/bin/driver
ln -s $out/bin/offline $driver/bin/offline
'';
}
2 changes: 1 addition & 1 deletion tests/asm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let

src = sourcePath;

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

buildPhase = ''
Expand Down
89 changes: 45 additions & 44 deletions tests/builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,57 +19,58 @@ let
# avoid adding jq to buildInputs, since it will make overriding buildInputs more error prone
jqBin = "${jq}/bin/jq";

caseDrv = 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: lib.recursiveUpdate
rec {
# don't set name directory, since it will be suffixed with target triple
pname = "${casePrefix}.${caseName}";
name = pname;

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

NIX_CFLAGS_COMPILE =
let
march = lib.pipe rtlDesignMetadata.march [
(lib.splitString "_")
(map (ext: if ext == "zvbb" then "zvbb1" else ext))
(lib.concatStringsSep "_")
];
in
[
"-mabi=ilp32f"
"-march=${march}"
"-mno-relax"
"-static"
"-mcmodel=medany"
"-fvisibility=hidden"
"-fno-PIC"
"-g"
"-O3"
] ++ lib.optionals (lib.elem "zvbb" (lib.splitString "_" rtlDesignMetadata.march)) [ "-menable-experimental-extensions" ];
NIX_CFLAGS_COMPILE =
let
march = lib.pipe rtlDesignMetadata.march [
(lib.splitString "_")
(map (ext: if ext == "zvbb" then "zvbb1" else ext))
(lib.concatStringsSep "_")
];
in
[
"-mabi=ilp32f"
"-march=${march}"
"-mno-relax"
"-static"
"-mcmodel=medany"
"-fvisibility=hidden"
"-fno-PIC"
"-g"
"-O3"
] ++ lib.optionals (lib.elem "zvbb" (lib.splitString "_" rtlDesignMetadata.march)) [ "-menable-experimental-extensions" ];

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;
dontFixup = true;

passthru = {
inherit rtlDesignMetadata;
emu-result = makeEmuResult caseDrv;
};

} // overrides);
passthru = {
inherit rtlDesignMetadata;
emu-result = makeEmuResult caseDrv;
};
}
overrides); # end of recursiveUpdate
in
caseDrv
6 changes: 3 additions & 3 deletions tests/codegen/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ let
)
rawCaseNames));

commonTests = buildTestsFromFile ./common.txt { featuresRequired = { extensions = [ ]; }; };
fpTests = buildTestsFromFile ./fp.txt { featuresRequired = { extensions = [ "zve32f" ]; }; };
zvbbTests = buildTestsFromFile ./zvbb.txt { featuresRequired = { extensions = [ "zvbb" ]; }; };
commonTests = buildTestsFromFile ./common.txt { passthru.featuresRequired = { extensions = [ ]; }; };
fpTests = buildTestsFromFile ./fp.txt { passthru.featuresRequired = { extensions = [ "zve32f" ]; }; };
zvbbTests = buildTestsFromFile ./zvbb.txt { passthru.featuresRequired = { extensions = [ "zvbb" ]; }; };
in
lib.recurseIntoAttrs (
commonTests //
Expand Down
41 changes: 27 additions & 14 deletions tests/default.nix
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
{ lib
, configName
, rtlDesignMetadata
, newScope
, rv32-stdenv
, runCommand
, verilator-emu
, verilator-emu-trace
, vcs-emu
, vcs-emu-trace

, configName
, rtlDesignMetadata

, t1rocket-emu ? null
, t1rocket-emu-trace ? null

, verilator-emu ? null
, verilator-emu-trace ? null

, vcs-emu ? null
, vcs-emu-trace ? null
}:

let
getVLen = ext:
let
val = builtins.tryEval
(lib.toInt
(lib.toLower
(lib.removeSuffix "b"
(lib.removePrefix "zvl"
(lib.toLower ext)))));
(lib.removeSuffix "b"
(lib.removePrefix "zvl"
(lib.toLower ext))));
in
if val.success then
val.value
Expand Down Expand Up @@ -66,7 +71,15 @@ let
scope = lib.recurseIntoAttrs (lib.makeScope newScope (casesSelf: {
recurseForDerivations = true;

inherit verilator-emu verilator-emu-trace vcs-emu vcs-emu-trace rtlDesignMetadata featuresSet;
inherit
verilator-emu
verilator-emu-trace
vcs-emu
vcs-emu-trace
t1rocket-emu
t1rocket-emu-trace
rtlDesignMetadata
featuresSet;

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

Expand All @@ -83,7 +96,7 @@ let
in
if lib.pathExists extraFeatures then
builtins.fromJSON (lib.fileContents extraFeatures)
else [ ];
else { };

filterByFeatures = caseName: caseDrv:
assert lib.assertMsg (caseDrv ? featuresRequired) "${caseName} doesn't have features specified";
Expand Down Expand Up @@ -175,7 +188,7 @@ let
in
runCommand "catch-${configName}-all-vcs-emu-result-for-ci" { } script;

all =
_all =
let
allCases = lib.filter
lib.isDerivation
Expand All @@ -195,4 +208,4 @@ let
{ }
script;
in
lib.recurseIntoAttrs (scopeStripped // { inherit all _allEmuResult _allVCSEmuResult; })
lib.recurseIntoAttrs (scopeStripped // { inherit _all _allEmuResult _allVCSEmuResult; })
2 changes: 1 addition & 1 deletion tests/intrinsic/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let

src = sourcePath;

featuresRequired = getTestRequiredFeatures sourcePath;
passthru.featuresRequired = getTestRequiredFeatures sourcePath;

buildPhase = ''
runHook preBuild
Expand Down
Loading

0 comments on commit 065a9c9

Please sign in to comment.