|
Petr Šabata |
f5bf49 |
#!/usr/bin/env sh
|
|
Petr Šabata |
f5bf49 |
[ -z "$BASEDIR" ] && BASEDIR=$(realpath $(dirname "$0"))
|
|
Petr Šabata |
f5bf49 |
[ -z "$TESTDIR" ] && TESTDIR=$(realpath $BASEDIR/../)
|
|
Petr Šabata |
f5bf49 |
[ -z "$TEST_BASE_IMAGE" ] && TEST_BASE_IMAGE=$TESTDIR/output/test-base-image
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
[[ ! -e $TEST_BASE_IMAGE ]] && echo "Test base image not found." && exit 1
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
DEFAULT_QEMU_CMD="-nodefaults \
|
|
Petr Šabata |
f5bf49 |
-nographic \
|
|
Petr Šabata |
f5bf49 |
-smp 2 \
|
|
Petr Šabata |
f5bf49 |
-m 768M \
|
|
Petr Šabata |
f5bf49 |
-monitor none"
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
_YELLOW='\033[1;33m'
|
|
Petr Šabata |
f5bf49 |
_GREEN='\033[0;32m'
|
|
Petr Šabata |
f5bf49 |
_RED='\033[0;31m'
|
|
Petr Šabata |
f5bf49 |
_NC='\033[0m' # No Color
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
get_test_path() {
|
|
Petr Šabata |
f5bf49 |
local script=$1
|
|
Petr Šabata |
f5bf49 |
local testname=$(basename $(dirname $script))
|
|
Petr Šabata |
f5bf49 |
local output=$TESTDIR/output/$testname
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
echo $output
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
get_test_entry_name() {
|
|
Petr Šabata |
f5bf49 |
echo $(basename ${1%.*})
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
get_test_image() {
|
|
Petr Šabata |
f5bf49 |
local script=$1
|
|
Petr Šabata |
f5bf49 |
local testout=$(get_test_path $script)
|
|
Petr Šabata |
f5bf49 |
local entry=$(get_test_entry_name $script)
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
echo $testout/$entry.img
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
get_test_qemu_cmd_file() {
|
|
Petr Šabata |
f5bf49 |
local script=$1
|
|
Petr Šabata |
f5bf49 |
local testout=$(get_test_path $script)
|
|
Petr Šabata |
f5bf49 |
local entry=$(get_test_entry_name $script)
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
echo $testout/$entry.qemu_cmd
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
get_test_qemu_cmd() {
|
|
Petr Šabata |
f5bf49 |
cat $(get_test_qemu_cmd_file $1)
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
get_test_output_file() {
|
|
Petr Šabata |
f5bf49 |
local script=$1
|
|
Petr Šabata |
f5bf49 |
local testout=$(get_test_path $script)
|
|
Petr Šabata |
f5bf49 |
local entry=$(get_test_entry_name $script)
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
echo $testout/$entry.output
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
get_test_console_file() {
|
|
Petr Šabata |
f5bf49 |
local script=$1
|
|
Petr Šabata |
f5bf49 |
local testout=$(get_test_path $script)
|
|
Petr Šabata |
f5bf49 |
local entry=$(get_test_entry_name $script)
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
echo $testout/$entry.console
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
get_test_output() {
|
|
Petr Šabata |
f5bf49 |
local output=$(get_test_output_file $1)
|
|
Petr Šabata |
f5bf49 |
if [ -e "$output" ]; then
|
|
Petr Šabata |
f5bf49 |
cat $(get_test_output_file $1)
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
echo "<No Output>"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
build_test_image() {
|
|
Petr Šabata |
f5bf49 |
local script=$1
|
|
Petr Šabata |
f5bf49 |
local test_image=$(get_test_image $script)
|
|
Petr Šabata |
f5bf49 |
mkdir -p $(dirname $test_image)
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
$BASEDIR/build-image.sh \
|
|
Petr Šabata |
f5bf49 |
$TEST_BASE_IMAGE \
|
|
Petr Šabata |
f5bf49 |
$test_image \
|
|
Petr Šabata |
f5bf49 |
$BASEDIR/build-scripts/test-image.sh \
|
|
Petr Šabata |
f5bf49 |
$script
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
run_test_sync() {
|
|
Petr Šabata |
f5bf49 |
local qemu_cmd=$(get_test_qemu_cmd $1)
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ -n "$qemu_cmd" ]; then
|
|
Petr Šabata |
f5bf49 |
timeout --foreground 10m qemu-kvm $(get_test_qemu_cmd $1)
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
echo "error: test qemu command line is not configured" > /dev/stderr
|
|
Petr Šabata |
f5bf49 |
return 1
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
_check_test_result() {
|
|
Petr Šabata |
f5bf49 |
grep "TEST PASSED" $1 2>/dev/null
|
|
Petr Šabata |
f5bf49 |
[ $? -eq 0 ] && return 0
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
grep "TEST FAILED" $1 2>/dev/null
|
|
Petr Šabata |
f5bf49 |
[ $? -eq 0 ] && return 1
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
grep "TEST ABORTED" $1 2>/dev/null
|
|
Petr Šabata |
f5bf49 |
[ $? -eq 0 ] && return 2
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
return 255
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# Print test result and return below value:
|
|
Petr Šabata |
f5bf49 |
# 0: Test passed
|
|
Petr Šabata |
f5bf49 |
# 1: Test failed
|
|
Petr Šabata |
f5bf49 |
# 2: Test aborted, test scripts errored out
|
|
Petr Šabata |
f5bf49 |
# 3: Test exited unexpectely, VM got killed early, or time out
|
|
Petr Šabata |
f5bf49 |
gather_test_result() {
|
|
Petr Šabata |
f5bf49 |
local ret=255
|
|
Petr Šabata |
f5bf49 |
local res=""
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
for i in $@; do
|
|
Petr Šabata |
f5bf49 |
res=$(_check_test_result $i)
|
|
Petr Šabata |
f5bf49 |
ret=$?
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ $ret -ne 255 ]; then
|
|
Petr Šabata |
f5bf49 |
echo $res
|
|
Petr Šabata |
f5bf49 |
return $ret
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
done
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
echo "${_RED}TEST RESULT NOT FOUND!${_NC}"
|
|
Petr Šabata |
f5bf49 |
return 3
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# Wait and watch for test result
|
|
Petr Šabata |
f5bf49 |
watch_test_outputs() {
|
|
Petr Šabata |
f5bf49 |
local ret=255
|
|
Petr Šabata |
f5bf49 |
local res=""
|
|
Petr Šabata |
f5bf49 |
# If VMs are still running, check for test result, if
|
|
Petr Šabata |
f5bf49 |
# test finished, kill remaining VMs
|
|
Petr Šabata |
f5bf49 |
while true; do
|
|
Petr Šabata |
f5bf49 |
if [ -n "$(jobs -r)" ]; then
|
|
Petr Šabata |
f5bf49 |
# VMs still running
|
|
Petr Šabata |
f5bf49 |
for i in $@; do
|
|
Petr Šabata |
f5bf49 |
res=$(_check_test_result $i)
|
|
Petr Šabata |
f5bf49 |
ret=$?
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ $ret -ne 255 ]; then
|
|
Petr Šabata |
f5bf49 |
# Test finished, kill VMs
|
|
Petr Šabata |
f5bf49 |
kill $(jobs -p)
|
|
Petr Šabata |
f5bf49 |
break 2
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
done
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
# VMs exited
|
|
Petr Šabata |
f5bf49 |
ret=255
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
for i in $@; do
|
|
Petr Šabata |
f5bf49 |
res=$(_check_test_result $i)
|
|
Petr Šabata |
f5bf49 |
ret=$?
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ $ret -ne 255 ]; then
|
|
Petr Šabata |
f5bf49 |
break 2
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
done
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ $ret -eq 255 ]; then
|
|
Petr Šabata |
f5bf49 |
ret=3
|
|
Petr Šabata |
f5bf49 |
break
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
sleep 1
|
|
Petr Šabata |
f5bf49 |
done
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
return $ret
|
|
Petr Šabata |
f5bf49 |
}
|