|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +function version_compare() { |
| 4 | + DPKG=`which dpkg` |
| 5 | + |
| 6 | + if [ "x$DPKG" = "x" ]; then |
| 7 | + echo "dpkg not found, cannot compare versions" |
| 8 | + exit 1 |
| 9 | + fi |
| 10 | + |
| 11 | + $DPKG --compare-versions "$1" "$2" "$3" |
| 12 | + return $? |
| 13 | +} |
| 14 | + |
| 15 | +function check_protocol_support() { |
| 16 | + version_compare "$LIBMEMCACHED_VERSION" gt 1.0.15 |
| 17 | + if [ $? = 0 ]; then |
| 18 | + ENABLE_PROTOOCOL=yes |
| 19 | + else |
| 20 | + ENABLE_PROTOOCOL=no |
| 21 | + fi |
| 22 | +} |
| 23 | + |
| 24 | +function check_sasl_support() { |
| 25 | + version_compare "$LIBMEMCACHED_VERSION" gt 1.0.15 |
| 26 | + if [ $? = 0 ]; then |
| 27 | + ENABLE_SASL=yes |
| 28 | + else |
| 29 | + ENABLE_SASL=no |
| 30 | + fi |
| 31 | +} |
| 32 | + |
| 33 | +function validate_package_xml() { |
| 34 | + retval=0 |
| 35 | + for file in tests/*.phpt; do |
| 36 | + grep $(basename $file) package.xml >/dev/null |
| 37 | + if [ $? != 0 ]; then |
| 38 | + echo "Missing $file from package.xml" |
| 39 | + retval=1; |
| 40 | + fi |
| 41 | + done |
| 42 | + return $retval |
| 43 | +} |
| 44 | + |
| 45 | +function install_libmemcached() { |
| 46 | + |
| 47 | + wget "https://launchpad.net/libmemcached/1.0/${LIBMEMCACHED_VERSION}/+download/libmemcached-${LIBMEMCACHED_VERSION}.tar.gz" -O libmemcached-${LIBMEMCACHED_VERSION}.tar.gz |
| 48 | + |
| 49 | + tar xvfz libmemcached-${LIBMEMCACHED_VERSION}.tar.gz |
| 50 | + pushd "libmemcached-${LIBMEMCACHED_VERSION}" |
| 51 | + |
| 52 | + local protocol_flag="" |
| 53 | + if test "x$ENABLE_PROTOOCOL" = "xyes"; then |
| 54 | + protocol_flag="--enable-libmemcachedprotocol" |
| 55 | + fi |
| 56 | + |
| 57 | + ./configure --prefix="$LIBMEMCACHED_PREFIX" $protocol_flag LDFLAGS="-lpthread" |
| 58 | + make |
| 59 | + make install |
| 60 | + popd |
| 61 | +} |
| 62 | + |
| 63 | +function install_igbinary() { |
| 64 | + git clone https://github.com/igbinary/igbinary.git |
| 65 | + pushd igbinary |
| 66 | + phpize |
| 67 | + ./configure |
| 68 | + make |
| 69 | + make install |
| 70 | + popd |
| 71 | +} |
| 72 | + |
| 73 | +function install_msgpack() { |
| 74 | + git clone https://github.com/msgpack/msgpack-php.git |
| 75 | + pushd msgpack-php |
| 76 | + phpize |
| 77 | + ./configure |
| 78 | + make |
| 79 | + make install |
| 80 | + popd |
| 81 | +} |
| 82 | + |
| 83 | +function install_sasl() { |
| 84 | + |
| 85 | + wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz -O memcached-1.4.15.tar.gz |
| 86 | + tar xfz memcached-1.4.15.tar.gz |
| 87 | + |
| 88 | + pushd memcached-1.4.15 |
| 89 | + ./configure --enable-sasl --prefix="${HOME}/memcached" |
| 90 | + make |
| 91 | + make install |
| 92 | + popd |
| 93 | + |
| 94 | + sudo apt-get install sasl2-bin |
| 95 | + export SASL_CONF_PATH="${HOME}/sasl2" |
| 96 | + |
| 97 | + # Create config path |
| 98 | + mkdir "${SASL_CONF_PATH}" |
| 99 | + |
| 100 | + # Create configuration |
| 101 | + cat<<EOF > "${SASL_CONF_PATH}/memcached.conf" |
| 102 | +mech_list: PLAIN |
| 103 | +plainlog_level: 5 |
| 104 | +sasldb_path: ${SASL_CONF_PATH}/sasldb2 |
| 105 | +EOF |
| 106 | + |
| 107 | + # Create password |
| 108 | + echo "test" | /usr/sbin/saslpasswd2 -c memcached -a memcached -f "${SASL_CONF_PATH}/sasldb2" |
| 109 | + |
| 110 | + # Run memcached on port 11212 with SASL support |
| 111 | + "${HOME}/memcached/bin/memcached" -S -d -p 11212 |
| 112 | +} |
| 113 | + |
| 114 | +function build_php_memcached() { |
| 115 | + pear package |
| 116 | + mkdir "$PHP_MEMCACHED_BUILD_DIR" |
| 117 | + tar xfz "memcached-${PHP_MEMCACHED_VERSION}.tgz" -C "$PHP_MEMCACHED_BUILD_DIR" |
| 118 | + pushd "${PHP_MEMCACHED_BUILD_DIR}/memcached-${PHP_MEMCACHED_VERSION}" |
| 119 | + phpize |
| 120 | + |
| 121 | + local protocol_flag="" |
| 122 | + if test "x$ENABLE_PROTOCOL" = "xyes"; then |
| 123 | + protocol_flag="--enable-memcached-protocol" |
| 124 | + fi |
| 125 | + |
| 126 | + local sasl_flag="--disable-memcached-sasl" |
| 127 | + if test "x$ENABLE_SASL" = "xyes"; then |
| 128 | + protocol_flag="--enable-memcached-sasl" |
| 129 | + fi |
| 130 | + |
| 131 | + ./configure --with-libmemcached-dir="$LIBMEMCACHED_PREFIX" $protocol_flag $sasl_flag --enable-memcached-json --enable-memcached-igbinary --enable-memcached-msgpack |
| 132 | + make |
| 133 | + make install |
| 134 | + popd |
| 135 | +} |
| 136 | + |
| 137 | +function create_memcached_test_configuration() { |
| 138 | +cat<<EOF > "${PHP_MEMCACHED_BUILD_DIR}/memcached-${PHP_MEMCACHED_VERSION}/tests/config.inc.local" |
| 139 | +<?php |
| 140 | + define ("MEMC_SERVER_HOST", "127.0.0.1"); |
| 141 | + define ("MEMC_SERVER_PORT", 11211); |
| 142 | +
|
| 143 | + define ("MEMC_SASL_SERVER_HOST", "127.0.0.1"); |
| 144 | + define ("MEMC_SASL_SERVER_PORT", 11212); |
| 145 | + |
| 146 | + define ('MEMC_SASL_USER', 'memcached'); |
| 147 | + define ('MEMC_SASL_PASS', 'test'); |
| 148 | +EOF |
| 149 | +} |
| 150 | + |
| 151 | +function run_memcached_tests() { |
| 152 | + export NO_INTERACTION=1 |
| 153 | + export REPORT_EXIT_STATUS=1 |
| 154 | + export TEST_PHP_EXECUTABLE=`which php` |
| 155 | + |
| 156 | + pushd "${PHP_MEMCACHED_BUILD_DIR}/memcached-${PHP_MEMCACHED_VERSION}" |
| 157 | + # We have one xfail test, we run it separately |
| 158 | + php run-tests.php -d extension=msgpack.so -d extension=igbinary.so -d extension=memcached.so -n ./tests/expire.phpt |
| 159 | + rm ./tests/expire.phpt |
| 160 | + |
| 161 | + # Run normal tests |
| 162 | + php run-tests.php -d extension=msgpack.so -d extension=igbinary.so -d extension=memcached.so -n ./tests/*.phpt |
| 163 | + retval=$? |
| 164 | + for i in `ls tests/*.out 2>/dev/null`; do |
| 165 | + echo "-- START ${i}"; |
| 166 | + cat $i; |
| 167 | + echo ""; |
| 168 | + echo "-- END"; |
| 169 | + done |
| 170 | + popd |
| 171 | + |
| 172 | + return $retval; |
| 173 | +} |
| 174 | + |
| 175 | +# Command line arguments |
| 176 | +ACTION=$1 |
| 177 | +LIBMEMCACHED_VERSION=$2 |
| 178 | + |
| 179 | +if test "x$ACTION" = "x"; then |
| 180 | + echo "Usage: $0 <action> <libmemcached version>" |
| 181 | + exit 1 |
| 182 | +fi |
| 183 | + |
| 184 | +if test "x$LIBMEMCACHED_VERSION" = "x"; then |
| 185 | + echo "Usage: $0 <action> <libmemcached version>" |
| 186 | + exit 1 |
| 187 | +fi |
| 188 | + |
| 189 | +# the extension version |
| 190 | +PHP_MEMCACHED_VERSION=$(php -r '$sxe = simplexml_load_file ("package.xml"); echo (string) $sxe->version->release;') |
| 191 | + |
| 192 | +# Libmemcached install dir |
| 193 | +LIBMEMCACHED_PREFIX="${HOME}/libmemcached-${LIBMEMCACHED_VERSION}" |
| 194 | + |
| 195 | +# Where to do the build |
| 196 | +PHP_MEMCACHED_BUILD_DIR="/tmp/php-memcached-build" |
| 197 | + |
| 198 | +# Check whether to enable building with protoocol and sasl support |
| 199 | +check_protocol_support |
| 200 | +check_sasl_support |
| 201 | + |
| 202 | +echo "Enable protocol: $ENABLE_PROTOOCOL" |
| 203 | +echo "Enable sasl: $ENABLE_SASL" |
| 204 | + |
| 205 | +set -e |
| 206 | + |
| 207 | +case $ACTION in |
| 208 | + before_script) |
| 209 | + # validate the package.xml |
| 210 | + validate_package_xml || exit 1 |
| 211 | + |
| 212 | + # Install libmemcached version |
| 213 | + install_libmemcached |
| 214 | + |
| 215 | + # Install igbinary extension |
| 216 | + install_igbinary |
| 217 | + |
| 218 | + # install msgpack |
| 219 | + install_msgpack |
| 220 | + |
| 221 | + # install SASL |
| 222 | + if test "x$ENABLE_SASL" = "xyes"; then |
| 223 | + install_sasl |
| 224 | + fi |
| 225 | + ;; |
| 226 | + |
| 227 | + script) |
| 228 | + # Build the extension |
| 229 | + build_php_memcached |
| 230 | + |
| 231 | + # Create configuration |
| 232 | + if test "x$ENABLE_SASL" = "xyes"; then |
| 233 | + create_memcached_test_configuration |
| 234 | + fi |
| 235 | + |
| 236 | + # Run tests |
| 237 | + set +e |
| 238 | + run_memcached_tests || exit 1 |
| 239 | + ;; |
| 240 | + |
| 241 | + *) |
| 242 | + echo "Unknown action. Valid actions are: before_script and script" |
| 243 | + exit 1 |
| 244 | + ;; |
| 245 | +esac |
| 246 | + |
| 247 | + |
| 248 | + |
| 249 | + |
| 250 | + |
0 commit comments