summaryrefslogtreecommitdiff
path: root/experiments/prepare_bazel_test_env/data/static/build/bazel/rules/tf_test_executable.sh.template
blob: f48e4fa7e4509b0f34ca8a7b88258c3299483cc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
#
# Script that handles set up for test execution in a Bazel environment.
# This script sets the PATH, LD_LIBRARY_PATH, TF_PATH, and TF_JAR_DIR
# that the called launcher script uses to execute the test.

BAZEL_BIN_WORK_DIR="$(dirname $0)/$0.runfiles/__main__/"

# Use the directory corresponding to the current module for running, this
# ensures that when Tradefed scans for tests, only the tests
# that were included as a dependency to the rule are referenced.
TESTCASE_RELPATH="{module_path}"

# Ensure that the test is executing from the top of the runfiles dir.
if [[ -d $BAZEL_BIN_WORK_DIR/$TESTCASE_RELPATH ]]
then
    cd $BAZEL_BIN_WORK_DIR || exit 1
fi

# Verify we can find the Tradefed launch script.
ATEST_TRADEFED_LAUNCHER="{tradefed_launcher_module_path}/atest_tradefed.sh"
if ! [[ -f $ATEST_TRADEFED_LAUNCHER ]]
then
    echo "ERROR: Cannot find Tradefed launch script" >&2
    exit 1
fi

# Set the required variables for the environment.
export PATH={adb_path}:$PATH
export LD_LIBRARY_PATH="$TESTCASE_RELPATH/lib:$TESTCASE_RELPATH/lib64:"
export TF_PATH="{tradefed_deps_module_path}/*"
export TF_JAR_DIR="{tradefed_deps_module_path}/"

# Call the test launcher, passing the module name and testcase directory
# and any additional arguments.
exec {launcher_path} $ATEST_TRADEFED_LAUNCHER "{module_name}" "$TESTCASE_RELPATH" "$@"