hostap/tests/hwsim/vm/vm-run.sh
Johannes Berg e339511007 tests: Optionally start telnet server inside VMs
If telnetd is installed and --telnet <port> is passed on the
vm-run.sh command line, start a telnet server (directly connected
to bash, no login) inside the VM(s) to be able to look into them
when something is wrong. Use a user network in qemu with a single
host forward from the specified port for this, listening only on
'localhost'.

Please note that this provides unauthenticated access to the guest
system from anything that can open a TCP connection on the host system.
The guess system does have access to reading all files on the host that
the user account running kvm has access to (and even write access if the
default ROTAG ,readonly parameter is cleared). In other words, this
option should not be used on any multiuser systems where kvm is run
under user accounts that are not dedicated for testing purposes (i.e.,
do not have access to any files that should not be readable to
everyone).

This needs CONFIG_VIRTIO_NET=y in the guest kernel.

For parallel-vm.py, the --telnet argument specifies the base port
and each VM index (0, 1, ...) is added to it.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
2019-02-05 14:26:36 +02:00

160 lines
3.7 KiB
Bash
Executable file

#!/bin/bash
cd "$(dirname $0)"
if [ -z "$TESTDIR" ] ; then
TESTDIR=$(pwd)/../
fi
if [ -n "$HWSIM_TEST_LOG_DIR" ] ; then
LOGS="$HWSIM_TEST_LOG_DIR"
else
LOGS=/tmp/hwsim-test-logs
fi
# increase the memory size if you want to run with valgrind, 512 MB works
MEMORY=256
# Some ubuntu systems (notably 12.04) have issues with this - since the guest
# mounts as read-only it should be safe to not specify ,readonly. Override in
# vm-config if needed (see below)
ROTAG=,readonly
# set this to ttyS0 to see kvm messages (if something doesn't work)
KVMOUT=ttyS1
# you can set EPATH if you need anything extra in $PATH inside the VM
#EPATH=/some/dir
# extra KVM arguments, e.g., -s for gdbserver
#KVMARGS=-s
# number of channels each hwsim device supports
CHANNELS=1
test -f vm-config && . vm-config
test -f ~/.wpas-vm-config && . ~/.wpas-vm-config
if [ -z "$KERNEL" ] && [ -z "$KERNELDIR" ] ; then
echo "You need to set a KERNEL or KERNELDIR (in the environment or vm-config)"
exit 2
fi
if [ -z "$KERNEL" ] ; then
KERNEL=$KERNELDIR/arch/x86_64/boot/bzImage
fi
CMD=$TESTDIR/vm/inside.sh
unset RUN_TEST_ARGS
TIMESTAMP=$(date +%s)
DATE=$TIMESTAMP
CODECOV=no
TIMEWARP=0
TELNET_QEMU=
TELNET_ARG=0
DELAY=0
CODECOV_DIR=
while [ "$1" != "" ]; do
case $1 in
--timestamp ) shift
TIMESTAMP=$1
shift
;;
--ext ) shift
DATE=$TIMESTAMP.$1
shift
;;
--codecov ) shift
CODECOV=yes
;;
--codecov_dir ) shift
CODECOV_DIR=$1
shift
;;
--timewrap ) shift
TIMEWARP=1
;;
--telnet ) shift
TELNET_ARG=1
TELNET_QEMU="-net nic,model=virtio -net user,id=telnet,restrict=on,net=172.16.0.0/24,hostfwd=tcp:127.0.0.1:$1-:23"
shift
;;
--delay ) shift
DELAY=$1
shift
;;
* )
RUN_TEST_ARGS="$RUN_TEST_ARGS$1 "
shift
;;
esac
done
LOGDIR=$LOGS/$DATE
mkdir -p $LOGDIR
rm -f $LOGS/latest
ln -s $LOGDIR $LOGS/latest
if [ -n "$CODECOV_DIR" ]; then
cp -a $CODECOV_DIR/alt-wpa_supplicant $LOGDIR
cp -a $CODECOV_DIR/alt-hostapd $LOGDIR
cp -a $CODECOV_DIR/alt-hostapd-as $LOGDIR
cp -a $CODECOV_DIR/alt-hlr_auc_gw $LOGDIR
elif [ $CODECOV = "yes" ]; then
./build-codecov.sh $LOGDIR || exit 1
else
CODECOV=no
fi
if [ $DELAY -gt 0 ]; then
echo "Wait $DELAY seconds before starting VM"
sleep $DELAY
fi
echo "Starting test run in a virtual machine"
KVM=kvm
for kvmprog in kvm qemu-kvm; do
if $kvmprog --version &> /dev/null; then
KVM=$kvmprog
break
fi
done
argsfile=$(mktemp)
if [ $? -ne 0 ] ; then
exit 2
fi
function finish {
rm -f $argsfile
}
trap finish EXIT
echo "$RUN_TEST_ARGS" > $argsfile
$KVM \
-kernel $KERNEL -smp 4 \
$KVMARGS -m $MEMORY -nographic \
-fsdev local,security_model=none,id=fsdev-root,path=/$ROTAG \
-device virtio-9p-pci,id=fs-root,fsdev=fsdev-root,mount_tag=/dev/root \
-fsdev local,security_model=none,id=fsdev-logs,path="$LOGDIR",writeout=immediate \
-device virtio-9p-pci,id=fs-logs,fsdev=fsdev-logs,mount_tag=logshare \
-monitor null -serial stdio -serial file:$LOGDIR/console \
$TELNET_QEMU \
-append "mac80211_hwsim.support_p2p_device=0 mac80211_hwsim.channels=$CHANNELS mac80211_hwsim.radios=7 cfg80211.dyndbg=+p mac80211.dyndbg=+p mac80211_hwsim.dyndbg=+p init=$CMD testdir=$TESTDIR timewarp=$TIMEWARP TELNET=$TELNET_ARG console=$KVMOUT root=/dev/root rootflags=trans=virtio,version=9p2000.u ro rootfstype=9p EPATH=$EPATH ARGS=$argsfile" | \
sed -u '0,/VM has started up/d'
if [ $CODECOV = "yes" ]; then
echo "Preparing code coverage reports"
./process-codecov.sh $LOGDIR "" restore
./combine-codecov.sh $LOGDIR lcov
fi
echo
echo "Test run completed"
echo "Logfiles are at $LOGDIR ($LOGS/latest)"
if [ $CODECOV = "yes" ]; then
echo "Code coverage report:"
echo "file://$LOGDIR/lcov/index.html"
fi