Debian Codegraph @

internal/proc/status_test.go

raw symbols SCIP
1 // Copyright 2018 psgo authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package proc
16
17 import (
18 "strings"
19 "testing"
20
21 "github.com/stretchr/testify/assert"
22 )
23
24 // copied from proc(5) manpage
25 var statusFile = `
26 Name: bash
27 Umask: 0022
28 State: S (sleeping)
29 Tgid: 17248
30 Ngid: 0
31 Pid: 17248
32 PPid: 17200
33 TracerPid: 0
34 Uid: 1000 1000 1000 1000
35 Gid: 100 100 100 100
36 FDSize: 256
37 Groups: 16 33 100
38 NStgid: 17248
39 NSpid: 17248
40 NSpgid: 17248
41 NSsid: 17200
42 VmPeak: 131168 kB
43 VmSize: 131168 kB
44 VmLck: 0 kB
45 VmPin: 0 kB
46 VmHWM: 13484 kB
47 VmRSS: 13484 kB
48 RssAnon: 10264 kB
49 RssFile: 3220 kB
50 RssShmem: 0 kB
51 VmData: 10332 kB
52 VmStk: 136 kB
53 VmExe: 992 kB
54 VmLib: 2104 kB
55 VmPTE: 76 kB
56 VmPMD: 12 kB
57 VmSwap: 0 kB
58 HugetlbPages: 0 kB # 4.4
59 Threads: 1
60 SigQ: 0/3067
61 SigPnd: 0000000000000000
62 ShdPnd: 0000000000000000
63 SigBlk: 0000000000010000
64 SigIgn: 0000000000384004
65 SigCgt: 000000004b813efb
66 CapInh: 0000000000000000
67 CapPrm: 0000000000000000
68 CapEff: 0000000000000000
69 CapBnd: ffffffffffffffff
70 CapAmb: 0000000000000000
71 NoNewPrivs: 0
72 Seccomp: 0
73 Seccomp_filters: 0
74 Cpus_allowed: 00000001
75 Cpus_allowed_list: 0
76 Mems_allowed: 1
77 Mems_allowed_list: 0
78 voluntary_ctxt_switches: 150
79 nonvoluntary_ctxt_switches: 545
80 `
81
82 func TestParseStatus(t *testing.T) {
83 s, err := parseStatus("testpid", strings.Split(statusFile, "\n"))
84
85 assert.Nil(t, err)
86 assert.NotNil(t, s)
87 assert.Equal(t, "bash", s.Name)
88 assert.Equal(t, "0022", s.Umask)
89 assert.Equal(t, "S", s.State)
90 assert.Equal(t, "17248", s.Tgid)
91 assert.Equal(t, "0", s.Ngid)
92 assert.Equal(t, "17200", s.PPid)
93 assert.Equal(t, "0", s.TracerPid)
94 assert.Equal(t, []string{"1000", "1000", "1000", "1000"}, s.Uids)
95 assert.Equal(t, []string{"100", "100", "100", "100"}, s.Gids)
96 assert.Equal(t, "256", s.FdSize)
97 assert.Equal(t, []string{"16", "33", "100"}, s.Groups)
98 assert.Equal(t, "17248", s.NStgid)
99 assert.Equal(t, []string{"17248"}, s.NSpid)
100 assert.Equal(t, "17248", s.NSpgid)
101 assert.Equal(t, "131168", s.VMPeak)
102 assert.Equal(t, "131168", s.VMSize)
103 assert.Equal(t, "0", s.VMLCK)
104 assert.Equal(t, "0", s.VMPin)
105 assert.Equal(t, "13484", s.VMHWM)
106 assert.Equal(t, "13484", s.VMRSS)
107 assert.Equal(t, "10264", s.RssAnon)
108 assert.Equal(t, "3220", s.RssFile)
109 assert.Equal(t, "0", s.RssShmem)
110 assert.Equal(t, "10332", s.VMData)
111 assert.Equal(t, "136", s.VMStk)
112 assert.Equal(t, "992", s.VMExe)
113 assert.Equal(t, "2104", s.VMLib)
114 assert.Equal(t, "76", s.VMPTE)
115 assert.Equal(t, "12", s.VMPMD)
116 assert.Equal(t, "0", s.VMSwap)
117 assert.Equal(t, "0", s.HugetlbPages)
118 assert.Equal(t, "1", s.Threads)
119 assert.Equal(t, "0/3067", s.SigQ)
120 assert.Equal(t, "0000000000000000", s.SigPnd)
121 assert.Equal(t, "0000000000000000", s.ShdPnd)
122 assert.Equal(t, "0000000000010000", s.SigBlk)
123 assert.Equal(t, "0000000000384004", s.SigIgn)
124 assert.Equal(t, "000000004b813efb", s.SigCgt)
125 assert.Equal(t, "0000000000000000", s.CapInh)
126 assert.Equal(t, "0000000000000000", s.CapPrm)
127 assert.Equal(t, "0000000000000000", s.CapEff)
128 assert.Equal(t, "ffffffffffffffff", s.CapBnd)
129 assert.Equal(t, "0000000000000000", s.CapAmb)
130 assert.Equal(t, "0", s.NoNewPrivs)
131 assert.Equal(t, "0", s.Seccomp)
132 assert.Equal(t, "0", s.SeccompFilters)
133 assert.Equal(t, "00000001", s.CpusAllowed)
134 assert.Equal(t, "0", s.CpusAllowedList)
135 assert.Equal(t, "1", s.MemsAllowed)
136 assert.Equal(t, "0", s.MemsAllowedList)
137 assert.Equal(t, "150", s.VoluntaryCtxtSwitches)
138 assert.Equal(t, "545", s.NonvoluntaryCtxtSwitches)
139 }