beaglebone: increase test coverage

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2017-05-03 12:59:49 +02:00
parent 45b52aa9c9
commit 4ac652ab19
2 changed files with 62 additions and 1 deletions

View File

@ -9,7 +9,7 @@ For more info about the BeagleBone platform go to [http://beagleboard.org/getti
## How to Install
We recommend updating to the latest Debian Jessie OS when using the BeagleBone, however Gobot should also support older versions of the OS, should your application require this.
We recommend updating to the latest Debian Jessie OS when using the BeagleBone. The current Gobot only supports 4.x versions of the OS. If you need support for older versions of the OS, you will need to use Gobot v1.4.
You would normally install Go and Gobot on your workstation. Once installed, cross compile your program on your workstation, transfer the final executable to your BeagleBone, and run the program on the BeagleBone itself as documented here.

View File

@ -174,3 +174,64 @@ func TestBeagleboneGetConnectionInvalidBus(t *testing.T) {
_, err := a.GetConnection(0x01, 99)
gobottest.Assert(t, err, errors.New("Bus number 99 out of range"))
}
func TestBeagleboneConnectNoSlot(t *testing.T) {
fs := sysfs.NewMockFilesystem([]string{
"/dev/i2c-2",
})
sysfs.SetFilesystem(fs)
a := NewAdaptor()
err := a.Connect()
gobottest.Assert(t, strings.Contains(err.Error(), "/sys/devices/platform/bone_capemgr/slots: No such file."), true)
}
func TestBeagleboneAnalogReadFileError(t *testing.T) {
fs := sysfs.NewMockFilesystem([]string{
"/sys/devices/platform/bone_capemgr/slots",
})
sysfs.SetFilesystem(fs)
a := NewAdaptor()
a.Connect()
_, err := a.AnalogRead("P9_40")
gobottest.Assert(t, strings.Contains(err.Error(), "/sys/bus/iio/devices/iio:device0/in_voltage1_raw: No such file."), true)
}
func TestBeagleboneDigitalPinDirectionFileError(t *testing.T) {
fs := sysfs.NewMockFilesystem([]string{
"/sys/devices/platform/bone_capemgr/slots",
"/sys/class/gpio/export",
"/sys/class/gpio/gpio60/value",
})
sysfs.SetFilesystem(fs)
a := NewAdaptor()
a.Connect()
err := a.DigitalWrite("P9_12", 1)
gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/gpio/gpio60/direction: No such file."), true)
err = a.Finalize()
gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/gpio/unexport: No such file."), true)
}
func TestBeagleboneDigitalPinFinalizeFileError(t *testing.T) {
fs := sysfs.NewMockFilesystem([]string{
"/sys/devices/platform/bone_capemgr/slots",
"/sys/class/gpio/export",
"/sys/class/gpio/gpio60/value",
"/sys/class/gpio/gpio60/direction",
})
sysfs.SetFilesystem(fs)
a := NewAdaptor()
a.Connect()
err := a.DigitalWrite("P9_12", 1)
gobottest.Assert(t, err, nil)
err = a.Finalize()
gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/gpio/unexport: No such file."), true)
}