ebpftest

package
v0.0.0-...-45a9bcf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2024 License: Apache-2.0, Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package ebpftest is utilities for tests against eBPF

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DumpMapsTestHelper

func DumpMapsTestHelper(t *testing.T, dumpfunc func(io.Writer, ...string) error, maps ...string)

DumpMapsTestHelper dumps the content of the given maps to the test log, handling errors if any.

func FailLogLevel

func FailLogLevel(t testing.TB, level string)

FailLogLevel sets the logger level for this test only and only outputs if the test fails

func LogLevel

func LogLevel(t testing.TB, level string)

LogLevel sets the logger level for this test only

func LogTracePipe

func LogTracePipe(t *testing.T)

LogTracePipe logs all messages read from /sys/kernel/[debug/]/tracing/trace_pipe during the test. This function will set the environment variable BPF_DEBUG=true for the duration of the test.

func LogTracePipeFilter

func LogTracePipeFilter(t *testing.T, filterFn func(ev *TraceEvent) bool)

LogTracePipeFilter logs only messages that pass `filterFn` read from /sys/kernel/[debug/]/tracing/trace_pipe during the test. This function will set the environment variable BPF_DEBUG=true for the duration of the test.

func LogTracePipeProcess

func LogTracePipeProcess(t *testing.T, pid uint32)

LogTracePipeProcess logs only messages from the provided process read from /sys/kernel/[debug/]/tracing/trace_pipe during the test. This function will set the environment variable BPF_DEBUG=true for the duration of the test.

func LogTracePipeSelf

func LogTracePipeSelf(t *testing.T)

LogTracePipeSelf logs only messages from the current process read from /sys/kernel/[debug/]/tracing/trace_pipe during the test. This function will set the environment variable BPF_DEBUG=true for the duration of the test.

func RequireKernelVersion

func RequireKernelVersion(tb testing.TB, version kernel.Version)

RequireKernelVersion skips a test if the minimum kernel version is not met

func TestBuildMode

func TestBuildMode(t *testing.T, mode BuildMode, name string, fn func(t *testing.T))

TestBuildMode runs the test under the provided build mode

func TestBuildModes

func TestBuildModes(t *testing.T, modes []BuildMode, name string, fn func(t *testing.T))

TestBuildModes runs the test under all the provided build modes

Types

type BuildMode

type BuildMode interface {
	fmt.Stringer
	Env() map[string]string
}

BuildMode is an eBPF build mode

var (
	Prebuilt        BuildMode
	RuntimeCompiled BuildMode
	CORE            BuildMode
	Fentry          BuildMode
	Ebpfless        BuildMode
)

TODO I don't love fentry as a buildmode here...

func GetBuildMode

func GetBuildMode() BuildMode

GetBuildMode returns which build mode the current environment matches, if any

func SupportedBuildModes

func SupportedBuildModes() []BuildMode

SupportedBuildModes returns the build modes supported on the current host

type TraceEvent

type TraceEvent struct {
	Raw       string
	Task      string
	PID       uint32
	CPU       string
	Flags     string
	Timestamp string
	Function  string
	Message   string
}

TraceEvent contains the raw event as well as the contents of every field as string, as defined under "Output format" in https://www.kernel.org/doc/Documentation/trace/ftrace.txt

func (TraceEvent) String

func (t TraceEvent) String() string

type TracePipe

type TracePipe struct {
	// contains filtered or unexported fields
}

TracePipe to read from /sys/kernel/[debug/]tracing/trace_pipe Note that data can be read only once, i.e. if you have more than one tracer / channel, only one will receive an event: "Once data is read from this file, it is consumed, and will not be read again with a sequential read." https://www.kernel.org/doc/Documentation/trace/ftrace.txt

func NewTracePipe

func NewTracePipe() (*TracePipe, error)

NewTracePipe instantiates a new trace pipe

func (*TracePipe) Channel

func (t *TracePipe) Channel() (<-chan *TraceEvent, <-chan error)

Channel returns a channel of events and another for errors

func (*TracePipe) Close

func (t *TracePipe) Close() error

Close the trace pipe

func (*TracePipe) ReadLine

func (t *TracePipe) ReadLine() (*TraceEvent, error)

ReadLine reads a line

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL