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

     1  package testutils
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  )
     7  
     8  // TempBPFFS creates a temporary directory on a BPF FS.
     9  //
    10  // The directory is automatically cleaned up at the end of the test run.
    11  func TempBPFFS(tb testing.TB) string {
    12  	tb.Helper()
    13  
    14  	tmp, err := os.MkdirTemp("/sys/fs/bpf", "ebpf-test")
    15  	if err != nil {
    16  		tb.Fatal("Create temporary directory on BPFFS:", err)
    17  	}
    18  	tb.Cleanup(func() { os.RemoveAll(tmp) })
    19  
    20  	return tmp
    21  }