Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

[asan] Add support for running lit tests in the iOS Simulator #9

Merged
merged 1 commit into from
Jun 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmake/Modules/AddCompilerRT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ function(add_compiler_rt_runtime name type)
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}
Expand Down
49 changes: 49 additions & 0 deletions test/asan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions test/asan/lit.site.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ config.target_cflags = "@ASAN_TEST_TARGET_CFLAGS@"
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@"

Expand Down
11 changes: 10 additions & 1 deletion test/lit.common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,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)))
Expand Down
2 changes: 2 additions & 0 deletions test/lit.common.configured.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ set_default("python_executable", "@PYTHON_EXECUTABLE@")
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_SOURCES_PYBOOL@)
set_default("can_symbolize", @CAN_SYMBOLIZE@)
Expand Down
17 changes: 17 additions & 0 deletions test/sanitizer_common/ios_commands/iossim_env.py
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions test/sanitizer_common/ios_commands/iossim_run.py
Original file line number Diff line number Diff line change
@@ -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)