vm-run.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/bin/bash
  2. cd "$(dirname $0)"
  3. if [ -z "$TESTDIR" ] ; then
  4. TESTDIR=$(pwd)/../
  5. fi
  6. if [ -n "$HWSIM_TEST_LOG_DIR" ] ; then
  7. LOGS="$HWSIM_TEST_LOG_DIR"
  8. else
  9. LOGS=/tmp/hwsim-test-logs
  10. fi
  11. # increase the memory size if you want to run with valgrind, 512 MB works
  12. MEMORY=192
  13. # Some ubuntu systems (notably 12.04) have issues with this - since the guest
  14. # mounts as read-only it should be safe to not specify ,readonly. Override in
  15. # vm-config if needed (see below)
  16. ROTAG=,readonly
  17. # set this to ttyS0 to see kvm messages (if something doesn't work)
  18. KVMOUT=ttyS1
  19. # you can set EPATH if you need anything extra in $PATH inside the VM
  20. #EPATH=/some/dir
  21. # extra KVM arguments, e.g., -s for gdbserver
  22. #KVMARGS=-s
  23. # number of channels each hwsim device supports
  24. CHANNELS=1
  25. test -f vm-config && . vm-config
  26. test -f ~/.wpas-vm-config && . ~/.wpas-vm-config
  27. if [ -z "$KERNEL" ] && [ -z "$KERNELDIR" ] ; then
  28. echo "You need to set a KERNEL or KERNELDIR (in the environment or vm-config)"
  29. exit 2
  30. fi
  31. if [ -z "$KERNEL" ] ; then
  32. KERNEL=$KERNELDIR/arch/x86_64/boot/bzImage
  33. fi
  34. CMD=$TESTDIR/vm/inside.sh
  35. unset RUN_TEST_ARGS
  36. TIMESTAMP=$(date +%s)
  37. DATE=$TIMESTAMP
  38. CODECOV=no
  39. TIMEWARP=0
  40. DELAY=0
  41. CODECOV_DIR=
  42. while [ "$1" != "" ]; do
  43. case $1 in
  44. --timestamp ) shift
  45. TIMESTAMP=$1
  46. shift
  47. ;;
  48. --ext ) shift
  49. DATE=$TIMESTAMP.$1
  50. shift
  51. ;;
  52. --codecov ) shift
  53. CODECOV=yes
  54. ;;
  55. --codecov_dir ) shift
  56. CODECOV_DIR=$1
  57. shift
  58. ;;
  59. --timewrap ) shift
  60. TIMEWARP=1
  61. ;;
  62. --delay ) shift
  63. DELAY=$1
  64. shift
  65. ;;
  66. * )
  67. RUN_TEST_ARGS="$RUN_TEST_ARGS$1 "
  68. shift
  69. ;;
  70. esac
  71. done
  72. LOGDIR=$LOGS/$DATE
  73. mkdir -p $LOGDIR
  74. if [ -n "$CODECOV_DIR" ]; then
  75. cp -a $CODECOV_DIR/alt-wpa_supplicant $LOGDIR
  76. cp -a $CODECOV_DIR/alt-hostapd $LOGDIR
  77. cp -a $CODECOV_DIR/alt-hostapd-as $LOGDIR
  78. cp -a $CODECOV_DIR/alt-hlr_auc_gw $LOGDIR
  79. elif [ $CODECOV = "yes" ]; then
  80. ./build-codecov.sh $LOGDIR || exit 1
  81. else
  82. CODECOV=no
  83. fi
  84. if [ $DELAY -gt 0 ]; then
  85. echo "Wait $DELAY seconds before starting VM"
  86. sleep $DELAY
  87. fi
  88. echo "Starting test run in a virtual machine"
  89. KVM=kvm
  90. for kvmprog in kvm qemu-kvm; do
  91. if $kvmprog --version &> /dev/null; then
  92. KVM=$kvmprog
  93. break
  94. fi
  95. done
  96. argsfile=$(mktemp)
  97. if [ $? -ne 0 ] ; then
  98. exit 2
  99. fi
  100. function finish {
  101. rm -f $argsfile
  102. }
  103. trap finish EXIT
  104. echo "$RUN_TEST_ARGS" > $argsfile
  105. $KVM \
  106. -kernel $KERNEL -smp 4 \
  107. $KVMARGS -m $MEMORY -nographic \
  108. -fsdev local,security_model=none,id=fsdev-root,path=/$ROTAG \
  109. -device virtio-9p-pci,id=fs-root,fsdev=fsdev-root,mount_tag=/dev/root \
  110. -fsdev local,security_model=none,id=fsdev-logs,path="$LOGDIR",writeout=immediate \
  111. -device virtio-9p-pci,id=fs-logs,fsdev=fsdev-logs,mount_tag=logshare \
  112. -monitor null -serial stdio -serial file:$LOGDIR/console \
  113. -append "mac80211_hwsim.support_p2p_device=0 mac80211_hwsim.channels=$CHANNELS mac80211_hwsim.radios=7 mac80211_hwsim.dyndbg=+p init=$CMD testdir=$TESTDIR timewarp=$TIMEWARP console=$KVMOUT root=/dev/root rootflags=trans=virtio,version=9p2000.u ro rootfstype=9p EPATH=$EPATH ARGS=$argsfile"
  114. if [ $CODECOV = "yes" ]; then
  115. echo "Preparing code coverage reports"
  116. ./process-codecov.sh $LOGDIR "" restore
  117. ./combine-codecov.sh $LOGDIR lcov
  118. fi
  119. echo
  120. echo "Test run completed"
  121. echo "Logfiles are at $LOGDIR"
  122. if [ $CODECOV = "yes" ]; then
  123. echo "Code coverage report:"
  124. echo "file://$LOGDIR/lcov/index.html"
  125. fi