...

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

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

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

View as plain text