genode/os/run/chroot_loader.run
Torsten Hilbrich df6a2f1365 chroot_loader: Fix run script for 64bit environment
The /lib64 path is required here to allow execution of 64bit binaries.

Here is an example-ldd call:

$ ldd /bin/ls
	linux-vdso.so.1 =>  (0x00007fffdedff000)
	libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f4ae207d000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f4ae1e75000)
	libacl.so.1 => /lib/x86_64-linux-gnu/libacl.so.1 (0x00007f4ae1c6c000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4ae18af000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4ae16ab000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f4ae22bd000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f4ae148d000)
	libattr.so.1 => /lib/x86_64-linux-gnu/libattr.so.1 (0x00007f4ae1288000)

Fixes #249
2012-06-20 19:44:08 +02:00

143 lines
3.5 KiB
Tcl

#
# \brief Test for using chroot on Linux
# \author Norman Feske
# \date 2012-06-06
#
#
if {![have_spec linux]} { puts "Run script requires Linux"; exit 0 }
#
# Build
#
build { core init app/chroot drivers/timer/linux test/timer
server/loader test/chroot_loader }
if {[catch { exec which setcap }]} {
puts stderr "Error: setcap not available, please install the libcap2-bin package"
return 0
}
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"/>
<service name="SIGNAL"/>
</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>
<start name="loader">
<resource name="RAM" quantum="1M"/>
<provides><service name="Loader"/></provides>
</start>
<start name="test-chroot_loader">
<resource name="RAM" quantum="32M"/>
<config>
<static_test chroot_path="chroot_path_1" />
<dynamic_test chroot_path="chroot_path_2" />
</config>
</start>
</config>
}
proc chroot_path { id } { return "/tmp/chroot-test-$id" }
proc chroot_cwd_path { id } { return "[chroot_path $id][pwd]/[run_dir]" }
proc chroot_genode_tmp_path { id } { return "[chroot_path $id]/tmp/genode-[exec id -u]" }
proc cleanup_chroot { } {
foreach id { 1 2 } {
catch { exec sudo umount -l [chroot_cwd_path $id] }
catch { exec sudo umount -l [chroot_genode_tmp_path $id] }
catch { exec sudo umount -l [chroot_path $id]/lib }
catch { exec sudo umount -l [chroot_path $id]/lib64 }
catch { exec rm -rf [chroot_path $id] }
}
}
# replace 'chroot_path' markers in config with actual paths
foreach id { 1 2 } {
regsub "chroot_path_$id" $config [chroot_path $id] 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.
#
foreach binary { core init chroot timer loader test-chroot_loader test-timer} {
exec cp -H bin/$binary [run_dir] }
#
# Grant chroot permission to 'chroot' tool
#
# CAP_SYS_ADMIN is needed for bind mounting genode runtime directories
# CAP_SYS_CHROOT is needed to perform the chroot syscall
#
exec sudo setcap cap_sys_admin,cap_sys_chroot=ep [run_dir]/chroot
#
# Setup chroot environment
#
# start with fresh directory
cleanup_chroot
foreach id { 1 2 } {
exec mkdir -p [chroot_path $id]
exec mkdir -p [chroot_path $id]/lib
exec mkdir -p [chroot_path $id]/lib64
# bind mount '/lib' as need libc within the chroot environment
exec sudo mount --bind /lib [chroot_path $id]/lib
catch { exec sudo mount --bind /lib64 [chroot_path $id]/lib64 }
}
#
# Execute test case
#
run_genode_until {.*--- chroot-loader test finished ---\s*\n} 60
#
# Validate log output
#
if {[regexp -all -- {--- timer test ---} $output] != 6} {
puts stderr "Number of spawned subsystems differs from 6"
exit 2
}
if {![regexp -- {chroot-1 -> test-timer] wait 2/10} $output]} {
puts stderr "Long-running timer test has made too little progress"
exit 3
}
#
# Remove artifacts created while running the test
#
cleanup_chroot
# vi: set ft=tcl :