vm-run.sh 5.4 KB

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