From bffa59d5bc778bf9850d21259a521550fc7bfda5 Mon Sep 17 00:00:00 2001 From: Max Wipfli Date: Mon, 4 Aug 2025 09:35:30 +0200 Subject: [PATCH] icestorm: add examples as integration tests --- pkgs/by-name/ic/icestorm/package.nix | 16 ++++++++++----- pkgs/by-name/ic/icestorm/tests.nix | 29 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 pkgs/by-name/ic/icestorm/tests.nix diff --git a/pkgs/by-name/ic/icestorm/package.nix b/pkgs/by-name/ic/icestorm/package.nix index 82b1a999edd3..f0ebd58a71aa 100644 --- a/pkgs/by-name/ic/icestorm/package.nix +++ b/pkgs/by-name/ic/icestorm/package.nix @@ -1,6 +1,7 @@ { lib, stdenv, + callPackage, fetchFromGitHub, pkg-config, libftdi1, @@ -18,13 +19,18 @@ usePyPy ? stdenv.hostPlatform.system == "x86_64-linux", }: -stdenv.mkDerivation rec { +stdenv.mkDerivation (finalAttrs: { pname = "icestorm"; version = "0-unstable-2025-06-03"; passthru = rec { pythonPkg = if (false && usePyPy) then pypy3 else python3; pythonInterp = pythonPkg.interpreter; + + tests.examples = callPackage ./tests.nix { + inherit (finalAttrs) pname src; + icestorm = finalAttrs.finalPackage; + }; }; src = fetchFromGitHub { @@ -36,12 +42,12 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ pkg-config ]; buildInputs = [ - passthru.pythonPkg + finalAttrs.passthru.pythonPkg libftdi1 ]; makeFlags = [ "PREFIX=$(out)" - "PYTHON3=${passthru.pythonInterp}" + "PYTHON3=${finalAttrs.passthru.pythonInterp}" ]; enableParallelBuilding = true; @@ -51,7 +57,7 @@ stdenv.mkDerivation rec { patchPhase = '' for x in $(find . -type f -iname '*.py' -executable); do substituteInPlace "$x" \ - --replace-fail '/usr/bin/env python3' '${passthru.pythonInterp}' + --replace-fail '/usr/bin/env python3' '${finalAttrs.passthru.pythonInterp}' done # We use GNU sed on Darwin, while icebox/Makefile assumed BSD sed (which @@ -75,4 +81,4 @@ stdenv.mkDerivation rec { ]; platforms = lib.platforms.all; }; -} +}) diff --git a/pkgs/by-name/ic/icestorm/tests.nix b/pkgs/by-name/ic/icestorm/tests.nix new file mode 100644 index 000000000000..c7e89a87171e --- /dev/null +++ b/pkgs/by-name/ic/icestorm/tests.nix @@ -0,0 +1,29 @@ +# Run the examples from $src/examples/ as simple integration tests. They require +# yosys and nextpnr (which itself depends on this package), so they cannot be +# ran during the check phase. +{ + runCommand, + icestorm, + nextpnr, + yosys, + + pname, + src, +}: + +runCommand "${pname}-test-examples" + { + nativeBuildInputs = [ + icestorm + nextpnr + yosys + ]; + } + '' + cp -r ${src}/examples . + chmod -R +w examples + for example in examples/*; do + make -C $example + done + touch $out + ''