File: status_test.go

package info (click to toggle)
golang-github-containers-psgo 1.7.1%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 372 kB
  • sloc: makefile: 46
file content (137 lines) | stat: -rw-r--r-- 4,057 bytes parent folder | download | duplicates (2)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2018 psgo authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package proc

import (
	"strings"
	"testing"

	"github.com/stretchr/testify/assert"
)

// copied from proc(5) manpage
var statusFile = `
Name:   bash
Umask:  0022
State:  S (sleeping)
Tgid:   17248
Ngid:   0
Pid:    17248
PPid:   17200
TracerPid:      0
Uid:    1000    1000    1000    1000
Gid:    100     100     100     100
FDSize: 256
Groups: 16 33 100
NStgid: 17248
NSpid:  17248
NSpgid: 17248
NSsid:  17200
VmPeak:     131168 kB
VmSize:     131168 kB
VmLck:           0 kB
VmPin:           0 kB
VmHWM:       13484 kB
VmRSS:       13484 kB
RssAnon:     10264 kB
RssFile:      3220 kB
RssShmem:        0 kB
VmData:      10332 kB
VmStk:         136 kB
VmExe:         992 kB
VmLib:        2104 kB
VmPTE:          76 kB
VmPMD:          12 kB
VmSwap:          0 kB
HugetlbPages:          0 kB        # 4.4
Threads:        1
SigQ:   0/3067
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000010000
SigIgn: 0000000000384004
SigCgt: 000000004b813efb
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: ffffffffffffffff
CapAmb:   0000000000000000
NoNewPrivs:     0
Seccomp:        0
Cpus_allowed:   00000001
Cpus_allowed_list:      0
Mems_allowed:   1
Mems_allowed_list:      0
voluntary_ctxt_switches:        150
nonvoluntary_ctxt_switches:     545
`

func TestParseStatus(t *testing.T) {
	s, err := parseStatus("testpid", strings.Split(statusFile, "\n"))

	assert.Nil(t, err)
	assert.NotNil(t, s)
	assert.Equal(t, "bash", s.Name)
	assert.Equal(t, "0022", s.Umask)
	assert.Equal(t, "S", s.State)
	assert.Equal(t, "17248", s.Tgid)
	assert.Equal(t, "0", s.Ngid)
	assert.Equal(t, "17200", s.PPid)
	assert.Equal(t, "0", s.TracerPid)
	assert.Equal(t, []string{"1000", "1000", "1000", "1000"}, s.Uids)
	assert.Equal(t, []string{"100", "100", "100", "100"}, s.Gids)
	assert.Equal(t, "256", s.FdSize)
	assert.Equal(t, []string{"16", "33", "100"}, s.Groups)
	assert.Equal(t, "17248", s.NStgid)
	assert.Equal(t, []string{"17248"}, s.NSpid)
	assert.Equal(t, "17248", s.NSpgid)
	assert.Equal(t, "131168", s.VMPeak)
	assert.Equal(t, "131168", s.VMSize)
	assert.Equal(t, "0", s.VMLCK)
	assert.Equal(t, "0", s.VMPin)
	assert.Equal(t, "13484", s.VMHWM)
	assert.Equal(t, "13484", s.VMRSS)
	assert.Equal(t, "10264", s.RssAnon)
	assert.Equal(t, "3220", s.RssFile)
	assert.Equal(t, "0", s.RssShmem)
	assert.Equal(t, "10332", s.VMData)
	assert.Equal(t, "136", s.VMStk)
	assert.Equal(t, "992", s.VMExe)
	assert.Equal(t, "2104", s.VMLib)
	assert.Equal(t, "76", s.VMPTE)
	assert.Equal(t, "12", s.VMPMD)
	assert.Equal(t, "0", s.VMSwap)
	assert.Equal(t, "0", s.HugetlbPages)
	assert.Equal(t, "1", s.Threads)
	assert.Equal(t, "0/3067", s.SigQ)
	assert.Equal(t, "0000000000000000", s.SigPnd)
	assert.Equal(t, "0000000000000000", s.ShdPnd)
	assert.Equal(t, "0000000000010000", s.SigBlk)
	assert.Equal(t, "0000000000384004", s.SigIgn)
	assert.Equal(t, "000000004b813efb", s.SigCgt)
	assert.Equal(t, "0000000000000000", s.CapInh)
	assert.Equal(t, "0000000000000000", s.CapPrm)
	assert.Equal(t, "0000000000000000", s.CapEff)
	assert.Equal(t, "ffffffffffffffff", s.CapBnd)
	assert.Equal(t, "0000000000000000", s.CapAmb)
	assert.Equal(t, "0", s.NoNewPrivs)
	assert.Equal(t, "0", s.Seccomp)
	assert.Equal(t, "00000001", s.CpusAllowed)
	assert.Equal(t, "0", s.CpusAllowedList)
	assert.Equal(t, "1", s.MemsAllowed)
	assert.Equal(t, "0", s.MemsAllowedList)
	assert.Equal(t, "150", s.VoluntaryCtxtSwitches)
	assert.Equal(t, "545", s.NonvoluntaryCtxtSwitches)
}