test: fix pad ring test for small pad ranges

The current tests worked because all rings had the same range, so our error
margin covered for that. With the upcoming MobileStudio Pro 16 pad device, the
range is half and our error margins don't work anymore. Switch to a more
reliable approach that tests every integer value the wheel can send, even
though it relies on kernel filtering.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit e3e6406c4f)
This commit is contained in:
Peter Hutterer 2017-08-28 09:16:53 +10:00
parent 62a9db6ddf
commit ed7ef90534

View file

@ -270,6 +270,9 @@ START_TEST(pad_ring)
struct libinput_event_tablet_pad *pev;
int val;
double degrees, expected;
int min, max;
int step_size;
int nevents = 0;
litest_pad_ring_start(dev, 10);
@ -278,11 +281,28 @@ START_TEST(pad_ring)
/* Wacom's 0 value is at 275 degrees */
expected = 270;
for (val = 0; val < 100; val += 10) {
min = libevdev_get_abs_minimum(dev->evdev, ABS_WHEEL);
max = libevdev_get_abs_maximum(dev->evdev, ABS_WHEEL);
step_size = 360/(max - min + 1);
/* This is a bit strange because we rely on kernel filtering here.
The litest_*() functions take a percentage, but mapping this to
the pads 72 or 36 range pad ranges is lossy and a bit
unpredictable. So instead we increase by a small percentage,
expecting *most* events to be filtered by the kernel because they
resolve to the same integer value as the previous event. Whenever
an event gets through, we expect that to be the next integer
value in the range and thus the next step on the circle.
*/
for (val = 0; val < 100.0; val += 1) {
litest_pad_ring_change(dev, val);
libinput_dispatch(li);
ev = libinput_get_event(li);
if (!ev)
continue;
nevents++;
pev = litest_is_pad_ring_event(ev,
0,
LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER);
@ -291,15 +311,14 @@ START_TEST(pad_ring)
ck_assert_double_ge(degrees, 0.0);
ck_assert_double_lt(degrees, 360.0);
/* rounding errors, mostly caused by small physical range */
ck_assert_double_ge(degrees, expected - 2);
ck_assert_double_le(degrees, expected + 2);
ck_assert_double_eq(degrees, expected);
libinput_event_destroy(ev);
expected = fmod(degrees + 36, 360);
expected = fmod(degrees + step_size, 360);
}
ck_assert_int_eq(nevents, 360/step_size - 1);
litest_pad_ring_end(dev);
}
END_TEST