xref: /third_party/node/deps/v8/tools/fuzz-harness.sh (revision 1cb0ef41)
11cb0ef41Sopenharmony_ci#!/bin/bash
21cb0ef41Sopenharmony_ci# Copyright 2012 the V8 project authors. All rights reserved.
31cb0ef41Sopenharmony_ci# Redistribution and use in source and binary forms, with or without
41cb0ef41Sopenharmony_ci# modification, are permitted provided that the following conditions are
51cb0ef41Sopenharmony_ci# met:
61cb0ef41Sopenharmony_ci#
71cb0ef41Sopenharmony_ci#     * Redistributions of source code must retain the above copyright
81cb0ef41Sopenharmony_ci#       notice, this list of conditions and the following disclaimer.
91cb0ef41Sopenharmony_ci#     * Redistributions in binary form must reproduce the above
101cb0ef41Sopenharmony_ci#       copyright notice, this list of conditions and the following
111cb0ef41Sopenharmony_ci#       disclaimer in the documentation and/or other materials provided
121cb0ef41Sopenharmony_ci#       with the distribution.
131cb0ef41Sopenharmony_ci#     * Neither the name of Google Inc. nor the names of its
141cb0ef41Sopenharmony_ci#       contributors may be used to endorse or promote products derived
151cb0ef41Sopenharmony_ci#       from this software without specific prior written permission.
161cb0ef41Sopenharmony_ci#
171cb0ef41Sopenharmony_ci# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
181cb0ef41Sopenharmony_ci# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
191cb0ef41Sopenharmony_ci# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
201cb0ef41Sopenharmony_ci# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
211cb0ef41Sopenharmony_ci# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
221cb0ef41Sopenharmony_ci# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
231cb0ef41Sopenharmony_ci# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
241cb0ef41Sopenharmony_ci# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
251cb0ef41Sopenharmony_ci# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
261cb0ef41Sopenharmony_ci# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
271cb0ef41Sopenharmony_ci# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci# A simple harness that downloads and runs 'jsfunfuzz' against d8. This
301cb0ef41Sopenharmony_ci# takes a long time because it runs many iterations and is intended for
311cb0ef41Sopenharmony_ci# automated usage. The package containing 'jsfunfuzz' can be found as an
321cb0ef41Sopenharmony_ci# attachment to this bug:
331cb0ef41Sopenharmony_ci# https://bugzilla.mozilla.org/show_bug.cgi?id=jsfunfuzz
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ciJSFUNFUZZ_URL="https://bugzilla.mozilla.org/attachment.cgi?id=310631"
361cb0ef41Sopenharmony_ciJSFUNFUZZ_MD5="d0e497201c5cd7bffbb1cdc1574f4e32"
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_civ8_root=$(readlink -f $(dirname $BASH_SOURCE)/../)
391cb0ef41Sopenharmony_cijsfunfuzz_dir="$v8_root/tools/jsfunfuzz"
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ciif [ -n "$1" ]; then
421cb0ef41Sopenharmony_ci  d8="${v8_root}/$1"
431cb0ef41Sopenharmony_cielse
441cb0ef41Sopenharmony_ci  d8="${v8_root}/d8"
451cb0ef41Sopenharmony_cifi
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ciif [ ! -f "$d8" ]; then
481cb0ef41Sopenharmony_ci  echo "Failed to find d8 binary: $d8"
491cb0ef41Sopenharmony_ci  exit 1
501cb0ef41Sopenharmony_cifi
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci# Deprecated download method. A prepatched archive is downloaded as a hook
531cb0ef41Sopenharmony_ci# if jsfunfuzz=1 is specified as a gyp flag. Requires google.com authentication
541cb0ef41Sopenharmony_ci# for google storage.
551cb0ef41Sopenharmony_ciif [ "$3" == "--download" ]; then
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci  jsfunfuzz_file="$v8_root/tools/jsfunfuzz.zip"
581cb0ef41Sopenharmony_ci  if [ ! -f "$jsfunfuzz_file" ]; then
591cb0ef41Sopenharmony_ci    echo "Downloading $jsfunfuzz_file ..."
601cb0ef41Sopenharmony_ci    wget -q -O "$jsfunfuzz_file" $JSFUNFUZZ_URL || exit 1
611cb0ef41Sopenharmony_ci  fi
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ci  jsfunfuzz_sum=$(md5sum "$jsfunfuzz_file" | awk '{ print $1 }')
641cb0ef41Sopenharmony_ci  if [ $jsfunfuzz_sum != $JSFUNFUZZ_MD5 ]; then
651cb0ef41Sopenharmony_ci    echo "Failed to verify checksum!"
661cb0ef41Sopenharmony_ci    exit 1
671cb0ef41Sopenharmony_ci  fi
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ci  if [ ! -d "$jsfunfuzz_dir" ]; then
701cb0ef41Sopenharmony_ci    echo "Unpacking into $jsfunfuzz_dir ..."
711cb0ef41Sopenharmony_ci    unzip "$jsfunfuzz_file" -d "$jsfunfuzz_dir" || exit 1
721cb0ef41Sopenharmony_ci    echo "Patching runner ..."
731cb0ef41Sopenharmony_ci    cat << EOF | patch -s -p0 -d "$v8_root"
741cb0ef41Sopenharmony_ci--- tools/jsfunfuzz/jsfunfuzz/multi_timed_run.py~
751cb0ef41Sopenharmony_ci+++ tools/jsfunfuzz/jsfunfuzz/multi_timed_run.py
761cb0ef41Sopenharmony_ci@@ -125,7 +125,7 @@
771cb0ef41Sopenharmony_ci 
781cb0ef41Sopenharmony_ci def many_timed_runs():
791cb0ef41Sopenharmony_ci     iteration = 0
801cb0ef41Sopenharmony_ci-    while True:
811cb0ef41Sopenharmony_ci+    while iteration < 100:
821cb0ef41Sopenharmony_ci         iteration += 1
831cb0ef41Sopenharmony_ci         logfilename = "w%d" % iteration
841cb0ef41Sopenharmony_ci         one_timed_run(logfilename)
851cb0ef41Sopenharmony_ciEOF
861cb0ef41Sopenharmony_ci  fi
871cb0ef41Sopenharmony_ci
881cb0ef41Sopenharmony_cifi
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_ciflags='--expose-gc --verify-gc'
911cb0ef41Sopenharmony_cipython -u "$jsfunfuzz_dir/jsfunfuzz/multi_timed_run.py" 300 \
921cb0ef41Sopenharmony_ci    "$d8" $flags "$jsfunfuzz_dir/jsfunfuzz/jsfunfuzz.js"
931cb0ef41Sopenharmony_ciexit_code=$(cat w* | grep " looking good" -c)
941cb0ef41Sopenharmony_ciexit_code=$((100-exit_code))
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_ciif [ -n "$2" ]; then
971cb0ef41Sopenharmony_ci  archive="$2"
981cb0ef41Sopenharmony_cielse
991cb0ef41Sopenharmony_ci  archive=fuzz-results-$(date +%Y%m%d%H%M%S).tar.bz2
1001cb0ef41Sopenharmony_cifi
1011cb0ef41Sopenharmony_ciecho "Creating archive $archive"
1021cb0ef41Sopenharmony_citar -cjf $archive err-* w*
1031cb0ef41Sopenharmony_cirm -f err-* w*
1041cb0ef41Sopenharmony_ci
1051cb0ef41Sopenharmony_ciecho "Total failures: $exit_code"
1061cb0ef41Sopenharmony_ciexit $exit_code
107