66 lines
2.0 KiB
C
Raw Normal View History

2012-07-30 10:58:13 +00:00
//===-- test.c ------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Sanity test for Go runtime.
//
//===----------------------------------------------------------------------===//
#include <stdio.h>
void __tsan_init(void **thr, void (*cb)(void*));
2012-07-30 10:58:13 +00:00
void __tsan_fini();
2013-01-18 20:06:45 +00:00
void __tsan_map_shadow(void *addr, unsigned long size);
2013-05-27 18:27:12 +00:00
void __tsan_go_start(void *thr, void **chthr, void *pc);
void __tsan_go_end(void *thr);
void __tsan_read(void *thr, void *addr, void *pc);
void __tsan_write(void *thr, void *addr, void *pc);
void __tsan_func_enter(void *thr, void *pc);
void __tsan_func_exit(void *thr);
void __tsan_malloc(void *p, unsigned long sz);
2013-05-27 18:27:12 +00:00
void __tsan_acquire(void *thr, void *addr);
void __tsan_release(void *thr, void *addr);
void __tsan_release_merge(void *thr, void *addr);
2012-07-30 10:58:13 +00:00
void symbolize_cb(void *ctx) {}
2012-07-30 10:58:13 +00:00
char buf0[100<<10];
2012-07-30 10:58:13 +00:00
void foobar() {}
void barfoo() {}
2012-07-30 10:58:13 +00:00
int main(void) {
2013-05-27 18:27:12 +00:00
void *thr0 = 0;
char *buf = (char*)((unsigned long)buf0 + (64<<10) - 1 & ~((64<<10) - 1));
__tsan_malloc(buf, 10);
__tsan_init(&thr0, symbolize_cb);
__tsan_map_shadow(buf, 4096);
__tsan_func_enter(thr0, (char*)&main + 1);
__tsan_malloc(buf, 10);
2013-05-27 18:27:12 +00:00
__tsan_release(thr0, buf);
__tsan_release_merge(thr0, buf);
void *thr1 = 0;
__tsan_go_start(thr0, &thr1, (char*)&barfoo + 1);
void *thr2 = 0;
__tsan_go_start(thr0, &thr2, (char*)&barfoo + 1);
__tsan_func_enter(thr1, (char*)&foobar + 1);
__tsan_func_enter(thr1, (char*)&foobar + 1);
__tsan_write(thr1, buf, (char*)&barfoo + 1);
2013-05-27 18:27:12 +00:00
__tsan_acquire(thr1, buf);
__tsan_func_exit(thr1);
__tsan_func_exit(thr1);
2013-05-27 18:27:12 +00:00
__tsan_go_end(thr1);
__tsan_func_enter(thr2, (char*)&foobar + 1);
__tsan_read(thr2, buf, (char*)&barfoo + 1);
__tsan_func_exit(thr2);
__tsan_go_end(thr2);
2013-05-27 18:27:12 +00:00
__tsan_func_exit(thr0);
2012-07-30 10:58:13 +00:00
__tsan_fini();
return 0;
}