Emery Hemingway
9fc90076d6
Replace a script that builds a Linux boot image into the current workings directory and boots it with a script that only builds the image.
131 lines
3.7 KiB
Nix
131 lines
3.7 KiB
Nix
# SPDX-License-Identifier: CC0-1.0
|
|
|
|
{ apps, testPkgs, hostPkgs, lib, depot }:
|
|
|
|
let
|
|
testDriver = with hostPkgs;
|
|
stdenv.mkDerivation {
|
|
name = "genode-test-driver";
|
|
preferLocalBuild = true;
|
|
|
|
buildInputs = [ makeWrapper expect ];
|
|
|
|
dontUnpack = true;
|
|
|
|
installPhase = ''
|
|
install -Dm555 ${./test-driver.exp} $out/bin/genode-test-driver
|
|
wrapProgram $out/bin/genode-test-driver \
|
|
--prefix PATH : "${lib.makeBinPath [ expect coreutils ]}"
|
|
'';
|
|
};
|
|
|
|
runTests = driver:
|
|
hostPkgs.stdenv.mkDerivation {
|
|
name = "linux-" + driver.testName;
|
|
preferLocalBuild = true;
|
|
|
|
buildCommand = ''
|
|
mkdir -p $out/nix-support
|
|
|
|
${driver}/bin/genode-test-driver | tee $out/log
|
|
|
|
touch $out/nix-support
|
|
echo "report testlog $out log" >> $out/nix-support/hydra-build-products
|
|
'';
|
|
};
|
|
|
|
mkTest = { name ? "unamed", testScript, testConfig, env ? { }, ... }:
|
|
with testPkgs;
|
|
let
|
|
env' = {
|
|
DHALL_PRELUDE = "${testPkgs.dhallPrelude}/package.dhall";
|
|
DHALL_GENODE = "${testPkgs.dhallGenode}/package.dhall";
|
|
BASE_MANIFEST = testPkgs.genode.base.manifest;
|
|
BASE_LINUX_MANIFEST = testPkgs.genode.base-linux.manifest;
|
|
OS_MANIFEST = testPkgs.genode.os.manifest;
|
|
} // env;
|
|
|
|
toExports = env:
|
|
with builtins;
|
|
let
|
|
keys = attrNames env;
|
|
f = key: ''set env(${key}) "${getAttr key env}"'';
|
|
exports = map f keys;
|
|
in concatStringsSep "\n" exports;
|
|
|
|
baseSetup = ''
|
|
${toExports env'}
|
|
|
|
proc run_genode_until {{wait_for_re forever} {timeout_value 0} {running_spawn_id -1}} {
|
|
#
|
|
# If a running_spawn_id is specified, wait for the expected output
|
|
#
|
|
if {$running_spawn_id != -1} {
|
|
wait_for_output $wait_for_re $timeout_value $running_spawn_id
|
|
return
|
|
}
|
|
|
|
global image_dir spawn_id
|
|
|
|
global env
|
|
set env(XDG_CACHE_HOME) /tmp
|
|
|
|
puts "${apps.linux-image.program} ${./driver-linux-config.dhall} ${testConfig}"
|
|
exec ${apps.linux-image.program} \
|
|
${./driver-linux-config.dhall} ${testConfig}
|
|
|
|
spawn ./core-linux
|
|
wait_for_output $wait_for_re $timeout_value $spawn_id
|
|
}
|
|
'';
|
|
|
|
driver = with hostPkgs;
|
|
runCommand "genode-test-driver-${name}" {
|
|
buildInputs = [ makeWrapper expect ];
|
|
inherit baseSetup testConfig testScript;
|
|
preferLocalBuild = true;
|
|
testName = name;
|
|
} ''
|
|
mkdir -p $out/bin
|
|
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 testScript=\"\$(cat $out/test-script)\"" \
|
|
--run "export baseSetup=\"\$(cat $out/base-setup)\"" \
|
|
'';
|
|
|
|
test = runTests driver;
|
|
|
|
in test // {
|
|
inherit driver test;
|
|
config = hostPkgs.runCommand (name + ".dhall") env' ''
|
|
${apps.dhall.program} <<< "(${
|
|
./driver-linux-config.dhall
|
|
} ${testConfig})" > $out
|
|
'';
|
|
xml = hostPkgs.runCommand (name + ".config") env' ''
|
|
${apps.render-init.program} "(${
|
|
./driver-linux-config.dhall
|
|
} ${testConfig}).config" > $out
|
|
'';
|
|
image = hostPkgs.runCommand (name + ".config") env' ''
|
|
mkdir -p $out
|
|
pushd $out
|
|
${apps.linux-image.program} "${./driver-linux-config.dhall} ${testConfig}"
|
|
'';
|
|
};
|
|
|
|
in {
|
|
callTest = path: args:
|
|
(import path ({
|
|
testEnv = {
|
|
inherit mkTest lib;
|
|
isLinux = true;
|
|
isNova = false;
|
|
};
|
|
pkgs = testPkgs;
|
|
inherit depot;
|
|
} // args));
|
|
}
|