[compiler-rt] r341306 - [UBSan] Add CMake and lit support for configuring and running UBSan

Dan Liew via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 3 03:30:10 PDT 2018


Author: delcypher
Date: Mon Sep  3 03:30:10 2018
New Revision: 341306

URL: http://llvm.org/viewvc/llvm-project?rev=341306&view=rev
Log:
[UBSan] Add CMake and lit support for configuring and running UBSan
tests for ios, watchos, tvos, and their simulator counterparts.

This commit does not make the tests actually pass. This will be handled
in later commits.

rdar://problem/41126835

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

Modified:
    compiler-rt/trunk/test/ubsan/CMakeLists.txt
    compiler-rt/trunk/test/ubsan/lit.common.cfg
    compiler-rt/trunk/test/ubsan/lit.site.cfg.in

Modified: compiler-rt/trunk/test/ubsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/CMakeLists.txt?rev=341306&r1=341305&r2=341306&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/ubsan/CMakeLists.txt Mon Sep  3 03:30:10 2018
@@ -62,6 +62,31 @@ foreach(arch ${UBSAN_TEST_ARCH})
   endif()
 endforeach()
 
+macro(add_ubsan_device_testsuite test_mode sanitizer platform arch)
+  # Note we expect the caller to have already set UBSAN_TEST_TARGET_CFLAGS
+  set(UBSAN_LIT_TEST_MODE "${test_mode}")
+  set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE}-${platform}-${arch})
+  set(UBSAN_TEST_TARGET_ARCH ${arch})
+  set(UBSAN_TEST_USE_LLD "False")
+  set(UBSAN_TEST_USE_THINLTO "False")
+  if (APPLE)
+    set(UBSAN_TEST_APPLE_PLATFORM "${platform}")
+  else()
+    unset(UBSAN_TEST_APPLE_PLATFORM)
+  endif()
+  configure_lit_site_cfg(
+    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+    ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg)
+  #list(APPEND UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
+  if(NOT COMPILER_RT_STANDALONE_BUILD)
+    list(APPEND UBSAN_TEST_DEPS ${sanitizer})
+  endif()
+  add_lit_testsuite(check-ubsan-${test_mode}-${platform}-${arch}
+    "UBSan ${CONFIG_NAME} tests"
+    ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
+    DEPENDS ${UBSAN_TEST_DEPS})
+endmacro()
+
 if(APPLE)
   foreach(arch ${UBSAN_TEST_ARCH})
     set(UBSAN_TEST_TARGET_ARCH ${arch})
@@ -69,9 +94,47 @@ if(APPLE)
     set(UBSAN_TEST_TARGET_CFLAGS "${UBSAN_TEST_TARGET_CFLAGS} -lc++abi")
     add_ubsan_testsuites("StandaloneStatic" ubsan ${arch})
   endforeach()
+
+  # Device and simulator test suites.
+  # These are not added into "check-all", in order to run these tests, use
+  # "check-asan-iossim-x86_64" and similar. They also require that an extra env
+  # variable to select which iOS device or simulator to use, e.g.:
+  # SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"
+  set(EXCLUDE_FROM_ALL ON)
+  set(UBSAN_APPLE_PLATFORMS "")
+  if (COMPILER_RT_ENABLE_IOS)
+    list(APPEND UBSAN_APPLE_PLATFORMS ios iossim)
+  endif()
+  if (COMPILER_RT_ENABLE_WATCHOS)
+    list(APPEND UBSAN_APPLE_PLATFORMS watchos watchossim)
+  endif()
+  if (COMPILER_RT_ENABLE_TVOS)
+    list(APPEND UBSAN_APPLE_PLATFORMS tvos tvossim)
+  endif()
+  foreach(platform ${UBSAN_APPLE_PLATFORMS})
+    foreach(arch ${DARWIN_${platform}_ARCHS})
+      get_target_flags_for_arch(${arch} UBSAN_TEST_TARGET_ARCH_FLAGS_AS_LIST)
+      string(REPLACE ";" " " UBSAN_TEST_TARGET_ARCH_FLAGS "${UBSAN_TEST_TARGET_ARCH_FLAGS_AS_LIST}")
+      set(UBSAN_TEST_TARGET_CFLAGS
+        "${UBSAN_TEST_TARGET_ARCH_FLAGS} -isysroot ${DARWIN_${platform}_SYSROOT}")
+      if (";${UBSAN_SUPPORTED_ARCH};" MATCHES ";${arch}")
+        add_ubsan_device_testsuite("Standalone" ubsan ${platform} ${arch})
+      endif()
+
+      if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
+        add_ubsan_device_testsuite("AddressSanitizer" asan ${platform} ${arch})
+      endif()
+
+      if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
+        add_ubsan_device_testsuite("ThreadSanitizer" tsan ${platform} ${arch})
+      endif()
+    endforeach()
+  endforeach()
+  set(EXCLUDE_FROM_ALL OFF)
 endif()
 
 add_lit_testsuite(check-ubsan "Running UndefinedBehaviorSanitizer tests"
   ${UBSAN_TESTSUITES}
   DEPENDS ${UBSAN_TEST_DEPS})
 set_target_properties(check-ubsan PROPERTIES FOLDER "Compiler-RT Misc")
+

Modified: compiler-rt/trunk/test/ubsan/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/lit.common.cfg?rev=341306&r1=341305&r2=341306&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/lit.common.cfg (original)
+++ compiler-rt/trunk/test/ubsan/lit.common.cfg Mon Sep  3 03:30:10 2018
@@ -74,3 +74,8 @@ if config.host_os not in ['Linux', 'Darw
 config.available_features.add('arch=' + config.target_arch)
 
 config.excludes = ['Inputs']
+
+# Limit parallelism if necessary
+if config.host_os == 'Darwin':
+  if config.apple_platform != "osx" and not config.apple_platform.endswith("sim"):
+    config.parallelism_group = "darwin-ios-device-sanitizer"

Modified: compiler-rt/trunk/test/ubsan/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/lit.site.cfg.in?rev=341306&r1=341305&r2=341306&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/lit.site.cfg.in (original)
+++ compiler-rt/trunk/test/ubsan/lit.site.cfg.in Mon Sep  3 03:30:10 2018
@@ -7,6 +7,7 @@ config.target_cflags = "@UBSAN_TEST_TARG
 config.target_arch = "@UBSAN_TEST_TARGET_ARCH@"
 config.use_lld = @UBSAN_TEST_USE_LLD@
 config.use_thinlto = @UBSAN_TEST_USE_THINLTO@
+config.apple_platform = "@UBSAN_TEST_APPLE_PLATFORM@"
 
 # Load common config for all compiler-rt lit tests.
 lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")




More information about the llvm-commits mailing list