From 2a34936437e5c3c3e5e7f3621cf92fa94eaa466a Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Fri, 7 Jun 2013 13:01:44 +0900 Subject: [PATCH] build: improve test harness Run each test in isolated directory so it can run in parallel. Also improve the test wrapper and rename it to a better name. BUG= Review URL: https://codereview.appspot.com/9937047 --- autogen.sh | 2 +- configure.ac | 2 +- src/tests/Makefile.am | 5 ++- src/tests/runtest | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/tests/setupenv | 42 ------------------ 5 files changed, 122 insertions(+), 46 deletions(-) create mode 100755 src/tests/runtest delete mode 100755 src/tests/setupenv diff --git a/autogen.sh b/autogen.sh index 9786ed1..fb1a9ec 100755 --- a/autogen.sh +++ b/autogen.sh @@ -25,4 +25,4 @@ which gnome-autogen.sh || { CFLAGS=${CFLAGS-"-Wall -Werror"} # need --enable-gtk-doc for gnome-autogen.sh to make dist -ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I m4" REQUIRED_AUTOMAKE_VERSION=1.10 CFLAGS="$CFLAGS" . gnome-autogen.sh "$@" +ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I m4" REQUIRED_AUTOMAKE_VERSION=1.11 CFLAGS="$CFLAGS" . gnome-autogen.sh "$@" diff --git a/configure.ac b/configure.ac index 369b505..1aba305 100644 --- a/configure.ac +++ b/configure.ac @@ -55,7 +55,7 @@ m4_define([glib_required_version], [2.32.0]) # Init automake. -AM_INIT_AUTOMAKE([1.10]) +AM_INIT_AUTOMAKE([1.11.1 parallel-tests]) AM_MAINTAINER_MODE([enable]) AC_GNU_SOURCE diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index cc029d1..a46113c 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -60,10 +60,11 @@ TESTS_ENVIRONMENT = \ top_builddir=$(top_builddir) \ top_srcdir=$(top_srcdir) \ builddir=$(builddir) \ - $(srcdir)/setupenv \ $(NULL) -EXTRA_DIST = setupenv +LOG_COMPILER = $(srcdir)/runtest + +EXTRA_DIST = runtest ibus_bus_SOURCES = ibus-bus.c ibus_bus_LDADD = $(prog_ldadd) diff --git a/src/tests/runtest b/src/tests/runtest new file mode 100755 index 0000000..a600f6b --- /dev/null +++ b/src/tests/runtest @@ -0,0 +1,117 @@ +#!/bin/sh + +# Run a test case given by the first argument in a separate directory. +# This script may also launch $top_builddir/bus/ibus-daemon for testing. + +# Executing a test that uses this file +# ==================================== +# +# Running a single test: +# +# $ make check TESTS=ibus-foo +# +# or +# +# $ top_builddir=<...> top_srcdir=<...> builddir=<...> ./runtest ibus-foo + +: ${top_builddir:=../..} +: ${top_srcdir:=../..} +: ${builddir:=.} + +BUS_REQUIRED_TESTS=" +ibus-bus +ibus-config +ibus-configservice +ibus-factory +ibus-inputcontext +ibus-inputcontext-create +ibus-engine-switch +" + +# Portable replacement of basename. +func_basename () { + case "$1" in + */*) + expr "$1" : '.*/\(.*\)' + ;; + *) + echo "$1" + esac +} + +# Portable replacement of dirname. +func_dirname () { + case "$1" in + */*) + expr "$1" : '\(.*\)/.*' + ;; + *) + echo . + esac +} + +# Kill ibus-daemon process and remove temporary files. +func_cleanup () { + tstdir=$1 + if test -f $tstdir/ibus-daemon.pid; then + . $tstdir/ibus-daemon.pid + kill $IBUS_DAEMON_PID &> /dev/null + fi + rm -fr $tstdir +} + +# Prepare component files necessary for testing, under components/. +func_copy_component () { + file=$1 + base=`func_basename $file` + if test -f $file.in; then + mkdir -p components + sed 's|@libexecdir@|'`func_dirname $file`'|g' < $file.in > components/$base + fi +} + +trap 'func_cleanup $tstdir' 1 2 3 15 + +tst=$1; shift +tstdir=tmp-`func_basename $tst` + +test -d $tstdir || mkdir $tstdir + +( cd $tstdir + + need_bus=no + for t in $BUS_REQUIRED_TESTS; do + if test $t = `func_basename $tst`; then + need_bus=yes + fi + done + + if test $need_bus = yes; then + func_copy_component "../$top_srcdir/engine/simple.xml" + func_copy_component "../$top_srcdir/conf/memconf/memconf.xml" + + IBUS_COMPONENT_PATH=$PWD/components + export IBUS_COMPONENT_PATH + + IBUS_ADDRESS_FILE=$PWD/ibus-daemon.pid + export IBUS_ADDRESS_FILE + + # Start ibus-daemon. + ../$top_builddir/bus/ibus-daemon \ + --daemonize \ + --cache=none \ + --panel=disable \ + --config=default \ + --verbose; + + # Wait until all necessary components are up. + sleep 1 + fi + + exec "../$tst" ${1+"$@"} ) + +retval=$? + +func_cleanup $tstdir + +exit $retval diff --git a/src/tests/setupenv b/src/tests/setupenv deleted file mode 100755 index df269e4..0000000 --- a/src/tests/setupenv +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/sh - -: ${top_builddir:=../..} -: ${top_srcdir:=../..} -: ${builddir:=.} - -trap 'exit' 1 2 3 15 -trap '. $IBUS_ADDRESS_FILE; kill $IBUS_DAEMON_PID &> /dev/null; rm -fr components $IBUS_ADDRESS_FILE' EXIT - -# copy some component files necessary for testing, under components/ -copy_component() { - file=$1 - base=`basename $file` - if test -f $file.in; then - mkdir -p components - ( libexecdir=`dirname $file`; - s=`cat $file.in`; - eval "echo \"${s}\"" ) > components/$base - fi -} -copy_component "$top_srcdir/engine/simple.xml" -copy_component "$top_srcdir/conf/memconf/memconf.xml" - -# start ibus-daemon -IBUS_COMPONENT_PATH=$PWD/components -export IBUS_COMPONENT_PATH - -IBUS_ADDRESS_FILE=$PWD/ibus-daemon.log -export IBUS_ADDRESS_FILE - -$top_builddir/bus/ibus-daemon \ - --daemonize \ - --cache=none \ - --panel=disable \ - --config=default \ - --verbose - -# wait until all necessary components are up -sleep 1 - -# run tests -"$@" -- 2.7.4