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 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 <chen.dylane@gmail.com>
  • Loading branch information
chentao-kernel committed Apr 8, 2024
1 parent 7371781 commit be0a5e6
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions selftest/tc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,41 @@ 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() {

Check failure on line 82 in selftest/tc/main.go

View workflow job for this annotation

GitHub Actions / Analyze Code

extra empty line at the end of a block
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 be0a5e6

Please sign in to comment.