Re: [PATCH] LeakSanitizer testsuite

2014-04-11 Thread Yury Gribov

This patch adds initial set of tests and dg infrastructure for
LeakSanitizer runtime.


Are you sure we need testsuite for something that doesn't have a GCC code
generation counterpart at all?


That's a valid point. We want this in GCC because
(1) support for cross-compilation and cross-testing in LLVM LSan is much 
less mature so testing non-Intel platforms there is PITA
(2) even though the code itself is the same, the build scripts and 
compilation options are GCC-specific so it may make sense to test these


As an example of (2), we currently don't have lsan_preinit.o so static 
liblsan isn't fully supported.


We understand that these may or may not be important for other community 
members so will accept either decision.


-Y


Re: [PATCH] LeakSanitizer testsuite

2014-03-24 Thread Jakub Jelinek
On Thu, Mar 20, 2014 at 10:22:38AM +0400, Maxim Ostapenko wrote:
 Hi,
 
 This patch adds initial set of tests and dg infrastructure for
 LeakSanitizer runtime.
 
 Tested on x86_64.
 
 Ok to commit?

Are you sure we need testsuite for something that doesn't have a GCC code
generation counterpart at all?

In any case, this isn't ok for 4.9, we are too late in the development
cycle.
Perhaps it could go in during next stage1.

 --- /dev/null
 +++ b/gcc/testsuite/c-c++-common/lsan/fork.c
 @@ -0,0 +1,23 @@
 +// Test that thread local data is handled correctly after forking without 
 exec().
 +/* { dg-do run } */
 +
 +#include assert.h
 +#include stdio.h
 +#include stdlib.h
 +#include sys/wait.h
 +#include unistd.h
 +
 +__thread void *thread_local_var;

Tests using __thread should be guarded with
/* { dg-require-effective-target tls_runtime } */
Also, I wonder given the explicit uses of unistd.h if you just shouldn't
limit the test to *-*-linux* or similar.
 --- /dev/null
 +++ b/gcc/testsuite/c-c++-common/lsan/swapcontext-1.c
 @@ -0,0 +1,41 @@
 +// We can't unwind stack if we're running coroutines on heap-allocated
 +// memory. Make sure we don't report these leaks.

I guess setcontext/getcontext/makecontext is supported even on far fewer
OSes.

Jakub


[PATCH] LeakSanitizer testsuite

2014-03-20 Thread Maxim Ostapenko

Hi,

This patch adds initial set of tests and dg infrastructure for 
LeakSanitizer runtime.


Tested on x86_64.

Ok to commit?

-Maxim
2014-03-20  Max Ostapenko  m.ostape...@partner.samsung.com

	* c-c++-common/lsan/fork.c: New test.
	* c-c++-common/lsan/ignore_object.c: New test.
	* c-c++-common/lsan/ignore_object_errors.c: New test.
	* c-c++-common/lsan/large_allocation_leak.c: New test.
	* c-c++-common/lsan/leak_check_at_exit-1.c: New test.
	* c-c++-common/lsan/leak_check_at_exit-2.c: New test.
	* c-c++-common/lsan/link_turned_off.c: New test.
	* c-c++-common/lsan/pointer_to_self.c: New test.
	* c-c++-common/lsan/suppressions_default.c: New test.
	* c-c++-common/lsan/swapcontext-1.c: New test.
	* c-c++-common/lsan/swapcontext-2.c: New test.
	* c-c++-common/lsan/use_after_return.c: New test.
	* c-c++-common/lsan/use_globals_initialized.c: New test.
	* c-c++-common/lsan/use_globals_uninitialized.c: New test.
	* c-c++-common/lsan/use_stacks.c: New test.
	* c-c++-common/lsan/use_tls_static.c: New test.
	* c-c++-common/lsan/use_unaligned.c: New test.
	* g++.dg/lsan/lsan.exp: New file.
	* gcc.dg/lsan/lsan.exp: New file.
	* lib/lsan-dg.exp: New file.


diff --git a/gcc/testsuite/c-c++-common/lsan/fork.c b/gcc/testsuite/c-c++-common/lsan/fork.c
new file mode 100644
index 000..4dc9d4b
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/lsan/fork.c
@@ -0,0 +1,23 @@
+// Test that thread local data is handled correctly after forking without exec().
+/* { dg-do run } */
+
+#include assert.h
+#include stdio.h
+#include stdlib.h
+#include sys/wait.h
+#include unistd.h
+
+__thread void *thread_local_var;
+
+int main() {
+  int status = 0;
+  thread_local_var = malloc(1337);
+  pid_t pid = fork();
+  assert(pid = 0);
+  if (pid  0) {
+waitpid(pid, status, 0);
+assert(WIFEXITED(status));
+return WEXITSTATUS(status);
+  }
+  return 0;
+}
diff --git a/gcc/testsuite/c-c++-common/lsan/ignore_object.c b/gcc/testsuite/c-c++-common/lsan/ignore_object.c
new file mode 100644
index 000..d73f08b
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/lsan/ignore_object.c
@@ -0,0 +1,31 @@
+// Test for __lsan_ignore_object().
+
+/* { dg-do run } */
+/* { dg-set-target-env-var LSAN_OPTIONS report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0:verbosity=3 } */
+/* { dg-set-target-env-var ASAN_OPTIONS verbosity=3 } */
+/* { dg-shouldfail lsan } */
+
+#include stdio.h
+#include stdlib.h
+
+#ifdef __cplusplus
+extern C
+#endif
+void __lsan_ignore_object(void **p);
+
+int main() {
+  // Explicitly ignored object.
+  void **p = (void **) malloc(sizeof(void **));
+  // Transitively ignored object.
+  *p = malloc(666);
+  // Non-ignored object.
+  volatile void *q = malloc(1337);
+  fprintf(stderr, Test alloc: %p.\n, p);
+  fprintf(stderr, Test alloc_2: %p.\n, q);
+  __lsan_ignore_object(p);
+  return 0;
+}
+
+/* { dg-output Test alloc: .* } */
+/* { dg-output ignoring heap object at .* } */
+/* { dg-output SUMMARY: (Leak|Address)Sanitizer: 1337 byte\\(s\\) leaked in 1 allocation\\(s\\).* } */
diff --git a/gcc/testsuite/c-c++-common/lsan/ignore_object_errors.c b/gcc/testsuite/c-c++-common/lsan/ignore_object_errors.c
new file mode 100644
index 000..47a1cd1
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/lsan/ignore_object_errors.c
@@ -0,0 +1,25 @@
+// Test for incorrect use of __lsan_ignore_object().
+/* { dg-do run } */
+/* { dg-set-target-env-var LSAN_OPTIONS verbosity=2 } */
+
+#include stdio.h
+#include stdlib.h
+
+#ifdef __cplusplus
+extern C
+#endif
+void __lsan_ignore_object(const void *p);
+
+int main() {
+  void *p = malloc(1337);
+  fprintf(stderr, Test alloc: %p.\n, p);
+  __lsan_ignore_object(p);
+  __lsan_ignore_object(p);
+  free(p);
+  __lsan_ignore_object(p);
+  return 0;
+}
+
+/* { dg-output Test alloc: .* } */
+/* { dg-output heap object at .* is already being ignored.* } */
+/* { dg-output no heap object found at .* } */
diff --git a/gcc/testsuite/c-c++-common/lsan/large_allocation_leak.c b/gcc/testsuite/c-c++-common/lsan/large_allocation_leak.c
new file mode 100644
index 000..36511d3
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/lsan/large_allocation_leak.c
@@ -0,0 +1,19 @@
+// Test that LargeMmapAllocator's chunks aren't reachable via some internal data structure.
+/* { dg-do run } */
+/* { dg-set-target-env-var LSAN_OPTIONS report_objects=1:use_stacks=0:use_registers=0 } */
+/* { dg-shouldfail lsan } */
+
+#include stdio.h
+#include stdlib.h
+
+int main() {
+  // maxsize in primary allocator is always less than this (1  25).
+  void *large_alloc = malloc(33554432);
+  fprintf(stderr, Test alloc: %p.\n, large_alloc);
+  return 0;
+}
+
+/* { dg-output Test alloc: .* } */
+/* { dg-output Directly leaked 33554432 byte object at .* } */
+/* { dg-output LeakSanitizer: detected memory leaks.* } */
+/* { dg-output SUMMARY: (Leak|Address)Sanitizer } */
diff --git a/gcc/testsuite/c-c++-common/lsan/leak_check_at_exit-1.c b/gcc/testsuite/c-c++-common/lsan/leak_check_at_exit-1.c
new file mode 100644

[PATCH] LeakSanitizer testsuite

2014-03-13 Thread Maxim Ostapenko


On 03/13/2014 12:33 PM, Maxim Ostapenko wrote:

Hi,

This patch adds initial set of tests and dg infrastructure for 
LeakSanitizer runtime.


Tested on x86_64.

Ok to commit?

-Maxim


Fixed subject.
2014-03-13  Max Ostapenko  m.ostape...@partner.samsung.com

	* c-c++-common/lsan/fork.c: New test.
	* c-c++-common/lsan/ignore_object.c: New test.
	* c-c++-common/lsan/ignore_object_errors.c: New test.
	* c-c++-common/lsan/large_allocation_leak.c: New test.
	* c-c++-common/lsan/leak_check_at_exit-1.c: New test.
	* c-c++-common/lsan/leak_check_at_exit-2.c: New test.
	* c-c++-common/lsan/link_turned_off.c: New test.
	* c-c++-common/lsan/pointer_to_self.c: New test.
	* c-c++-common/lsan/suppressions_default.c: New test.
	* c-c++-common/lsan/swapcontext-1.c: New test.
	* c-c++-common/lsan/swapcontext-2.c: New test.
	* c-c++-common/lsan/use_after_return.c: New test.
	* c-c++-common/lsan/use_globals_initialized.c: New test.
	* c-c++-common/lsan/use_globals_uninitialized.c: New test.
	* c-c++-common/lsan/use_stacks.c: New test.
	* c-c++-common/lsan/use_tls_static.c: New test.
	* c-c++-common/lsan/use_unaligned.c: New test.
	* g++.dg/lsan/lsan.exp: New file.
	* gcc.dg/lsan/lsan.exp: New file.
	* lib/lsan-dg.exp: New file.


diff --git a/gcc/testsuite/c-c++-common/lsan/fork.c b/gcc/testsuite/c-c++-common/lsan/fork.c
new file mode 100644
index 000..4dc9d4b
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/lsan/fork.c
@@ -0,0 +1,23 @@
+// Test that thread local data is handled correctly after forking without exec().
+/* { dg-do run } */
+
+#include assert.h
+#include stdio.h
+#include stdlib.h
+#include sys/wait.h
+#include unistd.h
+
+__thread void *thread_local_var;
+
+int main() {
+  int status = 0;
+  thread_local_var = malloc(1337);
+  pid_t pid = fork();
+  assert(pid = 0);
+  if (pid  0) {
+waitpid(pid, status, 0);
+assert(WIFEXITED(status));
+return WEXITSTATUS(status);
+  }
+  return 0;
+}
diff --git a/gcc/testsuite/c-c++-common/lsan/ignore_object.c b/gcc/testsuite/c-c++-common/lsan/ignore_object.c
new file mode 100644
index 000..d73f08b
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/lsan/ignore_object.c
@@ -0,0 +1,31 @@
+// Test for __lsan_ignore_object().
+
+/* { dg-do run } */
+/* { dg-set-target-env-var LSAN_OPTIONS report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0:verbosity=3 } */
+/* { dg-set-target-env-var ASAN_OPTIONS verbosity=3 } */
+/* { dg-shouldfail lsan } */
+
+#include stdio.h
+#include stdlib.h
+
+#ifdef __cplusplus
+extern C
+#endif
+void __lsan_ignore_object(void **p);
+
+int main() {
+  // Explicitly ignored object.
+  void **p = (void **) malloc(sizeof(void **));
+  // Transitively ignored object.
+  *p = malloc(666);
+  // Non-ignored object.
+  volatile void *q = malloc(1337);
+  fprintf(stderr, Test alloc: %p.\n, p);
+  fprintf(stderr, Test alloc_2: %p.\n, q);
+  __lsan_ignore_object(p);
+  return 0;
+}
+
+/* { dg-output Test alloc: .* } */
+/* { dg-output ignoring heap object at .* } */
+/* { dg-output SUMMARY: (Leak|Address)Sanitizer: 1337 byte\\(s\\) leaked in 1 allocation\\(s\\).* } */
diff --git a/gcc/testsuite/c-c++-common/lsan/ignore_object_errors.c b/gcc/testsuite/c-c++-common/lsan/ignore_object_errors.c
new file mode 100644
index 000..47a1cd1
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/lsan/ignore_object_errors.c
@@ -0,0 +1,25 @@
+// Test for incorrect use of __lsan_ignore_object().
+/* { dg-do run } */
+/* { dg-set-target-env-var LSAN_OPTIONS verbosity=2 } */
+
+#include stdio.h
+#include stdlib.h
+
+#ifdef __cplusplus
+extern C
+#endif
+void __lsan_ignore_object(const void *p);
+
+int main() {
+  void *p = malloc(1337);
+  fprintf(stderr, Test alloc: %p.\n, p);
+  __lsan_ignore_object(p);
+  __lsan_ignore_object(p);
+  free(p);
+  __lsan_ignore_object(p);
+  return 0;
+}
+
+/* { dg-output Test alloc: .* } */
+/* { dg-output heap object at .* is already being ignored.* } */
+/* { dg-output no heap object found at .* } */
diff --git a/gcc/testsuite/c-c++-common/lsan/large_allocation_leak.c b/gcc/testsuite/c-c++-common/lsan/large_allocation_leak.c
new file mode 100644
index 000..36511d3
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/lsan/large_allocation_leak.c
@@ -0,0 +1,19 @@
+// Test that LargeMmapAllocator's chunks aren't reachable via some internal data structure.
+/* { dg-do run } */
+/* { dg-set-target-env-var LSAN_OPTIONS report_objects=1:use_stacks=0:use_registers=0 } */
+/* { dg-shouldfail lsan } */
+
+#include stdio.h
+#include stdlib.h
+
+int main() {
+  // maxsize in primary allocator is always less than this (1  25).
+  void *large_alloc = malloc(33554432);
+  fprintf(stderr, Test alloc: %p.\n, large_alloc);
+  return 0;
+}
+
+/* { dg-output Test alloc: .* } */
+/* { dg-output Directly leaked 33554432 byte object at .* } */
+/* { dg-output LeakSanitizer: detected memory leaks.* } */
+/* { dg-output SUMMARY: (Leak|Address)Sanitizer } */
diff --git a/gcc/testsuite/c-c++-common/lsan/leak_check_at_exit-1.c