From: Richard Jones Date: Thu, 26 Nov 2009 15:17:37 +0000 (+0000) Subject: daemon/Win32: Add contributed test script to test daemon using Wine. X-Git-Tag: 1.0.80~19 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=4d53df4d7399d35b51bd69d76e00539d1de825e0;p=libguestfs.git daemon/Win32: Add contributed test script to test daemon using Wine. This test script allows you to test limited features of the Windows daemon by running it on a standard Fedora host using Wine. Read contrib/README and contrib/guestfsd-in-wine.sh in detail before using. --- diff --git a/.gitignore b/.gitignore index 8ef94ff..484b947 100644 --- a/.gitignore +++ b/.gitignore @@ -72,6 +72,7 @@ guestfs.3 guestfs-actions.pod guestfs-availability.pod guestfs-structs.pod +guestfsd-in-wine.log haskell/Bindtests haskell/Bindtests.hs haskell/Guestfs005Load diff --git a/contrib/README b/contrib/README index 2ae2c51..1e6ea7e 100644 --- a/contrib/README +++ b/contrib/README @@ -14,3 +14,7 @@ fedora-libguestfs.spec This used to be a Fedora 10+ specfile. Please use the specfile from Fedora instead: http://cvs.fedoraproject.org/viewvc/rpms/libguestfs/devel/ + +guestfsd-in-wine.sh + Run a Windows-compiled guestfsd under Wine. Read the + instructions at the top of this file carefully. diff --git a/contrib/guestfsd-in-wine.sh b/contrib/guestfsd-in-wine.sh new file mode 100755 index 0000000..aa5b482 --- /dev/null +++ b/contrib/guestfsd-in-wine.sh @@ -0,0 +1,121 @@ +#!/bin/bash - +# Copyright (C) 2009 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +# INSTRUCTIONS +#---------------------------------------------------------------------- +# +# This is a QEMU wrapper script that allows you to run a +# Windows-compiled guestfsd.exe (daemon) under Wine from a Linux main +# program. You need to read and understand all the instructions below +# before use. +# +# To understand how to compile the daemon for Windows, please read: +# http://www.redhat.com/archives/libguestfs/2009-November/msg00255.html +# +# Adjust the Wine configuration so it can find the libraries, as +# described here: +# http://fedoraproject.org/wiki/MinGW/Configure_wine +# +# On Fedora 13 there is a serious bug in Wine. See: +# https://bugzilla.redhat.com/show_bug.cgi?id=533806#c11 +# +# If necessary, adjust the line 'guestfsd=...' below so it points to +# the correct location of the guestfsd.exe program. You can use an +# absolute path here if you want. +guestfsd=daemon/guestfsd.exe +# +# This script is a QEMU wrapper. It pretends to be qemu as far as +# libguestfs programs are concerned. Read this to understand the +# purpose of QEMU wrappers: +# http://libguestfs.org/guestfs.3.html#qemu_wrappers +# +# With this script, the qemu program is not actually run. Instead we +# pretend to be qemu, parse out the necessary parts of the long +# command line that libguestfs passes to qemu, and run the Windows +# daemon, under Wine, with the right command line. The Windows daemon +# then hopefully connects back to the libguestfs socket, and as far as +# the libguestfs program is concerned, it looks like a full appliance +# is running. +# +# To use this script, you must set the environment variable +# LIBGUESTFS_QEMU=/path/to/contrib/guestfsd-in-wine.sh (ie. the path +# to this script). +# +# You can then run libguestfs test programs, and (hopefully!) they'll +# use the Windows guestfsd.exe, simulating calls using Wine. +# +# For example from the top build directory: +# +# LIBGUESTFS_QEMU=contrib/guestfsd-in-wine.sh fish/guestfish +# +# You might also need to set the environment variable LIBGUESTFS_PATH +# to point to an appliance. The appliance will never be used, but +# libguestfs needs to find one. +# +# Another suggested environment variable is LIBGUESTFS_DEBUG=1 which +# will give you must more detail about what is going on. Also look at +# the contents of the log file 'guestfsd-in-wine.log' after each run. +# +#---------------------------------------------------------------------- + +# Note that stdout & stderr messages will get eaten by libguestfs +# early on in the process. Therefore write log messages to +# a log file. +exec 5>>guestfsd-in-wine.log +echo "Environment:" >&5 +printenv | grep LIBGUESTFS >&5 +echo "Command line:" >&5 +echo " $@" >&5 + +# We're called several times, first with -help and -version, and we +# have to pretend to be qemu! (At least enough to trick libguestfs). +if [ "$1" = "-help" ]; then + echo -- " -net user " + echo -- " -no-hpet " + echo -- " -rtc-td-hack " + exit 0 +elif [ "$1" = "-version" ]; then + echo -- "0.0.0" + exit 0 +fi + +# The interesting parameter is -append. +append= +while [ $# -gt 0 ]; do + if [ $1 = "-append" ]; then + append="$2" + shift + fi + shift +done +echo "Append parameter:" >&5 +echo " $append" >&5 + +# guestfs_vmchannel parameter. +vmchannel_param=$(echo "$append" | grep -Eo 'guestfs_vmchannel=[^[:space:]]+') +echo "Vmchannel parameter:" >&5 +echo " $vmchannel_param" >&5 + +# Port number. +port=$(echo "$vmchannel_param" | grep -Eo '[[:digit:]]+$') +echo "Port number:" >&5 +echo " $vmchannel_param" >&5 + +# Run guestfsd.exe. +echo "Command:" >&5 +echo " $guestfsd -f -v -c tcp:localhost:$port" >&5 +$guestfsd -f -v -c tcp:127.0.0.1:$port