summaryrefslogtreecommitdiff
path: root/ktest
blob: 1a7eb699b96868483d328d96c6faaccbca2c391f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash

set -o nounset
set -o errexit
set -o errtrace

# check for typical shell script errors

export PS4='+${LINENO}+ '

ktest_dir=$(dirname "$(readlink -f "$0")")

ktest_kernel_binary=""	# dir that has the kernel to run
                        #       set with: -k <path>

. "$ktest_dir/lib/util.sh"
. "$ktest_dir/lib/libktest.sh"

usage()
{
    echo "ktest: Run generic virtual machine tests"
    echo "Usage: ktest cmd [options]"
    ktest_usage_cmds
    echo
    echo "  options:"
    ktest_usage_opts
    echo
    echo " options for ktest run:"
    ktest_usage_run_opts
    echo
    ktest_usage_post
}

if [[ $# = 0 ]]; then
    usage
    exit 1
fi

cmd_run()
{
    if [[ $# = 0 ]]; then
	echo "ktest: missing test"
	exit 1
    fi

    ktest_test=$1
    shift
    ktest_testargs="$@"

    echo Running test $(basename "$ktest_test")
    parse_test_deps "$ktest_test"

    start_vm
}

#parse command and shift for rest of arg parsing
CMD="$1"
shift

# check if command is valid
if [[ $(type -t "cmd_$CMD") == function ]]; then
    CMD="cmd_$CMD"
elif [[ $(type -t "ktest_$CMD") == function ]]; then
    CMD="ktest_$CMD"
else
    usage
    exit 1
fi

while getopts "h${ktest_args}" arg; do
    case $arg in
	h)
	    usage
	    exit 0
	    ;;
    esac
    parse_ktest_arg $arg
done
shift $((OPTIND - 1))

parse_args_post

$CMD "$@"