| 1 |
package rlimit |
| 2 |
|
| 3 |
import ( |
| •4 |
"strings" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"github.com/cilium/ebpf/internal/linux" |
| 8 |
"github.com/cilium/ebpf/internal/unix" |
| 9 |
|
| 10 |
"github.com/go-quicktest/qt" |
| 11 |
) |
| 12 |
|
| 13 |
func TestRemoveMemlock(t *testing.T) { |
| 14 |
var before unix.Rlimit |
| 15 |
qt.Assert(t, qt.IsNil(unix.Prlimit(0, unix.RLIMIT_MEMLOCK, nil, &before))) |
| 16 |
|
| 17 |
err := RemoveMemlock() |
| •18 |
if err != nil && strings.Contains(err.Error(), "operation not permitted") { |
| 19 |
t.Skipf("Skipping test: %v", err) |
| 20 |
} |
| 21 |
qt.Assert(t, qt.IsNil(err)) |
| 22 |
|
| 23 |
var after unix.Rlimit |
| 24 |
qt.Assert(t, qt.IsNil(unix.Prlimit(0, unix.RLIMIT_MEMLOCK, nil, &after))) |
| 25 |
|
| 26 |
|
| 27 |
version, err := linux.KernelVersion() |
| 28 |
qt.Assert(t, qt.IsNil(err)) |
| 29 |
|
| 30 |
if version.Less(unsupportedMemcgAccounting.MinimumVersion) { |
| 31 |
qt.Assert(t, qt.Equals(after.Cur, unix.RLIM_INFINITY), qt.Commentf("cur should be INFINITY")) |
| 32 |
qt.Assert(t, qt.Equals(after.Max, unix.RLIM_INFINITY), qt.Commentf("max should be INFINITY")) |
| 33 |
} else { |
| 34 |
qt.Assert(t, qt.Equals(after.Cur, before.Cur), qt.Commentf("cur should be unchanged")) |
| 35 |
qt.Assert(t, qt.Equals(after.Max, before.Max), qt.Commentf("max should be unchanged")) |
| 36 |
} |
| 37 |
} |