Autoscale testcase-provided timeout to compensate for slooow machines
Each test case has a timeout to guard against runaway tests. However
on really slow machines the timeout us not big enough. To compensate for this,
asses the "speed" of machine running tests and scale default timeout
if machine is slower than some (arbitrary) norm.
The speed assesment is done by measuring time to run (arbitrary) benchmark
code. This has the advantage to reflect actual machine load, not only
hardvare spec.
However, we may need to play with these magic numbers to make it working.
Generally a workaround.
# ### START OF common.sh.in ##########################################
#
# Common set of function to build a project.
#
# Determine operating system, bit simple but works
if [ "$OS" == "Windows_NT" ]; then
WIN32=1
UNIX=0
else
WIN32=0
UNIX=1
fi
# =====================================================
# Utility functions
# =====================================================
# Simple logging functions
function info {
echo "[INF] $1"
if [ ! -z "$2" ]; then
echo " $2"
fi
}
function error {
echo "[ERR] $1"
if [ ! -z "$2" ]; then
echo " $2"
fi
exit 1
}
# Run make in current directory. Caller should cd to target
# directory before calling this method.
function mk {
if [ "$WIN32" == "1" ]; then
cmd /C bmake.bat $1 $2
else
if [ -f Makefile.init ]; then
make -f Makefile.init || error "Failed to make package"
else
error "No Makefile.init found"
fi
make $1 $2 || error "Make failed"
fi
}
# Run tests for package specified in first argument.
function sunit {
pushd stx/goodies/builder/reports
info "Running tests for $1"
if [ "$WIN32" == "1" ]; then
cmd /C report-runner.bat -D ../../../.. -r Builder::TestReport -p "$1" || error "Failed to run reports"
else
(echo "" | ./report-runner.sh -D ../../../.. -r Builder::TestReport -p "$1") || error "Failed to run reports"
fi
popd
}
# Main function. Performs complete build or given task
function main {
pushd "$BUILD"
if [ -z "$1" ]; then
info "Checking out..."
checkout
info "Compiling..."
compile
info "Running tests..."
runtests
else
case "$1" in
checkout)
info "Checking out..."
checkout;;
compile)
info "Compiling..."
compile;;
tests)
info "Running tests..."
runtests;;
test)
info "Running tests..."
runtests;;
*)
error "Invalid command ($1)"
esac
fi
popd
exit 0
}
# Setup...
if [ "$WIN32" == "1" ]; then
# WINDOWS
# MUST export this, otherwise libjpeg fails to build!!!"
if [ -z "$BCB"]; then
export BCB="C:\Borland\BCC55"
fi
# To make cvs/ssh happy
if [ -z "$CVS_RSH" ]; then
export CVS_RSH=plink
fi
# Set home
export HOME=$USERPROFILE
else
# LINUX
# to get Mercurial on build slave
export PATH=$PATH:/home/vrany/bin
fi
if [ -z "$CVSROOT" ]; then
error "CVSROOT not set!"
fi
# Sorry, it's lot easier for all to have all the messages in EN :-)
export LANG=en_GB.UTF-8
# When run interactively, Jenkins env variables
# may not be set...
if [ -z "$WORKSPACE" ]; then
WORKSPACE="$PWD"
INTERACTIVE=1
else
INTERACTIVE=0
fi
if [ "$INTERACTIVE" == "0" ]; then
if [ "$WIN32" == "1" ]; then
WORKSPACE="$PWD"
fi
fi
if [ -z "$BUILD_NUMBER" ]; then
BUILD_NUMBER=$(date +%Y_%m_%d_interactive)
fi
BUILD="$PWD"
echo "INFO: BUILD=\"$BUILD\""
if [ -d "$BUILD" ]; then
if [ "$BUILD" != "$PWD" ]; then
info "Build directory already exists!"
fi
else
mkdir -p "$BUILD"
fi
# ===================================================================
# Actual build functions.
# ===================================================================
#
# User scripts should override following functions to define a build
function checkout {
error "You have to override function 'checkout'"
}
function compile {
error "You have to override function 'compile'"
}
function runtests {
info "No tests specified" "To do so, override function runtests"
}
# ### END OF common.sh.in ############################################