From ee352abc56af7650be5d542b536d135f30008d02 Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Mon, 7 Aug 2017 15:24:40 +0200 Subject: [PATCH] run: add Xen support When building Genode on a Linux system running in a Xen Dom0, the 'xen' run target can run a Genode scenario in a Xen DomU. Usage: in build/x86_*/etc/build.conf, define: RUN_OPT = --include boot_dir/$(KERNEL) --include image/iso --include power_on/xen --include log/xen --include power_off/xen The Xen DomU runs in HVM mode and loads Genode from an ISO image. Serial log output is printed to the console and graphical output is shown in an SDL window. The Xen DomU ist managed using the 'xl' command line tool and it is possible to add configuration options in the 'xen_args' variable in a run script. Common options are: - disabling the graphical output: append xen_args { sdl="0" } - configuring a network device: append xen_args { vif=\["model=e1000,mac=02:00:00:00:01:01,bridge=xenbr0"\] } - configuring USB input devices: append xen_args { usbdevice=\["mouse","keyboard"\] } Note: the 'xl' tool requires super-user permissions and interactive password input can be troublesome in combination with 'expect' and is not practical for automatic tests. For this reason, the current implementation assumes that no password input is needed when running 'sudo xl', which can be achieved by creating a file '/etc/sudoers.d/xl' with the content 'user ALL=(root) NOPASSWD: /usr/sbin/xl' (where 'user' is the Linux user name). Fixes #2504 --- repos/base/run/log.run | 1 + repos/dde_linux/run/usb_hid.run | 1 + repos/ports/run/lighttpd.run | 3 ++- tool/run/log/xen | 38 +++++++++++++++++++++++++++++++++ tool/run/power_off/xen | 3 +++ tool/run/power_on/xen | 36 +++++++++++++++++++++++++++++++ tool/run/xen.inc | 31 +++++++++++++++++++++++++++ 7 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 tool/run/log/xen create mode 100644 tool/run/power_off/xen create mode 100644 tool/run/power_on/xen create mode 100644 tool/run/xen.inc diff --git a/repos/base/run/log.run b/repos/base/run/log.run index e246a8a5f..68e5623f8 100644 --- a/repos/base/run/log.run +++ b/repos/base/run/log.run @@ -23,6 +23,7 @@ install_config { build_boot_image "core ld.lib.so init test-log" append qemu_args "-nographic " +append xen_args { sdl="0" } run_genode_until "Test done.*\n" 20 diff --git a/repos/dde_linux/run/usb_hid.run b/repos/dde_linux/run/usb_hid.run index 70f5c3a86..a3b9870db 100644 --- a/repos/dde_linux/run/usb_hid.run +++ b/repos/dde_linux/run/usb_hid.run @@ -143,6 +143,7 @@ build_boot_image $boot_modules append qemu_args " -usb -usbdevice mouse -usbdevice keyboard" append qemu_args " -device usb-ehci,id=ehci" +append xen_args { usbdevice=\["mouse","keyboard"\] } if { [have_include "power_on/qemu"] || ![get_cmd_switch --autopilot] } { run_genode_until forever } diff --git a/repos/ports/run/lighttpd.run b/repos/ports/run/lighttpd.run index e11c1645b..ed1d719c4 100644 --- a/repos/ports/run/lighttpd.run +++ b/repos/ports/run/lighttpd.run @@ -47,7 +47,7 @@ append config { - + @@ -123,5 +123,6 @@ append_if [have_spec lan9118] qemu_args " -net nic,model=lan9118 " append qemu_args " -net user -redir tcp:5555::80 " append qemu_args " -nographic -serial mon:stdio " +append xen_args { sdl=0\; vif=\["model=e1000,mac=02:00:00:00:01:01,bridge=xenbr0"\] } run_genode_until forever diff --git a/tool/run/log/xen b/tool/run/log/xen new file mode 100644 index 000000000..cd926bbbb --- /dev/null +++ b/tool/run/log/xen @@ -0,0 +1,38 @@ +## +# Capture the output of a scenario executed via Xen +# + +source [genode_dir]/tool/run/log.inc +source [genode_dir]/tool/run/xen.inc + + +proc run_log { wait_for_re timeout_value } { + global xen_spawn_id + global output_spawn_id + + set output_spawn_id $xen_spawn_id + + set kernel_msg [run_boot_string] + + if {$wait_for_re == "forever"} { + set timeout -1 + } else { + set timeout $timeout_value + } + + expect { + -i $output_spawn_id $kernel_msg { } + eof { + puts stderr "Aborting, received EOF" + return false + } + timeout { + puts stderr "Boot process timed out" + close + return false + } + } + + wait_for_output $wait_for_re $timeout_value $xen_spawn_id + return true +} diff --git a/tool/run/power_off/xen b/tool/run/power_off/xen new file mode 100644 index 000000000..24e5dba83 --- /dev/null +++ b/tool/run/power_off/xen @@ -0,0 +1,3 @@ +proc run_power_off { } { + catch { exec sudo xl destroy "genode-hvm" } +} diff --git a/tool/run/power_on/xen b/tool/run/power_on/xen new file mode 100644 index 000000000..5a9d0c7b4 --- /dev/null +++ b/tool/run/power_on/xen @@ -0,0 +1,36 @@ +## +# Reset the target machine or rather run the scenario as Xen DomU +# + +source [genode_dir]/tool/run/xen.inc + + +## +# Execute scenario using xl +# +proc run_power_on { } { + global xen_args + global xen_spawn_id + + # + # Back out on platforms w/o Xen support + # + if {![is_xen_available]} { return 0 } + + set xen_base_args { \ + builder="hvm"\; \ + name="genode-hvm"\; \ + cpus="1"\; \ + memory="512"\; \ + serial="pty"\; \ + sdl="1"\; \ + vnc="0"\; \ + disk=\["file:[run_dir].iso,hdc:cdrom,r"\]\; \ + boot="d"\; \ + } + + eval spawn sudo xl create -c /dev/null $xen_base_args $xen_args + set xen_spawn_id $spawn_id + + return true +} diff --git a/tool/run/xen.inc b/tool/run/xen.inc new file mode 100644 index 000000000..f2f8b0a43 --- /dev/null +++ b/tool/run/xen.inc @@ -0,0 +1,31 @@ +set xen_spawn_id "" +set xen_args [get_cmd_arg --xen-args ""] + + +# +# Enable run scripts to extend 'xen_arg' via 'append' without bothering +# about the required whitespace in front of the custom arguments. +# +append xen_args " " + + +proc xen_args { } { + global xen_args + return $xen_args +} + + +## +# Check whether Xen support is available +# +# XXX should by removed in favor of [have_include "exec/xen"] +# +proc is_xen_available { } { + if {[have_spec linux]} { return false } + + if {![have_spec x86]} { + puts stderr "skipping execution because platform is not supported by Xen" + return false + } + return true +}