]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix "go run" cgo source when cgo is disabled
authorShenghou Ma <minux.ma@gmail.com>
Thu, 28 Feb 2013 08:07:26 +0000 (16:07 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Thu, 28 Feb 2013 08:07:26 +0000 (16:07 +0800)
also move a cgo-depend test to appropriate source file in runtime.

R=golang-dev, dave, adg, rsc
CC=golang-dev
https://golang.org/cl/7393063

src/cmd/go/run.go
src/pkg/runtime/crash_cgo_test.go
src/pkg/runtime/crash_test.go

index 27f989fb9f07ff86d4d6ed2728f3587f9c839fc1..b50569363522cc9148bf542563f584e120785848 100644 (file)
@@ -68,8 +68,16 @@ func runRun(cmd *Command, args []string) {
        var src string
        if len(p.GoFiles) > 0 {
                src = p.GoFiles[0]
-       } else {
+       } else if len(p.CgoFiles) > 0 {
                src = p.CgoFiles[0]
+       } else {
+               // this case could only happen if the provided source uses cgo
+               // while cgo is disabled.
+               hint := ""
+               if !buildContext.CgoEnabled {
+                       hint = " (cgo is disabled)"
+               }
+               fatalf("go run: no suitable source files%s", hint)
        }
        p.exeName = src[:len(src)-len(".go")] // name temporary executable for first go file
        a1 := b.action(modeBuild, modeBuild, p)
index 12b75dc1b2c97460a730196da48e9f325dfd86ea..8ccea8f37c002c6641daca2811a97e5dd3a7c4ed 100644 (file)
@@ -13,3 +13,76 @@ import (
 func TestCgoCrashHandler(t *testing.T) {
        testCrashHandler(t, true)
 }
+
+func TestCgoSignalDeadlock(t *testing.T) {
+       got := executeTest(t, cgoSignalDeadlockSource, nil)
+       want := "OK\n"
+       if got != want {
+               t.Fatalf("expected %q, but got %q", want, got)
+       }
+}
+
+const cgoSignalDeadlockSource = `
+package main
+
+import "C"
+
+import (
+       "fmt"
+       "runtime"
+       "time"
+)
+
+func main() {
+       runtime.GOMAXPROCS(100)
+       ping := make(chan bool)
+       go func() {
+               for i := 0; ; i++ {
+                       runtime.Gosched()
+                       select {
+                       case done := <-ping:
+                               if done {
+                                       ping <- true
+                                       return
+                               }
+                               ping <- true
+                       default:
+                       }
+                       func() {
+                               defer func() {
+                                       recover()
+                               }()
+                               var s *string
+                               *s = ""
+                       }()
+               }
+       }()
+       time.Sleep(time.Millisecond)
+       for i := 0; i < 64; i++ {
+               go func() {
+                       runtime.LockOSThread()
+                       select {}
+               }()
+               go func() {
+                       runtime.LockOSThread()
+                       select {}
+               }()
+               time.Sleep(time.Millisecond)
+               ping <- false
+               select {
+               case <-ping:
+               case <-time.After(time.Second):
+                       fmt.Printf("HANG\n")
+                       return
+               }
+       }
+       ping <- true
+       select {
+       case <-ping:
+       case <-time.After(time.Second):
+               fmt.Printf("HANG\n")
+               return
+       }
+       fmt.Printf("OK\n")
+}
+`
index 90a5e099a3e73dfad057c085f9f89769028711c6..b2db1d7b95c93dccf07a485e07da440497c150f4 100644 (file)
@@ -99,14 +99,6 @@ func TestLockedDeadlock2(t *testing.T) {
        testDeadlock(t, lockedDeadlockSource2)
 }
 
-func TestCgoSignalDeadlock(t *testing.T) {
-       got := executeTest(t, cgoSignalDeadlockSource, nil)
-       want := "OK\n"
-       if got != want {
-               t.Fatalf("expected %q, but got %q", want, got)
-       }
-}
-
 const crashSource = `
 package main
 
@@ -191,68 +183,3 @@ func main() {
        select {}
 }
 `
-
-const cgoSignalDeadlockSource = `
-package main
-
-import "C"
-
-import (
-       "fmt"
-       "runtime"
-       "time"
-)
-
-func main() {
-       runtime.GOMAXPROCS(100)
-       ping := make(chan bool)
-       go func() {
-               for i := 0; ; i++ {
-                       runtime.Gosched()
-                       select {
-                       case done := <-ping:
-                               if done {
-                                       ping <- true
-                                       return
-                               }
-                               ping <- true
-                       default:
-                       }
-                       func() {
-                               defer func() {
-                                       recover()
-                               }()
-                               var s *string
-                               *s = ""
-                       }()
-               }
-       }()
-       time.Sleep(time.Millisecond)
-       for i := 0; i < 64; i++ {
-               go func() {
-                       runtime.LockOSThread()
-                       select {}
-               }()
-               go func() {
-                       runtime.LockOSThread()
-                       select {}
-               }()
-               time.Sleep(time.Millisecond)
-               ping <- false
-               select {
-               case <-ping:
-               case <-time.After(time.Second):
-                       fmt.Printf("HANG\n")
-                       return
-               }
-       }
-       ping <- true
-       select {
-       case <-ping:
-       case <-time.After(time.Second):
-               fmt.Printf("HANG\n")
-               return
-       }
-       fmt.Printf("OK\n")
-}
-`