Source file
src/runtime/decoratemappings_test.go
1
2
3
4
5 package runtime_test
6
7 import (
8 "os"
9 "regexp"
10 "runtime"
11 "testing"
12 )
13
14 func validateMapLabels(t *testing.T, labels []string) {
15
16
17
18
19
20 regions := map[string]bool{
21 "allspans array": false,
22 "gc bits": false,
23 "heap": false,
24 "heap index": false,
25 "heap reservation": false,
26 "immortal metadata": false,
27 "page alloc": false,
28 "page alloc index": false,
29 "page summary": false,
30 "scavenge index": false,
31 }
32 for _, label := range labels {
33 if _, ok := regions[label]; !ok {
34 t.Logf("unexpected region label found: \"%s\"", label)
35 }
36 regions[label] = true
37 }
38 for label, found := range regions {
39 if !found {
40 t.Logf("region label missing: \"%s\"", label)
41 }
42 }
43 }
44
45 func TestDecorateMappings(t *testing.T) {
46 if runtime.GOOS != "linux" {
47 t.Skip("decoratemappings is only supported on Linux")
48
49 }
50
51 var labels []string
52 if rawMaps, err := os.ReadFile("/proc/self/maps"); err != nil {
53 t.Fatalf("failed to read /proc/self/maps: %v", err)
54 } else {
55 t.Logf("maps:%s\n", string(rawMaps))
56 matches := regexp.MustCompile("[^[]+ \\[anon: Go: (.+)\\]\n").FindAllSubmatch(rawMaps, -1)
57 for _, match_pair := range matches {
58
59 labels = append(labels, string(match_pair[1]))
60 }
61 }
62 t.Logf("DebugDecorateMappings: %v", *runtime.DebugDecorateMappings)
63 if *runtime.DebugDecorateMappings != 0 && runtime.SetVMANameSupported() {
64 validateMapLabels(t, labels)
65 } else {
66 if len(labels) > 0 {
67 t.Errorf("unexpected mapping labels present: %v", labels)
68 } else {
69 t.Skip("mapping labels absent as expected")
70 }
71 }
72 }
73
View as plain text