-
Notifications
You must be signed in to change notification settings - Fork 726
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ebpf: run TestProgramTestRunInterrupt only on Linux
TestProgramTestRunInterrupt tests Linux specific behaviour around signal delivery. It doesn't make sense to run it on a different platform. The test was copied without making any changes. Signed-off-by: Lorenz Bauer <[email protected]>
- Loading branch information
Showing
2 changed files
with
84 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package ebpf | ||
|
||
import ( | ||
"math" | ||
"runtime" | ||
"testing" | ||
"time" | ||
|
||
"github.com/cilium/ebpf/internal" | ||
"github.com/cilium/ebpf/internal/testutils" | ||
"github.com/cilium/ebpf/internal/unix" | ||
) | ||
|
||
func TestProgramTestRunInterrupt(t *testing.T) { | ||
testutils.SkipOnOldKernel(t, "5.0", "EINTR from BPF_PROG_TEST_RUN") | ||
|
||
prog := createBasicProgram(t) | ||
|
||
var ( | ||
tgid = unix.Getpid() | ||
tidChan = make(chan int, 1) | ||
exit = make(chan struct{}) | ||
errs = make(chan error, 1) | ||
timeout = time.After(5 * time.Second) | ||
) | ||
|
||
defer close(exit) | ||
|
||
go func() { | ||
runtime.LockOSThread() | ||
defer func() { | ||
// Wait for the test to allow us to unlock the OS thread, to | ||
// ensure that we don't send SIGUSR1 to the wrong thread. | ||
<-exit | ||
runtime.UnlockOSThread() | ||
}() | ||
|
||
tidChan <- unix.Gettid() | ||
|
||
// Block this thread in the BPF syscall, so that we can | ||
// trigger EINTR by sending a signal. | ||
opts := RunOptions{ | ||
Data: internal.EmptyBPFContext, | ||
Repeat: math.MaxInt32, | ||
Reset: func() { | ||
// We don't know how long finishing the | ||
// test run would take, so flag that we've seen | ||
// an interruption and abort the goroutine. | ||
close(errs) | ||
runtime.Goexit() | ||
}, | ||
} | ||
_, _, err := prog.run(&opts) | ||
|
||
errs <- err | ||
}() | ||
|
||
tid := <-tidChan | ||
for { | ||
err := unix.Tgkill(tgid, tid, unix.SIGUSR1) | ||
if err != nil { | ||
t.Fatal("Can't send signal to goroutine thread:", err) | ||
} | ||
|
||
select { | ||
case err, ok := <-errs: | ||
if !ok { | ||
return | ||
} | ||
|
||
testutils.SkipIfNotSupported(t, err) | ||
if err == nil { | ||
t.Fatal("testRun wasn't interrupted") | ||
} | ||
|
||
t.Fatal("testRun returned an error:", err) | ||
|
||
case <-timeout: | ||
t.Fatal("Timed out trying to interrupt the goroutine") | ||
|
||
default: | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters