[PATCH xorg-gtest 09/11] test: add a self-check directory

Peter Hutterer peter.hutterer at who-t.net
Wed Aug 15 23:36:42 PDT 2012


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 Makefile.am           |  2 +-
 configure.ac          |  1 +
 test/.gitignore       |  1 +
 test/Makefile.am      | 62 +++++++++++++++++++++++++++++++++++++++++++++
 test/process-test.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 135 insertions(+), 1 deletion(-)
 create mode 100644 test/.gitignore
 create mode 100644 test/Makefile.am
 create mode 100644 test/process-test.cpp

diff --git a/Makefile.am b/Makefile.am
index 8e0a0c6..b984c8e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -23,7 +23,7 @@
 # SOFTWARE.
 #
 
-SUBDIRS = aclocal data doc include src examples
+SUBDIRS = aclocal data doc include src examples test
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = xorg-gtest.pc
diff --git a/configure.ac b/configure.ac
index e113dee..9245d99 100644
--- a/configure.ac
+++ b/configure.ac
@@ -83,6 +83,7 @@ AC_CONFIG_FILES([Makefile
                  examples/Makefile
                  include/Makefile
                  src/Makefile
+                 test/Makefile
                  xorg-gtest.pc])
 
 AC_OUTPUT
diff --git a/test/.gitignore b/test/.gitignore
new file mode 100644
index 0000000..096072f
--- /dev/null
+++ b/test/.gitignore
@@ -0,0 +1 @@
+process-test
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..44c1027
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,62 @@
+#
+# @file examples/Makefile.am
+# @brief automake recipe for the xorg-gtest self-tests
+#
+# Copyright (C) 2011, 2012 Canonical, Ltd.
+# 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 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.
+#
+
+noinst_PROGRAMS = process-test
+
+AM_CPPFLAGS = $(GTEST_CPPFLAGS)
+AM_CXXFLAGS = $(BASE_CXXFLAGS)
+
+tests_libraries = \
+	libgtest.a \
+	libxorg-gtest.a \
+	-lpthread \
+	$(X11_LIBS) \
+	$(EVEMU_LIBS)
+
+process_test_SOURCES = process-test.cpp
+process_test_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/include
+process_test_LDADD =  $(tests_libraries)
+
+check_LIBRARIES = libgtest.a libxorg-gtest.a
+
+# build googletest as static lib
+nodist_libgtest_a_SOURCES = $(GTEST_SOURCE)/src/gtest-all.cc
+libgtest_a_CPPFLAGS = $(AM_CPPFLAGS) -w
+libgtest_a_CXXFLAGS = $(GTEST_CXXFLAGS) $(AM_CXXFLAGS)
+
+# build xorg-gtest as static lib
+libxorg_gtest_a_SOURCES = $(top_srcdir)/src/xorg-gtest-all.cpp
+libxorg_gtest_a_CPPFLAGS = \
+	$(AM_CPPFLAGS) \
+	-I$(top_srcdir)/include \
+	-I$(top_srcdir) \
+	-DDUMMY_CONF_PATH="\"$(top_srcdir)/data/xorg/gtest/dummy.conf\""
+libxorg_gtest_a_CXXFLAGS = $(GTEST_CXXFLAGS) $(AM_CXXFLAGS)
+
+if ENABLE_XORG_GTEST_TESTS
+TESTS = $(noinst_PROGRAMS)
+endif
diff --git a/test/process-test.cpp b/test/process-test.cpp
new file mode 100644
index 0000000..dc5402c
--- /dev/null
+++ b/test/process-test.cpp
@@ -0,0 +1,70 @@
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <gtest/gtest.h>
+#include <xorg/gtest/xorg-gtest.h>
+
+using namespace xorg::testing;
+
+TEST(Process, StartWithNULLArg)
+{
+  SCOPED_TRACE("TESTCASE: invocation of 'ls' with no arguments");
+  Process p;
+  p.Start("ls", NULL);
+  ASSERT_GT(p.Pid(), 0);
+}
+
+TEST(Process, StartWithNULLTerminatedArg)
+{
+  SCOPED_TRACE("TESTCASE: invocation of 'ls' with NULL-terminated argument list");
+
+  Process p;
+  p.Start("ls", "-l", NULL);
+  ASSERT_GT(p.Pid(), 0);
+}
+
+TEST(Process, TerminationSuccess)
+{
+  SCOPED_TRACE("TESTCASE: invocation of 'echo -n', check for success exit status");
+
+  Process p;
+  ASSERT_EQ(p.GetState(), Process::NONE);
+
+  /* Process:Start closes stdout, so we need something that doesn't print */
+  p.Start("echo", "-n", NULL);
+  ASSERT_GT(p.Pid(), 0);
+  ASSERT_EQ(p.GetState(), Process::RUNNING);
+
+  /* ls shouldn't take longer terminate */
+  for (int i = 0; i < 100; i++) {
+    if (p.GetState() == Process::RUNNING)
+      usleep(5000);
+  }
+  ASSERT_EQ(p.GetState(), Process::FINISHED_SUCCESS);
+}
+
+TEST(Process, TerminationFailure)
+{
+  SCOPED_TRACE("TESTCASE: an invalid invocation of 'ls', check for error exit status");
+  Process p;
+  ASSERT_EQ(p.GetState(), Process::NONE);
+
+  /* Process:Start closes stdout, so ls should fail with status 2, if not,
+   * that file is unlikely to exists so we get status 1 */
+  p.Start("ls", "asqwerq.aqerqw_rqwe", NULL);
+  ASSERT_GT(p.Pid(), 0);
+  ASSERT_EQ(p.GetState(), Process::RUNNING);
+
+  /* ls shouldn't take longer than 5s to terminate */
+  for (int i = 0; i < 10; i++) {
+    if (p.GetState() == Process::RUNNING)
+      usleep(500);
+  }
+  ASSERT_EQ(p.GetState(), Process::FINISHED_FAILURE);
+}
+
+
+int main(int argc, char *argv[]) {
+  testing::InitGoogleTest(&argc, argv);
+  return RUN_ALL_TESTS();
+}
-- 
1.7.11.2



More information about the xorg-devel mailing list