From 7697558d5035f9456065e7824992d8afc6ff2f4d Mon Sep 17 00:00:00 2001 From: Lyupa Anastasia Date: Thu, 18 Apr 2024 12:40:31 +0300 Subject: [PATCH] [ASan][OHOS] Update tests for OHOS - Enable check-asan-dynamic for OHOS. - Add CHECK-OHOS prefix to large_func_test.cpp and use-after-delete.cpp tests. - Make init_fini_sections.cpp test unsupported because .preinit_array is not supported in musl. - Make global-overflow-bfd.cpp test unsupported because BFD linker does not support such emulation modes. - Make shmctl.cpp xfail because shmget() fails on OHOS. - Change file name for opening in readv.cpp test because /etc/hosts does not exist on OHOS. - Exclude wait4.cpp from XFAIL because it fails only on android. - Not add abort_on_error=0 option if abort_on_error is already present to fix handle_abort_on_error.cpp test because there is abort_on_error=1 in run command. - Add timeout to hdc call. - Make timed out tests xfail (rlimit_mmap_test.cpp, mmap_limit_mb.cpp). Issue: https://gitee.com/openharmony/third_party_llvm-project/issues/I9HWDV Signed-off-by: Lyupa Anastasia --- .../test/asan/TestCases/Linux/global-overflow-bfd.cpp | 3 +++ .../test/asan/TestCases/Linux/init_fini_sections.cpp | 3 +++ .../test/asan/TestCases/Linux/rlimit_mmap_test.cpp | 5 +++++ compiler-rt/test/asan/TestCases/Linux/shmctl.cpp | 2 +- compiler-rt/test/asan/TestCases/Posix/mmap_limit_mb.cpp | 4 ++++ compiler-rt/test/asan/TestCases/Posix/readv.cpp | 6 ++++++ compiler-rt/test/asan/TestCases/Posix/wait4.cpp | 2 +- compiler-rt/test/asan/TestCases/large_func_test.cpp | 6 +++++- compiler-rt/test/asan/TestCases/use-after-delete.cpp | 8 ++++++-- compiler-rt/test/asan/lit.cfg.py | 2 +- .../sanitizer_common/ohos_family_commands/ohos_common.py | 2 +- .../sanitizer_common/ohos_family_commands/ohos_run.py | 7 +++++-- 12 files changed, 41 insertions(+), 9 deletions(-) diff --git a/compiler-rt/test/asan/TestCases/Linux/global-overflow-bfd.cpp b/compiler-rt/test/asan/TestCases/Linux/global-overflow-bfd.cpp index 117a761af91f..4dadd579ff3a 100644 --- a/compiler-rt/test/asan/TestCases/Linux/global-overflow-bfd.cpp +++ b/compiler-rt/test/asan/TestCases/Linux/global-overflow-bfd.cpp @@ -1,6 +1,9 @@ // Test that gc-sections-friendly instrumentation of globals does not introduce // false negatives with the BFD linker. // RUN: %clangxx_asan -fuse-ld=bfd -Wl,-gc-sections -ffunction-sections -fdata-sections -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s +// +// OHOS_LOCAL +// UNSUPPORTED: ohos_family #include int main(int argc, char **argv) { diff --git a/compiler-rt/test/asan/TestCases/Linux/init_fini_sections.cpp b/compiler-rt/test/asan/TestCases/Linux/init_fini_sections.cpp index 3037b232926e..7cfc708aebc2 100644 --- a/compiler-rt/test/asan/TestCases/Linux/init_fini_sections.cpp +++ b/compiler-rt/test/asan/TestCases/Linux/init_fini_sections.cpp @@ -1,4 +1,7 @@ // RUN: %clangxx_asan %s -o %t && %run %t | FileCheck %s +// +// OHOS_LOCAL +// UNSUPPORTED: ohos_family #include diff --git a/compiler-rt/test/asan/TestCases/Linux/rlimit_mmap_test.cpp b/compiler-rt/test/asan/TestCases/Linux/rlimit_mmap_test.cpp index 7f37727b2eeb..4905e1516224 100644 --- a/compiler-rt/test/asan/TestCases/Linux/rlimit_mmap_test.cpp +++ b/compiler-rt/test/asan/TestCases/Linux/rlimit_mmap_test.cpp @@ -1,5 +1,10 @@ // Check that we properly report mmap failure. // RUN: %clangxx_asan %s -o %t && not %run %t 2>&1 | FileCheck %s +// +// OHOS_LOCAL +// FIXME: timed out test +// XFAIL: ohos_family + #include #include #include diff --git a/compiler-rt/test/asan/TestCases/Linux/shmctl.cpp b/compiler-rt/test/asan/TestCases/Linux/shmctl.cpp index 8fed52092be8..eec592c8fbee 100644 --- a/compiler-rt/test/asan/TestCases/Linux/shmctl.cpp +++ b/compiler-rt/test/asan/TestCases/Linux/shmctl.cpp @@ -1,5 +1,5 @@ // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 -// XFAIL: android && !ohos_family +// XFAIL: android // // RUN: %clangxx_asan -O1 %s -o %t && %run %t 2>&1 // Regression test for diff --git a/compiler-rt/test/asan/TestCases/Posix/mmap_limit_mb.cpp b/compiler-rt/test/asan/TestCases/Posix/mmap_limit_mb.cpp index cb613f53577a..d34e8db9e3e7 100644 --- a/compiler-rt/test/asan/TestCases/Posix/mmap_limit_mb.cpp +++ b/compiler-rt/test/asan/TestCases/Posix/mmap_limit_mb.cpp @@ -10,6 +10,10 @@ // // FIXME: Windows doesn't implement mmap_limit_mb. // XFAIL: windows-msvc +// +// OHOS_LOCAL +// FIXME: timed out test +// XFAIL: ohos_family #include #include diff --git a/compiler-rt/test/asan/TestCases/Posix/readv.cpp b/compiler-rt/test/asan/TestCases/Posix/readv.cpp index 27436a1ad3d9..79a4c9cefb0c 100644 --- a/compiler-rt/test/asan/TestCases/Posix/readv.cpp +++ b/compiler-rt/test/asan/TestCases/Posix/readv.cpp @@ -23,7 +23,13 @@ int main() { iov[0].iov_len = 5; iov[1].iov_base = buf + 10; iov[1].iov_len = 2000; +// OHOS_LOCAL begin +#if defined(__OHOS__) + int fd = open("/etc/resolv.conf", O_RDONLY); +#else int fd = open("/etc/hosts", O_RDONLY); +#endif +// OHOS_LOCAL end assert(fd > 0); readv(fd, iov, 2); // CHECK: WRITE of size 5 at diff --git a/compiler-rt/test/asan/TestCases/Posix/wait4.cpp b/compiler-rt/test/asan/TestCases/Posix/wait4.cpp index 1e574d99fe00..a806a0c7badf 100644 --- a/compiler-rt/test/asan/TestCases/Posix/wait4.cpp +++ b/compiler-rt/test/asan/TestCases/Posix/wait4.cpp @@ -4,7 +4,7 @@ // RUN: %clangxx_asan -DWAIT4_RUSAGE -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s // RUN: %clangxx_asan -DWAIT4_RUSAGE -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s -// XFAIL: android +// XFAIL: android && !ohos_family // UNSUPPORTED: darwin #include diff --git a/compiler-rt/test/asan/TestCases/large_func_test.cpp b/compiler-rt/test/asan/TestCases/large_func_test.cpp index 563c1458c966..3a4181e618ba 100644 --- a/compiler-rt/test/asan/TestCases/large_func_test.cpp +++ b/compiler-rt/test/asan/TestCases/large_func_test.cpp @@ -29,6 +29,8 @@ static void LargeFunction(int *x, int zero) { // CHECK-Windows:{{#0 0x.* in LargeFunction.*large_func_test.cpp:}}[[@LINE-5]] // CHECK-FreeBSD:{{#0 0x.* in LargeFunction.*large_func_test.cpp:}}[[@LINE-6]] // CHECK-Darwin: {{#0 0x.* in .*LargeFunction.*large_func_test.cpp}}:[[@LINE-7]] + // OHOS_LOCAL + // CHECK-OHOS: {{#0 0x.* in LargeFunction.*large_func_test.cpp:}}[[@LINE-9]] x[10]++; x[11]++; @@ -53,7 +55,9 @@ int main(int argc, char **argv) { // CHECK-Windows:{{ #0 0x.* in operator new}} // CHECK-FreeBSD:{{ #0 0x.* in operator new}} // CHECK-Darwin: {{ #0 0x.* in .*_Zna}} - // CHECK-NEXT: {{ #1 0x.* in main .*large_func_test.cpp:}}[[@LINE-10]] + // OHOS_LOCAL + // CHECK-OHOS: {{ #0 0x.* in operator new}} + // CHECK-NEXT: {{ #1 0x.* in main .*large_func_test.cpp:}}[[@LINE-12]] int y = x[argc]; delete[] x; return y; diff --git a/compiler-rt/test/asan/TestCases/use-after-delete.cpp b/compiler-rt/test/asan/TestCases/use-after-delete.cpp index 4d0c055368bb..f06048de064f 100644 --- a/compiler-rt/test/asan/TestCases/use-after-delete.cpp +++ b/compiler-rt/test/asan/TestCases/use-after-delete.cpp @@ -21,7 +21,9 @@ int main() { // CHECK-Windows:{{ #0 0x.* in operator delete\[\]}} // CHECK-FreeBSD:{{ #0 0x.* in operator delete\[\]}} // CHECK-Darwin: {{ #0 0x.* in .*_Zda}} - // CHECK-NEXT: {{ #1 0x.* in main .*use-after-delete.cpp:}}[[@LINE-14]] + // OHOS_LOCAL + // CHECK-OHOS: {{ #0 0x.* in operator delete\[\]}} + // CHECK-NEXT: {{ #1 0x.* in main .*use-after-delete.cpp:}}[[@LINE-16]] // CHECK: {{previously allocated by thread T0 here:}} // CHECK-Linux: {{ #0 0x.* in operator new\[\]}} @@ -29,7 +31,9 @@ int main() { // CHECK-Windows:{{ #0 0x.* in operator new\[\]}} // CHECK-FreeBSD:{{ #0 0x.* in operator new\[\]}} // CHECK-Darwin: {{ #0 0x.* in .*_Zna}} - // CHECK-NEXT: {{ #1 0x.* in main .*use-after-delete.cpp:}}[[@LINE-23]] + // OHOS_LOCAL + // CHECK-OHOS: {{ #0 0x.* in operator new\[\]}} + // CHECK-NEXT: {{ #1 0x.* in main .*use-after-delete.cpp:}}[[@LINE-27]] // CHECK: Shadow byte legend (one shadow byte represents {{[0-9]+}} application bytes): diff --git a/compiler-rt/test/asan/lit.cfg.py b/compiler-rt/test/asan/lit.cfg.py index cbe84170c61e..3fb929e3b16a 100644 --- a/compiler-rt/test/asan/lit.cfg.py +++ b/compiler-rt/test/asan/lit.cfg.py @@ -131,7 +131,7 @@ config.substitutions.append( ("%clangxx ", build_invocation(target_cxxflags)) ) config.substitutions.append( ("%clang_asan ", build_invocation(clang_asan_cflags)) ) config.substitutions.append( ("%clangxx_asan ", build_invocation(clang_asan_cxxflags)) ) if config.asan_dynamic: - if config.host_os in ['Linux', 'FreeBSD', 'NetBSD', 'SunOS']: + if config.host_os in ['Linux', 'FreeBSD', 'NetBSD', 'SunOS', 'OHOS']: # OHOS_LOCAL shared_libasan_path = os.path.join(config.compiler_rt_libdir, "libclang_rt.asan{}.so".format(config.target_suffix)) elif config.host_os == 'Darwin': shared_libasan_path = os.path.join(config.compiler_rt_libdir, 'libclang_rt.asan_{}_dynamic.dylib'.format(config.apple_platform)) 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 b84161f8b99c..dbe446a68483 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 @@ -14,7 +14,7 @@ def host_to_device_path(path): def hdc_output(args): command = hdc_constants.get_hdc_cmd_prefix() + args - return subprocess.check_output(command, stderr=subprocess.STDOUT) + return subprocess.check_output(command, stderr=subprocess.STDOUT, timeout=300) def hdc(args, attempts=1, check_stdout=''): if verbose: 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 1bdd8ea33771..a6e7596d2178 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 @@ -26,12 +26,15 @@ def build_env(): sanitizers = ( 'HWASAN', 'ASAN', 'LSAN', 'MEMPROF', 'MSAN', 'TSAN', 'UBSAN', 'SCUDO' ) + set_abort_on_error=True for san in sanitizers: - # for all sanitizers we need 'abort_on_error=0', + # for all sanitizers we need 'abort_on_error=0' if 'abort_on_error=1' is not set, # so prepare key for them, to set value later opt_str = '%s_OPTIONS' % san if opt_str not in os.environ: os.environ[opt_str] = '' + elif 'abort_on_error=1' in os.environ[opt_str]: + set_abort_on_error=False # All sanitizers need external symbolizers for some tests # set them by default to llvm-symbolizer @@ -42,7 +45,7 @@ def build_env(): args.append('LD_LIBRARY_PATH=%s' % ( hdc_constants.TMPDIR,)) for (key, value) in os.environ.items(): san_opt = key.endswith('SAN_OPTIONS') - if san_opt: + if san_opt and set_abort_on_error: value += ':abort_on_error=0' if key in ['ASAN_ACTIVATION_OPTIONS', 'SCUDO_OPTIONS'] or san_opt or key == 'LD_LIBRARY_PATH': if key in ['TSAN_OPTIONS', 'UBSAN_OPTIONS']: -- Gitee