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 GPIO
- type HAL
- 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 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.
func (*HAL) Chassis ¶
func (h *HAL) Chassis() hal.ChassisHAL
func (*HAL) Network ¶
func (h *HAL) Network() hal.NetworkHAL
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.