aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2017-01-11 15:08:08 -0800
committerKeith Randall <khr@golang.org>2017-01-13 17:31:33 +0000
commit4c4c5fc7a3248c063b279ffb3a28a12f0c6de04b (patch)
tree486f6379e882c73d2582aaeacf94036e7874e9ed
parent22689c445089501b2c9adc9b6556e2a5290d1584 (diff)
downloadgo-4c4c5fc7a3248c063b279ffb3a28a12f0c6de04b.tar.gz
go-4c4c5fc7a3248c063b279ffb3a28a12f0c6de04b.zip
misc/cgo/testplugin: test that types and itabs are unique
Make sure that the same type and itab generated in two different plugins are actually the same thing. See also CL 35115 Change-Id: I0c1ecb039d7e2bf5a601d58dfa162a435ae4ef76 Reviewed-on: https://go-review.googlesource.com/35116 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Crawshaw <crawshaw@golang.org>
-rw-r--r--misc/cgo/testplugin/src/iface/main.go46
-rw-r--r--misc/cgo/testplugin/src/iface_a/a.go17
-rw-r--r--misc/cgo/testplugin/src/iface_b/b.go17
-rw-r--r--misc/cgo/testplugin/src/iface_i/i.go17
-rwxr-xr-xmisc/cgo/testplugin/test.bash10
5 files changed, 105 insertions, 2 deletions
diff --git a/misc/cgo/testplugin/src/iface/main.go b/misc/cgo/testplugin/src/iface/main.go
new file mode 100644
index 0000000000..5e7e4d8b48
--- /dev/null
+++ b/misc/cgo/testplugin/src/iface/main.go
@@ -0,0 +1,46 @@
+// Copyright 2017 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 main
+
+import (
+ "iface_i"
+ "log"
+ "plugin"
+)
+
+func main() {
+ a, err := plugin.Open("iface_a.so")
+ if err != nil {
+ log.Fatalf(`plugin.Open("iface_a.so"): %v`, err)
+ }
+ b, err := plugin.Open("iface_b.so")
+ if err != nil {
+ log.Fatalf(`plugin.Open("iface_b.so"): %v`, err)
+ }
+
+ af, err := a.Lookup("F")
+ if err != nil {
+ log.Fatalf(`a.Lookup("F") failed: %v`, err)
+ }
+ bf, err := b.Lookup("F")
+ if err != nil {
+ log.Fatalf(`b.Lookup("F") failed: %v`, err)
+ }
+ if af.(func() interface{})() != bf.(func() interface{})() {
+ panic("empty interfaces not equal")
+ }
+
+ ag, err := a.Lookup("G")
+ if err != nil {
+ log.Fatalf(`a.Lookup("G") failed: %v`, err)
+ }
+ bg, err := b.Lookup("G")
+ if err != nil {
+ log.Fatalf(`b.Lookup("G") failed: %v`, err)
+ }
+ if ag.(func() iface_i.I)() != bg.(func() iface_i.I)() {
+ panic("nonempty interfaces not equal")
+ }
+}
diff --git a/misc/cgo/testplugin/src/iface_a/a.go b/misc/cgo/testplugin/src/iface_a/a.go
new file mode 100644
index 0000000000..29d2e27764
--- /dev/null
+++ b/misc/cgo/testplugin/src/iface_a/a.go
@@ -0,0 +1,17 @@
+// Copyright 2017 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 main
+
+import "iface_i"
+
+//go:noinline
+func F() interface{} {
+ return (*iface_i.T)(nil)
+}
+
+//go:noinline
+func G() iface_i.I {
+ return (*iface_i.T)(nil)
+}
diff --git a/misc/cgo/testplugin/src/iface_b/b.go b/misc/cgo/testplugin/src/iface_b/b.go
new file mode 100644
index 0000000000..29d2e27764
--- /dev/null
+++ b/misc/cgo/testplugin/src/iface_b/b.go
@@ -0,0 +1,17 @@
+// Copyright 2017 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 main
+
+import "iface_i"
+
+//go:noinline
+func F() interface{} {
+ return (*iface_i.T)(nil)
+}
+
+//go:noinline
+func G() iface_i.I {
+ return (*iface_i.T)(nil)
+}
diff --git a/misc/cgo/testplugin/src/iface_i/i.go b/misc/cgo/testplugin/src/iface_i/i.go
new file mode 100644
index 0000000000..31c80387c7
--- /dev/null
+++ b/misc/cgo/testplugin/src/iface_i/i.go
@@ -0,0 +1,17 @@
+// Copyright 2017 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 iface_i
+
+type I interface {
+ M()
+}
+
+type T struct {
+}
+
+func (t *T) M() {
+}
+
+// *T implements I
diff --git a/misc/cgo/testplugin/test.bash b/misc/cgo/testplugin/test.bash
index fee99a758c..584b83c744 100755
--- a/misc/cgo/testplugin/test.bash
+++ b/misc/cgo/testplugin/test.bash
@@ -15,8 +15,8 @@ goos=$(go env GOOS)
goarch=$(go env GOARCH)
function cleanup() {
- rm -f plugin*.so unnamed*.so
- rm -rf host pkg sub
+ rm -f plugin*.so unnamed*.so iface*.so
+ rm -rf host pkg sub iface
}
trap cleanup EXIT
@@ -32,3 +32,9 @@ GOPATH=$(pwd) go build -buildmode=plugin unnamed2.go
GOPATH=$(pwd) go build host
LD_LIBRARY_PATH=$(pwd) ./host
+
+# Test that types and itabs get properly uniqified.
+GOPATH=$(pwd) go build -buildmode=plugin iface_a
+GOPATH=$(pwd) go build -buildmode=plugin iface_b
+GOPATH=$(pwd) go build iface
+LD_LIBRARY_PATH=$(pwd) ./iface