Commit 5d8cdaf4 authored by Peter Hutterer's avatar Peter Hutterer
Browse files

Drop the half-baked test suite



This suite was never really maintained anyway, and it is quite hard to do so
anyway. The driver is linked to the server's API too tightly to easily do
independent testing. We need to re-implement stubs for the API the driver
uses, have to track API changes, etc. Not worth the effort.
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
parent e0069c15
...@@ -24,7 +24,7 @@ DISTCHECK_CONFIGURE_FLAGS = \ ...@@ -24,7 +24,7 @@ DISTCHECK_CONFIGURE_FLAGS = \
--with-sdkdir='$${includedir}/xorg' \ --with-sdkdir='$${includedir}/xorg' \
--with-xorg-conf-dir='$${datadir}/X11/xorg.conf.d' --with-xorg-conf-dir='$${datadir}/X11/xorg.conf.d'
SUBDIRS = include src man tools conf test SUBDIRS = include src man tools conf
MAINTAINERCLEANFILES = ChangeLog INSTALL MAINTAINERCLEANFILES = ChangeLog INSTALL
pkgconfigdir = $(libdir)/pkgconfig pkgconfigdir = $(libdir)/pkgconfig
......
...@@ -160,7 +160,6 @@ AC_CONFIG_FILES([Makefile ...@@ -160,7 +160,6 @@ AC_CONFIG_FILES([Makefile
tools/Makefile tools/Makefile
conf/Makefile conf/Makefile
include/Makefile include/Makefile
test/Makefile
xorg-synaptics.pc]) xorg-synaptics.pc])
AC_OUTPUT AC_OUTPUT
# Add & Override patterns for xf86-input-synaptics
#
# Edit the following section as needed
# For example, !report.pc overrides *.pc. See 'man gitignore'
eventcomm-test
if ENABLE_UNIT_TESTS
AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include
AM_CFLAGS = $(XORG_CFLAGS) $(CWARNFLAGS)
fake_syms = fake-symbols.c fake-symbols.h
if BUILD_EVENTCOMM
noinst_PROGRAMS = eventcomm-test
eventcomm_test_SOURCES = eventcomm-test.c\
$(top_srcdir)/src/eventcomm.c \
$(top_srcdir)/src/synproto.c \
$(fake_syms)
eventcomm_test_LDADD = $(MTDEV_LIBS) $(LIBEVDEV_LIBS)
AM_CPPFLAGS += $(LIBEVDEV_CFLAGS)
endif
TESTS = $(noinst_PROGRAMS)
endif
/*
* Copyright © 2011 Red Hat, Inc.
*
* 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 Red Hat
* not be used in advertising or publicity pertaining to distribution
* of the software without specific, written prior permission. Red
* Hat makes no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied
* warranty.
*
* THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL THE AUTHORS 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.
*
* Authors:
* Peter Hutterer
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <assert.h>
#include "synapticsstr.h"
#include "eventcomm.h"
#define ArrayLength(a) (sizeof(a) / (sizeof((a)[0])))
int fd_read, fd_write;
/* A syn event, always handy to have */
struct input_event syn = { {0, 0}, EV_SYN, SYN_REPORT, 0 };
static void
create_pipe_fd(void)
{
int pipefd[2];
assert(pipe(pipefd) != -1);
fd_read = pipefd[0];
fd_write = pipefd[1];
}
static void
reset_data(struct SynapticsHwState **hw, struct CommData *comm,
SynapticsPrivate * priv)
{
SynapticsHwStateFree(&comm->hwState);
memset(comm, 0, sizeof(struct CommData));
SynapticsHwStateFree(hw);
*hw = SynapticsHwStateAlloc(priv);
comm->hwState = SynapticsHwStateAlloc(priv);
}
/**
* Write n input events to fd, followed by the syn event.
*/
static void
write_event(int fd, struct input_event *ev, int n)
{
write(fd, ev, sizeof(struct input_event) * n);
write(fd, &syn, sizeof(syn));
}
static void
test_buttons(int fd, InputInfoPtr pInfo, struct CommData *comm)
{
SynapticsPrivate *priv = (SynapticsPrivate *) pInfo->private;
struct SynapticsHwState *hw = NULL;
struct input_event ev = { {0, 0}, EV_KEY, 0, 0 };
reset_data(&hw, comm, priv);
#define _test_press_release(_code, field) \
ev.code = (_code); \
ev.value = 1; \
write_event(fd, &ev, 1); \
EventReadHwState(pInfo, comm, hw); \
assert(hw->field == 1); \
ev.value = 0; /* button release */ \
write_event(fd_write, &ev, 1); \
EventReadHwState(pInfo, comm, hw); \
assert(hw->field == 0);
_test_press_release(BTN_LEFT, left);
_test_press_release(BTN_RIGHT, right);
_test_press_release(BTN_MIDDLE, middle);
_test_press_release(BTN_FORWARD, up);
_test_press_release(BTN_BACK, down);
_test_press_release(BTN_0, multi[0]);
_test_press_release(BTN_1, multi[1]);
_test_press_release(BTN_2, multi[2]);
_test_press_release(BTN_3, multi[3]);
_test_press_release(BTN_4, multi[4]);
_test_press_release(BTN_5, multi[5]);
_test_press_release(BTN_6, multi[6]);
_test_press_release(BTN_7, multi[7]);
SynapticsHwStateFree(&hw);
}
/**
* This test checks that the recognised event fields set the right hardware
* state. It's a fairly limited test and does not check whether any of the
* others change the HW state at all.
*/
static void
test_read_hw_state(void)
{
InputInfoRec info = { 0 };
SynapticsPrivate private;
struct SynapticsHwState *hw = NULL;
struct CommData comm = { 0 };
struct input_event ev[] = {
{{0, 0}, EV_KEY, BTN_TOOL_FINGER, 1},
{{0, 0}, EV_KEY, BTN_TOOL_DOUBLETAP, 1},
{{0, 0}, EV_KEY, BTN_TOOL_TRIPLETAP, 1},
{{0, 0}, EV_ABS, ABS_X, 42},
{{0, 0}, EV_ABS, ABS_Y, 21},
{{0, 0}, EV_ABS, ABS_PRESSURE, 56},
{{0, 0}, EV_ABS, ABS_TOOL_WIDTH, 204},
};
memset(&private, 0, sizeof(private));
info.private = &private;
info.fd = fd_read;
private.proto_data = EventProtoDataAlloc(fd_read);
/* just the syn event */
reset_data(&hw, &comm, &private);
write(fd_write, &syn, sizeof(syn));
EventReadHwState(&info, &comm, hw);
assert(hw->numFingers == 0);
/* one finger */
reset_data(&hw, &comm, &private);
write_event(fd_write, &ev[0], 1);
EventReadHwState(&info, &comm, hw);
assert(hw->numFingers == 1);
/* two fingers */
reset_data(&hw, &comm, &private);
write_event(fd_write, &ev[1], 1);
EventReadHwState(&info, &comm, hw);
assert(hw->numFingers == 2);
/* three fingers */
reset_data(&hw, &comm, &private);
write_event(fd_write, &ev[2], 1);
EventReadHwState(&info, &comm, hw);
assert(hw->numFingers == 3);
/* x/y data */
reset_data(&hw, &comm, &private);
write_event(fd_write, &ev[3], 2);
EventReadHwState(&info, &comm, hw);
assert(hw->x == ev[3].value);
assert(hw->y == ev[4].value);
/* pressure */
reset_data(&hw, &comm, &private);
write_event(fd_write, &ev[5], 1);
EventReadHwState(&info, &comm, hw);
assert(hw->z == ev[5].value);
/* finger width */
reset_data(&hw, &comm, &private);
write_event(fd_write, &ev[6], 1);
EventReadHwState(&info, &comm, hw);
assert(hw->fingerWidth == ev[6].value);
/* the various buttons */
test_buttons(fd_write, &info, &comm);
free(private.proto_data);
SynapticsHwStateFree(&hw);
SynapticsHwStateFree(&comm.hwState);
}
static Bool
compare_hw_state(const struct SynapticsHwState *a,
const struct SynapticsHwState *b)
{
#define COMPARE(x) \
if (a->x != b->x) return a->x - b->x
COMPARE(millis);
COMPARE(x);
COMPARE(y);
COMPARE(z);
COMPARE(numFingers);
COMPARE(fingerWidth);
COMPARE(left);
COMPARE(right);
COMPARE(up);
COMPARE(down);
if (memcmp(a->multi, b->multi, sizeof(a->multi)))
return memcmp(a->multi, b->multi, sizeof(a->multi));
COMPARE(middle);
#undef COMPARE
return 0;
}
/**
* Make sure that axes/keys unknown to the driver don't change the hardware
* state.
*/
static void
test_ignore_hw_state(void)
{
int i;
InputInfoRec info = { 0 };
SynapticsPrivate private;
struct SynapticsHwState *hw = NULL;
struct SynapticsHwState *hw_zero = NULL;
struct CommData comm = { 0 };
int known_abs[] = {
ABS_X,
ABS_Y,
ABS_PRESSURE,
ABS_TOOL_WIDTH,
};
int known_keys[] = {
BTN_LEFT,
BTN_RIGHT,
BTN_MIDDLE,
BTN_FORWARD,
BTN_BACK,
BTN_0,
BTN_1,
BTN_2,
BTN_3,
BTN_4,
BTN_5,
BTN_6,
BTN_7,
BTN_TOOL_FINGER,
BTN_TOOL_DOUBLETAP,
BTN_TOOL_TRIPLETAP,
BTN_TOUCH
};
struct input_event ev = { {0, 0}, 0, 0, 1 };
memset(&private, 0, sizeof(private));
info.private = &private;
info.fd = fd_read;
private.proto_data = EventProtoDataAlloc(fd_read);
reset_data(&hw_zero, &comm, &private);
#define _assert_no_change(_type, _code) \
reset_data(&hw, &comm, &private); \
ev.type = _type; \
ev.code = _code; \
ev.value = 1; \
write_event(fd_write, &ev, 1); \
EventReadHwState(&info, &comm, hw); \
assert(compare_hw_state(hw, hw_zero) == 0);
for (i = ABS_X; i < ABS_MAX; i++) {
int j, skip = 0;
for (j = 0; j < ArrayLength(known_abs); j++) {
if (i == known_abs[j]) {
skip = 1;
break;
}
}
if (skip)
continue;
_assert_no_change(EV_ABS, i);
}
for (i = KEY_RESERVED; i < KEY_MAX; i++) {
int j, skip = 0;
for (j = 0; j < ArrayLength(known_keys); j++) {
if (i == known_keys[j]) {
skip = 1;
break;
}
}
if (skip)
continue;
_assert_no_change(EV_KEY, i);
}
free(private.proto_data);
SynapticsHwStateFree(&hw);
SynapticsHwStateFree(&hw_zero);
SynapticsHwStateFree(&comm.hwState);
}
int
main(int argc, char **argv)
{
create_pipe_fd();
test_read_hw_state();
test_ignore_hw_state();
return 0;
}
#include "fake-symbols.h"
_X_EXPORT int
xf86ReadSerial(int fd, void *buf, int count)
{
return 0;
}
_X_EXPORT int
xf86WriteSerial(int fd, const void *buf, int count)
{
return 0;
}
_X_EXPORT int
xf86CloseSerial(int fd)
{
return 0;
}
_X_EXPORT int
xf86WaitForInput(int fd, int timeout)
{
return 0;
}
_X_EXPORT int
xf86OpenSerial(XF86OptionPtr options)
{
return 0;
}
_X_EXPORT int
xf86SetSerialSpeed(int fd, int speed)
{
return 0;
}
_X_EXPORT XF86OptionPtr
xf86ReplaceIntOption(XF86OptionPtr optlist, const char *name, const int val)
{
return NULL;
}
_X_EXPORT char *
xf86SetStrOption(XF86OptionPtr optlist, const char *name, const char *deflt)
{
return NULL;
}
_X_EXPORT int
xf86SetBoolOption(XF86OptionPtr optlist, const char *name, int deflt)
{
return 0;
}
_X_EXPORT XF86OptionPtr
xf86AddNewOption(XF86OptionPtr head, const char *name, const char *val)
{
return NULL;
}
_X_EXPORT const char *
xf86FindOptionValue(XF86OptionPtr options, const char *name)
{
return NULL;
}
_X_EXPORT char *
xf86OptionName(XF86OptionPtr opt)
{
return NULL;
}
_X_EXPORT char *
xf86OptionValue(XF86OptionPtr opt)
{
return NULL;
}
_X_EXPORT int
xf86NameCmp(const char *s1, const char *s2)
{
return 0;
}
_X_EXPORT void
xf86AddEnabledDevice(InputInfoPtr pInfo)
{
return;
}
_X_EXPORT void
xf86RemoveEnabledDevice(InputInfoPtr pInfo)
{
return;
}
_X_EXPORT Atom
XIGetKnownProperty(char *name)
{
return None;
}
_X_EXPORT void
xf86AddInputDriver(InputDriverPtr driver, pointer module, int flags)
{
return;
}
_X_EXPORT int
xf86ScaleAxis(int Cx, int to_max, int to_min, int from_max, int from_min)
{
int X;
int64_t to_width = to_max - to_min;
int64_t from_width = from_max - from_min;
if (from_width) {
X = (int) (((to_width * (Cx - from_min)) / from_width) + to_min);
}
else {
X = 0;
/*ErrorF ("Divide by Zero in xf86ScaleAxis\n"); */
}
if (X > to_max)
X = to_max;
if (X < to_min)
X = to_min;
return X;
}
_X_EXPORT void
DeleteInputDeviceRequest(DeviceIntPtr pDev)
{
return;
}
_X_EXPORT void
FreeInputAttributes(InputAttributes * attrs)
{
return;
}
_X_EXPORT void
xf86PostButtonEvent(DeviceIntPtr device,
int is_absolute,
int button,
int is_down, int first_valuator, int num_valuators, ...)
{
return;
}
_X_EXPORT int
Xasprintf(char **ret, const char *format, ...)
{
return 0;
}
_X_EXPORT int
XISetDevicePropertyDeletable(DeviceIntPtr dev, Atom property, Bool deletable)
{
return 0;
}
_X_EXPORT InputInfoPtr
xf86FirstLocalDevice(void)
{
return NULL;
}
_X_EXPORT void
xf86DeleteInput(InputInfoPtr pInp, int flags)
{
return;
}
_X_EXPORT XF86OptionPtr
xf86OptionListDuplicate(XF86OptionPtr options)
{
return NULL;
}
_X_EXPORT Bool
InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons, Atom *labels,
CARD8 *map)
{
return FALSE;
}
_X_EXPORT void
InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval,
int maxval, int resolution, int min_res, int max_res,
int mode)
{
return;
}
_X_EXPORT void
xf86PostKeyboardEvent(DeviceIntPtr device, unsigned int key_code, int is_down)
{
return;
}
_X_EXPORT int
xf86SetIntOption(XF86OptionPtr optlist, const char *name, int deflt)
{
return 0;
}
_X_EXPORT void
xf86PostButtonEventP(DeviceIntPtr device,
int is_absolute,
int button,
int is_down, int first_valuator, int num_valuators,
const int *valuators)
{
return;
}
_X_EXPORT Bool
InitPtrFeedbackClassDeviceStruct(DeviceIntPtr dev, PtrCtrlProcPtr controlProc)
{
return FALSE;
}
_X_EXPORT int
XIChangeDeviceProperty(DeviceIntPtr dev, Atom property, Atom type,
int format, int mode, unsigned long len,
XF86OptionPtr value, Bool sendevent)
{
return 0;
}
_X_EXPORT CARD32
GetTimeInMillis(void)
{
return 0;
}
_X_EXPORT int
NewInputDeviceRequest(InputOption *options,
InputAttributes * attrs,
DeviceIntPtr *pdev)
{
return 0;
}