Skip to content

Commit

Permalink
sysfs: increase test coverage for pwm pin
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Apr 21, 2017
1 parent 11c55dc commit 73a85ae
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions sysfs/pwm_pin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func TestPwmPin(t *testing.T) {
fs.Files["/sys/class/pwm/pwmchip0/pwm10/period"].Contents = "6"
data, _ := pin.Period()
gobottest.Assert(t, data, "6")

gobottest.Refute(t, fs.Files["/sys/class/pwm/pwmchip0/pwm10/duty_cycle"].Contents, "1")
err = pin.WriteDuty("100")
gobottest.Assert(t, err, nil)
gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm10/duty_cycle"].Contents, "100")
}

func TestPwmPinExportError(t *testing.T) {
Expand Down Expand Up @@ -77,3 +82,23 @@ func TestPwmPinUnxportError(t *testing.T) {

gobottest.Refute(t, pin.Unexport(), nil)
}

func TestPwmPinPeriodError(t *testing.T) {
fs := NewMockFilesystem([]string{
"/sys/class/pwm/pwmchip0/export",
"/sys/class/pwm/pwmchip0/unexport",
"/sys/class/pwm/pwmchip0/pwm10/enable",
"/sys/class/pwm/pwmchip0/pwm10/period",
"/sys/class/pwm/pwmchip0/pwm10/duty_cycle",
})

SetFilesystem(fs)

pin := NewPwmPin(10)
pin.read = func(string) ([]byte, error) {
return nil, &os.PathError{Err: syscall.EBUSY}
}

_, err := pin.Period()
gobottest.Refute(t, err, nil)
}

0 comments on commit 73a85ae

Please sign in to comment.