vm-run.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. if [ "$1" = "--ext" ]; then
  32. shift
  33. DATE=$(date +%s).$1
  34. shift
  35. else
  36. DATE=$(date +%s)
  37. fi
  38. LOGDIR=$LOGS/$DATE
  39. mkdir -p $LOGDIR
  40. if [ "$1" = "--codecov" ]; then
  41. shift
  42. CODECOV=yes
  43. DIR=$PWD
  44. if [ -e /tmp/logs ]; then
  45. echo "/tmp/logs exists - cannot prepare build trees"
  46. exit 1
  47. fi
  48. mkdir /tmp/logs
  49. echo "Preparing separate build trees for hostapd/wpa_supplicant"
  50. cd ../../..
  51. git archive --format=tar --prefix=hostap/ HEAD > /tmp/logs/hostap.tar
  52. cd $DIR
  53. cat ../../../wpa_supplicant/.config > /tmp/logs/wpa_supplicant.config
  54. echo "CONFIG_CODE_COVERAGE=y" >> /tmp/logs/wpa_supplicant.config
  55. cat ../../../hostapd/.config > /tmp/logs/hostapd.config
  56. echo "CONFIG_CODE_COVERAGE=y" >> /tmp/logs/hostapd.config
  57. cd /tmp/logs
  58. tar xf hostap.tar
  59. mv hostap alt-wpa_supplicant
  60. mv wpa_supplicant.config alt-wpa_supplicant/wpa_supplicant/.config
  61. tar xf hostap.tar
  62. mv hostap alt-hostapd
  63. cp hostapd.config alt-hostapd/hostapd/.config
  64. tar xf hostap.tar
  65. mv hostap alt-hostapd-as
  66. cp hostapd.config alt-hostapd-as/hostapd/.config
  67. tar xf hostap.tar
  68. mv hostap alt-hlr_auc_gw
  69. mv hostapd.config alt-hlr_auc_gw/hostapd/.config
  70. rm hostap.tar
  71. cd /tmp/logs/alt-wpa_supplicant/wpa_supplicant
  72. echo "Building wpa_supplicant"
  73. make -j8 > /dev/null
  74. cd /tmp/logs/alt-hostapd/hostapd
  75. echo "Building hostapd"
  76. make -j8 hostapd > /dev/null
  77. cd /tmp/logs/alt-hostapd-as/hostapd
  78. echo "Building hostapd (AS)"
  79. make -j8 hostapd > /dev/null
  80. cd /tmp/logs/alt-hlr_auc_gw/hostapd
  81. echo "Building hlr_auc_gw"
  82. make -j8 hlr_auc_gw > /dev/null
  83. cd $DIR
  84. mv /tmp/logs/alt-wpa_supplicant $LOGDIR
  85. mv /tmp/logs/alt-hostapd $LOGDIR
  86. mv /tmp/logs/alt-hostapd-as $LOGDIR
  87. mv /tmp/logs/alt-hlr_auc_gw $LOGDIR
  88. else
  89. CODECOV=no
  90. fi
  91. if [ "$1" == "--timewarp" ] ; then
  92. TIMEWARP=1
  93. shift
  94. else
  95. TIMEWARP=0
  96. fi
  97. echo "Starting test run in a virtual machine"
  98. kvm \
  99. -kernel $KERNEL -smp 4 \
  100. $KVMARGS -m $MEMORY -nographic \
  101. -fsdev local,security_model=none,id=fsdev-root,path=/$ROTAG \
  102. -device virtio-9p-pci,id=fs-root,fsdev=fsdev-root,mount_tag=/dev/root \
  103. -fsdev local,security_model=none,id=fsdev-logs,path="$LOGDIR",writeout=immediate \
  104. -device virtio-9p-pci,id=fs-logs,fsdev=fsdev-logs,mount_tag=logshare \
  105. -monitor null -serial stdio -serial file:$LOGDIR/console \
  106. -append "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=$*"
  107. if [ $CODECOV = "yes" ]; then
  108. mv $LOGDIR/alt-wpa_supplicant /tmp/logs
  109. mv $LOGDIR/alt-hostapd /tmp/logs
  110. mv $LOGDIR/alt-hostapd-as /tmp/logs
  111. mv $LOGDIR/alt-hlr_auc_gw /tmp/logs
  112. echo "Generating code coverage report for wpa_supplicant"
  113. cd /tmp/logs/alt-wpa_supplicant/wpa_supplicant
  114. lcov -c -d .. > lcov.info 2> lcov.log
  115. genhtml -t "wpa_supplicant hwsim test run $DATE" lcov.info --output-directory $LOGDIR/lcov-wpa_supplicant >> lcov.log 2>&1
  116. mv lcov.info lcov.log $LOGDIR/lcov-wpa_supplicant
  117. echo "Generating code coverage report for hostapd"
  118. cd /tmp/logs/alt-hostapd/hostapd
  119. lcov -c -d .. > lcov.info 2> lcov.log
  120. genhtml -t "hostapd hwsim test run $DATE" lcov.info --output-directory $LOGDIR/lcov-hostapd >> lcov.log 2>&1
  121. mv lcov.info lcov.log $LOGDIR/lcov-hostapd
  122. echo "Generating code coverage report for hostapd (AS)"
  123. cd /tmp/logs/alt-hostapd-as/hostapd
  124. lcov -c -d .. > lcov.info 2> lcov.log
  125. genhtml -t "hostapd (AS) hwsim test run $DATE" lcov.info --output-directory $LOGDIR/lcov-hostapd-as >> lcov.log 2>&1
  126. mv lcov.info lcov.log $LOGDIR/lcov-hostapd-as
  127. echo "Generating code coverage report for hlr_auc_gw"
  128. cd /tmp/logs/alt-hlr_auc_gw/hostapd
  129. lcov -c -d .. > lcov.info 2> lcov.log
  130. genhtml -t "hlr_auc_gw hwsim test run $DATE" lcov.info --output-directory $LOGDIR/lcov-hlr_auc_gw >> lcov.log 2>&1
  131. mv lcov.info lcov.log $LOGDIR/lcov-hlr_auc_gw
  132. echo "Generating combined code coverage report"
  133. mkdir $LOGDIR/lcov-combined
  134. for i in wpa_supplicant hostapd hostapd-as hlr_auc_gw; do
  135. sed s%SF:/tmp/logs/alt-[^/]*/%SF:/tmp/logs/alt-wpa_supplicant/% < $LOGDIR/lcov-$i/lcov.info > $LOGDIR/lcov-combined/$i.info
  136. done
  137. cd $LOGDIR/lcov-combined
  138. lcov -a wpa_supplicant.info -a hostapd.info -a hostapd-as.info -a hlr_auc_gw.info -o combined.info > lcov.log 2>&1
  139. genhtml -t "wpa_supplicant/hostapd combined for hwsim test run $DATE" combined.info --output-directory . >> lcov.log 2>&1
  140. cd $DIR
  141. rm -r /tmp/logs/alt-wpa_supplicant
  142. rm -r /tmp/logs/alt-hostapd
  143. rm -r /tmp/logs/alt-hostapd-as
  144. rm -r /tmp/logs/alt-hlr_auc_gw
  145. rmdir /tmp/logs
  146. fi
  147. echo
  148. echo "Test run completed"
  149. echo "Logfiles are at $LOGDIR"
  150. if [ $CODECOV = "yes" ]; then
  151. echo "Code coverage reports:"
  152. echo "wpa_supplicant: file://$LOGDIR/lcov-wpa_supplicant/index.html"
  153. echo "hostapd: file://$LOGDIR/lcov-hostapd/index.html"
  154. echo "hostapd (AS): file://$LOGDIR/lcov-hostapd-as/index.html"
  155. echo "hlr_auc_gw: file://$LOGDIR/lcov-hlr_auc_gw/index.html"
  156. echo "combined: file://$LOGDIR/lcov-combined/index.html"
  157. fi