super-test.sh 13.3 KB
Newer Older
1 2 3 4 5 6 7 8 9
#! /bin/bash

set -euo pipefail

doit() {
  echo "@@@@ $@"
  "$@"
}

Kenton Varda's avatar
Kenton Varda committed
10 11 12 13 14 15 16 17 18
QUICK=

while [ $# -gt 0 ]; do
  case "$1" in
    test )
      ;;  # nothing
    quick )
      QUICK=quick
      ;;
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    caffeinate )
      # Re-run preventing sleep.
      shift
      exec caffeinate $0 $@
      ;;
    tmpdir )
      # Clone to a temp directory.
      if [ "$#" -lt 2 ]; then
        echo "usage: $0 tmpdir NAME [COMMAND]" >&2
        exit 1
      fi
      DIR=/tmp/$2
      shift 2
      if [ -e $DIR ]; then
        if [ "${DIR/*..*}" = "" ]; then
          echo "NO DO NOT PUT .. IN THERE IT'S GOING TO GO IN /tmp AND I'M GONNA DELETE IT" >&2
          exit 1
        fi
        if [ ! -e "$DIR/super-test.sh" ]; then
          echo "$DIR exists and it doesn't look like one of mine." >&2
          exit 1
        fi
        # make distcheck leaves non-writable files when it fails, so we need to chmod to be safe.
        chmod -R +w $DIR
        rm -rf $DIR
      fi
      git clone . $DIR
      if [ -e c++/gtest ]; then
        cp -r c++/gtest $DIR/c++/gtest
      fi
      cd $DIR
      exec ./super-test.sh $@
      ;;
Kenton Varda's avatar
Kenton Varda committed
52 53 54 55 56 57 58 59 60 61
    remote )
      if [ "$#" -lt 2 ]; then
        echo "usage: $0 remote HOST [COMMAND]" >&2
        exit 1
      fi
      HOST=$2
      shift 2
      echo "========================================================================="
      echo "Pushing code to $HOST..."
      echo "========================================================================="
62
      BRANCH=$(git rev-parse --abbrev-ref HEAD)
Kenton Varda's avatar
Kenton Varda committed
63
      ssh $HOST 'rm -rf tmp-test-capnp && mkdir tmp-test-capnp && git init tmp-test-capnp'
64
      git push ssh://$HOST/~/tmp-test-capnp "$BRANCH:test"
65 66 67
      ssh $HOST "cd tmp-test-capnp && git checkout test"
      scp -qr c++/gtest $HOST:~/tmp-test-capnp/c++/gtest
      exec ssh $HOST "cd tmp-test-capnp && ./super-test.sh $@ && cd .. && rm -rf tmp-test-capnp"
Kenton Varda's avatar
Kenton Varda committed
68 69 70 71 72 73 74
      ;;
    clang )
      export CXX=clang++
      ;;
    gcc-4.8 )
      export CXX=g++-4.8
      ;;
Kenton Varda's avatar
Kenton Varda committed
75 76 77
    gcc-4.7 )
      export CXX=g++-4.7
      ;;
Kenton Varda's avatar
Kenton Varda committed
78 79
    kenton )
      cat << "__EOF__"
80 81 82 83 84 85 86 87 88 89 90
=========================================================================
*************************************************************************
  _     _                        ____  ____ ____
 | |   (_)_ __  _   ___  __     / ___|/ ___/ ___|
 | |   | | '_ \| | | \ \/ /____| |  _| |  | |
 | |___| | | | | |_| |>  <_____| |_| | |__| |___
 |_____|_|_| |_|\__,_/_/\_\     \____|\____\____|

*************************************************************************
=========================================================================
__EOF__
Kenton Varda's avatar
Kenton Varda committed
91 92 93
      $0 test $QUICK
      $0 clean
      cat << "__EOF__"
94 95 96 97 98 99 100 101 102 103 104
=========================================================================
*************************************************************************
   ___  ______  __      ____ _
  / _ \/ ___\ \/ /     / ___| | __ _ _ __   __ _
 | | | \___ \\  /_____| |   | |/ _` | '_ \ / _` |
 | |_| |___) /  \_____| |___| | (_| | | | | (_| |
  \___/|____/_/\_\     \____|_|\__,_|_| |_|\__, |
                                           |___/
*************************************************************************
=========================================================================
__EOF__
105
      $0 remote beat caffeinate $QUICK
Kenton Varda's avatar
Kenton Varda committed
106
      cat << "__EOF__"
107
=========================================================================
108 109 110 111 112 113 114 115 116 117
*************************************************************************
   ____                     _
  / ___|   _  __ ___      _(_)_ __
 | |  | | | |/ _` \ \ /\ / / | '_ \
 | |__| |_| | (_| |\ V  V /| | | | |
  \____\__, |\__, | \_/\_/ |_|_| |_|
       |___/ |___/
*************************************************************************
=========================================================================
__EOF__
Kenton Varda's avatar
Kenton Varda committed
118 119
      $0 remote Kenton@flashman $QUICK
      cat << "__EOF__"
120
=========================================================================
121 122 123 124 125 126 127 128 129 130
*************************************************************************
   ____  ____ ____   _  _    ___
  / ___|/ ___/ ___| | || |  ( _ )
 | |  _| |  | |     | || |_ / _ \
 | |_| | |__| |___  |__   _| (_) |
  \____|\____\____|    |_|(_)___/

*************************************************************************
=========================================================================
__EOF__
Kenton Varda's avatar
Kenton Varda committed
131 132 133
      $0 gcc-4.8 $QUICK
      $0 clean
      cat << "__EOF__"
134
=========================================================================
135 136 137 138 139 140 141 142 143 144
*************************************************************************
  _     _                        ____ _
 | |   (_)_ __  _   ___  __     / ___| | __ _ _ __   __ _
 | |   | | '_ \| | | \ \/ /____| |   | |/ _` | '_ \ / _` |
 | |___| | | | | |_| |>  <_____| |___| | (_| | | | | (_| |
 |_____|_|_| |_|\__,_/_/\_\     \____|_|\__,_|_| |_|\__, |
                                                    |___/
*************************************************************************
=========================================================================
__EOF__
Kenton Varda's avatar
Kenton Varda committed
145 146 147
      $0 clang $QUICK
      $0 clean
      cat << "__EOF__"
148
=========================================================================
149 150 151 152 153 154 155 156 157 158
*************************************************************************
  ____  _   _ ___ ____    ___ _____
 / ___|| | | |_ _|  _ \  |_ _|_   _|
 \___ \| |_| || || |_) |  | |  | |
  ___) |  _  || ||  __/   | |  | |
 |____/|_| |_|___|_|     |___| |_|

*************************************************************************
=========================================================================
__EOF__
Kenton Varda's avatar
Kenton Varda committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
      exit 0
      ;;
    clean )
      rm -rf tmp-staging
      cd c++
      if [ -e Makefile ]; then
        doit make maintainer-clean
      fi
      rm -f capnproto-*.tar.gz samples/addressbook samples/addressbook.capnp.c++ \
            samples/addressbook.capnp.h
      exit 0
      ;;
    help )
      echo "usage: $0 [COMMAND]"
      echo "commands:"
      echo "  test          Runs tests (the default)."
      echo "  clang         Runs tests using Clang compiler."
      echo "  gcc-4.8       Runs tests using gcc-4.8."
      echo "  remote HOST   Runs tests on HOST via SSH."
      echo "  kenton        Kenton's meta-test (uses hosts on Kenton's network)."
      echo "  clean         Delete temporary files that may be left after failure."
      echo "  help          Prints this help text."
      exit 0
      ;;
    * )
      echo "unknown command: $1" >&2
      echo "try: $0 help" >&2
      exit 1
      ;;
  esac
  shift
done
191

192
# Build optimized builds because they catch more problems, but also enable debugging macros.
193
# Enable lots of warnings and make sure the build breaks if they fire.  Disable strict-aliasing
194 195 196 197
# because GCC warns about code that I know is OK.  Disable sign-compare because I've fixed more
# sign-compare warnings than probably all other warnings combined and I've never seen it flag a
# real problem.
export CXXFLAGS="-O2 -DDEBUG -Wall -Werror -Wno-strict-aliasing -Wno-sign-compare"
198

199 200
STAGING=$PWD/tmp-staging

201 202 203 204 205 206 207
rm -rf "$STAGING"
mkdir "$STAGING"
mkdir "$STAGING/bin"
mkdir "$STAGING/lib"
export PATH=$STAGING/bin:$PATH
export LD_LIBRARY_PATH=$STAGING/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
export PKG_CONFIG_PATH=$STAGING/lib/pkgconfig
Kenton Varda's avatar
Kenton Varda committed
208 209 210 211

if [ "$QUICK" = quick ]; then
  echo "************************** QUICK TEST ***********************************"
fi
212 213 214 215 216

echo "========================================================================="
echo "Building c++"
echo "========================================================================="

217 218 219
# Apple now aliases gcc to clang, so probe to find out what compiler we're really using.
if (${CXX:-g++} -dM -E -x c++ /dev/null 2>&1 | grep -q '__clang__'); then
  IS_CLANG=yes
220
else
221
  IS_CLANG=no
222 223
fi

224 225 226 227
if [ $IS_CLANG = yes ]; then
  # There's an unused private field in gtest.
  export CXXFLAGS="$CXXFLAGS -Wno-unused-private-field"
else
Kenton Varda's avatar
Kenton Varda committed
228 229 230 231 232 233
  # GCC 4.8 emits a weird uninitialized warning in kj/parse/char-test, deep in one of the parser
  # combinators.  It could be a real bug but there is just not enough information to figure out
  # where the problem is coming from, because GCC does not provide any description of the inlining
  # that has occurred.  Since I have not observed any actual problem (tests pass, etc.), I'm
  # muting it for now.
  CXXFLAGS="$CXXFLAGS -Wno-maybe-uninitialized"
234
fi
235

236 237 238 239 240 241
cd c++
doit ./setup-autotools.sh | tr = -
doit autoreconf -i
doit ./configure --prefix="$STAGING"
doit make -j6 check

242 243 244 245 246
if [ $IS_CLANG = no ]; then
  # Verify that generated code compiles with pedantic warnings.  Make sure to treat capnp headers
  # as system headers so warnings in them are ignored.
  doit ${CXX:-g++} -isystem src -std=c++11 -fno-permissive -pedantic -Wall -Wextra -Werror \
      -c src/capnp/test.capnp.c++ -o /dev/null
Kenton Varda's avatar
Kenton Varda committed
247 248
fi

249 250 251 252 253 254
echo "========================================================================="
echo "Testing c++ install"
echo "========================================================================="

doit make install

Kenton Varda's avatar
Kenton Varda committed
255 256
test "x$(which capnp)" = "x$STAGING/bin/capnp"
test "x$(which capnpc-c++)" = "x$STAGING/bin/capnpc-c++"
257

258
cd samples
259

260
doit capnp compile -oc++ addressbook.capnp -I"$STAGING"/include --no-standard-import
261 262
doit ${CXX:-g++} -std=c++11 addressbook.c++ addressbook.capnp.c++ -o addressbook \
    $CXXFLAGS $(pkg-config --cflags --libs capnp)
263 264 265 266
echo "@@@@ ./addressbook (in various configurations)"
./addressbook write | ./addressbook read
./addressbook dwrite | ./addressbook dread
rm addressbook addressbook.capnp.c++ addressbook.capnp.h
267 268 269 270 271 272 273 274 275 276 277 278 279 280

doit capnp compile -oc++ calculator.capnp -I"$STAGING"/include --no-standard-import
doit ${CXX:-g++} -std=c++11 calculator-client.c++ calculator.capnp.c++ -o calculator-client \
    $CXXFLAGS $(pkg-config --cflags --libs capnp-rpc)
doit ${CXX:-g++} -std=c++11 calculator-server.c++ calculator.capnp.c++ -o calculator-server \
    $CXXFLAGS $(pkg-config --cflags --libs capnp-rpc)
rm -f /tmp/capnp-calculator-example-$$
./calculator-server unix:/tmp/capnp-calculator-example-$$ &
sleep 0.1
./calculator-client unix:/tmp/capnp-calculator-example-$$
kill %+
wait %+ || true
rm calculator-client calculator-server calculator.capnp.c++ calculator.capnp.h /tmp/capnp-calculator-example-$$

281 282
cd ..

283 284 285 286 287 288
if [ "$QUICK" = quick ]; then
  doit make maintainer-clean
  rm -rf "$STAGING"
  exit 0
fi

289 290 291 292 293
echo "========================================================================="
echo "Testing --with-external-capnp"
echo "========================================================================="

doit make distclean
294 295
doit ./configure --prefix="$STAGING" --disable-shared \
    --with-external-capnp CAPNP=$STAGING/bin/capnp
296
doit make -j6 check
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
doit make distclean

# Test 32-bit build now while we have $STAGING available for cross-compiling.
if [ "x`uname -m`" = "xx86_64" ]; then
  echo "========================================================================="
  echo "Testing 32-bit build"
  echo "========================================================================="

  if [[ "`uname`" =~ CYGWIN ]]; then
    # It's just not possible to run cygwin32 binaries from within cygwin64.

    # Build as if we are cross-compiling, using the capnp we installed to $STAGING.
    doit ./configure --prefix="$STAGING" --disable-shared --host=i686-pc-cygwin \
        --with-external-capnp CAPNP=$STAGING/bin/capnp
    doit make -j6 capnp-test.exe
312

313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
    # Expect a cygwin32 sshd to be listening at localhost port 2222, and use it
    # to run the tests.
    doit scp -P 2222 capnp-test.exe localhost:~/tmp-capnp-test.exe
    doit ssh -p 2222 localhost './tmp-capnp-test.exe && rm tmp-capnp-test.exe'

    doit make distclean

  elif [ "x${CXX:-g++}" != "xg++-4.8" ]; then
    doit ./configure CXX="${CXX:-g++} -m32" --disable-shared
    doit make -j6 check
    doit make distclean
  fi
fi

echo "========================================================================="
echo "Testing c++ uninstall"
echo "========================================================================="

doit ./configure --prefix="$STAGING"
332 333 334 335 336 337 338 339 340 341 342 343 344 345
doit make uninstall

echo "========================================================================="
echo "Testing c++ dist"
echo "========================================================================="

doit make distcheck
doit make distclean
rm capnproto-*.tar.gz

echo "========================================================================="
echo "Testing with -fno-rtti and -fno-exceptions"
echo "========================================================================="

346
doit ./configure --disable-shared CXXFLAGS="$CXXFLAGS -fno-rtti"
347 348
doit make -j6 check
doit make distclean
349
doit ./configure --disable-shared CXXFLAGS="$CXXFLAGS -fno-exceptions"
350 351
doit make -j6 check
doit make distclean
352
doit ./configure --disable-shared CXXFLAGS="$CXXFLAGS -fno-rtti -fno-exceptions"
353 354
doit make -j6 check

355 356 357 358
# Valgrind is currently "experimental and mostly broken" on OSX and fails to run the full test
# suite, but I have it installed because it did manage to help me track down a bug or two.  Anyway,
# skip it on OSX for now.
if [ "x`uname`" != xDarwin ] && which valgrind > /dev/null; then
Kenton Varda's avatar
Kenton Varda committed
359 360
  doit make distclean

361 362 363 364 365 366 367
  echo "========================================================================="
  echo "Testing with valgrind"
  echo "========================================================================="

  doit ./configure --disable-shared CXXFLAGS="-g"
  doit make -j6
  doit make -j6 capnp-test
Kenton Varda's avatar
Kenton Varda committed
368
  doit valgrind --leak-check=full --track-fds=yes --error-exitcode=1 ./capnp-test
369 370
fi

371 372 373
doit make maintainer-clean

rm -rf "$STAGING"