xref: /aosp_15_r20/frameworks/base/tools/systemfeatures/tests/golden_test.sh (revision d57664e9bc4670b3ecf6748a746a57c557b6bc9e)
1#!/usr/bin/env bash
2
3# Copyright (C) 2024 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
19GEN_DIR="tests/gen"
20GOLDEN_DIR="tests/golden"
21
22if [[ $(basename $0) == "golden_test.sh" ]]; then
23  # We're running via command-line, so we need to:
24  #   1) manually update generated srcs
25  #   2) use absolute paths
26  if [ -z $ANDROID_BUILD_TOP ]; then
27    echo "You need to source and lunch before you can use this script directly."
28    exit 1
29  fi
30  GEN_DIR="$ANDROID_BUILD_TOP/out/soong/.intermediates/frameworks/base/tools/systemfeatures/systemfeatures-gen-tests-golden-srcs/gen/$GEN_DIR"
31  GOLDEN_DIR="$ANDROID_BUILD_TOP/frameworks/base/tools/systemfeatures/$GOLDEN_DIR"
32  rm -rf "$GEN_DIR"
33  "$ANDROID_BUILD_TOP"/build/soong/soong_ui.bash --make-mode systemfeatures-gen-tests-golden-srcs
34fi
35
36if [[ "$1" == "--update" ]]; then
37  rm -rf "$GOLDEN_DIR"
38  cp -R "$GEN_DIR" "$GOLDEN_DIR"
39  echo "Updated golden test files."
40else
41  echo "Running diff from test output against golden test files..."
42  if diff -ruN "$GOLDEN_DIR" "$GEN_DIR" ; then
43    echo "No changes."
44  else
45    echo
46    echo "----------------------------------------------------------------------------------------"
47    echo "If changes look OK, run:"
48    echo "  \$ANDROID_BUILD_TOP/frameworks/base/tools/systemfeatures/tests/golden_test.sh --update"
49    echo "----------------------------------------------------------------------------------------"
50    exit 1
51  fi
52fi
53