Skip to main content

TestRun

Trait TestRun 

Source
pub trait TestRun {
    type Opts<'a>;
    type Result;

    // Required method
    fn test_run(
        &self,
        opts: Self::Opts<'_>,
    ) -> Result<Self::Result, ProgramError>;
}
Expand description

Trait for BPF programs that support test execution via BPF_PROG_TEST_RUN.

Required Associated Types§

Source

type Opts<'a>

The options type used to configure a single test invocation.

Different program types require different options: skb/XDP programs use TestRunOptions, raw tracepoint programs use RawTracePointRunOptions, and FExit programs use (). See FExit for the tracing-specific test-run semantics.

Source

type Result

The Result type for a single test invocation.

Required Methods§

Source

fn test_run(&self, opts: Self::Opts<'_>) -> Result<Self::Result, ProgramError>

Runs the program with test input data and returns the result.

This function uses the kernel’s BPF_PROG_TEST_RUN command to execute the program in a test environment with provided input data.

§Arguments
  • opts - Test run options including input/output data and context
§Returns

Returns a Self::Result containing the program-specific test output.

For most program types this is crate::TestRunResult. For RawTracePoint it is RawTracePointTestRunResult. For FExit it is (); see FExit for what a successful tracing test run means.

§Errors

Returns ProgramError::SyscallError if the underlying syscall fails. Common errors include -ENOSPC if output buffers are too small.

§Example
let input_data = [0u8; 64];
let mut output_data = [0u8; 64];

let opts = TestRunOptions {
    data_in: Some(&input_data),
    data_out: Some(&mut output_data),
    repeat: 1,
    ..Default::default()
};

let result = program.test_run(opts)?;
println!("Program returned: {}, took {} ns", result.return_value, result.duration.as_nanos());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§