File: synth_test.go

package info (click to toggle)
golang-github-google-pprof 0.0~git20211008.947d60d-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports, forky, sid, trixie
  • size: 5,036 kB
  • sloc: sh: 70; ansic: 11; makefile: 4
file content (36 lines) | stat: -rw-r--r-- 794 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package report

import (
	"testing"

	"github.com/google/pprof/profile"
)

func TestSynthAddresses(t *testing.T) {
	s := newSynthCode(nil)
	l1 := &profile.Location{}
	addr1 := s.address(l1)
	if s.address(l1) != addr1 {
		t.Errorf("different calls with same location returned different addresses")
	}

	l2 := &profile.Location{}
	addr2 := s.address(l2)
	if addr2 == addr1 {
		t.Errorf("same address assigned to different locations")
	}

}

func TestSynthAvoidsMapping(t *testing.T) {
	mappings := []*profile.Mapping{
		{Start: 100, Limit: 200},
		{Start: 300, Limit: 400},
	}
	s := newSynthCode(mappings)
	loc := &profile.Location{}
	addr := s.address(loc)
	if addr >= 100 && addr < 200 || addr >= 300 && addr < 400 {
		t.Errorf("synthetic location %d overlaps mapping %v", addr, mappings)
	}
}