Skip to content

[compiler-rt] Cleanup use of COMPILER_RT_INCLUDE_TESTS #98246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

vitalybuka
Copy link
Collaborator

  1. Move checks into parent test/CMakeLists.txt
  2. COMPILER_RT_INCLUDE_TESTS disable both lit and
    gtests. Before it was very inconsistent between
    sanitizers.

@llvmbot llvmbot added compiler-rt compiler-rt:asan Address sanitizer compiler-rt:fuzzer compiler-rt:tsan Thread sanitizer compiler-rt:scudo Scudo Hardened Allocator PGO Profile Guided Optimizations compiler-rt:msan Memory sanitizer compiler-rt:sanitizer labels Jul 9, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 9, 2024

@llvm/pr-subscribers-pgo

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Vitaly Buka (vitalybuka)

Changes
  1. Move checks into parent test/CMakeLists.txt
  2. COMPILER_RT_INCLUDE_TESTS disable both lit and
    gtests. Before it was very inconsistent between
    sanitizers.

Full diff: https://github.com/llvm/llvm-project/pull/98246.diff

14 Files Affected:

  • (modified) compiler-rt/cmake/base-config-ix.cmake (+2-2)
  • (modified) compiler-rt/test/CMakeLists.txt (+1-1)
  • (modified) compiler-rt/test/asan/CMakeLists.txt (+27-29)
  • (modified) compiler-rt/test/ctx_profile/CMakeLists.txt (+9-11)
  • (modified) compiler-rt/test/fuzzer/CMakeLists.txt (+7-11)
  • (modified) compiler-rt/test/gwp_asan/CMakeLists.txt (+2-2)
  • (modified) compiler-rt/test/interception/CMakeLists.txt (+1-1)
  • (modified) compiler-rt/test/memprof/CMakeLists.txt (+9-11)
  • (modified) compiler-rt/test/msan/CMakeLists.txt (+1-3)
  • (modified) compiler-rt/test/nsan/CMakeLists.txt (+1-3)
  • (modified) compiler-rt/test/rtsan/CMakeLists.txt (+10-12)
  • (modified) compiler-rt/test/sanitizer_common/CMakeLists.txt (+7-9)
  • (modified) compiler-rt/test/scudo/standalone/CMakeLists.txt (+16-18)
  • (modified) compiler-rt/test/tsan/CMakeLists.txt (+10-12)
diff --git a/compiler-rt/cmake/base-config-ix.cmake b/compiler-rt/cmake/base-config-ix.cmake
index 87137b3d111b6..5b52a30a94aaf 100644
--- a/compiler-rt/cmake/base-config-ix.cmake
+++ b/compiler-rt/cmake/base-config-ix.cmake
@@ -43,7 +43,7 @@ if (LLVM_TREE_AVAILABLE)
   get_clang_resource_dir(COMPILER_RT_OUTPUT_DIR PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/..)
   set(COMPILER_RT_EXEC_OUTPUT_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
   get_clang_resource_dir(COMPILER_RT_INSTALL_PATH)
-  option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests."
+  option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt tests."
          ${LLVM_INCLUDE_TESTS})
   option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered"
          ${LLVM_ENABLE_WERROR})
@@ -70,7 +70,7 @@ else()
     "Path where built compiler-rt executables should be stored.")
   set(COMPILER_RT_INSTALL_PATH "" CACHE PATH
     "Prefix for directories where built compiler-rt artifacts should be installed.")
-  option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests." OFF)
+  option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt tests." OFF)
   option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered" OFF)
   # Use a host compiler to compile/link tests.
   set(COMPILER_RT_TEST_COMPILER ${CMAKE_C_COMPILER} CACHE PATH "Compiler to use for testing")
diff --git a/compiler-rt/test/CMakeLists.txt b/compiler-rt/test/CMakeLists.txt
index 5982260c2d854..3d52bb552ccda 100644
--- a/compiler-rt/test/CMakeLists.txt
+++ b/compiler-rt/test/CMakeLists.txt
@@ -48,7 +48,7 @@ umbrella_lit_testsuite_begin(check-compiler-rt)
 
 function(compiler_rt_test_runtime runtime)
   string(TOUPPER ${runtime} runtime_uppercase)
-  if(COMPILER_RT_HAS_${runtime_uppercase})
+  if(COMPILER_RT_HAS_${runtime_uppercase} AND COMPILER_RT_INCLUDE_TESTS)
     if (${runtime} STREQUAL scudo_standalone)
       add_subdirectory(scudo/standalone)
     else()
diff --git a/compiler-rt/test/asan/CMakeLists.txt b/compiler-rt/test/asan/CMakeLists.txt
index 2d683e61d6954..fb9e81bbe8082 100644
--- a/compiler-rt/test/asan/CMakeLists.txt
+++ b/compiler-rt/test/asan/CMakeLists.txt
@@ -130,39 +130,37 @@ if(APPLE)
 endif()
 
 # Add unit tests.
-if(COMPILER_RT_INCLUDE_TESTS)
-  foreach(arch ${ASAN_TEST_ARCH})
-    string(TOUPPER ${arch} ARCH_UPPER_CASE)
-    set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
-    set(CONFIG_NAME_DYNAMIC ${ARCH_UPPER_CASE}${OS_NAME}DynamicConfig)
+foreach(arch ${ASAN_TEST_ARCH})
+  string(TOUPPER ${arch} ARCH_UPPER_CASE)
+  set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
+  set(CONFIG_NAME_DYNAMIC ${ARCH_UPPER_CASE}${OS_NAME}DynamicConfig)
 
-    if(NOT MINGW)
-      # MinGW environments don't provide a statically linked CRT, so only the
-      # dynamic asan test configuration can be expected to work.
-      set(ASAN_TEST_DYNAMIC False)
-      configure_lit_site_cfg(
-        ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
-        ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME}/lit.site.cfg.py)
+  if(NOT MINGW)
+    # MinGW environments don't provide a statically linked CRT, so only the
+    # dynamic asan test configuration can be expected to work.
+    set(ASAN_TEST_DYNAMIC False)
+    configure_lit_site_cfg(
+      ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
+      ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME}/lit.site.cfg.py)
+  endif()
+  if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
+    set(ASAN_TEST_DYNAMIC True)
+    configure_lit_site_cfg(
+      ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
+      ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME_DYNAMIC}/lit.site.cfg.py)
+  endif()
+  # FIXME: support unit test in the android test runner
+  if (NOT ANDROID)
+    if (NOT MINGW)
+      list(APPEND ASAN_TEST_DEPS AsanUnitTests)
+      list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME})
     endif()
     if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
-      set(ASAN_TEST_DYNAMIC True)
-      configure_lit_site_cfg(
-        ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
-        ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME_DYNAMIC}/lit.site.cfg.py)
+      list(APPEND ASAN_DYNAMIC_TEST_DEPS AsanDynamicUnitTests)
+      list(APPEND ASAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME_DYNAMIC})
     endif()
-    # FIXME: support unit test in the android test runner
-    if (NOT ANDROID)
-      if (NOT MINGW)
-        list(APPEND ASAN_TEST_DEPS AsanUnitTests)
-        list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME})
-      endif()
-      if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
-        list(APPEND ASAN_DYNAMIC_TEST_DEPS AsanDynamicUnitTests)
-        list(APPEND ASAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME_DYNAMIC})
-      endif()
-    endif()
-  endforeach()
-endif()
+  endif()
+endforeach()
 
 if (SHADOW_MAPPING_UNRELIABLE)
   set(exclude_from_check_all.g "EXCLUDE_FROM_CHECK_ALL")
diff --git a/compiler-rt/test/ctx_profile/CMakeLists.txt b/compiler-rt/test/ctx_profile/CMakeLists.txt
index 371f1a2dcbb05..fc3b3f3ec431f 100644
--- a/compiler-rt/test/ctx_profile/CMakeLists.txt
+++ b/compiler-rt/test/ctx_profile/CMakeLists.txt
@@ -25,17 +25,15 @@ foreach(arch ${CTX_PROFILE_SUPPORTED_ARCH})
 endforeach()
 
 # Add unit tests.
-if(COMPILER_RT_INCLUDE_TESTS)
-  foreach(arch ${CTX_PROFILE_SUPPORTED_ARCH})
-    string(TOUPPER ${arch} ARCH_UPPER_CASE)
-    set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
-    configure_lit_site_cfg(
-      ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
-      ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME}/lit.site.cfg.py)
-    list(APPEND CTX_PROFILE_TEST_DEPS CtxProfileUnitTests)
-    list(APPEND CTX_PROFILE_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME})
-  endforeach()
-endif()
+foreach(arch ${CTX_PROFILE_SUPPORTED_ARCH})
+  string(TOUPPER ${arch} ARCH_UPPER_CASE)
+  set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
+  configure_lit_site_cfg(
+    ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
+    ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME}/lit.site.cfg.py)
+  list(APPEND CTX_PROFILE_TEST_DEPS CtxProfileUnitTests)
+  list(APPEND CTX_PROFILE_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME})
+endforeach()
 
 add_lit_testsuite(check-ctx_profile "Running the Contextual Profiler tests"
   ${CTX_PROFILE_TESTSUITES}
diff --git a/compiler-rt/test/fuzzer/CMakeLists.txt b/compiler-rt/test/fuzzer/CMakeLists.txt
index 8d29a4bea5f34..b19f52e591fc0 100644
--- a/compiler-rt/test/fuzzer/CMakeLists.txt
+++ b/compiler-rt/test/fuzzer/CMakeLists.txt
@@ -22,20 +22,16 @@ if (APPLE)
   darwin_filter_host_archs(FUZZER_SUPPORTED_ARCH FUZZER_TEST_ARCH)
 endif()
 
-if(COMPILER_RT_INCLUDE_TESTS)
-  list(APPEND LIBFUZZER_TEST_DEPS FuzzerUnitTests)
-  list(APPEND LIBFUZZER_TEST_DEPS FuzzedDataProviderUnitTests)
-endif()
+list(APPEND LIBFUZZER_TEST_DEPS FuzzerUnitTests)
+list(APPEND LIBFUZZER_TEST_DEPS FuzzedDataProviderUnitTests)
 
 set(LIBFUZZER_TESTSUITES)
 
-if(COMPILER_RT_INCLUDE_TESTS)
-  # libFuzzer unit tests.
-  configure_lit_site_cfg(
-    ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.py.in
-    ${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg.py)
-  list(APPEND LIBFUZZER_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/unit)
-endif()
+# libFuzzer unit tests.
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.py.in
+  ${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg.py)
+list(APPEND LIBFUZZER_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/unit)
 
 macro(test_fuzzer stdlib)
   cmake_parse_arguments(TEST "" "" "DEPS" ${ARGN})
diff --git a/compiler-rt/test/gwp_asan/CMakeLists.txt b/compiler-rt/test/gwp_asan/CMakeLists.txt
index f9580e2592b2f..6ffa36e7ebbda 100644
--- a/compiler-rt/test/gwp_asan/CMakeLists.txt
+++ b/compiler-rt/test/gwp_asan/CMakeLists.txt
@@ -14,7 +14,7 @@ set(GWP_ASAN_TEST_DEPS
 # exported libc++ from the Android NDK is x86-64, even though it's part of the
 # ARM[64] toolchain... See similar measures for ASan and sanitizer-common that
 # disable unit tests for Android.
-if (COMPILER_RT_INCLUDE_TESTS AND NOT ANDROID)
+if (NOT ANDROID)
   list(APPEND GWP_ASAN_TEST_DEPS GwpAsanUnitTests)
   configure_lit_site_cfg(
     ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.py.in
@@ -22,7 +22,7 @@ if (COMPILER_RT_INCLUDE_TESTS AND NOT ANDROID)
   list(APPEND GWP_ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/unit)
 endif()
 
-if (COMPILER_RT_INCLUDE_TESTS AND COMPILER_RT_HAS_SCUDO_STANDALONE)
+if (COMPILER_RT_HAS_SCUDO_STANDALONE)
   foreach(arch ${GWP_ASAN_SUPPORTED_ARCH})
     set(GWP_ASAN_TEST_TARGET_ARCH ${arch})
     string(TOLOWER "-${arch}" GWP_ASAN_TEST_CONFIG_SUFFIX)
diff --git a/compiler-rt/test/interception/CMakeLists.txt b/compiler-rt/test/interception/CMakeLists.txt
index df69453c4fb4e..8ed1a003c1b3c 100644
--- a/compiler-rt/test/interception/CMakeLists.txt
+++ b/compiler-rt/test/interception/CMakeLists.txt
@@ -3,7 +3,7 @@ set(INTERCEPTION_TESTSUITES)
 
 # Unit tests. There are currently no unit tests capable to running on Apple or
 # Android targets.
-if(COMPILER_RT_INCLUDE_TESTS AND NOT ANDROID AND NOT APPLE)
+if(NOT ANDROID AND NOT APPLE)
   configure_lit_site_cfg(
     ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
     ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py)
diff --git a/compiler-rt/test/memprof/CMakeLists.txt b/compiler-rt/test/memprof/CMakeLists.txt
index 001245215201e..4c50ae6b83719 100644
--- a/compiler-rt/test/memprof/CMakeLists.txt
+++ b/compiler-rt/test/memprof/CMakeLists.txt
@@ -44,17 +44,15 @@ foreach(arch ${MEMPROF_TEST_ARCH})
 endforeach()
 
 # Add unit tests.
-if(COMPILER_RT_INCLUDE_TESTS)
-  foreach(arch ${MEMPROF_TEST_ARCH})
-    string(TOUPPER ${arch} ARCH_UPPER_CASE)
-    set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
-    configure_lit_site_cfg(
-      ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
-      ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME}/lit.site.cfg.py)
-    list(APPEND MEMPROF_TEST_DEPS MemProfUnitTests)
-    list(APPEND MEMPROF_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME})
-  endforeach()
-endif()
+foreach(arch ${MEMPROF_TEST_ARCH})
+  string(TOUPPER ${arch} ARCH_UPPER_CASE)
+  set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
+  configure_lit_site_cfg(
+    ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
+    ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME}/lit.site.cfg.py)
+  list(APPEND MEMPROF_TEST_DEPS MemProfUnitTests)
+  list(APPEND MEMPROF_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME})
+endforeach()
 
 add_lit_testsuite(check-memprof "Running the MemProfiler tests"
   ${MEMPROF_TESTSUITES}
diff --git a/compiler-rt/test/msan/CMakeLists.txt b/compiler-rt/test/msan/CMakeLists.txt
index ff19c11971b2d..df5719761e607 100644
--- a/compiler-rt/test/msan/CMakeLists.txt
+++ b/compiler-rt/test/msan/CMakeLists.txt
@@ -41,9 +41,7 @@ foreach(arch ${MSAN_TEST_ARCH})
   endif()
 endforeach()
 
-if(COMPILER_RT_INCLUDE_TESTS AND
-   COMPILER_RT_LIBCXX_PATH AND
-   COMPILER_RT_LIBCXXABI_PATH)
+if(COMPILER_RT_LIBCXX_PATH AND COMPILER_RT_LIBCXXABI_PATH)
   configure_lit_site_cfg(
     ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
     ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py)
diff --git a/compiler-rt/test/nsan/CMakeLists.txt b/compiler-rt/test/nsan/CMakeLists.txt
index fb73587574fba..d702e122a85ef 100644
--- a/compiler-rt/test/nsan/CMakeLists.txt
+++ b/compiler-rt/test/nsan/CMakeLists.txt
@@ -3,9 +3,7 @@ set(NSAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 set(NSAN_TESTSUITES)
 set(NSAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS} nsan)
 
-if(COMPILER_RT_INCLUDE_TESTS AND
-   COMPILER_RT_LIBCXX_PATH AND
-   COMPILER_RT_LIBCXXABI_PATH)
+if(COMPILER_RT_LIBCXX_PATH AND COMPILER_RT_LIBCXXABI_PATH)
   configure_lit_site_cfg(
     ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
     ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py)
diff --git a/compiler-rt/test/rtsan/CMakeLists.txt b/compiler-rt/test/rtsan/CMakeLists.txt
index 2a59a57f27372..e1f9eb39408dc 100644
--- a/compiler-rt/test/rtsan/CMakeLists.txt
+++ b/compiler-rt/test/rtsan/CMakeLists.txt
@@ -34,20 +34,18 @@ foreach(arch ${RTSAN_TEST_ARCH})
   list(APPEND RTSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
 endforeach()
 
-if(COMPILER_RT_INCLUDE_TESTS)
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
+  ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py)
+if(COMPILER_RT_RTSAN_HAS_STATIC_RUNTIME)
   configure_lit_site_cfg(
     ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
-    ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py)
-  if(COMPILER_RT_RTSAN_HAS_STATIC_RUNTIME)
-    configure_lit_site_cfg(
-      ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
-      ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic/lit.site.cfg.py)
-  endif()
-  list(APPEND RTSAN_TEST_DEPS RtsanUnitTests)
-  list(APPEND RTSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit)
-  if(COMPILER_RT_RTSAN_HAS_STATIC_RUNTIME)
-    list(APPEND RTSAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic)
-  endif()
+    ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic/lit.site.cfg.py)
+endif()
+list(APPEND RTSAN_TEST_DEPS RtsanUnitTests)
+list(APPEND RTSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit)
+if(COMPILER_RT_RTSAN_HAS_STATIC_RUNTIME)
+  list(APPEND RTSAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic)
 endif()
 
 add_lit_testsuite(check-rtsan "Running the Rtsan tests"
diff --git a/compiler-rt/test/sanitizer_common/CMakeLists.txt b/compiler-rt/test/sanitizer_common/CMakeLists.txt
index edecc04d48c75..fa06b82acebd9 100644
--- a/compiler-rt/test/sanitizer_common/CMakeLists.txt
+++ b/compiler-rt/test/sanitizer_common/CMakeLists.txt
@@ -99,15 +99,13 @@ foreach(tool ${SUPPORTED_TOOLS})
 endforeach()
 
 # Unit tests.
-if(COMPILER_RT_INCLUDE_TESTS)
-  configure_lit_site_cfg(
-    ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
-    ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py)
-  # FIXME: support unit test in the android test runner
-  if (NOT ANDROID)
-    list(APPEND SANITIZER_COMMON_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit)
-    list(APPEND SANITIZER_COMMON_TEST_DEPS SanitizerUnitTests)
-  endif()
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
+  ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py)
+# FIXME: support unit test in the android test runner
+if (NOT ANDROID)
+  list(APPEND SANITIZER_COMMON_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit)
+  list(APPEND SANITIZER_COMMON_TEST_DEPS SanitizerUnitTests)
 endif()
 
 if(SANITIZER_COMMON_TESTSUITES)
diff --git a/compiler-rt/test/scudo/standalone/CMakeLists.txt b/compiler-rt/test/scudo/standalone/CMakeLists.txt
index 0034cea360f37..3e6c8ab234b7e 100644
--- a/compiler-rt/test/scudo/standalone/CMakeLists.txt
+++ b/compiler-rt/test/scudo/standalone/CMakeLists.txt
@@ -1,21 +1,19 @@
-if(COMPILER_RT_INCLUDE_TESTS)
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.py.in
+  ${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg.py)
+list(APPEND SCUDO_STANDALONE_TEST_DEPS ScudoUnitTests)
+list(APPEND SCUDO_STANDALONE_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/unit)
+if (COMPILER_RT_HAS_GWP_ASAN)
   configure_lit_site_cfg(
-    ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.py.in
-    ${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg.py)
-  list(APPEND SCUDO_STANDALONE_TEST_DEPS ScudoUnitTests)
-  list(APPEND SCUDO_STANDALONE_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/unit)
-  if (COMPILER_RT_HAS_GWP_ASAN)
-    configure_lit_site_cfg(
-      ${CMAKE_CURRENT_SOURCE_DIR}/unit/gwp_asan/lit.site.cfg.py.in
-      ${CMAKE_CURRENT_BINARY_DIR}/unit/gwp_asan/lit.site.cfg.py)
-    list(APPEND SCUDO_STANDALONE_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/unit/gwp_asan)
-  endif()
+    ${CMAKE_CURRENT_SOURCE_DIR}/unit/gwp_asan/lit.site.cfg.py.in
+    ${CMAKE_CURRENT_BINARY_DIR}/unit/gwp_asan/lit.site.cfg.py)
+  list(APPEND SCUDO_STANDALONE_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/unit/gwp_asan)
+endif()
 
-  add_lit_testsuite(check-scudo_standalone
-    "Running Scudo Standalone tests"
-    ${SCUDO_STANDALONE_TESTSUITES}
-    DEPENDS ${SCUDO_STANDALONE_TEST_DEPS})
+add_lit_testsuite(check-scudo_standalone
+  "Running Scudo Standalone tests"
+  ${SCUDO_STANDALONE_TESTSUITES}
+  DEPENDS ${SCUDO_STANDALONE_TEST_DEPS})
 
-  set_target_properties(check-scudo_standalone
-    PROPERTIES FOLDER "Compiler-RT Tests")
-endif()
+set_target_properties(check-scudo_standalone
+  PROPERTIES FOLDER "Compiler-RT Tests")
diff --git a/compiler-rt/test/tsan/CMakeLists.txt b/compiler-rt/test/tsan/CMakeLists.txt
index 31cda53efd47f..163355d68ebc2 100644
--- a/compiler-rt/test/tsan/CMakeLists.txt
+++ b/compiler-rt/test/tsan/CMakeLists.txt
@@ -111,20 +111,18 @@ if(APPLE)
   endforeach()
 endif()
 
-if(COMPILER_RT_INCLUDE_TESTS)
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
+  ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py)
+if(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME)
   configure_lit_site_cfg(
     ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
-    ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py)
-  if(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME)
-    configure_lit_site_cfg(
-      ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
-      ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic/lit.site.cfg.py)
-  endif()
-  list(APPEND TSAN_TEST_DEPS TsanUnitTests)
-  list(APPEND TSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit)
-  if(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME)
-    list(APPEND TSAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic)
-  endif()
+    ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic/lit.site.cfg.py)
+endif()
+list(APPEND TSAN_TEST_DEPS TsanUnitTests)
+list(APPEND TSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit)
+if(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME)
+  list(APPEND TSAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic)
 endif()
 
 add_lit_testsuite(check-tsan "Running ThreadSanitizer tests"

@vitalybuka vitalybuka requested review from petrhosek and MaskRay July 10, 2024 00:01
Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not familiar with how the tests cmake work, but this patch indeed improves consistency.

For example, foreach(arch ${MEMPROF_TEST_ARCH}) is at the toplevel while its unittest foreach is guarded by COMPILER_RT_INCLUDE_TESTS. Removing COMPILER_RT_INCLUDE_TESTS is great.

@vitalybuka vitalybuka changed the base branch from users/vitalybuka/spr/main.compiler-rt-cleanup-use-of-compiler_rt_include_tests to main July 10, 2024 20:11
1. Move checks into parent test/CMakeLists.txt
2. COMPILER_RT_INCLUDE_TESTS disable both lit and
   gtests. Before it was very inconsistent between
   sanitizers.

Reviewers: petrhosek, MaskRay

Reviewed By: MaskRay

Pull Request: #98246
@vitalybuka vitalybuka force-pushed the users/vitalybuka/spr/compiler-rt-cleanup-use-of-compiler_rt_include_tests branch from b397839 to f3fb015 Compare July 19, 2024 01:32
@vitalybuka vitalybuka merged commit d4b28fb into main Jul 19, 2024
4 of 5 checks passed
@vitalybuka vitalybuka deleted the users/vitalybuka/spr/compiler-rt-cleanup-use-of-compiler_rt_include_tests branch July 19, 2024 01:33
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
Summary:
1. Move checks into parent test/CMakeLists.txt
2. COMPILER_RT_INCLUDE_TESTS disable both lit and
   gtests. Before it was very inconsistent between
   sanitizers.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250775
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-rt:asan Address sanitizer compiler-rt:fuzzer compiler-rt:msan Memory sanitizer compiler-rt:sanitizer compiler-rt:scudo Scudo Hardened Allocator compiler-rt:tsan Thread sanitizer compiler-rt PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants