1 //===-- test.c ------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Sanity test for Go runtime.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include <stdio.h>
15
16 void __tsan_init(void **thr, void (*cb)(void*));
17 void __tsan_fini();
18 void __tsan_map_shadow(void *addr, unsigned long size);
19 void __tsan_go_start(void *thr, void **chthr, void *pc);
20 void __tsan_go_end(void *thr);
21 void __tsan_read(void *thr, void *addr, void *pc);
22 void __tsan_write(void *thr, void *addr, void *pc);
23 void __tsan_func_enter(void *thr, void *pc);
24 void __tsan_func_exit(void *thr);
25 void __tsan_malloc(void *p, unsigned long sz);
26 void __tsan_acquire(void *thr, void *addr);
27 void __tsan_release(void *thr, void *addr);
28 void __tsan_release_merge(void *thr, void *addr);
29
symbolize_cb(void * ctx)30 void symbolize_cb(void *ctx) {}
31
32 char buf0[100<<10];
33
foobar()34 void foobar() {}
barfoo()35 void barfoo() {}
36
main(void)37 int main(void) {
38 void *thr0 = 0;
39 char *buf = (char*)((unsigned long)buf0 + (64<<10) - 1 & ~((64<<10) - 1));
40 __tsan_malloc(buf, 10);
41 __tsan_init(&thr0, symbolize_cb);
42 __tsan_map_shadow(buf, 4096);
43 __tsan_func_enter(thr0, (char*)&main + 1);
44 __tsan_malloc(buf, 10);
45 __tsan_release(thr0, buf);
46 __tsan_release_merge(thr0, buf);
47 void *thr1 = 0;
48 __tsan_go_start(thr0, &thr1, (char*)&barfoo + 1);
49 void *thr2 = 0;
50 __tsan_go_start(thr0, &thr2, (char*)&barfoo + 1);
51 __tsan_func_enter(thr1, (char*)&foobar + 1);
52 __tsan_func_enter(thr1, (char*)&foobar + 1);
53 __tsan_write(thr1, buf, (char*)&barfoo + 1);
54 __tsan_acquire(thr1, buf);
55 __tsan_func_exit(thr1);
56 __tsan_func_exit(thr1);
57 __tsan_go_end(thr1);
58 __tsan_func_enter(thr2, (char*)&foobar + 1);
59 __tsan_read(thr2, buf, (char*)&barfoo + 1);
60 __tsan_func_exit(thr2);
61 __tsan_go_end(thr2);
62 __tsan_func_exit(thr0);
63 __tsan_fini();
64 return 0;
65 }
66