xref: /aosp_15_r20/tools/asuite/atest/java/atest_tradefed.sh (revision c2e18aaa1096c836b086f94603d04f4eb9cf37f5)
1*c2e18aaaSAndroid Build Coastguard Worker#!/usr/bin/env bash
2*c2e18aaaSAndroid Build Coastguard Worker
3*c2e18aaaSAndroid Build Coastguard Worker# Copyright (C) 2015 The Android Open Source Project
4*c2e18aaaSAndroid Build Coastguard Worker#
5*c2e18aaaSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*c2e18aaaSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*c2e18aaaSAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*c2e18aaaSAndroid Build Coastguard Worker#
9*c2e18aaaSAndroid Build Coastguard Worker#      http://www.apache.org/licenses/LICENSE-2.0
10*c2e18aaaSAndroid Build Coastguard Worker#
11*c2e18aaaSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*c2e18aaaSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*c2e18aaaSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*c2e18aaaSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*c2e18aaaSAndroid Build Coastguard Worker# limitations under the License.
16*c2e18aaaSAndroid Build Coastguard Worker
17*c2e18aaaSAndroid Build Coastguard Worker# A helper script that launches Trade Federation for atest
18*c2e18aaaSAndroid Build Coastguard Workerif [[ -z "${ATEST_HELPER}" ]]; then
19*c2e18aaaSAndroid Build Coastguard Worker    ATEST_HELPER="$(dirname $0)/atest_script_help.sh"
20*c2e18aaaSAndroid Build Coastguard Workerfi
21*c2e18aaaSAndroid Build Coastguard Workersource $ATEST_HELPER
22*c2e18aaaSAndroid Build Coastguard Worker
23*c2e18aaaSAndroid Build Coastguard Worker# TODO b/63295046 (sbasi) - Remove this when LOCAL_JAVA_LIBRARIES includes
24*c2e18aaaSAndroid Build Coastguard Worker# installation.
25*c2e18aaaSAndroid Build Coastguard Worker# Include any host-side dependency jars.
26*c2e18aaaSAndroid Build Coastguard Workerif [[ ! -z "$ANDROID_HOST_OUT" ]]; then
27*c2e18aaaSAndroid Build Coastguard Worker    # TF will load the first test-suite-info.properties in those jar files it loaded.
28*c2e18aaaSAndroid Build Coastguard Worker    # In current cases that only those *ts suite jars have built in that file.
29*c2e18aaaSAndroid Build Coastguard Worker    # If user tested testcases which using those jar files with suite-info properties
30*c2e18aaaSAndroid Build Coastguard Worker    # but change the lunch target to different arch and continue testing other tests without the
31*c2e18aaaSAndroid Build Coastguard Worker    # need of those *ts jars then TF will not testing with below error message:
32*c2e18aaaSAndroid Build Coastguard Worker    # "None of the abi supported by this tests suite build".
33*c2e18aaaSAndroid Build Coastguard Worker    # Create atest-tradefed.jar with test-suite-info.properties and make sure it's priroty is higher
34*c2e18aaaSAndroid Build Coastguard Worker    # then other *ts-tradefed.jar.
35*c2e18aaaSAndroid Build Coastguard Worker    deps="atest-tradefed.jar
36*c2e18aaaSAndroid Build Coastguard Worker          compatibility-host-util.jar
37*c2e18aaaSAndroid Build Coastguard Worker          hamcrest-library.jar
38*c2e18aaaSAndroid Build Coastguard Worker          hosttestlib.jar
39*c2e18aaaSAndroid Build Coastguard Worker          cts-tradefed.jar
40*c2e18aaaSAndroid Build Coastguard Worker          sts-tradefed.jar
41*c2e18aaaSAndroid Build Coastguard Worker          vts-tradefed.jar
42*c2e18aaaSAndroid Build Coastguard Worker          csuite-harness.jar
43*c2e18aaaSAndroid Build Coastguard Worker          tradefed-isolation.jar
44*c2e18aaaSAndroid Build Coastguard Worker          host-libprotobuf-java-full.jar
45*c2e18aaaSAndroid Build Coastguard Worker          cts-dalvik-host-test-runner.jar
46*c2e18aaaSAndroid Build Coastguard Worker          compatibility-tradefed.jar"
47*c2e18aaaSAndroid Build Coastguard Worker    for dep in $deps; do
48*c2e18aaaSAndroid Build Coastguard Worker        if [ -f "$ANDROID_HOST_OUT/framework/$dep" ]; then
49*c2e18aaaSAndroid Build Coastguard Worker          TF_PATH+=":$ANDROID_HOST_OUT/framework/$dep"
50*c2e18aaaSAndroid Build Coastguard Worker        fi
51*c2e18aaaSAndroid Build Coastguard Worker    done
52*c2e18aaaSAndroid Build Coastguard Workerfi
53*c2e18aaaSAndroid Build Coastguard Worker
54*c2e18aaaSAndroid Build Coastguard Worker# Accumulate prebuilt jars as a part of classpath when the configurations are
55*c2e18aaaSAndroid Build Coastguard Worker# packaged into a prebuilt jar (b/192046472)
56*c2e18aaaSAndroid Build Coastguard WorkerTF_CORE_DIR=$ANDROID_BUILD_TOP/tools/tradefederation/core
57*c2e18aaaSAndroid Build Coastguard Workerif [ ! -d $TF_CORE_DIR ]; then
58*c2e18aaaSAndroid Build Coastguard Worker    TF_DIR=$ANDROID_BUILD_TOP/tools/tradefederation/prebuilts/filegroups
59*c2e18aaaSAndroid Build Coastguard Worker    GTF_DIR=$ANDROID_BUILD_TOP/vendor/google_tradefederation/prebuilts/filegroups
60*c2e18aaaSAndroid Build Coastguard Worker    PREBUILT_JARS=$(find $TF_DIR $GTF_DIR -type f -name '*.jar' 2>/dev/null)
61*c2e18aaaSAndroid Build Coastguard Worker    if [ -n "$PREBUILT_JARS" ]; then
62*c2e18aaaSAndroid Build Coastguard Worker        for jar in $PREBUILT_JARS; do
63*c2e18aaaSAndroid Build Coastguard Worker            TF_PATH+=":$jar"
64*c2e18aaaSAndroid Build Coastguard Worker        done
65*c2e18aaaSAndroid Build Coastguard Worker    fi
66*c2e18aaaSAndroid Build Coastguard Workerfi
67*c2e18aaaSAndroid Build Coastguard Worker
68*c2e18aaaSAndroid Build Coastguard Workerif [ "$(uname)" == "Darwin" ]; then
69*c2e18aaaSAndroid Build Coastguard Worker    local_tmp_dir="$ANDROID_HOST_OUT/tmp"
70*c2e18aaaSAndroid Build Coastguard Worker    [[ -f "$local_tmp_dir" ]] || mkdir -p "$local_tmp_dir"
71*c2e18aaaSAndroid Build Coastguard Worker    java_tmp_dir_opt="-Djava.io.tmpdir=$local_tmp_dir"
72*c2e18aaaSAndroid Build Coastguard Workerfi
73*c2e18aaaSAndroid Build Coastguard Worker
74*c2e18aaaSAndroid Build Coastguard Worker# Override the TF classpath with the minimal set of jars that correspond to the
75*c2e18aaaSAndroid Build Coastguard Worker# tests being run. This only happens when the Atest `--minimal-build` flag is
76*c2e18aaaSAndroid Build Coastguard Worker# enabled.
77*c2e18aaaSAndroid Build Coastguard Worker# TODO(b/283352284): Remove unnecessary entries once --minimal-build is the
78*c2e18aaaSAndroid Build Coastguard Worker# default.
79*c2e18aaaSAndroid Build Coastguard Workerif [ -n "${ATEST_HOST_JARS}" ]; then
80*c2e18aaaSAndroid Build Coastguard Worker    echo "Replaced TF_PATH from ${TF_PATH} to ${ATEST_HOST_JARS}"
81*c2e18aaaSAndroid Build Coastguard Worker    TF_PATH=${ATEST_HOST_JARS}
82*c2e18aaaSAndroid Build Coastguard Workerfi
83*c2e18aaaSAndroid Build Coastguard Worker
84*c2e18aaaSAndroid Build Coastguard Worker# Customize TF related settings for ATest local run to align with test runs on
85*c2e18aaaSAndroid Build Coastguard Worker# CI.
86*c2e18aaaSAndroid Build Coastguard Workerextra_settings="
87*c2e18aaaSAndroid Build Coastguard Worker  --test-arg com.android.tradefed.testtype.python.PythonBinaryHostTest:python-options:-vv"
88*c2e18aaaSAndroid Build Coastguard Worker
89*c2e18aaaSAndroid Build Coastguard Worker
90*c2e18aaaSAndroid Build Coastguard Worker# Note: must leave $RDBG_FLAG and $TRADEFED_OPTS unquoted so that they go away when unset
91*c2e18aaaSAndroid Build Coastguard WorkerLOCAL_MODE=1 START_FEATURE_SERVER=1 ${TF_JAVA} $RDBG_FLAG \
92*c2e18aaaSAndroid Build Coastguard Worker    -XX:+HeapDumpOnOutOfMemoryError \
93*c2e18aaaSAndroid Build Coastguard Worker    -XX:-OmitStackTraceInFastThrow \
94*c2e18aaaSAndroid Build Coastguard Worker    $TRADEFED_OPTS \
95*c2e18aaaSAndroid Build Coastguard Worker    -cp "${TF_PATH}" \
96*c2e18aaaSAndroid Build Coastguard Worker    -DTF_JAR_DIR=${TF_JAR_DIR} ${java_tmp_dir_opt} \
97*c2e18aaaSAndroid Build Coastguard Worker    com.android.tradefed.command.CommandRunner "$@" $extra_settings
98