summaryrefslogtreecommitdiff
path: root/php
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2008-08-07 20:19:28 -0700
committerRuss Allbery <rra@stanford.edu>2008-08-07 20:19:28 -0700
commitc02f5a1bfaf6e3b55f4575936f17d7878ef4689b (patch)
treeff05579cee9d5ee8938a2cc15e5c403cef931d02 /php
parent1daef6c89197e06d5607c0b7fb40103eea6e0248 (diff)
Integrate PHP testing into the build system
Add a wrapper around the PHP make test that works around the Debian module configuration problem by linking all the system modules into the modules directory. The wrapper also gets a Kerberos ticket and spawns a remctl server for the use of the tests.
Diffstat (limited to 'php')
-rwxr-xr-xphp/test-wrapper111
1 files changed, 111 insertions, 0 deletions
diff --git a/php/test-wrapper b/php/test-wrapper
new file mode 100755
index 0000000..3644a37
--- /dev/null
+++ b/php/test-wrapper
@@ -0,0 +1,111 @@
+#! /bin/sh
+#
+# This wrapper exists for two reasons: to work around a bug in the
+# phpize-generated test suite on Debian, and because I'm not a PHP programmer
+# and didn't want to figure out how to spawn a test version of remctld inside
+# PHP.
+#
+# This script starts a remctl server, if the right configuration is
+# available, and works around the Debian bug, then runs make test, and then
+# cleans up. It takes the path to the top of the remctl build directory as
+# its argument and should be run from the php directory.
+#
+# Written by Russ Allbery <rra@stanford.edu>
+# Copyright 2008 Board of Trustees, Leland Stanford Jr. University
+#
+# See LICENSE for licensing terms.
+
+if [ -z "$1" ] ; then
+ echo 'Missing top build directory argument' >&2
+ exit 1
+fi
+top="$1"
+
+# Debian loads additional modules from /etc/php5/cli/conf.d, and the test
+# framework doesn't deal with this. PHP only allows one module directory, so
+# when the test framework overrides the module directory, none of the standard
+# modules can be found. This causes initialization to fail and the tests to
+# fail.
+#
+# Work around it by extracting the regular PHP module directory from the
+# generated Makefile and then symlinking all modules in that directory into
+# the modules/ subdirectory used by the test suite.
+path=`grep '^EXTENSION_DIR *=' Makefile | sed 's/.* //'`
+if [ -z "$path" ] ; then
+ echo 'Cannot find EXTENSION_DIR in Makefile' >&2
+ exit 1
+fi
+for module in "$path"/*.so ; do
+ name=`basename "$module"`
+ if [ "$name" = "remctl.so" ] ; then
+ continue
+ fi
+ ln -s "$module" modules/"$name"
+done
+
+# Check whether we have a Kerberos configuration. If we do, we'll start a
+# remctl daemon and obtain a local ticket cache, and then touch a file telling
+# PHP to do the tests that require authentication.
+if [ -f "$top/tests/data/test.keytab" ] ; then
+ rm -f remctl-test.pid
+ principal=`cat "$top/tests/data/test.principal"`
+ keytab="$top/tests/data/test.keytab"
+ ( "$top/server/remctld" -m -p 14373 -s "$principal" -P remctl-test.pid \
+ -f "$top/tests/data/conf-simple" -d -S -F -k "$keytab" \
+ > remctl-test.out 2>&1 &)
+
+ # Try a few different syntaxes for kinit to allow for Heimdal, MIT, or the
+ # Stanford-local hack.
+ KRB5CCNAME=remctl-test.cache
+ export KRB5CCNAME
+ kinit -k -t "$keytab" "$principal" >/dev/null </dev/null
+ status=$?
+ if [ $status != 0 ] ; then
+ kinit -t "$keytab" "$principal" >/dev/null </dev/null
+ status=$?
+ fi
+ if [ $status != 0 ] ; then
+ kinit -k -K "$keytab" "$principal" >/dev/null </dev/null
+ status=$?
+ fi
+
+ # Wait for the remctl server to finish starting. Then, if we couldn't get
+ # Kerberos tickets, kill the remctl server.
+ [ -f remctl-test.pid ] || sleep 1
+ if [ $status != 0 ] ; then
+ echo 'Unable to obtain Kerberos tickets' >&2
+ if [ -f remctl-test.pid ] ; then
+ kill -HUP `cat remctl-test.pid`
+ fi
+ rm -f remctl-test.pid
+ else
+ if [ ! -f remctl-test.pid ] ; then
+ echo 'remctld did not start' >&2
+ fi
+ fi
+fi
+
+# Now we can finally run the tests, which will use remctl-test.pid as a flag
+# for whether to try the Kerberos tests.
+make test
+status=$?
+
+# Kill the remctl server.
+rm remctl-test.cache
+if [ "$status" = 0 ] ; then
+ rm -f remctl-test.out
+fi
+if [ -f remctl-test.pid ] ; then
+ kill -TERM `cat remctl-test.pid`
+ rm -f remctl-test.pid
+fi
+
+# Clean up our symlinks.
+for file in modules/* ; do
+ if [ `basename "$file"` != remctl.so ] ; then
+ rm "$file"
+ fi
+done
+
+# Exit with the exit status of the tests.
+exit "$status"