Skip to content

Commit cd306d3

Browse files
authored
Simplify cmake test invocation
Differential Revision: D66737276 Pull Request resolved: #7043
1 parent 5b2129e commit cd306d3

File tree

36 files changed

+225
-330
lines changed

36 files changed

+225
-330
lines changed

CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ option(EXECUTORCH_BUILD_EXTENSION_TENSOR "Build the Tensor extension" OFF)
200200

201201
option(EXECUTORCH_BUILD_EXTENSION_TRAINING "Build the training extension" OFF)
202202

203-
option(EXECUTORCH_BUILD_GTESTS "Build googletest based test binaries" OFF)
204-
205203
option(EXECUTORCH_BUILD_MPS "Build the MPS backend" OFF)
206204

207205
option(EXECUTORCH_BUILD_NEURON "Build the backends/mediatek directory" OFF)
@@ -216,6 +214,8 @@ option(EXECUTORCH_BUILD_KERNELS_QUANTIZED "Build the quantized kernels" OFF)
216214

217215
option(EXECUTORCH_BUILD_DEVTOOLS "Build the ExecuTorch Developer Tools")
218216

217+
option(EXECUTORCH_BUILD_TESTS "Build CMake-based unit tests" OFF)
218+
219219
option(EXECUTORCH_NNLIB_OPT "Build Cadence backend Hifi nnlib kernel" OFF)
220220

221221
option(EXECUTORCH_CADENCE_CPU_RUNNER "Build Cadence backend CPU runner" OFF)
@@ -330,6 +330,10 @@ if(EXECUTORCH_BUILD_PTHREADPOOL)
330330
)
331331
endif()
332332

333+
if(EXECUTORCH_BUILD_TESTS)
334+
include(CTest)
335+
endif()
336+
333337
if(NOT PYTHON_EXECUTABLE)
334338
resolve_python_executable()
335339
endif()
@@ -625,7 +629,7 @@ cmake_dependent_option(
625629
)
626630

627631
# Add googletest if any test targets should be built
628-
if(EXECUTORCH_BUILD_GTESTS)
632+
if(BUILD_TESTING)
629633
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third-party/googletest)
630634
endif()
631635

@@ -829,5 +833,7 @@ if(EXECUTORCH_BUILD_VULKAN)
829833
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/vulkan)
830834
endif()
831835

836+
include(Test.cmake)
837+
832838
# Print all summary
833839
executorch_print_configuration_summary()

Test.cmake

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
#
8+
# A helper CMake file to trigger C++ unit tests.
9+
#
10+
11+
if(BUILD_TESTING)
12+
# This contains the list of tests which are always built
13+
add_subdirectory(extension/evalue_util/test)
14+
add_subdirectory(extension/kernel_util/test)
15+
add_subdirectory(extension/memory_allocator/test)
16+
add_subdirectory(extension/parallel/test)
17+
add_subdirectory(extension/pytree/test)
18+
add_subdirectory(kernels/portable/cpu/util/test)
19+
add_subdirectory(kernels/prim_ops/test)
20+
add_subdirectory(kernels/test)
21+
add_subdirectory(runtime/core/exec_aten/testing_util/test)
22+
add_subdirectory(runtime/core/exec_aten/util/test)
23+
add_subdirectory(runtime/core/portable_type/test)
24+
add_subdirectory(runtime/core/test)
25+
add_subdirectory(runtime/executor/test)
26+
add_subdirectory(runtime/kernel/test)
27+
add_subdirectory(runtime/platform/test)
28+
add_subdirectory(test/utils)
29+
endif()

backends/xnnpack/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,7 @@ install(
140140
INCLUDES
141141
DESTINATION ${_common_include_directories}
142142
)
143+
144+
if(BUILD_TESTING)
145+
add_subdirectory(test)
146+
endif()

backends/xnnpack/test/CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,13 @@
1212
#
1313

1414
cmake_minimum_required(VERSION 3.19)
15-
project(backends_xnnpack_test)
16-
17-
# Use C++17 for test.
18-
set(CMAKE_CXX_STANDARD 17)
1915

2016
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
2117

2218
include(${EXECUTORCH_ROOT}/build/Test.cmake)
2319

24-
set(_test_srcs # We can't put runtime/test_runtime_utils.cpp because we don't
25-
# build aten
20+
set(_test_srcs
2621
runtime/test_xnnexecutor.cpp
27-
${EXECUTORCH_ROOT}/extension/threadpool/threadpool.cpp
28-
${EXECUTORCH_ROOT}/extension/threadpool/threadpool_guard.cpp
2922
${EXECUTORCH_ROOT}/extension/threadpool/test/threadpool_test.cpp
3023
)
3124

build/Test.cmake

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,6 @@
1717
# It should also be cmake-lint clean.
1818
#
1919

20-
include(${EXECUTORCH_ROOT}/build/Utils.cmake)
21-
22-
# Find prebuilt executorch library
23-
find_package(executorch CONFIG REQUIRED)
24-
25-
enable_testing()
26-
find_package(GTest CONFIG REQUIRED)
27-
28-
target_link_options_shared_lib(cpuinfo)
29-
target_link_options_shared_lib(extension_data_loader)
30-
target_link_options_shared_lib(portable_kernels)
31-
target_link_options_shared_lib(portable_ops_lib)
32-
target_link_options_shared_lib(pthreadpool)
33-
target_link_options_shared_lib(quantized_ops_lib)
34-
35-
# Add code coverage flags to supported compilers
36-
if(EXECUTORCH_USE_CPP_CODE_COVERAGE)
37-
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
38-
string(APPEND CMAKE_C_FLAGS " --coverage -fprofile-abs-path")
39-
string(APPEND CMAKE_CXX_FLAGS " --coverage -fprofile-abs-path")
40-
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
41-
string(APPEND CMAKE_C_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
42-
string(APPEND CMAKE_CXX_FLAGS
43-
" -fprofile-instr-generate -fcoverage-mapping"
44-
)
45-
else()
46-
message(ERROR
47-
"Code coverage for compiler ${CMAKE_CXX_COMPILER_ID} is unsupported"
48-
)
49-
endif()
50-
endif()
51-
5220
# A helper function to generate a gtest cxx executable target @param
5321
# target_name: name for the executable @param SOURCES <list_of_sources>: test
5422
# sources to be compiled. Sometimes util sources are used as well @param EXTRA
@@ -67,24 +35,14 @@ function(et_cxx_test target_name)
6735
set(multi_arg_names SOURCES EXTRA_LIBS)
6836
cmake_parse_arguments(ET_CXX_TEST "" "" "${multi_arg_names}" ${ARGN})
6937

70-
# Let files say "include <executorch/path/to/header.h>".
71-
target_include_directories(executorch INTERFACE ${EXECUTORCH_ROOT}/..)
72-
73-
set(ET_TEST_UTIL_SOURCES
74-
${EXECUTORCH_ROOT}/runtime/core/exec_aten/testing_util/tensor_util.cpp
75-
)
76-
77-
add_executable(${target_name} ${ET_CXX_TEST_SOURCES} ${ET_TEST_UTIL_SOURCES})
38+
add_executable(${target_name} ${ET_CXX_TEST_SOURCES} ${EXECUTORCH_ROOT}/runtime/core/exec_aten/testing_util/tensor_util.cpp)
7839
# Includes gtest, gmock, executorch by default
7940
target_link_libraries(
8041
${target_name} GTest::gtest GTest::gtest_main GTest::gmock executorch
8142
${ET_CXX_TEST_EXTRA_LIBS}
8243
)
8344

84-
# add_test adds a test target to be used by ctest. We use `ExecuTorchTest` as
85-
# the ctest target name for the test executable Usage: cd
86-
# cmake-out/path/to/test/; ctest Note: currently we directly invoke the test
87-
# target, without using ctest
88-
add_test(ExecuTorchTest ${target_name})
45+
# add_test adds a test target to be used by ctest
46+
add_test(NAME ${target_name} COMMAND ${target_name})
8947

9048
endfunction()

devtools/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,8 @@ install(
218218
INCLUDES
219219
DESTINATION ${_common_include_directories}
220220
)
221+
222+
if(BUILD_TESTING)
223+
# TODO: This is currently not working!
224+
# add_subdirectory(etdump/tests)
225+
endif()

devtools/etdump/tests/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
#
1313

1414
cmake_minimum_required(VERSION 3.19)
15-
project(sdk_etdump_tests)
16-
17-
# Use C++17 for test.
18-
set(CMAKE_CXX_STANDARD 17)
1915

2016
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
2117

@@ -30,7 +26,7 @@ et_cxx_test(
3026
EXTRA_LIBS
3127
bundled_program
3228
etdump
33-
flatccrt_d
29+
flatccrt
3430
)
3531
target_include_directories(
3632
sdk_etdump_tests PRIVATE ${CMAKE_INSTALL_PREFIX}/sdk/include

examples/models/llama/tokenizer/test/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
#
1313

1414
cmake_minimum_required(VERSION 3.19)
15-
project(tokenizer_test)
16-
17-
# Use C++17 for test.
18-
set(CMAKE_CXX_STANDARD 17)
1915

2016
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..)
2117

extension/data_loader/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ install(
2929
INCLUDES
3030
DESTINATION ${_common_include_directories}
3131
)
32+
33+
if(BUILD_TESTING)
34+
add_subdirectory(test)
35+
endif()

extension/data_loader/test/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
#
1515

1616
cmake_minimum_required(VERSION 3.19)
17-
project(extension_data_loader_test)
18-
19-
# Use C++17 for test.
20-
set(CMAKE_CXX_STANDARD 17)
2117

2218
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
2319

extension/evalue_util/test/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
#
1515

1616
cmake_minimum_required(VERSION 3.19)
17-
project(extension_evalue_util_test)
18-
19-
# Use C++17 for test.
20-
set(CMAKE_CXX_STANDARD 17)
2117

2218
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
2319

extension/kernel_util/test/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
#
1515

1616
cmake_minimum_required(VERSION 3.19)
17-
project(extension_kernel_util_test)
18-
19-
# Use C++17 for test.
20-
set(CMAKE_CXX_STANDARD 17)
2117

2218
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
2319

extension/memory_allocator/test/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
#
1515

1616
cmake_minimum_required(VERSION 3.19)
17-
project(extension_memory_allocator_test)
18-
19-
# Use C++17 for test.
20-
set(CMAKE_CXX_STANDARD 17)
2117

2218
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
2319

extension/module/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@ install(
5151
INCLUDES
5252
DESTINATION ${_common_include_directories}
5353
)
54+
55+
if(BUILD_TESTING)
56+
add_subdirectory(test)
57+
endif()

extension/module/test/CMakeLists.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
# @generated by test/utils/generate_gtest_cmakelists.py
8-
#
97
# This file should be formatted with
108
# ~~~
119
# cmake-format -i CMakeLists.txt
@@ -14,10 +12,6 @@
1412
#
1513

1614
cmake_minimum_required(VERSION 3.19)
17-
project(extension_module_test)
18-
19-
# Use C++17 for test.
20-
set(CMAKE_CXX_STANDARD 17)
2115

2216
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
2317

@@ -36,3 +30,11 @@ et_cxx_test(
3630
portable_kernels
3731
portable_ops_lib
3832
)
33+
34+
set(test_env "RESOURCES_PATH=${EXECUTORCH_ROOT}/extension/module/test/resources")
35+
36+
set_property(
37+
TEST extension_module_test
38+
PROPERTY ENVIRONMENT
39+
"${test_env}"
40+
)

extension/pytree/test/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
#
1515

1616
cmake_minimum_required(VERSION 3.19)
17-
project(extension_pytree_test)
18-
19-
# Use C++17 for test.
20-
set(CMAKE_CXX_STANDARD 17)
2117

2218
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
2319

extension/runner_util/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ install(
2929
INCLUDES
3030
DESTINATION ${_common_include_directories}
3131
)
32+
33+
if(BUILD_TESTING)
34+
add_subdirectory(test)
35+
endif()

extension/runner_util/test/CMakeLists.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
# @generated by test/utils/generate_gtest_cmakelists.py
8-
#
97
# This file should be formatted with
108
# ~~~
119
# cmake-format -i CMakeLists.txt
@@ -14,10 +12,6 @@
1412
#
1513

1614
cmake_minimum_required(VERSION 3.19)
17-
project(extension_runner_util_test)
18-
19-
# Use C++17 for test.
20-
set(CMAKE_CXX_STANDARD 17)
2115

2216
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
2317

@@ -35,3 +29,7 @@ et_cxx_test(
3529
portable_kernels
3630
portable_ops_lib
3731
)
32+
set_property(
33+
TEST extension_runner_util_test
34+
PROPERTY ENVIRONMENT "ET_MODULE_ADD_PATH=${CMAKE_BINARY_DIR}/ModuleAdd.pte"
35+
)

extension/tensor/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ install(
2929
INCLUDES
3030
DESTINATION ${_common_include_directories}
3131
)
32+
33+
if(BUILD_TESTING)
34+
add_subdirectory(test)
35+
endif()

extension/tensor/test/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
#
1515

1616
cmake_minimum_required(VERSION 3.19)
17-
project(extension_tensor_test)
18-
19-
# Use C++17 for test.
20-
set(CMAKE_CXX_STANDARD 17)
2117

2218
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
2319

kernels/portable/cpu/util/test/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
#
1515

1616
cmake_minimum_required(VERSION 3.19)
17-
project(kernels_portable_cpu_util_test)
18-
19-
# Use C++17 for test.
20-
set(CMAKE_CXX_STANDARD 17)
2117

2218
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..)
2319

0 commit comments

Comments
 (0)