summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-09-18 19:10:11 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-09-18 19:10:11 +0200
commit9bec5056ec35008afd4d68528718fd4519cd3503 (patch)
tree886fb51f744ed50a1fbdf6615f80be513fa488f0 /tools
Initial evemu commit
Evemu is a kernel device and emulator, which allows for remote creation and testing of arbitrary devices. Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile.am24
-rw-r--r--tools/evemu-describe.c64
-rw-r--r--tools/evemu-device.c110
-rw-r--r--tools/evemu-echo.c75
-rw-r--r--tools/evemu-play.c53
-rw-r--r--tools/evemu-record.c53
6 files changed, 379 insertions, 0 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am
new file mode 100644
index 0000000..2638bf5
--- /dev/null
+++ b/tools/Makefile.am
@@ -0,0 +1,24 @@
+noinst_PROGRAMS = \
+ evemu-echo
+
+bin_PROGRAMS = \
+ evemu-describe \
+ evemu-device \
+ evemu-record \
+ evemu-play
+
+INCLUDES=-I$(top_srcdir)/include/
+
+evemu_describe_SOURCES = evemu-describe.c
+evemu_describe_LDFLAGS = -L$(top_builddir)/src/.libs/ -levemu
+
+evemu_echo_SOURCES = evemu-echo.c
+evemu_echo_LDFLAGS = -L$(top_builddir)/src/.libs/ -levemu
+
+evemu_device_SOURCES = evemu-device.c
+evemu_device_LDFLAGS = -L$(top_builddir)/src/.libs/ -levemu
+
+evemu_record_SOURCES = evemu-record.c
+evemu_record_LDFLAGS = -L$(top_builddir)/src/.libs/ -levemu
+evemu_play_SOURCES = evemu-play.c
+evemu_play_LDFLAGS = -L$(top_builddir)/src/.libs/ -levemu
diff --git a/tools/evemu-describe.c b/tools/evemu-describe.c
new file mode 100644
index 0000000..ec6b1ef
--- /dev/null
+++ b/tools/evemu-describe.c
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ *
+ * evemu - Kernel device emulation
+ *
+ * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
+ * Copyright (C) 2010 Canonical Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ ****************************************************************************/
+
+#include "evemu.h"
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+
+static int describe_device(int fd)
+{
+ struct evemu_device dev;
+ int ret;
+
+ ret = evemu_extract(&dev, fd);
+ if (ret)
+ return ret;
+ evemu_write(&dev, stdout);
+
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ int fd;
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s <device>\n", argv[0]);
+ return -1;
+ }
+ fd = open(argv[1], O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "error: could not open device\n");
+ return -1;
+ }
+ if (describe_device(fd)) {
+ fprintf(stderr, "error: could not describe device\n");
+ }
+ close(fd);
+ return 0;
+}
diff --git a/tools/evemu-device.c b/tools/evemu-device.c
new file mode 100644
index 0000000..89c9d6c
--- /dev/null
+++ b/tools/evemu-device.c
@@ -0,0 +1,110 @@
+/*****************************************************************************
+ *
+ * evemu - Kernel device emulation
+ *
+ * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
+ * Copyright (C) 2010 Canonical Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ ****************************************************************************/
+
+#include "evemu.h"
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+
+#define UINPUT_NODE "/dev/uinput"
+#define MAX_EVENT_NODE 32
+
+static void hold_device(const struct evemu_device *dev)
+{
+ char node[256], data[256];
+ int fd, ret, i;
+
+ memset(node, 0, sizeof(node));
+ for (i = 0; i < MAX_EVENT_NODE; i++) {
+ char path[256], name[256];
+ sprintf(path, "/sys/class/input/event%d/device/name", i + 1);
+ memset(name, 0, sizeof(name));
+ fd = open(path, O_RDONLY);
+ if (fd < 0)
+ continue;
+ ret = read(fd, name, sizeof(name));
+ if (ret > 0)
+ name[ret - 1] = 0;
+ if (!strcmp(dev->name, name))
+ sprintf(node, "/dev/input/event%d", i + 1);
+ close(fd);
+ }
+
+ fd = open(node, O_RDONLY);
+ if (fd < 0)
+ return;
+ printf("%s: %s\n", dev->name, node);
+ while ((ret = read(fd, data, sizeof(data))) > 0);
+ close(fd);
+}
+
+static int evemu_device(FILE *fp)
+{
+ struct evemu_device dev;
+ int ret, fd;
+
+ ret = evemu_read(&dev, fp);
+ if (ret <= 0)
+ return ret;
+
+ sprintf(dev.name, "evemu-%d", getpid());
+
+ fd = open(UINPUT_NODE, O_WRONLY);
+ if (fd < 0)
+ return fd;
+ ret = evemu_create(&dev, fd);
+ if (ret < 0)
+ return ret;
+
+ hold_device(&dev);
+
+ evemu_destroy(fd);
+ close(fd);
+
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ FILE *fp;
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s <dev.prop>\n", argv[0]);
+ return -1;
+ }
+ fp = fopen(argv[1], "r");
+ if (!fp) {
+ fprintf(stderr, "error: could not open file\n");
+ return -1;
+ }
+ if (evemu_device(fp)) {
+ fprintf(stderr, "error: could not create device\n");
+ return -1;
+ }
+ fclose(fp);
+ return 0;
+}
diff --git a/tools/evemu-echo.c b/tools/evemu-echo.c
new file mode 100644
index 0000000..d3501ea
--- /dev/null
+++ b/tools/evemu-echo.c
@@ -0,0 +1,75 @@
+/*****************************************************************************
+ *
+ * evemu - Kernel device emulation
+ *
+ * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
+ * Copyright (C) 2010 Canonical Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ ****************************************************************************/
+
+#include "evemu.h"
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+
+static int evemu_echo_describe(FILE *fp)
+{
+ struct evemu_device dev;
+ int ret;
+
+ ret = evemu_read(&dev, fp);
+ if (ret <= 0)
+ return ret;
+
+ evemu_write(&dev, stdout);
+
+ return 0;
+}
+
+static int evemu_echo_event(FILE *fp)
+{
+ struct input_event ev;
+ int ret;
+
+ while ((ret = evemu_read_event(fp, &ev)) > 0)
+ evemu_write_event(stdout, &ev);
+
+ return ret;
+}
+
+int main(int argc, char *argv[])
+{
+ FILE *fp;
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s <dev.prop>\n", argv[0]);
+ return -1;
+ }
+ fp = fopen(argv[1], "r");
+ if (!fp) {
+ fprintf(stderr, "error: could not open file\n");
+ return -1;
+ }
+ evemu_echo_describe(fp);
+ evemu_echo_event(fp);
+ fclose(fp);
+ return 0;
+}
diff --git a/tools/evemu-play.c b/tools/evemu-play.c
new file mode 100644
index 0000000..54a16d9
--- /dev/null
+++ b/tools/evemu-play.c
@@ -0,0 +1,53 @@
+/*****************************************************************************
+ *
+ * evemu - Kernel device emulation
+ *
+ * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
+ * Copyright (C) 2010 Canonical Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ ****************************************************************************/
+
+#include "evemu.h"
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+
+int main(int argc, char *argv[])
+{
+ int fd;
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s <device>\n", argv[0]);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Event data is read from standard input.\n");
+ return -1;
+ }
+ fd = open(argv[1], O_WRONLY);
+ if (fd < 0) {
+ fprintf(stderr, "error: could not open device\n");
+ return -1;
+ }
+ if (evemu_play(stdin, fd)) {
+ fprintf(stderr, "error: could not describe device\n");
+ }
+ close(fd);
+ return 0;
+}
diff --git a/tools/evemu-record.c b/tools/evemu-record.c
new file mode 100644
index 0000000..e748351
--- /dev/null
+++ b/tools/evemu-record.c
@@ -0,0 +1,53 @@
+/*****************************************************************************
+ *
+ * evemu - Kernel device emulation
+ *
+ * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
+ * Copyright (C) 2010 Canonical Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ ****************************************************************************/
+
+#include "evemu.h"
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+
+#define WAIT_MS 10000
+
+int main(int argc, char *argv[])
+{
+ int fd;
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s <device>\n", argv[0]);
+ return -1;
+ }
+ fd = open(argv[1], O_RDONLY | O_NONBLOCK);
+ if (fd < 0) {
+ fprintf(stderr, "error: could not open device\n");
+ return -1;
+ }
+ if (evemu_record(stdout, fd, WAIT_MS)) {
+ fprintf(stderr, "error: could not describe device\n");
+ }
+ close(fd);
+ return 0;
+}