summaryrefslogtreecommitdiff
path: root/ravenwood/scripts/run-ravenwood-tests.sh
blob: 67ebb1fc94733f618cf750cf5f58e2a6beea11c1 (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
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
115
116
117
118
119
#!/bin/bash
# Copyright (C) 2024 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Run all the ravenwood tests + hoststubgen unit tests.
#
# Options:
#
#   -s: "Smoke" test -- skip slow tests (SysUI, ICU)
#
#   -x PCRE: Specify exclusion filter in PCRE
#            Example: -x '^(Cts|hoststub)' # Exclude CTS and hoststubgen tests.
#
#   -f PCRE: Specify inclusion filter in PCRE


# Regex to identify slow tests, in PCRE
SLOW_TEST_RE='^(SystemUiRavenTests|CtsIcuTestCasesRavenwood|CarSystemUIRavenTests)$'

smoke=0
include_re=""
exclude_re=""
smoke_exclude_re=""
dry_run=""
while getopts "sx:f:dtb" opt; do
case "$opt" in
    s)
        # Remove slow tests.
        smoke_exclude_re="$SLOW_TEST_RE"
        ;;
    x)
        # Take a PCRE from the arg, and use it as an exclusion filter.
        exclude_re="$OPTARG"
        ;;
    f)
        # Take a PCRE from the arg, and use it as an inclusion filter.
        include_re="$OPTARG"
        ;;
    d)
        # Dry run
        dry_run="echo"
        ;;
    t)
        # Redirect log to terminal
        export RAVENWOOD_LOG_OUT=$(tty)
        ;;
    b)
        # Build only
        ATEST=m
        ;;
    '?')
        exit 1
        ;;
esac
done
shift $(($OPTIND - 1))

all_tests=(hoststubgentest tiny-framework-dump-test hoststubgen-invoke-test ravenwood-stats-checker ravenhelpertest)
all_tests+=( $(${0%/*}/list-ravenwood-tests.sh) )

filter() {
    local re="$1"
    local grep_arg="$2"
    if [[ "$re" == "" ]] ; then
        cat # No filtering
    else
        grep $grep_arg -iP "$re"
    fi
}

filter_in() {
    filter "$1"
}

filter_out() {
    filter "$1" -v
}


# Remove the slow tests.
targets=( $(
    for t in "${all_tests[@]}"; do
        echo $t | filter_in "$include_re" | filter_out "$smoke_exclude_re" | filter_out "$exclude_re"
    done
) )

# Show the target tests

echo "Target tests:"
for t in "${targets[@]}"; do
    echo "  $t"
done

# Calculate the removed tests.

diff="$(diff  <(echo "${all_tests[@]}" | tr ' ' '\n') <(echo "${targets[@]}" | tr ' ' '\n') | grep -v [0-9] )"

if [[ "$diff" != "" ]]; then
    echo "Excluded tests:"
    echo "$diff"
fi

run() {
    echo "Running: ${@}"
    "${@}"
}

run $dry_run ${ATEST:-atest} "${targets[@]}"