Strips commonly used helper functions in scripts into its own file to be shared with scripts along with minor syntax cleanup.

Also includes first bits for valgrind testing.
This commit is contained in:
Christian Parpart 2019-04-24 11:23:22 +02:00
parent eac0048176
commit 1a3c31a926
3 changed files with 108 additions and 56 deletions

96
scripts/functions.sh Normal file
View File

@ -0,0 +1,96 @@
# ------------------------------------------------------------------------------
# This file is to be included by other scripts that want to include functionality exported below.
#
# ------------------------------------------------------------------------------
# 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) 2019 solidity contributors.
#------------------------------------------------------------------------------
# Default to xterm if no terminal was set.
export TERM=${TERM:-"xterm"}
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
function get_valgrind_prefix()
{
if [[ "${ENABLE_VALGRIND}" != "true" ]]; then
return
fi
if [[ "$CIRCLECI" ]]; then
apt-get install -qqy valgrind 1>&2
fi
local exe=`which valgrind 2>/dev/null`
if [[ -z "${exe}" ]]; then
return
fi
echo -n "${exe} -v --num-callers=64 --error-exitcode=42"
}
VG=`get_valgrind_prefix`
function ask_expectation_update()
{
local newExpectation="${1}"
local expectationFile="${2}"
while true;
do
set +e
read -t10 -p "(u)pdate expectation/(q)uit? "
if [ $? -gt 128 ];
then
echo -e "\nUser input timed out."
exit 1
fi
set -e
case $REPLY in
u* ) echo "$newExpectation" > $expectationFile ; break;;
q* ) exit 1;;
esac
done
}
function 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
}

View File

@ -29,6 +29,7 @@
set -e
REPO_ROOT="$(dirname "$0")"/..
source "${REPO_ROOT}/scripts/functions.sh"
WORKDIR=`mktemp -d`
# Will be printed in case of a test failure
@ -37,8 +38,9 @@ IPC_ENABLED=true
ALETH_PID=
CMDLINE_PID=
if [[ "$OSTYPE" == "darwin"* ]]
then
if [[ "$VG" != "" ]]; then
SMT_FLAGS="--no-smt"
elif [[ "$OSTYPE" == "darwin"* ]]; then
SMT_FLAGS="--no-smt"
if [ "$CIRCLECI" ]
then
@ -47,31 +49,6 @@ then
fi
fi
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
@ -103,15 +80,6 @@ else
log_directory=""
fi
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
printTask "Running commandline tests..."
# Only run in parallel if this is run on CI infrastructure
if [[ -n "$CI" ]]
@ -145,7 +113,6 @@ function download_aleth()
chmod +x $ALETH_PATH
sync # Otherwise we might get a "text file busy" error
fi
}
# $1: data directory
@ -212,16 +179,16 @@ do
log=""
if [ -n "$log_directory" ]
then
if [ -n "$optimize" ]
then
log=--logger=JUNIT,error,$log_directory/opt_$vm.xml $testargs
else
log=--logger=JUNIT,error,$log_directory/noopt_$vm.xml $testargs_no_opt
fi
if [ -n "$optimize" ]
then
log=--logger=JUNIT,error,$log_directory/opt_$vm.xml $testargs
else
log=--logger=JUNIT,error,$log_directory/noopt_$vm.xml $testargs_no_opt
fi
fi
set +e
"$REPO_ROOT"/build/test/soltest $progress $log -- --testpath "$REPO_ROOT"/test "$optimize" --evm-version "$vm" $SMT_FLAGS $IPC_FLAGS $force_abiv2_flag --ipcpath "${WORKDIR}/geth.ipc"
$VG "$REPO_ROOT"/build/test/soltest $progress $log -- --testpath "$REPO_ROOT"/test "$optimize" --evm-version "$vm" $SMT_FLAGS $IPC_FLAGS $force_abiv2_flag --ipcpath "${WORKDIR}/geth.ipc"
if test "0" -ne "$?"; then
if [ -n "$log_directory" ]
@ -234,7 +201,6 @@ do
exit 1
fi
set -e
done
done
done

View File

@ -36,16 +36,7 @@ SOLC="$REPO_ROOT/build/solc/solc"
FULLARGS="--optimize --ignore-missing --combined-json abi,asm,ast,bin,bin-runtime,compact-format,devdoc,hashes,interface,metadata,opcodes,srcmap,srcmap-runtime,userdoc"
## FUNCTIONS
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
source "${REPO_ROOT}/scripts/functions.sh"
function compileFull()
{
@ -199,7 +190,6 @@ function test_solc_behaviour()
fi
}
function test_solc_assembly_output()
{
local input="${1}"