mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-04-27 13:48:56 +08:00
sysfs: increase test coverage for pwm pin
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
11c55dcc60
commit
73a85aecdf
@ -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) {
|
||||
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user