fuzz-harness.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/bash
  2. # Copyright 2012 the V8 project authors. All rights reserved.
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions are
  5. # met:
  6. #
  7. # * Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # * Redistributions in binary form must reproduce the above
  10. # copyright notice, this list of conditions and the following
  11. # disclaimer in the documentation and/or other materials provided
  12. # with the distribution.
  13. # * Neither the name of Google Inc. nor the names of its
  14. # contributors may be used to endorse or promote products derived
  15. # from this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. # A simple harness that downloads and runs 'jsfunfuzz' against d8. This
  29. # takes a long time because it runs many iterations and is intended for
  30. # automated usage. The package containing 'jsfunfuzz' can be found as an
  31. # attachment to this bug:
  32. # https://bugzilla.mozilla.org/show_bug.cgi?id=jsfunfuzz
  33. JSFUNFUZZ_URL="https://bugzilla.mozilla.org/attachment.cgi?id=310631"
  34. JSFUNFUZZ_MD5="d0e497201c5cd7bffbb1cdc1574f4e32"
  35. v8_root=$(readlink -f $(dirname $BASH_SOURCE)/../)
  36. jsfunfuzz_dir="$v8_root/tools/jsfunfuzz"
  37. if [ -n "$1" ]; then
  38. d8="${v8_root}/$1"
  39. else
  40. d8="${v8_root}/d8"
  41. fi
  42. if [ ! -f "$d8" ]; then
  43. echo "Failed to find d8 binary: $d8"
  44. exit 1
  45. fi
  46. # Deprecated download method. A prepatched archive is downloaded as a hook
  47. # if jsfunfuzz=1 is specified as a gyp flag. Requires google.com authentication
  48. # for google storage.
  49. if [ "$3" == "--download" ]; then
  50. jsfunfuzz_file="$v8_root/tools/jsfunfuzz.zip"
  51. if [ ! -f "$jsfunfuzz_file" ]; then
  52. echo "Downloading $jsfunfuzz_file ..."
  53. wget -q -O "$jsfunfuzz_file" $JSFUNFUZZ_URL || exit 1
  54. fi
  55. jsfunfuzz_sum=$(md5sum "$jsfunfuzz_file" | awk '{ print $1 }')
  56. if [ $jsfunfuzz_sum != $JSFUNFUZZ_MD5 ]; then
  57. echo "Failed to verify checksum!"
  58. exit 1
  59. fi
  60. if [ ! -d "$jsfunfuzz_dir" ]; then
  61. echo "Unpacking into $jsfunfuzz_dir ..."
  62. unzip "$jsfunfuzz_file" -d "$jsfunfuzz_dir" || exit 1
  63. echo "Patching runner ..."
  64. cat << EOF | patch -s -p0 -d "$v8_root"
  65. --- tools/jsfunfuzz/jsfunfuzz/multi_timed_run.py~
  66. +++ tools/jsfunfuzz/jsfunfuzz/multi_timed_run.py
  67. @@ -125,7 +125,7 @@
  68. def many_timed_runs():
  69. iteration = 0
  70. - while True:
  71. + while iteration < 100:
  72. iteration += 1
  73. logfilename = "w%d" % iteration
  74. one_timed_run(logfilename)
  75. EOF
  76. fi
  77. fi
  78. flags='--expose-gc --verify-gc'
  79. python -u "$jsfunfuzz_dir/jsfunfuzz/multi_timed_run.py" 300 \
  80. "$d8" $flags "$jsfunfuzz_dir/jsfunfuzz/jsfunfuzz.js"
  81. exit_code=$(cat w* | grep " looking good" -c)
  82. exit_code=$((100-exit_code))
  83. if [ -n "$2" ]; then
  84. archive="$2"
  85. else
  86. archive=fuzz-results-$(date +%Y%m%d%H%M%S).tar.bz2
  87. fi
  88. echo "Creating archive $archive"
  89. tar -cjf $archive err-* w*
  90. rm -f err-* w*
  91. echo "Total failures: $exit_code"
  92. exit $exit_code