github.com/d4l3k/go@v0.0.0-20151015000803-65fc379daeda/src/cmd/newlink/layout_test.go (about)

     1  // Copyright 2014 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
     6  
     7  import (
     8  	"bytes"
     9  	"strings"
    10  	"testing"
    11  )
    12  
    13  func TestLayout(t *testing.T) {
    14  	p := Prog{GOOS: "darwin", GOARCH: "amd64", StartSym: "text_start"}
    15  	p.omitRuntime = true
    16  	p.Error = func(s string) { t.Error(s) }
    17  	var buf bytes.Buffer
    18  	const obj = "testdata/layout.6"
    19  	p.link(&buf, obj)
    20  	if p.NumError > 0 {
    21  		return // already reported
    22  	}
    23  	if len(p.Dead) > 0 {
    24  		t.Errorf("%s: unexpected dead symbols %v", obj, p.Dead)
    25  		return
    26  	}
    27  
    28  	for _, sym := range p.SymOrder {
    29  		if p.isAuto(sym.SymID) {
    30  			continue
    31  		}
    32  		if sym.Section == nil {
    33  			t.Errorf("%s: symbol %s is missing section", obj, sym)
    34  			continue
    35  		}
    36  		i := strings.Index(sym.Name, "_")
    37  		if i < 0 {
    38  			t.Errorf("%s: unexpected symbol %s", obj, sym)
    39  			continue
    40  		}
    41  		if sym.Section.Name != sym.Name[:i] {
    42  			t.Errorf("%s: symbol %s in section %s, want %s", obj, sym, sym.Section.Name, sym.Name[:i])
    43  		}
    44  	}
    45  }