Fix Travis build by running tests as root

A recent configuration change made it necessary to run our tests on
Travis as root.

This change also increases the timeout of ParallelChildCrashesDontHang
to make it pass in Travis virtualized containers.

Bug: google-breakpad:753
Change-Id: I6ca8ff4513c6ea3e0646f22457f28b5c4fca6654
Reviewed-on: https://chromium-review.googlesource.com/890564
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/.travis.yml b/.travis.yml
index 4a7b775..628362d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,6 +2,8 @@
 # https://docs.travis-ci.com/
 language: cpp
 
+sudo: required
+
 addons:
   apt:
     sources:
diff --git a/Makefile.am b/Makefile.am
index 21e5867..eac914c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -446,8 +446,12 @@
 LOG_DRIVER = $(top_srcdir)/android/test-driver
 else
 # The default Autotools test driver script.
+if TESTS_AS_ROOT
+LOG_DRIVER = $(top_srcdir)/autotools/root-test-driver $(top_srcdir)/autotools/test-driver
+else
 LOG_DRIVER = $(top_srcdir)/autotools/test-driver
-endif
+endif !TESTS_AS_ROOT
+endif !ANDROID_HOST
 
 if LINUX_HOST
 src_client_linux_linux_dumper_unittest_helper_SOURCES = \
diff --git a/Makefile.in b/Makefile.in
index e53104b..2bb6b40 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -2291,8 +2291,9 @@
 @DISABLE_PROCESSOR_FALSE@	src/processor/minidump_stackwalk_machine_readable_test
 
 TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
+@ANDROID_HOST_FALSE@@TESTS_AS_ROOT_FALSE@LOG_DRIVER = $(top_srcdir)/autotools/test-driver
 # The default Autotools test driver script.
-@ANDROID_HOST_FALSE@LOG_DRIVER = $(top_srcdir)/autotools/test-driver
+@ANDROID_HOST_FALSE@@TESTS_AS_ROOT_TRUE@LOG_DRIVER = $(top_srcdir)/autotools/root-test-driver $(top_srcdir)/autotools/test-driver
 
 # Since Autotools 1.2, tests are run through a special "test driver" script.
 # Unfortunately, it's not possible anymore to specify an alternative shell to
diff --git a/autotools/root-test-driver b/autotools/root-test-driver
new file mode 100755
index 0000000..66bf7eb
--- /dev/null
+++ b/autotools/root-test-driver
@@ -0,0 +1,3 @@
+#!/bin/sh
+# -E to keep the environment variables needed to run the tests.
+exec sudo -E "$@"
diff --git a/configure b/configure
index 5e94512..e0187dd 100755
--- a/configure
+++ b/configure
@@ -626,6 +626,8 @@
 am__EXEEXT_TRUE
 LTLIBOBJS
 LIBOBJS
+TESTS_AS_ROOT_FALSE
+TESTS_AS_ROOT_TRUE
 RUST_DEMANGLE_LIBS
 RUST_DEMANGLE_CFLAGS
 SELFTEST_FALSE
@@ -777,6 +779,7 @@
 enable_system_test_libs
 enable_selftest
 with_rust_demangle
+with_tests_as_root
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1444,6 +1447,9 @@
                           Link against the rust-demangle library to demangle
                           Rust language symbols during symbol dumping (default
                           is no) Pass the path to the crate root.
+  --with-tests-as-root    Run the tests as root. Use this on platforms like
+                          travis-ci.org that require root privileges to use
+                          ptrace (default is no)
 
 Some influential environment variables:
   CC          C compiler command
@@ -7870,6 +7876,33 @@
 
 
 
+
+# Check whether --with-tests-as-root was given.
+if test "${with_tests_as_root+set}" = set; then :
+  withval=$with_tests_as_root; case "${withval}" in
+               yes)
+                 tests_as_root=true
+                 ;;
+               no)
+                 tests_as_root=false
+                 ;;
+               *)
+                 as_fn_error $? "--with-tests-as-root can only be \"yes\" or \"no\"" "$LINENO" 5
+                 ;;
+             esac
+else
+  tests_as_root=false
+fi
+
+ if test x$tests_as_root = xtrue; then
+  TESTS_AS_ROOT_TRUE=
+  TESTS_AS_ROOT_FALSE='#'
+else
+  TESTS_AS_ROOT_TRUE='#'
+  TESTS_AS_ROOT_FALSE=
+fi
+
+
 ac_config_files="$ac_config_files breakpad.pc breakpad-client.pc Makefile"
 
 
@@ -8049,6 +8082,10 @@
   as_fn_error $? "conditional \"SELFTEST\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${TESTS_AS_ROOT_TRUE}" && test -z "${TESTS_AS_ROOT_FALSE}"; then
+  as_fn_error $? "conditional \"TESTS_AS_ROOT\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 
 : "${CONFIG_STATUS=./config.status}"
 ac_write_fail=0
diff --git a/configure.ac b/configure.ac
index ec194dd..9cca5aa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -246,6 +246,25 @@
 AC_ARG_VAR([RUST_DEMANGLE_CFLAGS], [Compiler flags for rust-demangle])
 AC_ARG_VAR([RUST_DEMANGLE_LIBS], [Linker flags for rust-demangle])
 
+AC_ARG_WITH(tests-as-root,
+            AS_HELP_STRING([--with-tests-as-root],
+                           [Run the tests as root. Use this on platforms]
+                           [like travis-ci.org that require root privileges]
+                           [to use ptrace (default is no)]),
+            [case "${withval}" in
+               yes)
+                 tests_as_root=true
+                 ;;
+               no)
+                 tests_as_root=false
+                 ;;
+               *)
+                 AC_MSG_ERROR(--with-tests-as-root can only be "yes" or "no")
+                 ;;
+             esac],
+            [tests_as_root=false])
+AM_CONDITIONAL(TESTS_AS_ROOT, test x$tests_as_root = xtrue)
+
 AC_CONFIG_FILES(m4_flatten([
   breakpad.pc
   breakpad-client.pc
diff --git a/scripts/travis-build.sh b/scripts/travis-build.sh
index a5f7ad5..1d1beb3 100755
--- a/scripts/travis-build.sh
+++ b/scripts/travis-build.sh
@@ -43,7 +43,7 @@
 
 # Do an in-tree build and make sure tests pass.
 build() {
-  ./configure
+  ./configure --with-tests-as-root
   make -j${JOBS} check VERBOSE=1
   make distclean
 }
@@ -52,7 +52,7 @@
 build_out_of_tree() {
   mkdir -p build/native
   pushd build/native >/dev/null
-  ../../configure
+  ../../configure --with-tests-as-root
   make -j${JOBS} distcheck VERBOSE=1
   popd >/dev/null
 }