| 1 |
|
| 2 |
|
| 3 |
package test |
| 4 |
|
| 5 |
import ( |
| 6 |
"reflect" |
| 7 |
"testing" |
| 8 |
"unsafe" |
| 9 |
|
| 10 |
"github.com/go-quicktest/qt" |
| 11 |
|
| 12 |
"github.com/cilium/ebpf/internal/testutils" |
| 13 |
) |
| 14 |
|
| 15 |
func TestLoadingSpec(t *testing.T) { |
| 16 |
spec, err := loadTest() |
| 17 |
testutils.SkipIfNotSupported(t, err) |
| 18 |
qt.Assert(t, qt.IsNil(err)) |
| 19 |
|
| 20 |
qt.Assert(t, qt.Not(qt.IsNil(spec))) |
| 21 |
qt.Assert(t, qt.Not(qt.IsNil(spec.Programs))) |
| 22 |
qt.Assert(t, qt.Not(qt.IsNil(spec.Maps))) |
| 23 |
qt.Assert(t, qt.Not(qt.IsNil(spec.Variables))) |
| 24 |
} |
| 25 |
|
| 26 |
func TestLoadingObjects(t *testing.T) { |
| 27 |
var objs testObjects |
| 28 |
err := loadTestObjects(&objs, nil) |
| 29 |
testutils.SkipIfNotSupported(t, err) |
| 30 |
if err != nil { |
| 31 |
t.Fatal("Can't load objects:", err) |
| 32 |
} |
| 33 |
defer objs.Close() |
| 34 |
|
| 35 |
qt.Assert(t, qt.Not(qt.IsNil(objs.Filter))) |
| 36 |
qt.Assert(t, qt.Not(qt.IsNil(objs.Map1))) |
| 37 |
qt.Assert(t, qt.Not(qt.IsNil(objs.MyConstant))) |
| 38 |
qt.Assert(t, qt.Not(qt.IsNil(objs.StructConst))) |
| 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 testE to be 4, got", size) |
| 52 |
} |
| 53 |
|
| 54 |
bf := testBarfoo{} |
| 55 |
if size := unsafe.Sizeof(bf); size != 16 { |
| 56 |
t.Error("Expected size of testBarfoo 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 testE") |
| 66 |
} |
| 67 |
} |