2
0
Fork 0
genodepkgs/tests/driver-linux.nix

125 lines
3.5 KiB
Nix

# SPDX-License-Identifier: CC0-1.0
{ addManifest, apps, buildPackages, depot, lib, nixpkgs, testPkgs }:
let
testDriver = with buildPackages;
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:
buildPackages.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, testInputs ? [ ]
, env ? { }, ... }:
with testPkgs;
let
manifest = lib.mergeManifests (map addManifest
((with testPkgs; [ base-linux init sotest-producer ] ++ testInputs)));
testConfig' = "${./test-wrapper.dhall} ${testConfig} (toMap ${manifest})";
env' = {
DHALL_GENODE = "${testPkgs.dhallGenode}/source.dhall";
DHALL_GENODE_TEST = "${./test.dhall}";
} // env;
build = lib.linuxScript name env' testConfig';
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
exec sh ${build}/script
spawn ./core-linux
wait_for_output $wait_for_re $timeout_value $spawn_id
}
'';
driver = with buildPackages;
runCommand "genode-test-driver-${name}" {
buildInputs = [ makeWrapper expect ];
inherit baseSetup 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 build driver test;
config = lib.runDhallCommand (name + ".dhall") env' ''
${apps.dhall.program} <<< "(${testConfig'}).config" > $out
'';
xml = lib.runDhallCommand (name + ".config") env' ''
${apps.render-init.program} <<< "(${testConfig'}).config" > $out
'';
image = lib.runDhallCommand (name + ".image.elf") env' ''
mkdir -p $out
pushd $out
. ${build}/script
'';
};
in {
callTest = path: args:
(import path ({
testEnv = {
inherit mkTest lib;
isLinux = true;
isNova = false;
};
pkgs = testPkgs;
inherit nixpkgs depot buildPackages;
} // args));
}