loader

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package loader defines a Loader, able to unmarshall a YAML document into a Description.

Index

Constants

View Source
const (
	// TestCaseStrategyVector specifies that the case generates a single test description from the provided values.
	TestCaseStrategyVector testCaseStrategy = "vector"
	// TestCaseStrategyMatrix specifies that the resource generates a test description for each combination of the
	// provided values.
	TestCaseStrategyMatrix testCaseStrategy = "matrix"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ContainerContext

type ContainerContext struct {
	// Image is the name the base event-generator image must be tagged with before being used to spawn the container. If
	// omitted, it defaults to the name of the base event-generator image.
	Image *string `yaml:"image" mapstructure:"image"`
	// Name is the name that must be used to identify the container. If omitted, it defaults to "event-generator".
	Name *string `yaml:"name,omitempty" mapstructure:"name"`
	// Env is the set of environment variables that must be provided to the container (in addition to the default ones).
	Env map[string]string `yaml:"env,omitempty" mapstructure:"env"`
}

ContainerContext contains information regarding the container instance that will run a test.

type Description

type Description struct {
	Tests []Test `yaml:"tests" mapstructure:"tests"`
}

Description contains the description of the tests.

func (*Description) Write

func (c *Description) Write(w io.Writer) error

Write writes the description to the provided writer.

type Loader

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

Loader loads tests descriptions.

func New

func New(reservedEnvKeyPrefixes, reservedEnvKeys []string) *Loader

New creates a new Loader. The provided reservedEnvKeyPrefixes and reservedEnvKeys are lists of environment variable prefixes and environment variables that are not allowed to be used in any place accepting environment variables.

func (*Loader) Load

func (l *Loader) Load(r io.Reader) (*Description, error)

Load loads the description from the provided reader.

type ProcessContext

type ProcessContext struct {
	// ExePath is the executable path. If omitted, it is randomly generated.
	ExePath *string `yaml:"exePath,omitempty" mapstructure:"exePath"`
	// Args is a string containing the space-separated list of command line arguments. If a single argument contains
	// spaces, the entire argument must be quoted in order to not be considered as multiple arguments. If omitted, it
	// defaults to "".
	Args *string `yaml:"args,omitempty" mapstructure:"args"`
	// Exe is the argument in position 0 (a.k.a. argv[0]) of the process. If omitted, it defaults to Name if this is
	// specified; otherwise, it defaults to filepath.Base(ExePath).
	Exe *string `yaml:"exe,omitempty" mapstructure:"exe"`
	// Name is the process name. If omitted, it defaults to filepath.Base(ExePath).
	Name *string `yaml:"name,omitempty" mapstructure:"name"`
	// Env is the set of environment variables that must be provided to the process (in addition to the default ones).
	Env map[string]string `yaml:"env,omitempty" mapstructure:"env"`
	// User is the name of the user that must run the process. If omitted, the current process user is used. If the user
	// does not exist, it is created before running the test and deleted after test execution.
	User *string `yaml:"user,omitempty" mapstructure:"user"`
	// Capabilities are the capabilities of the process. The syntax follows the conventions specified by
	// cap_from_text(3). If omitted or empty, it defaults to "all=iep".
	Capabilities *string `yaml:"capabilities,omitempty" mapstructure:"capabilities"`
}

ProcessContext contains information regarding the process that will run a test, or information about one of its ancestors.

type SyscallName

type SyscallName string

SyscallName represents a system call name.

const (
	// SyscallNameWrite specifies the name of the write system call.
	SyscallNameWrite SyscallName = "write"
	// SyscallNameRead specifies the name of the read system call.
	SyscallNameRead SyscallName = "read"
	// SyscallNameOpen specifies the name of the open system call.
	SyscallNameOpen SyscallName = "open"
	// SyscallNameOpenAt specifies the name of the openat system call.
	SyscallNameOpenAt SyscallName = "openat"
	// SyscallNameOpenAt2 specifies the name of the openat2 system call.
	SyscallNameOpenAt2 SyscallName = "openat2"
	// SyscallNameSymLink specifies the name of the symlink system call.
	SyscallNameSymLink SyscallName = "symlink"
	// SyscallNameSymLinkAt specifies the name of the symlinkat system call.
	SyscallNameSymLinkAt SyscallName = "symlinkat"
	// SyscallNameLink specifies the name of the link system call.
	SyscallNameLink SyscallName = "link"
	// SyscallNameLinkAt specifies the name of the linkat system call.
	SyscallNameLinkAt SyscallName = "linkat"
	// SyscallNameInitModule specifies the name of the init_module system call.
	SyscallNameInitModule SyscallName = "init_module"
	// SyscallNameFinitModule specifies the name of the finit_module system call.
	SyscallNameFinitModule SyscallName = "finit_module"
	// SyscallNameDup specifies the name of the dup system call.
	SyscallNameDup SyscallName = "dup"
	// SyscallNameDup2 specifies the name of the dup2 system call.
	SyscallNameDup2 SyscallName = "dup2"
	// SyscallNameDup3 specifies the name of the dup3 system call.
	SyscallNameDup3 SyscallName = "dup3"
	// SyscallNameConnect specifies the name of the connect system call.
	SyscallNameConnect SyscallName = "connect"
	// SyscallNameSocket specifies the name of the socket system call.
	SyscallNameSocket SyscallName = "socket"
	// SyscallNameSendTo specifies the name of the sendto system call.
	SyscallNameSendTo SyscallName = "sendto"
	// SyscallNameKill specifies the name of the kill system call.
	SyscallNameKill SyscallName = "kill"
)

type Test

type Test struct {
	Rule            *string              `yaml:"rule,omitempty" mapstructure:"rule"`
	Name            string               `yaml:"name" mapstructure:"name"`
	Description     *string              `yaml:"description,omitempty" mapstructure:"description"`
	Runner          TestRunnerType       `yaml:"runner" mapstructure:"runner"`
	Context         *TestContext         `yaml:"context,omitempty" mapstructure:"context"`
	BeforeScript    *string              `yaml:"before,omitempty" mapstructure:"before"`
	AfterScript     *string              `yaml:"after,omitempty" mapstructure:"after"`
	Resources       []TestResource       `yaml:"resources,omitempty" mapstructure:"resources"`
	Steps           []TestStep           `yaml:"steps,omitempty" mapstructure:"steps"`
	ExpectedOutcome *TestExpectedOutcome `yaml:"expectedOutcome,omitempty" mapstructure:"expectedOutcome"`

	// The following fields are generated at loading phase.
	//
	// OriginatingTestCase points to the test case that generated this test. If the test was not generated by
	// instantiating any template, this is nil.
	OriginatingTestCase TestCase `yaml:"-" mapstructure:"-"`
	// SourceIndex is the position of the test in the source from which it has been loaded. All tests generated from
	// the same test template, shares the same source position (which is equal to the test template position in the
	// source).
	SourceIndex int
}

Test is a rule test description.

type TestCase

type TestCase map[string]any

TestCase groups test case values by value key.

type TestContext

type TestContext struct {
	Container *ContainerContext `yaml:"container,omitempty" mapstructure:"container"`
	Processes []ProcessContext  `yaml:"processes,omitempty" mapstructure:"processes"`
}

TestContext contains information regarding the running context of a test.

type TestExpectedOutcome

type TestExpectedOutcome struct {
	Source       *string           `yaml:"source,omitempty" mapstructure:"source"`
	Hostname     *string           `yaml:"hostname,omitempty" mapstructure:"hostname"`
	Priority     *string           `yaml:"priority,omitempty" mapstructure:"priority"`
	OutputFields map[string]string `yaml:"outputFields,omitempty" mapstructure:"outputFields"`
}

TestExpectedOutcome is the expected outcome for a test.

type TestResource

type TestResource struct {
	Type TestResourceType `yaml:"type" mapstructure:"type"`
	Name string           `yaml:"name" mapstructure:"name"`
	Spec any              `yaml:"spec,inline" mapstructure:"-"`
}

TestResource describes a test resource.

type TestResourceClientServerL4Proto

type TestResourceClientServerL4Proto string

TestResourceClientServerL4Proto is the transport protocol used by the clientServer test resource client and the server.

const (
	// TestResourceClientServerL4ProtoUDP4 specifies that the clientServer test resource will use UDP over IPv4 to
	// implement the communication between client and server.
	TestResourceClientServerL4ProtoUDP4 TestResourceClientServerL4Proto = "udp4"
	// TestResourceClientServerL4ProtoUDP6 specifies that the clientServer test resource will use UDP over IPv6 to
	// implement the communication between client and server.
	TestResourceClientServerL4ProtoUDP6 TestResourceClientServerL4Proto = "udp6"
	// TestResourceClientServerL4ProtoTCP4 specifies that the clientServer test resource will use TCP over IPv4 to
	// implement the communication between client and server.
	TestResourceClientServerL4ProtoTCP4 TestResourceClientServerL4Proto = "tcp4"
	// TestResourceClientServerL4ProtoTCP6 specifies that the clientServer test resource will use TCP over IPv6 to
	// implement the communication between client and server.
	TestResourceClientServerL4ProtoTCP6 TestResourceClientServerL4Proto = "tcp6"
	// TestResourceClientServerL4ProtoUnix specifies that the clientServer test resource will use Unix sockets to
	// implement the communication between client and server.
	TestResourceClientServerL4ProtoUnix TestResourceClientServerL4Proto = "unix"
)

type TestResourceClientServerSpec

type TestResourceClientServerSpec struct {
	L4Proto TestResourceClientServerL4Proto `yaml:"l4Proto" mapstructure:"l4Proto"`
	Address string                          `yaml:"address" mapstructure:"address"`
}

TestResourceClientServerSpec describes a clientServer test resource.

type TestResourceFDDirectorySpec

type TestResourceFDDirectorySpec struct {
	DirPath string `yaml:"dirPath" mapstructure:"dirPath"`
}

TestResourceFDDirectorySpec describes a directory fd test resource.

type TestResourceFDEpollSpec

type TestResourceFDEpollSpec struct{}

TestResourceFDEpollSpec describes an epoll fd test resource.

type TestResourceFDEventSpec

type TestResourceFDEventSpec struct{}

TestResourceFDEventSpec describes an event fd test resource.

type TestResourceFDFileSpec

type TestResourceFDFileSpec struct {
	FilePath string `yaml:"filePath" mapstructure:"filePath"`
}

TestResourceFDFileSpec describes a regular file fd test resource.

type TestResourceFDInotifySpec

type TestResourceFDInotifySpec struct{}

TestResourceFDInotifySpec describes an inotify fd test resource.

type TestResourceFDMemSpec

type TestResourceFDMemSpec struct {
	FileName string `yaml:"fileName" mapstructure:"fileName"`
}

TestResourceFDMemSpec describes a mem fd test resource.

type TestResourceFDPipeSpec

type TestResourceFDPipeSpec struct{}

TestResourceFDPipeSpec describes a pipe fd test resource.

type TestResourceFDSignalSpec

type TestResourceFDSignalSpec struct{}

TestResourceFDSignalSpec describes a signal fd test resource.

type TestResourceFDSpec

type TestResourceFDSpec struct {
	Subtype TestResourceFDSubtype `yaml:"subtype" mapstructure:"subtype"`
	Spec    any                   `yaml:"spec,inline" mapstructure:"-"`
}

TestResourceFDSpec describes an fd test resource.

type TestResourceFDSubtype

type TestResourceFDSubtype string

TestResourceFDSubtype is the subtype of fd test resource.

const (
	// TestResourceFDSubtypeFile specifies to create a file descriptor referring to a regular file.
	TestResourceFDSubtypeFile TestResourceFDSubtype = "file"
	// TestResourceFDSubtypeDirectory specifies to create a file descriptor referring to a directory.
	TestResourceFDSubtypeDirectory TestResourceFDSubtype = "directory"
	// TestResourceFDSubtypePipe specifies to create a "read" and "write" file descriptor referring to the ends of a
	// pipe.
	TestResourceFDSubtypePipe TestResourceFDSubtype = "pipe"
	// TestResourceFDSubtypeEvent specifies to create an event file descriptor.
	TestResourceFDSubtypeEvent TestResourceFDSubtype = "event"
	// TestResourceFDSubtypeSignal specifies to create a signal file descriptor.
	TestResourceFDSubtypeSignal TestResourceFDSubtype = "signalfd"
	// TestResourceFDSubtypeEpoll specifies to create an epoll file descriptor.
	TestResourceFDSubtypeEpoll TestResourceFDSubtype = "eventpoll"
	// TestResourceFDSubtypeInotify specifies to create an inotify file descriptor.
	TestResourceFDSubtypeInotify TestResourceFDSubtype = "inotify"
	// TestResourceFDSubtypeMem specifies to create a mem file descriptor.
	TestResourceFDSubtypeMem TestResourceFDSubtype = "memfd"
)

type TestResourceProcessSpec

type TestResourceProcessSpec struct {
	// ExePath is the executable path. If omitted, it is randomly generated.
	ExePath *string `yaml:"exePath,omitempty" mapstructure:"exePath"`
	// Args is a string containing the space-separated list of command line arguments. If a single argument contains
	// spaces, the entire argument must be quoted in order to not be considered as multiple arguments. If omitted, it
	// defaults to "".
	Args *string `yaml:"args,omitempty" mapstructure:"args"`
	// Exe is the argument in position 0 (a.k.a. argv[0]) of the process. If omitted, it defaults to Name if this is
	// specified; otherwise, it defaults to filepath.Base(ExePath).
	Exe *string `yaml:"exe,omitempty" mapstructure:"exe"`
	// Name is the process name. If omitted, it defaults to filepath.Base(ExePath).
	Name *string `yaml:"procName,omitempty" mapstructure:"procName"`
	// Env is the set of environment variables that must be provided to the process (in addition to the default ones).
	Env map[string]string `yaml:"env,omitempty" mapstructure:"env"`
}

TestResourceProcessSpec describes a process test resource.

type TestResourceType

type TestResourceType string

TestResourceType is the type of test resource.

const (
	// TestResourceTypeClientServer specifies that the resource runs a client and a server.
	TestResourceTypeClientServer TestResourceType = "clientServer"
	// TestResourceTypeFD specifies that the resource creates a file descriptor.
	TestResourceTypeFD TestResourceType = "fd"
	// TestResourceTypeProcess specifies that the resource creates a process.
	TestResourceTypeProcess TestResourceType = "process"
)

type TestRunnerType

type TestRunnerType string

TestRunnerType is the type of test runner.

const (
	// TestRunnerTypeHost specifies to run the test on the host system.
	TestRunnerTypeHost TestRunnerType = "HostRunner"
)

type TestStep

type TestStep struct {
	Type          TestStepType            `yaml:"type" mapstructure:"type"`
	Name          string                  `yaml:"name" mapstructure:"name"`
	Spec          any                     `yaml:"-" mapstructure:"-"`
	FieldBindings []*TestStepFieldBinding `yaml:"-" mapstructure:"-"`
}

TestStep describes a test step.

func (TestStep) MarshalYAML

func (s TestStep) MarshalYAML() (any, error)

MarshalYAML returns an inner representation of the TestStep instance that is used, in place of the instance, to marshal the content.

type TestStepFieldBinding

type TestStepFieldBinding struct {
	LocalField string
	SrcName    string
	SrcField   string
}

TestStepFieldBinding contains the information to perform the binding of a field belonging to a source step.

type TestStepSyscallSpec

type TestStepSyscallSpec struct {
	Syscall SyscallName    `yaml:"syscall" mapstructure:"syscall"`
	Args    map[string]any `yaml:"args" mapstructure:"args"`
}

TestStepSyscallSpec describes a system call test step.

type TestStepType

type TestStepType string

TestStepType is the type of test step.

const (
	// TestStepTypeSyscall specifies that the test step runs a system call.
	TestStepTypeSyscall TestStepType = "syscall"
)

Directories

Path Synopsis
Package schema provides validation for the loaded tests description and documentation generation leveraging JSON schemas.
Package schema provides validation for the loaded tests description and documentation generation leveraging JSON schemas.

Jump to

Keyboard shortcuts

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