github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/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  	"github.com/go-quicktest/qt"
    10  )
    11  
    12  func TestRemoveMemlock(t *testing.T) {
    13  	var before unix.Rlimit
    14  	qt.Assert(t, qt.IsNil(unix.Prlimit(0, unix.RLIMIT_MEMLOCK, nil, &before)))
    15  
    16  	err := RemoveMemlock()
    17  	qt.Assert(t, qt.IsNil(err))
    18  
    19  	var after unix.Rlimit
    20  	qt.Assert(t, qt.IsNil(unix.Prlimit(0, unix.RLIMIT_MEMLOCK, nil, &after)))
    21  
    22  	// We can't use testutils here due to an import cycle.
    23  	version, err := internal.KernelVersion()
    24  	qt.Assert(t, qt.IsNil(err))
    25  
    26  	if version.Less(unsupportedMemcgAccounting.MinimumVersion) {
    27  		qt.Assert(t, qt.Equals(after.Cur, unix.RLIM_INFINITY), qt.Commentf("cur should be INFINITY"))
    28  		qt.Assert(t, qt.Equals(after.Max, unix.RLIM_INFINITY), qt.Commentf("max should be INFINITY"))
    29  	} else {
    30  		qt.Assert(t, qt.Equals(after.Cur, before.Cur), qt.Commentf("cur should be unchanged"))
    31  		qt.Assert(t, qt.Equals(after.Max, before.Max), qt.Commentf("max should be unchanged"))
    32  	}
    33  }