1#!/bin/bash 2set -e 3set -x 4 5TEST_MODULE="{module_name}" 6TEST_PATH="{tradefed_tests_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}" 13read -a ADDITIONAL_TRADEFED_OPTIONS <<< "{additional_tradefed_options}" 14 15# Export variables expected by the Atest launcher script. 16export LD_LIBRARY_PATH="${SHARED_LIB_DIRS}" 17export TF_PATH="${TRADEFED_CLASSPATH}" 18export PATH="${PATH_ADDITIONS}:${PATH}" 19export ATEST_HELPER="${ATEST_HELPER}" 20 21# Prepend the TF_JAVA_HOME environment variable to the path to ensure that all Java invocations 22# throughout the test execution flow use the same version. 23if [ ! -z "${TF_JAVA_HOME}" ]; then 24 export PATH="${TF_JAVA_HOME}/bin:${PATH}" 25fi 26 27exit_code_file="$(mktemp /tmp/tf-exec-XXXXXXXXXX)" 28 29"${ATEST_TF_LAUNCHER}" template/atest_local_min \ 30 --template:map test=atest \ 31 --template:map reporters="${RESULT_REPORTERS_CONFIG_FILE}" \ 32 --tests-dir "${TEST_PATH}" \ 33 --logcat-on-failure \ 34 --no-enable-granular-attempts \ 35 --no-early-device-release \ 36 --include-filter "${TEST_MODULE}" \ 37 --skip-loading-config-jar \ 38 --log-level-display VERBOSE \ 39 --log-level VERBOSE \ 40 "${ADDITIONAL_TRADEFED_OPTIONS[@]}" \ 41 --bazel-exit-code-result-reporter:file=${exit_code_file} \ 42 --bazel-xml-result-reporter:file=${XML_OUTPUT_FILE} \ 43 "$@" 44 45# Use the TF exit code if it terminates abnormally. 46tf_exit=$? 47if [ ${tf_exit} -ne 0 ] 48then 49 echo "Tradefed command failed with exit code ${tf_exit}" 50 exit ${tf_exit} 51fi 52 53# Set the exit code based on the exit code in the reporter-generated file. 54exit_code=$(<${exit_code_file}) 55if [ $? -ne 0 ] 56then 57 echo "Could not read exit code file: ${exit_code_file}" 58 exit 36 59fi 60 61if [ ${exit_code} -ne 0 ] 62then 63 echo "Test failed with exit code ${exit_code}" 64 exit ${exit_code} 65fi 66