1#!/usr/bin/env bash
2
3# Copyright (C) 2023 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
17# This script is dedicated to build the atest integration test in build server.
18# To run the test locally, it's recommended to invoke the test via
19# `atest atest_integration_tests` or `python atest_integration_tests.py`.
20# For usage examples please run `python atest_integration_tests.py --help`.
21
22set -eo pipefail
23set -x
24
25# Legacy support for the deprecated argument --artifacts_dir and directory name
26for ((i=1; i<=$#; i++)); do
27  arg="${@:$i:1}"
28  case "$arg" in
29    --artifacts_dir)
30      export SNAPSHOT_STORAGE_TAR_PATH="${@:$i+1:1}"/atest_integration_tests.tar
31      i=$((i+1))
32      ;;
33    *)
34      filtered_args+=("$arg")
35      ;;
36  esac
37done
38
39if [ -n "${DIST_DIR}" ] ; then
40  export SNAPSHOT_STORAGE_TAR_PATH=${DIST_DIR}/atest_integration_tests.tar
41fi
42
43function get_build_var()
44{
45  (${PWD}/build/soong/soong_ui.bash --dumpvar-mode --abs $1)
46}
47
48if [ ! -n "${ANDROID_BUILD_TOP}" ] ; then
49  export ANDROID_BUILD_TOP=${PWD}
50fi
51
52# Uncomment the following if verifying locally without running envsetup
53# if [ ! -n "${TARGET_PRODUCT}" ] || [ ! -n "${TARGET_BUILD_VARIANT}" ] ; then
54#   export \
55#     TARGET_PRODUCT=aosp_x86_64 \
56#     TARGET_BUILD_VARIANT=userdebug \
57#     TARGET_RELEASE="trunk_staging"
58# fi
59
60# ANDROID_BUILD_TOP is deprecated, so don't use it throughout the script.
61# But if someone sets it, we'll respect it.
62cd ${ANDROID_BUILD_TOP:-.}
63
64if [ ! -n "${ANDROID_PRODUCT_OUT}" ] ; then
65  export ANDROID_PRODUCT_OUT=$(get_build_var PRODUCT_OUT)
66fi
67
68if [ ! -n "${OUT}" ] ; then
69  export OUT=$ANDROID_PRODUCT_OUT
70fi
71
72if [ ! -n "${ANDROID_HOST_OUT}" ] ; then
73  export ANDROID_HOST_OUT=$(get_build_var HOST_OUT)
74fi
75
76if [ ! -n "${ANDROID_TARGET_OUT_TESTCASES}" ] ; then
77  export ANDROID_TARGET_OUT_TESTCASES=$(get_build_var TARGET_OUT_TESTCASES)
78fi
79
80if [ ! -n "${HOST_OUT_TESTCASES}" ] ; then
81  export HOST_OUT_TESTCASES=$(get_build_var HOST_OUT_TESTCASES)
82  export ANDROID_HOST_OUT_TESTCASES=$HOST_OUT_TESTCASES
83fi
84
85if [ ! -n "${ANDROID_JAVA_HOME}" ] ; then
86  export ANDROID_JAVA_HOME=$(get_build_var ANDROID_JAVA_HOME)
87  export JAVA_HOME=$(get_build_var JAVA_HOME)
88fi
89
90export REMOTE_AVD=true
91
92# Use the versioned Python binaries in prebuilts/ for a reproducible
93# build with minimal reliance on host tools. Add build/bazel/bin to PATH since
94# atest needs 'b'
95export PATH=${PWD}/prebuilts/build-tools/path/linux-x86:${PWD}/build/bazel/bin:${PWD}/out/host/linux-x86/bin/:${PATH}
96
97# Use the versioned Java binaries in prebuilds/ for a reproducible
98# build with minimal reliance on host tools.
99export PATH=${ANDROID_JAVA_HOME}/bin:${PATH}
100
101python3 tools/asuite/atest/integration_tests/atest_integration_tests.py "${filtered_args[@]}" --build --tar_snapshot