From a2a152b68a53689db29b083af4ecbc186fe7a8aa Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Sun, 8 Nov 2020 17:25:35 +0100 Subject: [PATCH] tests: add Bash test Test Bash and Coretuils from the Genode Labs ports. --- packages/genodelabs/default.nix | 2 +- packages/genodelabs/depot-targets.nix | 18 +++ packages/genodelabs/ports.nix | 5 + tests/bash.dhall | 170 ++++++++++++++++++++++++++ tests/bash.nix | 24 ++++ tests/default.nix | 1 + 6 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 tests/bash.dhall create mode 100644 tests/bash.nix diff --git a/packages/genodelabs/default.nix b/packages/genodelabs/default.nix index 186f766..11deab8 100644 --- a/packages/genodelabs/default.nix +++ b/packages/genodelabs/default.nix @@ -301,7 +301,7 @@ let in makePackages // depotPackages // { genodeSources = genodeSources // { - inherit buildUpstream buildDepot genodeBase ports specs toolchain; + inherit arch buildUpstream buildDepot genodeBase ports specs toolchain; }; base-hw-pc = buildUpstream { diff --git a/packages/genodelabs/depot-targets.nix b/packages/genodelabs/depot-targets.nix index 898a2cf..18b4e4c 100644 --- a/packages/genodelabs/depot-targets.nix +++ b/packages/genodelabs/depot-targets.nix @@ -21,8 +21,26 @@ in { acpi_drv = { }; + bash = { + enableParallelBuilding = false; + nativeBuildInputs = with buildPackages; [ autoconf ]; + portInputs = with ports; [ bash libc ]; + postInstall = '' + find depot/genodelabs/bin/ -name '*.tar' -exec tar xf {} -C $out \; + rm "''${!outputBin}/bin/bashbug" + ''; + }; + cached_fs_rom.patches = [ ./cached_fs_rom.patch ]; + coreutils = { + enableParallelBuilding = false; + portInputs = with ports; [ coreutils libc ]; + postInstall = '' + find depot/genodelabs/bin/ -name '*.tar' -exec tar xf {} -C $out \; + ''; + }; + fb_sdl = with buildPackages; { nativeBuildInputs = [ pkgconfig ]; buildInputs = [ SDL ]; diff --git a/packages/genodelabs/ports.nix b/packages/genodelabs/ports.nix index 9cb2c2e..83e65c8 100644 --- a/packages/genodelabs/ports.nix +++ b/packages/genodelabs/ports.nix @@ -5,10 +5,15 @@ with pkgs; { + bash.hash = "sha256-Se03Eyh8grk+QGAXLGoig7oXqmHtAwtHJX54fCVHw+8="; + binutils = { hash = "sha256-ERzYT3TjbK3fzRVN1UE7RM6XiPPeMKzkeulKx5IQa2o="; nativeBuildInputs = [ autoconf ]; }; + + coreutils.hash = "sha256-ZVlFfLghHcXxwwRsN5xw2bVdIvvXoCNj2oZniOlSXrg="; + dde_bsd.hash = "sha256-/n9aHPU6/+AgRSyFD545p3BT63n3myymez1tIRhJisA="; dde_ipxe.hash = "sha256-NJ129+DkxFg1fFHJBABBFRRjqEVNSz6v2hEB80AuEM4="; dde_linux.hash = "sha256-xHAgeKfArgMGKCGHi0762qkUcY97vbiAQYjM/ZRXCes="; diff --git a/tests/bash.dhall b/tests/bash.dhall new file mode 100644 index 0000000..020aa8e --- /dev/null +++ b/tests/bash.dhall @@ -0,0 +1,170 @@ +let Genode = env:DHALL_GENODE + +let Prelude = Genode.Prelude + +let XML = Prelude.XML + +let VFS = Genode.VFS + +let Init = Genode.Init + +let Child = Init.Child + +in λ(params : { bash : Text, coreutils : Text }) → + let init = + Init::{ + , verbose = True + , routes = + [ Init.ServiceRoute.parent "Timer" + , Init.ServiceRoute.parent "Rtc" + ] + , children = toMap + { vfs = + Child.flat + Child.Attributes::{ + , binary = "vfs" + , provides = [ "File_system" ] + , resources = Genode.Init.Resources::{ + , caps = 256 + , ram = Genode.units.MiB 8 + } + , routes = + Prelude.List.map + Text + Init.ServiceRoute.Type + Init.ServiceRoute.parent + [ "File_system", "Rtc" ] + , config = Init.Config::{ + , content = + [ VFS.vfs + [ VFS.dir + "dev" + [ VFS.dir "pipes" [ VFS.leaf "pipe" ] + , VFS.leaf "log" + , VFS.leaf "null" + , VFS.leaf "rtc" + , VFS.leaf "zero" + ] + , VFS.dir + "usr" + [ VFS.dir + "bin" + [ VFS.symlink + "env" + "${params.coreutils}/bin/env" + ] + ] + , VFS.dir "ram" [ VFS.leaf "ram" ] + , VFS.dir + "nix" + [ VFS.dir + "store" + [ VFS.fs VFS.FS::{ label = "nix-store" } ] + ] + , VFS.inline + "script.sh" + '' + bash --version + bash -c "bash --version" + '' + ] + ] + , policies = + [ Init.Config.Policy::{ + , service = "File_system" + , label = Init.LabelSelector.prefix "shell" + , attributes = toMap + { root = "/", writeable = "yes" } + } + , Init.Config.Policy::{ + , service = "File_system" + , label = Init.LabelSelector.prefix "vfs_rom" + , attributes = toMap { root = "/" } + } + ] + } + } + , vfs_rom = + Child.flat + Child.Attributes::{ + , binary = "cached_fs_rom" + , provides = [ "ROM" ] + , resources = Init.Resources::{ + , caps = 256 + , ram = Genode.units.MiB 32 + } + , config = Init.Config::{ + , policies = + [ Init.Config.Policy::{ + , service = "ROM" + , label = Init.LabelSelector.prefix "shell" + } + ] + } + } + , shell = + Child.flat + Child.Attributes::{ + , binary = "${params.bash}/bin/bash" + , exitPropagate = True + , resources = Genode.Init.Resources::{ + , caps = 256 + , ram = Genode.units.MiB 8 + } + , routes = + Prelude.List.map + Text + Init.ServiceRoute.Type + ( λ(label : Text) → + Init.ServiceRoute.parentLabel + "ROM" + (Some label) + (Some label) + ) + [ "libc.lib.so" + , "libm.lib.so" + , "posix.lib.so" + , "vfs.lib.so" + ] + , config = Genode.Init.Config::{ + , attributes = toMap { ld_verbose = "true" } + , content = + let env = + λ(key : Text) → + λ(value : Text) → + XML.leaf + { name = "env" + , attributes = toMap { key, value } + } + + let arg = + λ(value : Text) → + XML.leaf + { name = "arg" + , attributes = toMap { value } + } + + in [ XML.leaf + { name = "libc" + , attributes = toMap + { stdin = "/dev/null" + , stdout = "/dev/log" + , stderr = "/dev/log" + , pipe = "/dev/pipe" + , rtc = "/dev/rtc" + } + } + , VFS.vfs [ VFS.fs VFS.FS::{ label = "root" } ] + , env "TERM" "screen" + , env + "PATH" + "${params.coreutils}/bin:${params.bash}/bin" + , arg "bash" + , arg "/script.sh" + ] + } + } + } + } + + in Init.toChild init Init.Attributes::{=} diff --git a/tests/bash.nix b/tests/bash.nix new file mode 100644 index 0000000..26309d1 --- /dev/null +++ b/tests/bash.nix @@ -0,0 +1,24 @@ +{ + name = "bash"; + machine = { pkgs, ... }: { + genode.init.children.bash = { + configFile = pkgs.writeText "bash.child.dhall" '' + ${ + ./bash.dhall + } { bash = "${pkgs.genodePackages.bash}", coreutils = "${pkgs.coreutils}" } + ''; + inputs = with pkgs.genodePackages; [ + bash + cached_fs_rom + libc + posix + vfs + vfs_pipe + ]; + }; + }; + testScript = '' + start_all() + machine.wait_until_serial_output('child "bash" exited with exit value 0') + ''; +} diff --git a/tests/default.nix b/tests/default.nix index f002555..a26b11d 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -8,6 +8,7 @@ let testingPython = import ./lib/testing-python.nix; testSpecs = map (p: import p) [ + ./bash.nix ./hello.nix ./log.nix ./solo5/multi.nix