]> Cypherpunks repositories - gostls13.git/commitdiff
misc/cgo/testplugin: test that types and itabs are unique
authorKeith Randall <khr@golang.org>
Wed, 11 Jan 2017 23:08:08 +0000 (15:08 -0800)
committerKeith Randall <khr@golang.org>
Fri, 13 Jan 2017 17:31:33 +0000 (17:31 +0000)
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>
misc/cgo/testplugin/src/iface/main.go [new file with mode: 0644]
misc/cgo/testplugin/src/iface_a/a.go [new file with mode: 0644]
misc/cgo/testplugin/src/iface_b/b.go [new file with mode: 0644]
misc/cgo/testplugin/src/iface_i/i.go [new file with mode: 0644]
misc/cgo/testplugin/test.bash

diff --git a/misc/cgo/testplugin/src/iface/main.go b/misc/cgo/testplugin/src/iface/main.go
new file mode 100644 (file)
index 0000000..5e7e4d8
--- /dev/null
@@ -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 (file)
index 0000000..29d2e27
--- /dev/null
@@ -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 (file)
index 0000000..29d2e27
--- /dev/null
@@ -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 (file)
index 0000000..31c8038
--- /dev/null
@@ -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
index fee99a758c0c0aea6cd81efe760b9349631e993b..584b83c744d261e34f07f7795135197716670e07 100755 (executable)
@@ -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