From ba672960b842b29a306e0a69beef531c3a00673b Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Thu, 30 May 2024 14:31:28 -0700 Subject: [PATCH] extension/runner_util test (#3777) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/3777 Reviewed By: shoumikhin Differential Revision: D57976685 Pulled By: kirklandsign fbshipit-source-id: 8bd8cd565b5ae8eaddb5f900ef6434c669c8148f --- build/executorch-config.cmake | 1 + examples/models/toy_model/model.py | 3 -- extension/runner_util/test/CMakeLists.txt | 37 +++++++++++++++++++++++ test/run_oss_cpp_tests.sh | 11 ++++++- test/utils/OSSTestConfig.json | 13 +++++++- 5 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 extension/runner_util/test/CMakeLists.txt diff --git a/build/executorch-config.cmake b/build/executorch-config.cmake index 9091ec2734..6fbd4dbd31 100644 --- a/build/executorch-config.cmake +++ b/build/executorch-config.cmake @@ -44,6 +44,7 @@ set(lib_list portable_ops_lib extension_module extension_module_static + extension_runner_util xnnpack_backend XNNPACK cpuinfo diff --git a/examples/models/toy_model/model.py b/examples/models/toy_model/model.py index 9369170d7a..9ebe42e662 100644 --- a/examples/models/toy_model/model.py +++ b/examples/models/toy_model/model.py @@ -45,9 +45,6 @@ def __init__(self): def forward(self, x, y): z = x + y - z = z + x - z = z + x - z = z + z return z def get_eager_model(self) -> torch.nn.Module: diff --git a/extension/runner_util/test/CMakeLists.txt b/extension/runner_util/test/CMakeLists.txt new file mode 100644 index 0000000000..aefb3b0417 --- /dev/null +++ b/extension/runner_util/test/CMakeLists.txt @@ -0,0 +1,37 @@ +# 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. + +# @generated by test/utils/generate_gtest_cmakelists.py +# +# This file should be formatted with +# ~~~ +# cmake-format -i CMakeLists.txt +# ~~~ +# It should also be cmake-lint clean. +# + +cmake_minimum_required(VERSION 3.19) +project(extension_runner_util_test) + +# Use C++17 for test. +set(CMAKE_CXX_STANDARD 17) + +set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) + +include(${EXECUTORCH_ROOT}/build/Test.cmake) + +set(_test_srcs inputs_test.cpp) + +et_cxx_test( + extension_runner_util_test + SOURCES + ${_test_srcs} + EXTRA_LIBS + extension_data_loader + extension_runner_util + portable_kernels + portable_ops_lib +) diff --git a/test/run_oss_cpp_tests.sh b/test/run_oss_cpp_tests.sh index 7d27fe5154..bc3cb8fe95 100755 --- a/test/run_oss_cpp_tests.sh +++ b/test/run_oss_cpp_tests.sh @@ -32,6 +32,7 @@ build_executorch() { -DEXECUTORCH_USE_CPP_CODE_COVERAGE=ON \ -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ + -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \ -DEXECUTORCH_BUILD_VULKAN=$BUILD_VULKAN \ -Bcmake-out cmake --build cmake-out -j9 --target install @@ -46,6 +47,10 @@ build_gtest() { popd } +export_test_add_model() { + python3 -m examples.portable.scripts.export --model_name="add" --output_dir="cmake-out" +} + build_and_run_test() { local test_dir=$1 cmake "${test_dir}" \ @@ -55,7 +60,10 @@ build_and_run_test() { -Bcmake-out/"${test_dir}" cmake --build cmake-out/"${test_dir}" -j9 - export RESOURCES_PATH=extension/module/test/resources + RESOURCES_PATH=$(realpath extension/module/test/resources) + export RESOURCES_PATH + ET_MODULE_ADD_PATH=$(realpath cmake-out/add.pte) + export ET_MODULE_ADD_PATH for t in cmake-out/"${test_dir}"/*test; do if [ -e "$t" ]; then @@ -92,6 +100,7 @@ probe_tests() { build_executorch build_gtest +export_test_add_model if [ -z "$1" ]; then echo "Running all directories:" diff --git a/test/utils/OSSTestConfig.json b/test/utils/OSSTestConfig.json index af6fa3dce9..f9d56b2656 100644 --- a/test/utils/OSSTestConfig.json +++ b/test/utils/OSSTestConfig.json @@ -21,7 +21,18 @@ "extension_module_static", "portable_kernels", "portable_ops_lib" - + ] + }, + { + "directory": "extension/runner_util/test", + "sources": [ + "inputs_test.cpp" + ], + "additional_libs": [ + "extension_data_loader", + "extension_runner_util", + "portable_kernels", + "portable_ops_lib" ] }, {