Skip to content

Commit

Permalink
[ci] let all CI runner use pre-built verilatorEmulator in nix cache
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Oct 27, 2023
1 parent 9a11339 commit 8d274a7
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 29 deletions.
3 changes: 1 addition & 2 deletions .github/scripts/ci.sc
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ def runTest(root: os.Path, jobs: String, outDir: Option[os.Path]) = {
}

if (failed.length > 0) {
os.write.over(logDir / "fail" / s"fail-test-${md5}.md",
s"${failed.map(f => s"* $f").mkString("\n")}")
os.write.over(logDir / "fail" / s"fail-test-${md5}.md", failed.map(f => s"* $f").mkString("\n"))
println(s"${failed.length} tests failed:\n${failed.mkString("\n")}")
throw new Exception("Tests failed")
} else {
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/postpr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
builders = ssh://nix-remote@${{secrets.ROCKETCHIP_NIX_REMOTE_HOST}}?ssh-key=/etc/nix/builder-key
builders-use-substitutes = true
- id: ci-tests
run: nix develop .#testcase -c make ci-unpassed-tests DEFAULT_PASSED=.github/passed/default.txt
run: nix develop '.?submodules=1#ci' -c make ci-unpassed-tests DEFAULT_PASSED=.github/passed/default.txt

ci:
name: "CI"
Expand Down Expand Up @@ -75,8 +75,8 @@ jobs:
builders-use-substitutes = true
- id: ci-run
run: |
nix develop .#testcase -c make ci-run "NAME=${{ matrix.name }}"
nix develop .#testcase -c make convert-perf-to-md
nix develop '.?submodules=1#ci' -c make ci-run "NAME=${{ matrix.name }}"
nix develop '.?submodules=1#ci' -c make convert-perf-to-md
- uses: actions/upload-artifact@v3
if: always()
Expand Down
67 changes: 65 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
builders = ssh://nix-remote@${{secrets.ROCKETCHIP_NIX_REMOTE_HOST}}?ssh-key=/etc/nix/builder-key
builders-use-substitutes = true
- id: ci-tests
run: nix develop .#testcase -c make ci-passed-tests DEFAULT_PASSED=.github/passed/default.txt
run: nix develop '.?submodules=1#ci' -c make ci-passed-tests DEFAULT_PASSED=.github/passed/default.txt

ci:
name: "CI"
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
builders-use-substitutes = true
- id: ci-run
run: |
nix develop .#testcase -c make ci-run "NAME=${{ matrix.name }}"
nix develop '.?submodules=1#ci' -c make ci-run "NAME=${{ matrix.name }}"
- uses: actions/upload-artifact@v3
if: always()
Expand All @@ -93,6 +93,69 @@ jobs:
name: nix-post-build-hook-log
path: /tmp/nix-post-build-hook.log


gen-fail-wave:
name: "Generate wave for failing test"
if: always()
needs: [ci]
runs-on: [self-hosted, linux]
outputs:
generate_wave: ${{ steps.filter-fail-jobs.outputs.generate_wave }}
retry_tasks: ${{ steps.filter-fail-jobs.outputs.retry_tasks }}
steps:
- uses: actions/download-artifact@v3
with:
name: results
- id: filter-fail-jobs
name: fileter-fail-jobs
run: |
touch all-fail-tests.txt
find . -name 'fail-test-*.md' -exec bash -c 'cat {} >> all-fail-tests.txt' \;
retry=$(sed 's/\* //' all-fail-tests.txt | tail -n3)
[[ -n "$retry" ]] \
&& echo "generate_wave=true" >> "$GITHUB_OUTPUT" \
&& echo "$retry" | jq -n --indent 0 "{include:[{name: inputs}]}"
build-fail-wave:
name: "Generate wave for failing tests"
needs: [gen-fail-wave]
if: ${{ needs.gen-fail-wave.outputs.generate_wave == 'true' }}
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.gen-fail-wave.outputs.retry_tasks) }}
runs-on: [self-hosted, linux]
steps:
- uses: actions/checkout@v3
with:
submodules: true
- run: sudo -E .github/setup-actions.sh
env:
AWS_CREDENTIALS: ${{secrets.AWS_CREDENTIALS}}
CACHE_PRIV_KEY: ${{secrets.CACHE_PRIV_KEY}}
CACHE_DOMAIN: ${{secrets.CACHE_DOMAIN}}
ROCKETCHIP_NIX_REMOTE_SSH_PRIVKEY: ${{secrets.ROCKETCHIP_NIX_REMOTE_SSH_PRIVKEY}}
ROCKETCHIP_NIX_REMOTE_HOST: ${{secrets.ROCKETCHIP_NIX_REMOTE_HOST}}
- uses: cachix/install-nix-action@v19
with:
install_url: https://releases.nixos.org/nix/nix-2.13.3/install
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
post-build-hook = /etc/nix/upload-to-cache.sh
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= minio.inner.fi.c-3.moe:gDg5SOIH65O0tTV89dUawME5BTmduWWaA7as/cqvevM=
extra-substituters = https://${{secrets.CACHE_DOMAIN}}/nix
sandbox = relaxed
max-jobs = 0
builders = ssh://nix-remote@${{secrets.ROCKETCHIP_NIX_REMOTE_HOST}}?ssh-key=/etc/nix/builder-key
builders-use-substitutes = true
- run: |
millTask=$(echo ${{ matrix.name }} | sed 's/v1024l8b2-test/v1024l8b2-test-trace/')
nix develop '.?submodules=1#ci' -c mill -i "$millTask"
find out -name 'wave.fst' -exec mv {} "$millTask".fst \;
- uses: actions/upload-artifact@v3
with:
name: fail-test-wave
path: './*.fst'

report:
name: "Report CI result"
if: always()
Expand Down
2 changes: 1 addition & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ trait Emulator
Option.when(os.exists(path))(path)
}
.getOrElse {
println(s"No pre-built emulator found, try to build with config $config")
System.err.println(s"No pre-built emulator found, try to build with config $config")
// either rtl or testbench change should trigger elf rebuild
elaborator(config).mfccompile.rtls()
allCSourceFiles()
Expand Down
32 changes: 14 additions & 18 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,30 @@
chisel = pkgs.mkShell {
buildInputs = commonDeps ++ chiselDeps;
};
# This environment is provided for writing and compiling testcase.
# If you are going to run test cases, use the .#testcase devShell.
testcase-bootstrap = mkLLVMShell {
buildInputs = commonDeps ++ testcaseDeps ++ [ pkgs.ammonite pkgs.mill ];

env = {
CODEGEN_BIN_PATH = "${pkgs.rvv-codegen}/bin/single";
CODEGEN_INC_PATH = "${pkgs.rvv-codegen}/include";
CODEGEN_CFG_PATH = "${pkgs.rvv-codegen}/configs";
};
};
# This devShell is used for running testcase
testcase = mkLLVMShell {
# TODO: Currently, the emulator needs all the dependencies to run a test case ,
# but most of them are used to get version information, so they should be cleaned up one day.
buildInputs = commonDeps ++ chiselDeps ++ testcaseDeps ++ emulatorDeps;

env = {
# to build and run your testcase, run `unset TEST_CASE_DIR`
TEST_CASE_DIR = "${pkgs.rvv-testcase}";
VERILATOR_EMULATOR_BIN_PATH =
let
verilatorEmulator = pkgs.callPackage
./nix/verilator-emulator.nix
{ emulatorTypes = [ "v1024l8b2-test" "v1024l8b2-test-trace" ]; };
in
"${verilatorEmulator}/bin";
};
};
ci = mkLLVMShell {
buildInputs = commonDeps ++ chiselDeps ++ testcaseDeps ++ emulatorDeps;
env =
let
verilatorEmulator = pkgs.callPackage ./nix/verilator-emulator.nix {
emulatorTypes = [ "v1024l8b2-test" "v1024l8b2-test-trace" ];
emulatorSrc = self;
};
in
{
VERILATOR_EMULATOR_BIN_PATH = "${verilatorEmulator}/bin";
};
};
emulator = mkLLVMShell {
buildInputs = commonDeps ++ chiselDeps ++ emulatorDeps;

Expand Down
8 changes: 5 additions & 3 deletions nix/verilator-emulator.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
llvmPackages_14
, # Compile options
emulatorTypes ? [ "v1024l8b2-test" ]
, emulatorSrc ? null
}:

assert lib.assertMsg ((builtins.typeOf emulatorTypes) == "list") "`emulatorTypes` is not a `list`";
Expand All @@ -49,15 +50,16 @@ let
cp -pr --reflink=auto -- "$src" "$dest"
done
'';

src = if (builtins.typeOf emulatorSrc != "null") then emulatorSrc else pureEmulatorSrc;
in
llvmPackages_14.stdenv.mkDerivation rec {
version = "unstable-2023-10";
pname = "emulator";
src = pureEmulatorSrc;
inherit src;

millDeps = fetchMillDeps {
inherit pname;
src = pureEmulatorSrc;
inherit src pname;
millDepsHash = "sha256-Z/CobcyBWB3y81iT+IFVapRn1gJh7ky71es11a4NvCU=";
};

Expand Down

0 comments on commit 8d274a7

Please sign in to comment.