(t *testing.T)
| 464 | } |
| 465 | |
| 466 | func 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…