i2ctest

package
v3.6.8 Latest Latest
Warning

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

Go to latest
Published: May 28, 2021 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IO

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

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

func (p *Playback) Close() error

Close implements i2c.BusCloser.

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

func (*Playback) SCL

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

SCL implements i2c.Pins.

func (*Playback) SDA

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

SDA implements i2c.Pins.

func (*Playback) SetSpeed

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

SetSpeed implements i2c.Bus.

func (*Playback) String

func (p *Playback) String() string

func (*Playback) Tx

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

Tx implements i2c.Bus.

type Record

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

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

SCL implements i2c.Pins.

func (*Record) SDA

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

SDA implements i2c.Pins.

func (*Record) SetSpeed

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

SetSpeed implements i2c.Bus.

func (*Record) String

func (r *Record) String() string

func (*Record) Tx

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

Tx implements i2c.Bus

Jump to

Keyboard shortcuts

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