From aee8229a3280cc6930c36383dc04d93f2dbf2b90 Mon Sep 17 00:00:00 2001 From: Yuanfang Chen Date: Mon, 22 Aug 2022 16:01:09 -0700 Subject: [PATCH 1/2] [compiler-rt][lit] initialize LIT LLVMConfig instance to handle lit tools searching. Otherwise compiler-rt depends on system environment variable PATH for lit tools which diverge from the other LLVM projects. This reverts D83486 which really should be implemented in LIT itself when the PATH is constructed. Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D122837 Signed-off-by: Nikolai Kholiavin --- compiler-rt/test/lit.common.cfg.py | 2 -- compiler-rt/test/lit.common.configured.in | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py index 04093624454c..30e47066d3cd 100644 --- a/compiler-rt/test/lit.common.cfg.py +++ b/compiler-rt/test/lit.common.cfg.py @@ -176,8 +176,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', diff --git a/compiler-rt/test/lit.common.configured.in b/compiler-rt/test/lit.common.configured.in index a06ede7e7331..1a20461cbf7d 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") -- Gitee From 2c3738c12991809e306219491c0e3a02234cc7f3 Mon Sep 17 00:00:00 2001 From: Nikolai Kholiavin Date: Thu, 15 Feb 2024 12:18:02 +0000 Subject: [PATCH 2/2] [OHOS][compiler-rt][test] Enable TSan testing remotely on OHOS devices This enables TSan tests for OHOS; disables some tests that use features absent from upstream or OHOS musl; turns on pthread_setname_np and pthread_getname_np interceptors, because these functions are available on OHOS musl. Also, modifies test suite to be able to run TSan tests, in particular the handling of LD_LIBRARY_PATH and local suppressions files to work on the remote device as well; replaces pthread_yield with sched_yield in tests. Issue: https://gitee.com/openharmony/third_party_llvm-project/issues/I91O7W Signed-off-by: Nikolai Kholiavin --- .../sanitizer_platform_interceptors.h | 6 +++-- compiler-rt/lib/tsan/tests/CMakeLists.txt | 6 +++++ .../TestCases/Posix/halt_on_error-torture.cpp | 6 +++-- compiler-rt/test/lit.common.cfg.py | 22 ++++++++++++++++ .../ohos_family_commands/hdc_constants.py | 1 + .../ohos_family_commands/ohos_common.py | 2 +- .../ohos_family_commands/ohos_compile.py | 6 ++--- .../ohos_family_commands/ohos_run.py | 26 ++++++++++++++++++- .../ohos_family_commands/ohos_tool.py | 11 ++++++++ compiler-rt/test/tsan/CMakeLists.txt | 12 ++++++--- compiler-rt/test/tsan/Linux/lit.local.cfg.py | 2 +- compiler-rt/test/tsan/Linux/mutex_robust.cpp | 3 +++ compiler-rt/test/tsan/Linux/mutex_robust2.cpp | 3 +++ .../test/tsan/Linux/thread_timedjoin.c | 3 +++ compiler-rt/test/tsan/Linux/thread_tryjoin.c | 5 +++- compiler-rt/test/tsan/cond_cancel.c | 3 +++ compiler-rt/test/tsan/debugging.cpp | 6 +++-- compiler-rt/test/tsan/dtls.c | 3 +++ compiler-rt/test/tsan/fiber_from_thread.cpp | 3 +++ compiler-rt/test/tsan/fiber_longjmp.cpp | 3 +++ compiler-rt/test/tsan/fiber_race.cpp | 3 +++ compiler-rt/test/tsan/fiber_simple.cpp | 3 +++ compiler-rt/test/tsan/fiber_two_threads.cpp | 3 +++ compiler-rt/test/tsan/ignore_lib1.cpp | 4 +++ compiler-rt/test/tsan/ignore_lib2.cpp | 4 +++ compiler-rt/test/tsan/ignore_lib3.cpp | 4 +++ compiler-rt/test/tsan/ignore_lib4.cpp | 4 +++ compiler-rt/test/tsan/ignore_lib5.cpp | 4 +++ .../test/tsan/ignored-interceptors-mmap.cpp | 7 +++-- compiler-rt/test/tsan/java_finalizer2.cpp | 6 ++--- compiler-rt/test/tsan/lit.cfg.py | 23 ++++++++-------- .../test/tsan/mutex_lock_destroyed.cpp | 4 +++ compiler-rt/test/tsan/on_exit.cpp | 4 +++ compiler-rt/test/tsan/signal_sync2.cpp | 12 ++++++++- compiler-rt/test/tsan/strerror_r.cpp | 3 ++- compiler-rt/test/tsan/thread_name.cpp | 8 +++++- compiler-rt/test/tsan/tls_race.cpp | 2 ++ compiler-rt/test/tsan/tls_race2.cpp | 2 ++ llvm/utils/lit/lit/llvm/subst.py | 12 +++++++++ 39 files changed, 208 insertions(+), 36 deletions(-) create mode 100755 compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_tool.py diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index d2858ab538f3..8131bb915337 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 8afd217cb8b0..d36ed16b499a 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 559f9434e392..f0f36ec310c7 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 30e47066d3cd..869d0e233ef3 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. @@ -255,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 ")) @@ -263,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, @@ -272,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, @@ -341,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))) @@ -516,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/sanitizer_common/ohos_family_commands/hdc_constants.py b/compiler-rt/test/sanitizer_common/ohos_family_commands/hdc_constants.py index af6853ed8b1d..5fcfb514f4b3 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 de2aabe8107e..b84161f8b99c 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 9006dac3d3b9..b3f48571588e 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 c53c94c46ce9..675e064fa8ff 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 000000000000..cb3eb0fdabd6 --- /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 25e95aa98cf9..45039aecff7b 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 57271b8078a4..ce7ce5ddde93 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 5ca5e70d49a7..bddf57e96539 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 0914c1763604..d6cae7a7c497 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 1d3f1098ece7..a7cdb335bcbe 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 675e1595528a..789842e0ed1b 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 7f20b8f8add4..0c741f7106a0 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 be0a0c7b0824..ec4dd59625c3 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 57c9da83a374..9b4febb0c019 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 d27379e7acf4..7f859a0c55e8 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 e56fd21befbb..189726e4a042 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 add66940ffd1..eef17cf42c5c 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 8123eb8eafc8..633f8bd408f5 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 d2961b94dde1..b4d6604c7ef1 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 01139519e491..2b17dee50141 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 05b7c2ed915a..24b7f5e66a3e 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 b1a3940d03b6..b13229184141 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 06241c7b89f3..00bde34639d0 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 a71d560ab913..9ae3f7bcbb95 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 2b35627229df..bbf43be5b605 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 87528900541a..77e222766bd8 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 4295514f0a5e..ddd4d21642fa 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 892d44400541..1a4135008410 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 2dadd68c144a..567fd0a8a73b 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 a1c31dcdc1ee..7f61dae6a9a6 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 438f54914d6c..3b0497ed97f3 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 bc65421b36d0..f6396ed29c79 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 5f5b6aae4f58..0821680d0aae 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 0e008313518a..b05547e6643f 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 4275b8a56a3b..c51a257386bb 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 -- Gitee