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# A script to test the end-to-end flow of atest on the Android CI.
18
19set -euo pipefail
20set -x
21
22function get_build_var()
23{
24  (${PWD}/build/soong/soong_ui.bash --dumpvar-mode --abs $1)
25}
26
27if [ ! -n "${ANDROID_BUILD_TOP}" ] ; then
28  export ANDROID_BUILD_TOP=${PWD}
29fi
30
31if [ ! -n "${TARGET_PRODUCT}" ] || [ ! -n "${TARGET_BUILD_VARIANT}" ] ; then
32  export \
33    TARGET_PRODUCT=aosp_x86_64 \
34    TARGET_BUILD_VARIANT=userdebug
35fi
36
37out=$(get_build_var PRODUCT_OUT)
38
39# ANDROID_BUILD_TOP is deprecated, so don't use it throughout the script.
40# But if someone sets it, we'll respect it.
41cd ${ANDROID_BUILD_TOP:-.}
42
43# Use the versioned Python binaries in prebuilts/ for a reproducible
44# build with minimal reliance on host tools.
45export PATH=${PWD}/prebuilts/build-tools/path/linux-x86:${PATH}
46
47export \
48  ANDROID_PRODUCT_OUT=${out} \
49  OUT=${out} \
50  ANDROID_HOST_OUT=$(get_build_var HOST_OUT) \
51  ANDROID_TARGET_OUT_TESTCASES=$(get_build_var TARGET_OUT_TESTCASES)
52
53build/soong/soong_ui.bash --make-mode atest --skip-soong-tests
54
55${OUT_DIR}/host/linux-x86/bin/atest-dev --host atest_unittests
56