• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright 2016 the V8 project authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# A simple harness that downloads and runs 'jsfunfuzz' against d8. This
7# takes a long time because it runs many iterations and is intended for
8# automated usage. The package containing 'jsfunfuzz' can be found as an
9# attachment to this bug:
10# https://bugzilla.mozilla.org/show_bug.cgi?id=jsfunfuzz
11
12JSFUNFUZZ_URL="https://bugzilla.mozilla.org/attachment.cgi?id=310631"
13JSFUNFUZZ_MD5="d0e497201c5cd7bffbb1cdc1574f4e32"
14
15v8_root=$(readlink -f $(dirname $BASH_SOURCE)/../../)
16jsfunfuzz_dir="$v8_root/tools/jsfunfuzz"
17cd "$jsfunfuzz_dir"
18
19if [ -n "$1" ]; then
20  d8="${v8_root}/$1"
21else
22  d8="${v8_root}/d8"
23fi
24
25if [ ! -f "$d8" ]; then
26  echo "Failed to find d8 binary: $d8"
27  exit 1
28fi
29
30# Deprecated download method. A prepatched archive is downloaded as a hook
31# if jsfunfuzz=1 is specified as a gyp flag. Requires google.com authentication
32# for google storage.
33if [ "$3" == "--download" ]; then
34
35  jsfunfuzz_file="$v8_root/tools/jsfunfuzz.zip"
36  if [ ! -f "$jsfunfuzz_file" ]; then
37    echo "Downloading $jsfunfuzz_file ..."
38    wget -q -O "$jsfunfuzz_file" $JSFUNFUZZ_URL || exit 1
39  fi
40
41  jsfunfuzz_sum=$(md5sum "$jsfunfuzz_file" | awk '{ print $1 }')
42  if [ $jsfunfuzz_sum != $JSFUNFUZZ_MD5 ]; then
43    echo "Failed to verify checksum!"
44    exit 1
45  fi
46
47  if [ ! -d "$jsfunfuzz_dir" ]; then
48    echo "Unpacking into $jsfunfuzz_dir ..."
49    unzip "$jsfunfuzz_file" -d "$jsfunfuzz_dir" || exit 1
50    echo "Patching runner ..."
51    cat << EOF | patch -s -p0 -d "$v8_root"
52--- tools/jsfunfuzz/jsfunfuzz/multi_timed_run.py~
53+++ tools/jsfunfuzz/jsfunfuzz/multi_timed_run.py
54@@ -118,19 +118,19 @@
55-def showtail(logfilename):
56+def showtail(logfilename, method="tail"):
57-   cmd = "tail -n 20 %s" % logfilename
58+   cmd = "%s -n 20 %s" % (method, logfilename)
59    print cmd
60    print ""
61    os.system(cmd)
62    print ""
63    print ""
64
65 def many_timed_runs():
66     iteration = 0
67-    while True:
68+    while iteration < 100:
69         iteration += 1
70         logfilename = "w%d" % iteration
71         one_timed_run(logfilename)
72         if not succeeded(logfilename):
73             showtail(logfilename)
74-            showtail("err-" + logfilename)
75+            showtail("err-" + logfilename, method="head")
76
77             many_timed_runs()
78EOF
79  fi
80
81fi
82
83flags='--expose-gc --verify-gc'
84python -u "$jsfunfuzz_dir/jsfunfuzz/multi_timed_run.py" 300 \
85    "$d8" $flags "$jsfunfuzz_dir/jsfunfuzz/jsfunfuzz.js"
86exit_code=$(cat w* | grep " looking good" -c)
87exit_code=$((100-exit_code))
88
89if [ -n "$2" ]; then
90  archive="$2"
91else
92  archive=fuzz-results-$(date +%Y%m%d%H%M%S).tar.bz2
93fi
94echo "Creating archive $archive"
95tar -cjf $archive err-* w*
96rm -f err-* w*
97
98echo "Total failures: $exit_code"
99exit $exit_code
100