Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EBPF] gpu: refactor probe_test to use a suite #30846

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 36 additions & 29 deletions pkg/gpu/probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,66 @@ import (
"time"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/DataDog/datadog-agent/pkg/ebpf/ebpftest"
"github.com/DataDog/datadog-agent/pkg/gpu/config"
"github.com/DataDog/datadog-agent/pkg/gpu/testutil"
"github.com/DataDog/datadog-agent/pkg/network/usm/utils"
"github.com/DataDog/datadog-agent/pkg/process/monitor"
)

func TestProbeCanLoad(t *testing.T) {
type probeTestSuite struct {
suite.Suite
}

func TestProbe(t *testing.T) {
if err := config.CheckGPUSupported(); err != nil {
t.Skipf("minimum kernel version not met, %v", err)
}

ebpftest.TestBuildModes(t, []ebpftest.BuildMode{ebpftest.CORE}, "", func(t *testing.T) {
suite.Run(t, new(probeTestSuite))
})
}

func (s *probeTestSuite) getProbe() *Probe {
t := s.T()

cfg := config.New()

// Avoid waiting for the initial sync to finish in tests, we don't need it
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to have at least one test to check this scenario and make sure there are no "timing" edge-cases or any other unexpected surprises?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could check it, although it shouldn't be too problematic, the initial sync is just scanning the procfs before starting the goroutine that listens to new processes. Created a ticket to track it

cfg.InitialProcessSync = false
nvmlMock := testutil.GetBasicNvmlMock()
probe, err := NewProbe(cfg, ProbeDependencies{NvmlLib: nvmlMock})

deps := ProbeDependencies{
NvmlLib: testutil.GetBasicNvmlMock(),
}
probe, err := NewProbe(cfg, deps)
require.NoError(t, err)
require.NotNil(t, probe)
t.Cleanup(probe.Close)

return probe
}

func (s *probeTestSuite) TestCanLoad() {
t := s.T()

probe := s.getProbe()
data, err := probe.GetAndFlush()
require.NoError(t, err)
require.NotNil(t, data)
}

func TestProbeCanReceiveEvents(t *testing.T) {
if err := config.CheckGPUSupported(); err != nil {
t.Skipf("minimum kernel version not met, %v", err)
}
func (s *probeTestSuite) TestCanReceiveEvents() {
t := s.T()

procMon := monitor.GetProcessMonitor()
require.NotNil(t, procMon)
require.NoError(t, procMon.Initialize(false))
t.Cleanup(procMon.Stop)

cfg := config.New()
cfg.InitialProcessSync = false
cfg.BPFDebug = true

nvmlMock := testutil.GetBasicNvmlMock()

probe, err := NewProbe(cfg, ProbeDependencies{NvmlLib: nvmlMock})
require.NoError(t, err)
t.Cleanup(probe.Close)
probe := s.getProbe()

cmd, err := testutil.RunSample(t, testutil.CudaSample)
require.NoError(t, err)
Expand Down Expand Up @@ -89,25 +106,15 @@ func TestProbeCanReceiveEvents(t *testing.T) {
require.Greater(t, alloc.endKtime, alloc.startKtime)
}

func TestProbeCanGenerateStats(t *testing.T) {
if err := config.CheckGPUSupported(); err != nil {
t.Skipf("minimum kernel version not met, %v", err)
}
func (s *probeTestSuite) TestCanGenerateStats() {
t := s.T()

procMon := monitor.GetProcessMonitor()
require.NotNil(t, procMon)
require.NoError(t, procMon.Initialize(false))
t.Cleanup(procMon.Stop)

cfg := config.New()
cfg.InitialProcessSync = false
cfg.BPFDebug = true

nvmlMock := testutil.GetBasicNvmlMock()

probe, err := NewProbe(cfg, ProbeDependencies{NvmlLib: nvmlMock})
require.NoError(t, err)
t.Cleanup(probe.Close)
probe := s.getProbe()

cmd, err := testutil.RunSample(t, testutil.CudaSample)
require.NoError(t, err)
Expand Down
Loading