[PATCH xorg-gtest v2] Add xorg::testing::evemu::Device
Chase Douglas
chase.douglas at canonical.com
Tue Mar 6 17:23:45 PST 2012
Device uses utouch-evemu for input device recording playback through the
Linux kernel.
Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
Acked-by: Peter Hutterer <peter.hutterer at who-t.net>
---
Changes since v1:
* Drop xorg::testing::evemu::Recording
- Instead, simply call Device.Play(<recording file>)
- The overhead of opening a recording file each time should be negligible
configure.ac | 13 +++++
include/Makefile.am | 4 ++
include/xorg/gtest/evemu/device.h | 91 +++++++++++++++++++++++++++++++++++
src/Makefile.am | 6 ++
src/device.cpp | 94 +++++++++++++++++++++++++++++++++++++
src/libxorg-gtest.ver | 11 ++++-
6 files changed, 218 insertions(+), 1 deletions(-)
create mode 100644 include/xorg/gtest/evemu/device.h
create mode 100644 src/device.cpp
diff --git a/configure.ac b/configure.ac
index 3178a3f..5e760e2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,19 @@ AS_IF([test "x$ac_cv_lib_gtest_main" != xyes],
AC_SUBST([GTEST_CPPFLAGS])
+# Check if we should include support for utouch-evemu
+AC_ARG_WITH([evemu],
+ [AS_HELP_STRING([--with-evemu],
+ [support Linux input device recording playback (default: enabled if available)])],
+ [],
+ [with_evemu=check])
+
+AS_IF([test "x$with_evemu" == xyes],
+ [PKG_CHECK_MODULES(EVEMU, utouch-evemu, [have_evemu=yes])],
+ [test "x$with_evemu" == xcheck],
+ [PKG_CHECK_MODULES(EVEMU, utouch-evemu, [have_evemu=yes], [:])])
+AM_CONDITIONAL([HAVE_EVEMU], [test "x$have_evemu" = "xyes"])
+
AC_SUBST(DUMMY_CONF_PATH, "$datadir/xorg/gtest/dummy.conf")
AC_CONFIG_FILES([Makefile
diff --git a/include/Makefile.am b/include/Makefile.am
index 14768c3..ffc7767 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -27,3 +27,7 @@ nobase_include_HEADERS = \
xorg/gtest/environment.h \
xorg/gtest/process.h \
xorg/gtest/test.h
+
+if HAVE_EVEMU
+nobase_include_HEADERS += xorg/gtest/evemu/device.h
+endif
diff --git a/include/xorg/gtest/evemu/device.h b/include/xorg/gtest/evemu/device.h
new file mode 100644
index 0000000..4e456ce
--- /dev/null
+++ b/include/xorg/gtest/evemu/device.h
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ *
+ * X testing environment - Google Test environment feat. dummy x server
+ *
+ * Copyright (C) 2012 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.
+ *
+ ******************************************************************************/
+
+#ifndef XORG_GTEST_EVEMU_DEVICE_H_
+#define XORG_GTEST_EVEMU_DEVICE_H_
+
+#include <memory>
+#include <string>
+
+extern "C" {
+
+#include <evemu.h>
+
+} // extern "C"
+
+namespace xorg {
+namespace testing {
+namespace evemu {
+
+/**
+ * @class Device device.h xorg/gtest/evemu/device.h
+ *
+ * uTouch-Evemu input device for replaying events through the Linux uinput
+ * evdev subsystem.
+ *
+ * Use the Recording class to play back a specific recording.
+ */
+
+class Device {
+ public:
+ /**
+ * Create a new device context.
+ *
+ * @param [in] path Path to uTouch-Evemu device property file.
+ *
+ * @throws std::runtime_error if the device property file could not be found
+ * or the device could not be created.
+ */
+ explicit Device(const std::string& path);
+ ~Device();
+
+ /**
+ * Play a uTouch-Evemu recording through the device.
+ *
+ * Plays the recording from the beginning through the end. This call will
+ * block until the recording has finished.
+ *
+ * @param [in] path Path to uTouch-Evemu recording file.
+ *
+ * @throws std::runtime_error if playback failed for any reason.
+ */
+ void Play(const std::string& path) const;
+
+ private:
+ struct Private;
+ std::auto_ptr<Private> d_;
+
+ /* Disable copy constructor & assignment operator */
+ Device(const Device&);
+ Device& operator=(const Device&);
+};
+
+} // namespace evemu
+} // namespace testing
+} // namespace xorg
+
+#endif // XORG_GTEST_EVEMU_DEVICE_H_
diff --git a/src/Makefile.am b/src/Makefile.am
index 204c7ab..a75fb9e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -54,4 +54,10 @@ libxorg_gtest_main_la_LDFLAGS = \
$(XSERVER_LIBS) \
-Wl,--version-script=$(top_srcdir)/src/libxorg-gtest_main.ver
+if HAVE_EVEMU
+libxorg_gtest_la_SOURCES += device.cpp
+
+libxorg_gtest_la_LIBADD = $(EVEMU_LIBS)
+endif
+
EXTRA_DIST = libxorg-gtest.ver libxorg-gtest_main.ver
diff --git a/src/device.cpp b/src/device.cpp
new file mode 100644
index 0000000..13d90ee
--- /dev/null
+++ b/src/device.cpp
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ *
+ * X testing environment - Google Test environment feat. dummy x server
+ *
+ * Copyright (C) 2012 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 "xorg/gtest/evemu/device.h"
+
+#include <fcntl.h>
+
+#include <stdexcept>
+
+#include <gtest/gtest.h>
+
+struct xorg::testing::evemu::Device::Private {
+ Private() : fd(-1), device(NULL) {}
+
+ int fd;
+ struct evemu_device* device;
+};
+
+xorg::testing::evemu::Device::Device(const std::string& path)
+ : d_(new Private) {
+ static const char UINPUT_NODE[] = "/dev/uinput";
+
+ d_->device = evemu_new(NULL);
+ if (!d_->device)
+ throw std::runtime_error("Failed to create evemu record");
+
+ FILE* fp = fopen(path.c_str(), "r");
+ if (fp == NULL) {
+ evemu_delete(d_->device);
+ throw std::runtime_error("Failed to open device file");
+ }
+
+ if (evemu_read(d_->device, fp) <= 0) {
+ fclose(fp);
+ evemu_delete(d_->device);
+ throw std::runtime_error("Failed to read device file");
+ }
+
+ fclose(fp);
+
+ d_->fd = open(UINPUT_NODE, O_WRONLY);
+ if (d_->fd < 0) {
+ evemu_delete(d_->device);
+ throw std::runtime_error("Failed to open uinput node");
+ }
+
+ if (evemu_create(d_->device, d_->fd) < 0) {
+ close(d_->fd);
+ evemu_delete(d_->device);
+ throw std::runtime_error("Failed to create evemu device");
+ }
+}
+
+void xorg::testing::evemu::Device::Play(const std::string& path) const {
+ FILE* file = fopen(path.c_str(), "r");
+ if (!file)
+ throw std::runtime_error("Failed to open recording file");
+
+ if (evemu_play(file, d_->fd) != 0) {
+ fclose(file);
+ throw std::runtime_error("Failed to play evemu recording");
+ }
+
+ fclose(file);
+}
+
+xorg::testing::evemu::Device::~Device() {
+ close(d_->fd);
+ evemu_delete(d_->device);
+}
diff --git a/src/libxorg-gtest.ver b/src/libxorg-gtest.ver
index e66c83a..c617446 100644
--- a/src/libxorg-gtest.ver
+++ b/src/libxorg-gtest.ver
@@ -1,7 +1,9 @@
XORG_GTEST_1.0 {
global:
extern "C++" {
- xorg::testing::*;
+ xorg::testing::Environment::*;
+ xorg::testing::Process::*;
+ xorg::testing::Test::*;
"typeinfo for xorg::testing::Environment";
"typeinfo for xorg::testing::Test";
"typeinfo name for xorg::testing::Environment";
@@ -13,3 +15,10 @@ XORG_GTEST_1.0 {
local:
*;
};
+
+XORG_GTEST_1.1 {
+ global:
+ extern "C++" {
+ xorg::testing::evemu::*;
+ };
+} XORG_GTEST_1.0;
--
1.7.9
More information about the xorg-devel
mailing list