MCPcopy Create free account
hub / github.com/google/pprof / TestSymbolizationPath

Function TestSymbolizationPath

internal/driver/fetch_test.go:45–102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

43)
44
45func TestSymbolizationPath(t *testing.T) {
46 if runtime.GOOS == "windows" {
47 t.Skip("test assumes Unix paths")
48 }
49
50 // Save environment variables to restore after test
51 saveHome := os.Getenv(homeEnv())
52 savePath := os.Getenv("PPROF_BINARY_PATH")
53
54 tempdir, err := os.MkdirTemp("", "home")
55 if err != nil {
56 t.Fatal("creating temp dir: ", err)
57 }
58 defer os.RemoveAll(tempdir)
59 os.MkdirAll(filepath.Join(tempdir, "pprof", "binaries", "abcde10001"), 0700)
60 os.Create(filepath.Join(tempdir, "pprof", "binaries", "abcde10001", "binary"))
61
62 os.MkdirAll(filepath.Join(tempdir, "pprof", "binaries", "fg"), 0700)
63 os.Create(filepath.Join(tempdir, "pprof", "binaries", "fg", "hij10001.debug"))
64
65 obj := testObj{tempdir}
66 os.Setenv(homeEnv(), tempdir)
67 for _, tc := range []struct {
68 env, file, buildID, want string
69 msgCount int
70 }{
71 {"", "/usr/bin/binary", "", "/usr/bin/binary", 0},
72 {"", "/usr/bin/binary", "fedcb10000", "/usr/bin/binary", 0},
73 {"/usr", "/bin/binary", "", "/usr/bin/binary", 0},
74 {"", "/prod/path/binary", "abcde10001", filepath.Join(tempdir, "pprof/binaries/abcde10001/binary"), 0},
75 {"/alternate/architecture", "/usr/bin/binary", "", "/alternate/architecture/binary", 0},
76 {"/alternate/architecture", "/usr/bin/binary", "abcde10001", "/alternate/architecture/binary", 0},
77 {"", "", "fghij10001", filepath.Join(tempdir, "pprof/binaries/fg/hij10001.debug"), 0},
78 {"/nowhere:/alternate/architecture", "/usr/bin/binary", "fedcb10000", "/usr/bin/binary", 1},
79 {"/nowhere:/alternate/architecture", "/usr/bin/binary", "abcde10002", "/usr/bin/binary", 1},
80 // A single-character BuildID must not panic when the LLVM debug-file
81 // lookup slices BuildID[:2] / BuildID[2:]. Prior to the fix, this caused
82 // a "slice bounds out of range" panic.
83 {"", "/usr/bin/binary", "X", "/usr/bin/binary", 0},
84 } {
85 os.Setenv("PPROF_BINARY_PATH", tc.env)
86 p := &profile.Profile{
87 Mapping: []*profile.Mapping{
88 {
89 File: tc.file,
90 BuildID: tc.buildID,
91 },
92 },
93 }
94 s := &source{}
95 locateBinaries(p, s, obj, &proftest.TestUI{T: t, Ignore: tc.msgCount})
96 if file := p.Mapping[0].File; file != tc.want {
97 t.Errorf("%s:%s:%s, want %s, got %s", tc.env, tc.file, tc.buildID, tc.want, file)
98 }
99 }
100 os.Setenv(homeEnv(), saveHome)
101 os.Setenv("PPROF_BINARY_PATH", savePath)
102}

Callers

nothing calls this directly

Calls 2

homeEnvFunction · 0.85
locateBinariesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…