...

Source file src/github.com/cilium/ebpf/cmd/bpf2go/test/api_test.go

Documentation: github.com/cilium/ebpf/cmd/bpf2go/test

     1  package test
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  	"unsafe"
     7  
     8  	"github.com/cilium/ebpf/internal/testutils"
     9  )
    10  
    11  func TestLoadingSpec(t *testing.T) {
    12  	spec, err := loadTest()
    13  	testutils.SkipIfNotSupported(t, err)
    14  	if err != nil {
    15  		t.Fatal("Can't load spec:", err)
    16  	}
    17  
    18  	if spec == nil {
    19  		t.Fatal("Got a nil spec")
    20  	}
    21  }
    22  
    23  func TestLoadingObjects(t *testing.T) {
    24  	var objs testObjects
    25  	err := loadTestObjects(&objs, nil)
    26  	testutils.SkipIfNotSupported(t, err)
    27  	if err != nil {
    28  		t.Fatal("Can't load objects:", err)
    29  	}
    30  	defer objs.Close()
    31  
    32  	if objs.Filter == nil {
    33  		t.Error("Loading returns an object with nil programs")
    34  	}
    35  
    36  	if objs.Map1 == nil {
    37  		t.Error("Loading returns an object with nil maps")
    38  	}
    39  }
    40  
    41  func TestTypes(t *testing.T) {
    42  	if testEHOOPY != 0 {
    43  		t.Error("Expected testEHOOPY to be 0, got", testEHOOPY)
    44  	}
    45  	if testEFROOD != 1 {
    46  		t.Error("Expected testEFROOD to be 0, got", testEFROOD)
    47  	}
    48  
    49  	e := testE(0)
    50  	if size := unsafe.Sizeof(e); size != 4 {
    51  		t.Error("Expected size of exampleE to be 4, got", size)
    52  	}
    53  
    54  	bf := testBarfoo{}
    55  	if size := unsafe.Sizeof(bf); size != 16 {
    56  		t.Error("Expected size of exampleE to be 16, got", size)
    57  	}
    58  	if reflect.TypeOf(bf.Bar).Kind() != reflect.Int64 {
    59  		t.Error("Expected testBarfoo.Bar to be int64")
    60  	}
    61  	if reflect.TypeOf(bf.Baz).Kind() != reflect.Bool {
    62  		t.Error("Expected testBarfoo.Baz to be bool")
    63  	}
    64  	if reflect.TypeOf(bf.Boo) != reflect.TypeOf(e) {
    65  		t.Error("Expected testBarfoo.Boo to be exampleE")
    66  	}
    67  }
    68  

View as plain text