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
This commit is contained in:
Christian Prochaska 2017-08-07 15:24:40 +02:00 committed by Christian Helmuth
parent 7a006ccf50
commit ee352abc56
7 changed files with 112 additions and 1 deletions

View File

@ -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

View File

@ -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 }

View File

@ -47,7 +47,7 @@ append config {
<resource name="RAM" quantum="4M"/>
<provides><service name="Nic"/></provides>
</start>
<start name="lighttpd">
<start name="lighttpd" caps="200">
<resource name="RAM" quantum="1G" />
<config>
<arg value="lighttpd" />
@ -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

38
tool/run/log/xen Normal file
View File

@ -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
}

3
tool/run/power_off/xen Normal file
View File

@ -0,0 +1,3 @@
proc run_power_off { } {
catch { exec sudo xl destroy "genode-hvm" }
}

36
tool/run/power_on/xen Normal file
View File

@ -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
}

31
tool/run/xen.inc Normal file
View File

@ -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
}