| 1 | #! /bin/sh |
|---|
| 2 | # |
|---|
| 3 | # This wrapper exists for two reasons: to work around a bug in the |
|---|
| 4 | # phpize-generated test suite on Debian, and because I'm not a PHP programmer |
|---|
| 5 | # and didn't want to figure out how to spawn a test version of remctld inside |
|---|
| 6 | # PHP. |
|---|
| 7 | # |
|---|
| 8 | # This script starts a remctl server, if the right configuration is available, |
|---|
| 9 | # and works around the Debian bug, then runs make test, and then cleans up. |
|---|
| 10 | # It takes the path to the top of the remctl build directory and the top of |
|---|
| 11 | # the source directory as its arguments and should be run from the php |
|---|
| 12 | # directory. |
|---|
| 13 | # |
|---|
| 14 | # Written by Russ Allbery <rra@stanford.edu> |
|---|
| 15 | # Copyright 2008, 2009 Board of Trustees, Leland Stanford Jr. University |
|---|
| 16 | # |
|---|
| 17 | # See LICENSE for licensing terms. |
|---|
| 18 | |
|---|
| 19 | if [ -z "$1" ] ; then |
|---|
| 20 | echo 'Missing top build directory argument' >&2 |
|---|
| 21 | exit 1 |
|---|
| 22 | fi |
|---|
| 23 | top="$1" |
|---|
| 24 | if [ -z "$2" ] ; then |
|---|
| 25 | echo 'Missing top source directory argument' >&2 |
|---|
| 26 | exit 1 |
|---|
| 27 | fi |
|---|
| 28 | source="$2" |
|---|
| 29 | |
|---|
| 30 | # Debian loads additional modules from /etc/php5/cli/conf.d, and the test |
|---|
| 31 | # framework doesn't deal with this. PHP only allows one module directory, so |
|---|
| 32 | # when the test framework overrides the module directory, none of the standard |
|---|
| 33 | # modules can be found. This causes initialization to fail and the tests to |
|---|
| 34 | # fail. |
|---|
| 35 | # |
|---|
| 36 | # Work around it by extracting the regular PHP module directory from the |
|---|
| 37 | # generated Makefile and then symlinking all modules in that directory into |
|---|
| 38 | # the modules/ subdirectory used by the test suite. |
|---|
| 39 | path=`grep '^EXTENSION_DIR *=' Makefile | sed 's/.* //'` |
|---|
| 40 | if [ -z "$path" ] ; then |
|---|
| 41 | echo 'Cannot find EXTENSION_DIR in Makefile' >&2 |
|---|
| 42 | exit 1 |
|---|
| 43 | fi |
|---|
| 44 | for module in "$path"/*.so ; do |
|---|
| 45 | name=`basename "$module"` |
|---|
| 46 | if [ "$name" = "remctl.so" ] ; then |
|---|
| 47 | continue |
|---|
| 48 | fi |
|---|
| 49 | ln -s "$module" modules/"$name" |
|---|
| 50 | done |
|---|
| 51 | |
|---|
| 52 | # Check whether we have a Kerberos configuration. If we do, we'll start a |
|---|
| 53 | # remctl daemon and obtain a local ticket cache, and then touch a file telling |
|---|
| 54 | # PHP to do the tests that require authentication. |
|---|
| 55 | if [ -f "$top/tests/data/test.keytab" ] ; then |
|---|
| 56 | rm -f remctl-test.pid |
|---|
| 57 | principal=`cat "$top/tests/data/test.principal"` |
|---|
| 58 | keytab="$top/tests/data/test.keytab" |
|---|
| 59 | ( cd "$source/tests" && "$top/server/remctld" -m -p 14373 \ |
|---|
| 60 | -s "$principal" -P "$top/php/remctl-test.pid" -f "data/conf-simple" \ |
|---|
| 61 | -d -S -F -k "$keytab" 2>&1 &) > remctl-test.out |
|---|
| 62 | |
|---|
| 63 | # Try a few different syntaxes for kinit to allow for Heimdal, MIT, or the |
|---|
| 64 | # Stanford-local hack. |
|---|
| 65 | KRB5CCNAME="`pwd`"/remctl-test.cache |
|---|
| 66 | export KRB5CCNAME |
|---|
| 67 | kinit -k -t "$keytab" "$principal" >/dev/null </dev/null |
|---|
| 68 | status=$? |
|---|
| 69 | if [ $status != 0 ] ; then |
|---|
| 70 | kinit -t "$keytab" "$principal" >/dev/null </dev/null |
|---|
| 71 | status=$? |
|---|
| 72 | fi |
|---|
| 73 | if [ $status != 0 ] ; then |
|---|
| 74 | kinit -k -K "$keytab" "$principal" >/dev/null </dev/null |
|---|
| 75 | status=$? |
|---|
| 76 | fi |
|---|
| 77 | |
|---|
| 78 | # Wait for the remctl server to finish starting. Then, if we couldn't get |
|---|
| 79 | # Kerberos tickets, kill the remctl server. |
|---|
| 80 | [ -f remctl-test.pid ] || sleep 1 |
|---|
| 81 | if [ $status != 0 ] ; then |
|---|
| 82 | echo 'Unable to obtain Kerberos tickets' >&2 |
|---|
| 83 | if [ -f remctl-test.pid ] ; then |
|---|
| 84 | kill -HUP `cat remctl-test.pid` |
|---|
| 85 | fi |
|---|
| 86 | rm -f remctl-test.pid |
|---|
| 87 | else |
|---|
| 88 | if [ ! -f remctl-test.pid ] ; then |
|---|
| 89 | echo 'remctld did not start' >&2 |
|---|
| 90 | else |
|---|
| 91 | echo "$principal" > remctl-test.princ |
|---|
| 92 | fi |
|---|
| 93 | fi |
|---|
| 94 | fi |
|---|
| 95 | |
|---|
| 96 | # Now we can finally run the tests, which will use remctl-test.pid as a flag |
|---|
| 97 | # for whether to try the Kerberos tests. |
|---|
| 98 | env LD_LIBRARY_PATH="$top"/client/.libs make test |
|---|
| 99 | status=$? |
|---|
| 100 | |
|---|
| 101 | # Kill the remctl server. |
|---|
| 102 | rm -f remctl-test.cache remctl-test.princ |
|---|
| 103 | if [ "$status" = 0 ] ; then |
|---|
| 104 | rm -f remctl-test.out |
|---|
| 105 | fi |
|---|
| 106 | if [ -f remctl-test.pid ] ; then |
|---|
| 107 | kill -TERM `cat remctl-test.pid` |
|---|
| 108 | rm -f remctl-test.pid |
|---|
| 109 | fi |
|---|
| 110 | |
|---|
| 111 | # Clean up our symlinks. |
|---|
| 112 | for file in modules/* ; do |
|---|
| 113 | if [ `basename "$file"` != remctl.so ] ; then |
|---|
| 114 | rm "$file" |
|---|
| 115 | fi |
|---|
| 116 | done |
|---|
| 117 | |
|---|
| 118 | # Exit with the exit status of the tests. |
|---|
| 119 | exit "$status" |
|---|