11// Copyright The OpenTelemetry Authors
22// SPDX-License-Identifier: Apache-2.0
33
4- //go:build amd64 && !integration
5-
64package rtld_test
75
86import (
@@ -15,6 +13,7 @@ import (
1513 "github.com/coreos/pkg/dlopen"
1614 log "github.com/sirupsen/logrus"
1715 "github.com/stretchr/testify/require"
16+ "go.opentelemetry.io/ebpf-profiler/libpf"
1817 "go.opentelemetry.io/ebpf-profiler/metrics"
1918 "go.opentelemetry.io/ebpf-profiler/support"
2019 "go.opentelemetry.io/ebpf-profiler/testutils"
@@ -23,22 +22,32 @@ import (
2322 "go.opentelemetry.io/ebpf-profiler/util"
2423)
2524
26- func TestIntegration (t * testing.T ) {
25+ func test (t * testing.T ) {
2726 if ! testutils .IsRoot () {
2827 t .Skip ("This test requires root privileges" )
2928 }
3029
30+ // Enable debug logging for CI debugging
31+ if os .Getenv ("DEBUG_TEST" ) != "" {
32+ log .SetLevel (log .DebugLevel )
33+ }
34+
3135 // Create a context for the tracer
3236 ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
3337 defer cancel ()
3438
3539 // Start the tracer with all tracers enabled
3640 traceCh , trc := testutils .StartTracer (ctx , t ,
37- tracertypes .AllTracers ( ),
41+ tracertypes .IncludedTracers ( 0 ),
3842 & testutils.MockReporter {},
3943 false )
4044 defer trc .Close ()
4145
46+ trc .StartPIDEventProcessor (ctx )
47+
48+ // tickle tihs process to speed things up
49+ trc .ForceProcessPID (libpf .PID (uint32 (os .Getpid ())))
50+
4251 // Consume traces to prevent blocking
4352 go func () {
4453 for {
@@ -73,70 +82,20 @@ func TestIntegration(t *testing.T) {
7382
7483 // Check that the metric was incremented
7584 return finalCount > initialCount
76- }, 10 * time .Second , 50 * time .Millisecond )
85+ }, 10 * time .Second , 100 * time .Millisecond )
7786}
7887
79- func TestIntegrationSingleShot (t * testing.T ) {
80- if ! testutils .IsRoot () {
81- t .Skip ("This test requires root privileges" )
82- }
83-
84- // Enable debug logging for CI debugging
85- if os .Getenv ("DEBUG_TEST" ) != "" {
86- log .SetLevel (log .DebugLevel )
87- }
88+ func TestIntegration (t * testing.T ) {
89+ test (t )
90+ }
8891
89- // Override HasMultiUprobeSupport to force single-shot mode
92+ func TestIntegrationSingleShot (t * testing.T ) {
93+ // Override HasMultiUprobeSupport to force single-shot mode on newer kernels.
9094 multiUProbeOverride := false
9195 util .SetTestOnlyMultiUprobeSupport (& multiUProbeOverride )
9296 defer util .SetTestOnlyMultiUprobeSupport (nil )
9397
94- // Create a context for the tracer
95- ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
96- defer cancel ()
97-
98- // Start the tracer with all tracers enabled
99- traceCh , trc := testutils .StartTracer (ctx , t ,
100- tracertypes .AllTracers (),
101- & testutils.MockReporter {},
102- false )
103- defer trc .Close ()
104-
105- // Consume traces to prevent blocking
106- go func () {
107- for {
108- select {
109- case <- ctx .Done ():
110- return
111- case <- traceCh :
112- // Discard traces
113- }
114- }
115- }()
116-
117- // retry a few times to get the metric, our process has to be detected and
118- // the dlopen uprobe has to attach.
119- require .Eventually (t , func () bool {
120- // Get the initial metric value
121- initialCount := getEBPFMetricValue (trc , metrics .IDDlopenUprobeHits )
122- //t.Logf("Initial dlopen uprobe metric count: %d", initialCount)
123-
124- // Use dlopen to load a shared library
125- // libm is a standard math library that's always present
126- lib , err := dlopen .GetHandle ([]string {
127- "/lib/x86_64-linux-gnu/libm.so.6" ,
128- "libm.so.6" ,
129- })
130- require .NoError (t , err , "Failed to open libm.so.6" )
131- defer lib .Close ()
132-
133- // Get the metrics after dlopen
134- finalCount := getEBPFMetricValue (trc , metrics .IDDlopenUprobeHits )
135- //t.Logf("Final dlopen uprobe metric count: %d", finalCount)
136-
137- // Check that the metric was incremented
138- return finalCount > initialCount
139- }, 10 * time .Second , 50 * time .Millisecond )
98+ test (t )
14099}
141100
142101func getEBPFMetricValue (trc * tracer.Tracer , metricID metrics.MetricID ) uint64 {
0 commit comments