@@ -16,15 +16,12 @@ import (
1616 "io"
1717 "net"
1818 "net/http"
19- "os"
2019 "runtime"
2120 "strconv"
2221 "sync"
2322 "testing"
2423 "time"
2524
26- log "github.com/sirupsen/logrus"
27-
2825 "github.com/docker/go-connections/nat"
2926 "github.com/stretchr/testify/require"
3027 testcontainers "github.com/testcontainers/testcontainers-go"
@@ -33,13 +30,14 @@ import (
3330 "go.opentelemetry.io/ebpf-profiler/interpreter/luajit"
3431 "go.opentelemetry.io/ebpf-profiler/libpf"
3532 "go.opentelemetry.io/ebpf-profiler/reporter"
33+ "go.opentelemetry.io/ebpf-profiler/testutils"
3634 "go.opentelemetry.io/ebpf-profiler/tracer"
3735 tracertypes "go.opentelemetry.io/ebpf-profiler/tracer/types"
3836)
3937
4038// Run
4139func TestIntegration (t * testing.T ) {
42- if ! isRoot () {
40+ if ! testutils . IsRoot () {
4341 t .Skip ("root privileges required" )
4442 }
4543 // TODO:
@@ -118,8 +116,10 @@ func TestIntegration(t *testing.T) {
118116 port , err := cont .MappedPort (ctx , "8080" )
119117 require .NoError (t , err )
120118
119+ enabledTracers , _ := tracertypes .Parse ("luajit" )
120+ enabledTracers .Enable (tracertypes .LuaJITTracer )
121121 r := & mockReporter {symbols : make (symbolMap )}
122- traceCh , trc := startTracer (ctx , t , r )
122+ traceCh , trc := testutils . StartTracer (ctx , t , enabledTracers , r )
123123
124124 var waitGroup sync.WaitGroup
125125 defer waitGroup .Wait ()
@@ -203,44 +203,6 @@ outer:
203203 return true
204204}
205205
206- // FIXME: refactor this to copy less code.
207- func startTracer (ctx context.Context , t * testing.T , r * mockReporter ) (chan * host.Trace ,
208- * tracer.Tracer ) {
209- enabledTracers , _ := tracertypes .Parse ("luajit" )
210- enabledTracers .Enable (tracertypes .LuaJITTracer )
211- trc , err := tracer .NewTracer (ctx , & tracer.Config {
212- DebugTracer : true ,
213- Reporter : r ,
214- Intervals : & mockIntervals {},
215- IncludeTracers : enabledTracers ,
216- SamplesPerSecond : 1000 ,
217- ProbabilisticInterval : 100 ,
218- ProbabilisticThreshold : 100 ,
219- })
220- require .NoError (t , err )
221-
222- trc .StartPIDEventProcessor (ctx )
223-
224- err = trc .AttachTracer ()
225- require .NoError (t , err )
226-
227- log .Info ("Attached tracer program" )
228-
229- err = trc .EnableProfiling ()
230- require .NoError (t , err )
231-
232- err = trc .AttachSchedMonitor ()
233- require .NoError (t , err )
234-
235- traceCh := make (chan * host.Trace )
236-
237- // Spawn monitors for the various result maps
238- err = trc .StartMapMonitors (ctx , traceCh )
239- require .NoError (t , err )
240-
241- return traceCh , trc
242- }
243-
244206func startContainer (ctx context.Context , t * testing.T , image string ) testcontainers.Container {
245207 t .Log ("starting" , image )
246208 // The offset tests load both platform images so docker gets confused if we don't specify
@@ -316,12 +278,6 @@ func makeRequests(ctx context.Context, t *testing.T, wg *sync.WaitGroup,
316278 }()
317279}
318280
319- type mockIntervals struct {}
320-
321- func (f mockIntervals ) MonitorInterval () time.Duration { return 1 * time .Second }
322- func (f mockIntervals ) TracePollInterval () time.Duration { return 250 * time .Millisecond }
323- func (f mockIntervals ) PIDCleanupInterval () time.Duration { return 1 * time .Second }
324-
325281type symbolMap map [libpf.FrameID ]string
326282
327283type mockReporter struct {
@@ -349,10 +305,6 @@ func (m *mockReporter) getFunctionName(frameID libpf.FrameID) string {
349305 return m .symbols [frameID ]
350306}
351307
352- func isRoot () bool {
353- return os .Geteuid () == 0
354- }
355-
356308func removeSentinel (frames []host.Frame ) []host.Frame {
357309 for i , f := range frames {
358310 if f .File == 0 {
0 commit comments