2016-10-30 18:22:27 +00:00
|
|
|
#!/bin/bash
|
2016-10-31 22:02:35 +00:00
|
|
|
#
|
|
|
|
# This script builds tests, deploys them on one of the available test
|
2016-11-11 23:25:08 +00:00
|
|
|
# servers and runs them. If deployment fails it will not return an error code.
|
|
|
|
# If tests fail the script will return an error code.
|
|
|
|
# It is done this way not to fail Travis build if one of the test servers is
|
|
|
|
# down.
|
2016-10-30 18:22:27 +00:00
|
|
|
|
2016-10-31 22:02:35 +00:00
|
|
|
# Test servers configuration
|
|
|
|
TEST_SERVERS[0]="IP=195.138.84.66;User=pi;Type=solo"
|
|
|
|
TEST_SERVERS[1]="IP=195.138.84.66;User=pi;Type=dual"
|
2016-10-30 18:22:27 +00:00
|
|
|
|
2016-11-11 23:25:08 +00:00
|
|
|
# It will be populated in 'build' function
|
2016-10-31 22:02:35 +00:00
|
|
|
FLASH_CMD=
|
|
|
|
|
2016-11-11 23:25:08 +00:00
|
|
|
# Function doesn't accept any arguments. It builds the tests,
|
2016-10-31 22:02:35 +00:00
|
|
|
# packages the binaries into the archive and populates FLASH_CMD variable.
|
2016-10-30 18:22:27 +00:00
|
|
|
function build {
|
|
|
|
echo "Building tests"
|
|
|
|
make -C ./tests clean
|
|
|
|
make -C ./tests -j8
|
2016-10-31 22:32:03 +00:00
|
|
|
FLASH_CMD=$(make -s -C ./tests print_flash_cmd)
|
2016-10-31 22:02:35 +00:00
|
|
|
|
|
|
|
# Now we need to pack all files that are included in the flash cmd
|
2016-11-11 23:25:08 +00:00
|
|
|
# so they can be transferred to the remote server and run there
|
2016-10-31 22:02:35 +00:00
|
|
|
# Also we need to prepare flash command:
|
|
|
|
# - remove firmware files path
|
|
|
|
# - remove serial port parameter
|
|
|
|
mkdir -p /tmp/firmware
|
|
|
|
rm -rf /tmp/firmware/*
|
|
|
|
params=($FLASH_CMD)
|
|
|
|
pushd ./tests
|
|
|
|
for param in "${params[@]}"
|
|
|
|
do
|
|
|
|
if [ -f ${param} ]
|
|
|
|
then
|
|
|
|
file_name=${param##*/}
|
|
|
|
cp ${param} /tmp/firmware/
|
|
|
|
FLASH_CMD=${FLASH_CMD/${param}/${file_name}}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Removing port parameter from the cmd string
|
|
|
|
if [[ "$param" == "-p" || "$param" == "--port" ]]
|
|
|
|
then
|
|
|
|
FLASH_CMD=${FLASH_CMD/${param}/}
|
|
|
|
next_port=true
|
|
|
|
else
|
|
|
|
# Removing port value from the cmd string
|
|
|
|
if [ "$next_port" ]
|
|
|
|
then
|
|
|
|
FLASH_CMD=${FLASH_CMD/${param} /}
|
|
|
|
unset next_port
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
cp test_runner.py /tmp/firmware/
|
|
|
|
tar -czf /tmp/tests.tar.gz -C /tmp/firmware .
|
|
|
|
popd
|
2016-10-30 18:22:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# $1 - Server IP
|
|
|
|
# $2 - Login user name
|
|
|
|
function deploy {
|
|
|
|
echo "Deploying tests, server IP=${1}"
|
|
|
|
scp /tmp/tests.tar.gz ${2}@${1}:/tmp/tests.tar.gz
|
|
|
|
ssh ${2}@${1} mkdir -p /tmp/eor_test
|
|
|
|
ssh ${2}@${1} rm -rf /tmp/eor_test/*
|
|
|
|
ssh ${2}@${1} tar -xzf /tmp/tests.tar.gz -C /tmp/eor_test
|
|
|
|
}
|
|
|
|
|
|
|
|
# $1 - Server IP
|
|
|
|
# $2 - Login user name
|
|
|
|
# $3 - Type "solo" or "dual"
|
|
|
|
function run_tests {
|
2016-10-31 22:02:35 +00:00
|
|
|
echo "Running tests, server IP=${1}, type=${3}"
|
|
|
|
echo "Flash cmd: ${FLASH_CMD}"
|
|
|
|
# Run test runner on the remote server
|
|
|
|
# ssh ${2}@${1} "source /home/pi/.profile; cd /tmp/eor_test/; ./test_runner.py --type ${3} -f -c \"${FLASH_CMD}\""
|
|
|
|
ssh ${2}@${1} "source /home/pi/.profile; /tmp/eor_test/test_runner.py --type ${3} -f -c \"${FLASH_CMD}\""
|
2016-10-30 18:22:27 +00:00
|
|
|
}
|
|
|
|
|
2016-10-31 22:02:35 +00:00
|
|
|
# First step is to build a firmware
|
2016-10-30 18:22:27 +00:00
|
|
|
build
|
|
|
|
|
2016-10-31 22:02:35 +00:00
|
|
|
failed=0
|
|
|
|
|
2016-10-30 18:22:27 +00:00
|
|
|
for server in "${TEST_SERVERS[@]}"
|
|
|
|
do
|
|
|
|
params=(${server//;/ })
|
|
|
|
ip=${params[0]#IP=}
|
|
|
|
user=${params[1]#User=}
|
|
|
|
type=${params[2]#Type=}
|
2016-10-31 22:02:35 +00:00
|
|
|
|
2016-10-30 18:22:27 +00:00
|
|
|
deploy ${ip} ${user}
|
2016-10-31 22:02:35 +00:00
|
|
|
if [ "$?" -eq "0" ]
|
|
|
|
then
|
|
|
|
run_tests ${ip} ${user} ${type}
|
|
|
|
if [ "$?" -ne "0" ]
|
|
|
|
then
|
|
|
|
failed=$((failed+1))
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Server ${ip} is not available"
|
|
|
|
fi
|
2016-10-30 18:22:27 +00:00
|
|
|
done
|
|
|
|
|
2016-10-31 22:02:35 +00:00
|
|
|
exit $failed
|