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

     1  package ebpf
     2  
     3  import (
     4  	"bytes"
     5  	"debug/elf"
     6  	"testing"
     7  )
     8  
     9  func FuzzLoadCollectionSpec(f *testing.F) {
    10  	f.Add([]byte(elf.ELFMAG))
    11  	f.Fuzz(func(t *testing.T, data []byte) {
    12  		if len(data) < len(elf.ELFMAG) {
    13  			t.Skip("input can't be valid ELF")
    14  		}
    15  
    16  		spec, err := LoadCollectionSpecFromReader(bytes.NewReader(data))
    17  		if err != nil {
    18  			if spec != nil {
    19  				t.Fatal("spec is not nil")
    20  			}
    21  		} else if spec == nil {
    22  			t.Fatal("spec is nil")
    23  		}
    24  	})
    25  }