mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-30 09:13:29 +00:00
tests: Add ability to restrict which tests run
Added options to the test script to allow: - all tests for a specific distro (`--distro $distro`). - all image tests (`--test-images-only`). - all initrd tests (`--test-initrds-only`). Any combination of the above is also permitted. By default, all tests will be run. Fixes #142. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
parent
80e1997721
commit
c679cae92c
@ -7,6 +7,7 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
readonly script_dir="$(dirname $(readlink -f $0))"
|
readonly script_dir="$(dirname $(readlink -f $0))"
|
||||||
|
readonly script_name=${0##*/}
|
||||||
|
|
||||||
readonly rootfs_sh="${script_dir}/../rootfs-builder/rootfs.sh"
|
readonly rootfs_sh="${script_dir}/../rootfs-builder/rootfs.sh"
|
||||||
readonly image_builder_sh="${script_dir}/../image-builder/image_builder.sh"
|
readonly image_builder_sh="${script_dir}/../image-builder/image_builder.sh"
|
||||||
@ -23,9 +24,42 @@ readonly mgr="${tests_repo_dir}/cmd/kata-manager/kata-manager.sh"
|
|||||||
readonly RUNTIME=${RUNTIME:-kata-runtime}
|
readonly RUNTIME=${RUNTIME:-kata-runtime}
|
||||||
readonly MACHINE_TYPE=`uname -m`
|
readonly MACHINE_TYPE=`uname -m`
|
||||||
|
|
||||||
|
# all distro tests must have this prefix
|
||||||
|
readonly test_func_prefix="test_distro_"
|
||||||
|
|
||||||
# "docker build" does not work with a VM-based runtime
|
# "docker build" does not work with a VM-based runtime
|
||||||
readonly docker_build_runtime="runc"
|
readonly docker_build_runtime="runc"
|
||||||
|
|
||||||
|
test_images_only="false"
|
||||||
|
test_initrds_only="false"
|
||||||
|
|
||||||
|
usage()
|
||||||
|
{
|
||||||
|
cat <<EOT
|
||||||
|
Usage: $script_name [help|<distro>]
|
||||||
|
$script_name [options]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
|
||||||
|
-h | --help # Show usage.
|
||||||
|
--distro <distro> # Only run tests for specified distro.
|
||||||
|
--list # List all distros that can be tested.
|
||||||
|
--test-images-only # Only run images tests for the list of distros under test.
|
||||||
|
--test-initrds-only # Only run initrds tests for the list of distros under test.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
|
||||||
|
|
||||||
|
help : Show usage.
|
||||||
|
<distro> : Only run tests for specified distro.
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
|
||||||
|
- If no options or parameters are specified, all tests will be run.
|
||||||
|
|
||||||
|
EOT
|
||||||
|
}
|
||||||
|
|
||||||
exit_handler()
|
exit_handler()
|
||||||
{
|
{
|
||||||
if [ "$?" -eq 0 ]
|
if [ "$?" -eq 0 ]
|
||||||
@ -284,13 +318,23 @@ create_and_run()
|
|||||||
|
|
||||||
if [ "$image_options" != "no" ]
|
if [ "$image_options" != "no" ]
|
||||||
then
|
then
|
||||||
|
if [ "${test_initrds_only}" = "true" ]
|
||||||
|
then
|
||||||
|
info "only testing initrds: skipping image test for distro $distro"
|
||||||
|
else
|
||||||
handle_options "$distro" "image" "$image_options"
|
handle_options "$distro" "image" "$image_options"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$initrd_options" != "no" ]
|
if [ "$initrd_options" != "no" ]
|
||||||
then
|
then
|
||||||
|
if [ "${test_images_only}" = "true" ]
|
||||||
|
then
|
||||||
|
info "only testing images: skipping initrd test for distro $distro"
|
||||||
|
else
|
||||||
handle_options "$distro" "initrd" "$initrd_options"
|
handle_options "$distro" "initrd" "$initrd_options"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test()
|
run_test()
|
||||||
@ -347,6 +391,47 @@ test_distro_alpine()
|
|||||||
run_test "${name}" "" "alpine" "no" "init"
|
run_test "${name}" "" "alpine" "no" "init"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Displays a list of all distro test functions
|
||||||
|
get_distro_test_names()
|
||||||
|
{
|
||||||
|
typeset -F | awk '{print $3}' |\
|
||||||
|
grep "^${test_func_prefix}" | sort
|
||||||
|
}
|
||||||
|
|
||||||
|
# Displays a list of distros which can be tested
|
||||||
|
list_distros()
|
||||||
|
{
|
||||||
|
get_distro_test_names | sed "s/${test_func_prefix}//g"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_single_distro()
|
||||||
|
{
|
||||||
|
local -r distro="$1"
|
||||||
|
|
||||||
|
[ -z "$distro" ] && die "distro cannot be blank"
|
||||||
|
|
||||||
|
local -r expected_func="${test_func_prefix}${distro}"
|
||||||
|
|
||||||
|
local test_funcs
|
||||||
|
test_funcs=$(get_distro_test_names)
|
||||||
|
|
||||||
|
local defined_func
|
||||||
|
defined_func=$(echo "$test_funcs" | grep "^${expected_func}$" || true)
|
||||||
|
|
||||||
|
if [ -z "$defined_func" ]
|
||||||
|
then
|
||||||
|
local distros
|
||||||
|
|
||||||
|
# make a comma-separated list
|
||||||
|
distros=$(list_distros | tr '\n' ',' | sed 's/,$//g')
|
||||||
|
|
||||||
|
die "no test for distro '$distro' (try one of $distros)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# run the test
|
||||||
|
$defined_func
|
||||||
|
}
|
||||||
|
|
||||||
test_all_distros()
|
test_all_distros()
|
||||||
{
|
{
|
||||||
test_distro_fedora
|
test_distro_fedora
|
||||||
@ -364,9 +449,59 @@ test_all_distros()
|
|||||||
|
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
|
local args=$(getopt \
|
||||||
|
-n "$script_name" \
|
||||||
|
-a \
|
||||||
|
--options="h" \
|
||||||
|
--longoptions="help distro: list test-images-only test-initrds-only" \
|
||||||
|
-- "$@")
|
||||||
|
|
||||||
|
eval set -- "$args"
|
||||||
|
[ $? -ne 0 ] && { usage >&2; exit 1; }
|
||||||
|
|
||||||
|
local distro=
|
||||||
|
|
||||||
|
while [ $# -gt 1 ]
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
--distro) distro="$2";;
|
||||||
|
|
||||||
|
-h|--help) usage; exit 0 ;;
|
||||||
|
|
||||||
|
--list) list_distros; exit 0;;
|
||||||
|
|
||||||
|
--test-images-only)
|
||||||
|
test_images_only="true"
|
||||||
|
test_initrds_only="false"
|
||||||
|
;;
|
||||||
|
|
||||||
|
--test-initrds-only)
|
||||||
|
test_initrds_only="true"
|
||||||
|
test_images_only="false"
|
||||||
|
;;
|
||||||
|
|
||||||
|
--) shift; break ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
# Consume getopt cruft
|
||||||
|
[ "$1" = "--" ] && shift
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
help) usage && exit 0;;
|
||||||
|
*) distro="$1";;
|
||||||
|
esac
|
||||||
|
|
||||||
setup
|
setup
|
||||||
|
|
||||||
|
if [ -n "$distro" ]
|
||||||
|
then
|
||||||
|
test_single_distro "$distro"
|
||||||
|
else
|
||||||
test_all_distros
|
test_all_distros
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
Loading…
Reference in New Issue
Block a user