@@ -13,6 +13,7 @@ import (
1313 "github.com/coreos/pkg/dlopen"
1414 log "github.com/sirupsen/logrus"
1515 "github.com/stretchr/testify/require"
16+ "go.opentelemetry.io/ebpf-profiler/libpf"
1617 "go.opentelemetry.io/ebpf-profiler/metrics"
1718 "go.opentelemetry.io/ebpf-profiler/support"
1819 "go.opentelemetry.io/ebpf-profiler/testutils"
@@ -21,7 +22,7 @@ import (
2122 "go.opentelemetry.io/ebpf-profiler/util"
2223)
2324
24- func TestIntegration (t * testing.T ) {
25+ func test (t * testing.T ) {
2526 if ! testutils .IsRoot () {
2627 t .Skip ("This test requires root privileges" )
2728 }
@@ -35,13 +36,21 @@ func TestIntegration(t *testing.T) {
3536 ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
3637 defer cancel ()
3738
39+ enabledTracers , err := tracertypes .Parse ("RTLD" )
40+ require .NoError (t , err , "Failed to parse enabled tracers" )
41+
3842 // Start the tracer with all tracers enabled
3943 traceCh , trc := testutils .StartTracer (ctx , t ,
40- tracertypes . AllTracers () ,
44+ enabledTracers ,
4145 & testutils.MockReporter {},
4246 false )
4347 defer trc .Close ()
4448
49+ trc .StartPIDEventProcessor (ctx )
50+
51+ // tickle tihs process to speed things up
52+ trc .ForceProcessPID (libpf .PID (uint32 (os .Getpid ())))
53+
4554 // Consume traces to prevent blocking
4655 go func () {
4756 for {
@@ -79,67 +88,17 @@ func TestIntegration(t *testing.T) {
7988 }, 5 * time .Minute , 100 * time .Millisecond )
8089}
8190
82- func TestIntegrationSingleShot (t * testing.T ) {
83- if ! testutils .IsRoot () {
84- t .Skip ("This test requires root privileges" )
85- }
86-
87- // Enable debug logging for CI debugging
88- if os .Getenv ("DEBUG_TEST" ) != "" {
89- log .SetLevel (log .DebugLevel )
90- }
91+ func TestIntegration (t * testing.T ) {
92+ test (t )
93+ }
9194
92- // Override HasMultiUprobeSupport to force single-shot mode
95+ func TestIntegrationSingleShot (t * testing.T ) {
96+ // Override HasMultiUprobeSupport to force single-shot mode on newer kernels.
9397 multiUProbeOverride := false
9498 util .SetTestOnlyMultiUprobeSupport (& multiUProbeOverride )
9599 defer util .SetTestOnlyMultiUprobeSupport (nil )
96100
97- // Create a context for the tracer
98- ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
99- defer cancel ()
100-
101- // Start the tracer with all tracers enabled
102- traceCh , trc := testutils .StartTracer (ctx , t ,
103- tracertypes .AllTracers (),
104- & testutils.MockReporter {},
105- false )
106- defer trc .Close ()
107-
108- // Consume traces to prevent blocking
109- go func () {
110- for {
111- select {
112- case <- ctx .Done ():
113- return
114- case <- traceCh :
115- // Discard traces
116- }
117- }
118- }()
119-
120- // retry a few times to get the metric, our process has to be detected and
121- // the dlopen uprobe has to attach.
122- require .Eventually (t , func () bool {
123- // Get the initial metric value
124- initialCount := getEBPFMetricValue (trc , metrics .IDDlopenUprobeHits )
125- t .Logf ("Initial dlopen uprobe metric count: %d" , initialCount )
126-
127- // Use dlopen to load a shared library
128- // libm is a standard math library that's always present
129- lib , err := dlopen .GetHandle ([]string {
130- "/lib/x86_64-linux-gnu/libm.so.6" ,
131- "libm.so.6" ,
132- })
133- require .NoError (t , err , "Failed to open libm.so.6" )
134- defer lib .Close ()
135-
136- // Get the metrics after dlopen
137- finalCount := getEBPFMetricValue (trc , metrics .IDDlopenUprobeHits )
138- t .Logf ("Final dlopen uprobe metric count: %d" , finalCount )
139-
140- // Check that the metric was incremented
141- return finalCount > initialCount
142- }, 5 * time .Minute , 100 * time .Millisecond )
101+ test (t )
143102}
144103
145104func getEBPFMetricValue (trc * tracer.Tracer , metricID metrics.MetricID ) uint64 {
0 commit comments