blob: ab37baf01ea536d76d91c056ae59fd9255da9515 [file] [log] [blame]
John Wu98346162024-09-26 22:59:40 +00001#!/bin/bash
2# Copyright (C) 2024 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# Update f/b/r/TEST_MAPPING with all the ravenwood tests as presubmit.
17#
18# Note, before running it, make sure module-info.json is up-to-date by running
19# (any) build.
20
21set -e
22
23# Tests that shouldn't be in presubmit.
24EXEMPT='^(SystemUiRavenTests)$'
25
Makoto Onuki2c66eab2024-10-29 20:32:10 +000026is_car() {
27 local module="$1"
28
29 # If the module name starts with "Car", then it's a test for "Car".
30 [[ "$module" =~ ^Car ]]
31 return $?
32}
33
John Wu98346162024-09-26 22:59:40 +000034main() {
35 local script_name="${0##*/}"
36 local script_dir="${0%/*}"
37 local test_mapping="$script_dir/../TEST_MAPPING"
38 local test_mapping_bak="$script_dir/../TEST_MAPPING.bak"
39
40 local header="$(sed -ne '1,/AUTO-GENERATED-START/p' "$test_mapping")"
41 local footer="$(sed -ne '/AUTO-GENERATED-END/,$p' "$test_mapping")"
42
43 echo "Getting all tests"
44 local tests=( $("$script_dir/list-ravenwood-tests.sh" | grep -vP "$EXEMPT") )
45
46 local num_tests="${#tests[@]}"
47
48 if (( $num_tests == 0 )) ; then
49 echo "Something went wrong. No ravenwood tests detected." 1>&2
50 return 1
51 fi
52
53 echo "Tests: ${tests[@]}"
54
55 echo "Creating backup at $test_mapping_bak"
56 cp "$test_mapping" "$test_mapping_bak"
57
58 echo "Updating $test_mapping"
59 {
60 echo "$header"
61
62 echo " // DO NOT MODIFY MANUALLY"
63 echo " // Use scripts/$script_name to update it."
64
65 local i=0
66 while (( $i < $num_tests )) ; do
67 local comma=","
68 if (( $i == ($num_tests - 1) )); then
69 comma=""
70 fi
71 echo " {"
72 echo " \"name\": \"${tests[$i]}\","
Makoto Onuki2c66eab2024-10-29 20:32:10 +000073 if is_car "${tests[$i]}"; then
74 echo ' "keywords": ["automotive_code_coverage"],'
75 fi
76
John Wu98346162024-09-26 22:59:40 +000077 echo " \"host\": true"
78 echo " }$comma"
79
80 i=$(( $i + 1 ))
81 done
82
83 echo "$footer"
84 } >"$test_mapping"
85
86 if cmp "$test_mapping_bak" "$test_mapping" ; then
87 echo "No change detecetd."
88 return 0
89 fi
90 echo "Updated $test_mapping"
91
92 # `|| true` is needed because of `set -e`.
93 diff -u "$test_mapping_bak" "$test_mapping" || true
94 return 0
95}
96
97main