github.com/cilium/ebpf@v0.10.0/rlimit/rlimit_test.go (about)

     1  package rlimit
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/cilium/ebpf/internal"
     7  	"github.com/cilium/ebpf/internal/unix"
     8  
     9  	qt "github.com/frankban/quicktest"
    10  )
    11  
    12  func TestRemoveMemlock(t *testing.T) {
    13  	var before unix.Rlimit
    14  	qt.Assert(t, unix.Prlimit(0, unix.RLIMIT_MEMLOCK, nil, &before), qt.IsNil)
    15  
    16  	err := RemoveMemlock()
    17  	qt.Assert(t, err, qt.IsNil)
    18  
    19  	var after unix.Rlimit
    20  	qt.Assert(t, unix.Prlimit(0, unix.RLIMIT_MEMLOCK, nil, &after), qt.IsNil)
    21  
    22  	// We can't use testutils here due to an import cycle.
    23  	version, err := internal.KernelVersion()
    24  	qt.Assert(t, err, qt.IsNil)
    25  
    26  	if version.Less(unsupportedMemcgAccounting.MinimumVersion) {
    27  		qt.Assert(t, after.Cur, qt.Equals, uint64(unix.RLIM_INFINITY), qt.Commentf("cur should be INFINITY"))
    28  		qt.Assert(t, after.Max, qt.Equals, uint64(unix.RLIM_INFINITY), qt.Commentf("max should be INFINITY"))
    29  	} else {
    30  		qt.Assert(t, after.Cur, qt.Equals, before.Cur, qt.Commentf("cur should be unchanged"))
    31  		qt.Assert(t, after.Max, qt.Equals, before.Max, qt.Commentf("max should be unchanged"))
    32  	}
    33  }