periph: periph.io/x/periph/conn/onewire/onewiretest Index | Files

package onewiretest

import "periph.io/x/periph/conn/onewire/onewiretest"

Package onewiretest is meant to be used to test drivers over a fake 1-wire bus.

Index

Package Files

onewiretest.go

type IO Uses

type IO struct {
    W    []byte
    R    []byte
    Pull onewire.Pullup
}

IO registers the I/O that happened on either a real or fake 1-wire bus.

type Playback Uses

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) Close Uses

func (p *Playback) Close() error

Close implements onewire.BusCloser.

func (*Playback) Q Uses

func (p *Playback) Q() gpio.PinIO

Q implements onewire.Pins.

func (*Playback) Search Uses

func (p *Playback) Search(alarmOnly bool) ([]onewire.Address, error)

Search implements onewire.Bus using the Search function (which calls SearchTriplet).

func (*Playback) SearchTriplet Uses

func (p *Playback) SearchTriplet(direction byte) (onewire.TripletResult, error)

SearchTriplet implements onewire.BusSearcher.

func (*Playback) String Uses

func (p *Playback) String() string

func (*Playback) Tx Uses

func (p *Playback) Tx(w, r []byte, pull onewire.Pullup) error

Tx implements onewire.Bus.

type Record Uses

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.

func (*Record) Q Uses

func (r *Record) Q() gpio.PinIO

Q implements onewire.Pins.

func (*Record) Search Uses

func (r *Record) Search(alarmOnly bool) ([]onewire.Address, error)

Search implements onewire.Bus

func (*Record) String Uses

func (r *Record) String() string

func (*Record) Tx Uses

func (r *Record) Tx(w, read []byte, pull onewire.Pullup) error

Tx implements onewire.Bus.

Package onewiretest imports 5 packages (graph). Updated 2017-12-31. Refresh now. Tools for package owners.