File: run-tests.sh

package info (click to toggle)
android-platform-system-tools-hidl 10.0.0%2Br36-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,936 kB
  • sloc: cpp: 21,933; yacc: 1,416; java: 1,239; lex: 496; sh: 360; python: 44; xml: 20; makefile: 12
file content (114 lines) | stat: -rwxr-xr-x 3,107 bytes parent folder | download | duplicates (3)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash

# See hal_hidl_gtest.py

THREADS=
CHECKER=vts_testability_checker
CHECKER_DEVICE_PATH="/data/local/tmp/${CHECKER}"
PRINT_COMMANDS=

function run() {
    if [ "${PRINT_COMMANDS}" = true ] ; then
        >&2 echo "*** $@"
    fi
    $@
}

function make_modules() {
    if [ "${THREADS}" != "0" ] ; then
        run make -j${THREADS} -C ${ANDROID_BUILD_TOP} -f build/core/main.mk $@
    fi
}

function push_checker() {
    run adb push ${OUT}/system/bin/${CHECKER} ${CHECKER_DEVICE_PATH}
}

function push_test() {
    local module=$1
    for test_dir in nativetest nativetest64 ; do
        local test_file=/data/${test_dir}/${module}/${module}
        run adb push ${OUT}${test_file} ${test_file}
    done
}

function read_checker_output() {
    python -c 'import json,sys;obj=json.load(sys.stdin);sys.stdout.write("%s\n"%obj["Testable"]);map(lambda i:sys.stdout.write("%s\n"%i),obj["instances"])'
}

function run_test() {
    local module=$1
    local status=0

    for test_dir in nativetest nativetest64 ; do
        local test_file=/data/${test_dir}/${module}/${module}
        local interfaces=$(run adb shell ${test_file} --list_registered_services \
            | sed -n 's/^hal_service: \(.*\)$/\1/p')
        if [ -z "$interfaces" ]; then
            run adb shell ${test_file} || status=$?
        else
            for interface in ${interfaces} ; do
                local output=$(run adb shell ${CHECKER_DEVICE_PATH} -c ${interface} | read_checker_output)
                local testable=$(echo "${output}" | head -n1)
                local instances=$(echo "${output}" | tail -n+2)

                if [ "${testable}" == "True" ] ; then
                    for instance in ${instances} ; do
                        run adb shell ${test_file} --hal_service_instance="${interface}/${instance}" || status=$?
                    done
                fi
            done
        fi
    done
    return ${status}
}

function usage() {
    echo "usage: $0 -m <module_name> [-m <module_name>[...]] [-j <jobs>] [-p]"
    echo "          -m <module_name>: name of test (e.g. VtsHalHealthV2_0TargetTest)"
    echo "          -p: print commands"
    echo "          -j <jobs>: # jobs in make. "
    echo "                     -j0 skips making any modules."
    echo "                     If not present, use infinite number of jobs."

    exit 1
}

function main() {
    local modules=

    while getopts "m:j:p" option ; do
        case "${option}" in
            m)
                [ ! -z ${OPTARG} ] || usage
                modules="${modules} ${OPTARG}"
                ;;
            j)
                THREADS=${OPTARG}
                ;;
            p)
                PRINT_COMMANDS=true
                ;;
            *)
                usage
                ;;
        esac
    done

    set -e
    make_modules ${CHECKER} ${modules}
    run adb root
    push_checker
    for module in ${modules} ; do
        push_test ${module}
    done

    set +e
    local status=0
    for module in ${modules} ; do
        run_test ${module} || status=$?
    done
    return ${status}
}

main $@