summaryrefslogtreecommitdiff
path: root/ravenwood/scripts/update-test-mapping.sh
blob: ab37baf01ea536d76d91c056ae59fd9255da9515 (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
#!/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.

# Update f/b/r/TEST_MAPPING with all the ravenwood tests as presubmit.
#
# Note, before running it, make sure module-info.json is up-to-date by running
# (any) build.

set -e

# Tests that shouldn't be in presubmit.
EXEMPT='^(SystemUiRavenTests)$'

is_car() {
    local module="$1"

    # If the module name starts with "Car", then it's a test for "Car".
    [[ "$module" =~ ^Car ]]
    return $?
}

main() {
    local script_name="${0##*/}"
    local script_dir="${0%/*}"
    local test_mapping="$script_dir/../TEST_MAPPING"
    local test_mapping_bak="$script_dir/../TEST_MAPPING.bak"

    local header="$(sed -ne '1,/AUTO-GENERATED-START/p' "$test_mapping")"
    local footer="$(sed -ne '/AUTO-GENERATED-END/,$p' "$test_mapping")"

    echo "Getting all tests"
    local tests=( $("$script_dir/list-ravenwood-tests.sh" | grep -vP "$EXEMPT") )

    local num_tests="${#tests[@]}"

    if (( $num_tests == 0 )) ; then
        echo "Something went wrong. No ravenwood tests detected." 1>&2
        return 1
    fi

    echo "Tests: ${tests[@]}"

    echo "Creating backup at $test_mapping_bak"
    cp "$test_mapping" "$test_mapping_bak"

    echo "Updating $test_mapping"
    {
        echo "$header"

        echo "    // DO NOT MODIFY MANUALLY"
        echo "    // Use scripts/$script_name to update it."

        local i=0
        while (( $i < $num_tests )) ; do
            local comma=","
            if (( $i == ($num_tests - 1) )); then
                comma=""
            fi
            echo "    {"
            echo "      \"name\": \"${tests[$i]}\","
            if is_car "${tests[$i]}"; then
                echo '      "keywords": ["automotive_code_coverage"],'
            fi

            echo "      \"host\": true"
            echo "    }$comma"

            i=$(( $i + 1 ))
        done

        echo "$footer"
    } >"$test_mapping"

    if cmp "$test_mapping_bak" "$test_mapping" ; then
        echo "No change detecetd."
        return 0
    fi
    echo "Updated $test_mapping"

    # `|| true` is needed because of `set -e`.
    diff -u "$test_mapping_bak" "$test_mapping" || true
    return 0
}

main