@@ -35,10 +35,10 @@ import (
3535 "google.golang.org/protobuf/proto"
3636
3737 "github.com/cilium/cilium/pkg/bpf"
38- "github.com/cilium/cilium/pkg/byteorder"
3938 "github.com/cilium/cilium/pkg/datapath/link"
4039 "github.com/cilium/cilium/pkg/maps/eventsmap"
41- "github.com/cilium/cilium/pkg/monitor"
40+ "github.com/cilium/cilium/pkg/monitor/api"
41+ "github.com/cilium/cilium/pkg/monitor/format"
4242)
4343
4444var (
5353 dumpCtx = flag .Bool ("dump-ctx" , false , "If set, the program context will be dumped after a CHECK and SETUP run." )
5454)
5555
56+ type testLogWriter struct {
57+ t * testing.T
58+ }
59+
60+ func (w * testLogWriter ) Write (p []byte ) (n int , err error ) {
61+ // use the formatted output to avoid the new line
62+ w .t .Logf ("%s" , string (p ))
63+ return len (p ), nil
64+ }
65+
5666func TestBPF (t * testing.T ) {
5767 if testPath == nil || * testPath == "" {
5868 t .Skip ("Set -bpf-test-path to run BPF tests" )
@@ -221,22 +231,14 @@ func loadAndRunSpec(t *testing.T, entry fs.DirEntry, instrLog io.Writer) []*cove
221231 }
222232 defer globalLogReader .Close ()
223233
224- linkCache := link .NewLinkCache ()
225-
234+ formatter := format .NewMonitorFormatter (api .DEBUG , link .NewLinkCache (), & testLogWriter {t : t })
226235 go func () {
227236 for {
228237 rec , err := globalLogReader .Read ()
229238 if err != nil {
230239 return
231240 }
232-
233- dm := monitor.DebugMsg {}
234- reader := bytes .NewReader (rec .RawSample )
235- if err := binary .Read (reader , byteorder .Native , & dm ); err != nil {
236- return
237- }
238-
239- t .Log (dm .Message (linkCache ))
241+ formatter .FormatSample (rec .RawSample , rec .CPU )
240242 }
241243 }()
242244 }
0 commit comments