[compiler-rt] r301443 - [asan] Add support for running lit tests in the iOS Simulator
Kuba Mracek via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 26 11:59:24 PDT 2017
Author: kuba.brecka
Date: Wed Apr 26 13:59:22 2017
New Revision: 301443
URL: http://llvm.org/viewvc/llvm-project?rev=301443&view=rev
Log:
[asan] Add support for running lit tests in the iOS Simulator
This patch adds a basic support for running the ASan lit test suite against an iOS Simulator. This is done by generating more lit.site.cfg configurations into subdirectories such as IOSSimI386Config and IOSSimX86_64Config. These test suites are not added into "check-all" or into "check-asan", they have to be run manually.
Differential Revision: https://reviews.llvm.org/D31477
Added:
compiler-rt/trunk/test/sanitizer_common/ios_commands/
compiler-rt/trunk/test/sanitizer_common/ios_commands/iossim_env.py
compiler-rt/trunk/test/sanitizer_common/ios_commands/iossim_run.py
Modified:
compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
compiler-rt/trunk/test/asan/CMakeLists.txt
compiler-rt/trunk/test/asan/lit.site.cfg.in
compiler-rt/trunk/test/lit.common.cfg
compiler-rt/trunk/test/lit.common.configured.in
Modified: compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake?rev=301443&r1=301442&r2=301443&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake (original)
+++ compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake Wed Apr 26 13:59:22 2017
@@ -210,6 +210,14 @@ function(add_compiler_rt_runtime name ty
set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "")
set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib")
endif()
+ if(APPLE)
+ # Ad-hoc sign the dylibs
+ add_custom_command(TARGET ${libname}
+ POST_BUILD
+ COMMAND codesign --sign - $<TARGET_FILE:${libname}>
+ WORKING_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
+ )
+ endif()
endif()
install(TARGETS ${libname}
ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
Modified: compiler-rt/trunk/test/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/CMakeLists.txt?rev=301443&r1=301442&r2=301443&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/asan/CMakeLists.txt Wed Apr 26 13:59:22 2017
@@ -41,6 +41,12 @@ foreach(arch ${ASAN_TEST_ARCH})
else()
set(ASAN_TEST_TARGET_ARCH ${arch})
endif()
+
+ set(ASAN_TEST_IOS "0")
+ pythonize_bool(ASAN_TEST_IOS)
+ set(ASAN_TEST_IOSSIM "0")
+ pythonize_bool(ASAN_TEST_IOSSIM)
+
string(TOLOWER "-${arch}-${OS_NAME}" ASAN_TEST_CONFIG_SUFFIX)
get_bits_for_arch(${arch} ASAN_TEST_BITS)
get_test_cc_for_arch(${arch} ASAN_TEST_TARGET_CC ASAN_TEST_TARGET_CFLAGS)
@@ -69,6 +75,49 @@ foreach(arch ${ASAN_TEST_ARCH})
endif()
endforeach()
+# iOS and iOS simulator test suites
+# These are not added into "check-all", in order to run these tests, you have to
+# manually call (from the build directory). They also require that an extra env
+# variable to select which iOS device or simulator to use, e.g.:
+# $ SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER=BBE44C1C-8AAA-4000-8D06-91C89ED58172
+# $ ./bin/llvm-lit ./projects/compiler-rt/test/asan/IOSSimI386Config
+if(APPLE)
+ set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
+ set(ASAN_TEST_IOS "1")
+ pythonize_bool(ASAN_TEST_IOS)
+ set(ASAN_TEST_DYNAMIC True)
+
+ foreach(arch ${DARWIN_iossim_ARCHS})
+ set(ASAN_TEST_IOSSIM "1")
+ pythonize_bool(ASAN_TEST_IOSSIM)
+ set(ASAN_TEST_TARGET_ARCH ${arch})
+ set(ASAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_iossim_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
+ set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-iossim")
+ 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.in
+ ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
+ )
+ endforeach()
+
+ foreach (arch ${DARWIN_ios_ARCHS})
+ set(ASAN_TEST_IOSSIM "0")
+ pythonize_bool(ASAN_TEST_IOSSIM)
+ set(ASAN_TEST_TARGET_ARCH ${arch})
+ set(ASAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
+ set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-ios")
+ 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.in
+ ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
+ )
+ endforeach()
+endif()
+
# Add unit tests.
if(COMPILER_RT_INCLUDE_TESTS)
set(ASAN_TEST_DYNAMIC False)
Modified: compiler-rt/trunk/test/asan/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/lit.site.cfg.in?rev=301443&r1=301442&r2=301443&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/lit.site.cfg.in (original)
+++ compiler-rt/trunk/test/asan/lit.site.cfg.in Wed Apr 26 13:59:22 2017
@@ -7,6 +7,8 @@ config.target_cflags = "@ASAN_TEST_TARGE
config.clang = "@ASAN_TEST_TARGET_CC@"
config.bits = "@ASAN_TEST_BITS@"
config.android = "@ANDROID@"
+config.ios = @ASAN_TEST_IOS_PYBOOL@
+config.iossim = @ASAN_TEST_IOSSIM_PYBOOL@
config.asan_dynamic = @ASAN_TEST_DYNAMIC@
config.target_arch = "@ASAN_TEST_TARGET_ARCH@"
Modified: compiler-rt/trunk/test/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lit.common.cfg?rev=301443&r1=301442&r2=301443&view=diff
==============================================================================
--- compiler-rt/trunk/test/lit.common.cfg (original)
+++ compiler-rt/trunk/test/lit.common.cfg Wed Apr 26 13:59:22 2017
@@ -94,7 +94,16 @@ config.substitutions.append(
instead define '%clangXXX' substitution in lit config. ***\n\n""") )
# Allow tests to be executed on a simulator or remotely.
-config.substitutions.append( ('%run', config.emulator) )
+if config.emulator:
+ config.substitutions.append( ('%run', config.emulator) )
+elif config.ios:
+ device_id_env = "SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER" if config.iossim else "SANITIZER_IOS_TEST_DEVICE_IDENTIFIER"
+ if device_id_env in os.environ: config.environment[device_id_env] = os.environ[device_id_env]
+ ios_commands_dir = os.path.join(config.compiler_rt_src_root, "test", "sanitizer_common", "ios_commands")
+ run_wrapper = os.path.join(ios_commands_dir, "iossim_run.py" if config.iossim else "ios_run.py")
+ config.substitutions.append(('%run', run_wrapper))
+else:
+ config.substitutions.append( ('%run', "") )
# Define CHECK-%os to check for OS-dependent output.
config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
Modified: compiler-rt/trunk/test/lit.common.configured.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lit.common.configured.in?rev=301443&r1=301442&r2=301443&view=diff
==============================================================================
--- compiler-rt/trunk/test/lit.common.configured.in (original)
+++ compiler-rt/trunk/test/lit.common.configured.in Wed Apr 26 13:59:22 2017
@@ -25,6 +25,8 @@ set_default("python_executable", "@PYTHO
set_default("compiler_rt_debug", @COMPILER_RT_DEBUG_PYBOOL@)
set_default("compiler_rt_libdir", "@COMPILER_RT_LIBRARY_OUTPUT_DIR@")
set_default("emulator", "@COMPILER_RT_EMULATOR@")
+set_default("ios", False)
+set_default("iossim", False)
set_default("sanitizer_can_use_cxxabi", @SANITIZER_CAN_USE_CXXABI_PYBOOL@)
set_default("has_lld", @COMPILER_RT_HAS_LLD_PYBOOL@)
set_default("can_symbolize", @CAN_SYMBOLIZE@)
Added: compiler-rt/trunk/test/sanitizer_common/ios_commands/iossim_env.py
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/ios_commands/iossim_env.py?rev=301443&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/ios_commands/iossim_env.py (added)
+++ compiler-rt/trunk/test/sanitizer_common/ios_commands/iossim_env.py Wed Apr 26 13:59:22 2017
@@ -0,0 +1,17 @@
+#!/usr/bin/python
+
+import os, sys, subprocess
+
+
+idx = 1
+for arg in sys.argv[1:]:
+ if not "=" in arg:
+ break
+ idx += 1
+ (argname, argval) = arg.split("=")
+ os.environ["SIMCTL_CHILD_" + argname] = argval
+
+exitcode = subprocess.call(sys.argv[idx:])
+if exitcode > 125:
+ exitcode = 126
+sys.exit(exitcode)
Added: compiler-rt/trunk/test/sanitizer_common/ios_commands/iossim_run.py
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/ios_commands/iossim_run.py?rev=301443&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/ios_commands/iossim_run.py (added)
+++ compiler-rt/trunk/test/sanitizer_common/ios_commands/iossim_run.py Wed Apr 26 13:59:22 2017
@@ -0,0 +1,17 @@
+#!/usr/bin/python
+
+import os, sys, subprocess
+
+
+if not "SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER" in os.environ:
+ raise EnvironmentError("Specify SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER to select which simulator to use.")
+
+device_id = os.environ["SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER"]
+
+if "ASAN_OPTIONS" in os.environ:
+ os.environ["SIMCTL_CHILD_ASAN_OPTIONS"] = os.environ["ASAN_OPTIONS"]
+
+exitcode = subprocess.call(["xcrun", "simctl", "spawn", device_id] + sys.argv[1:])
+if exitcode > 125:
+ exitcode = 126
+sys.exit(exitcode)
More information about the llvm-commits
mailing list