1#!/usr/bin/env bash 2 3# Copyright (C) 2020 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17set -e 18 19if [ $# != 1 ]; then 20 echo "Usage: golden_test.sh [check|update]" 21fi 22 23function _golden_test() { 24 local update=0 25 case $1 in 26 check) 27 update=0 28 ;; 29 update) 30 update=1 31 ;; 32 *) 33 echo "Argument must be 'check' or 'update'" 34 exit 1 35 ;; 36 esac 37 38 # warning: this list must be kept in sync with system/tools/aidl/Android.bp 39 modules=( 40 "aidl-test-interface-cpp-source" 41 "aidl-test-interface-java-source" 42 "aidl-test-versioned-interface-V1-cpp-source" 43 "aidl-test-versioned-interface-V1-java-source" 44 "aidl-test-versioned-interface-V1-ndk-source" 45 "aidl-test-versioned-interface-V1-rust-source" 46 "aidl-test-interface-ndk-source" 47 "aidl-test-interface-rust-source" 48 "aidl_test_loggable_interface-cpp-source" 49 "aidl_test_loggable_interface-java-source" 50 "aidl_test_loggable_interface-ndk-source" 51 "aidl-test-interface-permission-java-source" 52 "aidl-test-fixedsizearray-cpp-source" 53 "aidl-test-fixedsizearray-java-source" 54 "aidl-test-fixedsizearray-ndk-source" 55 "aidl-test-fixedsizearray-rust-source" 56 "aidl-test-interface-cpp-analyzer-source" 57 ) 58 59 local root="." 60 if [ "$ANDROID_BUILD_TOP" != "" ]; then 61 root="$ANDROID_BUILD_TOP" 62 fi 63 64 if [ "$update" = 1 ]; then 65 "$root"/build/soong/soong_ui.bash --make-mode \ 66 $(for i in "${modules[@]}"; do 67 echo "out/soong/.intermediates/system/tools/aidl/$i/timestamp" 68 done) 69 fi 70 71 local e=0 72 for module in "${modules[@]}"; do 73 local built="$root/out/soong/.intermediates/system/tools/aidl/$module/" 74 local golden="$root/system/tools/aidl/tests/golden_output/$module/" 75 76 if [ "$update" = 1 ]; then 77 rm -rf "$golden" 78 mkdir -p "$golden" 79 cp -r "$built/gen" "$golden" 80 else 81 diff -rN "$built/gen" "$golden/gen" || e=1 82 fi 83 done 84 85 if [ "$e" = 1 ]; then 86 echo "ERROR: The AIDL compiler is outputting files in an unknown way." 87 echo "ERROR: to accept these changes, please run:" 88 echo "ERROR: \$ANDROID_BUILD_TOP/system/tools/aidl/tests/golden_test.sh update" 89 exit 1 90 else 91 if [ "$update" = 1 ]; then 92 echo "UPDATE GOLDEN TEST SUCCESS" 93 fi 94 fi 95} 96 97_golden_test "$@" 98