summaryrefslogtreecommitdiff
path: root/misc/cgo
diff options
context:
space:
mode:
Diffstat (limited to 'misc/cgo')
-rw-r--r--misc/cgo/life/Makefile14
-rw-r--r--misc/cgo/test/Makefile1
-rw-r--r--misc/cgo/test/basic.go12
-rw-r--r--misc/cgo/test/callback.go2
-rw-r--r--misc/cgo/test/cgo_test.go3
-rw-r--r--misc/cgo/test/helpers.go35
6 files changed, 66 insertions, 1 deletions
diff --git a/misc/cgo/life/Makefile b/misc/cgo/life/Makefile
index 5a10380ed..39ec13be2 100644
--- a/misc/cgo/life/Makefile
+++ b/misc/cgo/life/Makefile
@@ -11,6 +11,20 @@ CGOFILES=\
CGO_OFILES=\
c-life.o\
+
+ifeq ($(GOOS),windows)
+ifeq ($(GOARCH),amd64)
+CGO_OFILES+=\
+ lib64_libmingwex_a-wassert.o\
+ lib64_libmingw32_a-mingw_helpers.o\
+
+lib64_libmingwex_a-wassert.o:
+ ar -x /mingw/x86_64-w64-mingw32/lib/libmingwex.a lib64_libmingwex_a-wassert.o
+
+lib64_libmingw32_a-mingw_helpers.o:
+ ar -x /mingw/x86_64-w64-mingw32/lib/libmingw32.a lib64_libmingw32_a-mingw_helpers.o
+endif
+endif
CLEANFILES+=life
diff --git a/misc/cgo/test/Makefile b/misc/cgo/test/Makefile
index d4309be3c..5617e78c3 100644
--- a/misc/cgo/test/Makefile
+++ b/misc/cgo/test/Makefile
@@ -12,6 +12,7 @@ CGOFILES=\
callback.go\
env.go\
exports.go\
+ helpers.go\
issue1222.go\
issue1328.go\
issue1560.go\
diff --git a/misc/cgo/test/basic.go b/misc/cgo/test/basic.go
index b9d0953bd..626e0e91b 100644
--- a/misc/cgo/test/basic.go
+++ b/misc/cgo/test/basic.go
@@ -48,6 +48,10 @@ struct ibv_async_event {
struct ibv_context {
xxpthread_mutex_t mutex;
};
+
+int add(int x, int y) {
+ return x+y;
+};
*/
import "C"
import (
@@ -132,3 +136,11 @@ var (
type Context struct {
ctx *C.struct_ibv_context
}
+
+func benchCgoCall(b *testing.B) {
+ const x = C.int(2)
+ const y = C.int(3)
+ for i := 0; i < b.N; i++ {
+ C.add(x, y)
+ }
+}
diff --git a/misc/cgo/test/callback.go b/misc/cgo/test/callback.go
index 3edee9758..d20790e87 100644
--- a/misc/cgo/test/callback.go
+++ b/misc/cgo/test/callback.go
@@ -65,7 +65,7 @@ func testCallbackPanic(t *testing.T) {
func testCallbackPanicLoop(t *testing.T) {
// Make sure we don't blow out m->g0 stack.
for i := 0; i < 100000; i++ {
- TestCallbackPanic(t)
+ testCallbackPanic(t)
}
}
diff --git a/misc/cgo/test/cgo_test.go b/misc/cgo/test/cgo_test.go
index 94fba15db..34beee69d 100644
--- a/misc/cgo/test/cgo_test.go
+++ b/misc/cgo/test/cgo_test.go
@@ -26,3 +26,6 @@ func TestBlocking(t *testing.T) { testBlocking(t) }
func Test1328(t *testing.T) { test1328(t) }
func TestParallelSleep(t *testing.T) { testParallelSleep(t) }
func TestSetEnv(t *testing.T) { testSetEnv(t) }
+func TestHelpers(t *testing.T) { testHelpers(t) }
+
+func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }
diff --git a/misc/cgo/test/helpers.go b/misc/cgo/test/helpers.go
new file mode 100644
index 000000000..de14d19ab
--- /dev/null
+++ b/misc/cgo/test/helpers.go
@@ -0,0 +1,35 @@
+// Copyright 2011 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
+
+// const char *greeting = "hello, world";
+import "C"
+
+import (
+ "reflect"
+ "testing"
+ "unsafe"
+)
+
+const greeting = "hello, world"
+
+type testPair struct {
+ Name string
+ Got, Want interface{}
+}
+
+var testPairs = []testPair{
+ {"GoString", C.GoString(C.greeting), greeting},
+ {"GoStringN", C.GoStringN(C.greeting, 5), greeting[:5]},
+ {"GoBytes", C.GoBytes(unsafe.Pointer(C.greeting), 5), []byte(greeting[:5])},
+}
+
+func testHelpers(t *testing.T) {
+ for _, pair := range testPairs {
+ if !reflect.DeepEqual(pair.Got, pair.Want) {
+ t.Errorf("%s: got %#v, want %#v", pair.Got, pair.Want)
+ }
+ }
+}