xref: /aosp_15_r20/tools/asuite/atest/bazel/resources/rules/tradefed_test.sh.template (revision c2e18aaa1096c836b086f94603d04f4eb9cf37f5)
1#!/bin/bash
2set -e
3set -x
4
5TEST_MODULE="{module_name}"
6TEST_PATH="{tradefed_test_dir}"
7ATEST_TF_LAUNCHER="{atest_tradefed_launcher}"
8ATEST_HELPER="{atest_helper}"
9SHARED_LIB_DIRS="{shared_lib_dirs}"
10PATH_ADDITIONS="{path_additions}"
11TRADEFED_CLASSPATH="{tradefed_classpath}"
12RESULT_REPORTERS_CONFIG_FILE="{result_reporters_config_file}"
13ATEST_JAVA_HOME="{atest_java_home}"
14read -a ADDITIONAL_TRADEFED_OPTIONS <<< "{additional_tradefed_options}"
15
16# Export variables expected by the Atest launcher script.
17export LD_LIBRARY_PATH="${SHARED_LIB_DIRS}"
18export TF_PATH="${TRADEFED_CLASSPATH}"
19export PATH="${PATH_ADDITIONS}:${PATH}"
20export ATEST_HELPER="${ATEST_HELPER}"
21export JAVA_HOME="${ATEST_JAVA_HOME}"
22
23exit_code_file="$(mktemp /tmp/tf-exec-XXXXXXXXXX)"
24
25"${ATEST_TF_LAUNCHER}" template/atest_local_min \
26    --template:map test=atest \
27    --template:map reporters="${RESULT_REPORTERS_CONFIG_FILE}" \
28    --tests-dir "${TEST_PATH}" \
29    --no-enable-granular-attempts \
30    --no-early-device-release \
31    --include-filter "${TEST_MODULE}" \
32    --skip-loading-config-jar \
33    --log-level-display VERBOSE \
34    --log-level VERBOSE \
35    "${ADDITIONAL_TRADEFED_OPTIONS[@]}" \
36    --bazel-exit-code-result-reporter:file=${exit_code_file} \
37    --bazel-xml-result-reporter:file=${XML_OUTPUT_FILE} \
38    --proto-output-file="${TEST_UNDECLARED_OUTPUTS_DIR}/proto-results" \
39    --use-delimited-api=true \
40    --log-file-path="${TEST_UNDECLARED_OUTPUTS_DIR}" \
41    --compress-files=false \
42    "$@"
43
44# Use the TF exit code if it terminates abnormally.
45tf_exit=$?
46if [ ${tf_exit} -ne 0 ]
47then
48     echo "Tradefed command failed with exit code ${tf_exit}"
49     exit ${tf_exit}
50fi
51
52# Set the exit code based on the exit code in the reporter-generated file.
53exit_code=$(<${exit_code_file})
54if [ $? -ne 0 ]
55then
56  echo "Could not read exit code file: ${exit_code_file}"
57  exit 36
58fi
59
60if [ ${exit_code} -ne 0 ]
61then
62  echo "Test failed with exit code ${exit_code}"
63  exit ${exit_code}
64fi
65