github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/helpers_test.go (about)

     1  package ebpf
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  
     7  	"github.com/cilium/ebpf/btf"
     8  	"github.com/cilium/ebpf/internal/testutils"
     9  )
    10  
    11  func haveTestmod(tb testing.TB) bool {
    12  	haveTestmod := false
    13  	if !testutils.IsKernelLessThan(tb, "5.11") {
    14  		// See https://github.com/torvalds/linux/commit/290248a5b7d829871b3ea3c62578613a580a1744
    15  		testmod, err := btf.FindHandle(func(info *btf.HandleInfo) bool {
    16  			return info.IsModule() && info.Name == "bpf_testmod"
    17  		})
    18  		if err != nil && !errors.Is(err, btf.ErrNotFound) {
    19  			tb.Fatal(err)
    20  		}
    21  		haveTestmod = testmod != nil
    22  		testmod.Close()
    23  	}
    24  
    25  	return haveTestmod
    26  }