Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions extension/wasm/test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Internal build generated files
__tests__/
test_models/*.pte
44 changes: 44 additions & 0 deletions extension/wasm/test/TARGETS
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")

oncall("executorch")

export_genrule_cmd = [
"$(exe //executorch/examples/portable/scripts:export)",
"--model_name={model_name}",
"--output_dir=$OUT",
]

runtime.python_binary(
name = "test_model",
srcs = [
"test_model.py",
],
main_module = "executorch.extension.wasm.test.test_model",
deps = [
"//executorch/extension/export_util:export_util",
],
)

test_pte_genrule_cmd = [
"$(exe :test_model)",
"$OUT/test.pte",
]

models_genrule_cmd = [
"mkdir -p $OUT &&",
" ".join(export_genrule_cmd).format(model_name="add_mul"),
"&&",
" ".join(export_genrule_cmd).format(model_name="add"),
"&&",
" ".join(test_pte_genrule_cmd),
]

runtime.genrule(
name = "models",
outs = {
"add.pte": ["add.pte"],
"add_mul.pte": ["add_mul.pte"],
"test.pte": ["test.pte"],
},
cmd = " ".join(models_genrule_cmd),
)
9 changes: 8 additions & 1 deletion extension/wasm/test/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"name": "wasm-test",
"private": true,
"scripts": {
"test": "jest"
"build": "bash xplat_build.sh",
"test": "jest --verbose",
"clean": "rm -rf __tests__ node_modules test_models/*.pte"
},
"devDependencies": {
"jest": "^30.1.3"
}
}
1 change: 1 addition & 0 deletions extension/wasm/test/test_models/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unit tests will not build without a file in this directory. Normally, running the build script should add the model files to this directory, but the Build Rule CIs will attempt and fail to build the unit tests directly without this file present.
53 changes: 53 additions & 0 deletions extension/wasm/test/xplat_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

# This script is used to build unit tests internally. It is not intended to be used in OSS.

set -xueo pipefail

THIS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OUTPUT_DIR="${THIS_DIR}/__tests__"
TEST_MODEL_DIR="${THIS_DIR}/test_models/"

if [[ "${THIS_DIR}" != *"xplat"* ]]; then
echo "This script must be run from xplat, not fbcode or oss"
exit 1
fi

ENABLE_ETDUMP=0
for arg in "$@"; do
if [[ "$arg" == "etdump" ]]; then
ENABLE_ETDUMP=1
else
echo "Unknown argument: $arg"
exit 1
fi
done

# Build the models
# Using fbcode because the Python scripts are only supported in fbcode
MODEL_TARGET_DIR=$(buck2 build fbcode//executorch/extension/wasm/test:models --show-full-output | awk '{print $2}')

mkdir -p "${TEST_MODEL_DIR}"
cp ${MODEL_TARGET_DIR}/*.pte ${TEST_MODEL_DIR}

if (( ENABLE_ETDUMP != 0 )); then
ETDUMP_OPTIONS="-DET_EVENT_TRACER_ENABLED=1"
WASM_TARGET_NAME="wasm_etdump.test"
else
ETDUMP_OPTIONS=""
WASM_TARGET_NAME="wasm.test"
fi

# Emscripten build options don't work properly on fbcode; copy test artifacts to xplat and run the test in xplat.
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}'))

mkdir -p "${OUTPUT_DIR}"
cp ${BUILD_TARGET_DIR}/${WASM_TARGET_NAME}.js ${OUTPUT_DIR}
cp ${BUILD_TARGET_DIR}/${WASM_TARGET_NAME}.wasm ${OUTPUT_DIR}

yarn install
Loading
Loading