[compiler-rt] r208854 - [ASan tests] Add ASan Windows threading tests
Timur Iskhodzhanov
timurrrr at google.com
Thu May 15 02:12:56 PDT 2014
Author: timurrrr
Date: Thu May 15 04:12:55 2014
New Revision: 208854
URL: http://llvm.org/viewvc/llvm-project?rev=208854&view=rev
Log:
[ASan tests] Add ASan Windows threading tests
Added:
compiler-rt/trunk/test/asan/TestCases/Windows/beginthreadex.cc
compiler-rt/trunk/test/asan/TestCases/Windows/thread_simple.cc
compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_array_right_oob.cc
- copied, changed from r208807, compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc
compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_reuse.cc
compiler-rt/trunk/test/asan/TestCases/Windows/thread_stress.cc
compiler-rt/trunk/test/asan/TestCases/Windows/windows_h.cc
Modified:
compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc
Added: compiler-rt/trunk/test/asan/TestCases/Windows/beginthreadex.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/beginthreadex.cc?rev=208854&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/beginthreadex.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/beginthreadex.cc Thu May 15 04:12:55 2014
@@ -0,0 +1,21 @@
+// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %run %t
+
+#include <windows.h>
+#include <process.h>
+
+unsigned WINAPI thread_proc(void *) {
+ volatile char stack_buffer[42];
+ for (int i = 0; i < sizeof(stack_buffer); ++i)
+ stack_buffer[i] = 42;
+ return 0;
+}
+
+int main() {
+ HANDLE thr = (HANDLE)_beginthreadex(NULL, 0, thread_proc, NULL, 0, NULL);
+ if (thr == 0)
+ return 1;
+ if (WAIT_OBJECT_0 != WaitForSingleObject(thr, INFINITE))
+ return 2;
+ CloseHandle(thr);
+}
Added: compiler-rt/trunk/test/asan/TestCases/Windows/thread_simple.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/thread_simple.cc?rev=208854&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/thread_simple.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/thread_simple.cc Thu May 15 04:12:55 2014
@@ -0,0 +1,26 @@
+// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %run %t
+
+#include <windows.h>
+
+DWORD WINAPI thread_proc(void *) {
+ volatile char stack_buffer[42];
+ for (int i = 0; i < sizeof(stack_buffer); ++i)
+ stack_buffer[i] = 42;
+ return 0x42;
+}
+
+int main() {
+ DWORD exitcode;
+ HANDLE thr = CreateThread(NULL, 0, thread_proc, NULL, 0, NULL);
+ if (thr == 0)
+ return 1;
+ if (WAIT_OBJECT_0 != WaitForSingleObject(thr, INFINITE))
+ return 2;
+
+ GetExitCodeThread(thr, &exitcode);
+ if (exitcode != 0x42)
+ return 3;
+ CloseHandle(thr);
+}
+
Modified: compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc?rev=208854&r1=208853&r2=208854&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc Thu May 15 04:12:55 2014
@@ -4,7 +4,7 @@
#include <windows.h>
-DWORD WINAPI thread_proc(void *context) {
+DWORD WINAPI thread_proc(void *) {
int subscript = -1;
volatile char stack_buffer[42];
stack_buffer[subscript] = 42;
@@ -16,10 +16,13 @@ DWORD WINAPI thread_proc(void *context)
return 0;
}
-int main(void) {
+int main() {
HANDLE thr = CreateThread(NULL, 0, thread_proc, NULL, 0, NULL);
// CHECK: Thread T1 created by T0 here:
// CHECK: {{#[01] .* main .*thread_stack_array_left_oob.cc}}:[[@LINE-2]]
+
+ // A failure to create a thread should fail the test!
+ if (thr == 0) return 0;
+
WaitForSingleObject(thr, INFINITE);
- return 0;
}
Copied: compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_array_right_oob.cc (from r208807, compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_array_right_oob.cc?p2=compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_array_right_oob.cc&p1=compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc&r1=208807&r2=208854&rev=208854&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_array_right_oob.cc Thu May 15 04:12:55 2014
@@ -4,13 +4,13 @@
#include <windows.h>
-DWORD WINAPI thread_proc(void *context) {
- int subscript = -1;
+DWORD WINAPI thread_proc(void *) {
+ int subscript = 42;
volatile char stack_buffer[42];
stack_buffer[subscript] = 42;
// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
// CHECK: WRITE of size 1 at [[ADDR]] thread T1
-// CHECK: {{#0 .* thread_proc .*thread_stack_array_left_oob.cc}}:[[@LINE-3]]
+// CHECK: {{#0 .* thread_proc .*thread_stack_array_right_oob.cc}}:[[@LINE-3]]
// CHECK: Address [[ADDR]] is located in stack of thread T1 at offset {{.*}} in frame
// CHECK: thread_proc
return 0;
@@ -19,7 +19,10 @@ DWORD WINAPI thread_proc(void *context)
int main(void) {
HANDLE thr = CreateThread(NULL, 0, thread_proc, NULL, 0, NULL);
// CHECK: Thread T1 created by T0 here:
-// CHECK: {{#[01] .* main .*thread_stack_array_left_oob.cc}}:[[@LINE-2]]
+// CHECK: {{#[01] .* main .*thread_stack_array_right_oob.cc}}:[[@LINE-2]]
+
+ // A failure to create a thread should fail the test!
+ if (thr == 0) return 0;
+
WaitForSingleObject(thr, INFINITE);
- return 0;
}
Added: compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_reuse.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_reuse.cc?rev=208854&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_reuse.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/thread_stack_reuse.cc Thu May 15 04:12:55 2014
@@ -0,0 +1,37 @@
+// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %run %t
+
+#include <windows.h>
+
+DWORD WINAPI thread_proc_1(void *) {
+ volatile int x, y, z;
+ x = 1;
+ y = 2;
+ z = 3;
+ return 0;
+}
+
+DWORD WINAPI thread_proc_2(void *) {
+ volatile char stack_buffer[42];
+ for (int i = 0; i < sizeof(stack_buffer); ++i)
+ stack_buffer[i] = 42;
+ return 0;
+}
+
+int main(void) {
+ HANDLE thr = NULL;
+
+ thr = CreateThread(NULL, 0, thread_proc_1, NULL, 0, NULL);
+ if (thr == 0)
+ return 1;
+ if (WAIT_OBJECT_0 != WaitForSingleObject(thr, INFINITE))
+ return 2;
+
+ thr = CreateThread(NULL, 0, thread_proc_2, NULL, 0, NULL);
+ if (thr == 0)
+ return 3;
+ if (WAIT_OBJECT_0 != WaitForSingleObject(thr, INFINITE))
+ return 4;
+ CloseHandle(thr);
+}
+
Added: compiler-rt/trunk/test/asan/TestCases/Windows/thread_stress.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/thread_stress.cc?rev=208854&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/thread_stress.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/thread_stress.cc Thu May 15 04:12:55 2014
@@ -0,0 +1,30 @@
+// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %run %t
+
+#include <windows.h>
+
+DWORD WINAPI thread_proc(void *) {
+ volatile char stack_buffer[42];
+ for (int i = 0; i < sizeof(stack_buffer); ++i)
+ stack_buffer[i] = 42;
+ return 0;
+}
+
+int main(void) {
+ for (int iter = 0; iter < 1024; ++iter) {
+ const int NUM_THREADS = 8;
+ HANDLE thr[NUM_THREADS];
+ for (int i = 0; i < NUM_THREADS; ++i) {
+ thr[i] = CreateThread(NULL, 0, thread_proc, NULL, 0, NULL);
+ if (thr[i] == 0)
+ return 1;
+ }
+ for (int i = 0; i < NUM_THREADS; ++i) {
+ if (WAIT_OBJECT_0 != WaitForSingleObject(thr[i], INFINITE))
+ return 2;
+ CloseHandle(thr[i]);
+ }
+ }
+ return 0;
+}
+
Added: compiler-rt/trunk/test/asan/TestCases/Windows/windows_h.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/windows_h.cc?rev=208854&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/windows_h.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/windows_h.cc Thu May 15 04:12:55 2014
@@ -0,0 +1,7 @@
+// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %run %t
+
+// Just make sure we can parse <windows.h>
+#include <windows.h>
+
+int main() {}
More information about the llvm-commits
mailing list