Documentation ¶
Overview ¶
Package testutil provides common test utilities for kernfs-based filesystems.
Index ¶
- func Boot() (*kernel.Kernel, error)
- func CreateTask(ctx context.Context, name string, tc *kernel.ThreadGroup, ...) (*kernel.Task, error)
- type DirentCollector
- func (d *DirentCollector) Contains(name string, typ uint8) error
- func (d *DirentCollector) Count() int
- func (d *DirentCollector) Dirents() map[string]*vfs.Dirent
- func (d *DirentCollector) Handle(dirent vfs.Dirent) error
- func (d *DirentCollector) OrderedDirents() []*vfs.Dirent
- func (d *DirentCollector) SkipDotsChecks(value bool)
- type DirentType
- type System
- func (s *System) AssertAllDirentTypes(collector *DirentCollector, expected map[string]DirentType)
- func (s *System) AssertDirentOffsets(collector *DirentCollector, expected map[string]int64)
- func (s *System) Destroy()
- func (s *System) GetDentryOrDie(pop *vfs.PathOperation) vfs.VirtualDentry
- func (s *System) ListDirents(pop *vfs.PathOperation) *DirentCollector
- func (s *System) PathOpAtRoot(path string) *vfs.PathOperation
- func (s *System) ReadToEnd(fd *vfs.FileDescription) (string, error)
- func (s *System) WithSubtest(t *testing.T) *System
- func (s *System) WithTemporaryContext(ctx context.Context) *System
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
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.