2012-04-18 14:56:15 +00:00
|
|
|
#
|
|
|
|
# \brief Test for using chroot on Linux
|
|
|
|
# \author Norman Feske
|
|
|
|
# \date 2012-04-18
|
|
|
|
#
|
|
|
|
#
|
|
|
|
if {![have_spec linux]} { puts "Run script requires Linux"; exit 0 }
|
|
|
|
|
|
|
|
#
|
|
|
|
# Build
|
|
|
|
#
|
|
|
|
|
2013-05-07 09:13:02 +00:00
|
|
|
build { core init drivers/timer test/timer }
|
2012-04-18 14:56:15 +00:00
|
|
|
|
|
|
|
if {[catch { exec which setcap }]} {
|
|
|
|
puts stderr "Error: setcap not available, please install the libcap2-bin package"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2013-05-07 09:13:02 +00:00
|
|
|
#
|
|
|
|
# Clean up remains of a potentially failed previous run
|
|
|
|
#
|
|
|
|
|
|
|
|
proc chroot_path { } { return "/tmp/chroot-test" }
|
|
|
|
proc chroot_cwd_path { } { return "[chroot_path][pwd]/[run_dir]" }
|
|
|
|
proc chroot_genode_tmp_path { } { return "[chroot_path]/tmp/genode-[exec id -u]" }
|
|
|
|
|
|
|
|
proc cleanup_chroot { } {
|
|
|
|
umount_and_rmdir [chroot_cwd_path]
|
|
|
|
umount_and_rmdir [chroot_path]/lib
|
|
|
|
umount_and_rmdir [chroot_path]/lib64
|
|
|
|
}
|
2012-04-18 14:56:15 +00:00
|
|
|
|
|
|
|
create_boot_directory
|
|
|
|
|
|
|
|
#
|
|
|
|
# Generate config
|
|
|
|
#
|
|
|
|
|
|
|
|
set config {
|
|
|
|
<config>
|
|
|
|
<parent-provides>
|
|
|
|
<service name="ROM"/>
|
|
|
|
<service name="LOG"/>
|
|
|
|
<service name="CAP"/>
|
|
|
|
<service name="RAM"/>
|
|
|
|
<service name="CPU"/>
|
|
|
|
<service name="RM"/>
|
|
|
|
<service name="PD"/>
|
2013-05-07 09:13:02 +00:00
|
|
|
<service name="SIGNAL"/>
|
2012-04-18 14:56:15 +00:00
|
|
|
</parent-provides>
|
|
|
|
<default-route>
|
|
|
|
<any-service> <parent/> <any-child/> </any-service>
|
|
|
|
</default-route>
|
|
|
|
<start name="timer">
|
|
|
|
<resource name="RAM" quantum="1M"/>
|
|
|
|
<provides><service name="Timer"/></provides>
|
|
|
|
</start>
|
2012-10-24 14:27:26 +00:00
|
|
|
<start name="test-timer" root="chroot_path">
|
2012-04-18 14:56:15 +00:00
|
|
|
<resource name="RAM" quantum="1G"/>
|
|
|
|
</start>
|
|
|
|
</config>
|
|
|
|
}
|
|
|
|
|
|
|
|
# replace 'chroot_path' marker in config with actual path
|
|
|
|
regsub "chroot_path" $config [chroot_path] config
|
|
|
|
|
|
|
|
install_config $config
|
|
|
|
|
|
|
|
#
|
|
|
|
# Copy boot modules into run directory
|
|
|
|
#
|
|
|
|
# We cannot use the predefined 'build_boot_image' function here because
|
|
|
|
# this would create mere symlinks. However, we want to hardlink the
|
|
|
|
# run directory into the chroot environment. If the directory entries
|
|
|
|
# were symlinks, those would point to nowhere within the chroot.
|
|
|
|
#
|
2012-10-24 14:27:26 +00:00
|
|
|
foreach binary { core init timer test-timer } {
|
2012-04-18 14:56:15 +00:00
|
|
|
exec cp -H bin/$binary [run_dir] }
|
|
|
|
|
|
|
|
#
|
2012-10-24 14:27:26 +00:00
|
|
|
# Grant chroot permission to core
|
2012-04-18 14:56:15 +00:00
|
|
|
#
|
|
|
|
# CAP_SYS_ADMIN is needed for bind mounting genode runtime directories
|
|
|
|
# CAP_SYS_CHROOT is needed to perform the chroot syscall
|
|
|
|
#
|
2012-10-24 14:27:26 +00:00
|
|
|
exec sudo setcap cap_sys_admin,cap_sys_chroot=ep [run_dir]/core
|
2012-04-18 14:56:15 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Setup chroot environment
|
|
|
|
#
|
|
|
|
|
|
|
|
# start with fresh directory
|
|
|
|
cleanup_chroot
|
|
|
|
exec mkdir -p [chroot_path]
|
2012-06-06 15:27:21 +00:00
|
|
|
exec mkdir -p [chroot_path]/lib
|
|
|
|
|
2012-10-24 14:27:26 +00:00
|
|
|
# bind mount '/lib' as we need ldso and libc within the chroot environment
|
|
|
|
exec sudo mount --bind /lib [chroot_path]/lib
|
2012-04-18 14:56:15 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Execute test case
|
|
|
|
#
|
|
|
|
run_genode_until {.*--- timer test finished ---.*} 60
|
|
|
|
|
|
|
|
#
|
|
|
|
# Remove artifacts created while running the test
|
|
|
|
#
|
|
|
|
cleanup_chroot
|
|
|
|
|
|
|
|
# vi: set ft=tcl :
|