[compiler-rt] 1262745 - [CMake][NFC] Refactor iOS simulator/device test configuration generation code for ASan.

Dan Liew via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 23 12:44:39 PST 2020


Author: Dan Liew
Date: 2020-01-23T12:44:00-08:00
New Revision: 12627450609cf0a0a5c3bc7419fbb642740a5bb2

URL: https://github.com/llvm/llvm-project/commit/12627450609cf0a0a5c3bc7419fbb642740a5bb2
DIFF: https://github.com/llvm/llvm-project/commit/12627450609cf0a0a5c3bc7419fbb642740a5bb2.diff

LOG: [CMake][NFC] Refactor iOS simulator/device test configuration generation code for ASan.

Summary:
The previous code hard-coded platform names but compiler-rt's CMake
build system actually already knows which Apple platforms ASan supports.

This change uses this information to enumerate the different Apple
platforms.

rdar://problem/58798733

Reviewers: kubamracek, yln

Subscribers: mgorny, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D73232

Added: 
    

Modified: 
    compiler-rt/cmake/config-ix.cmake
    compiler-rt/test/asan/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index 3aad08e88969..c1d0f65854bc 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -224,6 +224,18 @@ function(get_test_cflags_for_apple_platform platform arch cflags_out)
   set(${cflags_out} "${test_cflags_str}" PARENT_SCOPE)
 endfunction()
 
+function(get_capitalized_apple_platform platform platform_capitalized)
+  # TODO(dliew): Remove uses of this function. It exists to preserve needlessly complex
+  # directory naming conventions used by the Sanitizer lit test suites.
+  is_valid_apple_platform("${platform}" is_valid_platform)
+  if (NOT is_valid_platform)
+    message(FATAL_ERROR "\"${platform}\" is not a valid apple platform")
+  endif()
+  string(TOUPPER "${platform}" platform_upper)
+  string(REGEX REPLACE "OSSIM$" "OSSim" platform_upper_capitalized "${platform_upper}")
+  set(${platform_capitalized} "${platform_upper_capitalized}" PARENT_SCOPE)
+endfunction()
+
 function(is_valid_apple_platform platform is_valid_out)
   set(is_valid FALSE)
   if ("${platform}" STREQUAL "")

diff  --git a/compiler-rt/test/asan/CMakeLists.txt b/compiler-rt/test/asan/CMakeLists.txt
index e67a0e869974..316442e856ae 100644
--- a/compiler-rt/test/asan/CMakeLists.txt
+++ b/compiler-rt/test/asan/CMakeLists.txt
@@ -82,56 +82,43 @@ endforeach()
 # variable to select which iOS device or simulator to use, e.g.:
 # SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"
 if(APPLE)
-  # FIXME(dliew): This logic should be refactored to the way UBSan Darwin
-  # testing is done.
   set(EXCLUDE_FROM_ALL ON)
-
   set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
   set(ASAN_TEST_DYNAMIC True)
+  set(ASAN_APPLE_PLATFORMS ${SANITIZER_COMMON_SUPPORTED_OS})
 
-  list_intersect(ASAN_TEST_IOSSIM_ARCHS ASAN_SUPPORTED_ARCH DARWIN_iossim_ARCHS)
-  foreach(arch ${ASAN_TEST_IOSSIM_ARCHS})
-    set(ASAN_TEST_APPLE_PLATFORM "iossim")
-    set(ASAN_TEST_TARGET_ARCH ${arch})
-    get_test_cflags_for_apple_platform(
-      "${ASAN_TEST_APPLE_PLATFORM}"
-      "${ASAN_TEST_TARGET_ARCH}"
-      ASAN_TEST_TARGET_CFLAGS
-      )
-    set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-${ASAN_TEST_APPLE_PLATFORM}")
-    get_bits_for_arch(${arch} ASAN_TEST_BITS)
-    string(TOUPPER ${arch} ARCH_UPPER_CASE)
-    set(CONFIG_NAME "IOSSim${ARCH_UPPER_CASE}Config")
-    configure_lit_site_cfg(
-      ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
-      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
-      )
-    add_lit_testsuite(check-asan-iossim-${arch} "AddressSanitizer iOS Simulator ${arch} tests"
-      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
-      DEPENDS ${ASAN_TEST_DEPS})
-  endforeach()
-
-  list_intersect(ASAN_TEST_IOS_ARCHS ASAN_SUPPORTED_ARCH DARWIN_ios_ARCHS)
-  foreach (arch ${ASAN_TEST_IOS_ARCHS})
-    set(ASAN_TEST_APPLE_PLATFORM "ios")
-    set(ASAN_TEST_TARGET_ARCH ${arch})
-    get_test_cflags_for_apple_platform(
-      "${ASAN_TEST_APPLE_PLATFORM}"
-      "${arch}"
-      ASAN_TEST_TARGET_CFLAGS)
-    set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-${ASAN_TEST_APPLE_PLATFORM}")
-    get_bits_for_arch(${arch} ASAN_TEST_BITS)
-    string(TOUPPER ${arch} ARCH_UPPER_CASE)
-    set(CONFIG_NAME "IOS${ARCH_UPPER_CASE}Config")
-    configure_lit_site_cfg(
-      ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
-      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
-      )
-    add_lit_testsuite(check-asan-ios-${arch} "AddressSanitizer iOS ${arch} tests"
-      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
-      DEPENDS ${ASAN_TEST_DEPS})
+  foreach(platform ${ASAN_APPLE_PLATFORMS})
+    if ("${platform}" STREQUAL "osx")
+      # Skip macOS because it's handled by the code above that builds tests for the host machine.
+      continue()
+    endif()
+    list_intersect(
+      ASAN_TEST_${platform}_ARCHS
+      ASAN_SUPPORTED_ARCH
+      DARWIN_${platform}_ARCHS
+    )
+    foreach(arch ${ASAN_TEST_${platform}_ARCHS})
+      get_test_cflags_for_apple_platform(
+        "${platform}"
+        "${arch}"
+        ASAN_TEST_TARGET_CFLAGS
+        )
+      string(TOUPPER "${arch}" ARCH_UPPER_CASE)
+      get_capitalized_apple_platform("${platform}" PLATFORM_CAPITALIZED)
+      set(CONFIG_NAME "${PLATFORM_CAPITALIZED}${ARCH_UPPER_CASE}Config")
+      set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-${platform}")
+      set(ASAN_TEST_APPLE_PLATFORM "${platform}")
+      set(ASAN_TEST_TARGET_ARCH "${arch}")
+      get_bits_for_arch(${arch} ASAN_TEST_BITS)
+      configure_lit_site_cfg(
+        ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
+        ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
+        )
+      add_lit_testsuite(check-asan-${platform}-${arch} "AddressSanitizer ${platform} ${arch} tests"
+        ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
+        DEPENDS ${ASAN_TEST_DEPS})
+    endforeach()
   endforeach()
-
   set(EXCLUDE_FROM_ALL OFF)
 endif()
 


        


More information about the llvm-commits mailing list