Exemplo n.º 1
0
void test_create_device(struct uinput_device **uidev_return,
			struct libevdev **dev_return,
			...)
{
	int rc, fd;
	struct uinput_device *uidev;
	struct libevdev *dev;
	va_list args;

	va_start(args, dev_return);

	rc = uinput_device_new_with_events_v(&uidev, TEST_DEVICE_NAME, DEFAULT_IDS, args);
	va_end(args);

	ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));

	fd = uinput_device_get_fd(uidev);

	rc = libevdev_new_from_fd(fd, &dev);
	ck_assert_msg(rc == 0, "Failed to init device device: %s", strerror(-rc));
	rc = fcntl(fd, F_SETFL, O_NONBLOCK);
	ck_assert_msg(rc == 0, "fcntl failed: %s", strerror(errno));

	*uidev_return = uidev;
	*dev_return = dev;
}
Exemplo n.º 2
0
void test_create_abs_device(struct uinput_device **uidev_return,
			    struct libevdev **dev_return,
			    int nabs,
			    const struct input_absinfo *abs,
			    ...)
{
	int rc, fd;
	struct uinput_device *uidev;
	struct libevdev *dev;
	va_list args;

	uidev = uinput_device_new(TEST_DEVICE_NAME);
	ck_assert(uidev != NULL);

	va_start(args, abs);
	rc = uinput_device_set_event_bits_v(uidev, args);
	va_end(args);

	while (--nabs >= 0) {
		int code;
		struct input_absinfo a;

		code = abs[nabs].value;
		a = abs[nabs];
		a.value = 0;

		rc = uinput_device_set_abs_bit(uidev, code, &a);
		ck_assert_msg(rc == 0, "for abs field %d\n", nabs);
	}

	rc = uinput_device_create(uidev);
	ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));

	fd = uinput_device_get_fd(uidev);

	rc = libevdev_new_from_fd(fd, &dev);
	ck_assert_msg(rc == 0, "Failed to init device device: %s", strerror(-rc));
	rc = fcntl(fd, F_SETFL, O_NONBLOCK);
	ck_assert_msg(rc == 0, "fcntl failed: %s", strerror(errno));

	*uidev_return = uidev;
	*dev_return = dev;
}
Exemplo n.º 3
0
END_TEST

START_TEST(test_syn_event)
{
	struct uinput_device* uidev;
	struct libevdev *dev;
	int rc;
	struct input_event ev;
	int pipefd[2];

	rc = test_create_device(&uidev, &dev,
				EV_SYN, SYN_REPORT,
				EV_SYN, SYN_DROPPED,
				EV_REL, REL_X,
				EV_REL, REL_Y,
				EV_KEY, BTN_LEFT,
				-1);
	ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));

	/* This is a bid complicated:
	   we can't get SYN_DROPPED through uinput, so we push two events down
	   uinput, and fetch one off libevdev (reading in the other one on the
	   way). Then write a SYN_DROPPED on a pipe, switch the fd and read
	   one event off the wire (but returning the second event from
	   before). Switch back, so that when we do read off the SYN_DROPPED
	   we have the fd back on the device and the ioctls work.
	 */
	uinput_device_event(uidev, EV_KEY, BTN_LEFT, 1);
	uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0);
	rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev);
	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
	ck_assert_int_eq(ev.type, EV_KEY);
	ck_assert_int_eq(ev.code, BTN_LEFT);
	rc = pipe2(pipefd, O_NONBLOCK);
	ck_assert_int_eq(rc, 0);

	libevdev_change_fd(dev, pipefd[0]);
	ev.type = EV_SYN;
	ev.code = SYN_DROPPED;
	ev.value = 0;
	rc = write(pipefd[1], &ev, sizeof(ev));
	ck_assert_int_eq(rc, sizeof(ev));
	rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev);

	libevdev_change_fd(dev, uinput_device_get_fd(uidev));

	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SUCCESS);
	ck_assert_int_eq(ev.type, EV_SYN);
	ck_assert_int_eq(ev.code, SYN_REPORT);
	rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev);
	ck_assert_int_eq(rc, LIBEVDEV_READ_STATUS_SYNC);

	/* only check for the rc, nothing actually changed on the device */

	libevdev_free(dev);
	uinput_device_free(uidev);

	close(pipefd[0]);
	close(pipefd[1]);

}