github.com/mdempsky/go@v0.0.0-20151201204031-5dd372bd1e70/src/cmd/go/note_test.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main_test 6 7 import ( 8 main "cmd/go" 9 "runtime" 10 "testing" 11 ) 12 13 func TestNoteReading(t *testing.T) { 14 testNoteReading(t) 15 } 16 17 func TestNoteReading2K(t *testing.T) { 18 if runtime.GOOS == "windows" { 19 t.Skipf("2kB is not enough on %s", runtime.GOOS) 20 } 21 // Set BuildIDReadSize to 2kB to exercise Mach-O parsing more strictly. 22 defer func(old int) { 23 main.BuildIDReadSize = old 24 }(main.BuildIDReadSize) 25 main.BuildIDReadSize = 2 * 1024 26 27 testNoteReading(t) 28 } 29 30 func testNoteReading(t *testing.T) { 31 if runtime.GOOS == "dragonfly" { 32 t.Skipf("TestNoteReading is broken on dragonfly - golang.org/issue/13364", runtime.GOOS) 33 } 34 tg := testgo(t) 35 defer tg.cleanup() 36 tg.tempFile("hello.go", `package main; func main() { print("hello, world\n") }`) 37 const buildID = "TestNoteReading-Build-ID" 38 tg.run("build", "-ldflags", "-buildid="+buildID, "-o", tg.path("hello.exe"), tg.path("hello.go")) 39 id, err := main.ReadBuildIDFromBinary(tg.path("hello.exe")) 40 if err != nil { 41 t.Fatalf("reading build ID from hello binary: %v", err) 42 } 43 if id != buildID { 44 t.Fatalf("buildID in hello binary = %q, want %q", id, buildID) 45 } 46 47 switch { 48 case runtime.GOOS == "linux" && (runtime.GOARCH == "ppc64le" || runtime.GOARCH == "ppc64"): 49 t.Skipf("skipping - external linking not supported, golang.org/issue/11184") 50 case runtime.GOOS == "linux" && (runtime.GOARCH == "mips64le" || runtime.GOARCH == "mips64"): 51 t.Skipf("skipping - external linking not supported, golang.org/issue/12560") 52 case runtime.GOOS == "openbsd" && runtime.GOARCH == "arm": 53 t.Skipf("skipping - external linking not supported, golang.org/issue/10619") 54 case runtime.GOOS == "plan9": 55 t.Skipf("skipping - external linking not supported") 56 } 57 58 tg.run("build", "-ldflags", "-buildid="+buildID+" -linkmode=external", "-o", tg.path("hello.exe"), tg.path("hello.go")) 59 id, err = main.ReadBuildIDFromBinary(tg.path("hello.exe")) 60 if err != nil { 61 t.Fatalf("reading build ID from hello binary (linkmode=external): %v", err) 62 } 63 if id != buildID { 64 t.Fatalf("buildID in hello binary = %q, want %q (linkmode=external)", id, buildID) 65 } 66 }