MCPcopy Create free account
hub / github.com/containerd/cgroups / TestToResources

Function TestToResources

cgroup2/utils_test.go:110–133  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

108}
109
110func TestToResources(t *testing.T) {
111 var (
112 quota int64 = 8000
113 period uint64 = 10000
114 shares uint64 = 5000
115
116 mem int64 = 300
117 swap int64 = 500
118 )
119 weight := ConvertCPUSharesToCgroupV2Value(shares)
120 res := specs.LinuxResources{
121 CPU: &specs.LinuxCPU{Quota: &quota, Period: &period, Shares: &shares},
122 Memory: &specs.LinuxMemory{Limit: &mem, Swap: &swap},
123 }
124 v2resources := ToResources(&res)
125
126 assert.Equal(t, weight, *v2resources.CPU.Weight)
127 assert.Equal(t, CPUMax("8000 10000"), v2resources.CPU.Max)
128 assert.Equal(t, swap-mem, *v2resources.Memory.Swap)
129
130 res2 := specs.LinuxResources{CPU: &specs.LinuxCPU{Period: &period}}
131 v2resources2 := ToResources(&res2)
132 assert.Equal(t, CPUMax("max 10000"), v2resources2.CPU.Max)
133}
134
135func BenchmarkGetStatFileContentUint64(b *testing.B) {
136 b.ReportAllocs()

Callers

nothing calls this directly

Calls 3

ToResourcesFunction · 0.85
CPUMaxTypeAlias · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…