github.com/rsc/go@v0.0.0-20150416155037-e040fd465409/test/fixedbugs/issue9355.go (about)

     1  // run
     2  
     3  // Copyright 2014 The Go Authors.  All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package main
     8  
     9  import (
    10  	"fmt"
    11  	"go/build"
    12  	"os"
    13  	"os/exec"
    14  	"path/filepath"
    15  	"regexp"
    16  	"runtime"
    17  )
    18  
    19  func main() {
    20  	if runtime.Compiler != "gc" || runtime.GOOS == "nacl" {
    21  		return
    22  	}
    23  	a, err := build.ArchChar(runtime.GOARCH)
    24  	check(err)
    25  
    26  	err = os.Chdir(filepath.Join("fixedbugs", "issue9355.dir"))
    27  	check(err)
    28  
    29  	out := run("go", "tool", a+"g", "-S", "a.go")
    30  	os.Remove("a." + a)
    31  
    32  	// 6g/8g print the offset as dec, but 5g/9g print the offset as hex.
    33  	patterns := []string{
    34  		`rel 0\+\d t=1 \"\"\.x\+8\r?\n`,       // y = &x.b
    35  		`rel 0\+\d t=1 \"\"\.x\+(28|1c)\r?\n`, // z = &x.d.q
    36  		`rel 0\+\d t=1 \"\"\.b\+5\r?\n`,       // c = &b[5]
    37  		`rel 0\+\d t=1 \"\"\.x\+(88|58)\r?\n`, // w = &x.f[3].r
    38  	}
    39  	for _, p := range patterns {
    40  		if ok, err := regexp.Match(p, out); !ok || err != nil {
    41  			println(string(out))
    42  			panic("can't find pattern " + p)
    43  		}
    44  	}
    45  }
    46  
    47  func run(cmd string, args ...string) []byte {
    48  	out, err := exec.Command(cmd, args...).CombinedOutput()
    49  	if err != nil {
    50  		fmt.Println(string(out))
    51  		fmt.Println(err)
    52  		os.Exit(1)
    53  	}
    54  	return out
    55  }
    56  
    57  func check(err error) {
    58  	if err != nil {
    59  		fmt.Println("BUG:", err)
    60  		os.Exit(1)
    61  	}
    62  }