From bb72f3cbf3a23ef230325a5e6744837f18ab8b9b Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Tue, 14 May 2024 10:52:09 -0700 Subject: [PATCH 1/4] Add a way to run c++ unittest on OSS --- .../core/portable_type/test/CMakeLists.txt | 40 +++++++++++++++++++ test/run_oss_cpp_tests.sh | 23 +++++++++++ 2 files changed, 63 insertions(+) create mode 100644 runtime/core/portable_type/test/CMakeLists.txt create mode 100644 test/run_oss_cpp_tests.sh diff --git a/runtime/core/portable_type/test/CMakeLists.txt b/runtime/core/portable_type/test/CMakeLists.txt new file mode 100644 index 00000000000..8649a926672 --- /dev/null +++ b/runtime/core/portable_type/test/CMakeLists.txt @@ -0,0 +1,40 @@ +# 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. + +# ### Editing this file ### +# +# 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(runtime_core_portable_type_test) + +# Use C++11 for size test. +set(CMAKE_CXX_STANDARD 11) + +set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) + +include(${EXECUTORCH_ROOT}/build/Utils.cmake) + +# Find prebuilt executorch library +find_package(executorch CONFIG REQUIRED) + +enable_testing() +find_package(GTest CONFIG REQUIRED) + +# Let files say "include ". +set(_common_include_directories ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT}/third-party/googletest/googletest/include) +target_include_directories(executorch INTERFACE ${_common_include_directories}) + +set(_test_srcs optional_test.cpp executor_tensor_test.cpp half_test.cpp scalar_test.cpp tensor_impl_test.cpp) + +add_executable(runtime_core_portable_type_test ${_test_srcs}) +target_link_libraries(runtime_core_portable_type_test GTest::gtest GTest::gtest_main executorch) +add_test(ExecuTorchTest runtime_core_portable_type_test) diff --git a/test/run_oss_cpp_tests.sh b/test/run_oss_cpp_tests.sh new file mode 100644 index 00000000000..2101e3b0bab --- /dev/null +++ b/test/run_oss_cpp_tests.sh @@ -0,0 +1,23 @@ +#!/bin/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. + +set -ex + +build_executorch() { + cmake . -DCMAKE_INSTALL_PREFIX=cmake-out -DEXECUTORCH_BUILD_GTESTS=ON -Bcmake-out + cmake --build cmake-out -j9 --target install +} + +build_and_run_test() { + local test_dir=$1 + cmake "${test_dir}" -Bcmake-out/"${test_dir}" -DCMAKE_INSTALL_PREFIX=cmake-out + cmake --build cmake-out/"${test_dir}" + cmake-out/"${test_dir}"/*test +} + +build_executorch +build_and_run_test runtime/core/portable_type/test/ From 844bd53f66a34b7662ece7eb1cccb693c1ad1a6d Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Tue, 14 May 2024 10:58:50 -0700 Subject: [PATCH 2/4] format --- runtime/core/portable_type/test/CMakeLists.txt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/runtime/core/portable_type/test/CMakeLists.txt b/runtime/core/portable_type/test/CMakeLists.txt index 8649a926672..6d40fa2d622 100644 --- a/runtime/core/portable_type/test/CMakeLists.txt +++ b/runtime/core/portable_type/test/CMakeLists.txt @@ -30,11 +30,18 @@ enable_testing() find_package(GTest CONFIG REQUIRED) # Let files say "include ". -set(_common_include_directories ${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT}/third-party/googletest/googletest/include) +set(_common_include_directories + ${EXECUTORCH_ROOT}/.. + ${EXECUTORCH_ROOT}/third-party/googletest/googletest/include +) target_include_directories(executorch INTERFACE ${_common_include_directories}) -set(_test_srcs optional_test.cpp executor_tensor_test.cpp half_test.cpp scalar_test.cpp tensor_impl_test.cpp) +set(_test_srcs optional_test.cpp executor_tensor_test.cpp half_test.cpp + scalar_test.cpp tensor_impl_test.cpp +) add_executable(runtime_core_portable_type_test ${_test_srcs}) -target_link_libraries(runtime_core_portable_type_test GTest::gtest GTest::gtest_main executorch) +target_link_libraries( + runtime_core_portable_type_test GTest::gtest GTest::gtest_main executorch +) add_test(ExecuTorchTest runtime_core_portable_type_test) From 33e9df7cd9d16072397ccb71e709469bd7135609 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Tue, 14 May 2024 11:25:49 -0700 Subject: [PATCH 3/4] improve cmake --- runtime/core/portable_type/test/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/runtime/core/portable_type/test/CMakeLists.txt b/runtime/core/portable_type/test/CMakeLists.txt index 6d40fa2d622..3ea05677c3d 100644 --- a/runtime/core/portable_type/test/CMakeLists.txt +++ b/runtime/core/portable_type/test/CMakeLists.txt @@ -16,7 +16,7 @@ cmake_minimum_required(VERSION 3.19) project(runtime_core_portable_type_test) -# Use C++11 for size test. +# Use C++11 for test. set(CMAKE_CXX_STANDARD 11) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) @@ -32,7 +32,6 @@ find_package(GTest CONFIG REQUIRED) # Let files say "include ". set(_common_include_directories ${EXECUTORCH_ROOT}/.. - ${EXECUTORCH_ROOT}/third-party/googletest/googletest/include ) target_include_directories(executorch INTERFACE ${_common_include_directories}) From 6d7c27dc564264cc09f8c68b545d19b522128d60 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Tue, 14 May 2024 20:56:46 -0700 Subject: [PATCH 4/4] lint --- test/run_oss_cpp_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run_oss_cpp_tests.sh b/test/run_oss_cpp_tests.sh index 2101e3b0bab..dcc8b4d27f6 100644 --- a/test/run_oss_cpp_tests.sh +++ b/test/run_oss_cpp_tests.sh @@ -16,7 +16,7 @@ build_and_run_test() { local test_dir=$1 cmake "${test_dir}" -Bcmake-out/"${test_dir}" -DCMAKE_INSTALL_PREFIX=cmake-out cmake --build cmake-out/"${test_dir}" - cmake-out/"${test_dir}"/*test + for t in $(cmake-out/"${test_dir}"/*test); do ./"$t"; done } build_executorch