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

Function TestStatFiltered

cgroup2/manager_test.go:466–561  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

464}
465
466func TestStatFiltered(t *testing.T) {
467 checkCgroupMode(t)
468 group := "/stat-filtered-test-cg"
469 groupPath := fmt.Sprintf("%s-%d", group, os.Getpid())
470 c, err := NewManager(defaultCgroup2Path, groupPath, &Resources{})
471 require.NoError(t, err, "failed to init new cgroup manager")
472 t.Cleanup(func() {
473 _ = c.Delete()
474 })
475
476 t.Run("StatAll", func(t *testing.T) {
477 statAll, err := c.StatFiltered(StatAll)
478 require.NoError(t, err)
479
480 assert.NotNil(t, statAll.Pids)
481 assert.NotNil(t, statAll.CPU)
482 assert.NotNil(t, statAll.Memory)
483 assert.NotNil(t, statAll.Io)
484 assert.NotNil(t, statAll.Rdma)
485 })
486
487 t.Run("CPUOnly", func(t *testing.T) {
488 stats, err := c.StatFiltered(StatCPU)
489 require.NoError(t, err)
490
491 assert.NotNil(t, stats.CPU, "CPU stats should be populated")
492 assert.Nil(t, stats.Pids, "Pids stats should be nil")
493 assert.Nil(t, stats.Memory, "Memory stats should be nil")
494 assert.Nil(t, stats.MemoryEvents, "MemoryEvents should be nil")
495 assert.Nil(t, stats.Io, "IO stats should be nil")
496 assert.Nil(t, stats.Rdma, "RDMA stats should be nil")
497 assert.Nil(t, stats.Hugetlb, "Hugetlb stats should be nil")
498 })
499
500 t.Run("MemoryOnly", func(t *testing.T) {
501 stats, err := c.StatFiltered(StatMemory)
502 require.NoError(t, err)
503
504 assert.NotNil(t, stats.Memory, "Memory stats should be populated")
505 assert.Nil(t, stats.Pids, "Pids stats should be nil")
506 assert.Nil(t, stats.CPU, "CPU stats should be nil")
507 assert.Nil(t, stats.MemoryEvents, "MemoryEvents should be nil")
508 assert.Nil(t, stats.Io, "IO stats should be nil")
509 })
510
511 t.Run("MemoryEventsOnly", func(t *testing.T) {
512 stats, err := c.StatFiltered(StatMemoryEvents)
513 require.NoError(t, err)
514
515 assert.NotNil(t, stats.MemoryEvents, "MemoryEvents should be populated")
516 assert.Nil(t, stats.Memory, "Memory stats should be nil")
517 assert.Nil(t, stats.CPU, "CPU stats should be nil")
518 })
519
520 t.Run("CPUAndMemory", func(t *testing.T) {
521 stats, err := c.StatFiltered(StatCPU | StatMemory)
522 require.NoError(t, err)
523

Callers

nothing calls this directly

Calls 4

DeleteMethod · 0.95
StatFilteredMethod · 0.95
checkCgroupModeFunction · 0.85
NewManagerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…