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