summaryrefslogtreecommitdiff
path: root/libgo/misc/cgo
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2018-01-27 23:44:29 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2018-01-27 23:44:29 +0000
commitd779dffc4b6ec69cb51b426f779eca4bc37fd063 (patch)
treec305b88e41d468affc247b4f066bc9340fb2209e /libgo/misc/cgo
parentace36c8bcc112f1ecf889f413e22df5a41ed3e87 (diff)
libgo: update to Go1.10rc1
Reviewed-on: https://go-review.googlesource.com/90295 From-SVN: r257126
Diffstat (limited to 'libgo/misc/cgo')
-rw-r--r--libgo/misc/cgo/errors/ptr_test.go8
-rw-r--r--libgo/misc/cgo/testcarchive/carchive_test.go47
-rw-r--r--libgo/misc/cgo/testcshared/cshared_test.go117
-rw-r--r--libgo/misc/cgo/testshared/shared_test.go5
4 files changed, 168 insertions, 9 deletions
diff --git a/libgo/misc/cgo/errors/ptr_test.go b/libgo/misc/cgo/errors/ptr_test.go
index d295a5849db..fe8dfff1d89 100644
--- a/libgo/misc/cgo/errors/ptr_test.go
+++ b/libgo/misc/cgo/errors/ptr_test.go
@@ -349,6 +349,14 @@ var ptrTests = []ptrTest{
body: `var wg sync.WaitGroup; wg.Add(100); for i := 0; i < 100; i++ { go func(i int) { for j := 0; j < 100; j++ { C.f(); runtime.GOMAXPROCS(i) }; wg.Done() }(i) }; wg.Wait()`,
fail: false,
},
+ {
+ // Test poller deadline with cgocheck=2. Issue #23435.
+ name: "deadline",
+ c: `#define US 10`,
+ imports: []string{"os", "time"},
+ body: `r, _, _ := os.Pipe(); r.SetDeadline(time.Now().Add(C.US * time.Microsecond))`,
+ fail: false,
+ },
}
func TestPointerChecks(t *testing.T) {
diff --git a/libgo/misc/cgo/testcarchive/carchive_test.go b/libgo/misc/cgo/testcarchive/carchive_test.go
index e3f67955802..4a8cc0f077b 100644
--- a/libgo/misc/cgo/testcarchive/carchive_test.go
+++ b/libgo/misc/cgo/testcarchive/carchive_test.go
@@ -695,3 +695,50 @@ func TestCompileWithoutShared(t *testing.T) {
t.Logf("%s", out)
expectSignal(t, err, syscall.SIGPIPE)
}
+
+// Test that installing a second time recreates the header files.
+func TestCachedInstall(t *testing.T) {
+ defer os.RemoveAll("pkg")
+
+ h1 := filepath.Join("pkg", libgodir, "libgo.h")
+ h2 := filepath.Join("pkg", libgodir, "p.h")
+
+ buildcmd := []string{"go", "install", "-i", "-buildmode=c-archive", "libgo"}
+
+ cmd := exec.Command(buildcmd[0], buildcmd[1:]...)
+ cmd.Env = gopathEnv
+ t.Log(buildcmd)
+ if out, err := cmd.CombinedOutput(); err != nil {
+ t.Logf("%s", out)
+ t.Fatal(err)
+ }
+
+ if _, err := os.Stat(h1); err != nil {
+ t.Errorf("libgo.h not installed: %v", err)
+ }
+ if _, err := os.Stat(h2); err != nil {
+ t.Errorf("p.h not installed: %v", err)
+ }
+
+ if err := os.Remove(h1); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Remove(h2); err != nil {
+ t.Fatal(err)
+ }
+
+ cmd = exec.Command(buildcmd[0], buildcmd[1:]...)
+ cmd.Env = gopathEnv
+ t.Log(buildcmd)
+ if out, err := cmd.CombinedOutput(); err != nil {
+ t.Logf("%s", out)
+ t.Fatal(err)
+ }
+
+ if _, err := os.Stat(h1); err != nil {
+ t.Errorf("libgo.h not installed in second run: %v", err)
+ }
+ if _, err := os.Stat(h2); err != nil {
+ t.Errorf("p.h not installed in second run: %v", err)
+ }
+}
diff --git a/libgo/misc/cgo/testcshared/cshared_test.go b/libgo/misc/cgo/testcshared/cshared_test.go
index 49be0923966..e43422de6e6 100644
--- a/libgo/misc/cgo/testcshared/cshared_test.go
+++ b/libgo/misc/cgo/testcshared/cshared_test.go
@@ -7,6 +7,7 @@ package cshared_test
import (
"debug/elf"
"fmt"
+ "io/ioutil"
"log"
"os"
"os/exec"
@@ -55,7 +56,8 @@ func TestMain(m *testing.M) {
androiddir = fmt.Sprintf("/data/local/tmp/testcshared-%d", os.Getpid())
if GOOS == "android" {
- cmd := exec.Command("adb", "shell", "mkdir", "-p", androiddir)
+ args := append(adbCmd(), "shell", "mkdir", "-p", androiddir)
+ cmd := exec.Command(args[0], args[1:]...)
out, err := cmd.CombinedOutput()
if err != nil {
log.Fatalf("setupAndroid failed: %v\n%s\n", err, out)
@@ -154,11 +156,19 @@ func cmdToRun(name string) string {
return "./" + name + exeSuffix
}
+func adbCmd() []string {
+ cmd := []string{"adb"}
+ if flags := os.Getenv("GOANDROID_ADB_FLAGS"); flags != "" {
+ cmd = append(cmd, strings.Split(flags, " ")...)
+ }
+ return cmd
+}
+
func adbPush(t *testing.T, filename string) {
if GOOS != "android" {
return
}
- args := []string{"adb", "push", filename, fmt.Sprintf("%s/%s", androiddir, filename)}
+ args := append(adbCmd(), "push", filename, fmt.Sprintf("%s/%s", androiddir, filename))
cmd := exec.Command(args[0], args[1:]...)
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("adb command failed: %v\n%s\n", err, out)
@@ -169,7 +179,7 @@ func adbRun(t *testing.T, env []string, adbargs ...string) string {
if GOOS != "android" {
t.Fatalf("trying to run adb command when operating system is not android.")
}
- args := []string{"adb", "shell"}
+ args := append(adbCmd(), "shell")
// Propagate LD_LIBRARY_PATH to the adb shell invocation.
for _, e := range env {
if strings.Index(e, "LD_LIBRARY_PATH=") != -1 {
@@ -237,7 +247,7 @@ func createHeaders() error {
}
if GOOS == "android" {
- args = []string{"adb", "push", libgoname, fmt.Sprintf("%s/%s", androiddir, libgoname)}
+ args = append(adbCmd(), "push", libgoname, fmt.Sprintf("%s/%s", androiddir, libgoname))
cmd = exec.Command(args[0], args[1:]...)
out, err = cmd.CombinedOutput()
if err != nil {
@@ -270,7 +280,8 @@ func cleanupAndroid() {
if GOOS != "android" {
return
}
- cmd := exec.Command("adb", "shell", "rm", "-rf", androiddir)
+ args := append(adbCmd(), "shell", "rm", "-rf", androiddir)
+ cmd := exec.Command(args[0], args[1:]...)
out, err := cmd.CombinedOutput()
if err != nil {
log.Fatalf("cleanupAndroid failed: %v\n%s\n", err, out)
@@ -477,3 +488,99 @@ func TestPIE(t *testing.T) {
}
}
}
+
+// Test that installing a second time recreates the header files.
+func TestCachedInstall(t *testing.T) {
+ tmpdir, err := ioutil.TempDir("", "cshared")
+ if err != nil {
+ t.Fatal(err)
+ }
+ // defer os.RemoveAll(tmpdir)
+
+ copyFile(t, filepath.Join(tmpdir, "src", "libgo", "libgo.go"), filepath.Join("src", "libgo", "libgo.go"))
+ copyFile(t, filepath.Join(tmpdir, "src", "p", "p.go"), filepath.Join("src", "p", "p.go"))
+
+ env := append(os.Environ(), "GOPATH="+tmpdir)
+
+ buildcmd := []string{"go", "install", "-x", "-i", "-buildmode=c-shared", "-installsuffix", "testcshared", "libgo"}
+
+ cmd := exec.Command(buildcmd[0], buildcmd[1:]...)
+ cmd.Env = env
+ t.Log(buildcmd)
+ out, err := cmd.CombinedOutput()
+ t.Logf("%s", out)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ var libgoh, ph string
+
+ walker := func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ t.Fatal(err)
+ }
+ var ps *string
+ switch filepath.Base(path) {
+ case "libgo.h":
+ ps = &libgoh
+ case "p.h":
+ ps = &ph
+ }
+ if ps != nil {
+ if *ps != "" {
+ t.Fatalf("%s found again", *ps)
+ }
+ *ps = path
+ }
+ return nil
+ }
+
+ if err := filepath.Walk(tmpdir, walker); err != nil {
+ t.Fatal(err)
+ }
+
+ if libgoh == "" {
+ t.Fatal("libgo.h not installed")
+ }
+ if ph == "" {
+ t.Fatal("p.h not installed")
+ }
+
+ if err := os.Remove(libgoh); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Remove(ph); err != nil {
+ t.Fatal(err)
+ }
+
+ cmd = exec.Command(buildcmd[0], buildcmd[1:]...)
+ cmd.Env = env
+ t.Log(buildcmd)
+ out, err = cmd.CombinedOutput()
+ t.Logf("%s", out)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if _, err := os.Stat(libgoh); err != nil {
+ t.Errorf("libgo.h not installed in second run: %v", err)
+ }
+ if _, err := os.Stat(ph); err != nil {
+ t.Errorf("p.h not installed in second run: %v", err)
+ }
+}
+
+// copyFile copies src to dst.
+func copyFile(t *testing.T, dst, src string) {
+ t.Helper()
+ data, err := ioutil.ReadFile(src)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := os.MkdirAll(filepath.Dir(dst), 0777); err != nil {
+ t.Fatal(err)
+ }
+ if err := ioutil.WriteFile(dst, data, 0666); err != nil {
+ t.Fatal(err)
+ }
+}
diff --git a/libgo/misc/cgo/testshared/shared_test.go b/libgo/misc/cgo/testshared/shared_test.go
index f1e8f0605b6..cf049ec35b8 100644
--- a/libgo/misc/cgo/testshared/shared_test.go
+++ b/libgo/misc/cgo/testshared/shared_test.go
@@ -351,10 +351,10 @@ func readNotes(f *elf.File) ([]*note, error) {
func dynStrings(t *testing.T, path string, flag elf.DynTag) []string {
f, err := elf.Open(path)
- defer f.Close()
if err != nil {
t.Fatalf("elf.Open(%q) failed: %v", path, err)
}
+ defer f.Close()
dynstrings, err := f.DynString(flag)
if err != nil {
t.Fatalf("DynString(%s) failed on %s: %v", flag, path, err)
@@ -598,7 +598,6 @@ func TestThreeGopathShlibs(t *testing.T) {
// If gccgo is not available or not new enough call t.Skip. Otherwise,
// return a build.Context that is set up for gccgo.
func prepGccgo(t *testing.T) build.Context {
- t.Skip("golang.org/issue/22472")
gccgoName := os.Getenv("GCCGO")
if gccgoName == "" {
gccgoName = "gccgo"
@@ -648,8 +647,6 @@ func TestGoPathShlibGccgo(t *testing.T) {
// library with gccgo, another GOPATH package that depends on the first and an
// executable that links the second library.
func TestTwoGopathShlibsGccgo(t *testing.T) {
- t.Skip("golang.org/issue/22224")
-
gccgoContext := prepGccgo(t)
libgoRE := regexp.MustCompile("libgo.so.[0-9]+")