update-wasm-spec-tests.sh 5.84 KB
Newer Older
1 2 3 4 5
#!/bin/bash
# Copyright 2017 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

6
# Exit immediately if a command exits with a non-zero status.
7 8
set -e

9 10 11 12 13 14 15
# Treat unset variables as an error when substituting.
set -u

# return value of a pipeline is the status of the last command to exit with a
# non-zero status, or zero if no command exited with a non-zero status
set -o pipefail

16 17 18 19 20 21 22 23 24 25 26 27
log_and_run() {
  echo ">>" $*
  if ! $*; then
    echo "sub-command failed: $*"
    exit
  fi
}

###############################################################################
# Setup directories.
###############################################################################

28 29
TOOLS_WASM_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
V8_DIR="${TOOLS_WASM_DIR}/../.."
30
SPEC_TEST_DIR=${V8_DIR}/test/wasm-spec-tests
31
TMP_DIR=${SPEC_TEST_DIR}/tmp
32

33 34
JS_API_TEST_DIR=${V8_DIR}/test/wasm-js

35
log_and_run cd ${V8_DIR}
36

37 38
log_and_run rm -rf ${SPEC_TEST_DIR}/tests
log_and_run mkdir ${SPEC_TEST_DIR}/tests
39

40
log_and_run mkdir ${SPEC_TEST_DIR}/tests/proposals
41

42 43
log_and_run rm -rf ${TMP_DIR}
log_and_run mkdir ${TMP_DIR}
44

45 46
log_and_run rm -rf ${JS_API_TEST_DIR}/tests
log_and_run mkdir ${JS_API_TEST_DIR}/tests
47
log_and_run mkdir ${JS_API_TEST_DIR}/tests/wpt
48 49
log_and_run mkdir ${JS_API_TEST_DIR}/tests/proposals

50 51 52
###############################################################################
# Generate the spec tests.
###############################################################################
53

54 55 56 57 58
echo Process spec
log_and_run cd ${TMP_DIR}
log_and_run git clone https://github.com/WebAssembly/spec
log_and_run cd spec/interpreter

59
# The next step requires that ocaml is installed. See the README.md in
60
# https://github.com/WebAssembly/spec/tree/master/interpreter/.
61 62
log_and_run make clean opt

63
log_and_run cd ${TMP_DIR}/spec/test/core
64 65
log_and_run cp *.wast ${SPEC_TEST_DIR}/tests/

66
log_and_run ./run.py --wasm ${TMP_DIR}/spec/interpreter/wasm --out ${TMP_DIR}
67
log_and_run cp ${TMP_DIR}/*.js ${SPEC_TEST_DIR}/tests/
68

69 70
log_and_run cp -r ${TMP_DIR}/spec/test/js-api/* ${JS_API_TEST_DIR}/tests

71
###############################################################################
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
# Generate the wpt tests.
###############################################################################

echo Process wpt
log_and_run cd ${TMP_DIR}
log_and_run git clone https://github.com/web-platform-tests/wpt
log_and_run cp -r wpt/wasm/jsapi/* ${JS_API_TEST_DIR}/tests/wpt

log_and_run cd ${JS_API_TEST_DIR}/tests
for spec_test_name in $(find ./ -name '*.any.js' -not -wholename '*/wpt/*'); do
  wpt_test_name="wpt/${spec_test_name}"
  if [ -f "$wpt_test_name" ] && cmp -s $spec_test_name $wpt_test_name ; then
    log_and_run rm $wpt_test_name
  elif [ -f "$wpt_test_name" ]; then
    echo "keep" $wpt_test_name
  fi
done

###############################################################################
91 92
# Generate the proposal tests.
###############################################################################
93

94
repos='js-types tail-call simd memory64'
95

96 97
for repo in ${repos}; do
  echo "Process ${repo}"
98
  echo ">> Process core tests"
99 100 101 102 103 104 105 106 107 108
  log_and_run cd ${TMP_DIR}
  log_and_run git clone https://github.com/WebAssembly/${repo}
  # Compile the spec interpreter to generate the .js test cases later.
  log_and_run cd ${repo}/interpreter
  log_and_run make clean opt
  log_and_run cd ../test/core
  log_and_run mkdir ${SPEC_TEST_DIR}/tests/proposals/${repo}

  # Iterate over all proposal tests. Those which differ from the spec tests are
  # copied to the output directory and converted to .js tests.
109 110
  for rel_filename in $(find . -name '*.wast'); do
    abs_filename=$(realpath $rel_filename)
111
    spec_filename=${TMP_DIR}/spec/test/core/${rel_filename}
112 113 114 115 116
    if [ ! -f "$spec_filename" ] || ! cmp -s $abs_filename $spec_filename ; then
      log_and_run cp ${rel_filename} ${SPEC_TEST_DIR}/tests/proposals/${repo}/
      log_and_run ./run.py --wasm ../../interpreter/wasm ${rel_filename} --out _build 2> /dev/null
    fi
  done
117 118 119 120

  if ls _build/*.js > /dev/null; then
    log_and_run cp _build/*.js ${SPEC_TEST_DIR}/tests/proposals/${repo}/
  fi
121 122 123 124 125 126 127 128 129 130 131 132 133 134

  echo ">> Process js-api tests"
  log_and_run mkdir ${JS_API_TEST_DIR}/tests/proposals/${repo}
  log_and_run cp -r ${TMP_DIR}/${repo}/test/js-api/* ${JS_API_TEST_DIR}/tests/proposals/${repo}
  # Delete duplicate tests
  log_and_run cd ${JS_API_TEST_DIR}/tests
  for spec_test_name in $(find ./ -name '*.any.js' -not -wholename '*/proposals/*'); do
    proposal_test_name="proposals/${repo}/${spec_test_name}"
    if [ -f "$proposal_test_name" ] && cmp -s $spec_test_name $proposal_test_name ; then
      log_and_run rm $proposal_test_name
    elif [ -f "$proposal_test_name" ]; then
      echo "keep" $proposal_test_name
    fi
  done
135 136 137 138 139
done

###############################################################################
# Report and cleanup.
###############################################################################
140

141 142 143
cd ${SPEC_TEST_DIR}
echo
echo "The following files will get uploaded:"
144
ls -R tests
145
echo
146

147 148 149 150
cd ${JS_API_TEST_DIR}
ls -R tests
echo

151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
log_and_run rm -rf ${TMP_DIR}

###############################################################################
# Upload all spec tests.
###############################################################################

echo "****************************************************************************"
echo "* For the following command you first have to authenticate with google cloud"
echo "* storage. For that you have to execute"
echo "*"
echo "* > gsutil.py config"
echo "*"
echo "* When the script asks you for your project-id, use 0."
echo "****************************************************************************"
log_and_run cd ${SPEC_TEST_DIR}
log_and_run upload_to_google_storage.py -a -b v8-wasm-spec-tests tests
167 168 169

log_and_run cd ${JS_API_TEST_DIR}
log_and_run upload_to_google_storage.py -a -b v8-wasm-spec-tests tests