Skip to content

Commit 96a417b

Browse files
committed
Cleanup test
Remove duplicate code Trigger test process to be processed immediately to get rtld.Loader and Attach to happen faster.
1 parent 49078be commit 96a417b

File tree

4 files changed

+27
-59
lines changed

4 files changed

+27
-59
lines changed

interpreter/rtld/rtld_test.go

Lines changed: 17 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -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

145104
func getEBPFMetricValue(trc *tracer.Tracer, metricID metrics.MetricID) uint64 {

processmanager/execinfomanager/manager.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ func NewExecutableInfoManager(
140140
if includeTracers.Has(types.Labels) {
141141
interpreterLoaders = append(interpreterLoaders, golabels.Loader, customlabels.Loader)
142142
}
143-
interpreterLoaders = append(interpreterLoaders, oomwatcher.Loader, rtld.Loader)
143+
if includeTracers.Has(types.RTLD) {
144+
interpreterLoaders = append(interpreterLoaders, rtld.Loader)
145+
}
146+
interpreterLoaders = append(interpreterLoaders, oomwatcher.Loader)
144147

145148
if includeTracers.Has(types.CUDATracer) {
146149
// USDT support requires cookies

tracer/tracer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,3 +1204,7 @@ func (t *Tracer) GetEbpfHandler() interpreter.EbpfHandler {
12041204
func (t *Tracer) GetInterpretersForPID(pid libpf.PID) []interpreter.Instance {
12051205
return t.processManager.GetInterpretersForPID(pid)
12061206
}
1207+
1208+
func (t *Tracer) ForceProcessPID(pid libpf.PID) {
1209+
t.pidEvents <- libpf.PIDTID(uint64(pid) + uint64(pid)<<32)
1210+
}

tracer/types/parse.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const (
2525
LuaJITTracer
2626
GoTracer
2727
Labels
28+
RTLD
2829
CUDATracer
2930

3031
// maxTracers indicates the max. number of different tracers
@@ -42,6 +43,7 @@ var tracerTypeToName = map[tracerType]string{
4243
LuaJITTracer: "luajit",
4344
GoTracer: "go",
4445
Labels: "labels",
46+
RTLD: "rtld",
4547
CUDATracer: "cuda",
4648
}
4749

0 commit comments

Comments
 (0)