vm-run.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. if [ -z "$KERNEL" ] && [ -z "$KERNELDIR" ] ; then
  23. echo "You need to set a KERNEL or KERNELDIR (in the environment or vm-config)"
  24. exit 2
  25. fi
  26. if [ -z "$KERNEL" ] ; then
  27. KERNEL=$KERNELDIR/arch/x86_64/boot/bzImage
  28. fi
  29. CMD=$TESTDIR/vm/inside.sh
  30. DATE=$(date +%s)
  31. LOGDIR=$LOGS/$DATE
  32. mkdir -p $LOGDIR
  33. if [ "$1" = "--codecov" ]; then
  34. shift
  35. CODECOV=yes
  36. DIR=$PWD
  37. if [ -e /tmp/logs ]; then
  38. echo "/tmp/logs exists - cannot prepare build trees"
  39. exit 1
  40. fi
  41. mkdir /tmp/logs
  42. echo "Preparing separate build trees for hostapd/wpa_supplicant"
  43. cd ../../..
  44. git archive --format=tar --prefix=hostap/ HEAD > /tmp/logs/hostap.tar
  45. cd $DIR
  46. cat ../../../wpa_supplicant/.config > /tmp/logs/wpa_supplicant.config
  47. echo "CONFIG_CODE_COVERAGE=y" >> /tmp/logs/wpa_supplicant.config
  48. cat ../../../hostapd/.config > /tmp/logs/hostapd.config
  49. echo "CONFIG_CODE_COVERAGE=y" >> /tmp/logs/hostapd.config
  50. cd /tmp/logs
  51. tar xf hostap.tar
  52. mv hostap alt-wpa_supplicant
  53. mv wpa_supplicant.config alt-wpa_supplicant/wpa_supplicant/.config
  54. tar xf hostap.tar
  55. mv hostap alt-hostapd
  56. cp hostapd.config alt-hostapd/hostapd/.config
  57. tar xf hostap.tar
  58. mv hostap alt-hostapd-as
  59. mv hostapd.config alt-hostapd-as/hostapd/.config
  60. rm hostap.tar
  61. cd /tmp/logs/alt-wpa_supplicant/wpa_supplicant
  62. echo "Building wpa_supplicant"
  63. make -j8 > /dev/null
  64. cd /tmp/logs/alt-hostapd/hostapd
  65. echo "Building hostapd"
  66. make -j8 hostapd > /dev/null
  67. cd /tmp/logs/alt-hostapd-as/hostapd
  68. echo "Building hostapd/hlr_auc_gw (AS)"
  69. make -j8 hostapd hlr_auc_gw > /dev/null
  70. cd $DIR
  71. mv /tmp/logs/alt-wpa_supplicant $LOGDIR
  72. mv /tmp/logs/alt-hostapd $LOGDIR
  73. mv /tmp/logs/alt-hostapd-as $LOGDIR
  74. else
  75. CODECOV=no
  76. fi
  77. echo "Starting test run in a virtual machine"
  78. kvm \
  79. -kernel $KERNEL -smp 4 \
  80. $KVMARGS -m $MEMORY -nographic \
  81. -fsdev local,security_model=none,id=fsdev-root,path=/$ROTAG \
  82. -device virtio-9p-pci,id=fs-root,fsdev=fsdev-root,mount_tag=/dev/root \
  83. -fsdev local,security_model=none,id=fsdev-logs,path="$LOGDIR",writeout=immediate \
  84. -device virtio-9p-pci,id=fs-logs,fsdev=fsdev-logs,mount_tag=logshare \
  85. -monitor null -serial stdio -serial file:$LOGDIR/console \
  86. -append "mac80211_hwsim.channels=$CHANNELS mac80211_hwsim.radios=5 init=$CMD testdir=$TESTDIR console=$KVMOUT root=/dev/root rootflags=trans=virtio,version=9p2000.u ro rootfstype=9p EPATH=$EPATH ARGS=$*"
  87. if [ $CODECOV = "yes" ]; then
  88. mv $LOGDIR/alt-wpa_supplicant /tmp/logs
  89. mv $LOGDIR/alt-hostapd /tmp/logs
  90. mv $LOGDIR/alt-hostapd-as /tmp/logs
  91. echo "Generating code coverage report for wpa_supplicant"
  92. cd /tmp/logs/alt-wpa_supplicant/wpa_supplicant
  93. lcov -c -d .. > lcov.info 2> lcov.log
  94. genhtml -t "wpa_supplicant hwsim test run $DATE" lcov.info --output-directory $LOGDIR/lcov-wpa_supplicant >> lcov.log 2>&1
  95. mv lcov.info lcov.log $LOGDIR/lcov-wpa_supplicant
  96. echo "Generating code coverage report for hostapd"
  97. cd /tmp/logs/alt-hostapd/hostapd
  98. lcov -c -d .. > lcov.info 2> lcov.log
  99. genhtml -t "hostapd hwsim test run $DATE" lcov.info --output-directory $LOGDIR/lcov-hostapd >> lcov.log 2>&1
  100. mv lcov.info lcov.log $LOGDIR/lcov-hostapd
  101. echo "Generating code coverage report for hostapd/hlr_auc_gw (AS)"
  102. cd /tmp/logs/alt-hostapd-as/hostapd
  103. lcov -c -d .. > lcov.info 2> lcov.log
  104. genhtml -t "hostapd/hlr_auc_gw (AS) hwsim test run $DATE" lcov.info --output-directory $LOGDIR/lcov-hostapd-as >> lcov.log 2>&1
  105. mv lcov.info lcov.log $LOGDIR/lcov-hostapd-as
  106. cd $DIR
  107. rm -r /tmp/logs/alt-wpa_supplicant
  108. rm -r /tmp/logs/alt-hostapd
  109. rm -r /tmp/logs/alt-hostapd-as
  110. rmdir /tmp/logs
  111. fi
  112. echo
  113. echo "Test run completed"
  114. echo "Logfiles are at $LOGDIR"
  115. if [ $CODECOV = "yes" ]; then
  116. echo "Code coverage reports:"
  117. echo "wpa_supplicant: file://$LOGDIR/lcov-wpa_supplicant/index.html"
  118. echo "hostapd: file://$LOGDIR/lcov-hostapd/index.html"
  119. echo "hostapd/hlr_auc_gw (AS): file://$LOGDIR/lcov-hostapd-as/index.html"
  120. fi