From 5922617eab9ce52e742ccc732442bd079ad4635f Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Wed, 28 May 2014 14:48:33 +0200 Subject: [PATCH] vbox: add test for shared folders Issue #1176 --- repos/ports/run/virtualbox_auto.inc | 4 +- repos/ports/run/virtualbox_auto_disk.run | 5 + repos/ports/run/virtualbox_auto_share.run | 326 ++++++++++++++++++++ repos/ports/src/virtualbox/autotest/main.cc | 17 +- tool/autopilot.list | 3 +- 5 files changed, 349 insertions(+), 6 deletions(-) create mode 100644 repos/ports/run/virtualbox_auto_share.run diff --git a/repos/ports/run/virtualbox_auto.inc b/repos/ports/run/virtualbox_auto.inc index 14a77fe14..703b24c73 100644 --- a/repos/ports/run/virtualbox_auto.inc +++ b/repos/ports/run/virtualbox_auto.inc @@ -5,7 +5,7 @@ if {[is_qemu_available]} { exit } -set build_components { +append build_components { core init virtualbox server/part_blk server/rump_fs @@ -122,7 +122,7 @@ append config { install_config $config -set boot_modules { +append boot_modules { core init timer part_blk ahci ld.lib.so libc.lib.so libm.lib.so pthread.lib.so diff --git a/repos/ports/run/virtualbox_auto_disk.run b/repos/ports/run/virtualbox_auto_disk.run index a09eec574..599c10ad6 100644 --- a/repos/ports/run/virtualbox_auto_disk.run +++ b/repos/ports/run/virtualbox_auto_disk.run @@ -1,4 +1,5 @@ # Tested for nova 64bit solely. +assert_spec nova assert_spec 64bit set use_vdi 1 @@ -28,6 +29,10 @@ source ${genode_dir}/repos/ports/run/virtualbox_auto.inc run_genode_until "vbox_auto_test_helper is done." 20 exec kill [exp_pid −i $spawn_id] +# reset values used before +set build_components { } +set boot_modules { } + set config_of_app { diff --git a/repos/ports/run/virtualbox_auto_share.run b/repos/ports/run/virtualbox_auto_share.run new file mode 100644 index 000000000..77b789e96 --- /dev/null +++ b/repos/ports/run/virtualbox_auto_share.run @@ -0,0 +1,326 @@ +# +# This script is used to test the shared folder support of Vbox@Genode/NOVA. +# +# Requirements to run this script: +# - hard disk with 4 primary partitions +# - on the 4. partition an ext2 filesystem is expected with following files: +# -- /win7.vdi +# -- /ram/overlay-original.vdi +# +# The overlay file must be generated beforehand, e.g.: +# +# vboxmanage showhdinfo win7.vdi +# +# to find out the size of the vdi and then to create the overlay: +# +# vboxmanage createhd --filename overlay-original.vdi --size [vdi_size] --format vdi +# +# +# +# +# The Windows image (win7.vdi) is prepared to contain a bat file with following +# content: +# +# :check +# IF EXIST E:\test.bat (GOTO start) ELSE (timeout /t 3 >nul) +# GOTO check +# +# :start +# +# call E:\test.bat +# +# This file must be configured to be autostarted by Windows, e.g change the +# value in the registry entry at +# +# HKEY_CURRENT_USER\Software/Microsoft\Windows\CurrentVersion\Run +# +# to the batch file in the Windows vdi image as described above. +# +# +# What this script does: +# +# A VM containing a Win7 image is started configured with two different +# Virtualbox fileshares (D: and E:). One contains a test file (test.bin), +# which will be copied by the Windows VM from the one file share over to the +# second one. +# On Genode side a Noux instance is running a bash shell with the two +# filesystems mounted. The shell is scripted by this script to wait for +# completion of the copy operation performed by the Windows VM. If this is +# detected, the bash scripts use sha1sum to generate hashes of the original +# test file of the one file system share and of the copy on the second file +# system share. This run scripts then compares the hashes and reports +# "Test succeeded" if they are identical. +# +# This script generates the test file out of /dev/urandom and generates a +# batch file test.bat which is placed in the shared folder for the VM. test.bat +# is invoked by the batch file running already in the Windows VM as described +# beforehand. test.bat contains the actual instructions to be performed by +# the VM - for this script to copy the test.bin file from D: to E:. + + + + +# Tested for nova 64bit solely. +assert_spec nova +assert_spec 64bit + +# +# Build Noux packages only once +# +foreach pkg {bash coreutils} { + lappend_if [expr ![file exists bin/$pkg]] build_components noux-pkg/$pkg } + +# +# Create .bat file to be executed by Win VM +# +set template_bat_fd [open "bin/template.bat" w] +puts $template_bat_fd {:check +IF EXIST E:\start.txt (GOTO start) ELSE (timeout /t 3 >nul) +GOTO check + +:start + +copy D:\test.bin E:\test.bin +copy D:\template.bat E:\done.txt +shutdown /s /t 00} + +close $template_bat_fd + +# Convert bat file to dos format +catch { exec unix2dos bin/template.bat } + +# +# Create random test binary to be copied via shared folder of vbox +# +catch { exec dd if=/dev/urandom of=bin/test.bin bs=4096 count=8160 } + + +# +# Step 0: prepare overlay.vdi for a clean run of the VM +# +set config_of_app { + + + + + + + + + + + + + + + +} + +source ${genode_dir}/repos/ports/run/virtualbox_auto.inc + +run_genode_until "vbox_auto_test_helper is done." 20 +exec kill [exp_pid −i $spawn_id] + + + +# +# Step 1: prepare and start the actual VM +# +exec tar cfv bin/bash.tar -h -C bin/bash . +exec tar cfv bin/coreutils.tar -h -C bin/coreutils . + +set build_components { + server/ram_fs + server/tcp_terminal drivers/nic + noux/minimal +} + +set boot_modules { + ram_fs + noux libc_noux.lib.so bash.tar coreutils.tar + tcp_terminal lwip.lib.so nic_drv + test.bin template.bat +} + +set config_of_app { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +} + +source ${genode_dir}/repos/ports/run/virtualbox_auto.inc + +# +# Step 2: Read out TCP/IP address of tcp_terminal running on Genode target +# +run_genode_until {\[init -> tcp_terminal\] listening on port 8888\.\.\.} 20 +set serial_id $spawn_id + +regexp {\[init -> tcp_terminal\] .{1,5}got IP address [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+} $output serial_ip_addr +regexp {[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+} $serial_ip_addr serial_ip_addr + +# +# Step 3: Wait until Windows is up for sure +# +run_genode_until {\[init -\> vbox\].*Guest Additions capability report:.*seamless: yes, hostWindowMapping: no, graphics: yes} 300 $serial_id + + +# +# Step 4 : connect to Noux of the running Genode target and issue bash commands +# via netcat +# +puts "\nTest shared folder\n" + +spawn netcat $serial_ip_addr 8888 +set noux_id $spawn_id + +run_genode_until {\[init -> tcp_terminal\] connection established} 20 $serial_id + +# +# Step 5 : interact with netcat -> ... -> tcp_terminal -> Noux -> bash +# + +# Windows does not like trailing zeros introduced by our ROM service. +# -> .bat script does not find labels like 'check' with zero bytes +# so - delete zero bytes +puts $noux_id "cat from/template\.bat | tr -d \"\\0\" >to/test\.bat" + +# SHA1 of original file +puts $noux_id "sha1sum from/test.bin" + +# Tell Windows VM to start copying +puts $noux_id "echo \"start\" > to/start\.txt" + +# Wait until Windows finished copying +puts $noux_id "while \[ ! -f to/done\.txt ]" +puts $noux_id "do" +puts $noux_id "sleep 5" +puts $noux_id "done" + +# Wait until VM signaled shutdown state +run_genode_until {\[init -\> vbox\].*Changing the VM state from 'POWERING_OFF' to 'OFF'} 120 $serial_id + +# SHA1 of copied file +puts $noux_id "sha1sum to/test.bin" + +# Wait for output of bash shell until last SHA1 sum is calculated +run_genode_until {[[:xdigit:]]+ to/test\.bin} 50 $noux_id + + +# cleanup created files +foreach pkg {bash coreutils} { exec rm -f bin/$pkg.tar } +exec rm -f bin/test.bin +exec rm -f bin/template.bat + + +# +# Step 5: Compare sha1sum of original file and of copy made by .bat file in VM +# +set sha1sum_original [regexp -inline {[[:xdigit:]]+ from/test\.bin} $output] +set sha1sum_copy [regexp -inline {[[:xdigit:]]+ to/test\.bin} $output] +set sha1sum_original [regexp -inline {[[:xdigit:]]+} $sha1sum_original] +set sha1sum_copy [regexp -inline {[[:xdigit:]]+} $sha1sum_copy] + +puts -nonewline "\n$sha1sum_original ?= $sha1sum_copy --> " +if {$sha1sum_original eq ""} { + puts " empty -> no " +} else { + if {$sha1sum_original != $sha1sum_copy} { + puts "no" + } else { + puts "yes" + puts "\nTest succeeded" + } +} diff --git a/repos/ports/src/virtualbox/autotest/main.cc b/repos/ports/src/virtualbox/autotest/main.cc index f26c54943..d4c16d615 100644 --- a/repos/ports/src/virtualbox/autotest/main.cc +++ b/repos/ports/src/virtualbox/autotest/main.cc @@ -3,8 +3,9 @@ #include #include +#include -static char buf[256]; +static char buf[128 * 1024]; int main(int argc, char **argv) { @@ -22,8 +23,18 @@ int main(int argc, char **argv) return 1; while ((len = read(fd_src, buf, sizeof(buf))) > 0) { - write(fd_dst, buf, len); - sum += len; + while (len) { + ssize_t written = write(fd_dst, buf, len); + len -= written; + sum += written; + + if (written > 0 && len >= 0) + continue; + + PERR("could not write whole file - %zu %zu %d\n", + sum, written, errno); + return -1; + } } close(fd_src); close(fd_dst); diff --git a/tool/autopilot.list b/tool/autopilot.list index 85d4c8952..6e6fe0c40 100644 --- a/tool/autopilot.list +++ b/tool/autopilot.list @@ -40,6 +40,7 @@ part_blk xml_generator blk_cache rump_ext2 -virtualbox_auto_disk thread pthread +virtualbox_auto_disk +virtualbox_auto_share