1
2
3
4
5 package abi_test
6
7 import (
8 "internal/abi"
9 "internal/testenv"
10 "os/exec"
11 "path/filepath"
12 "strings"
13 "testing"
14 )
15
16 func TestFuncPC(t *testing.T) {
17
18 pcFromAsm := abi.FuncPCTestFnAddr
19
20
21 pcFromGo := abi.FuncPCTest()
22 if pcFromGo != pcFromAsm {
23 t.Errorf("FuncPC returns wrong PC, want %x, got %x", pcFromAsm, pcFromGo)
24 }
25
26
27 pcFromGo = abi.FuncPCABI0(abi.FuncPCTestFn)
28 if pcFromGo != pcFromAsm {
29 t.Errorf("FuncPC returns wrong PC, want %x, got %x", pcFromAsm, pcFromGo)
30 }
31 }
32
33 func TestFuncPCCompileError(t *testing.T) {
34
35 testenv.MustHaveGoBuild(t)
36
37
38
39 tmpdir := t.TempDir()
40 asmSrc := filepath.Join("testdata", "x.s")
41 goSrc := filepath.Join("testdata", "x.go")
42 symabi := filepath.Join(tmpdir, "symabi")
43 obj := filepath.Join(tmpdir, "x.o")
44
45
46 cmd := exec.Command(testenv.GoToolPath(t), "tool", "asm", "-gensymabis", "-o", symabi, asmSrc)
47 out, err := cmd.CombinedOutput()
48 if err != nil {
49 t.Fatalf("go tool asm -gensymabis failed: %v\n%s", err, out)
50 }
51
52
53 cmd = exec.Command(testenv.GoToolPath(t), "tool", "compile", "-symabis", symabi, "-o", obj, goSrc)
54 out, err = cmd.CombinedOutput()
55 if err == nil {
56 t.Fatalf("go tool compile did not fail")
57 }
58
59
60 want := []string{"x.go:17", "x.go:18", "x.go:20"}
61 got := strings.Split(string(out), "\n")
62 if got[len(got)-1] == "" {
63 got = got[:len(got)-1]
64 }
65 for i, s := range got {
66 if !strings.Contains(s, want[i]) {
67 t.Errorf("did not error on line %s", want[i])
68 }
69 }
70 if len(got) != len(want) {
71 t.Errorf("unexpected number of errors, want %d, got %d", len(want), len(got))
72 }
73 if t.Failed() {
74 t.Logf("output:\n%s", string(out))
75 }
76 }
77
View as plain text