testutil

package
v0.0.0-...-44562d8 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0, MIT Imports: 32 Imported by: 0

Documentation

Overview

Package testutil provides common test utilities for kernfs-based filesystems.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Boot

func Boot() (*kernel.Kernel, error)

Boot initializes a new bare bones kernel for test.

func CreateTask

func CreateTask(ctx context.Context, name string, tc *kernel.ThreadGroup, mntns *vfs.MountNamespace, root, cwd vfs.VirtualDentry) (*kernel.Task, error)

CreateTask creates a new bare bones task for tests.

Types

type DirentCollector

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

DirentCollector provides an implementation for vfs.IterDirentsCallback for testing. It simply iterates to the end of a given directory FD and collects all dirents emitted by the callback.

func (*DirentCollector) Contains

func (d *DirentCollector) Contains(name string, typ uint8) error

Contains checks whether the collector has a dirent with the given name and type.

func (*DirentCollector) Count

func (d *DirentCollector) Count() int

Count returns the number of dirents currently in the collector.

func (*DirentCollector) Dirents

func (d *DirentCollector) Dirents() map[string]*vfs.Dirent

Dirents returns all dirents discovered by this collector.

func (*DirentCollector) Handle

func (d *DirentCollector) Handle(dirent vfs.Dirent) error

Handle implements vfs.IterDirentsCallback.Handle.

func (*DirentCollector) OrderedDirents

func (d *DirentCollector) OrderedDirents() []*vfs.Dirent

OrderedDirents returns an ordered list of dirents as discovered by this collector.

func (*DirentCollector) SkipDotsChecks

func (d *DirentCollector) SkipDotsChecks(value bool)

SkipDotsChecks enables or disables the implicit checks on "." and ".." when the collector is used in various Assert* functions. Note that "." and ".." are still collected if passed to d.Handle, so the caller should only disable the checks when they aren't expected.

type DirentType

type DirentType = uint8

DirentType is an alias for values for linux_dirent64.d_type.

type System

type System struct {
	Ctx   context.Context
	Creds *auth.Credentials
	VFS   *vfs.VirtualFilesystem
	Root  vfs.VirtualDentry
	MntNs *vfs.MountNamespace
	// contains filtered or unexported fields
}

System represents the context for a single test.

Test systems must be explicitly destroyed with System.Destroy.

func NewSystem

func NewSystem(ctx context.Context, t *testing.T, v *vfs.VirtualFilesystem, mns *vfs.MountNamespace) *System

NewSystem constructs a System.

Precondition: Caller must hold a reference on mns, whose ownership is transferred to the new System.

func (*System) AssertAllDirentTypes

func (s *System) AssertAllDirentTypes(collector *DirentCollector, expected map[string]DirentType)

AssertAllDirentTypes verifies that the set of dirents in collector contains exactly the specified set of expected entries. AssertAllDirentTypes respects collector.skipDots, and implicitly checks for "." and ".." accordingly.

func (*System) AssertDirentOffsets

func (s *System) AssertDirentOffsets(collector *DirentCollector, expected map[string]int64)

AssertDirentOffsets verifies that collector contains at least the entries specified in expected, with the given NextOff field. Entries specified in expected but missing from collector result in failure. Extra entries in collector are ignored. AssertDirentOffsets respects collector.skipDots, and implicitly checks for "." and ".." accordingly.

func (*System) Destroy

func (s *System) Destroy()

Destroy release resources associated with a test system.

func (*System) GetDentryOrDie

func (s *System) GetDentryOrDie(pop *vfs.PathOperation) vfs.VirtualDentry

GetDentryOrDie attempts to resolve a dentry referred to by the provided path operation. If unsuccessful, the test fails.

func (*System) ListDirents

func (s *System) ListDirents(pop *vfs.PathOperation) *DirentCollector

ListDirents lists the Dirents for a directory at pop.

func (*System) PathOpAtRoot

func (s *System) PathOpAtRoot(path string) *vfs.PathOperation

PathOpAtRoot constructs a PathOperation with the given path from the root of the filesystem.

func (*System) ReadToEnd

func (s *System) ReadToEnd(fd *vfs.FileDescription) (string, error)

ReadToEnd reads the contents of fd until EOF to a string.

func (*System) WithSubtest

func (s *System) WithSubtest(t *testing.T) *System

WithSubtest creates a temporary test system with a new test harness, referencing all other resources from the original system. This is useful when a system is reused for multiple subtests, and the T needs to change for each case. Note that this is safe when test cases run in parallel, as all resources referenced by the system are immutable, or handle interior mutations in a thread-safe manner.

The returned system must not outlive the original and should not be destroyed via System.Destroy.

func (*System) WithTemporaryContext

func (s *System) WithTemporaryContext(ctx context.Context) *System

WithTemporaryContext constructs a temporary test system with a new context ctx. The temporary system borrows all resources and references from the original system. The returned temporary system must not outlive the original system, and should not be destroyed via System.Destroy.

Jump to

Keyboard shortcuts

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