Documentation
¶
Overview ¶
Package mock provides in-memory hal.HAL implementations for use in tests and simulation environments.
All fields are exported so tests can set initial state and inspect results directly. Methods are safe for concurrent use only if the test sets fields before calling [NewHAL] and does not mutate them afterwards; for race-free concurrent tests, protect shared state with a mutex in a custom sub-struct.
Index ¶
- type Chassis
- func (c *Chassis) ColdReset(_ context.Context) error
- func (c *Chassis) GetBootFlags(_ context.Context) (*types.BootOptionParam_BootFlags, error)
- func (c *Chassis) GetBootInfoAcknowledge(_ context.Context) (*types.BootOptionParam_BootInfoAcknowledge, error)
- func (c *Chassis) Identify(_ context.Context, seconds uint8) error
- func (c *Chassis) IntrusionState(_ context.Context) (bool, error)
- func (c *Chassis) PowerCycle(_ context.Context) error
- func (c *Chassis) PowerState(_ context.Context) (bool, error)
- func (c *Chassis) SetBootFlags(_ context.Context, flags *types.BootOptionParam_BootFlags) error
- func (c *Chassis) SetBootInfoAcknowledge(_ context.Context, ack *types.BootOptionParam_BootInfoAcknowledge) error
- func (c *Chassis) SetPower(_ context.Context, on bool) error
- func (c *Chassis) WarmReset(_ context.Context) error
- type Console
- type FakeConsoleConn
- func (f *FakeConsoleConn) Close() error
- func (f *FakeConsoleConn) FeedRX(p []byte)
- func (f *FakeConsoleConn) IsClosed() bool
- func (f *FakeConsoleConn) ReadAvailable(p []byte) (int, error)
- func (f *FakeConsoleConn) SendBreak(_ context.Context) error
- func (f *FakeConsoleConn) SetReadErr(err error)
- func (f *FakeConsoleConn) SetWriteErr(err error)
- func (f *FakeConsoleConn) TXString() string
- func (f *FakeConsoleConn) Write(p []byte) (int, error)
- type GPIO
- type HAL
- func (h *HAL) Chassis() hal.ChassisHAL
- func (h *HAL) Close() error
- func (h *HAL) Console() hal.ConsoleHAL
- func (h *HAL) GPIO() hal.GPIOHAL
- func (h *HAL) I2C() hal.I2CHAL
- func (h *HAL) Network() hal.NetworkHAL
- func (h *HAL) Sensors() hal.SensorHAL
- func (h *HAL) SetConsole(c hal.ConsoleHAL)
- func (h *HAL) Storage() hal.StorageHAL
- type I2C
- type I2CWrite
- type Network
- type Sensors
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chassis ¶
type Chassis struct {
On bool
Intruded bool
ColdResets int
WarmResets int
PowerCycles int
LastIdentifySec uint8
BootFlags *types.BootOptionParam_BootFlags
BootInfoAck *types.BootOptionParam_BootInfoAcknowledge
// Hook allows tests to inject custom behaviour.
SetPowerHook func(on bool) error
// contains filtered or unexported fields
}
Chassis is the mock hal.ChassisHAL.
func (*Chassis) GetBootFlags ¶
GetBootFlags returns the last stored boot flags, or hal.ErrNotSupported when none have been set.
func (*Chassis) GetBootInfoAcknowledge ¶
func (c *Chassis) GetBootInfoAcknowledge(_ context.Context) (*types.BootOptionParam_BootInfoAcknowledge, error)
GetBootInfoAcknowledge returns the last stored acknowledge data, or a default value when none have been stored.
func (*Chassis) PowerCycle ¶
PowerCycle performs a power cycle. The mock counts calls independently so tests can assert that Chassis Control action 0x02 dispatched here rather than to ColdReset. Real noop HALs that lack a distinct power-cycle operation may delegate to ColdReset; the mock keeps the counters separate for clarity.
func (*Chassis) SetBootFlags ¶
SetBootFlags stores the full boot flags structure so tests and the reference server can round-trip Set/Get System Boot Options.
func (*Chassis) SetBootInfoAcknowledge ¶
func (c *Chassis) SetBootInfoAcknowledge(_ context.Context, ack *types.BootOptionParam_BootInfoAcknowledge) error
SetBootInfoAcknowledge stores the boot info acknowledge data.
type Console ¶ added in v0.9.1
type Console struct {
// Conn is returned by Open when OpenHook is nil. Nil means "no console
// hardware": Open then returns hal.ErrNotSupported.
Conn hal.ConsoleConn
// OpenHook allows tests to inject custom behaviour (e.g. fail the open).
OpenHook func(ctx context.Context) (hal.ConsoleConn, error)
// OpenCount records how many activations attached to the console.
OpenCount int
// contains filtered or unexported fields
}
Console is the mock hal.ConsoleHAL.
type FakeConsoleConn ¶ added in v0.9.1
type FakeConsoleConn struct {
// RX holds console output waiting to be drained by ReadAvailable.
RX []byte
// TX records everything written toward the system console.
TX []byte
Closed bool
Breaks int
WriteErr error
ReadErr error
// WriteLimit, when > 0, caps how many bytes a single Write accepts,
// forcing the partial accepts (and NACKs) a flow-controlled serial
// controller produces.
WriteLimit int
// contains filtered or unexported fields
}
FakeConsoleConn is an in-memory hal.ConsoleConn for tests.
func (*FakeConsoleConn) Close ¶ added in v0.9.1
func (f *FakeConsoleConn) Close() error
func (*FakeConsoleConn) FeedRX ¶ added in v0.9.1
func (f *FakeConsoleConn) FeedRX(p []byte)
FeedRX appends bytes to the pending console output, as if the system had written them to its serial port. Safe for concurrent use with a running SOL session, unlike direct RX mutation.
func (*FakeConsoleConn) IsClosed ¶ added in v0.9.1
func (f *FakeConsoleConn) IsClosed() bool
IsClosed reports whether Close was called. Safe for concurrent use with a running SOL session, unlike direct Closed reads.
func (*FakeConsoleConn) ReadAvailable ¶ added in v0.9.1
func (f *FakeConsoleConn) ReadAvailable(p []byte) (int, error)
func (*FakeConsoleConn) SendBreak ¶ added in v0.9.1
func (f *FakeConsoleConn) SendBreak(_ context.Context) error
func (*FakeConsoleConn) SetReadErr ¶ added in v0.9.1
func (f *FakeConsoleConn) SetReadErr(err error)
SetReadErr arms a read failure for the next ReadAvailable, safe for concurrent use with a running SOL session (unlike direct ReadErr writes).
func (*FakeConsoleConn) SetWriteErr ¶ added in v0.9.1
func (f *FakeConsoleConn) SetWriteErr(err error)
SetWriteErr arms a write failure for the next Write, safe for concurrent use with a running SOL session (unlike direct WriteErr writes).
func (*FakeConsoleConn) TXString ¶ added in v0.9.1
func (f *FakeConsoleConn) TXString() string
TXString returns everything written toward the system console so far.
type GPIO ¶
type GPIO struct {
// contains filtered or unexported fields
}
GPIO is the mock hal.GPIOHAL.
type HAL ¶
type HAL struct {
// contains filtered or unexported fields
}
HAL is a fully in-memory hal.HAL.
func New ¶
func New() *HAL
New returns a HAL with all sub-interfaces initialised. Each sub-type is also exported individually for targeted embedding.
The console sub-interface is left unset: most simulated targets have no redirectable serial port, so HAL.Console returns nil until HAL.SetConsole installs one.
func (*HAL) Chassis ¶
func (h *HAL) Chassis() hal.ChassisHAL
func (*HAL) Console ¶ added in v0.9.1
func (h *HAL) Console() hal.ConsoleHAL
Console returns the console installed by HAL.SetConsole, or nil when the simulated target has no redirectable serial port.
func (*HAL) Network ¶
func (h *HAL) Network() hal.NetworkHAL
func (*HAL) SetConsole ¶ added in v0.9.1
func (h *HAL) SetConsole(c hal.ConsoleHAL)
SetConsole installs the console sub-interface returned by HAL.Console. Tests typically pass *Console; production wiring may pass any hal.ConsoleHAL implementation.
func (*HAL) Storage ¶
func (h *HAL) Storage() hal.StorageHAL
type I2C ¶
type I2C struct {
ReadFunc func(bus int, addr, reg uint8, length int) ([]byte, error)
Writes []I2CWrite
// contains filtered or unexported fields
}
I2C is the mock hal.I2CHAL. Reads return data from ReadFunc if set, otherwise ErrNotSupported.
type Network ¶
Network is the mock hal.NetworkHAL.
type Sensors ¶
type Sensors struct {
Values map[uint8]uint8
Descs []hal.SensorDescriptor
// contains filtered or unexported fields
}
Sensors is the mock hal.SensorHAL.