vm-run.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #!/bin/bash
  2. cd "$(dirname $0)"
  3. if [ -z "$TESTDIR" ] ; then
  4. TESTDIR=$(pwd)/../
  5. fi
  6. LOGS=/tmp/hwsim-test-logs
  7. # increase the memory size if you want to run with valgrind, 512 MB works
  8. MEMORY=128
  9. # Some ubuntu systems (notably 12.04) have issues with this - since the guest
  10. # mounts as read-only it should be safe to not specify ,readonly. Override in
  11. # vm-config if needed (see below)
  12. ROTAG=,readonly
  13. # set this to ttyS0 to see kvm messages (if something doesn't work)
  14. KVMOUT=ttyS1
  15. # you can set EPATH if you need anything extra in $PATH inside the VM
  16. #EPATH=/some/dir
  17. # extra KVM arguments, e.g., -s for gdbserver
  18. #KVMARGS=-s
  19. # number of channels each hwsim device supports
  20. CHANNELS=1
  21. test -f vm-config && . vm-config
  22. test -f ~/.wpas-vm-config && . ~/.wpas-vm-config
  23. if [ -z "$KERNEL" ] && [ -z "$KERNELDIR" ] ; then
  24. echo "You need to set a KERNEL or KERNELDIR (in the environment or vm-config)"
  25. exit 2
  26. fi
  27. if [ -z "$KERNEL" ] ; then
  28. KERNEL=$KERNELDIR/arch/x86_64/boot/bzImage
  29. fi
  30. CMD=$TESTDIR/vm/inside.sh
  31. unset RUN_TEST_ARGS
  32. DATE=$(date +%s)
  33. CODECOV=no
  34. TIMEWARP=0
  35. while [ "$1" != "" ]; do
  36. case $1 in
  37. --ext ) shift
  38. DATE=$(date +%s).$1
  39. shift
  40. ;;
  41. --codecov ) shift
  42. CODECOV=yes
  43. ;;
  44. --timewrap ) shift
  45. TIMEWARP=1
  46. ;;
  47. * )
  48. RUN_TEST_ARGS="$RUN_TEST_ARGS$1 "
  49. shift
  50. ;;
  51. esac
  52. done
  53. LOGDIR=$LOGS/$DATE
  54. mkdir -p $LOGDIR
  55. if [ $CODECOV = "yes" ]; then
  56. DIR=$PWD
  57. if [ -e /tmp/logs ]; then
  58. echo "/tmp/logs exists - cannot prepare build trees"
  59. exit 1
  60. fi
  61. mkdir /tmp/logs
  62. echo "Preparing separate build trees for hostapd/wpa_supplicant"
  63. cd ../../..
  64. git archive --format=tar --prefix=hostap/ HEAD > /tmp/logs/hostap.tar
  65. cd $DIR
  66. cat ../../../wpa_supplicant/.config > /tmp/logs/wpa_supplicant.config
  67. echo "CONFIG_CODE_COVERAGE=y" >> /tmp/logs/wpa_supplicant.config
  68. cat ../../../hostapd/.config > /tmp/logs/hostapd.config
  69. echo "CONFIG_CODE_COVERAGE=y" >> /tmp/logs/hostapd.config
  70. cd /tmp/logs
  71. tar xf hostap.tar
  72. mv hostap alt-wpa_supplicant
  73. mv wpa_supplicant.config alt-wpa_supplicant/wpa_supplicant/.config
  74. tar xf hostap.tar
  75. mv hostap alt-hostapd
  76. cp hostapd.config alt-hostapd/hostapd/.config
  77. tar xf hostap.tar
  78. mv hostap alt-hostapd-as
  79. cp hostapd.config alt-hostapd-as/hostapd/.config
  80. tar xf hostap.tar
  81. mv hostap alt-hlr_auc_gw
  82. mv hostapd.config alt-hlr_auc_gw/hostapd/.config
  83. rm hostap.tar
  84. cd /tmp/logs/alt-wpa_supplicant/wpa_supplicant
  85. echo "Building wpa_supplicant"
  86. make -j8 > /dev/null
  87. cd /tmp/logs/alt-hostapd/hostapd
  88. echo "Building hostapd"
  89. make -j8 hostapd > /dev/null
  90. cd /tmp/logs/alt-hostapd-as/hostapd
  91. echo "Building hostapd (AS)"
  92. make -j8 hostapd > /dev/null
  93. cd /tmp/logs/alt-hlr_auc_gw/hostapd
  94. echo "Building hlr_auc_gw"
  95. make -j8 hlr_auc_gw > /dev/null
  96. cd $DIR
  97. mv /tmp/logs/alt-wpa_supplicant $LOGDIR
  98. mv /tmp/logs/alt-hostapd $LOGDIR
  99. mv /tmp/logs/alt-hostapd-as $LOGDIR
  100. mv /tmp/logs/alt-hlr_auc_gw $LOGDIR
  101. else
  102. CODECOV=no
  103. fi
  104. echo "Starting test run in a virtual machine"
  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=6 init=$CMD testdir=$TESTDIR timewarp=$TIMEWARP console=$KVMOUT root=/dev/root rootflags=trans=virtio,version=9p2000.u ro rootfstype=9p EPATH=$EPATH ARGS=$RUN_TEST_ARGS"
  114. if [ $CODECOV = "yes" ]; then
  115. mv $LOGDIR/alt-wpa_supplicant /tmp/logs
  116. mv $LOGDIR/alt-hostapd /tmp/logs
  117. mv $LOGDIR/alt-hostapd-as /tmp/logs
  118. mv $LOGDIR/alt-hlr_auc_gw /tmp/logs
  119. echo "Generating code coverage report for wpa_supplicant"
  120. cd /tmp/logs/alt-wpa_supplicant/wpa_supplicant
  121. lcov -c -d .. > lcov.info 2> lcov.log
  122. genhtml -t "wpa_supplicant hwsim test run $DATE" lcov.info --output-directory $LOGDIR/lcov-wpa_supplicant >> lcov.log 2>&1
  123. mv lcov.info lcov.log $LOGDIR/lcov-wpa_supplicant
  124. echo "Generating code coverage report for hostapd"
  125. cd /tmp/logs/alt-hostapd/hostapd
  126. lcov -c -d .. > lcov.info 2> lcov.log
  127. genhtml -t "hostapd hwsim test run $DATE" lcov.info --output-directory $LOGDIR/lcov-hostapd >> lcov.log 2>&1
  128. mv lcov.info lcov.log $LOGDIR/lcov-hostapd
  129. echo "Generating code coverage report for hostapd (AS)"
  130. cd /tmp/logs/alt-hostapd-as/hostapd
  131. lcov -c -d .. > lcov.info 2> lcov.log
  132. genhtml -t "hostapd (AS) hwsim test run $DATE" lcov.info --output-directory $LOGDIR/lcov-hostapd-as >> lcov.log 2>&1
  133. mv lcov.info lcov.log $LOGDIR/lcov-hostapd-as
  134. echo "Generating code coverage report for hlr_auc_gw"
  135. cd /tmp/logs/alt-hlr_auc_gw/hostapd
  136. lcov -c -d .. > lcov.info 2> lcov.log
  137. genhtml -t "hlr_auc_gw hwsim test run $DATE" lcov.info --output-directory $LOGDIR/lcov-hlr_auc_gw >> lcov.log 2>&1
  138. mv lcov.info lcov.log $LOGDIR/lcov-hlr_auc_gw
  139. echo "Generating combined code coverage report"
  140. mkdir $LOGDIR/lcov-combined
  141. for i in wpa_supplicant hostapd hostapd-as hlr_auc_gw; do
  142. sed s%SF:/tmp/logs/alt-[^/]*/%SF:/tmp/logs/alt-wpa_supplicant/% < $LOGDIR/lcov-$i/lcov.info > $LOGDIR/lcov-combined/$i.info
  143. done
  144. cd $LOGDIR/lcov-combined
  145. lcov -a wpa_supplicant.info -a hostapd.info -a hostapd-as.info -a hlr_auc_gw.info -o combined.info > lcov.log 2>&1
  146. genhtml -t "wpa_supplicant/hostapd combined for hwsim test run $DATE" combined.info --output-directory . >> lcov.log 2>&1
  147. cd $DIR
  148. rm -r /tmp/logs/alt-wpa_supplicant
  149. rm -r /tmp/logs/alt-hostapd
  150. rm -r /tmp/logs/alt-hostapd-as
  151. rm -r /tmp/logs/alt-hlr_auc_gw
  152. rmdir /tmp/logs
  153. fi
  154. echo
  155. echo "Test run completed"
  156. echo "Logfiles are at $LOGDIR"
  157. if [ $CODECOV = "yes" ]; then
  158. echo "Code coverage reports:"
  159. echo "wpa_supplicant: file://$LOGDIR/lcov-wpa_supplicant/index.html"
  160. echo "hostapd: file://$LOGDIR/lcov-hostapd/index.html"
  161. echo "hostapd (AS): file://$LOGDIR/lcov-hostapd-as/index.html"
  162. echo "hlr_auc_gw: file://$LOGDIR/lcov-hlr_auc_gw/index.html"
  163. echo "combined: file://$LOGDIR/lcov-combined/index.html"
  164. fi