1
2
3
4
5 package cgotlstest
6
7
8
9
10 import "C"
11
12 import (
13 "runtime"
14 "testing"
15 )
16
17 func testTLS(t *testing.T) {
18 if skip := C.checkTLS(); skip != nil {
19 t.Skipf("%s", C.GoString(skip))
20 }
21
22 runtime.LockOSThread()
23 defer runtime.UnlockOSThread()
24
25 if val := C.getTLS(); val != 0 {
26 t.Fatalf("at start, C.getTLS() = %#x, want 0", val)
27 }
28
29 const keyVal = 0x1234
30 C.setTLS(keyVal)
31 if val := C.getTLS(); val != keyVal {
32 t.Fatalf("at end, C.getTLS() = %#x, want %#x", val, keyVal)
33 }
34 }
35
View as plain text