onewiretest

package
v3.6.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IO

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

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

func (p *Playback) Close() error

Close implements onewire.BusCloser.

func (*Playback) Q

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

Q implements onewire.Pins.

func (*Playback) Search

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

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.

func (*Playback) String

func (p *Playback) String() string

func (*Playback) Tx

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

Tx implements onewire.Bus.

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.

func (*Record) Q

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

Q implements onewire.Pins.

func (*Record) Search

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

Search implements onewire.Bus

func (*Record) String

func (r *Record) String() string

func (*Record) Tx

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

Tx implements onewire.Bus.

Jump to

Keyboard shortcuts

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