github.com/cilium/cilium@v1.16.2/pkg/testutils/bpffs.go (about)

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