[compiler-rt] r307537 - [tsan] Add support for running TSan tests on iOS simulator and devices

Kuba Mracek via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 10 08:00:55 PDT 2017


Author: kuba.brecka
Date: Mon Jul 10 08:00:55 2017
New Revision: 307537

URL: http://llvm.org/viewvc/llvm-project?rev=307537&view=rev
Log:
[tsan] Add support for running TSan tests on iOS simulator and devices

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


Modified:
    compiler-rt/trunk/lib/lsan/lsan_common.cc
    compiler-rt/trunk/test/sanitizer_common/ios_commands/iossim_run.py
    compiler-rt/trunk/test/tsan/CMakeLists.txt
    compiler-rt/trunk/test/tsan/Darwin/dlopen.cc
    compiler-rt/trunk/test/tsan/Darwin/osspinlock-norace.cc
    compiler-rt/trunk/test/tsan/Darwin/xpc-cancel.mm
    compiler-rt/trunk/test/tsan/Darwin/xpc-race.mm
    compiler-rt/trunk/test/tsan/Darwin/xpc.mm
    compiler-rt/trunk/test/tsan/deep_stack1.cc
    compiler-rt/trunk/test/tsan/ignore_lib0.cc
    compiler-rt/trunk/test/tsan/lit.cfg
    compiler-rt/trunk/test/tsan/lit.site.cfg.in

Modified: compiler-rt/trunk/lib/lsan/lsan_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common.cc?rev=307537&r1=307536&r2=307537&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common.cc Mon Jul 10 08:00:55 2017
@@ -76,6 +76,7 @@ static const char kStdSuppressions[] =
 #endif  // SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT
   // TLS leak in some glibc versions, described in
   // https://sourceware.org/bugzilla/show_bug.cgi?id=12650.
+  "leak:*_os_trace*\n"
   "leak:*tls_get_addr*\n";
 
 void InitializeSuppressions() {

Modified: 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=307537&r1=307536&r2=307537&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/ios_commands/iossim_run.py (original)
+++ compiler-rt/trunk/test/sanitizer_common/ios_commands/iossim_run.py Mon Jul 10 08:00:55 2017
@@ -8,8 +8,9 @@ if not "SANITIZER_IOSSIM_TEST_DEVICE_IDE
 
 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"]
+for e in ["ASAN_OPTIONS", "TSAN_OPTIONS"]:
+  if e in os.environ:
+    os.environ["SIMCTL_CHILD_" + e] = os.environ[e]
 
 exitcode = subprocess.call(["xcrun", "simctl", "spawn", device_id] + sys.argv[1:])
 if exitcode > 125:

Modified: compiler-rt/trunk/test/tsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/CMakeLists.txt?rev=307537&r1=307536&r2=307537&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/tsan/CMakeLists.txt Mon Jul 10 08:00:55 2017
@@ -1,3 +1,5 @@
+set(TSAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+
 set(TSAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
 if(${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "x86_64")
   list(APPEND TSAN_TEST_DEPS GotsanRuntimeCheck)
@@ -22,6 +24,11 @@ if(APPLE)
 endif()
 
 foreach(arch ${TSAN_TEST_ARCH})
+  set(TSAN_TEST_IOS "0")
+  pythonize_bool(TSAN_TEST_IOS)
+  set(TSAN_TEST_IOSSIM "0")
+  pythonize_bool(TSAN_TEST_IOSSIM)
+
   set(TSAN_TEST_TARGET_ARCH ${arch})
   string(TOLOWER "-${arch}" TSAN_TEST_CONFIG_SUFFIX)
   get_test_cc_for_arch(${arch} TSAN_TEST_TARGET_CC TSAN_TEST_TARGET_CFLAGS)
@@ -35,6 +42,44 @@ foreach(arch ${TSAN_TEST_ARCH})
   list(APPEND TSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
 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/tsan/IOSSimX86_64Config
+if(APPLE)
+  set(TSAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
+  set(TSAN_TEST_IOS "1")
+  pythonize_bool(TSAN_TEST_IOS)
+
+  set(arch "x86_64")
+  set(TSAN_TEST_IOSSIM "1")
+  pythonize_bool(TSAN_TEST_IOSSIM)
+  set(TSAN_TEST_TARGET_ARCH ${arch})
+  set(TSAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_iossim_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
+  set(TSAN_TEST_CONFIG_SUFFIX "-${arch}-iossim")
+  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
+    )
+
+  set(arch "arm64")
+  set(TSAN_TEST_IOSSIM "0")
+  pythonize_bool(TSAN_TEST_IOSSIM)
+  set(TSAN_TEST_TARGET_ARCH ${arch})
+  set(TSAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
+  set(TSAN_TEST_CONFIG_SUFFIX "-${arch}-ios")
+  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
+    )
+endif()
+
 if(COMPILER_RT_INCLUDE_TESTS)
   configure_lit_site_cfg(
     ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in

Modified: compiler-rt/trunk/test/tsan/Darwin/dlopen.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/dlopen.cc?rev=307537&r1=307536&r2=307537&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/dlopen.cc (original)
+++ compiler-rt/trunk/test/tsan/Darwin/dlopen.cc Mon Jul 10 08:00:55 2017
@@ -4,6 +4,8 @@
 
 // REQUIRES: osx-autointerception
 
+// XFAIL: ios
+
 // RUN: %clangxx_tsan %s -o %t.so -shared -DSHARED_LIB
 // RUN: %clangxx_tsan -fno-sanitize=thread %s -o %t
 

Modified: compiler-rt/trunk/test/tsan/Darwin/osspinlock-norace.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/osspinlock-norace.cc?rev=307537&r1=307536&r2=307537&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/osspinlock-norace.cc (original)
+++ compiler-rt/trunk/test/tsan/Darwin/osspinlock-norace.cc Mon Jul 10 08:00:55 2017
@@ -1,8 +1,11 @@
 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
-#include <libkern/OSAtomic.h>
 #include <pthread.h>
 #include <stdio.h>
 
+typedef int32_t OSSpinLock;
+extern "C" void OSSpinLockLock(OSSpinLock *);
+extern "C" void OSSpinLockUnlock(OSSpinLock *);
+
 int Global;
 OSSpinLock lock;
 

Modified: compiler-rt/trunk/test/tsan/Darwin/xpc-cancel.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/xpc-cancel.mm?rev=307537&r1=307536&r2=307537&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/xpc-cancel.mm (original)
+++ compiler-rt/trunk/test/tsan/Darwin/xpc-cancel.mm Mon Jul 10 08:00:55 2017
@@ -1,7 +1,7 @@
 // RUN: %clang_tsan %s -o %t -framework Foundation
 // RUN: %run %t 2>&1 | FileCheck %s
 
-// XFAIL: ios
+// UNSUPPORTED: ios
 
 #import <Foundation/Foundation.h>
 #import <xpc/xpc.h>

Modified: compiler-rt/trunk/test/tsan/Darwin/xpc-race.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/xpc-race.mm?rev=307537&r1=307536&r2=307537&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/xpc-race.mm (original)
+++ compiler-rt/trunk/test/tsan/Darwin/xpc-race.mm Mon Jul 10 08:00:55 2017
@@ -1,7 +1,7 @@
 // RUN: %clang_tsan %s -o %t -framework Foundation
 // RUN: %deflake %run %t 2>&1 | FileCheck %s
 
-// XFAIL: ios
+// UNSUPPORTED: ios
 
 #import <Foundation/Foundation.h>
 #import <xpc/xpc.h>

Modified: compiler-rt/trunk/test/tsan/Darwin/xpc.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/xpc.mm?rev=307537&r1=307536&r2=307537&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/xpc.mm (original)
+++ compiler-rt/trunk/test/tsan/Darwin/xpc.mm Mon Jul 10 08:00:55 2017
@@ -1,7 +1,7 @@
 // RUN: %clang_tsan %s -o %t -framework Foundation
 // RUN: %run %t 2>&1 | FileCheck %s
 
-// XFAIL: ios
+// UNSUPPORTED: ios
 
 #import <Foundation/Foundation.h>
 #import <xpc/xpc.h>

Modified: compiler-rt/trunk/test/tsan/deep_stack1.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/deep_stack1.cc?rev=307537&r1=307536&r2=307537&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/deep_stack1.cc (original)
+++ compiler-rt/trunk/test/tsan/deep_stack1.cc Mon Jul 10 08:00:55 2017
@@ -24,6 +24,10 @@ void *Thread(void *p) {
   return 0;
 }
 
+static size_t RoundUp(size_t n, size_t to) {
+  return ((n + to - 1) / to) * to;
+} 
+
 int main() {
   barrier_init(&barrier, 2);
   N = 50000;
@@ -31,7 +35,10 @@ int main() {
   pthread_t t;
   pthread_attr_t a;
   pthread_attr_init(&a);
-  pthread_attr_setstacksize(&a, N * 256 + (1 << 20));
+  size_t stack_size = N * 256 + (1 << 20);
+  stack_size = RoundUp(stack_size, 0x10000);  // round the stack size to 64k
+  int ret = pthread_attr_setstacksize(&a, stack_size);
+  if (ret) abort();
   pthread_create(&t, &a, Thread, 0);
 #ifdef ORDER2
   barrier_wait(&barrier);

Modified: compiler-rt/trunk/test/tsan/ignore_lib0.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/ignore_lib0.cc?rev=307537&r1=307536&r2=307537&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/ignore_lib0.cc (original)
+++ compiler-rt/trunk/test/tsan/ignore_lib0.cc Mon Jul 10 08:00:55 2017
@@ -11,6 +11,8 @@
 // Some aarch64 kernels do not support non executable write pages
 // REQUIRES: stable-runtime
 
+// UNSUPPORTED: ios
+
 #ifndef LIB
 
 extern "C" void libfunc();

Modified: compiler-rt/trunk/test/tsan/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/lit.cfg?rev=307537&r1=307536&r2=307537&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/lit.cfg (original)
+++ compiler-rt/trunk/test/tsan/lit.cfg Mon Jul 10 08:00:55 2017
@@ -66,7 +66,7 @@ if config.has_libcxx and config.host_os
                           "-Wl,-rpath=%s" % libcxx_libdir]
 
 def build_invocation(compile_flags):
-  return " " + " ".join([config.clang] + compile_flags) + " "
+  return " " + " ".join([config.compile_wrapper, config.clang] + compile_flags) + " "
 
 config.substitutions.append( ("%clang_tsan ", build_invocation(clang_tsan_cflags)) )
 config.substitutions.append( ("%clangxx_tsan ", build_invocation(clang_tsan_cxxflags)) )

Modified: compiler-rt/trunk/test/tsan/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/lit.site.cfg.in?rev=307537&r1=307536&r2=307537&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/lit.site.cfg.in (original)
+++ compiler-rt/trunk/test/tsan/lit.site.cfg.in Mon Jul 10 08:00:55 2017
@@ -1,7 +1,10 @@
 @LIT_SITE_CFG_IN_HEADER@
 
 config.name_suffix = "@TSAN_TEST_CONFIG_SUFFIX@"
+config.tsan_lit_source_dir = "@TSAN_LIT_SOURCE_DIR@"
 config.has_libcxx = @TSAN_HAS_LIBCXX@
+config.ios = @TSAN_TEST_IOS_PYBOOL@
+config.iossim = @TSAN_TEST_IOSSIM_PYBOOL@
 config.target_cflags = "@TSAN_TEST_TARGET_CFLAGS@"
 config.target_arch = "@TSAN_TEST_TARGET_ARCH@"
 




More information about the llvm-commits mailing list