1// Copyright 2013 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package cgotlstest 6 7// extern const char *checkTLS(); 8// extern void setTLS(int); 9// extern int getTLS(); 10import "C" 11 12import ( 13 "runtime" 14 "testing" 15) 16 17func 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