diff options
Diffstat (limited to 'misc/cgo/test/cthread.go')
-rw-r--r-- | misc/cgo/test/cthread.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/misc/cgo/test/cthread.go b/misc/cgo/test/cthread.go new file mode 100644 index 000000000..d918d033f --- /dev/null +++ b/misc/cgo/test/cthread.go @@ -0,0 +1,44 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package cgotest + +// extern void doAdd(int, int); +import "C" + +import ( + "runtime" + "sync" + "testing" +) + +var sum struct { + sync.Mutex + i int +} + +//export Add +func Add(x int) { + defer func() { + recover() + }() + sum.Lock() + sum.i += x + sum.Unlock() + var p *int + *p = 2 +} + +func testCthread(t *testing.T) { + if runtime.GOARCH == "arm" { + t.Skip("testCthread disabled on arm") + } + + C.doAdd(10, 6) + + want := 10 * (10 - 1) / 2 * 6 + if sum.i != want { + t.Fatalf("sum=%d, want %d", sum.i, want) + } +} |