|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# This source code is licensed under the BSD-style license found in the |
| 6 | +# LICENSE file in the root directory of this source tree. |
| 7 | + |
| 8 | +# This script is used to build unit tests internally. It is not intended to be used in OSS. |
| 9 | + |
| 10 | +set -xueo pipefail |
| 11 | + |
| 12 | +THIS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 13 | +OUTPUT_DIR="${THIS_DIR}/__tests__" |
| 14 | +TEST_MODEL_DIR="${THIS_DIR}/test_models/" |
| 15 | + |
| 16 | +if [[ "${THIS_DIR}" != *"xplat"* ]]; then |
| 17 | + echo "This script must be run from xplat, not fbcode or oss" |
| 18 | + exit 1 |
| 19 | +fi |
| 20 | + |
| 21 | +ENABLE_ETDUMP=0 |
| 22 | +for arg in "$@"; do |
| 23 | + if [[ "$arg" == "etdump" ]]; then |
| 24 | + ENABLE_ETDUMP=1 |
| 25 | + else |
| 26 | + echo "Unknown argument: $arg" |
| 27 | + exit 1 |
| 28 | + fi |
| 29 | +done |
| 30 | + |
| 31 | +# Build the models |
| 32 | +# Using fbcode because the Python scripts are only supported in fbcode |
| 33 | +MODEL_TARGET_DIR=$(buck2 build fbcode//executorch/extension/wasm/test:models --show-full-output | awk '{print $2}') |
| 34 | + |
| 35 | +mkdir -p "${TEST_MODEL_DIR}" |
| 36 | +cp ${MODEL_TARGET_DIR}/*.pte ${TEST_MODEL_DIR} |
| 37 | + |
| 38 | +if (( ENABLE_ETDUMP != 0 )); then |
| 39 | + ETDUMP_OPTIONS="-DET_EVENT_TRACER_ENABLED=1" |
| 40 | + WASM_TARGET_NAME="wasm_etdump.test" |
| 41 | +else |
| 42 | + ETDUMP_OPTIONS="" |
| 43 | + WASM_TARGET_NAME="wasm.test" |
| 44 | +fi |
| 45 | + |
| 46 | +# Emscripten build options don't work properly on fbcode; copy test artifacts to xplat and run the test in xplat. |
| 47 | +BUILD_TARGET_DIR=$(dirname $(buck2 build :${WASM_TARGET_NAME}.js --show-full-output -c "cxx.extra_cxxflags=-DET_LOG_ENABLED=0 $ETDUMP_OPTIONS" | awk '{print $2}')) |
| 48 | + |
| 49 | +mkdir -p "${OUTPUT_DIR}" |
| 50 | +cp ${BUILD_TARGET_DIR}/${WASM_TARGET_NAME}.js ${OUTPUT_DIR} |
| 51 | +cp ${BUILD_TARGET_DIR}/${WASM_TARGET_NAME}.wasm ${OUTPUT_DIR} |
| 52 | + |
| 53 | +yarn install |
0 commit comments