summaryrefslogtreecommitdiff
path: root/libgo/go/debug/gosym/pclntab_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/debug/gosym/pclntab_test.go')
-rw-r--r--libgo/go/debug/gosym/pclntab_test.go98
1 files changed, 88 insertions, 10 deletions
diff --git a/libgo/go/debug/gosym/pclntab_test.go b/libgo/go/debug/gosym/pclntab_test.go
index 7347139b5df..d690a1e3f2d 100644
--- a/libgo/go/debug/gosym/pclntab_test.go
+++ b/libgo/go/debug/gosym/pclntab_test.go
@@ -29,6 +29,10 @@ func dotest(t *testing.T) {
if runtime.GOARCH != "amd64" {
t.Skipf("skipping on non-AMD64 system %s", runtime.GOARCH)
}
+ // This test builds a Linux/AMD64 binary. Skipping in short mode if cross compiling.
+ if runtime.GOOS != "linux" && testing.Short() {
+ t.Skipf("skipping in short mode on non-Linux system %s", runtime.GOARCH)
+ }
var err error
pclineTempDir, err = os.MkdirTemp("", "pclinetest")
if err != nil {
@@ -198,9 +202,6 @@ func TestLineAline(t *testing.T) {
}
func TestPCLine(t *testing.T) {
- if testing.Short() {
- t.Skip("skipping in -short mode")
- }
dotest(t)
defer endtest()
@@ -267,7 +268,8 @@ func TestPCLine(t *testing.T) {
}
}
-// Test that we can parse a pclntab from 1.15.
+// read115Executable returns a hello world executable compiled by Go 1.15.
+//
// The file was compiled in /tmp/hello.go:
// [BEGIN]
// package main
@@ -276,25 +278,30 @@ func TestPCLine(t *testing.T) {
// println("hello")
// }
// [END]
-func Test115PclnParsing(t *testing.T) {
+func read115Executable(tb testing.TB) []byte {
zippedDat, err := os.ReadFile("testdata/pcln115.gz")
if err != nil {
- t.Fatal(err)
+ tb.Fatal(err)
}
var gzReader *gzip.Reader
gzReader, err = gzip.NewReader(bytes.NewBuffer(zippedDat))
if err != nil {
- t.Fatal(err)
+ tb.Fatal(err)
}
var dat []byte
dat, err = io.ReadAll(gzReader)
if err != nil {
- t.Fatal(err)
+ tb.Fatal(err)
}
+ return dat
+}
+
+// Test that we can parse a pclntab from 1.15.
+func Test115PclnParsing(t *testing.T) {
+ dat := read115Executable(t)
const textStart = 0x1001000
pcln := NewLineTable(dat, textStart)
- var tab *Table
- tab, err = NewTable(nil, pcln)
+ tab, err := NewTable(nil, pcln)
if err != nil {
t.Fatal(err)
}
@@ -314,3 +321,74 @@ func Test115PclnParsing(t *testing.T) {
t.Fatalf("expected to parse name as main.main, got %v", f.Name)
}
}
+
+var (
+ sinkLineTable *LineTable
+ sinkTable *Table
+)
+
+func Benchmark115(b *testing.B) {
+ dat := read115Executable(b)
+ const textStart = 0x1001000
+
+ b.Run("NewLineTable", func(b *testing.B) {
+ b.ReportAllocs()
+ for i := 0; i < b.N; i++ {
+ sinkLineTable = NewLineTable(dat, textStart)
+ }
+ })
+
+ pcln := NewLineTable(dat, textStart)
+ b.Run("NewTable", func(b *testing.B) {
+ b.ReportAllocs()
+ for i := 0; i < b.N; i++ {
+ var err error
+ sinkTable, err = NewTable(nil, pcln)
+ if err != nil {
+ b.Fatal(err)
+ }
+ }
+ })
+
+ tab, err := NewTable(nil, pcln)
+ if err != nil {
+ b.Fatal(err)
+ }
+
+ b.Run("LineToPC", func(b *testing.B) {
+ b.ReportAllocs()
+ for i := 0; i < b.N; i++ {
+ var f *Func
+ var pc uint64
+ pc, f, err = tab.LineToPC("/tmp/hello.go", 3)
+ if err != nil {
+ b.Fatal(err)
+ }
+ if pcln.version != ver12 {
+ b.Fatalf("want version=%d, got %d", ver12, pcln.version)
+ }
+ if pc != 0x105c280 {
+ b.Fatalf("want pc=0x105c280, got 0x%x", pc)
+ }
+ if f.Name != "main.main" {
+ b.Fatalf("want name=main.main, got %q", f.Name)
+ }
+ }
+ })
+
+ b.Run("PCToLine", func(b *testing.B) {
+ b.ReportAllocs()
+ for i := 0; i < b.N; i++ {
+ file, line, fn := tab.PCToLine(0x105c280)
+ if file != "/tmp/hello.go" {
+ b.Fatalf("want name=/tmp/hello.go, got %q", file)
+ }
+ if line != 3 {
+ b.Fatalf("want line=3, got %d", line)
+ }
+ if fn.Name != "main.main" {
+ b.Fatalf("want name=main.main, got %q", fn.Name)
+ }
+ }
+ })
+}