diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index d2858ab538f337d00675fd0961ef03b52ba5c269..8131bb9153371af881ba4f33b6a34e15c271b313 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -405,10 +405,12 @@ #define SANITIZER_INTERCEPT_PTHREAD_MUTEX SI_POSIX #define SANITIZER_INTERCEPT___PTHREAD_MUTEX SI_GLIBC #define SANITIZER_INTERCEPT___LIBC_MUTEX SI_NETBSD +// OHOS_LOCAL begin #define SANITIZER_INTERCEPT_PTHREAD_SETNAME_NP \ - (SI_FREEBSD || SI_NETBSD || SI_GLIBC || SI_SOLARIS) + (SI_FREEBSD || SI_NETBSD || SI_GLIBC || SI_SOLARIS || SI_OHOS) #define SANITIZER_INTERCEPT_PTHREAD_GETNAME_NP \ - (SI_FREEBSD || SI_NETBSD || SI_GLIBC || SI_SOLARIS) + (SI_FREEBSD || SI_NETBSD || SI_GLIBC || SI_SOLARIS || SI_OHOS) +// OHOS_LOCAL end #define SANITIZER_INTERCEPT_TLS_GET_ADDR \ (SI_FREEBSD || SI_NETBSD || (SI_LINUX_NOT_ANDROID && !SI_OHOS) || SI_SOLARIS) diff --git a/compiler-rt/lib/tsan/tests/CMakeLists.txt b/compiler-rt/lib/tsan/tests/CMakeLists.txt index 8afd217cb8b0e06d649c5abdac1478f96fc49a74..d36ed16b499a8e0ad6126ddf8709aee5ae6ef82d 100644 --- a/compiler-rt/lib/tsan/tests/CMakeLists.txt +++ b/compiler-rt/lib/tsan/tests/CMakeLists.txt @@ -15,6 +15,12 @@ set(TSAN_UNITTEST_CFLAGS -fno-rtti ) +# OHOS_LOCAL begin +if(OHOS) + list(APPEND TSAN_UNITTEST_CFLAGS -fno-emulated-tls) +endif() +# OHOS_LOCAL end + if(COMPILER_RT_TSAN_DEBUG_OUTPUT) # Need to match these flags with the runtime. list(APPEND TSAN_UNITTEST_CFLAGS -DTSAN_COLLECT_STATS=1 diff --git a/compiler-rt/test/asan/TestCases/Posix/halt_on_error-torture.cpp b/compiler-rt/test/asan/TestCases/Posix/halt_on_error-torture.cpp index 559f9434e3925dc7ed3801378610ba794cd7b074..f0f36ec310c71b4c3885a011b551a519b7a52111 100644 --- a/compiler-rt/test/asan/TestCases/Posix/halt_on_error-torture.cpp +++ b/compiler-rt/test/asan/TestCases/Posix/halt_on_error-torture.cpp @@ -38,7 +38,8 @@ void *run(void *arg) { for (size_t i = 0; i < niter; ++i) { random_delay(&seed); - // CHECK: ERROR: AddressSanitizer: use-after-poison + // OHOS_LOCAL + // CHECK-DAG: ERROR: AddressSanitizer: use-after-poison volatile int idx = 0; tmp[idx] = 0; } @@ -71,7 +72,8 @@ int main(int argc, char **argv) { } } - // CHECK: All threads terminated + // OHOS_LOCAL + // CHECK-DAG: All threads terminated printf("All threads terminated\n"); delete [] tids; diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py index 04093624454cce1df583fcde9cbd68d28a24a892..869d0e233ef34d946260aae60ad71b1cfc4b2121 100644 --- a/compiler-rt/test/lit.common.cfg.py +++ b/compiler-rt/test/lit.common.cfg.py @@ -12,6 +12,10 @@ import json import lit.formats import lit.util +# OHOS_LOCAL begin +from lit.llvm import llvm_config +from lit.llvm.subst import ToolSubst, WrapTool, FindTool +# OHOS_LOCAL end # Get shlex.quote if available (added in 3.3), and fall back to pipes.quote if # it's not available. @@ -176,8 +180,6 @@ if config.asan_shadow_scale != '': if config.memprof_shadow_scale != '': config.target_cflags += " -mllvm -memprof-mapping-scale=" + config.memprof_shadow_scale -config.environment = dict(os.environ) - # Clear some environment variables that might affect Clang. possibly_dangerous_env_vars = ['ASAN_OPTIONS', 'DFSAN_OPTIONS', 'LSAN_OPTIONS', 'MSAN_OPTIONS', 'UBSAN_OPTIONS', @@ -257,6 +259,7 @@ def get_ios_commands_dir(): return os.path.join(config.compiler_rt_src_root, "test", "sanitizer_common", "ios_commands") # Allow tests to be executed on a simulator or remotely. +tools = [] # OHOS_LOCAL if emulator: config.substitutions.append(('%run', emulator)) config.substitutions.append(('%env ', "env ")) @@ -265,6 +268,7 @@ if emulator: lit_config.warning('%device_rm is not implemented') config.substitutions.append(('%device_rm', 'echo ')) config.compile_wrapper = "" +# OHOS_LOCAL begin elif is_ohos_family_mobile(): config.available_features.add('ohos_family') # FIXME: some tests for hos also need this now, @@ -274,6 +278,9 @@ elif is_ohos_family_mobile(): config.compile_wrapper = compile_wrapper config.substitutions.append( ('%run', "") ) config.substitutions.append( ('%env ', "env ") ) + tool_wrapper = os.path.join(config.compiler_rt_src_root, "test", "sanitizer_common", "ohos_family_commands", "ohos_tool.py") + " " + tools.append(ToolSubst('llvm-objdump', command=WrapTool('llvm-objdump', tool_wrapper), unresolved='fatal')) +# OHOS_LOCAL end elif config.host_os == 'Darwin' and config.apple_platform != "osx": # Darwin tests can be targetting macOS, a device or a simulator. All devices # are declared as "ios", even for iOS derivatives (tvOS, watchOS). Similarly, @@ -343,6 +350,9 @@ else: config.substitutions.append(('%device_rm', 'echo ')) config.compile_wrapper = "" +# OHOS_LOCAL +llvm_config.add_tool_substitutions(tools, [config.llvm_tools_dir] + config.environment['PATH'].split(os.path.pathsep)) + # Define CHECK-%os to check for OS-dependent output. config.substitutions.append(('CHECK-%os', ("CHECK-" + config.host_os))) @@ -518,6 +528,16 @@ if config.android: # OHOS_LOCAL begin elif config.host_os == 'OHOS': + for var in [ + 'HDC', + 'HDC_SERVER_IP_PORT', + 'HDC_UTID', + 'OHOS_REMOTE_TMP_DIR', + 'OHOS_REMOTE_DYN_LINKER', + ]: + if var in os.environ: + config.environment[var] = os.environ[var] + hdc_imp = os.path.join(os.path.dirname(__file__), 'sanitizer_common', 'ohos_family_commands') sys.path.append(hdc_imp) import hdc_constants diff --git a/compiler-rt/test/lit.common.configured.in b/compiler-rt/test/lit.common.configured.in index a06ede7e73313af10081e4eb3b53d2c1e6d5ea49..1a20461cbf7d83c322b717e8fcf506e00e9b6cae 100644 --- a/compiler-rt/test/lit.common.configured.in +++ b/compiler-rt/test/lit.common.configured.in @@ -18,6 +18,7 @@ set_default("compiler_rt_src_root", "@COMPILER_RT_SOURCE_DIR@") set_default("compiler_rt_obj_root", "@COMPILER_RT_BINARY_DIR@") set_default("enable_per_target_runtime_dir", @LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_PYBOOL@) set_default("llvm_tools_dir", "@LLVM_TOOLS_DIR@") +set_default("lit_tools_dir", "@LLVM_LIT_TOOLS_DIR@") set_default("llvm_shlib_dir", "@LLVM_LIBRARY_OUTPUT_INTDIR@") set_default("gnu_ld_executable", "@GNU_LD_EXECUTABLE@") set_default("gold_executable", "@GOLD_EXECUTABLE@") @@ -77,5 +78,8 @@ config.compiler_rt_libdir = lit_config.substitute(config.compiler_rt_libdir) if not os.path.exists(config.clang): lit_config.fatal("Can't find compiler on path %r" % config.clang) +import lit.llvm +lit.llvm.initialize(lit_config, config) + # Setup attributes common for all compiler-rt projects. lit_config.load_config(config, "@COMPILER_RT_SOURCE_DIR@/test/lit.common.cfg.py") diff --git a/compiler-rt/test/sanitizer_common/ohos_family_commands/hdc_constants.py b/compiler-rt/test/sanitizer_common/ohos_family_commands/hdc_constants.py index af6853ed8b1d63bfad1f8260dd41328bec8ecfd0..5fcfb514f4b32a9e5b3f57e8fddee110ef3322d8 100644 --- a/compiler-rt/test/sanitizer_common/ohos_family_commands/hdc_constants.py +++ b/compiler-rt/test/sanitizer_common/ohos_family_commands/hdc_constants.py @@ -6,6 +6,7 @@ HDC = os.environ.get('HDC', 'hdc') HDC_SERVER_IP_PORT = os.environ.get('HDC_SERVER_IP_PORT') HDC_UTID = os.environ.get('HDC_UTID') TMPDIR = os.environ.get('OHOS_REMOTE_TMP_DIR', '/data/local/tmp/Output') +DYN_LINKER = os.environ.get('OHOS_REMOTE_DYN_LINKER') # emit warning on import if some required constants are not set if not HDC_SERVER_IP_PORT or not HDC_UTID: diff --git a/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_common.py b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_common.py index de2aabe8107e3d6e4e9580134ca93ef4d05351ac..b84161f8b99c3a11efe3593dd209f9eeefd278da 100755 --- a/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_common.py +++ b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_common.py @@ -55,4 +55,4 @@ def push_to_device(path): dst_path = host_to_device_path(path) # hdc do not auto create directories on device hdc(['shell', 'mkdir', '-p', os.path.dirname(dst_path)]) - hdc(['file', 'send', path, dst_path], attempts=5, check_stdout='FileTransfer finish') + hdc(['file', 'send', '-m', path, dst_path], attempts=5, check_stdout='FileTransfer finish') diff --git a/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_compile.py b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_compile.py index 9006dac3d3b94448d25cb58ce5b5f20704e653cf..b3f48571588e6d7c0bbce42eaf7b4a7d2962f53a 100755 --- a/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_compile.py +++ b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_compile.py @@ -21,20 +21,20 @@ while args: output_type = 'object' elif arg == '-o': output = args.pop(0) +if hdc_constants.DYN_LINKER: + append_args.append('-Wl,--dynamic-linker=' + hdc_constants.DYN_LINKER) if output == None: print ("No output file name!") sys.exit(1) -with open(f'{output}.stderr', 'w') as f: - ret = subprocess.call(sys.argv[1:] + append_args, stderr=f) +ret = subprocess.call(sys.argv[1:] + append_args) if ret != 0: sys.exit(ret) if output_type in ['executable', 'shared']: push_to_device(output) - hdc(['shell', 'chmod', '+x', host_to_device_path(output)]) if output_type == 'executable': os.rename(output, output + '.real') diff --git a/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_run.py b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_run.py index c53c94c46ce971c632b21b721375e13d7237dead..675e064fa8ffaa6fbfad75c9653e9f569a44ee16 100755 --- a/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_run.py +++ b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_run.py @@ -6,6 +6,21 @@ from ohos_common import * device_binary = host_to_device_path(sys.argv[0]) +def map_path(path, do_push): + if os.path.exists(path): + if do_push: + push_to_device(path) + return host_to_device_path(path) + return path + +def map_list(value, sep, regex, get_path_and_do_push): + def repl(m): + path, do_push = get_path_and_do_push(m) + return map_path(path, do_push) + + opts = value.split(sep) + return sep.join(re.sub(regex, repl, opt) for opt in opts) + def build_env(): args = [] sanitizers = ( @@ -29,7 +44,14 @@ def build_env(): san_opt = key.endswith('SAN_OPTIONS') if san_opt: value += ':abort_on_error=0' - if key in ['ASAN_ACTIVATION_OPTIONS', 'SCUDO_OPTIONS'] or san_opt: + if key in ['ASAN_ACTIVATION_OPTIONS', 'SCUDO_OPTIONS'] or san_opt or key == 'LD_LIBRARY_PATH': + if key == 'TSAN_OPTIONS': + # Map TSan suppressions file to device + value = map_list(value, ':', r'(?<=suppressions=)(.+)', lambda m: (m.group(1), True)) + elif key == 'LD_LIBRARY_PATH': + # Map LD_LIBRARY_PATH to device + value = map_list(value, ':', r'(.+)', lambda m: (m.group(1), False)) + args.append('%s="%s"' % (key, value)) return ' '.join(args) @@ -49,6 +71,8 @@ hdc(['shell', 'unset UBSAN_OPTIONS && cd %s && %s %s %s %s >%s 2>%s ; echo $? >% sys.stdout.write(pull_from_device(device_stdout)) sys.stderr.write(pull_from_device(device_stderr)) +sys.stdout.flush() +sys.stderr.flush() retcode = int(pull_from_device(device_exitcode)) # If the device process died with a signal, do abort(). # Not exactly the same, but good enough to fool "not --crash". diff --git a/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_tool.py b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_tool.py new file mode 100755 index 0000000000000000000000000000000000000000..cb3eb0fdabd6c386b0e18ebd9ce07db1adf104f5 --- /dev/null +++ b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_tool.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 + +import os, sys, subprocess + +def map_arg(arg): + if not arg.startswith('-') and os.path.exists(arg) and os.path.exists(arg + '.real'): + return arg + '.real' + return arg + +args = [map_arg(arg) for arg in sys.argv[2:]] +sys.exit(subprocess.call([sys.argv[1]] + args)) diff --git a/compiler-rt/test/tsan/CMakeLists.txt b/compiler-rt/test/tsan/CMakeLists.txt index 25e95aa98cf9501109f41beb14f2343476ac9d69..45039aecff7b72de1e2c59546587382715e4abf1 100644 --- a/compiler-rt/test/tsan/CMakeLists.txt +++ b/compiler-rt/test/tsan/CMakeLists.txt @@ -122,11 +122,15 @@ if(COMPILER_RT_INCLUDE_TESTS) ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic/lit.site.cfg.py) endif() - list(APPEND TSAN_TEST_DEPS TsanUnitTests) - list(APPEND TSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit) - if(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME) - list(APPEND TSAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic) + # OHOS_LOCAL begin + if (NOT OHOS) + list(APPEND TSAN_TEST_DEPS TsanUnitTests) + list(APPEND TSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit) + if(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME) + list(APPEND TSAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic) + endif() endif() + # OHOS_LOCAL end endif() add_lit_testsuite(check-tsan "Running ThreadSanitizer tests" diff --git a/compiler-rt/test/tsan/Linux/lit.local.cfg.py b/compiler-rt/test/tsan/Linux/lit.local.cfg.py index 57271b8078a49730b9ae06f901ec3faf907dcef5..ce7ce5ddde93dd9896fe163d5c871ef899cb3316 100644 --- a/compiler-rt/test/tsan/Linux/lit.local.cfg.py +++ b/compiler-rt/test/tsan/Linux/lit.local.cfg.py @@ -5,5 +5,5 @@ def getRoot(config): root = getRoot(config) -if root.host_os not in ['Linux']: +if root.host_os not in ['Linux', 'OHOS']: # OHOS_LOCAL config.unsupported = True diff --git a/compiler-rt/test/tsan/Linux/mutex_robust.cpp b/compiler-rt/test/tsan/Linux/mutex_robust.cpp index 5ca5e70d49a71854ef30e9eefbb27030b7105451..bddf57e9653964eaa4b7836a470db2da8e68a3f5 100644 --- a/compiler-rt/test/tsan/Linux/mutex_robust.cpp +++ b/compiler-rt/test/tsan/Linux/mutex_robust.cpp @@ -1,4 +1,7 @@ // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s +// OHOS_LOCAL +// pthread_mutexattr_setrobust not available on OHOS musl +// UNSUPPORTED: ohos_family #include #include #include diff --git a/compiler-rt/test/tsan/Linux/mutex_robust2.cpp b/compiler-rt/test/tsan/Linux/mutex_robust2.cpp index 0914c1763604457ec462c186ee23732b88454131..d6cae7a7c4974e9b3cba86c04ff602ce1073a1cb 100644 --- a/compiler-rt/test/tsan/Linux/mutex_robust2.cpp +++ b/compiler-rt/test/tsan/Linux/mutex_robust2.cpp @@ -1,4 +1,7 @@ // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s +// OHOS_LOCAL +// pthread_mutexattr_setrobust not available on OHOS musl +// UNSUPPORTED: ohos_family #include #include #include diff --git a/compiler-rt/test/tsan/Linux/thread_timedjoin.c b/compiler-rt/test/tsan/Linux/thread_timedjoin.c index 1d3f1098ece753e2809b7888fd41909229a616b7..a7cdb335bcbefdd24f19adcf44dc0f0a7c10558b 100644 --- a/compiler-rt/test/tsan/Linux/thread_timedjoin.c +++ b/compiler-rt/test/tsan/Linux/thread_timedjoin.c @@ -1,4 +1,7 @@ // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s +// OHOS_LOCAL +// pthread_timedjoin_np not available on OHOS musl +// UNSUPPORTED: ohos_family #define _GNU_SOURCE #include "../test.h" #include diff --git a/compiler-rt/test/tsan/Linux/thread_tryjoin.c b/compiler-rt/test/tsan/Linux/thread_tryjoin.c index 675e1595528a7504186744f638c94a650cfcf74e..789842e0ed1b953bbe493e6aba532efea8af99aa 100644 --- a/compiler-rt/test/tsan/Linux/thread_tryjoin.c +++ b/compiler-rt/test/tsan/Linux/thread_tryjoin.c @@ -1,4 +1,7 @@ // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s +// OHOS_LOCAL +// pthread_tryjoin_np not available on OHOS musl +// UNSUPPORTED: ohos_family #define _GNU_SOURCE #include "../test.h" #include @@ -29,7 +32,7 @@ int main() { if (!res) break; check(res); - pthread_yield(); + sched_yield(); // OHOS_LOCAL } var = 2; fprintf(stderr, "PASS\n"); diff --git a/compiler-rt/test/tsan/cond_cancel.c b/compiler-rt/test/tsan/cond_cancel.c index 7f20b8f8add43f99be5bd9d6fc1ab3d2a25ef122..0c741f7106a0f407d8f2ce27c26bb6e7ee8028e3 100644 --- a/compiler-rt/test/tsan/cond_cancel.c +++ b/compiler-rt/test/tsan/cond_cancel.c @@ -9,6 +9,9 @@ // however the same version GLIBC-2.17 will not make fail the test on // powerpc64 BE (VMA=46) // UNSUPPORTED: powerpc64-unknown-linux-gnu +// OHOS_LOCAL +// pthread_cancel not available on OHOS musl +// UNSUPPORTED: ohos_family #include "test.h" diff --git a/compiler-rt/test/tsan/debugging.cpp b/compiler-rt/test/tsan/debugging.cpp index be0a0c7b0824deacc8f89bace5e5262c3b3e9a4a..ec4dd59625c36f8640d770a34c42a2829d6b78dd 100644 --- a/compiler-rt/test/tsan/debugging.cpp +++ b/compiler-rt/test/tsan/debugging.cpp @@ -79,7 +79,8 @@ __tsan_on_report(void *report) { tid, addr, size, write, atomic); // CHECK: tid = 1, addr = [[GLOBAL]], size = 8, write = 1, atomic = 0 fprintf(stderr, "trace[0] = %p, trace[1] = %p\n", trace[0], trace[1]); - // CHECK: trace[0] = 0x{{[0-9a-f]+}}, trace[1] = {{0x0|\(nil\)|\(null\)}} + // OHOS_LOCAL + // CHECK: trace[0] = 0x{{[0-9a-f]+}}, trace[1] = {{0x0|\(nil\)|\(null\)|0}} __tsan_get_report_mop(report, 1, &tid, &addr, &size, &write, &atomic, trace, 16); @@ -87,7 +88,8 @@ __tsan_on_report(void *report) { tid, addr, size, write, atomic); // CHECK: tid = 0, addr = [[GLOBAL]], size = 8, write = 1, atomic = 0 fprintf(stderr, "trace[0] = %p, trace[1] = %p\n", trace[0], trace[1]); - // CHECK: trace[0] = 0x{{[0-9a-f]+}}, trace[1] = {{0x0|\(nil\)|\(null\)}} + // OHOS_LOCAL + // CHECK: trace[0] = 0x{{[0-9a-f]+}}, trace[1] = {{0x0|\(nil\)|\(null\)|0}} fprintf(stderr, "thread_count = %d\n", thread_count); // CHECK: thread_count = 2 diff --git a/compiler-rt/test/tsan/dtls.c b/compiler-rt/test/tsan/dtls.c index 57c9da83a374e0f62dbae705b3adb5fae490b9fb..9b4febb0c019ba906db2eb1c80b1f56edf182353 100644 --- a/compiler-rt/test/tsan/dtls.c +++ b/compiler-rt/test/tsan/dtls.c @@ -32,6 +32,9 @@ void *Thread2(void *arg) { } int main(int argc, char *argv[]) { + // OHOS_LOCAL + dlerror(); // Clear any previous errors + char path[4096]; snprintf(path, sizeof(path), "%s-so.so", argv[0]); diff --git a/compiler-rt/test/tsan/fiber_from_thread.cpp b/compiler-rt/test/tsan/fiber_from_thread.cpp index d27379e7acf4038a957b4998391f260289f5c56c..7f859a0c55e8a01e43563921a9474419de47c9a9 100644 --- a/compiler-rt/test/tsan/fiber_from_thread.cpp +++ b/compiler-rt/test/tsan/fiber_from_thread.cpp @@ -1,6 +1,9 @@ // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s // UNSUPPORTED: tvos, watchos // XFAIL: ios && !iossim +// OHOS_LOCAL +// ucontext.h not available on musl +// UNSUPPORTED: ohos_family #include "sanitizer_common/sanitizer_ucontext.h" #include "test.h" diff --git a/compiler-rt/test/tsan/fiber_longjmp.cpp b/compiler-rt/test/tsan/fiber_longjmp.cpp index e56fd21befbbb1122c85627caaf9058a81542184..189726e4a042de14946067678c0d996c5c50b0e8 100644 --- a/compiler-rt/test/tsan/fiber_longjmp.cpp +++ b/compiler-rt/test/tsan/fiber_longjmp.cpp @@ -1,6 +1,9 @@ // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s // UNSUPPORTED: tvos, watchos // XFAIL: ios && !iossim +// OHOS_LOCAL +// ucontext.h not available on musl +// UNSUPPORTED: ohos_family #include "sanitizer_common/sanitizer_ucontext.h" #include "test.h" #include diff --git a/compiler-rt/test/tsan/fiber_race.cpp b/compiler-rt/test/tsan/fiber_race.cpp index add66940ffd11fbaf8c41f9d521d27d9c5cf0e42..eef17cf42c5c7d90f8dabdbab0c3b4ce748edb68 100644 --- a/compiler-rt/test/tsan/fiber_race.cpp +++ b/compiler-rt/test/tsan/fiber_race.cpp @@ -1,6 +1,9 @@ // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s // UNSUPPORTED: tvos, watchos // XFAIL: ios && !iossim +// OHOS_LOCAL +// ucontext.h not available on musl +// UNSUPPORTED: ohos_family #include "sanitizer_common/sanitizer_ucontext.h" #include "test.h" diff --git a/compiler-rt/test/tsan/fiber_simple.cpp b/compiler-rt/test/tsan/fiber_simple.cpp index 8123eb8eafc8a3b3d7c9327e50ab6f818be2a2ad..633f8bd408f50c25cfe328b5b439d7367cac92b8 100644 --- a/compiler-rt/test/tsan/fiber_simple.cpp +++ b/compiler-rt/test/tsan/fiber_simple.cpp @@ -1,6 +1,9 @@ // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s // UNSUPPORTED: tvos, watchos // XFAIL: ios && !iossim +// OHOS_LOCAL +// ucontext.h not available on musl +// UNSUPPORTED: ohos_family #include "sanitizer_common/sanitizer_ucontext.h" #include "test.h" diff --git a/compiler-rt/test/tsan/fiber_two_threads.cpp b/compiler-rt/test/tsan/fiber_two_threads.cpp index d2961b94dde10179f4efd02a5e3f33f98f729c12..b4d6604c7ef15b94920fe3abfec2b06c37355080 100644 --- a/compiler-rt/test/tsan/fiber_two_threads.cpp +++ b/compiler-rt/test/tsan/fiber_two_threads.cpp @@ -1,6 +1,9 @@ // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s // UNSUPPORTED: tvos, watchos // XFAIL: ios && !iossim +// OHOS_LOCAL +// ucontext.h not available on musl +// UNSUPPORTED: ohos_family #include "sanitizer_common/sanitizer_ucontext.h" #include "test.h" diff --git a/compiler-rt/test/tsan/ignore_lib1.cpp b/compiler-rt/test/tsan/ignore_lib1.cpp index 01139519e491b466917945723d9c5501551eefec..2b17dee501418bb40489f11d7654bcefd2540120 100644 --- a/compiler-rt/test/tsan/ignore_lib1.cpp +++ b/compiler-rt/test/tsan/ignore_lib1.cpp @@ -16,6 +16,10 @@ // FIXME: This test regularly fails on powerpc64 LE possibly starting with // r279664. Re-enable the test once the problem(s) have been fixed. +// OHOS_LOCAL +// dlopen not intercepted on OHOS +// UNSUPPORTED: ohos_family + #ifndef LIB #include diff --git a/compiler-rt/test/tsan/ignore_lib2.cpp b/compiler-rt/test/tsan/ignore_lib2.cpp index 05b7c2ed915a766a7546d65b4da6d5f70a268b6a..24b7f5e66a3e8972769dc6ff894026ef944ad09d 100644 --- a/compiler-rt/test/tsan/ignore_lib2.cpp +++ b/compiler-rt/test/tsan/ignore_lib2.cpp @@ -6,6 +6,10 @@ // RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t-dir/executable // RUN: %env_tsan_opts=suppressions='%s.supp' %deflake %run %t-dir/executable | FileCheck %s +// OHOS_LOCAL +// dlopen not intercepted on OHOS +// UNSUPPORTED: ohos_family + // Tests that called_from_lib suppression matched against 2 libraries // causes program crash (this is not supported). diff --git a/compiler-rt/test/tsan/ignore_lib3.cpp b/compiler-rt/test/tsan/ignore_lib3.cpp index b1a3940d03b615a24b143a140eb2ec76e47742e1..b13229184141e15d1aa2003a135c89b2938d32c5 100644 --- a/compiler-rt/test/tsan/ignore_lib3.cpp +++ b/compiler-rt/test/tsan/ignore_lib3.cpp @@ -11,6 +11,10 @@ // Some aarch64 kernels do not support non executable write pages // REQUIRES: stable-runtime +// OHOS_LOCAL +// dlopen not intercepted on OHOS +// UNSUPPORTED: ohos_family + #ifndef LIB #include diff --git a/compiler-rt/test/tsan/ignore_lib4.cpp b/compiler-rt/test/tsan/ignore_lib4.cpp index 06241c7b89f3024dd26e83a1507ff5b7a9e117bf..00bde34639d0f9441de755a8ad07aa50ac68bfdf 100644 --- a/compiler-rt/test/tsan/ignore_lib4.cpp +++ b/compiler-rt/test/tsan/ignore_lib4.cpp @@ -13,6 +13,10 @@ // is matched against 2 libraries". // UNSUPPORTED: aarch64 +// OHOS_LOCAL +// dlopen not intercepted on OHOS +// UNSUPPORTED: ohos_family + // Test longjmp in ignored lib. // It used to crash since we jumped out of ScopedInterceptor scope. diff --git a/compiler-rt/test/tsan/ignore_lib5.cpp b/compiler-rt/test/tsan/ignore_lib5.cpp index a71d560ab913c1e6855fb5bee3b6c46b6b7383db..9ae3f7bcbb9546368dff938a474472cdbdc35971 100644 --- a/compiler-rt/test/tsan/ignore_lib5.cpp +++ b/compiler-rt/test/tsan/ignore_lib5.cpp @@ -21,6 +21,10 @@ // ReadProcMaps() on NetBSD does not handle >=1MB of memory layout information // UNSUPPORTED: netbsd +// OHOS_LOCAL +// dlopen not intercepted on OHOS +// UNSUPPORTED: ohos_family + #ifndef LIB #include diff --git a/compiler-rt/test/tsan/ignored-interceptors-mmap.cpp b/compiler-rt/test/tsan/ignored-interceptors-mmap.cpp index 2b35627229df7495b4eaac9da27c0eca91ce71b5..bbf43be5b6050bb1b4a596141a49f7977b2c77c9 100644 --- a/compiler-rt/test/tsan/ignored-interceptors-mmap.cpp +++ b/compiler-rt/test/tsan/ignored-interceptors-mmap.cpp @@ -49,7 +49,10 @@ int main(int argc, const char *argv[]) { return 0; } -// CHECK-RACE: WARNING: ThreadSanitizer: data race -// CHECK-RACE: OK +// OHOS_LOCAL begin +// CHECK-RACE-DAG: WARNING: ThreadSanitizer: data race +// CHECK-RACE-DAG: OK // CHECK-IGNORE-NOT: WARNING: ThreadSanitizer: data race // CHECK-IGNORE: OK +// CHECK-IGNORE-NOT: WARNING: ThreadSanitizer: data race +// OHOS_LOCAL end diff --git a/compiler-rt/test/tsan/java_finalizer2.cpp b/compiler-rt/test/tsan/java_finalizer2.cpp index 87528900541a84be2e3603b510cd8d08eaebe1eb..77e222766bd80ce4f5c73ee127f2902bb33c3619 100644 --- a/compiler-rt/test/tsan/java_finalizer2.cpp +++ b/compiler-rt/test/tsan/java_finalizer2.cpp @@ -37,9 +37,9 @@ void *Thread3(void *p) { Heap* heap = (Heap*)p; pthread_barrier_wait(&heap->barrier_finalizer); while (__atomic_load_n(&heap->ready, __ATOMIC_ACQUIRE) != 1) - pthread_yield(); + sched_yield(); // OHOS_LOCAL while (__atomic_load_n(&heap->finalized, __ATOMIC_RELAXED) != 1) - pthread_yield(); + sched_yield(); // OHOS_LOCAL __atomic_fetch_add(&heap->wg, 1, __ATOMIC_RELEASE); return 0; } @@ -70,7 +70,7 @@ int main() { pthread_join(ballast[i], 0); pthread_barrier_wait(&heap->barrier_finalizer); while (__atomic_load_n(&heap->wg, __ATOMIC_ACQUIRE) != 2) - pthread_yield(); + sched_yield(); // OHOS_LOCAL if (heap->data != 1) exit(printf("no data\n")); for (int i = 0; i < 3; i++) diff --git a/compiler-rt/test/tsan/lit.cfg.py b/compiler-rt/test/tsan/lit.cfg.py index 4295514f0a5e32386f38b6f0de0a4341594a41ac..ddd4d21642fa558a66763c25c00e152c699d1e1e 100644 --- a/compiler-rt/test/tsan/lit.cfg.py +++ b/compiler-rt/test/tsan/lit.cfg.py @@ -18,24 +18,25 @@ config.name = 'ThreadSanitizer' + config.name_suffix config.test_source_root = os.path.dirname(__file__) # Setup environment variables for running ThreadSanitizer. -default_tsan_opts = "atexit_sleep_ms=0" +# OHOS_LOCAL begin +default_tsan_opts = list(config.default_sanitizer_opts) +default_tsan_opts += ["atexit_sleep_ms=0"] if config.host_os == 'Darwin': - # On Darwin, we default to `abort_on_error=1`, which would make tests run - # much slower. Let's override this and run lit tests with 'abort_on_error=0'. - default_tsan_opts += ':abort_on_error=0' # On Darwin, we default to ignore_noninstrumented_modules=1, which also # suppresses some races the tests are supposed to find. Let's run without this # setting, but turn it back on for Darwin tests (see Darwin/lit.local.cfg.py). - default_tsan_opts += ':ignore_noninstrumented_modules=0' - default_tsan_opts += ':ignore_interceptors_accesses=0' + default_tsan_opts += ['ignore_noninstrumented_modules=0'] + default_tsan_opts += ['ignore_interceptors_accesses=0'] # Platform-specific default TSAN_OPTIONS for lit tests. -if default_tsan_opts: - config.environment['TSAN_OPTIONS'] = default_tsan_opts - default_tsan_opts += ':' +default_tsan_opts_str = ':'.join(default_tsan_opts) +if default_tsan_opts_str: + config.environment['TSAN_OPTIONS'] = default_tsan_opts_str + default_tsan_opts_str += ':' config.substitutions.append(('%env_tsan_opts=', - 'env TSAN_OPTIONS=' + default_tsan_opts)) + 'env TSAN_OPTIONS=' + default_tsan_opts_str)) +# OHOS_LOCAL end # GCC driver doesn't add necessary compile/link flags with -fsanitize=thread. if config.compiler_id == 'GNU': @@ -81,7 +82,7 @@ config.substitutions.append( ("%deflake ", os.path.join(os.path.dirname(__file__ # Default test suffixes. config.suffixes = ['.c', '.cpp', '.m', '.mm'] -if config.host_os not in ['FreeBSD', 'Linux', 'Darwin', 'NetBSD']: +if config.host_os not in ['FreeBSD', 'Linux', 'Darwin', 'NetBSD', 'OHOS']: # OHOS_LOCAL config.unsupported = True if config.android: diff --git a/compiler-rt/test/tsan/mutex_lock_destroyed.cpp b/compiler-rt/test/tsan/mutex_lock_destroyed.cpp index 892d444005411b3658c4a3b3c474da54dbc9f87a..1a4135008410973e5d25e2458ab478c8341f40eb 100644 --- a/compiler-rt/test/tsan/mutex_lock_destroyed.cpp +++ b/compiler-rt/test/tsan/mutex_lock_destroyed.cpp @@ -5,6 +5,10 @@ // The pthread_mutex_lock interceptor assumes incompatible internals w/ NetBSD // XFAIL: netbsd +// OHOS_LOCAL +// musl seems to not return error when calling pthread_mutex_lock with a destroyed mutex +// UNSUPPORTED: ohos_family + #include #include #include diff --git a/compiler-rt/test/tsan/on_exit.cpp b/compiler-rt/test/tsan/on_exit.cpp index 2dadd68c144a41b7716203c421b6b64ad2e8c9f6..567fd0a8a73b8f53a808a431ece6d9694db7c2c4 100644 --- a/compiler-rt/test/tsan/on_exit.cpp +++ b/compiler-rt/test/tsan/on_exit.cpp @@ -3,6 +3,10 @@ // on_exit() is not available on Darwin. // UNSUPPORTED: darwin +// OHOS_LOCAL +// on_exit() is not available on musl. +// UNSUPPORTED: ohos_family + #include "test.h" volatile long global; diff --git a/compiler-rt/test/tsan/signal_sync2.cpp b/compiler-rt/test/tsan/signal_sync2.cpp index a1c31dcdc1ee74dddb0ea57c075d5ec0aa1e8901..7f61dae6a9a6c56e10e8b327a569f7b7b27861a8 100644 --- a/compiler-rt/test/tsan/signal_sync2.cpp +++ b/compiler-rt/test/tsan/signal_sync2.cpp @@ -13,13 +13,21 @@ const int kSignalCount = 500; -__thread int process_signals; +// OHOS_LOCAL begin +pthread_t main_tid; +int process_signals; +// OHOS_LOCAL end int signals_handled; int done; int ready[kSignalCount]; long long data[kSignalCount]; static void handler(int sig) { + // OHOS_LOCAL begin + // avoid using possibly emulated TLS in signal handlers + if (pthread_self() == main_tid) + return; + // OHOS_LOCAL end if (!__atomic_load_n(&process_signals, __ATOMIC_RELAXED)) return; int pos = signals_handled++; @@ -39,6 +47,8 @@ static void* thr(void *p) { } int main() { + main_tid = pthread_self(); // OHOS_LOCAL + struct sigaction act = {}; act.sa_handler = handler; if (sigaction(SIGPROF, &act, 0)) { diff --git a/compiler-rt/test/tsan/strerror_r.cpp b/compiler-rt/test/tsan/strerror_r.cpp index 438f54914d6c1cbf92bffcea86e8991c1c713684..3b0497ed97f3068d62d49412474aecebe40306d3 100644 --- a/compiler-rt/test/tsan/strerror_r.cpp +++ b/compiler-rt/test/tsan/strerror_r.cpp @@ -1,7 +1,8 @@ // RUN: %clangxx_tsan -O1 -DTEST_ERROR=ERANGE %s -o %t && %run %t 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-SYS %s // RUN: %clangxx_tsan -O1 -DTEST_ERROR=-1 %s -o %t && not %run %t 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-USER %s // This test is for GNU specific version of strerror_r() -// UNSUPPORTED: darwin, netbsd, freebsd +// OHOS_LOCAL +// UNSUPPORTED: darwin, netbsd, freebsd, ohos_family #include "test.h" diff --git a/compiler-rt/test/tsan/thread_name.cpp b/compiler-rt/test/tsan/thread_name.cpp index bc65421b36d0159c1ec65d5872e7c9338761c0e1..f6396ed29c79a6d901c8f6cd04aef82881714ebf 100644 --- a/compiler-rt/test/tsan/thread_name.cpp +++ b/compiler-rt/test/tsan/thread_name.cpp @@ -1,7 +1,8 @@ // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" -#if defined(__linux__) +// OHOS_LOCAL +#if defined(__linux__) && !defined(__OHOS__) #define USE_PTHREAD_SETNAME_NP __GLIBC_PREREQ(2, 12) #define tsan_pthread_setname_np pthread_setname_np #elif defined(__FreeBSD__) @@ -11,6 +12,11 @@ #elif defined(__NetBSD__) #define USE_PTHREAD_SETNAME_NP 1 #define tsan_pthread_setname_np(a, b) pthread_setname_np((a), "%s", (void *)(b)) +// OHOS_LOCAL begin +#elif defined(__OHOS__) +#define USE_PTHREAD_SETNAME_NP 1 +#define tsan_pthread_setname_np pthread_setname_np +// OHOS_LOCAL end #else #define USE_PTHREAD_SETNAME_NP 0 #endif diff --git a/compiler-rt/test/tsan/tls_race.cpp b/compiler-rt/test/tsan/tls_race.cpp index 5f5b6aae4f586f6c645dff7c28396abea3a059f0..0821680d0aaefa566189e1f19f109fee436588ed 100644 --- a/compiler-rt/test/tsan/tls_race.cpp +++ b/compiler-rt/test/tsan/tls_race.cpp @@ -24,3 +24,5 @@ int main() { // CHECK-FreeBSD: Location is TLS of main thread. // CHECK-NetBSD: Location is TLS of main thread. // CHECK-Darwin: Location is heap block of size 4 +// OHOS_LOCAL +// CHECK-OHOS: Location is heap block of size diff --git a/compiler-rt/test/tsan/tls_race2.cpp b/compiler-rt/test/tsan/tls_race2.cpp index 0e008313518a27cd3f88917c0f67303bce0af0a2..b05547e6643fbc5f4513cc93ec6eae28a9d474e8 100644 --- a/compiler-rt/test/tsan/tls_race2.cpp +++ b/compiler-rt/test/tsan/tls_race2.cpp @@ -33,4 +33,6 @@ int main() { // CHECK-FreeBSD: Location is TLS of thread T1. // CHECK-NetBSD: Location is TLS of thread T1. // CHECK-Darwin: Location is heap block of size 4 +// OHOS_LOCAL +// CHECK-OHOS: Location is heap block of size // CHECK: DONE diff --git a/llvm/utils/lit/lit/llvm/subst.py b/llvm/utils/lit/lit/llvm/subst.py index 4275b8a56a3be4aad21a22fddfa914876fd89777..c51a257386bb24a9b2cda8e0cb418c0597b4c217 100644 --- a/llvm/utils/lit/lit/llvm/subst.py +++ b/llvm/utils/lit/lit/llvm/subst.py @@ -29,6 +29,18 @@ class FindTool(object): command += ' go=' + exe return command +# OHOS_LOCAL begin +class WrapTool(FindTool): + def __init__(self, name, wrapper): + super().__init__(name) + self.wrapper = wrapper + + def resolve(self, config, dirs): + command = super().resolve(config, dirs) + if not command: + return None + return self.wrapper + " " + command +# OHOS_LOCAL end class ToolSubst(object): """String-like class used to build regex substitution patterns for llvm