[PATCH libinput 2/2] test: Add scale li_fixed overflow test
Add a test case and test device that checks if the scale transform can handle high resolution devices and output monitor resolutions. The test case is created in a way that it will fail if the coordinate transform expression will overflow if only 32 bit integer data containers are used. Signed-off-by: Jonas Ådahl jad...@gmail.com --- fwiw, this is exactly the type of use-case where it would be simple and worth it to knock up a test for a single device and make sure that the coordinates are correct. which gives us a nice reproducer and prevents us from errors like this in the future. And here is such a test case. It will fail as is, but pass if either the expression uses 64 bit integers or doubles. Jonas test/Makefile.am| 1 + test/litest-generic-highres-touch.c | 139 test/litest.c | 2 + test/litest.h | 1 + test/touch.c| 40 ++- 5 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 test/litest-generic-highres-touch.c diff --git a/test/Makefile.am b/test/Makefile.am index 59687f6..4b923aa 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -14,6 +14,7 @@ liblitest_la_SOURCES = \ litest-synaptics.c \ litest-trackpoint.c \ litest-wacom-touch.c \ + litest-generic-highres-touch.c \ litest.c run_tests = test-udev test-path test-pointer test-touch diff --git a/test/litest-generic-highres-touch.c b/test/litest-generic-highres-touch.c new file mode 100644 index 000..bd326ce --- /dev/null +++ b/test/litest-generic-highres-touch.c @@ -0,0 +1,139 @@ +/* + * Copyright © 2013 Red Hat, Inc. + * Copyright © 2014 Jonas Ådahl + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the name of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided as + * is without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include config.h + +#include litest.h +#include litest-int.h +#include libinput-util.h + +void litest_generic_highres_touch_setup(void) +{ + struct litest_device *d = + litest_create_device(LITEST_GENERIC_HIGHRES_TOUCH); + litest_set_current_device(d); +} + +void +litest_generic_highres_touch_touch_down(struct litest_device *d, + unsigned int slot, + int x, int y) +{ + static int tracking_id; + struct input_event *ev; + struct input_event down[] = { + { .type = EV_ABS, .code = ABS_X, .value = x }, + { .type = EV_ABS, .code = ABS_Y, .value = y }, + { .type = EV_ABS, .code = ABS_MT_SLOT, .value = slot }, + { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = ++tracking_id }, + { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = x }, + { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = y }, + { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 }, + { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, + }; + + down[0].value = litest_scale(d, ABS_X, x); + down[1].value = litest_scale(d, ABS_Y, y); + down[4].value = litest_scale(d, ABS_X, x); + down[5].value = litest_scale(d, ABS_Y, y); + + ARRAY_FOR_EACH(down, ev) + litest_event(d, ev-type, ev-code, ev-value); +} + +void +litest_generic_highres_touch_move(struct litest_device *d, + unsigned int slot, + int x, int y) +{ + struct input_event *ev; + struct input_event move[] = { + { .type = EV_ABS, .code = ABS_MT_SLOT, .value = slot }, + { .type = EV_ABS, .code = ABS_X, .value = x }, + { .type = EV_ABS, .code = ABS_Y, .value = y }, + { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = x }, + { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = y }, +
Re: [PATCH libinput 2/2] test: Add scale li_fixed overflow test
On Tue, Feb 18, 2014 at 08:13:58PM +0100, Jonas Ådahl wrote: Add a test case and test device that checks if the scale transform can handle high resolution devices and output monitor resolutions. The test case is created in a way that it will fail if the coordinate transform expression will overflow if only 32 bit integer data containers are used. Signed-off-by: Jonas Ådahl jad...@gmail.com --- fwiw, this is exactly the type of use-case where it would be simple and worth it to knock up a test for a single device and make sure that the coordinates are correct. which gives us a nice reproducer and prevents us from errors like this in the future. And here is such a test case. It will fail as is, but pass if either the expression uses 64 bit integers or doubles. Jonas test/Makefile.am| 1 + test/litest-generic-highres-touch.c | 139 test/litest.c | 2 + test/litest.h | 1 + test/touch.c| 40 ++- 5 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 test/litest-generic-highres-touch.c diff --git a/test/Makefile.am b/test/Makefile.am index 59687f6..4b923aa 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -14,6 +14,7 @@ liblitest_la_SOURCES = \ litest-synaptics.c \ litest-trackpoint.c \ litest-wacom-touch.c \ + litest-generic-highres-touch.c \ litest.c run_tests = test-udev test-path test-pointer test-touch diff --git a/test/litest-generic-highres-touch.c b/test/litest-generic-highres-touch.c new file mode 100644 index 000..bd326ce --- /dev/null +++ b/test/litest-generic-highres-touch.c @@ -0,0 +1,139 @@ +/* + * Copyright © 2013 Red Hat, Inc. + * Copyright © 2014 Jonas Ådahl + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the name of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided as + * is without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include config.h + +#include litest.h +#include litest-int.h +#include libinput-util.h + +void litest_generic_highres_touch_setup(void) +{ + struct litest_device *d = + litest_create_device(LITEST_GENERIC_HIGHRES_TOUCH); + litest_set_current_device(d); +} + +void +litest_generic_highres_touch_touch_down(struct litest_device *d, + unsigned int slot, + int x, int y) +{ + static int tracking_id; + struct input_event *ev; + struct input_event down[] = { + { .type = EV_ABS, .code = ABS_X, .value = x }, + { .type = EV_ABS, .code = ABS_Y, .value = y }, + { .type = EV_ABS, .code = ABS_MT_SLOT, .value = slot }, + { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = ++tracking_id }, + { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = x }, + { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = y }, + { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 }, + { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, + }; + + down[0].value = litest_scale(d, ABS_X, x); + down[1].value = litest_scale(d, ABS_Y, y); + down[4].value = litest_scale(d, ABS_X, x); + down[5].value = litest_scale(d, ABS_Y, y); + + ARRAY_FOR_EACH(down, ev) + litest_event(d, ev-type, ev-code, ev-value); +} + +void +litest_generic_highres_touch_move(struct litest_device *d, + unsigned int slot, + int x, int y) +{ + struct input_event *ev; + struct input_event move[] = { + { .type = EV_ABS, .code = ABS_MT_SLOT, .value = slot }, + { .type = EV_ABS, .code = ABS_X, .value = x }, + { .type = EV_ABS, .code = ABS_Y, .value = y }, + { .type = EV_ABS,