From 1d7c7c8ef2a242660223a036f9a183844d4ae00c Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Fri, 31 May 2024 15:20:19 -0700 Subject: [PATCH] Add more tests and clean up helper (#3783) Summary: Added extension/evalue_util/test, extension/kernel_util/test, runtime/platform/test, kernels/portable/cpu/util/test Clean up Test.cmake Pull Request resolved: https://github.com/pytorch/executorch/pull/3783 Reviewed By: shoumikhin Differential Revision: D58031811 Pulled By: kirklandsign fbshipit-source-id: 4e5bbfcee486a2e0c1d9d9e596649bb9b6268443 --- build/Test.cmake | 22 +++++++------ extension/evalue_util/test/CMakeLists.txt | 28 +++++++++++++++++ extension/kernel_util/test/CMakeLists.txt | 28 +++++++++++++++++ kernels/portable/cpu/util/test/CMakeLists.txt | 31 +++++++++++++++++++ .../testing_util/test/CMakeLists.txt | 2 +- .../core/exec_aten/util/test/CMakeLists.txt | 6 ++-- runtime/platform/test/CMakeLists.txt | 30 ++++++++++++++++++ test/utils/CMakeLists.txt | 26 ++++++++++++++++ test/utils/OSSTestConfig.json | 30 +++++++++++++++--- 9 files changed, 184 insertions(+), 19 deletions(-) create mode 100644 extension/evalue_util/test/CMakeLists.txt create mode 100644 extension/kernel_util/test/CMakeLists.txt create mode 100644 kernels/portable/cpu/util/test/CMakeLists.txt create mode 100644 runtime/platform/test/CMakeLists.txt create mode 100644 test/utils/CMakeLists.txt diff --git a/build/Test.cmake b/build/Test.cmake index c4ff600c80..c08dd61b7b 100644 --- a/build/Test.cmake +++ b/build/Test.cmake @@ -19,6 +19,15 @@ include(${EXECUTORCH_ROOT}/build/Utils.cmake) +# Find prebuilt executorch library +find_package(executorch CONFIG REQUIRED) + +enable_testing() +find_package(GTest CONFIG REQUIRED) + +target_link_options_shared_lib(extension_data_loader) +target_link_options_shared_lib(portable_ops_lib) + # Add code coverage flags to supported compilers if(EXECUTORCH_USE_CPP_CODE_COVERAGE) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") @@ -53,19 +62,12 @@ function(et_cxx_test target_name) set(multi_arg_names SOURCES EXTRA_LIBS) cmake_parse_arguments(ET_CXX_TEST "" "" "${multi_arg_names}" ${ARGN}) -# Find prebuilt executorch library -find_package(executorch CONFIG REQUIRED) - -target_link_options_shared_lib(extension_data_loader) -target_link_options_shared_lib(portable_ops_lib) - -enable_testing() -find_package(GTest CONFIG REQUIRED) - # Let files say "include ". target_include_directories(executorch INTERFACE ${EXECUTORCH_ROOT}/..) -add_executable(${target_name} ${ET_CXX_TEST_SOURCES}) +set(ET_TEST_UTIL_SOURCES ${EXECUTORCH_ROOT}/runtime/core/exec_aten/testing_util/tensor_util.cpp) + +add_executable(${target_name} ${ET_CXX_TEST_SOURCES} ${ET_TEST_UTIL_SOURCES}) # Includes gtest, gmock, executorch by default target_link_libraries( ${target_name} GTest::gtest GTest::gtest_main GTest::gmock executorch diff --git a/extension/evalue_util/test/CMakeLists.txt b/extension/evalue_util/test/CMakeLists.txt new file mode 100644 index 0000000000..f14383ed63 --- /dev/null +++ b/extension/evalue_util/test/CMakeLists.txt @@ -0,0 +1,28 @@ +# 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_evalue_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 print_evalue_test.cpp ../print_evalue.cpp) + +et_cxx_test(extension_evalue_util_test SOURCES ${_test_srcs} EXTRA_LIBS) diff --git a/extension/kernel_util/test/CMakeLists.txt b/extension/kernel_util/test/CMakeLists.txt new file mode 100644 index 0000000000..1d960062be --- /dev/null +++ b/extension/kernel_util/test/CMakeLists.txt @@ -0,0 +1,28 @@ +# 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_kernel_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 make_boxed_from_unboxed_functor_test.cpp) + +et_cxx_test(extension_kernel_util_test SOURCES ${_test_srcs} EXTRA_LIBS) diff --git a/kernels/portable/cpu/util/test/CMakeLists.txt b/kernels/portable/cpu/util/test/CMakeLists.txt new file mode 100644 index 0000000000..7edb9cf458 --- /dev/null +++ b/kernels/portable/cpu/util/test/CMakeLists.txt @@ -0,0 +1,31 @@ +# 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(kernels_portable_cpu_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 broadcast_test.cpp reduce_test.cpp) + +et_cxx_test( + kernels_portable_cpu_util_test SOURCES ${_test_srcs} EXTRA_LIBS + portable_kernels portable_ops_lib +) diff --git a/runtime/core/exec_aten/testing_util/test/CMakeLists.txt b/runtime/core/exec_aten/testing_util/test/CMakeLists.txt index 0121592a15..78e7ad6d3c 100644 --- a/runtime/core/exec_aten/testing_util/test/CMakeLists.txt +++ b/runtime/core/exec_aten/testing_util/test/CMakeLists.txt @@ -23,7 +23,7 @@ set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..) include(${EXECUTORCH_ROOT}/build/Test.cmake) -set(_test_srcs tensor_util_test.cpp tensor_factory_test.cpp ../tensor_util.cpp) +set(_test_srcs tensor_util_test.cpp tensor_factory_test.cpp) et_cxx_test( runtime_core_exec_aten_testing_util_test SOURCES ${_test_srcs} EXTRA_LIBS diff --git a/runtime/core/exec_aten/util/test/CMakeLists.txt b/runtime/core/exec_aten/util/test/CMakeLists.txt index 060b216653..123db7efd5 100644 --- a/runtime/core/exec_aten/util/test/CMakeLists.txt +++ b/runtime/core/exec_aten/util/test/CMakeLists.txt @@ -23,10 +23,8 @@ set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..) include(${EXECUTORCH_ROOT}/build/Test.cmake) -set(_test_srcs - tensor_util_test.cpp scalar_type_util_test.cpp - operator_impl_example_test.cpp dim_order_util_test.cpp - ../../testing_util/tensor_util.cpp +set(_test_srcs tensor_util_test.cpp scalar_type_util_test.cpp + operator_impl_example_test.cpp dim_order_util_test.cpp ) et_cxx_test(runtime_core_exec_aten_util_test SOURCES ${_test_srcs} EXTRA_LIBS) diff --git a/runtime/platform/test/CMakeLists.txt b/runtime/platform/test/CMakeLists.txt new file mode 100644 index 0000000000..f4b2f2e4a5 --- /dev/null +++ b/runtime/platform/test/CMakeLists.txt @@ -0,0 +1,30 @@ +# 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 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_platform_test) + +# Use C++17 for test. +set(CMAKE_CXX_STANDARD 17) + +set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) + +include(${EXECUTORCH_ROOT}/build/Test.cmake) + +et_cxx_test(platform_test SOURCES executor_pal_test.cpp) + +et_cxx_test(platform_death_test SOURCES executor_pal_death_test.cpp) + +et_cxx_test(logging_test SOURCES logging_test.cpp) + +et_cxx_test(clock_test SOURCES clock_test.cpp stub_platform.cpp) diff --git a/test/utils/CMakeLists.txt b/test/utils/CMakeLists.txt new file mode 100644 index 0000000000..9183deeb69 --- /dev/null +++ b/test/utils/CMakeLists.txt @@ -0,0 +1,26 @@ +# 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 file should be formatted with +# ~~~ +# cmake-format -i CMakeLists.txt +# ~~~ +# It should also be cmake-lint clean. +# + +cmake_minimum_required(VERSION 3.19) +project(test_utils) + +# 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 alignment_test.cpp UnitTestMain.cpp) + +et_cxx_test(test_utils_test SOURCES ${_test_srcs} EXTRA_LIBS) diff --git a/test/utils/OSSTestConfig.json b/test/utils/OSSTestConfig.json index f9d56b2656..5b443be23b 100644 --- a/test/utils/OSSTestConfig.json +++ b/test/utils/OSSTestConfig.json @@ -11,6 +11,19 @@ "extension_data_loader" ] }, + { + "directory": "extension/evalue_util/test", + "sources": [ + "print_evalue_test.cpp", + "../print_evalue.cpp" + ] + }, + { + "directory": "extension/kernel_util/test", + "sources": [ + "make_boxed_from_unboxed_functor_test.cpp" + ] + }, { "directory": "extension/module/test", "sources": [ @@ -35,6 +48,17 @@ "portable_ops_lib" ] }, + { + "directory": "kernels/portable/cpu/util/test", + "sources": [ + "broadcast_test.cpp", + "reduce_test.cpp" + ], + "additional_libs": [ + "portable_kernels", + "portable_ops_lib" + ] + }, { "directory": "runtime/core/portable_type/test", "sources": [ @@ -64,16 +88,14 @@ "tensor_util_test.cpp", "scalar_type_util_test.cpp", "operator_impl_example_test.cpp", - "dim_order_util_test.cpp", - "../../testing_util/tensor_util.cpp" + "dim_order_util_test.cpp" ] }, { "directory": "runtime/core/exec_aten/testing_util/test", "sources": [ "tensor_util_test.cpp", - "tensor_factory_test.cpp", - "../tensor_util.cpp" + "tensor_factory_test.cpp" ] } ] }