2016-08-01 05:25:37 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Bash script to execute the Solidity tests.
|
|
|
|
#
|
|
|
|
# The documentation for solidity is hosted at:
|
|
|
|
#
|
|
|
|
# https://solidity.readthedocs.org
|
|
|
|
#
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# This file is part of solidity.
|
|
|
|
#
|
|
|
|
# solidity is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# solidity is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with solidity. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
#
|
|
|
|
# (c) 2016 solidity contributors.
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
2016-08-01 13:33:01 +00:00
|
|
|
set -e
|
|
|
|
|
2016-11-02 11:32:55 +00:00
|
|
|
REPO_ROOT="$(dirname "$0")"/..
|
|
|
|
|
2018-07-27 08:32:04 +00:00
|
|
|
WORKDIR=`mktemp -d`
|
2018-04-26 11:38:20 +00:00
|
|
|
IPC_ENABLED=true
|
2018-07-27 08:32:04 +00:00
|
|
|
ALETH_PID=
|
|
|
|
CMDLINE_PID=
|
|
|
|
|
2018-04-26 11:38:20 +00:00
|
|
|
if [[ "$OSTYPE" == "darwin"* ]]
|
|
|
|
then
|
|
|
|
SMT_FLAGS="--no-smt"
|
|
|
|
if [ "$CIRCLECI" ]
|
|
|
|
then
|
|
|
|
IPC_ENABLED=false
|
|
|
|
IPC_FLAGS="--no-ipc"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-07-27 08:32:04 +00:00
|
|
|
safe_kill() {
|
|
|
|
local PID=${1}
|
|
|
|
local NAME=${2:-${1}}
|
|
|
|
local n=1
|
|
|
|
|
|
|
|
# only proceed if $PID does exist
|
|
|
|
kill -0 $PID 2>/dev/null || return
|
|
|
|
|
|
|
|
echo "Sending SIGTERM to ${NAME} (${PID}) ..."
|
|
|
|
kill $PID
|
|
|
|
|
|
|
|
# wait until process terminated gracefully
|
|
|
|
while kill -0 $PID 2>/dev/null && [[ $n -le 4 ]]; do
|
|
|
|
echo "Waiting ($n) ..."
|
|
|
|
sleep 1
|
|
|
|
n=$[n + 1]
|
|
|
|
done
|
|
|
|
|
|
|
|
# process still alive? then hard-kill
|
|
|
|
if kill -0 $PID 2>/dev/null; then
|
|
|
|
echo "Sending SIGKILL to ${NAME} (${PID}) ..."
|
|
|
|
kill -9 $PID
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
# ensure failing commands don't cause termination during cleanup (especially within safe_kill)
|
|
|
|
set +e
|
|
|
|
|
|
|
|
if [[ "$IPC_ENABLED" = true ]] && [[ -n "${ALETH_PID}" ]]
|
|
|
|
then
|
|
|
|
safe_kill $ALETH_PID $ALETH_PATH
|
|
|
|
fi
|
|
|
|
if [[ -n "$CMDLINE_PID" ]]
|
|
|
|
then
|
|
|
|
safe_kill $CMDLINE_PID "Commandline tests"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Cleaning up working directory ${WORKDIR} ..."
|
|
|
|
rm -rf "$WORKDIR" || true
|
|
|
|
}
|
|
|
|
trap cleanup INT TERM
|
|
|
|
|
2018-02-13 10:54:22 +00:00
|
|
|
if [ "$1" = --junit_report ]
|
|
|
|
then
|
|
|
|
if [ -z "$2" ]
|
|
|
|
then
|
|
|
|
echo "Usage: $0 [--junit_report <report_directory>]"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-02-22 16:21:26 +00:00
|
|
|
log_directory="$2"
|
2018-02-13 10:54:22 +00:00
|
|
|
else
|
2018-02-22 16:21:26 +00:00
|
|
|
log_directory=""
|
2018-02-13 10:54:22 +00:00
|
|
|
fi
|
|
|
|
|
2018-09-28 21:31:23 +00:00
|
|
|
if [ "$CIRCLECI" ]
|
|
|
|
then
|
|
|
|
function printTask() { echo "$(tput bold)$(tput setaf 2)$1$(tput setaf 7)"; }
|
|
|
|
function printError() { echo "$(tput setaf 1)$1$(tput setaf 7)"; }
|
|
|
|
else
|
|
|
|
function printTask() { echo "$(tput bold)$(tput setaf 2)$1$(tput sgr0)"; }
|
|
|
|
function printError() { echo "$(tput setaf 1)$1$(tput sgr0)"; }
|
|
|
|
fi
|
2018-04-17 06:53:21 +00:00
|
|
|
|
|
|
|
printTask "Running commandline tests..."
|
2018-02-26 19:41:18 +00:00
|
|
|
# Only run in parallel if this is run on CI infrastructure
|
2018-07-27 08:32:04 +00:00
|
|
|
if [[ -n "$CI" ]]
|
2018-02-26 19:41:18 +00:00
|
|
|
then
|
2018-07-27 08:32:04 +00:00
|
|
|
"$REPO_ROOT/test/cmdlineTests.sh" &
|
|
|
|
CMDLINE_PID=$!
|
|
|
|
else
|
|
|
|
if ! $REPO_ROOT/test/cmdlineTests.sh
|
2018-04-17 06:53:21 +00:00
|
|
|
then
|
|
|
|
printError "Commandline tests FAILED"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-02-26 19:41:18 +00:00
|
|
|
fi
|
2017-07-05 10:28:15 +00:00
|
|
|
|
2018-06-20 15:26:27 +00:00
|
|
|
function download_aleth()
|
2018-02-26 19:41:18 +00:00
|
|
|
{
|
|
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
2018-06-20 15:26:27 +00:00
|
|
|
ALETH_PATH="$REPO_ROOT/aleth"
|
2018-02-26 19:41:18 +00:00
|
|
|
elif [ -z $CI ]; then
|
2018-06-20 15:26:27 +00:00
|
|
|
ALETH_PATH="aleth"
|
2018-02-26 19:41:18 +00:00
|
|
|
else
|
|
|
|
mkdir -p /tmp/test
|
2018-09-12 12:35:41 +00:00
|
|
|
# Any time the hash is updated here, the "Running compiler tests" section should also be updated.
|
2019-02-14 11:45:06 +00:00
|
|
|
ALETH_HASH="a6a9884bf3e5d8b3e01b55d4f6e9fe6dce5b5db7"
|
|
|
|
ALETH_VERSION=1.5.2
|
2018-09-12 12:35:41 +00:00
|
|
|
wget -q -O /tmp/test/aleth.tar.gz https://github.com/ethereum/aleth/releases/download/v${ALETH_VERSION}/aleth-${ALETH_VERSION}-linux-x86_64.tar.gz
|
|
|
|
test "$(shasum /tmp/test/aleth.tar.gz)" = "$ALETH_HASH /tmp/test/aleth.tar.gz"
|
|
|
|
tar -xf /tmp/test/aleth.tar.gz -C /tmp/test
|
|
|
|
ALETH_PATH="/tmp/test/bin/aleth"
|
2018-02-26 19:41:18 +00:00
|
|
|
sync
|
2018-06-20 15:26:27 +00:00
|
|
|
chmod +x $ALETH_PATH
|
2018-02-26 19:41:18 +00:00
|
|
|
sync # Otherwise we might get a "text file busy" error
|
2018-02-13 10:54:22 +00:00
|
|
|
fi
|
2016-08-01 05:25:37 +00:00
|
|
|
|
2018-02-26 19:41:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# $1: data directory
|
|
|
|
# echos the PID
|
2018-06-20 15:26:27 +00:00
|
|
|
function run_aleth()
|
2018-02-26 19:41:18 +00:00
|
|
|
{
|
2018-12-13 11:07:32 +00:00
|
|
|
$ALETH_PATH --db memorydb --test -d "${WORKDIR}" >/dev/null 2>&1 &
|
2018-02-26 19:41:18 +00:00
|
|
|
echo $!
|
|
|
|
# Wait until the IPC endpoint is available.
|
2018-07-27 08:32:04 +00:00
|
|
|
while [ ! -S "${WORKDIR}/geth.ipc" ] ; do sleep 1; done
|
2018-02-26 19:41:18 +00:00
|
|
|
sleep 2
|
|
|
|
}
|
|
|
|
|
2018-06-20 15:26:27 +00:00
|
|
|
function check_aleth() {
|
|
|
|
printTask "Running IPC tests with $ALETH_PATH..."
|
|
|
|
if ! hash $ALETH_PATH 2>/dev/null; then
|
|
|
|
printError "$ALETH_PATH not found"
|
2018-07-03 01:23:49 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-04-26 11:38:20 +00:00
|
|
|
if [ "$IPC_ENABLED" = true ];
|
|
|
|
then
|
2018-06-20 15:26:27 +00:00
|
|
|
download_aleth
|
|
|
|
check_aleth
|
2018-07-27 08:32:04 +00:00
|
|
|
ALETH_PID=$(run_aleth)
|
2018-04-26 11:38:20 +00:00
|
|
|
fi
|
2018-02-26 19:41:18 +00:00
|
|
|
|
|
|
|
progress="--show-progress"
|
2018-04-16 20:12:30 +00:00
|
|
|
if [ "$CIRCLECI" ]
|
2018-02-26 19:41:18 +00:00
|
|
|
then
|
|
|
|
progress=""
|
|
|
|
fi
|
2016-08-01 05:25:37 +00:00
|
|
|
|
2018-04-06 10:20:01 +00:00
|
|
|
EVM_VERSIONS="homestead byzantium"
|
|
|
|
|
|
|
|
if [ "$CIRCLECI" ] || [ -z "$CI" ]
|
|
|
|
then
|
|
|
|
EVM_VERSIONS+=" constantinople"
|
|
|
|
fi
|
|
|
|
|
2018-02-22 16:21:26 +00:00
|
|
|
# And then run the Solidity unit-tests in the matrix combination of optimizer / no optimizer
|
|
|
|
# and homestead / byzantium VM, # pointing to that IPC endpoint.
|
|
|
|
for optimize in "" "--optimize"
|
|
|
|
do
|
2018-04-06 10:20:01 +00:00
|
|
|
for vm in $EVM_VERSIONS
|
2018-02-22 16:21:26 +00:00
|
|
|
do
|
2018-04-17 06:53:21 +00:00
|
|
|
printTask "--> Running tests using "$optimize" --evm-version "$vm"..."
|
2018-02-22 16:21:26 +00:00
|
|
|
log=""
|
|
|
|
if [ -n "$log_directory" ]
|
|
|
|
then
|
|
|
|
if [ -n "$optimize" ]
|
|
|
|
then
|
|
|
|
log=--logger=JUNIT,test_suite,$log_directory/opt_$vm.xml $testargs
|
|
|
|
else
|
|
|
|
log=--logger=JUNIT,test_suite,$log_directory/noopt_$vm.xml $testargs_no_opt
|
|
|
|
fi
|
|
|
|
fi
|
2018-07-27 08:32:04 +00:00
|
|
|
"$REPO_ROOT"/build/test/soltest $progress $log -- --testpath "$REPO_ROOT"/test "$optimize" --evm-version "$vm" $SMT_FLAGS $IPC_FLAGS --ipcpath "${WORKDIR}/geth.ipc"
|
2018-02-22 16:21:26 +00:00
|
|
|
done
|
|
|
|
done
|
2018-02-26 19:41:18 +00:00
|
|
|
|
2018-07-27 08:32:04 +00:00
|
|
|
if [[ -n $CMDLINE_PID ]] && ! wait $CMDLINE_PID
|
2018-04-17 06:53:21 +00:00
|
|
|
then
|
|
|
|
printError "Commandline tests FAILED"
|
2018-07-27 08:32:04 +00:00
|
|
|
CMDLINE_PID=
|
2018-04-17 06:53:21 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2018-02-26 19:41:18 +00:00
|
|
|
|
2018-07-27 08:32:04 +00:00
|
|
|
cleanup
|