machine

package
v0.0.0-...-1dd1f65 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package machine contains models for compiler-bearing machines.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNoMachine = errors.New("no such machine")

ErrNoMachine occurs when we try to look up the compilers of a missing machine.

View Source
var ErrUnsupportedGOARCH = errors.New("local GOARCH not supported by prober")

ErrUnsupportedGOARCH occurs when a GOARCH not supported by the prober occurs

Functions

func ArchOfGOARCH

func ArchOfGOARCH(goarch string) (id.ID, error)

ArchOfGOARCH maps from the Go architecture goarch to a C4 architecture id. It fails with ErrUnsupportedGOARCH if the architecture isn't supported by C4.

func OnMachines

func OnMachines(m Message, obs ...Observer)

OnMachines broadcasts the message m to every observer in obs.

func OnMachinesFinish

func OnMachinesFinish(obs ...Observer)

OnMachinesFinish broadcasts the end of a machines block to every observer in obs.

func OnMachinesRecord

func OnMachinesRecord(index int, machine Named, obs ...Observer)

OnMachinesRecord broadcasts a record in a machines block to every observer in obs.

func OnMachinesStart

func OnMachinesStart(nmachines int, obs ...Observer)

OnMachinesStart broadcasts the start of a machines block to every observer in obs.

Types

type Config

type Config struct {
	Machine

	// Arch is the default architecture for compilers in this configuration.
	Arch id.ID `toml:"arch,omitempty"`

	// RawCompilers contains raw information about the compilers attached to this machine.
	//
	// The keys are strings that will become IDs in the fully processed compiler map.
	// We don't store them as IDs here, to avoid issues with TOML serialisation.
	//
	// This doesn't contain machine-level defaults; use Compilers() to get a fully resolved version.
	RawCompilers compiler.ConfigMap `toml:"compilers,omitempty"`

	// Mutation contains information about how to mutation-test on this machine.
	Mutation *mutation.Config `toml:"mutation,omitempty"`
}

Config is a config record for a particular machine.

The difference between a Machine and a Config is that the latter contains raw configuration data for things that get mapped into expanded forms in the plan, for instance compilers.

func (*Config) Compilers

func (c *Config) Compilers() (map[id.ID]compiler.Compiler, error)

Compilers prepares a fully resolved compiler map, with any machine defaults filled in. It errors if there are missing parts of compiler configuration for a particular compiler, or if there is a problem with the compiler ID.

This is always a separate map from RawCompilers, even when no defaults exist.

func (*Config) Probe

func (c *Config) Probe(m Prober) error

Probe populates this config using the prober m.

type ConfigMap

type ConfigMap map[id.ID]Config

ConfigMap is a map from IDs to machine configuration.

func (ConfigMap) Filter

func (m ConfigMap) Filter(glob id.ID) (ConfigMap, error)

Filter filters this Config's machines according to glob.

Example

ExampleConfigMap_Filter is a runnable example for Filter.

package main

import (
	"fmt"

	"github.com/c4-project/c4t/internal/id"

	"github.com/c4-project/c4t/internal/machine"
)

func main() {
	cm := machine.ConfigMap{
		id.FromString("bar"):         machine.Config{Machine: machine.Machine{Cores: 1}},
		id.FromString("foo.bar"):     machine.Config{Machine: machine.Machine{Cores: 2}},
		id.FromString("foo.bar.baz"): machine.Config{Machine: machine.Machine{Cores: 3}},
		id.FromString("foo.baz"):     machine.Config{Machine: machine.Machine{Cores: 4}},
	}
	cm, _ = cm.Filter(id.FromString("foo.*.baz"))
	ids, _ := cm.IDs()
	for _, n := range ids {
		fmt.Println(n)
	}

}
Output:

foo.bar.baz
foo.baz

func (ConfigMap) IDs

func (m ConfigMap) IDs() ([]id.ID, error)

IDs gets a sorted slice of IDs present in this machine map. It returns an error if any of the configured machines have an invalid ID.

Example

ExampleConfigMap_IDs is a runnable example for IDs.

package main

import (
	"fmt"

	"github.com/c4-project/c4t/internal/machine"
)

func main() {
	cm := machine.ConfigMap{
		id.FromString("localhost"): machine.Config{Machine: machine.Machine{Cores: 3}},
		id.FromString("bar"):       machine.Config{Machine: machine.Machine{Cores: 1}},
		id.FromString("foo.bar"):   machine.Config{Machine: machine.Machine{Cores: 2}},
	}
	ids, _ := cm.IDs()
	for _, n := range ids {
		fmt.Println(n)
	}

}
Output:

bar
foo.bar
localhost

func (ConfigMap) ListCompilers

func (m ConfigMap) ListCompilers(_ context.Context, machine id.ID) (map[id.ID]compiler.Compiler, error)

ListCompilers implements the compiler listing operation using a config.

func (ConfigMap) ObserveOn

func (m ConfigMap) ObserveOn(obs ...Observer) error

ObserveOn sends this map to obs as a series of machine observations.

type Machine

type Machine struct {
	// Cores is the number of known cores on the machine.
	// If zero, there is no known core count.
	Cores int `toml:"cores,omitzero" json:"cores,omitempty"`

	// SSH contains, if present, information about how to dial into a remote machine through SSH.
	SSH *remote.MachineConfig `toml:"ssh,omitempty" json:"ssh,omitempty"`

	// Quantities contains, if present, quantity overrides for this machine.
	Quantities *quantity.MachineSet `toml:"quantities,omitempty,omitzero" json:"quantities,omitempty"`
}

Machine represents the information about a machine that is relevant to the tester.

type Message

type Message struct {
	// Kind is the kind of message being sent.
	Kind MessageKind
	// Index is the index, or count, depending on the kind.
	Index int
	// Machine, if present, gives information about the machine being described.
	Machine *Named
}

Message outlines a machine information message.

type MessageKind

type MessageKind uint8

MessageKind is the enumeration of machine observer message kinds.

const (
	// MessageStart signifies that this machine message is starting a machine block.
	// Index stores the number of machines being defined.
	MessageStart MessageKind = iota
	// MessageRecord signifies that this machine message is defining a machine.
	// Index stores the index of the machine being defined.
	MessageRecord
	// MessageFinish signifies the end of a machine block.
	MessageFinish
)

type Named

type Named struct {
	// ID is the ID of the machine.
	ID id.ID `toml:"id,omitzero" json:"id,omitempty"`
	Machine
}

Named wraps a plan machine with its ID.

type Observer

type Observer interface {
	// OnMachines sends an observation about the machines defined on a tester.
	OnMachines(m Message)
}

Observer is the observer interface for machine configuration.

type Prober

type Prober interface {
	// Hostname gets the full hostname of the machine.
	Hostname() (string, error)

	// NCores gets the number of cores available for the machine.
	NCores() (int, error)

	// Arch gets the architecture ID for the machine.
	Arch() (id.ID, error)
}

Prober contains functionality for probing various parts of a machine.

func LocalProber

func LocalProber() Prober

LocalProber gets a prober that probes the local system.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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