From 63bc898a5d7817501c4378e6201dcf7886375983 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Wed, 3 May 2017 20:43:31 +0200 Subject: [PATCH] joule: remove incorrect pin assignment and improve test coverage Signed-off-by: deadprogram --- platforms/intel-iot/joule/joule_adaptor.go | 3 --- .../intel-iot/joule/joule_adaptor_test.go | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/platforms/intel-iot/joule/joule_adaptor.go b/platforms/intel-iot/joule/joule_adaptor.go index aebcbb59..6a2bbc4b 100644 --- a/platforms/intel-iot/joule/joule_adaptor.go +++ b/platforms/intel-iot/joule/joule_adaptor.go @@ -136,9 +136,6 @@ func (e *Adaptor) PWMPin(pin string) (sysfsPin sysfs.PWMPinner, err error) { sysPin := sysfsPinMap[pin] if sysPin.pwmPin != -1 { if e.pwmPins[sysPin.pwmPin] == nil { - if err = e.DigitalWrite(pin, 1); err != nil { - return - } e.pwmPins[sysPin.pwmPin] = sysfs.NewPWMPin(sysPin.pwmPin) if err = e.pwmPins[sysPin.pwmPin].Export(); err != nil { return diff --git a/platforms/intel-iot/joule/joule_adaptor_test.go b/platforms/intel-iot/joule/joule_adaptor_test.go index 52cf056f..35014eef 100644 --- a/platforms/intel-iot/joule/joule_adaptor_test.go +++ b/platforms/intel-iot/joule/joule_adaptor_test.go @@ -180,3 +180,21 @@ func TestAdaptorPwm(t *testing.T) { err = a.PwmWrite("4", 100) gobottest.Assert(t, err, errors.New("Not a PWM pin")) } + +func TestAdaptorPwmPinExportError(t *testing.T) { + a, fs := initTestAdaptor() + + delete(fs.Files, "/sys/class/pwm/pwmchip0/export") + + err := a.PwmWrite("25", 100) + gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/pwm/pwmchip0/export: No such file"), true) +} + +func TestAdaptorPwmPinEnableError(t *testing.T) { + a, fs := initTestAdaptor() + + delete(fs.Files, "/sys/class/pwm/pwmchip0/pwm0/enable") + + err := a.PwmWrite("25", 100) + gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/pwm/pwmchip0/pwm0/enable: No such file"), true) +}