Skip to content

Commit

Permalink
[nix] move test to derivation inside gcd vcs
Browse files Browse the repository at this point in the history
For all chipsalliance CI runner, RestrictNamespaces and RestrictSUIDSGID
properties are set for best safety ensurance. So running VCS directly
inside the GitHub Runner is not possible.

This commit give an example of how to get out of the boundary of the
GitHub Action by integrating all simulation into derivation.

Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Sep 9, 2024
1 parent 2b9ed4f commit 19bf2c7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
ref: ${{ github.event.pull_request.head.sha }}
- name: "Run VCS"
run: |
nix run '.#gcd.vcs' --impure
nix build '.#gcd.vcs.tests.simple-sim' --impure -L
run-verilator:
name: "Run Verilator"
Expand Down
24 changes: 20 additions & 4 deletions templates/chisel/nix/gcd/vcs.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2024 Jiuyang Liu <[email protected]>

{ lib, bash, stdenv, rtl, dpi-lib, vcs-fhs-env }:
let binName = "gcd-vcs-simulator";
in stdenv.mkDerivation {
{ lib
, bash
, stdenv
, rtl
, dpi-lib
, vcs-fhs-env
, runCommand
}:

let
binName = "gcd-vcs-simulator";
in
stdenv.mkDerivation (finalAttr: {
name = "vcs";

# Add "sandbox = relaxed" into /etc/nix/nix.conf, and run `systemctl restart nix-daemon`
Expand Down Expand Up @@ -46,6 +56,12 @@ in stdenv.mkDerivation {
inherit vcs-fhs-env;
inherit dpi-lib;
inherit rtl;

tests.simple-sim = runCommand "${binName}-test" { __noChroot = true; } ''
# Combine stderr and stdout and redirect them to tee
# So that we can have log saving to output and also printing to stdout
${finalAttr.finalPackage}/bin/${binName} &> >(tee $out)
'';
};

shellHook = ''
Expand All @@ -71,4 +87,4 @@ in stdenv.mkDerivation {
runHook postInstall
'';
}
})

0 comments on commit 19bf2c7

Please sign in to comment.