package testutils

import "github.com/cilium/ebpf/internal/testutils"

Index

Functions

func CheckFeatureMatrix

func CheckFeatureMatrix[K comparable](t *testing.T, fm internal.FeatureMatrix[K])

func CheckFeatureTest

func CheckFeatureTest(t *testing.T, fn func() error)

func ClangBin

func ClangBin(tb testing.TB) string

func Contains

func Contains[T, I any](i I) bool

Contains checks if interface value I is of type T. Use with qt.Satisfies:

qt.Assert(t, qt.Satisfies(p, testutils.Contains[*ebpf.Program]))

func CreateCgroup

func CreateCgroup(tb testing.TB) *os.File

func DupFD

func DupFD(tb testing.TB, fd int) int

func Files

func Files(t *testing.T, files []string, fn func(*testing.T, string))

Files calls fn for each given file.

The function errors out if the pattern matches no files.

func GetCgroupIno

func GetCgroupIno(t *testing.T, cgroup *os.File) uint64

func Glob

func Glob(tb testing.TB, pattern string, excludes ...string) []string

Glob finds files matching a pattern.

The pattern should may include full path. Excludes use the same syntax as pattern, but are only applied to the basename instead of the full path.

func IsDeepCopy

func IsDeepCopy[T any](got, want T) qt.Checker

IsDeepCopy checks that got is a deep copy of want.

All primitive values must be equal, but pointers must be distinct. This is different from reflect.DeepEqual which will accept equal pointer values. That is, reflect.DeepEqual(a, a) is true, while IsDeepCopy(a, a) is false.

func IsVersionLessThan

func IsVersionLessThan(tb testing.TB, minVersions ...string) bool

Check whether the current runtime version is less than some minimum.

func LockOSThreadToSingleCPU

func LockOSThreadToSingleCPU(tb testing.TB)

LockOSThreadToSingleCPU force the current goroutine to run on a single CPU.

func NativeFile

func NativeFile(tb testing.TB, path string) string

NativeFile substitutes %s with an abbreviation of the host endianness.

func Rand

func Rand(tb testing.TB) *rand.Rand

func SkipIfNotSupported

func SkipIfNotSupported(tb testing.TB, err error)

func SkipIfNotSupportedOnOS

func SkipIfNotSupportedOnOS(tb testing.TB, err error)

func SkipOnOldKernel

func SkipOnOldKernel(tb testing.TB, minVersion, feature string)

Skip a test based on the Linux version we are running on.

Warning: this function does not have an effect on platforms other than Linux.

func TempBPFFS

func TempBPFFS(tb testing.TB) string

TempBPFFS creates a temporary directory on a BPF FS.

The directory is automatically cleaned up at the end of the test run.

Source Files

bpffs_other.go cgroup.go checkers.go cpu.go fd_other.go feature.go feature_other.go glob.go programs.go rlimit.go seed.go

Directories

PathSynopsis
internal/testutils/testmain
Version
v0.18.0 (latest)
Published
Apr 2, 2025
Platform
linux/amd64
Imports
20 packages
Last checked
1 week ago

Tools for package owners.