Skip to content

Commit 19bf2c7

Browse files
committed
[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 <[email protected]>
1 parent 2b9ed4f commit 19bf2c7

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
ref: ${{ github.event.pull_request.head.sha }}
5757
- name: "Run VCS"
5858
run: |
59-
nix run '.#gcd.vcs' --impure
59+
nix build '.#gcd.vcs.tests.simple-sim' --impure -L
6060
6161
run-verilator:
6262
name: "Run Verilator"

templates/chisel/nix/gcd/vcs.nix

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# SPDX-FileCopyrightText: 2024 Jiuyang Liu <[email protected]>
33

4-
{ lib, bash, stdenv, rtl, dpi-lib, vcs-fhs-env }:
5-
let binName = "gcd-vcs-simulator";
6-
in stdenv.mkDerivation {
4+
{ lib
5+
, bash
6+
, stdenv
7+
, rtl
8+
, dpi-lib
9+
, vcs-fhs-env
10+
, runCommand
11+
}:
12+
13+
let
14+
binName = "gcd-vcs-simulator";
15+
in
16+
stdenv.mkDerivation (finalAttr: {
717
name = "vcs";
818

919
# Add "sandbox = relaxed" into /etc/nix/nix.conf, and run `systemctl restart nix-daemon`
@@ -46,6 +56,12 @@ in stdenv.mkDerivation {
4656
inherit vcs-fhs-env;
4757
inherit dpi-lib;
4858
inherit rtl;
59+
60+
tests.simple-sim = runCommand "${binName}-test" { __noChroot = true; } ''
61+
# Combine stderr and stdout and redirect them to tee
62+
# So that we can have log saving to output and also printing to stdout
63+
${finalAttr.finalPackage}/bin/${binName} &> >(tee $out)
64+
'';
4965
};
5066

5167
shellHook = ''
@@ -71,4 +87,4 @@ in stdenv.mkDerivation {
7187
7288
runHook postInstall
7389
'';
74-
}
90+
})

0 commit comments

Comments
 (0)