2016-06-21 19:37:02 +03:00
#!/bin/bash
set -euo pipefail
2016-06-24 23:40:20 +03:00
. ${ commondir } /libvm.sh
2016-07-15 20:30:56 +03:00
# create ssh-config if needed and export cmds
vm_setup
2016-06-21 19:37:02 +03:00
# stand up ssh connection and sanity check that it all works
2016-06-29 00:23:53 +03:00
if ! vm_ssh_wait 20; then
2016-06-21 19:37:02 +03:00
echo "ERROR: A running VM is required for 'make vmcheck'."
exit 1
fi
2016-11-14 20:07:43 +03:00
echo "VM is running."
2016-07-04 18:39:40 +03:00
# just error out if we're unlocked -- we use the current deployment as the
# fallback between each test, so we need to be sure it's in a state that works.
# also, the user might have forgotten that these tests are somewhat destructive
# and thus would wipe out unlocked changes, hotfix or not.
2016-06-29 00:23:53 +03:00
unlocked_cur = $( vm_get_booted_deployment_info unlocked)
if [ [ $unlocked_cur != none ] ] ; then
echo "ERROR: VM is unlocked."
exit 1
fi
# remember the csum we're currently on and tag it so that ostree doesn't wipe it
csum_orig = $( vm_get_booted_csum)
vm_cmd ostree rev-parse $csum_orig & > /dev/null # validate
vm_cmd ostree refs vmcheck_orig --delete
vm_cmd ostree refs $csum_orig --create vmcheck_orig
2016-06-21 19:37:02 +03:00
LOG = ${ LOG :- " $PWD /vmcheck.log " }
echo -n '' > ${ LOG }
testdir = " $( dirname $( realpath $0 ) ) "
cd $testdir
2016-07-04 18:39:40 +03:00
colour_print( ) {
colour = $1 ; shift
[ ! -t 1 ] || echo -en " \e[ ${ colour } m "
echo -n " $@ "
[ ! -t 1 ] || echo -en "\e[0m"
echo
}
pass_print( ) {
colour_print 32 " $@ " # green
}
fail_print( ) {
colour_print 31 " $@ " # red
}
skip_print( ) {
colour_print 34 " $@ " # blue
}
total = 0
pass = 0
fail = 0
skip = 0
2016-06-21 19:37:02 +03:00
for tf in $( find . -name 'test-*.sh' | sort) ; do
if [ -n " ${ TESTS + } " ] ; then
tfbn = $( basename " $tf " .sh)
tfbn = " ${ tfbn #test- } "
if [ [ " $TESTS " != *$tfbn * ] ] ; then
continue
fi
fi
2016-07-04 18:39:40 +03:00
let "total += 1"
2016-06-21 19:37:02 +03:00
bn = $( basename ${ tf } )
printf " Running $bn ...\n "
printf " \n==== ${ tf } ====\n " >> ${ LOG }
# do some dirty piping to get some instant feedback and help debugging
if ${ tf } | & tee -a ${ LOG } \
2016-07-14 23:47:35 +03:00
| grep -e '^ok ' --line-buffered \
2016-06-21 19:37:02 +03:00
| xargs -d '\n' -n 1 echo " " ; then
2016-07-04 18:39:40 +03:00
pass_print " PASS: $bn "
2016-07-15 03:10:47 +03:00
echo "PASS" >> ${ LOG }
2016-07-04 18:39:40 +03:00
let "pass += 1"
2016-06-21 19:37:02 +03:00
else
if test $? = 77; then
2016-07-04 18:39:40 +03:00
skip_print " SKIP: $bn "
2016-07-15 03:10:47 +03:00
echo "SKIP" >> ${ LOG }
2016-07-04 18:39:40 +03:00
let "skip += 1"
2016-06-21 19:37:02 +03:00
else
2016-07-04 18:39:40 +03:00
fail_print " FAIL: $bn "
2016-07-15 03:10:47 +03:00
echo "FAIL" >> ${ LOG }
2016-07-04 18:39:40 +03:00
let "fail += 1"
2016-06-21 19:37:02 +03:00
fi
fi
2016-06-29 00:23:53 +03:00
# go back to the original vmcheck deployment if needed
csum_cur = $( vm_get_booted_csum)
unlocked_cur = $( vm_get_booted_deployment_info unlocked)
if [ [ $csum_orig != $csum_cur ] ] || \
[ [ $unlocked_cur != none ] ] ; then
# redeploy under the name 'vmcheck' so that tests can never modify the
# vmcheck_orig ref itself (e.g. package layering)
2016-07-04 18:39:40 +03:00
echo "Restoring vmcheck commit" >> ${ LOG }
vm_cmd ostree commit -b vmcheck --tree= ref = vmcheck_orig & >> ${ LOG }
vm_cmd ostree admin deploy vmcheck & >> ${ LOG }
2016-06-29 00:23:53 +03:00
vm_reboot
fi
2016-06-21 19:37:02 +03:00
done
2016-07-14 23:47:35 +03:00
# tear down ssh connection if needed
if $SSH -O check & >/dev/null; then
$SSH -O exit & >/dev/null
fi
2016-06-21 19:37:02 +03:00
2016-07-04 18:39:40 +03:00
[ ${ fail } -eq 0 ] && printer = pass || printer = fail
${ printer } _print " TOTAL: $total PASS: $pass SKIP: $skip FAIL: $fail "
echo " See ${ LOG } for more information. "
[ ${ fail } -eq 0 ]