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 @@
1noinst_PROGRAMS = \
2 evemu-echo
3
4bin_PROGRAMS = \
5 evemu-describe \
6 evemu-device \
7 evemu-record \
8 evemu-play
9
10INCLUDES=-I$(top_srcdir)/include/
11
12evemu_describe_SOURCES = evemu-describe.c
13evemu_describe_LDFLAGS = -L$(top_builddir)/src/.libs/ -levemu
14
15evemu_echo_SOURCES = evemu-echo.c
16evemu_echo_LDFLAGS = -L$(top_builddir)/src/.libs/ -levemu
17
18evemu_device_SOURCES = evemu-device.c
19evemu_device_LDFLAGS = -L$(top_builddir)/src/.libs/ -levemu
20
21evemu_record_SOURCES = evemu-record.c
22evemu_record_LDFLAGS = -L$(top_builddir)/src/.libs/ -levemu
23evemu_play_SOURCES = evemu-play.c
24evemu_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 @@
1/*****************************************************************************
2 *
3 * evemu - Kernel device emulation
4 *
5 * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
6 * Copyright (C) 2010 Canonical Ltd.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 *
27 ****************************************************************************/
28
29#include "evemu.h"
30#include <stdio.h>
31#include <fcntl.h>
32#include <string.h>
33
34static int describe_device(int fd)
35{
36 struct evemu_device dev;
37 int ret;
38
39 ret = evemu_extract(&dev, fd);
40 if (ret)
41 return ret;
42 evemu_write(&dev, stdout);
43
44 return 0;
45}
46
47int main(int argc, char *argv[])
48{
49 int fd;
50 if (argc < 2) {
51 fprintf(stderr, "Usage: %s <device>\n", argv[0]);
52 return -1;
53 }
54 fd = open(argv[1], O_RDONLY);
55 if (fd < 0) {
56 fprintf(stderr, "error: could not open device\n");
57 return -1;
58 }
59 if (describe_device(fd)) {
60 fprintf(stderr, "error: could not describe device\n");
61 }
62 close(fd);
63 return 0;
64}
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 @@
1/*****************************************************************************
2 *
3 * evemu - Kernel device emulation
4 *
5 * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
6 * Copyright (C) 2010 Canonical Ltd.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 *
27 ****************************************************************************/
28
29#include "evemu.h"
30#include <stdio.h>
31#include <fcntl.h>
32#include <string.h>
33
34#define UINPUT_NODE "/dev/uinput"
35#define MAX_EVENT_NODE 32
36
37static void hold_device(const struct evemu_device *dev)
38{
39 char node[256], data[256];
40 int fd, ret, i;
41
42 memset(node, 0, sizeof(node));
43 for (i = 0; i < MAX_EVENT_NODE; i++) {
44 char path[256], name[256];
45 sprintf(path, "/sys/class/input/event%d/device/name", i + 1);
46 memset(name, 0, sizeof(name));
47 fd = open(path, O_RDONLY);
48 if (fd < 0)
49 continue;
50 ret = read(fd, name, sizeof(name));
51 if (ret > 0)
52 name[ret - 1] = 0;
53 if (!strcmp(dev->name, name))
54 sprintf(node, "/dev/input/event%d", i + 1);
55 close(fd);
56 }
57
58 fd = open(node, O_RDONLY);
59 if (fd < 0)
60 return;
61 printf("%s: %s\n", dev->name, node);
62 while ((ret = read(fd, data, sizeof(data))) > 0);
63 close(fd);
64}
65
66static int evemu_device(FILE *fp)
67{
68 struct evemu_device dev;
69 int ret, fd;
70
71 ret = evemu_read(&dev, fp);
72 if (ret <= 0)
73 return ret;
74
75 sprintf(dev.name, "evemu-%d", getpid());
76
77 fd = open(UINPUT_NODE, O_WRONLY);
78 if (fd < 0)
79 return fd;
80 ret = evemu_create(&dev, fd);
81 if (ret < 0)
82 return ret;
83
84 hold_device(&dev);
85
86 evemu_destroy(fd);
87 close(fd);
88
89 return 0;
90}
91
92int main(int argc, char *argv[])
93{
94 FILE *fp;
95 if (argc < 2) {
96 fprintf(stderr, "Usage: %s <dev.prop>\n", argv[0]);
97 return -1;
98 }
99 fp = fopen(argv[1], "r");
100 if (!fp) {
101 fprintf(stderr, "error: could not open file\n");
102 return -1;
103 }
104 if (evemu_device(fp)) {
105 fprintf(stderr, "error: could not create device\n");
106 return -1;
107 }
108 fclose(fp);
109 return 0;
110}
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 @@
1/*****************************************************************************
2 *
3 * evemu - Kernel device emulation
4 *
5 * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
6 * Copyright (C) 2010 Canonical Ltd.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 *
27 ****************************************************************************/
28
29#include "evemu.h"
30#include <stdio.h>
31#include <fcntl.h>
32#include <string.h>
33
34static int evemu_echo_describe(FILE *fp)
35{
36 struct evemu_device dev;
37 int ret;
38
39 ret = evemu_read(&dev, fp);
40 if (ret <= 0)
41 return ret;
42
43 evemu_write(&dev, stdout);
44
45 return 0;
46}
47
48static int evemu_echo_event(FILE *fp)
49{
50 struct input_event ev;
51 int ret;
52
53 while ((ret = evemu_read_event(fp, &ev)) > 0)
54 evemu_write_event(stdout, &ev);
55
56 return ret;
57}
58
59int main(int argc, char *argv[])
60{
61 FILE *fp;
62 if (argc < 2) {
63 fprintf(stderr, "Usage: %s <dev.prop>\n", argv[0]);
64 return -1;
65 }
66 fp = fopen(argv[1], "r");
67 if (!fp) {
68 fprintf(stderr, "error: could not open file\n");
69 return -1;
70 }
71 evemu_echo_describe(fp);
72 evemu_echo_event(fp);
73 fclose(fp);
74 return 0;
75}
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 @@
1/*****************************************************************************
2 *
3 * evemu - Kernel device emulation
4 *
5 * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
6 * Copyright (C) 2010 Canonical Ltd.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 *
27 ****************************************************************************/
28
29#include "evemu.h"
30#include <stdio.h>
31#include <fcntl.h>
32#include <string.h>
33
34int main(int argc, char *argv[])
35{
36 int fd;
37 if (argc < 2) {
38 fprintf(stderr, "Usage: %s <device>\n", argv[0]);
39 fprintf(stderr, "\n");
40 fprintf(stderr, "Event data is read from standard input.\n");
41 return -1;
42 }
43 fd = open(argv[1], O_WRONLY);
44 if (fd < 0) {
45 fprintf(stderr, "error: could not open device\n");
46 return -1;
47 }
48 if (evemu_play(stdin, fd)) {
49 fprintf(stderr, "error: could not describe device\n");
50 }
51 close(fd);
52 return 0;
53}
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 @@
1/*****************************************************************************
2 *
3 * evemu - Kernel device emulation
4 *
5 * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
6 * Copyright (C) 2010 Canonical Ltd.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 *
27 ****************************************************************************/
28
29#include "evemu.h"
30#include <stdio.h>
31#include <fcntl.h>
32#include <string.h>
33
34#define WAIT_MS 10000
35
36int main(int argc, char *argv[])
37{
38 int fd;
39 if (argc < 2) {
40 fprintf(stderr, "Usage: %s <device>\n", argv[0]);
41 return -1;
42 }
43 fd = open(argv[1], O_RDONLY | O_NONBLOCK);
44 if (fd < 0) {
45 fprintf(stderr, "error: could not open device\n");
46 return -1;
47 }
48 if (evemu_record(stdout, fd, WAIT_MS)) {
49 fprintf(stderr, "error: could not describe device\n");
50 }
51 close(fd);
52 return 0;
53}