1 //===-- test.c ------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Sanity test for Go runtime.
12 //===----------------------------------------------------------------------===//
17 void __tsan_init(void **thr, void **proc, void (*cb)(long, void*));
19 void __tsan_map_shadow(void *addr, unsigned long size);
20 void __tsan_go_start(void *thr, void **chthr, void *pc);
21 void __tsan_go_end(void *thr);
22 void __tsan_proc_create(void **pproc);
23 void __tsan_proc_destroy(void *proc);
24 void __tsan_proc_wire(void *proc, void *thr);
25 void __tsan_proc_unwire(void *proc, void *thr);
26 void __tsan_read(void *thr, void *addr, void *pc);
27 void __tsan_write(void *thr, void *addr, void *pc);
28 void __tsan_func_enter(void *thr, void *pc);
29 void __tsan_func_exit(void *thr);
30 void __tsan_malloc(void *thr, void *pc, void *p, unsigned long sz);
31 void __tsan_free(void *p, unsigned long sz);
32 void __tsan_acquire(void *thr, void *addr);
33 void __tsan_release(void *thr, void *addr);
34 void __tsan_release_merge(void *thr, void *addr);
38 void symbolize_cb(long cmd, void *ctx) {
41 if (current_proc == 0)
43 *(void**)ctx = current_proc;
55 __tsan_init(&thr0, &proc0, symbolize_cb);
57 char *buf = (char*)((unsigned long)buf0 + (64<<10) - 1 & ~((64<<10) - 1));
58 __tsan_map_shadow(buf, 4096);
59 __tsan_malloc(thr0, (char*)&barfoo + 1, buf, 10);
61 __tsan_func_enter(thr0, (char*)&main + 1);
62 __tsan_malloc(thr0, (char*)&barfoo + 1, buf, 10);
63 __tsan_release(thr0, buf);
64 __tsan_release_merge(thr0, buf);
66 __tsan_go_start(thr0, &thr1, (char*)&barfoo + 1);
68 __tsan_go_start(thr0, &thr2, (char*)&barfoo + 1);
69 __tsan_func_exit(thr0);
70 __tsan_func_enter(thr1, (char*)&foobar + 1);
71 __tsan_func_enter(thr1, (char*)&foobar + 1);
72 __tsan_write(thr1, buf, (char*)&barfoo + 1);
73 __tsan_acquire(thr1, buf);
74 __tsan_func_exit(thr1);
75 __tsan_func_exit(thr1);
78 __tsan_proc_create(&proc1);
80 __tsan_func_enter(thr2, (char*)&foobar + 1);
81 __tsan_read(thr2, buf, (char*)&barfoo + 1);
83 __tsan_func_exit(thr2);
85 __tsan_proc_destroy(proc1);