summaryrefslogtreecommitdiff
path: root/ktest
blob: e027afbef91fb9e8880dd1483a5cd373796ebda4 (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
84
85
86
87
#!/bin/bash

# Dec 2019: requires additional validation via https://github.com/koalaman/shellcheck

set -o nounset
set -o errexit
set -o errtrace
shopt -s lastpipe

# 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>

source "$ktest_dir/lib/util.sh" || exit 1
source "$ktest_dir/lib/libktest.sh" || exit 1

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:"
    echo "      -k <dir>    kernel to 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=("$@")

    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 "k:h${ktest_args}" arg; do
    case $arg in
    k)
        ktest_kernel_binary=$OPTARG
        ;;
    h)
        usage
        exit 0
        ;;
    esac
    parse_ktest_arg "$arg"
done
shift $((OPTIND - 1))

parse_args_post

$CMD "$@"