Skip to content

Commit

Permalink
[nix] refactor test case
Browse files Browse the repository at this point in the history
* cases is now under the ip scope
* replace isFp detect with features abstract layer, so that tests can
  have more extensible way to declare their required emulator type.

Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Jul 31, 2024
1 parent 21f7014 commit 38c413d
Show file tree
Hide file tree
Showing 18 changed files with 148 additions and 74 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 }}.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
4 changes: 2 additions & 2 deletions .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 }}.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
gen-matrix:
name: "Prepare for running testcases"
Expand Down Expand Up @@ -91,4 +91,4 @@ jobs:
run: |
nix run ".#ci-helper" -- postCI --failed-tests-file-path ./failed-tests.md --cycle-update-file-path ./cycle-update.md
cat ./failed-tests.md >> $GITHUB_STEP_SUMMARY
cat ./cycle-update.md >> $GITHUB_STEP_SUMMARY
cat ./cycle-update.md >> $GITHUB_STEP_SUMMARY
36 changes: 25 additions & 11 deletions nix/t1/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
, stdenv
, useMoldLinker
, newScope
, runCommand

, pkgsX86
}:
Expand Down Expand Up @@ -51,16 +52,6 @@ lib.makeScope newScope
elaborateConfigJson = configPath;
elaborateConfig = builtins.fromJSON (lib.readFile configPath);

cases = innerSelf.callPackage ../../tests {
inherit (ip) verilator-emu verilator-emu-trace vcs-emu vcs-emu-trace;
};

# for the convenience to use x86 cases on non-x86 machines, avoiding the extra build time
cases-x86 =
if system == "x86-64-linux"
then self.cases
else pkgsX86.t1."${configName}".cases;

ip = rec {
recurseForDerivations = true;

Expand All @@ -80,8 +71,31 @@ lib.makeScope newScope
"--lowering-options=verifLabels,omitVersionComment,emittedLineLength=240,locationInfoStyle=none"
];
};
omreader = self.omreader-unwrapped.mkWrapper { inherit mlirbc; };

om = innerSelf.callPackage ./om.nix { inherit mlirbc; };
omreader = self.omreader-unwrapped.mkWrapper { inherit mlirbc; };

emu-om = innerSelf.callPackage ./om.nix { mlirbc = emu-mlirbc; };
emu-omreader = self.omreader-unwrapped.mkWrapper { mlirbc = emu-mlirbc; };
omGet = args: lib.fileContents (runCommand "get-${args}" { } ''
${emu-omreader}/bin/omreader ${args} > $out
'');
rtlDesignMetadata = {
march = omGet "march";
extensions = builtins.fromJSON (omGet "extensionsJson");
vlen = omGet "vlen";
dlen = omGet "dlen";
};

cases = innerSelf.callPackage ../../tests {
inherit (ip) verilator-emu verilator-emu-trace vcs-emu vcs-emu-trace rtlDesignMetadata;
};

# for the convenience to use x86 cases on non-x86 machines, avoiding the extra build time
cases-x86 =
if system == "x86-64-linux"
then self.cases
else pkgsX86.t1."${configName}".cases;

emu-elaborate = innerSelf.callPackage ./elaborate.nix { target = "ipemu"; };
emu-mlirbc = innerSelf.callPackage ./mlirbc.nix { elaborate = emu-elaborate; };
Expand Down
12 changes: 6 additions & 6 deletions script/ci/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ object Main:

val testAttr = testType.toLowerCase() match
case "verilator" =>
s".#t1.$config.cases.$caseName.emu-result.with-offline"
case "vcs" => s".#t1.$config.cases.$caseName.emu-result.with-vcs"
s".#t1.$config.ip.cases.$caseName.emu-result.with-offline"
case "vcs" => s".#t1.$config.ip.cases.$caseName.emu-result.with-vcs"
case _ => Logger.fatal(s"Invalid test type ${testType}")
val testResultPath =
try
Expand All @@ -186,7 +186,7 @@ object Main:
os.read(testResultPath / "offline-check-status").trim() == "0"
if !testSuccess then
Logger.error(s"Offline check FAILED for $caseName ($config)")
allFailedTest :+ s"t1.$config.cases.$caseName"
allFailedTest :+ s"t1.$config.ip.cases.$caseName"
else
Logger.info(s"Offline check PASS for $caseName ($config)")
allFailedTest
Expand Down Expand Up @@ -268,8 +268,8 @@ object Main:
Logger.info("Fetching CI results")
val resultAttr = emuType.toLowerCase() match
case "verilator" =>
s".#t1.$config.cases._allEmuResult"
case "vcs" => s".#t1.$config.cases._allVCSEmuResult"
s".#t1.$config.ip.cases._allEmuResult"
case "vcs" => s".#t1.$config.ip.cases._allVCSEmuResult"
case _ => Logger.fatal(s"Invalid test type ${emuType}")
val emuResultPath = os.Path(nixResolvePath(
resultAttr,
Expand Down 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.cases.all")
val allCasesPath = nixResolvePath(s".#t1.$configName.ip.cases.all")
os.walk(os.Path(allCasesPath) / "configs")
.filter: path =>
path.ext == "json"
Expand Down
4 changes: 3 additions & 1 deletion tests/asm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
, makeBuilder
, findAndBuild
, t1main
, getTestRequiredFeatures
}:

let
Expand All @@ -13,6 +14,7 @@ let

src = sourcePath;

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

buildPhase = ''
Expand All @@ -29,5 +31,5 @@ let
meta.description = "test case '${caseName}', written in C assembly";
};
in
findAndBuild ./. build
findAndBuild ./. build

1 change: 1 addition & 0 deletions tests/asm/fpsmoke/features-required.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["zve32f"]
Empty file removed tests/asm/fpsmoke/isFp
Empty file.
36 changes: 16 additions & 20 deletions tests/builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
{ stdenv
, lib
, jq
, elaborateConfig
, isFp
, vLen
, rtlDesignMetadata

, makeEmuResult
}:
Expand All @@ -28,22 +26,17 @@ let

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

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"
];
NIX_CFLAGS_COMPILE = [
"-mabi=ilp32f"
"-march=${rtlDesignMetadata.march}"
"-mno-relax"
"-static"
"-mcmodel=medany"
"-fvisibility=hidden"
"-fno-PIC"
"-g"
"-O3"
];

installPhase = ''
runHook preInstall
Expand All @@ -63,7 +56,10 @@ let

dontFixup = true;

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

} // overrides);
in
Expand Down
38 changes: 24 additions & 14 deletions tests/codegen/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@
, linkerScript
, rvv-codegen
, makeBuilder
, xLen
, vLen
, isFp
# Instead of testing feature is supported on TOP level,
# codegen case are always generated with supported code.
, currentFeatures
}:

let
builder = makeBuilder { casePrefix = "codegen"; };
makeCaseName = lib.replaceStrings [ "." ] [ "_" ];
extraValueFromFeatures = pattern:
lib.last
(lib.splitString ":"
(lib.head
(lib.filter
(lib.hasPrefix pattern)
currentFeatures)));
vlen = extraValueFromFeatures "vlen";
xlen = extraValueFromFeatures "xlen";

build = { rawCaseName, isFp }:
build = { rawCaseName, passthru }:
builder rec {
caseName = makeCaseName rawCaseName;

Expand All @@ -22,14 +31,14 @@ let

dontUnpack = true;

inherit isFp;
inherit passthru;

buildPhase = ''
runHook preBuild
${rvv-codegen}/bin/single \
-VLEN "${toString vLen}" \
-XLEN "${toString xLen}" \
-VLEN "${vlen}" \
-XLEN "${xlen}" \
-repeat 16 \
-testfloat3level 2 \
-configfile ${rvv-codegen}/configs/${rawCaseName}.toml \
Expand All @@ -50,7 +59,7 @@ let
meta.description = "test case '${caseName}' generated by codegen";
};

buildTestsFromFile = file: { isFp ? false }:
buildTestsFromFile = file: passthru:
with lib;
let
rawCaseNames = lib.splitString "\n" (lib.fileContents file);
Expand All @@ -59,17 +68,18 @@ let
(map
(rawCaseName: nameValuePair
(makeCaseName rawCaseName)
(build { inherit rawCaseName isFp; })
(build { inherit rawCaseName passthru; })
)
rawCaseNames));

commonTests = buildTestsFromFile ./common.txt { };
fpTests = buildTestsFromFile ./fp.txt { isFp = true; };

fpTests = buildTestsFromFile ./fp.txt { featuresRequired = [ "zve32f" ]; };
zvbbTests = buildTestsFromFile ./zvbb.txt { featuresRequired = [ "zvbb" ]; };
hasFeature = feat: lib.any (f: feat == f) currentFeatures;
in
lib.recurseIntoAttrs (
if isFp
then commonTests // fpTests
else commonTests
commonTests //
lib.optionalAttrs (hasFeature "zve32f") fpTests //
lib.optionalAttrs (hasFeature "zvbb") zvbbTests
)

16 changes: 16 additions & 0 deletions tests/codegen/zvbb.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
vandn.vv
vandn.vx
vbrev.v
vbreav8.v
vclz.v
vcpop.v
vctz.v
vrev8.v
vrol.vv
vrol.vx
vror.vi
vror.vv
vror.vx
vwsll.vi
vwsll.vv
vwsll.vx
Loading

0 comments on commit 38c413d

Please sign in to comment.