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

Function buildMemoryMetrics

cgroup1/memory_test.go:261–289  ·  view source on GitHub ↗

buildMemoryMetrics creates fake cgroups memory entries in a temporary dir. Returns the fake cgroups root

(t *testing.T, modules []string, metrics []string)

Source from the content-addressed store, hash-verified

259
260// buildMemoryMetrics creates fake cgroups memory entries in a temporary dir. Returns the fake cgroups root
261func buildMemoryMetrics(t *testing.T, modules []string, metrics []string) string {
262 tmpRoot := t.TempDir()
263 tmpDir := path.Join(tmpRoot, string(Memory))
264 if err := os.MkdirAll(tmpDir, defaultDirPerm); err != nil {
265 t.Fatal(err)
266 }
267 if err := os.WriteFile(path.Join(tmpDir, "memory.stat"), []byte(memoryData), defaultFilePerm); err != nil {
268 t.Fatal(err)
269 }
270 if err := os.WriteFile(path.Join(tmpDir, "memory.oom_control"), []byte(memoryOomControlData), defaultFilePerm); err != nil {
271 t.Fatal(err)
272 }
273 cnt := 0
274 for _, mod := range modules {
275 for _, metric := range metrics {
276 var fileName string
277 if mod == "" {
278 fileName = path.Join(tmpDir, strings.Join([]string{"memory", metric}, "."))
279 } else {
280 fileName = path.Join(tmpDir, strings.Join([]string{"memory", mod, metric}, "."))
281 }
282 if err := os.WriteFile(fileName, []byte(fmt.Sprintln(cnt)), defaultFilePerm); err != nil {
283 t.Fatal(err)
284 }
285 cnt++
286 }
287 }
288 return tmpRoot
289}
290
291func Test_getOomControlValue(t *testing.T) {
292 var (

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…