blob: e478b50cc2b903dc14336e0d8a4bc900654f1f14 [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
26main() {
27 local script_name="${0##*/}"
28 local script_dir="${0%/*}"
29 local test_mapping="$script_dir/../TEST_MAPPING"
30 local test_mapping_bak="$script_dir/../TEST_MAPPING.bak"
31
32 local header="$(sed -ne '1,/AUTO-GENERATED-START/p' "$test_mapping")"
33 local footer="$(sed -ne '/AUTO-GENERATED-END/,$p' "$test_mapping")"
34
35 echo "Getting all tests"
36 local tests=( $("$script_dir/list-ravenwood-tests.sh" | grep -vP "$EXEMPT") )
37
38 local num_tests="${#tests[@]}"
39
40 if (( $num_tests == 0 )) ; then
41 echo "Something went wrong. No ravenwood tests detected." 1>&2
42 return 1
43 fi
44
45 echo "Tests: ${tests[@]}"
46
47 echo "Creating backup at $test_mapping_bak"
48 cp "$test_mapping" "$test_mapping_bak"
49
50 echo "Updating $test_mapping"
51 {
52 echo "$header"
53
54 echo " // DO NOT MODIFY MANUALLY"
55 echo " // Use scripts/$script_name to update it."
56
57 local i=0
58 while (( $i < $num_tests )) ; do
59 local comma=","
60 if (( $i == ($num_tests - 1) )); then
61 comma=""
62 fi
63 echo " {"
64 echo " \"name\": \"${tests[$i]}\","
65 echo " \"host\": true"
66 echo " }$comma"
67
68 i=$(( $i + 1 ))
69 done
70
71 echo "$footer"
72 } >"$test_mapping"
73
74 if cmp "$test_mapping_bak" "$test_mapping" ; then
75 echo "No change detecetd."
76 return 0
77 fi
78 echo "Updated $test_mapping"
79
80 # `|| true` is needed because of `set -e`.
81 diff -u "$test_mapping_bak" "$test_mapping" || true
82 return 0
83}
84
85main