perfring

package
v1.2.0-pre.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package perfring provides utilities to do tests using the perf ringbuffer directly

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterTestMessages added in v0.9.0

func FilterTestMessages(n notify.Message) bool

func ProcessEvents

func ProcessEvents(t *testing.T, ctx context.Context, eventFn EventFn, wgStarted *sync.WaitGroup)

ProcessEvents will open the perf ringbuffer and process events.

It will complete, whenever it sees a number of MsgTestEventUnix on _all_ cpus or when the ctx is done. Hence, callers need to load the test sensor before they call it or use the ctx to cancel its operation.

Example code to load the test sensor:

import testsensor "github.com/cilium/tetragon/pkg/sensors/test"
import tus "github.com/cilium/tetragon/pkg/testutils/sensors"
tus.LoadSensor(t, testsensor.GetTestSensor())

If the test sensor is loaded, users can use TestCheckerMarkEnd to generate the appropriate MsgTestEventUnix.

func RunSubTest

func RunSubTest(t *testing.T, ctx context.Context, name string, selfOperations func(t *testing.T), eventFn EventFn) bool

similar to RunTest, but uses t.Run()

func RunTest

func RunTest(t *testing.T, ctx context.Context, selfOperations func(), eventFn EventFn)

RunTest is a convinience wrapper around ProcessEvents it will:

  • run ProcessEvents on a different goroutinem using eventFn
  • execute selfOperations provided by the user
  • execute TestCheckerMarkEnd so that ProcessEvents returns
  • wait for ProcessEvents to finish, and return

func RunTestEventReduce added in v0.9.0

func RunTestEventReduce[K any, V any](
	t *testing.T,
	ctx context.Context,
	selfOperations func(),
	filterFn func(notify.Message) bool,
	mapFn func(notify.Message) K,
	reduceFn func(val V, key K) V,
) V

func RunTestEvents

func RunTestEvents(t *testing.T, ctx context.Context, selfOperations func()) []notify.Message

RunTestEvents: returns a list of events after running the test with selfOperations (see RunTest) MsgTestEventUnix events are filtered out.

Types

type EventFn

type EventFn func(ev notify.Message) error

EventFn is the type of function called by ProcessEvents for each event.

Jump to

Keyboard shortcuts

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