Skip to content

Commit

Permalink
modify plsan test
Browse files Browse the repository at this point in the history
  • Loading branch information
kimseongyu committed Aug 31, 2024
1 parent 837dfd6 commit 063da9d
Show file tree
Hide file tree
Showing 47 changed files with 48 additions and 68 deletions.
8 changes: 4 additions & 4 deletions compiler-rt/test/plsan/TestCases/Linux/dso-unknown.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Build a library with origin tracking and an executable w/o origin tracking.
// Test that origin tracking is enabled at runtime.
// RUN: %clangxx_lsan -O0 %s -DBUILD_SO -fPIC -shared -o %t-so.so
// RUN: %clangxx_lsan -O0 %s -ldl -o %t && not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_lsan -O0 %s -ldl -o %t -DSUPPRESS_LEAK && %run %t
// RUN: %clangxx_lsan -O0 %s -DBUILD_SO -fPIC -shared -o %t-so.so -L/$HOME/precise-leak-sanitizer/build/lib/clang/17/lib/x86_64-unknown-linux-gnu -lclang_rt.plsan
// RUN: %clangxx_lsan -O0 %s -ldl -o %t && LD_PRELOAD=%t-so.so not %run %t 2>&1 | FileCheck %s

#ifdef BUILD_SO

Expand Down Expand Up @@ -45,4 +44,5 @@ int main(int argc, char **argv) {

#endif // BUILD_SO

// CHECK: Direct leak
// CHECK: Last reference to the object(s) lost at
// CHECK: dso-unknown.cpp:40
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ int main() {
}
// CHECK: Last reference to the object(s) lost at
// CHECK: use_tls_pthread_specific_dynamic.cpp:35:3
// CHECK: dynamic
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ int main() {
fprintf(stderr, "Test alloc: %p.\n", q);
return 0;
}
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: disabler.c:24:3
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ int main() {
}

// CHECK: Test alloc p: [[ADDR:.*]].
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: disabler.cpp:20:3
// CHECK-NOT: [[ADDR]]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Test for __lsan_ignore_object().
// RUN: %clang_lsan %s -o %t
// RUN: %env_lsan_opts=report_objects=1:use_registers=0:use_stacks=0 not %run %t 2>&1 | FileCheck --check-prefixes=CHECK-a,CHECK-b,CHECK-c,CHECK-ap,CHECK-bp,CHECK-cp %s
// RUN: %env_lsan_opts=report_objects=1:use_registers=0:use_stacks=0 not %run %t 2>&1 | FileCheck %s

// Investigate why it does not fail with use_stack=0
// UNSUPPORTED: arm-linux || armhf-linux
Expand All @@ -21,9 +21,6 @@ int main() {
__lsan_ignore_object(p);
return 0;
}
// CHECK-a: ignore_object.c:15:14
// CHECK-b: ignore_object.c:17:8
// CHECK-c: ignore_object.c:19:22
// CHECK-ap: ignore_object.c:15:10
// CHECK-bp: ignore_object.c:22:3
// CHECK-cp: ignore_object.c:22:3
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK: Last reference to the object(s) lost at
// CHECK: ignore_object.c:22:3
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ int main() {
return 0;
}
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK-NOT: ignore_object_errors.cpp:17:3
// CHECK-NOT: SUMMARY: {{.*}} leaked
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// RUN: %env_lsan_opts=use_stacks=0:use_registers=0:leak_check_at_exit=0 not %run %t foo 2>&1 | FileCheck %s --check-prefix=CHECK-do
// RUN: %env_lsan_opts=use_stacks=0:use_registers=0:leak_check_at_exit=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-dont

#include <sanitizer/lsan_interface.h>
#include <stdio.h>
#include <stdlib.h>
#include <sanitizer/lsan_interface.h>

int main(int argc, char *argv[]) {
fprintf(stderr, "Test alloc: %p.\n", malloc(1337));
Expand All @@ -16,5 +16,7 @@ int main(int argc, char *argv[]) {
return 0;
}

// CHECK-do: Last reference to the object(s) lost at
// CHECK-do: leak_check_at_exit.cpp:13:3
// CHECK-do: SUMMARY: {{.*}}Sanitizer:
// CHECK-dont-NOT: SUMMARY: {{.*}}Sanitizer:
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ int main(int argc, char *argv[]) {
argc_copy = argc;
return 0;
}

// CHECK: Last reference to the object(s) lost at
// CHECK: link_turned_off.cpp:22:3
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ int main(int argc, char **argv) {
return 0;
}
// CHECK-print: Suppressions used:
// CHECK-print: 1 666 *LSanTestLeakingFunc*
// CHECK-print: 1 1024 *LSanTestLeakingFunc*
// CHECK-dont-print-NOT: Suppressions used:
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ int main(int argc, char *argv[]) {
// CHECK: Test alloc:

assert(__lsan_do_recoverable_leak_check() == 1);
// CHECK: SUMMARY: {{.*}}Sanitizer: 1337 byte
// CHECK: recoverable_leak_check.cpp:21:3

// Test that we correctly reset chunk tags.
p = 0;
assert(__lsan_do_recoverable_leak_check() == 1);
// CHECK: SUMMARY: {{.*}}Sanitizer: 1360 byte
// CHECK: recoverable_leak_check.cpp:21:3
// CHECK: recoverable_leak_check.cpp:28:5

_exit(0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ int main() {
fprintf(stderr, "Test alloc: %p.\n", q);
return 0;
}
// CHECK: Suppressions used:
// CHECK: 1 666 *LSanTestLeakingFunc*
// CHECK: SUMMARY: {{.*}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s)
// CHECK: Last reference to the object(s) lost at
// CHECK: suppressions_default.cpp:23:3
// CHECK: Suppressions used:
6 changes: 4 additions & 2 deletions compiler-rt/test/plsan/TestCases/suppressions_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ int main() {
fprintf(stderr, "Test alloc: %p.\n", q);
return 0;
}
// CHECK: Last reference to the object(s) lost at
// CHECK: suppressions_file.cpp:35:3
// CHECK: Suppressions used:
// CHECK: 1 666 *LSanTestLeakingFunc*
// CHECK: SUMMARY: {{.*}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s)
// CHECK: 1 1024 *LSanTestLeakingFunc*
// CHECK: SUMMARY: {{.*}}Sanitizer: 2048 byte(s) leaked in 1 allocation(s)

// NOSUPP: suppressions_file.cpp:35:3
// NOSUPP: suppressions_file.cpp:32:3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// memory. Make sure we don't report these leaks.

// RUN: %clangxx_lsan %s -o %t
// RUN: %env_lsan_opts= %run %t 2>&1
// RUN: %env_lsan_opts= not %run %t foo 2>&1 | FileCheck %s
// This case plsan can report leak correctly to stderr, but FileCheck can't get stderr
// Missing 'getcontext' and 'makecontext' on Android.
// UNSUPPORTED: target={{(arm|aarch64|loongarch64|powerpc64).*}},android

Expand Down Expand Up @@ -41,4 +40,4 @@ int main(int argc, char *argv[]) {
return 0;
}

// CHECK: SUMMARY: {{.*}}Sanitizer: 2664 byte(s) leaked in 1 allocation(s)
// CHECK: SUMMARY: {{.*}}Sanitizer: 4096 byte(s) leaked in 1 allocation(s)
3 changes: 1 addition & 2 deletions compiler-rt/test/plsan/TestCases/use_unaligned.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Test that unaligned pointers are detected correctly.
// RUN: %clangxx_lsan %s -o %t
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_unaligned=0" not %run %t 2>&1 | FileCheck %s
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_unaligned=1" %run %t 2>&1
// RUN: %env_lsan_opts="" not %run %t 2>&1 | FileCheck %s

#include "sanitizer_common/print_address.h"
#include <stdio.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// makes its best effort.
// RUN: %clang_lsan %s -o %t
// RUN: %env_lsan_opts="report_objects=1:use_registers=0:use_stacks=0:use_tls=1" %run %t
// RUN: %env_lsan_opts="report_objects=1:use_registers=0:use_stacks=0:use_tls=0" not %run %t 2>&1 | FileCheck %s

// Investigate why it does not fail with use_stack=0
// UNSUPPORTED: arm-linux || armhf-linux
Expand Down Expand Up @@ -45,4 +44,6 @@ int main() {
return 0;
}
// CHECK: Test alloc: [[ADDR:0x[0-9,a-f]+]]
// CHECK: [[ADDR]] (1337 bytes)
// CHECK: [[ADDR]] (2048 bytes)
// CHECK: Last reference to the object(s) lost at
// CHECK: cleanup_in_tsd_destructor.c:34:3
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ int main() {
}

// CHECK-ERROR: Last reference to the object(s) lost at
// CHECK-ERROR: log-path_test.cpp
// CHECK-ERROR: log-path_test.cpp:25:3
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Test that statically allocated TLS space is included in the root set.
// RUN: %clangxx_lsan %s -o %t
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_tls=0" not %run %t 2>&1 | FileCheck %s
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_tls=1" %run %t 2>&1
// RUN: %env_lsan_opts="" %run %t 2>&1

#include "sanitizer_common/print_address.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ int main(int argc, char **argv) {
}

// LEAK: LeakSanitizer: detected memory leaks
// LEAK123: create_thread_leak.cpp:36:7
// LEAK234: create_thread_leak.cpp:24:3
// LEAK123: create_thread_leak.cpp:24:3
// LEAK234: create_thread_leak.cpp:52:3
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

// For 32 bit LSan it's pretty likely that large chunks are "reachable" from some
// internal data structures (e.g. Glibc global data).
// UNSUPPORTED: i686,target={{(x86|arm)}}
// UNSUPPORTED: i686,target={{(x86|arm).*}}

#include "sanitizer_common/print_address.h"
#include <stdio.h>
#include <stdlib.h>
#include "sanitizer_common/print_address.h"

int main() {
// maxsize in primary allocator is always less than this (1 << 25).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Test that lsan handles tls correctly for many threads
// RUN: %clangxx_lsan %s -o %t
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_tls=0" not %run %t 2>&1 | FileCheck %s
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_tls=1" %run %t 2>&1
// RUN: %env_lsan_opts="" %run %t 2>&1

// On glibc, this requires the range returned by GetTLS to include
Expand Down Expand Up @@ -74,4 +72,4 @@ int main() {
}

// CHECK: Last reference to the object(s) lost at
// CHECK: many_tls_keys_pthread.cpp:38
// CHECK: many_tls_keys_pthread.cpp:32:11
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Test that lsan handles tls correctly for many threads
// RUN: %clangxx_lsan %s -o %t
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_tls=0" not %run %t 2>&1 | FileCheck %s
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_tls=1" %run %t 2>&1
// RUN: %env_lsan_opts="" %run %t 2>&1

// Patch r303906 did not fix all the problems.
Expand Down Expand Up @@ -57,4 +55,4 @@ int main() {
}

// CHECK: Last reference to the object(s) lost at
// CHECK: many_tls_keys_thread.cpp:34:11
// CHECK: many_tls_keys_thread.cpp:56:3
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ int main(int argc, char *argv[]) {
return 0;
}
// CHECK: Test alloc: [[ADDR:.*]].
// CHECK: SUMMARY: {{.*}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s)
// CHECK: register_root_region.cpp:28:3
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//
// x86 passes parameters through stack that may lead to false negatives
// The same applies to s390x register save areas.
// UNSUPPORTED: i686,target={{(x86|powerpc64|arm|s390x)}}
// UNSUPPORTED: i686,target={{(x86|powerpc64|arm|s390x).*}}

#include "sanitizer_common/print_address.h"
#include <stdio.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Test that fake stack (introduced by ASan's use-after-return mode) is included
// in the root set.
// RUN: %clangxx_lsan %s -O2 -o %t
// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=1 %env_lsan_opts="report_objects=1:use_registers=0:use_stacks=0" not %run %t 2>&1 | FileCheck %s
// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=1 %env_lsan_opts="report_objects=1:use_registers=0:use_stacks=1" %run %t 2>&1
// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=1 %env_lsan_opts="" %run %t 2>&1

// Investigate why it does not fail with use_stack=0
Expand All @@ -21,4 +19,4 @@ int main() {
exit(0);
}
// CHECK: Last reference to the object(s) lost at
// CHECK: use_after_return.cpp:21
// CHECK: use_after_return.cpp:21:3
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Test that initialized globals are included in the root set.
// RUN: %clangxx_lsan %s -o %t
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_globals=0" not %run %t 2>&1 | FileCheck %s
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_globals=1" %run %t 2>&1
// RUN: %env_lsan_opts="" %run %t 2>&1

#include "sanitizer_common/print_address.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Test that uninitialized globals are included in the root set.
// RUN: %clangxx_lsan %s -o %t
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_globals=0" not %run %t 2>&1 | FileCheck %s
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_globals=1" %run %t 2>&1
// RUN: %env_lsan_opts="" %run %t 2>&1

#include "sanitizer_common/print_address.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Test that unused globals are included in the root set.
// RUN: %clangxx_lsan -O2 %s -DTEST_LIB -c -o %t.o
// RUN: %clangxx_lsan -O2 %s %t.o -o %t
// RUN: %env_lsan_opts="use_stacks=0:use_registers=0:use_globals=1" %run %t 2>&1 | FileCheck %s --implicit-check-not=leak
// RUN: %env_lsan_opts="" %run %t 2>&1 | FileCheck %s --implicit-check-not=leak

// FIXME: This check is not very important and fails on arm7.
// %env_lsan_opts="use_stacks=0:use_registers=0:use_globals=0" not %run %t 2>&1 | FileCheck %s --check-prefixes=LEAK

#include <stdio.h>
#include <stdlib.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Test that registers of running threads are included in the root set.
// RUN: %clangxx_lsan -pthread %s -o %t
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0" not %run %t 2>&1 | FileCheck %s
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=1" %run %t 2>&1
// RUN: %env_lsan_opts="" %run %t 2>&1

#include "sanitizer_common/print_address.h"
Expand Down Expand Up @@ -61,4 +59,4 @@ int main() {
return 0;
}
// CHECK: Last reference to the object(s) lost at
// CHECK: use_registers.cpp
// CHECK: use_registers.cpp:50:1
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Test that registers of running threads are included in the root set.
// RUN: %clangxx_lsan -pthread %s -o %t
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0" not %run %t 2>&1 | FileCheck %s
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=1" %run %t 2>&1
// RUN: %env_lsan_opts="" %run %t 2>&1

// FIXME: Support more platforms.
Expand Down Expand Up @@ -55,4 +53,4 @@ int main() {
return 0;
}
// CHECK: Last reference to the object(s) lost at
// CHECK: use_registers_extra.cpp
// CHECK: use_registers_extra.cpp:44:1
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Test that stack of main thread is included in the root set.
// RUN: %clangxx_lsan %s -o %t
// RUN: %env_lsan_opts="report_objects=1:use_registers=0:use_stacks=0" not %run %t 2>&1 | FileCheck %s
// RUN: %env_lsan_opts="report_objects=1:use_registers=0:use_stacks=1" %run %t 2>&1
// RUN: %env_lsan_opts="" %run %t 2>&1

#include "sanitizer_common/print_address.h"
Expand All @@ -15,4 +13,4 @@ int main() {
exit(0);
}
// CHECK: Last reference to the object(s) lost at
// CHECK: use_stacks.cpp
// CHECK: use_stacks.cpp:15:3
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Test that stacks of non-main threads are included in the root set.
// RUN: %clangxx_lsan -pthread %s -o %t
// RUN: %env_lsan_opts="report_objects=1:use_registers=0:use_stacks=0" not %run %t 2>&1 | FileCheck %s
// RUN: %env_lsan_opts="report_objects=1:use_registers=0:use_stacks=1" %run %t 2>&1
// RUN: %env_lsan_opts="" %run %t 2>&1

#include "sanitizer_common/print_address.h"
Expand Down Expand Up @@ -31,4 +29,4 @@ int main() {
return 0;
}
// CHECK: Last reference to the object(s) lost at
// CHECK: use_stacks_threaded.cpp
// CHECK: use_stacks_threaded.cpp:20:1
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Checks if a user pointer is found by the leak sanitizer.
// RUN: %clang_lsan %s -o %t
// RUN: %run %t 2>&1
// RUN: %env_lsan_opts="" not %run %t 2>&1 | FileCheck %s
// RUN: %env_lsan_opts="" %run %t 2>&1

#include <stdint.h>
#include <stdio.h>
Expand All @@ -16,4 +15,3 @@ int main() {
}
return 0;
}
// CHECK: Last reference to the object(s) lost at

0 comments on commit 063da9d

Please sign in to comment.