emulator

package
v0.0.0-...-bbc9ce3 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: BSD-2-Clause Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultVirtualDevice

func DefaultVirtualDevice(arch string) *fvdpb.VirtualDevice

DefaultVirtualDevice returns a virtual device configuration for testing.

The returned virtual device is compatible with the image manifest produced by a Fuchsia build for the specified architecture.

Types

type Arch

type Arch string

Arch is the architecture to emulate.

const (
	X64   Arch = "x64"
	Arm64 Arch = "arm64"
)

type Disk

type Disk struct {
	Path string
	USB  bool
}

Disk represents a single disk that will be attached to the virtual machine.

type Distribution

type Distribution struct {
	Emulator Emulator
	// contains filtered or unexported fields
}

Distribution is a collection of QEMU-related artifacts.

Delete must be called once done with it.

func UnpackFrom

func UnpackFrom(path string, distroParams DistributionParams) (*Distribution, error)

UnpackFrom unpacks the emulator distribution.

path is the path to host_x64/test_data containing the emulator. emulator is the emulator to unpack.

func (*Distribution) Create

func (d *Distribution) Create(fvd *fvdpb.VirtualDevice) (*Instance, error)

Create creates an instance of the emulator with the given parameters.

func (*Distribution) Delete

func (d *Distribution) Delete() error

Delete removes the emulator-related artifacts.

func (*Distribution) RunNonInteractive

func (d *Distribution) RunNonInteractive(toRun, hostPathMinfsBinary, hostPathZbiBinary string, fvd *fvdpb.VirtualDevice) (string, string, error)

RunNonInteractive runs an instance of the emulator that runs a single command and returns the log that results from doing so.

This mode is non-interactive and is intended specifically to test the case where the serial port has been disabled. The following modifications are made to the emulator invocation compared with Create()/Start():

  • amalgamate the given ZBI into a larger one that includes an additional entry of a script which includes commands to run.
  • that script mounts a disk created on the host in /tmp, and runs the given command with output redirected to a file also on the /tmp disk
  • the script triggers shutdown of the machine
  • after emulator shutdown, the log file is extracted and returned.

In order to achieve this, here we need to create the host minfs file system, write the commands to run, build the augmented .zbi to be used to boot. We then use Start() and wait for shutdown. Finally, extract and return the log from the minfs disk.

func (*Distribution) TargetCPU

func (d *Distribution) TargetCPU() (Arch, error)

TargetCPU returns the target CPU used by the build that produced this library.

type DistributionParams

type DistributionParams struct {
	Emulator Emulator
}

DistributionParams is passed to UnpackFrom().

type Emulator

type Emulator int

Emulator is the emulator to use.

const (
	Qemu Emulator = iota
	Femu
)

type Instance

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

Instance is a live emulator instance.

func (*Instance) AssertLogMessageNotSeenWithinTimeout

func (i *Instance) AssertLogMessageNotSeenWithinTimeout(notSeen string, timeout time.Duration) error

AssertLogMessageNotSeenWithinTimeout will fail if |notSeen| is seen within the |timeout| period. This function will timeout as success if more than |timeout| has passed without seeing |notSeen|.

func (*Instance) CaptureLinesContaining

func (i *Instance) CaptureLinesContaining(msg string, stop string) ([]string, error)

CaptureLinesContaining returns all the lines that contain the given msg, up until a line containing stop is found.

func (*Instance) Kill

func (i *Instance) Kill() error

Kill terminates the emulator instance.

func (*Instance) RunCommand

func (i *Instance) RunCommand(cmd string) error

RunCommand runs the given command in the serial console for the emulator instance.

func (*Instance) Start

func (i *Instance) Start() error

Start the emulator instance.

func (*Instance) StartPiped

func (i *Instance) StartPiped(piped *exec.Cmd) error

StartPiped starts the emulator instance with stdin/stdout piped through a different process.

Assumes that the stderr from the piped process should replace the stdout from the emulator.

func (*Instance) Wait

func (i *Instance) Wait() (*os.ProcessState, error)

Wait for the emulator instance to terminate

func (*Instance) WaitForAnyLogMessage

func (i *Instance) WaitForAnyLogMessage(msgs ...string) (string, error)

WaitForAnyLogMessage reads log messages from the emulator instance looking for any line that contains a message from msgs. Returns the first message that was found, or an error.

func (*Instance) WaitForLogMessage

func (i *Instance) WaitForLogMessage(msg string) error

WaitForLogMessage reads log messages from the emulator instance until it reads a message that contains the given string.

func (*Instance) WaitForLogMessageAssertNotSeen

func (i *Instance) WaitForLogMessageAssertNotSeen(msg string, notSeen string) error

WaitForLogMessageAssertNotSeen is the same as WaitForLogMessage() but with the addition that it will return an error if |notSeen| is contained in a retrieved message.

func (*Instance) WaitForLogMessages

func (i *Instance) WaitForLogMessages(msgs []string) error

WaitForLogMessages reads log messages from the emulator instance until it reads all message in |msgs|. The log messages can appear in *any* order. Only one expected message from |msgs| is retired per matching actual message even if multiple messages from |msgs| match the log line.

Directories

Path Synopsis
Package emulatortest wraps package emulator for use in unit tests.
Package emulatortest wraps package emulator for use in unit tests.

Jump to

Keyboard shortcuts

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