blob: c874d018451730fa8862ab9f062d1349ef696264 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001#!/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
29# A simple harness that downloads and runs 'jsfunfuzz' against d8. This
30# takes a long time because it runs many iterations and is intended for
31# automated usage. The package containing 'jsfunfuzz' can be found as an
32# attachment to this bug:
33# https://bugzilla.mozilla.org/show_bug.cgi?id=jsfunfuzz
34
35JSFUNFUZZ_URL="https://bugzilla.mozilla.org/attachment.cgi?id=310631"
36JSFUNFUZZ_MD5="d0e497201c5cd7bffbb1cdc1574f4e32"
37
38v8_root=$(readlink -f $(dirname $BASH_SOURCE)/../)
Ben Murdoch097c5b22016-05-18 11:27:45 +010039jsfunfuzz_dir="$v8_root/tools/jsfunfuzz"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000040
41if [ -n "$1" ]; then
42 d8="${v8_root}/$1"
43else
44 d8="${v8_root}/d8"
45fi
46
47if [ ! -f "$d8" ]; then
48 echo "Failed to find d8 binary: $d8"
49 exit 1
50fi
51
Ben Murdoch097c5b22016-05-18 11:27:45 +010052# Deprecated download method. A prepatched archive is downloaded as a hook
53# if jsfunfuzz=1 is specified as a gyp flag. Requires google.com authentication
54# for google storage.
55if [ "$3" == "--download" ]; then
Ben Murdochb8a8cc12014-11-26 15:28:44 +000056
Ben Murdoch097c5b22016-05-18 11:27:45 +010057 jsfunfuzz_file="$v8_root/tools/jsfunfuzz.zip"
58 if [ ! -f "$jsfunfuzz_file" ]; then
59 echo "Downloading $jsfunfuzz_file ..."
60 wget -q -O "$jsfunfuzz_file" $JSFUNFUZZ_URL || exit 1
61 fi
Ben Murdochb8a8cc12014-11-26 15:28:44 +000062
Ben Murdoch097c5b22016-05-18 11:27:45 +010063 jsfunfuzz_sum=$(md5sum "$jsfunfuzz_file" | awk '{ print $1 }')
64 if [ $jsfunfuzz_sum != $JSFUNFUZZ_MD5 ]; then
65 echo "Failed to verify checksum!"
66 exit 1
67 fi
68
69 if [ ! -d "$jsfunfuzz_dir" ]; then
70 echo "Unpacking into $jsfunfuzz_dir ..."
71 unzip "$jsfunfuzz_file" -d "$jsfunfuzz_dir" || exit 1
72 echo "Patching runner ..."
73 cat << EOF | patch -s -p0 -d "$v8_root"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000074--- tools/jsfunfuzz/jsfunfuzz/multi_timed_run.py~
75+++ tools/jsfunfuzz/jsfunfuzz/multi_timed_run.py
76@@ -125,7 +125,7 @@
77
78 def many_timed_runs():
79 iteration = 0
80- while True:
81+ while iteration < 100:
82 iteration += 1
83 logfilename = "w%d" % iteration
84 one_timed_run(logfilename)
85EOF
Ben Murdoch097c5b22016-05-18 11:27:45 +010086 fi
87
Ben Murdochb8a8cc12014-11-26 15:28:44 +000088fi
89
90flags='--debug-code --expose-gc --verify-gc'
91python -u "$jsfunfuzz_dir/jsfunfuzz/multi_timed_run.py" 300 \
92 "$d8" $flags "$jsfunfuzz_dir/jsfunfuzz/jsfunfuzz.js"
93exit_code=$(cat w* | grep " looking good" -c)
94exit_code=$((100-exit_code))
Ben Murdoch097c5b22016-05-18 11:27:45 +010095
96if [ -n "$2" ]; then
97 archive="$2"
98else
99 archive=fuzz-results-$(date +%Y%m%d%H%M%S).tar.bz2
100fi
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000101echo "Creating archive $archive"
102tar -cjf $archive err-* w*
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000103rm -f err-* w*
104
105echo "Total failures: $exit_code"
106exit $exit_code