From 2f7eaee524d1ab4aa313a1055e2a98f9848e1637 Mon Sep 17 00:00:00 2001 From: Avimitin Date: Tue, 10 Sep 2024 02:14:40 +0800 Subject: [PATCH] [nix] move test to derivation inside gcd vcs 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 --- .github/workflows/main.yml | 2 +- templates/chisel/nix/gcd/vcs.nix | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a5f1536..e2e5be4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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' --impure run-verilator: name: "Run Verilator" diff --git a/templates/chisel/nix/gcd/vcs.nix b/templates/chisel/nix/gcd/vcs.nix index 580b647..fd8f986 100644 --- a/templates/chisel/nix/gcd/vcs.nix +++ b/templates/chisel/nix/gcd/vcs.nix @@ -1,9 +1,19 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: 2024 Jiuyang Liu -{ 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` @@ -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 = '' @@ -71,4 +87,4 @@ in stdenv.mkDerivation { runHook postInstall ''; -} +})