Debian Codegraph @

internal/cgroups/subsys_test.go

raw symbols SCIP
1 // Copyright (c) 2017 Uber Technologies, Inc.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20
21 //go:build linux
22 // +build linux
23
24 package cgroupsscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/
25
26 import (
27 "strconvscip-go gomod github.com/golang/go/src go1.18 strconv/"
28 "testingscip-go gomod github.com/golang/go/src go1.18 testing/"
29
30 "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.7.1 `github.com/stretchr/testify/assert`/"
31 )
32
33 func TestNewCGroupSubsysFromLinescip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/TestNewCGroupSubsysFromLine().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) {
34 testTable := []struct {
35 name string
36 line string
37 expectedSubsys *CGroupSubsysscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroupSubsys#
38 }{
39 {
40 name: "single-subsys",
41 line: "1:cpu:/",
42 expectedSubsys: &CGroupSubsysscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroupSubsys#{
43 IDscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroupSubsys#ID.: 1,
44 Subsystemsscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroupSubsys#Subsystems.: []string{"cpu"},
45 Namescip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroupSubsys#Name.: "/",
46 },
47 },
48 {
49 name: "multi-subsys",
50 line: "8:cpu,cpuacct,cpuset:/docker/1234567890abcdef",
51 expectedSubsys: &CGroupSubsysscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroupSubsys#{
52 IDscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroupSubsys#ID.: 8,
53 Subsystemsscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroupSubsys#Subsystems.: []string{"cpu", "cpuacct", "cpuset"},
54 Namescip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroupSubsys#Name.: "/docker/1234567890abcdef",
55 },
56 },
57 {
58 name: "multi-subsys",
59 line: "12:cpu,cpuacct:/system.slice/containerd.service/kubepods-besteffort-podb41662f7_b03a_4c65_8ef9_6e4e55c3cf27.slice:cri-containerd:1753b7cbbf62734d812936961224d5bc0cf8f45214e0d5cdd1a781a053e7c48f",
60 expectedSubsys: &CGroupSubsysscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroupSubsys#{
61 IDscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroupSubsys#ID.: 12,
62 Subsystemsscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroupSubsys#Subsystems.: []string{"cpu", "cpuacct"},
63 Namescip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroupSubsys#Name.: "/system.slice/containerd.service/kubepods-besteffort-podb41662f7_b03a_4c65_8ef9_6e4e55c3cf27.slice:cri-containerd:1753b7cbbf62734d812936961224d5bc0cf8f45214e0d5cdd1a781a053e7c48f",
64 },
65 },
66 }
67
68 for _, tt := range testTable {
69 subsys, err := NewCGroupSubsysFromLinescip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/NewCGroupSubsysFromLine().(tt.line)
70 assertscip-go gomod github.com/stretchr/testify v1.7.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.7.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.expectedSubsys, subsys, tt.name)
71 assertscip-go gomod github.com/stretchr/testify v1.7.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.7.1 `github.com/stretchr/testify/assert`/NoError().(t, err, tt.name)
72 }
73 }
74
75 func TestNewCGroupSubsysFromLineErrscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/TestNewCGroupSubsysFromLineErr().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) {
76 lines := []string{
77 "1:cpu",
78 "not-a-number:cpu:/",
79 }
80 _, parseError := strconvscip-go gomod github.com/golang/go/src go1.18 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.18 strconv/Atoi().("not-a-number")
81
82 testTable := []struct {
83 name string
84 line string
85 expectedError error
86 }{
87 {
88 name: "fewer-fields",
89 line: lines[0],
90 expectedError: cgroupSubsysFormatInvalidErrorscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/cgroupSubsysFormatInvalidError#{lines[0]},
91 },
92 {
93 name: "illegal-id",
94 line: lines[1],
95 expectedError: parseError,
96 },
97 }
98
99 for _, tt := range testTable {
100 subsys, err := NewCGroupSubsysFromLinescip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/NewCGroupSubsysFromLine().(tt.line)
101 assertscip-go gomod github.com/stretchr/testify v1.7.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.7.1 `github.com/stretchr/testify/assert`/Nil().(t, subsys, tt.name)
102 assertscip-go gomod github.com/stretchr/testify v1.7.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.7.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.expectedError, err, tt.name)
103 }
104 }