Skip to content

Commit

Permalink
chore(selftest): Add tc Query test case
Browse files Browse the repository at this point in the history
The bpf_tc_query/bpf_tc_detach interface should init the parameter
first, sometimes it may be confused for us, so add the case to reduce
the confusion.

#421
#420

Signed-off-by: Tao Chen <[email protected]>
  • Loading branch information
chentao-kernel committed Apr 8, 2024
1 parent 7371781 commit 1d3c72c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions selftest/tc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,40 @@ func main() {

var tcOpts bpf.TcOpts
tcOpts.ProgFd = int(tcProg.GetFd())
tcOpts.Flags = bpf.BpfTcFReplace
tcOpts.Handle = 1
err = hook.Attach(&tcOpts)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
}

// test for query
tcOpts.Flags = 0
tcOpts.ProgFd = 0
tcOpts.ProgId = 0
err = hook.Query(&tcOpts)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
}
if tcOpts.Handle != 1 {
fmt.Fprintln(os.Stderr, "query info error, handle:%d", tcOpts.Handle)
os.Exit(-1)
}

// test for detach
defer func() {
tcOpts.Flags = 0
tcOpts.ProgFd = 0
tcOpts.ProgId = 0
err = hook.Detach(&tcOpts)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
}
}()

eventsChannel := make(chan []byte)
rb, err := bpfModule.InitRingBuf("events", eventsChannel)
if err != nil {
Expand Down

0 comments on commit 1d3c72c

Please sign in to comment.