periph: periph.io/x/periph/conn/i2c/i2ctest Index | Files

package i2ctest

import "periph.io/x/periph/conn/i2c/i2ctest"

Package i2ctest is meant to be used to test drivers over a fake I²C bus.

Index

Package Files

i2ctest.go

type IO Uses

type IO struct {
    Addr uint16
    W    []byte
    R    []byte
}

IO registers the I/O that happened on either a real or fake I²C bus.

type Playback Uses

type Playback struct {
    sync.Mutex
    Ops       []IO
    Count     int
    DontPanic bool
    SDAPin    gpio.PinIO
    SCLPin    gpio.PinIO
}

Playback implements i2c.Bus and plays back a recorded I/O flow.

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 i2c.BusCloser.

Close() verifies that all the expected Ops have been consumed.

func (*Playback) SCL Uses

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

SCL implements i2c.Pins.

func (*Playback) SDA Uses

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

SDA implements i2c.Pins.

func (*Playback) SetSpeed Uses

func (p *Playback) SetSpeed(f physic.Frequency) error

SetSpeed implements i2c.Bus.

func (*Playback) String Uses

func (p *Playback) String() string

func (*Playback) Tx Uses

func (p *Playback) Tx(addr uint16, w, r []byte) error

Tx implements i2c.Bus.

type Record Uses

type Record struct {
    sync.Mutex
    Bus i2c.Bus // Bus can be nil if only writes are being recorded.
    Ops []IO
}

Record implements i2c.Bus that records everything written to it.

This can then be used to feed to Playback to do "replay" based unit tests.

Record doesn't implement i2c.BusCloser on purpose.

func (*Record) SCL Uses

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

SCL implements i2c.Pins.

func (*Record) SDA Uses

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

SDA implements i2c.Pins.

func (*Record) SetSpeed Uses

func (r *Record) SetSpeed(f physic.Frequency) error

SetSpeed implements i2c.Bus.

func (*Record) String Uses

func (r *Record) String() string

func (*Record) Tx Uses

func (r *Record) Tx(addr uint16, w, read []byte) error

Tx implements i2c.Bus

Package i2ctest imports 6 packages (graph) and is imported by 4 packages. Updated 2018-08-17. Refresh now. Tools for package owners.