Documentation ¶
Overview ¶
Package onewiretest is meant to be used to test drivers over a fake 1-wire bus.
Index ¶
- type IO
- type Playback
- func (p *Playback) Close() error
- func (p *Playback) Q() gpio.PinIO
- func (p *Playback) Search(alarmOnly bool) ([]onewire.Address, error)
- func (p *Playback) SearchTriplet(direction byte) (onewire.TripletResult, error)
- func (p *Playback) String() string
- func (p *Playback) Tx(w, r []byte, pull onewire.Pullup) error
- type Record
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Playback ¶
type Playback struct { sync.Mutex Ops []IO // recorded operations Count int Devices []onewire.Address // devices that respond to a search operation QPin gpio.PinIO DontPanic bool // contains filtered or unexported fields }
Playback implements onewire.Bus and plays back a recorded I/O flow.
The bus' search function is special-cased. When a Tx operation has 0xf0 in w[0] the search state is reset and subsequent triplet operations respond according to the list of Devices. In other words, Tx is replayed but the responses to SearchTriplet operations are simulated.
While "replay" type of unit tests are of limited value, they still present an easy way to do basic code coverage.
Set DontPanic to true to return an error instead of panicking, which is the default.
func (*Playback) Search ¶
Search implements onewire.Bus using the Search function (which calls SearchTriplet).
func (*Playback) SearchTriplet ¶
func (p *Playback) SearchTriplet(direction byte) (onewire.TripletResult, error)
SearchTriplet implements onewire.BusSearcher.
type Record ¶
type Record struct { sync.Mutex Bus onewire.Bus // Bus can be nil if only writes are being recorded. Ops []IO }
Record implements onewire.Bus that records everything written to it.
This can then be used to feed to Playback to do "replay" based unit tests.