github.com/cilium/ebpf@v0.16.0/cmd/bpf2go/test/test_bpfel.go (about) 1 // Code generated by bpf2go; DO NOT EDIT. 2 //go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64 3 4 package test 5 6 import ( 7 "bytes" 8 _ "embed" 9 "fmt" 10 "io" 11 12 "github.com/cilium/ebpf" 13 ) 14 15 type testBarfoo struct { 16 Bar int64 17 Baz bool 18 _ [3]byte 19 Boo testE 20 } 21 22 type testE uint32 23 24 const ( 25 testEHOOPY testE = 0 26 testEFROOD testE = 1 27 ) 28 29 // loadTest returns the embedded CollectionSpec for test. 30 func loadTest() (*ebpf.CollectionSpec, error) { 31 reader := bytes.NewReader(_TestBytes) 32 spec, err := ebpf.LoadCollectionSpecFromReader(reader) 33 if err != nil { 34 return nil, fmt.Errorf("can't load test: %w", err) 35 } 36 37 return spec, err 38 } 39 40 // loadTestObjects loads test and converts it into a struct. 41 // 42 // The following types are suitable as obj argument: 43 // 44 // *testObjects 45 // *testPrograms 46 // *testMaps 47 // 48 // See ebpf.CollectionSpec.LoadAndAssign documentation for details. 49 func loadTestObjects(obj interface{}, opts *ebpf.CollectionOptions) error { 50 spec, err := loadTest() 51 if err != nil { 52 return err 53 } 54 55 return spec.LoadAndAssign(obj, opts) 56 } 57 58 // testSpecs contains maps and programs before they are loaded into the kernel. 59 // 60 // It can be passed ebpf.CollectionSpec.Assign. 61 type testSpecs struct { 62 testProgramSpecs 63 testMapSpecs 64 } 65 66 // testSpecs contains programs before they are loaded into the kernel. 67 // 68 // It can be passed ebpf.CollectionSpec.Assign. 69 type testProgramSpecs struct { 70 Filter *ebpf.ProgramSpec `ebpf:"filter"` 71 } 72 73 // testMapSpecs contains maps before they are loaded into the kernel. 74 // 75 // It can be passed ebpf.CollectionSpec.Assign. 76 type testMapSpecs struct { 77 Map1 *ebpf.MapSpec `ebpf:"map1"` 78 } 79 80 // testObjects contains all objects after they have been loaded into the kernel. 81 // 82 // It can be passed to loadTestObjects or ebpf.CollectionSpec.LoadAndAssign. 83 type testObjects struct { 84 testPrograms 85 testMaps 86 } 87 88 func (o *testObjects) Close() error { 89 return _TestClose( 90 &o.testPrograms, 91 &o.testMaps, 92 ) 93 } 94 95 // testMaps contains all maps after they have been loaded into the kernel. 96 // 97 // It can be passed to loadTestObjects or ebpf.CollectionSpec.LoadAndAssign. 98 type testMaps struct { 99 Map1 *ebpf.Map `ebpf:"map1"` 100 } 101 102 func (m *testMaps) Close() error { 103 return _TestClose( 104 m.Map1, 105 ) 106 } 107 108 // testPrograms contains all programs after they have been loaded into the kernel. 109 // 110 // It can be passed to loadTestObjects or ebpf.CollectionSpec.LoadAndAssign. 111 type testPrograms struct { 112 Filter *ebpf.Program `ebpf:"filter"` 113 } 114 115 func (p *testPrograms) Close() error { 116 return _TestClose( 117 p.Filter, 118 ) 119 } 120 121 func _TestClose(closers ...io.Closer) error { 122 for _, closer := range closers { 123 if err := closer.Close(); err != nil { 124 return err 125 } 126 } 127 return nil 128 } 129 130 // Do not access this directly. 131 // 132 //go:embed test_bpfel.o 133 var _TestBytes []byte