mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-04-26 13:48:49 +08:00
sysfs: increase test coverage
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
39e7ec000d
commit
eefe547d25
@ -47,8 +47,12 @@ func TestPwmPin(t *testing.T) {
|
||||
|
||||
gobottest.Assert(t, pin.InvertPolarity(true), nil)
|
||||
gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm10/polarity"].Contents, "inverted")
|
||||
pol, _ := pin.Polarity()
|
||||
gobottest.Assert(t, pol, "inverted")
|
||||
gobottest.Assert(t, pin.InvertPolarity(false), nil)
|
||||
gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm10/polarity"].Contents, "normal")
|
||||
pol, _ = pin.Polarity()
|
||||
gobottest.Assert(t, pol, "normal")
|
||||
|
||||
gobottest.Refute(t, fs.Files["/sys/class/pwm/pwmchip0/pwm10/duty_cycle"].Contents, "1")
|
||||
err = pin.SetDutyCycle(100)
|
||||
@ -115,3 +119,43 @@ func TestPwmPinPeriodError(t *testing.T) {
|
||||
_, err := pin.Period()
|
||||
gobottest.Refute(t, err, nil)
|
||||
}
|
||||
|
||||
func TestPwmPinPolarityError(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.Polarity()
|
||||
gobottest.Refute(t, err, nil)
|
||||
}
|
||||
|
||||
func TestPwmPinDutyCycleError(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.DutyCycle()
|
||||
gobottest.Refute(t, err, nil)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user