Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 210 lines (180 sloc) 5.37 KB
#!/bin/bash
#
# Clone source repo to be tested and run tests
#
SCRIPT_PID=$$
if [ $# -ne 5 ]; then
echo 'arguments: <main_repo_url> <requester_repo_url> <sha_pull_req> <ref_repo_url> <temp_path>'
echo
exit
fi
MAIN_URL=$1
TARGET_URL=$2
SHA=$3
REF_URL=$4
TMP_DIR=$5
#
# Make sure there are no stray processes running
#
if [ -z "$PDFJSBOT_STAGING" ]; then
echo "========== Killing any stray processes"
ps ax -o "pid command" | grep -v 'grep' | grep -E -i 'test.py' | sed -E 's/([0-9]+) .+/\1/g' | xargs kill -TERM 1>/dev/null 2>/dev/null
ps ax -o "pid comm" | grep -E -i 'firefox' | sed -E 's/([0-9]+) .+/\1/g' | xargs kill -9 1>/dev/null 2>/dev/null
fi
#
# killtree(): Kills all descendant child processes
#
killtree() {
local _pid=$1
local _regex="[ ]*([0-9]+)[ ]+${_pid}"
for _child in $(/bin/ps ax -o "pid= ppid=" | grep -E "${_regex}" | sed -E "s/${_regex}/\1/g"); do
killtree ${_child}
done
kill -KILL ${_pid} 1>/dev/null 2>/dev/null
}
#
# Run killtree() upon signal
# NB: trap only works during "wait" or after a command is done
trap "killtree $SCRIPT_PID" SIGTERM SIGINT
#
# Set up vars
#
# Get absolute path for current dir
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
# Hack to get absolute path for tmp path
mkdir -p $TMP_DIR; cd $TMP_DIR
TMP_DIR="$( cd "$( dirname "$0" )" && pwd )"
TARGET_DIR=$TMP_DIR/tests/$SHA
if [ -d $TARGET_DIR ]; then
rm -rf $TARGET_DIR
fi
#
# Garbage collector
#
echo
echo "========== Running garbage collector in $TMP_DIR"
cd $SCRIPT_DIR
./run-gc $TMP_DIR
#
# Fetch git repo to be tested (target), checkout desired sha
#
echo
echo "========== Cloning pull request repo"
mkdir -p $TARGET_DIR
cd $TARGET_DIR
git clone $TARGET_URL .
if [ $? != 0 ]; then
echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "ERROR: Could not clone $TARGET_URL"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit
fi
git checkout --quiet $SHA
if [ $? != 0 ]; then
echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "ERROR: Could not checkout sha $SHA"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit
fi
#
# Merge upstream into pull request
#
echo
echo "========== Merging upstream into pull request clone"
cd $TARGET_DIR
git pull --quiet $MAIN_URL master
if [ $? != 0 ]; then
echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "ERROR: Could not merge upstream into pull request. Please resolve conflicts."
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit
fi
#
# Run linter
#
echo
echo "========== Running 'make lint'"
cd $TARGET_DIR
make lint &
wait $! # so we can trap SIGTERM, see above
#
# Pull reference snapshots
#
echo
echo "========== Cloning reference images repo into test/ref/"
mkdir -p $TARGET_DIR/test/ref
cd $TARGET_DIR/test/ref
git init; git pull -f --quiet $REF_URL
if [ $? != 0 ]; then
echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "ERROR: Something went wrong."
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit
fi
#
# Check if commit/SHA used to generate snapshots is present in history
# and issue WARNING if not
#
echo
echo "========== Checking for consistency with reference repo"
cd $TARGET_DIR/test/ref
ORIGINAL_SHA=`grep 'sha' REF-INFO | sed -e 's/sha \([0-9a-z]*\)/\1/g'` # get SHA from REF-INFO
COMMIT_EXISTS=`cd $TARGET_DIR; git log --format="%H" | grep $ORIGINAL_SHA` # ask git if SHA exists in index
if [ -z "$COMMIT_EXISTS" ]; then # is COMMIT_EXISTS zero-length? (i.e. no match)
echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "WARNING: Could not find commit that generated reference images in history."
echo " Someone must have forgotten to merge a reference pull request into"
echo " upstream."
echo " If the tests all pass, that should be OK though."
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "Commit used to create snapshots (REF-INFO file from reference repo):"
cat $TARGET_DIR/test/ref/REF-INFO
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
fi
#
# Copy existing PDFs *from* local cache
#
cd $TARGET_DIR
cp -n $TMP_DIR/pdf-cache/* test/pdfs
#
# Deploy missing test/ files, run tests
#
echo
echo "========== Running 'make bot_test'"
cd $TARGET_DIR
# Deploy Makefile for bot_test
cp -f $SCRIPT_DIR/test-files/local.mk . 2>/dev/null
# Deploy missing test/ files
cp -f $SCRIPT_DIR/test-files/browser_manifest.json ./test/resources/browser_manifests 2>/dev/null
# prepare Xvfb
killall -9 Xvfb
Xvfb :1 -screen 0 1280x1024x24 1>/dev/null 2>/dev/null &
XVFB_PID=$!
export DISPLAY=:1
# bot_test
make bot_test &
wait $! # so we can trap SIGTERM, see above
# kill Xvfb
kill -9 $XVFB_PID 1>/dev/null 2>/dev/null
#
# Copy new PDFs *to* local cache
#
cd $TARGET_DIR
mkdir -p $TMP_DIR/pdf-cache
cp -n test/pdfs/*.pdf $TMP_DIR/pdf-cache
#
# Erase everything but eq.log and reftest-analyzer
#
echo
echo "========== Cleaning up"
cd $TARGET_DIR
mv -f test/eq.log . 2>/dev/null
mv -f test/resources/reftest-analyzer.xhtml . 2>/dev/null
find . ! -iname 'eq.log' -and ! -iname 'reftest-analyzer.xhtml' -delete
echo
echo "All done."