summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2012-07-06 16:35:50 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2012-07-06 16:35:50 +1000
commitf94bbe302c749a736ce0506c7d4d4af11ad93121 (patch)
tree11147c367977d0c350dc9d72e116894dad1a27bc
initial setup for X.Org testing through googletestxorg-integration-tests-0.0.1
Includes a basic test that should bring up an acecad device and test for its presence. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--.gitignore83
-rw-r--r--Makefile-xorg-gtest.am64
-rw-r--r--Makefile.am5
-rwxr-xr-xautogen.sh12
-rw-r--r--configure.ac53
-rw-r--r--m4/xorg-gtest.m4110
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.am24
-rw-r--r--tests/acecad.cpp132
9 files changed, 484 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2729ff1
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,83 @@
+#
+# X.Org module default exclusion patterns
+# The next section if for module specific patterns
+#
+# Do not edit the following section
+# GNU Build System (Autotools)
+aclocal.m4
+autom4te.cache/
+autoscan.log
+ChangeLog
+compile
+config.guess
+config.h
+config.h.in
+config.log
+config-ml.in
+config.py
+config.status
+config.status.lineno
+config.sub
+configure
+configure.scan
+depcomp
+.deps/
+INSTALL
+install-sh
+.libs/
+libtool
+libtool.m4
+ltmain.sh
+lt~obsolete.m4
+ltoptions.m4
+ltsugar.m4
+ltversion.m4
+Makefile
+Makefile.in
+mdate-sh
+missing
+mkinstalldirs
+*.pc
+py-compile
+stamp-h?
+symlink-tree
+texinfo.tex
+ylwrap
+
+# Do not edit the following section
+# Edit Compile Debug Document Distribute
+*~
+*.[0-9]
+*.[0-9]x
+*.bak
+*.bin
+core
+*.dll
+*.exe
+*-ISO*.bdf
+*-JIS*.bdf
+*-KOI8*.bdf
+*.kld
+*.ko
+*.ko.cmd
+*.lai
+*.l[oa]
+*.[oa]
+*.obj
+*.patch
+*.so
+*.pcf.gz
+*.pdb
+*.tar.bz2
+*.tar.gz
+#
+# Add & Override patterns for xserver
+#
+# Edit the following section as needed
+# For example, !report.pc overrides *.pc. See 'man gitignore'
+#
+doltcompile
+doltlibtool
+xserver.ent
+
+*.swp
diff --git a/Makefile-xorg-gtest.am b/Makefile-xorg-gtest.am
new file mode 100644
index 0000000..20983eb
--- /dev/null
+++ b/Makefile-xorg-gtest.am
@@ -0,0 +1,64 @@
+# 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.
+#
+
+XORG_GTEST_BUILD_LIBS = \
+ libgtest.a \
+ libgtest_main.a \
+ libxorg-gtest.a \
+ libxorg-gtest_main.a
+
+# Here and below we compile without warnings (-w) because the projects using
+# xorg-gtest will not want to see warnings or fail to build due to warnings in
+# gtest or xorg-gtest.
+nodist_libgtest_a_SOURCES = $(GTEST_SOURCE)/src/gtest-all.cc
+libgtest_a_CPPFLAGS = $(GTEST_CPPFLAGS) $(AM_CPPFLAGS) -w
+libgtest_a_CXXFLAGS = $(GTEST_CXXFLAGS) $(AM_CXXFLAGS)
+
+nodist_libgtest_main_a_SOURCES = $(GTEST_SOURCE)/src/gtest_main.cc
+libgtest_main_a_CPPFLAGS = $(GTEST_CPPFLAGS) $(AM_CPPFLAGS) -w
+libgtest_main_a_CXXFLAGS = $(GTEST_CXXFLAGS) $(AM_CXXFLAGS)
+
+nodist_libxorg_gtest_a_SOURCES = $(XORG_GTEST_SOURCE)/src/xorg-gtest-all.cpp
+libxorg_gtest_a_CPPFLAGS = \
+ $(XORG_GTEST_CPPFLAGS) \
+ $(GTEST_CPPFLAGS) \
+ $(AM_CPPFLAGS) \
+ -w
+libxorg_gtest_a_CXXFLAGS = \
+ $(XORG_GTEST_CXXFLAGS) \
+ $(GTEST_CXXFLAGS) \
+ $(AM_CPPFLAGS)
+
+nodist_libxorg_gtest_main_a_SOURCES = \
+ $(XORG_GTEST_SOURCE)/src/xorg-gtest_main.cpp
+libxorg_gtest_main_a_CPPFLAGS = \
+ $(XORG_GTEST_CPPFLAGS) \
+ $(GTEST_CPPFLAGS) \
+ $(AM_CPPFLAGS) \
+ -w
+libxorg_gtest_main_a_CXXFLAGS = \
+ $(XORG_GTEST_CXXFLAGS) \
+ $(GTEST_CXXFLAGS) \
+ $(AM_CXXFLAGS)
+
+XORG_GTEST_LIBS = libxorg-gtest.a libgtest.a -lpthread $(X11_LIBS)
+XORG_GTEST_MAIN_LIBS = libxorg-gtest_main.a
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..95f6af3
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,5 @@
+ACLOCAL_AMFLAGS = -I m4
+
+SUBDIRS = tests
+
+EXTRA_DIST = autogen.sh
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..904cd67
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,12 @@
+#! /bin/sh
+
+srcdir=`dirname $0`
+test -z "$srcdir" && srcdir=.
+
+ORIGDIR=`pwd`
+cd $srcdir
+
+autoreconf -v --install || exit 1
+cd $ORIGDIR || exit $?
+
+$srcdir/configure --enable-maintainer-mode "$@"
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..703aec4
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,53 @@
+# Copyright 2012 Red Hat, Inc.
+#
+# 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
+# on the rights to use, copy, modify, merge, publish, distribute, sub
+# license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL
+# ADAM JACKSON 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.
+#
+# Process this file with autoconf to produce a configure script
+
+# Initialize Autoconf
+AC_PREREQ([2.60])
+AC_INIT([RHEL-XOrg-testing], [0.0.1])
+AC_CONFIG_SRCDIR([Makefile.am])
+AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_AUX_DIR(.)
+
+# Initialize Automake
+AM_INIT_AUTOMAKE([foreign dist-bzip2 no-dist-gzip])
+AM_MAINTAINER_MODE
+
+# Initialize libtool
+AC_DISABLE_STATIC
+AC_PROG_LIBTOOL
+AC_PROG_CXX
+
+m4_ifndef([XORG_MACROS_VERSION],
+ [m4_fatal([must install xorg-macros 1.17 or later before running autoconf/autogen])])
+XORG_MACROS_VERSION(1.17)
+XORG_DEFAULT_OPTIONS
+XORG_ENABLE_INTEGRATION_TESTS(yes)
+
+PKG_CHECK_MODULES(XI, x11 [xi >= 1.6])
+PKG_CHECK_MODULES(EVEMU, utouch-evemu)
+PKG_CHECK_MODULES(XORGGTEST, xorg-gtest)
+
+CHECK_XORG_GTEST
+
+AC_CONFIG_FILES([Makefile
+ tests/Makefile])
+AC_OUTPUT
diff --git a/m4/xorg-gtest.m4 b/m4/xorg-gtest.m4
new file mode 100644
index 0000000..062842c
--- /dev/null
+++ b/m4/xorg-gtest.m4
@@ -0,0 +1,110 @@
+# serial 2
+
+# 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.
+
+# Checks whether the gtest source is available on the system. Allows for
+# adjusting the include and source path. Sets have_gtest=yes if the source is
+# present. Sets GTEST_CPPFLAGS and GTEST_SOURCE to the preprocessor flags and
+# source location respectively.
+AC_DEFUN([_CHECK_GTEST],
+[
+ AC_ARG_WITH([gtest-source-path],
+ [AS_HELP_STRING([--with-gtest-source-path],
+ [location of the Google test sources, defaults to /usr/src/gtest])],
+ [GTEST_SOURCE="$withval"; GTEST_CPPFLAGS="-I$withval/include"],
+ [GTEST_SOURCE="/usr/src/gtest"])
+
+ AC_ARG_WITH([gtest-include-path],
+ [AS_HELP_STRING([--with-gtest-include-path],
+ [location of the Google test headers])],
+ [GTEST_CPPFLAGS="-I$withval"])
+
+ GTEST_CPPFLAGS="$GTEST_CPPFLAGS -I$GTEST_SOURCE"
+
+ AC_CHECK_FILES([$GTEST_SOURCE/src/gtest-all.cc]
+ [$GTEST_SOURCE/src/gtest_main.cc],
+ [have_gtest=yes],
+ [have_gtest=no])
+
+ AS_IF([test "x$have_gtest_source" = xyes],
+ [AC_SUBST(GTEST_CPPFLAGS)]
+ [AC_SUBST(GTEST_SOURCE)])
+]) # _CHECK_GTEST
+
+# CHECK_XORG_GTEST([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+#
+# Checks whether the xorg-gtest source is available on the system. Allows for
+# adjusting the include and source path. Sets have_xorg_gtest=yes if the source
+# is present. Sets XORG_GTEST_CPPFLAGS and XORG_GTEST_SOURCE to the preprocessor
+# flags and source location respectively. Sets XORG_GTEST_LIBS to all the
+# libraries needed to link against a built xorg-gtest library.
+#
+# Both default actions are no-ops.
+AC_DEFUN([CHECK_XORG_GTEST],
+[
+ AC_REQUIRE([_CHECK_GTEST])
+
+ PKG_CHECK_EXISTS([xorg-gtest],
+ [have_xorg_gtest=yes],
+ [have_xorg_gtest=no])
+
+ XORG_GTEST_SOURCE=`$PKG_CONFIG --variable=sourcedir --print-errors xorg-gtest`
+ XORG_GTEST_CPPFLAGS=`$PKG_CONFIG --variable=CPPflags --print-errors xorg-gtest`
+ XORG_GTEST_CPPFLAGS="$GTEST_CPPFLAGS $XORG_GTEST_CPPFLAGS"
+ XORG_GTEST_CPPFLAGS="$XORG_GTEST_CPPFLAGS -I$XORG_GTEST_SOURCE"
+
+ PKG_CHECK_MODULES(X11, [x11], [have_x11=yes], [have_x11=no])
+
+ # 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_xorg_gtest_evemu=yes])],
+ [test "x$with_evemu" = xcheck],
+ [PKG_CHECK_MODULES(EVEMU,
+ [utouch-evemu],
+ [have_xorg_gtest_evemu=yes],
+ [have_xorg_gtest_evemu=no])])
+ AS_IF([test "x$have_xorg_gtest_evemu" = xyes],
+ [XORG_GTEST_CPPFLAGS="$XORG_GTEST_CPPFLAGS -DHAVE_EVEMU"])
+
+ AS_IF([test "x$have_gtest" != xyes -o "x$have_x11" != xyes],
+ [have_xorg_gtest=no])
+
+ AS_IF([test "x$have_xorg_gtest" = xyes],
+ [AC_SUBST(XORG_GTEST_SOURCE)]
+ [AC_SUBST(XORG_GTEST_CPPFLAGS)]
+
+ # Get BASE_CXXFLAGS and STRICT_CXXFLAGS
+ [XORG_MACROS_VERSION(1.17)]
+ [AC_LANG_PUSH([C++])]
+ [XORG_STRICT_OPTION]
+ [AC_LANG_POP]
+ [$1],
+ [$2])
+
+]) # CHECK_XORG_GTEST
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 0000000..4a27085
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1 @@
+acecad
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..51e84a6
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,24 @@
+noinst_PROGRAMS = acecad
+
+include $(top_srcdir)/Makefile-xorg-gtest.am
+noinst_LIBRARIES = $(XORG_GTEST_BUILD_LIBS)
+
+TESTS=$(noinst_PROGRAMS)
+
+AM_CPPFLAGS = \
+ $(XI_CFLAGS) \
+ $(GTEST_CPPFLAGS) \
+ $(XORG_GTEST_CPPFLAGS) \
+ -DDEFAULT_XORG_SERVER=\"$(prefix)/bin/Xorg\" \
+ -DTEST_ROOT_DIR=\"$(abs_top_srcdir)/tests/\"
+
+AM_CXXFLAGS = $(GTEST_CXXFLAGS) $(XORG_GTEST_CXXFLAGS)
+
+GTEST_LDADDS = \
+ $(XI_LIBS) \
+ $(XORG_GTEST_LIBS) \
+ $(EVEMU_LIBS) \
+ $(XORG_GTEST_MAIN_LIBS)
+
+acecad_SOURCES = acecad.cpp
+acecad_LDADD = $(GTEST_LDADDS)
diff --git a/tests/acecad.cpp b/tests/acecad.cpp
new file mode 100644
index 0000000..dbdf5ad
--- /dev/null
+++ b/tests/acecad.cpp
@@ -0,0 +1,132 @@
+#include <stdexcept>
+#include <fstream>
+#include <xorg/gtest/xorg-gtest.h>
+
+#include <X11/extensions/XInput.h>
+#include <X11/extensions/XInput2.h>
+
+/**
+ * A test fixture for testing some input drivers
+ *
+ */
+class InputDriverTest : public xorg::testing::Test,
+ public ::testing::WithParamInterface<const char*> {
+protected:
+ void WriteConfig(const char *param) {
+ std::stringstream s;
+ s << "/tmp/" << param << ".conf";
+ config_file = s.str();
+
+ std::ofstream conffile(config_file.c_str());
+ conffile.exceptions(std::ofstream::failbit | std::ofstream::badbit);
+
+ std::string driver(param);
+
+ conffile << ""
+" Section \"ServerLayout\""
+" Identifier \"Dummy layout\""
+" Screen 0 \"Dummy screen\" 0 0"
+" Option \"AutoAddDevices\" \"off\""
+" InputDevice \"--device--\""
+""
+" EndSection"
+""
+" Section \"Screen\""
+" Identifier \"Dummy screen\""
+" Device \"Dummy video device\""
+" EndSection"
+""
+" Section \"Device\""
+" Identifier \"Dummy video device\""
+" Driver \"dummy\""
+" EndSection";
+ server.SetOption("-config", config_file);
+ }
+
+ void AddDriverSection(const char *param, const char *options = "") {
+ std::ofstream conffile(config_file.c_str(), std::ios_base::app);
+ conffile.exceptions(std::ofstream::failbit | std::ofstream::badbit);
+
+ std::string driver(param);
+
+ conffile << ""
+" Section \"InputDevice\""
+" Identifier \"--device--\""
+" Driver \"" << driver << "\""
+ << options <<
+" EndSection";
+ server.SetOption("-config", config_file);
+ }
+
+ void StartServer() {
+ server.Start();
+ server.WaitForConnections();
+ xorg::testing::Test::SetDisplayString(server.GetDisplayString());
+
+ ASSERT_NO_FATAL_FAILURE(xorg::testing::Test::SetUp());
+
+ int event_start;
+ int error_start;
+
+ ASSERT_TRUE(XQueryExtension(Display(), "XInputExtension", &xi2_opcode_,
+ &event_start, &error_start));
+
+ int major = 2;
+ int minor = 0;
+
+ ASSERT_EQ(Success, XIQueryVersion(Display(), &major, &minor));
+ }
+
+ virtual void SetUp()
+ {
+ WriteConfig(GetParam());
+ AddDriverSection(GetParam());
+ StartServer();
+ }
+
+ virtual void TearDown()
+ {
+ if (server.Pid() != -1)
+ if (!server.Terminate())
+ server.Kill();
+
+ if (config_file.size())
+ unlink(config_file.c_str());
+ }
+
+ int xi2_opcode_;
+ std::string config_file;
+ xorg::testing::XServer server;
+};
+
+TEST_P(InputDriverTest, DriverDevice)
+{
+ const char *param;
+ int ndevices;
+ XIDeviceInfo *info;
+
+ param = GetParam();
+ info = XIQueryDevice(Display(), XIAllDevices, &ndevices);
+ /* VCP, VCK, 2 test devices, forced mouse/keyboard */
+ ASSERT_EQ(ndevices, 6) << "Drivers required for this test: mouse, "
+ "keyboard, " << param;
+
+ bool found = false;
+ while(ndevices--) {
+ if (strcmp(info[ndevices].name, "--device--") == 0) {
+ ASSERT_EQ(found, false) << "Duplicate device" << std::endl;
+ found = true;
+ }
+ }
+
+ ASSERT_EQ(found, true);
+
+ XIFreeDeviceInfo(info);
+}
+
+INSTANTIATE_TEST_CASE_P(, InputDriverTest, ::testing::Values("acecad"));
+
+int main(int argc, char **argv) {
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}