| 1 |
package testutils |
| 2 |
|
| 3 |
import ( |
| 4 |
"runtime" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"github.com/cilium/ebpf/internal/unix" |
| 8 |
|
| 9 |
"github.com/go-quicktest/qt" |
| 10 |
) |
| 11 |
|
| 12 |
|
| 13 |
func LockOSThreadToSingleCPU(tb testing.TB) { |
| 14 |
tb.Helper() |
| 15 |
|
| 16 |
runtime.LockOSThread() |
| 17 |
tb.Cleanup(runtime.UnlockOSThread) |
| 18 |
|
| 19 |
var old unix.CPUSet |
| 20 |
err := unix.SchedGetaffinity(0, &old) |
| 21 |
qt.Assert(tb, qt.IsNil(err)) |
| 22 |
|
| 23 |
|
| 24 |
var first unix.CPUSet |
| 25 |
first.Set(0) |
| 26 |
err = unix.SchedSetaffinity(0, &first) |
| 27 |
qt.Assert(tb, qt.IsNil(err)) |
| 28 |
|
| 29 |
tb.Cleanup(func() { |
| 30 |
_ = unix.SchedSetaffinity(0, &old) |
| 31 |
}) |
| 32 |
} |