11cb0ef41Sopenharmony_ci#!/bin/bash
21cb0ef41Sopenharmony_ci# Copyright 2017 the V8 project authors. All rights reserved.
31cb0ef41Sopenharmony_ci# Use of this source code is governed by a BSD-style license that can be
41cb0ef41Sopenharmony_ci# found in the LICENSE file.
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci# Exit immediately if a command exits with a non-zero status.
71cb0ef41Sopenharmony_ciset -e
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci# Treat unset variables as an error when substituting.
101cb0ef41Sopenharmony_ciset -u
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci# return value of a pipeline is the status of the last command to exit with a
131cb0ef41Sopenharmony_ci# non-zero status, or zero if no command exited with a non-zero status
141cb0ef41Sopenharmony_ciset -o pipefail
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_cilog_and_run() {
171cb0ef41Sopenharmony_ci  echo ">>" $*
181cb0ef41Sopenharmony_ci  if ! $*; then
191cb0ef41Sopenharmony_ci    echo "sub-command failed: $*"
201cb0ef41Sopenharmony_ci    exit
211cb0ef41Sopenharmony_ci  fi
221cb0ef41Sopenharmony_ci}
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci###############################################################################
251cb0ef41Sopenharmony_ci# Setup directories.
261cb0ef41Sopenharmony_ci###############################################################################
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ciTOOLS_WASM_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
291cb0ef41Sopenharmony_ciV8_DIR="${TOOLS_WASM_DIR}/../.."
301cb0ef41Sopenharmony_ciSPEC_TEST_DIR=${V8_DIR}/test/wasm-spec-tests
311cb0ef41Sopenharmony_ciTMP_DIR=${SPEC_TEST_DIR}/tmp
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ciJS_API_TEST_DIR=${V8_DIR}/test/wasm-js
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_cilog_and_run cd ${V8_DIR}
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_cilog_and_run rm -rf ${SPEC_TEST_DIR}/tests
381cb0ef41Sopenharmony_cilog_and_run mkdir ${SPEC_TEST_DIR}/tests
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_cilog_and_run mkdir ${SPEC_TEST_DIR}/tests/proposals
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_cilog_and_run rm -rf ${TMP_DIR}
431cb0ef41Sopenharmony_cilog_and_run mkdir ${TMP_DIR}
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_cilog_and_run rm -rf ${JS_API_TEST_DIR}/tests
461cb0ef41Sopenharmony_cilog_and_run mkdir ${JS_API_TEST_DIR}/tests
471cb0ef41Sopenharmony_cilog_and_run mkdir ${JS_API_TEST_DIR}/tests/wpt
481cb0ef41Sopenharmony_cilog_and_run mkdir ${JS_API_TEST_DIR}/tests/proposals
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci###############################################################################
511cb0ef41Sopenharmony_ci# Generate the spec tests.
521cb0ef41Sopenharmony_ci###############################################################################
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ciecho Process spec
551cb0ef41Sopenharmony_cilog_and_run cd ${TMP_DIR}
561cb0ef41Sopenharmony_cilog_and_run git clone https://github.com/WebAssembly/spec
571cb0ef41Sopenharmony_cilog_and_run cd spec/interpreter
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci# The next step requires that ocaml is installed. See the README.md in
601cb0ef41Sopenharmony_ci# https://github.com/WebAssembly/spec/tree/master/interpreter/.
611cb0ef41Sopenharmony_cilog_and_run make clean opt
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_cilog_and_run cd ${TMP_DIR}/spec/test/core
641cb0ef41Sopenharmony_cilog_and_run cp *.wast ${SPEC_TEST_DIR}/tests/
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_cilog_and_run ./run.py --wasm ${TMP_DIR}/spec/interpreter/wasm --out ${TMP_DIR}
671cb0ef41Sopenharmony_cilog_and_run cp ${TMP_DIR}/*.js ${SPEC_TEST_DIR}/tests/
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_cilog_and_run cp -r ${TMP_DIR}/spec/test/js-api/* ${JS_API_TEST_DIR}/tests
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci###############################################################################
721cb0ef41Sopenharmony_ci# Generate the wpt tests.
731cb0ef41Sopenharmony_ci###############################################################################
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_ciecho Process wpt
761cb0ef41Sopenharmony_cilog_and_run cd ${TMP_DIR}
771cb0ef41Sopenharmony_cilog_and_run git clone https://github.com/web-platform-tests/wpt
781cb0ef41Sopenharmony_cilog_and_run cp -r wpt/wasm/jsapi/* ${JS_API_TEST_DIR}/tests/wpt
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_cilog_and_run cd ${JS_API_TEST_DIR}/tests
811cb0ef41Sopenharmony_cifor spec_test_name in $(find ./ -name '*.any.js' -not -wholename '*/wpt/*'); do
821cb0ef41Sopenharmony_ci  wpt_test_name="wpt/${spec_test_name}"
831cb0ef41Sopenharmony_ci  if [ -f "$wpt_test_name" ] && cmp -s $spec_test_name $wpt_test_name ; then
841cb0ef41Sopenharmony_ci    log_and_run rm $wpt_test_name
851cb0ef41Sopenharmony_ci  elif [ -f "$wpt_test_name" ]; then
861cb0ef41Sopenharmony_ci    echo "keep" $wpt_test_name
871cb0ef41Sopenharmony_ci  fi
881cb0ef41Sopenharmony_cidone
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_ci###############################################################################
911cb0ef41Sopenharmony_ci# Generate the proposal tests.
921cb0ef41Sopenharmony_ci###############################################################################
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_cirepos='js-types tail-call simd memory64'
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_cifor repo in ${repos}; do
971cb0ef41Sopenharmony_ci  echo "Process ${repo}"
981cb0ef41Sopenharmony_ci  echo ">> Process core tests"
991cb0ef41Sopenharmony_ci  log_and_run cd ${TMP_DIR}
1001cb0ef41Sopenharmony_ci  log_and_run git clone https://github.com/WebAssembly/${repo}
1011cb0ef41Sopenharmony_ci  # Compile the spec interpreter to generate the .js test cases later.
1021cb0ef41Sopenharmony_ci  log_and_run cd ${repo}/interpreter
1031cb0ef41Sopenharmony_ci  log_and_run make clean opt
1041cb0ef41Sopenharmony_ci  log_and_run cd ../test/core
1051cb0ef41Sopenharmony_ci  log_and_run mkdir ${SPEC_TEST_DIR}/tests/proposals/${repo}
1061cb0ef41Sopenharmony_ci
1071cb0ef41Sopenharmony_ci  # Iterate over all proposal tests. Those which differ from the spec tests are
1081cb0ef41Sopenharmony_ci  # copied to the output directory and converted to .js tests.
1091cb0ef41Sopenharmony_ci  for rel_filename in $(find . -name '*.wast'); do
1101cb0ef41Sopenharmony_ci    abs_filename=$(realpath $rel_filename)
1111cb0ef41Sopenharmony_ci    spec_filename=${TMP_DIR}/spec/test/core/${rel_filename}
1121cb0ef41Sopenharmony_ci    if [ ! -f "$spec_filename" ] || ! cmp -s $abs_filename $spec_filename ; then
1131cb0ef41Sopenharmony_ci      log_and_run cp ${rel_filename} ${SPEC_TEST_DIR}/tests/proposals/${repo}/
1141cb0ef41Sopenharmony_ci      log_and_run ./run.py --wasm ../../interpreter/wasm ${rel_filename} --out _build 2> /dev/null
1151cb0ef41Sopenharmony_ci    fi
1161cb0ef41Sopenharmony_ci  done
1171cb0ef41Sopenharmony_ci
1181cb0ef41Sopenharmony_ci  if ls _build/*.js > /dev/null; then
1191cb0ef41Sopenharmony_ci    log_and_run cp _build/*.js ${SPEC_TEST_DIR}/tests/proposals/${repo}/
1201cb0ef41Sopenharmony_ci  fi
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ci  echo ">> Process js-api tests"
1231cb0ef41Sopenharmony_ci  log_and_run mkdir ${JS_API_TEST_DIR}/tests/proposals/${repo}
1241cb0ef41Sopenharmony_ci  log_and_run cp -r ${TMP_DIR}/${repo}/test/js-api/* ${JS_API_TEST_DIR}/tests/proposals/${repo}
1251cb0ef41Sopenharmony_ci  # Delete duplicate tests
1261cb0ef41Sopenharmony_ci  log_and_run cd ${JS_API_TEST_DIR}/tests
1271cb0ef41Sopenharmony_ci  for spec_test_name in $(find ./ -name '*.any.js' -not -wholename '*/proposals/*'); do
1281cb0ef41Sopenharmony_ci    proposal_test_name="proposals/${repo}/${spec_test_name}"
1291cb0ef41Sopenharmony_ci    if [ -f "$proposal_test_name" ] && cmp -s $spec_test_name $proposal_test_name ; then
1301cb0ef41Sopenharmony_ci      log_and_run rm $proposal_test_name
1311cb0ef41Sopenharmony_ci    elif [ -f "$proposal_test_name" ]; then
1321cb0ef41Sopenharmony_ci      echo "keep" $proposal_test_name
1331cb0ef41Sopenharmony_ci    fi
1341cb0ef41Sopenharmony_ci  done
1351cb0ef41Sopenharmony_cidone
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_ci###############################################################################
1381cb0ef41Sopenharmony_ci# Report and cleanup.
1391cb0ef41Sopenharmony_ci###############################################################################
1401cb0ef41Sopenharmony_ci
1411cb0ef41Sopenharmony_cicd ${SPEC_TEST_DIR}
1421cb0ef41Sopenharmony_ciecho
1431cb0ef41Sopenharmony_ciecho "The following files will get uploaded:"
1441cb0ef41Sopenharmony_cils -R tests
1451cb0ef41Sopenharmony_ciecho
1461cb0ef41Sopenharmony_ci
1471cb0ef41Sopenharmony_cicd ${JS_API_TEST_DIR}
1481cb0ef41Sopenharmony_cils -R tests
1491cb0ef41Sopenharmony_ciecho
1501cb0ef41Sopenharmony_ci
1511cb0ef41Sopenharmony_cilog_and_run rm -rf ${TMP_DIR}
1521cb0ef41Sopenharmony_ci
1531cb0ef41Sopenharmony_ci###############################################################################
1541cb0ef41Sopenharmony_ci# Upload all spec tests.
1551cb0ef41Sopenharmony_ci###############################################################################
1561cb0ef41Sopenharmony_ci
1571cb0ef41Sopenharmony_ciecho "****************************************************************************"
1581cb0ef41Sopenharmony_ciecho "* For the following command you first have to authenticate with google cloud"
1591cb0ef41Sopenharmony_ciecho "* storage. For that you have to execute"
1601cb0ef41Sopenharmony_ciecho "*"
1611cb0ef41Sopenharmony_ciecho "* > gsutil.py config"
1621cb0ef41Sopenharmony_ciecho "*"
1631cb0ef41Sopenharmony_ciecho "* When the script asks you for your project-id, use 0."
1641cb0ef41Sopenharmony_ciecho "****************************************************************************"
1651cb0ef41Sopenharmony_cilog_and_run cd ${SPEC_TEST_DIR}
1661cb0ef41Sopenharmony_cilog_and_run upload_to_google_storage.py -a -b v8-wasm-spec-tests tests
1671cb0ef41Sopenharmony_ci
1681cb0ef41Sopenharmony_cilog_and_run cd ${JS_API_TEST_DIR}
1691cb0ef41Sopenharmony_cilog_and_run upload_to_google_storage.py -a -b v8-wasm-spec-tests tests
170