2
0
Fork 0

Use a host-only Nixpkgs for test environment

Discriminate test-packages and host-packages when building tests.
This avoids the test tooling being tainted with the hostPlatform
and targetPlatform of the test. For example, QEMU must be built
independently and isolated from the guest platform, for the sake
of test control and minimizing rebuilds.
20.02
Emery Hemingway 3 years ago
parent 70c090af51
commit 693ac303e0
  1. 7
      default.nix
  2. 6
      nixpkgs.nix
  3. 20
      tests/default.nix
  4. 47
      tests/driver-linux.nix

@ -16,12 +16,7 @@ let
toolchainOverlay = import ./toolchain-overlay;
# Overlay of toolchain patches
nixpkgs' = builtins.fetchGit {
# A branch of Nixpkgs with a custom "crossSystem" mechanism
url = "https://github.com/ehmry/nixpkgs.git";
ref = "hybrid-19.09";
rev = "9a704b7def9bc9ea04d12d6a0d55ebebe0af982a";
};
nixpkgs' = import ./nixpkgs.nix;
in { nixpkgs ? nixpkgs', dhall-haskell ? ./dhall-haskell.nix }:

@ -0,0 +1,6 @@
# A branch of Nixpkgs with a custom "crossSystem" mechanism
builtins.fetchGit {
url = "https://github.com/ehmry/nixpkgs.git";
ref = "hybrid-19.09";
rev = "9a704b7def9bc9ea04d12d6a0d55ebebe0af982a";
}

@ -10,21 +10,24 @@ let
signal = call ./signal.nix { };
solo5 = call ./solo5.nix { };
};
in { pkgs ? (import ./.. { }) }:
nixpkgs' = import ./../nixpkgs.nix;
in { nixpkgs ? nixpkgs' }:
let
hostPkgs = import nixpkgs { };
testPkgs = import ./.. { inherit nixpkgs; };
lib = pkgs.buildPackages.pkgs.lib // {
lib = hostPkgs.lib // {
renderDhallInit = path: args:
pkgs.buildPackages.runCommand "init.xml" {
buildInputs = with pkgs.buildPackages; [ linux-dhall ];
hostPkgs.runCommand "init.xml" {
buildInputs = [ testPkgs.buildPackages.linux-dhall ];
initConfig = path;
initArgs = args;
DHALL_PRELUDE = "${pkgs.dhallPackages.prelude}/package.dhall";
DHALL_GENODE = "${pkgs.dhallPackages.genode}/package.dhall";
DHALL_PRELUDE = "${testPkgs.dhallPackages.prelude}/package.dhall";
DHALL_GENODE = "${testPkgs.dhallPackages.genode}/package.dhall";
} ''
set -v
export XDG_CACHE_HOME=$NIX_BUILD_TOP
echo 'let Prelude = env:DHALL_GENODE in Prelude.Init.render (Prelude.Init.defaults { children = toMap (env:initConfig env:initArgs) })' \
| dhall text \
> $out
@ -33,5 +36,6 @@ let
};
in {
linux = tests (import ./driver-linux.nix { inherit pkgs lib; }).callTest;
linux = tests
(import ./driver-linux.nix { inherit testPkgs hostPkgs lib; }).callTest;
}

@ -2,10 +2,10 @@
#
# SPDX-License-Identifier: LicenseRef-Hippocratic-1.1
{ pkgs, lib }:
{ testPkgs, hostPkgs, lib }:
let
testDriver = with pkgs.buildPackages;
testDriver = with hostPkgs;
stdenv.mkDerivation {
name = "genode-test-driver";
@ -23,7 +23,7 @@ let
};
runTests = driver:
pkgs.stdenv.mkDerivation {
hostPkgs.stdenv.mkDerivation {
name = "test-run-${driver.testName}";
buildCommand = ''
@ -39,7 +39,7 @@ let
makeTest = { testScript, testConfig, name ? "unamed", ... }@t:
let
baseSetup = with pkgs; ''
baseSetup = with testPkgs; ''
file link -s core ${depot.base-linux}/bin/core
file link -s timer ${depot.base-linux}/bin/timer
file link -s ld.lib.so ${depot.base-linux}/lib/ld.lib.so
@ -48,22 +48,23 @@ let
file link -s test.config $env(testConfig)
'';
driver = pkgs.buildPackages.runCommand "genode-test-driver-${name}" {
buildInputs = with pkgs.buildPackages; [ makeWrapper expect ];
inherit baseSetup testConfig testScript;
preferLocalBuild = true;
testName = name;
} ''
mkdir -p $out/bin
echo "$testConfig" > $out/test.config
echo "$testScript" > $out/test-script
echo "$baseSetup" > $out/base-setup
ln -s ${testDriver}/bin/genode-test-driver $out/bin/
wrapProgram $out/bin/genode-test-driver \
--run "export testConfig=\"$testConfig\"" \
--run "export testScript=\"\$(cat $out/test-script)\"" \
--run "export baseSetup=\"\$(cat $out/base-setup)\"" \
'';
driver = with hostPkgs;
runCommand "genode-test-driver-${name}" {
buildInputs = [ makeWrapper expect ];
inherit baseSetup testConfig testScript;
preferLocalBuild = true;
testName = name;
} ''
mkdir -p $out/bin
echo "$testConfig" > $out/test.config
echo "$testScript" > $out/test-script
echo "$baseSetup" > $out/base-setup
ln -s ${testDriver}/bin/genode-test-driver $out/bin/
wrapProgram $out/bin/genode-test-driver \
--run "export testConfig=\"$testConfig\"" \
--run "export testScript=\"\$(cat $out/test-script)\"" \
--run "export baseSetup=\"\$(cat $out/base-setup)\"" \
'';
passMeta = drv:
drv
@ -74,5 +75,9 @@ let
in test // { inherit driver test; };
in {
callTest = path: args: makeTest (import path ({ inherit pkgs lib; } // args));
callTest = path: args:
makeTest (import path ({
pkgs = testPkgs;
inherit lib;
} // args));
}

Loading…
Cancel
Save