guest

package
v0.0.0-...-5d9f3d3 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package guest has functions for use in tests running in VM guests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectKernelCoverage

func CollectKernelCoverage()

CollectKernelCoverage saves the kernel coverage report to a tar file.

Assumes that the `vmmount` command has been used to mount the kernel coverage 9P shared dir at /mount/9p/kcoverage.

func Mount9PDir

func Mount9PDir(dir, tag string) (*mount.MountPoint, error)

Mount9PDir mounts a directory shared as tag at dir. It creates dir if it does not exist.

func SkipIfInVM

func SkipIfInVM(t testing.TB)

SkipIfInVM skips the test if it is running in a vmtest-started VM.

The presence of VMTEST_IN_GUEST=1 env var (which can be passed on the kernel commandline, using qemu.WithVmtestIdent) is used to determine this.

func SkipIfNotInVM

func SkipIfNotInVM(t testing.TB)

SkipIfNotInVM skips the test if it is not running in a vmtest-started VM.

The presence of VMTEST_IN_GUEST=1 env var (which can be passed on the kernel commandline, using qemu.WithVmtestIdent) is used to determine this.

func VirtioSerialDevice

func VirtioSerialDevice(name string) (string, error)

VirtioSerialDevice looks up the device path for the given virtio-serial name.

The name would be configured in the QEMU command-line (or e.g. with qemu.EventChannel).

Types

type Emitter

type Emitter[T any] struct {
	// contains filtered or unexported fields
}

Emitter is an event channel emitter.

func EventChannel

func EventChannel[T any](path string) (*Emitter[T], error)

EventChannel opens an event channel to the host over the given device.

Callers must call Close on Emitter to publish a final "done" event to signal the host no more events are coming. If the "done" event is not published, qemu.EventChannel is configured to return an error on VM exit on the host.

T should be the type of a JSON event being sent, matching the host configuration on qemu.EventChannel reading from this channel.

func SerialEventChannel

func SerialEventChannel[T any](name string) (*Emitter[T], error)

SerialEventChannel opens an event channel to the host over virtio-serial with the given virtio-serial port name.

Callers must call Close on Emitter to publish a final "done" event to signal the host no more events are coming. If the "done" event is not published, qemu.EventChannel is configured to return an error on VM exit on the host.

T should be the type of a JSON event being sent, matching the host configuration on qemu.EventChannel reading from this channel.

The name should match the qemu.EventChannel configuration on the host as well.

func (*Emitter[T]) Close

func (e *Emitter[T]) Close() error

Close sends the "done" event to assure the host there will be no more events and closes the event channel.

func (*Emitter[T]) Emit

func (e *Emitter[T]) Emit(t T) error

Emit emits one T event.

func (*Emitter[T]) Write

func (e *Emitter[T]) Write(p []byte) (int, error)

Write writes JSON bytes on the event channel. Write expects events to be separated by new lines. Callers may chunk their writes.

This makes the Emitter compatible with exec.Cmd.Stdout/Stderr for commands that emit JSON one line at a time.

Jump to

Keyboard shortcuts

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