conform

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package conform is the shared test suite every packetio backend must pass.

The contract in the packetio package doc is prose, and prose does not fail a build. Every bug the backends have had in practice was a place where one of them quietly meant something different from the interface: frames returned to the pool that the caller still owned, a Reclaim that reclaimed nothing, a build callback whose zero return meant three different things. Those are the cases here.

A backend's own test calls Run with a function that opens a device. It is in internal/ because it is a test of this module's backends, not something an out-of-tree backend can use -- if that is ever wanted, move it up.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Required

func Required() bool

Required is set by PACKETIO_CONFORM_REQUIRED. When it is on, a suite that cannot open a device fails instead of skipping.

This exists because of how AF_XDP went unverified for the whole life of this module. Its test opened a device in a way that backend always refuses, so every subtest skipped, "go test ./..." printed ok, and the suite reported nothing at all -- for months. The first time it actually ran it found a contract violation on the first check.

A test that skips silently is indistinguishable from a test that passes, and the difference matters most exactly where it is hardest to see: a backend that needs hardware. So on a machine that has the hardware, say so, and a suite that skips is then a failure rather than a quiet nothing.

func Run

func Run(t *testing.T, open OpenFunc)

Run exercises the parts of the contract that every backend shares.

func RunSteering

func RunSteering(t *testing.T, openWith func(t *testing.T, f packetio.SteeringFilter) (Device, error))

RunSteering checks a backend's handling of receive filters: a filter it accepts is reported, and one it cannot express is refused at Open with ErrUnsupported rather than installed as something wider. openWith opens a device with the given filter, returning nil to skip and the error Open gave.

func RunTimestamps added in v0.1.2

func RunTimestamps(t *testing.T, open OpenFunc, send func(t *testing.T, d Device) int)

RunTimestamps checks a backend that claims Capabilities.RxTimestamps: the interface is really there, and the times it reports are usable.

It needs traffic, which the suite cannot make on its own, so send is the caller's: it puts packets on the wire and returns how many, or zero if it cannot. A run that sees nothing skips rather than passes, on the rule that a skipped test and a passing test must not print the same word.

Types

type Device

type Device = packetio.Device

Device is what a backend hands the suite: a freshly opened device with at least one transmit queue, plus a way to close it. The suite never transmits anything the device is expected to accept, so a loopback or a down link is fine; what it checks is bookkeeping.

type OpenFunc

type OpenFunc func(t *testing.T) Device

OpenFunc opens a device for one subtest. It returns nil to skip, for a backend that cannot open anything in this environment (no hardware, no privilege). Every device it returns is closed by the suite.

Jump to

Keyboard shortcuts

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