Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 1 | #!/bin/bash -eu |
| 2 | |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 3 | set -o pipefail |
| 4 | |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 5 | HARDWIRED_MOCK_TOP= |
| 6 | # Uncomment this to be able to view the source tree after a test is run |
| 7 | # HARDWIRED_MOCK_TOP=/tmp/td |
| 8 | |
| 9 | REAL_TOP="$(readlink -f "$(dirname "$0")"/../../..)" |
| 10 | |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 11 | if [[ -n "$HARDWIRED_MOCK_TOP" ]]; then |
Lukacs T. Berki | 686965b | 2021-04-14 16:40:03 +0200 | [diff] [blame] | 12 | MOCK_TOP="$HARDWIRED_MOCK_TOP" |
| 13 | else |
| 14 | MOCK_TOP=$(mktemp -t -d st.XXXXX) |
| 15 | trap cleanup_mock_top EXIT |
| 16 | fi |
| 17 | |
| 18 | WARMED_UP_MOCK_TOP=$(mktemp -t soong_integration_tests_warmup.XXXXXX.tar.gz) |
| 19 | trap 'rm -f "$WARMED_UP_MOCK_TOP"' EXIT |
| 20 | |
| 21 | function warmup_mock_top { |
| 22 | info "Warming up mock top ..." |
| 23 | info "Mock top warmup archive: $WARMED_UP_MOCK_TOP" |
| 24 | cleanup_mock_top |
| 25 | mkdir -p "$MOCK_TOP" |
| 26 | cd "$MOCK_TOP" |
| 27 | |
| 28 | create_mock_soong |
| 29 | run_soong |
| 30 | tar czf "$WARMED_UP_MOCK_TOP" * |
| 31 | } |
| 32 | |
| 33 | function cleanup_mock_top { |
| 34 | cd / |
| 35 | rm -fr "$MOCK_TOP" |
| 36 | } |
| 37 | |
| 38 | function info { |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 39 | echo -e "\e[92;1m[TEST HARNESS INFO]\e[0m" "$*" |
Lukacs T. Berki | 686965b | 2021-04-14 16:40:03 +0200 | [diff] [blame] | 40 | } |
| 41 | |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 42 | function fail { |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 43 | echo -e "\e[91;1mFAILED:\e[0m" "$*" |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 44 | exit 1 |
| 45 | } |
| 46 | |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 47 | function copy_directory { |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 48 | local dir="$1" |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 49 | local -r parent="$(dirname "$dir")" |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 50 | |
| 51 | mkdir -p "$MOCK_TOP/$parent" |
| 52 | cp -R "$REAL_TOP/$dir" "$MOCK_TOP/$parent" |
| 53 | } |
| 54 | |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 55 | function symlink_file { |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 56 | local file="$1" |
| 57 | |
| 58 | mkdir -p "$MOCK_TOP/$(dirname "$file")" |
| 59 | ln -s "$REAL_TOP/$file" "$MOCK_TOP/$file" |
| 60 | } |
| 61 | |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 62 | function symlink_directory { |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 63 | local dir="$1" |
| 64 | |
| 65 | mkdir -p "$MOCK_TOP/$dir" |
| 66 | # We need to symlink the contents of the directory individually instead of |
| 67 | # using one symlink for the whole directory because finder.go doesn't follow |
| 68 | # symlinks when looking for Android.bp files |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 69 | for i in "$REAL_TOP/$dir"/*; do |
| 70 | i=$(basename "$i") |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 71 | local target="$MOCK_TOP/$dir/$i" |
| 72 | local source="$REAL_TOP/$dir/$i" |
| 73 | |
| 74 | if [[ -e "$target" ]]; then |
| 75 | if [[ ! -d "$source" || ! -d "$target" ]]; then |
| 76 | fail "Trying to symlink $dir twice" |
| 77 | fi |
| 78 | else |
| 79 | ln -s "$REAL_TOP/$dir/$i" "$MOCK_TOP/$dir/$i"; |
| 80 | fi |
| 81 | done |
| 82 | } |
| 83 | |
Lukacs T. Berki | 686965b | 2021-04-14 16:40:03 +0200 | [diff] [blame] | 84 | function create_mock_soong { |
Chris Parsons | b6e9690 | 2022-10-31 20:08:45 -0400 | [diff] [blame] | 85 | create_mock_bazel |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 86 | copy_directory build/blueprint |
| 87 | copy_directory build/soong |
Joe Onorato | fa5fc26 | 2022-12-05 15:02:29 -0800 | [diff] [blame] | 88 | copy_directory build/make |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 89 | |
Lukacs T. Berki | e3487c8 | 2022-05-02 10:13:19 +0200 | [diff] [blame] | 90 | symlink_directory prebuilts/sdk |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 91 | symlink_directory prebuilts/go |
| 92 | symlink_directory prebuilts/build-tools |
Liz Kammer | 0940b89 | 2022-03-18 15:55:04 -0400 | [diff] [blame] | 93 | symlink_directory prebuilts/clang/host |
Dan Willemsen | 4591b64 | 2021-05-24 14:24:12 -0700 | [diff] [blame] | 94 | symlink_directory external/go-cmp |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 95 | symlink_directory external/golang-protobuf |
Cole Faust | d9932ad | 2022-03-24 17:27:41 -0700 | [diff] [blame] | 96 | symlink_directory external/starlark-go |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 97 | |
| 98 | touch "$MOCK_TOP/Android.bp" |
Lukacs T. Berki | 686965b | 2021-04-14 16:40:03 +0200 | [diff] [blame] | 99 | } |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 100 | |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 101 | function setup { |
Lukacs T. Berki | 686965b | 2021-04-14 16:40:03 +0200 | [diff] [blame] | 102 | cleanup_mock_top |
| 103 | mkdir -p "$MOCK_TOP" |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 104 | |
Lukacs T. Berki | 686965b | 2021-04-14 16:40:03 +0200 | [diff] [blame] | 105 | echo |
| 106 | echo ---------------------------------------------------------------------------- |
Lukacs T. Berki | 7a51907 | 2021-04-15 18:18:45 +0200 | [diff] [blame] | 107 | info "Running test case \e[96;1m${FUNCNAME[1]}\e[0m" |
Lukacs T. Berki | 686965b | 2021-04-14 16:40:03 +0200 | [diff] [blame] | 108 | cd "$MOCK_TOP" |
| 109 | |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 110 | tar xzf "$WARMED_UP_MOCK_TOP" --warning=no-timestamp |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 111 | } |
| 112 | |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 113 | # shellcheck disable=SC2120 |
| 114 | function run_soong { |
Sam Delmerico | 970b96d | 2022-08-04 14:00:08 -0400 | [diff] [blame] | 115 | USE_RBE=false build/soong/soong_ui.bash --make-mode --skip-ninja --skip-config --soong-only --skip-soong-tests "$@" |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 116 | } |
| 117 | |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 118 | function create_mock_bazel { |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 119 | copy_directory build/bazel |
Yifan Hong | 82799f2 | 2022-06-28 16:25:56 -0700 | [diff] [blame] | 120 | copy_directory build/bazel_common_rules |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 121 | |
Sam Delmerico | eddd3c0 | 2022-12-02 17:31:58 -0500 | [diff] [blame] | 122 | symlink_directory packages/modules/common/build |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 123 | symlink_directory prebuilts/bazel |
Lukacs T. Berki | e3487c8 | 2022-05-02 10:13:19 +0200 | [diff] [blame] | 124 | symlink_directory prebuilts/clang |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 125 | symlink_directory prebuilts/jdk |
Jingwen Chen | 9163225 | 2021-08-10 13:00:33 +0000 | [diff] [blame] | 126 | symlink_directory external/bazel-skylib |
Lukacs T. Berki | e3487c8 | 2022-05-02 10:13:19 +0200 | [diff] [blame] | 127 | symlink_directory external/bazelbuild-rules_android |
Sasha Smundak | 8bea267 | 2022-08-04 13:31:14 -0700 | [diff] [blame] | 128 | symlink_directory external/bazelbuild-rules_license |
Romain Jobredeaux | 0dfe8d3 | 2022-09-06 16:20:09 -0400 | [diff] [blame] | 129 | symlink_directory external/bazelbuild-kotlin-rules |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 130 | |
| 131 | symlink_file WORKSPACE |
Liz Kammer | 09f947d | 2021-05-12 14:51:49 -0400 | [diff] [blame] | 132 | symlink_file BUILD |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 133 | } |
| 134 | |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 135 | function run_bazel { |
Jingwen Chen | d4b1dc8 | 2022-05-12 11:08:03 +0000 | [diff] [blame] | 136 | # Remove the ninja_build output marker file to communicate to buildbot that this is not a regular Ninja build, and its |
| 137 | # output should not be parsed as such. |
| 138 | rm -rf out/ninja_build |
| 139 | |
Joe Onorato | ba29f38 | 2022-10-24 06:38:11 -0700 | [diff] [blame] | 140 | build/bazel/bin/bazel "$@" |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 141 | } |
| 142 | |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 143 | function run_ninja { |
Colin Cross | 34d60c9 | 2021-10-28 16:19:40 -0700 | [diff] [blame] | 144 | build/soong/soong_ui.bash --make-mode --skip-config --soong-only --skip-soong-tests "$@" |
Spandan Das | 0506361 | 2021-06-25 01:39:04 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 147 | info "Starting Soong integration test suite $(basename "$0")" |
Lukacs T. Berki | 686965b | 2021-04-14 16:40:03 +0200 | [diff] [blame] | 148 | info "Mock top: $MOCK_TOP" |
| 149 | |
| 150 | |
| 151 | export ALLOW_MISSING_DEPENDENCIES=true |
Lukacs T. Berki | e3487c8 | 2022-05-02 10:13:19 +0200 | [diff] [blame] | 152 | export ALLOW_BP_UNDER_SYMLINKS=true |
Lukacs T. Berki | 686965b | 2021-04-14 16:40:03 +0200 | [diff] [blame] | 153 | warmup_mock_top |
Usta Shrestha | 572ecec | 2022-12-08 01:29:21 -0500 | [diff] [blame] | 154 | |
| 155 | function scan_and_run_tests { |
| 156 | # find all test_ functions |
| 157 | # NB "declare -F" output is sorted, hence test order is deterministic |
| 158 | readarray -t test_fns < <(declare -F | sed -n -e 's/^declare -f \(test_.*\)$/\1/p') |
| 159 | info "Found ${#test_fns[*]} tests" |
| 160 | if [[ ${#test_fns[*]} -eq 0 ]]; then |
| 161 | fail "No tests found" |
| 162 | fi |
| 163 | for f in ${test_fns[*]}; do |
| 164 | $f |
| 165 | done |
Joe Onorato | fa5fc26 | 2022-12-05 15:02:29 -0800 | [diff] [blame] | 166 | } |