aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/android/android_instrumentation_test_template.txt
blob: ab1cace19a33b7593e30f0855ac57beca01411ea (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash --posix
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eux

# Unset TESTBRIDGE_TEST_ONLY environment variable set by Bazel's --test_filter
# flag so that JUnit3 doesn't filter out the Android test suite class. Instead,
# forward this variable as a Java flag with the same name.
if [ -z "${TESTBRIDGE_TEST_ONLY+1}" ]; then
  ANDROID_TESTBRIDGE_TEST_ONLY=""
else
  ANDROID_TESTBRIDGE_TEST_ONLY=${TESTBRIDGE_TEST_ONLY}
  unset TESTBRIDGE_TEST_ONLY
fi

function join_paths() {
  local base_dir=$1
  local sep=$2
  shift 2
  local paths=$@

  local result=""
  for path in $paths
  do
    result=${base_dir}/${path}${sep}${result}
  done
  echo ${result}
}

test_label="%test_label%"
test_entry_point="%test_entry_point%"
WORKSPACE_DIR="${TEST_SRCDIR}/%workspace%"
adb="${WORKSPACE_DIR}/%adb%"
aapt="${WORKSPACE_DIR}/%aapt%"
device_script="${WORKSPACE_DIR}/%device_script%"

data_deps="%data_deps%"
data_deps=$(join_paths ${WORKSPACE_DIR} "," ${data_deps})

device_broker_type="%device_broker_type%"

target_apk="%target_apk%"

instrumentation_apk="%instrumentation_apk%"

support_apks="%support_apks%"
support_apks=$(join_paths ${WORKSPACE_DIR} "," ${support_apks})

apks_to_install="${support_apks}${target_apk},${instrumentation_apk}"

declare -A device_script_fixtures=( %device_script_fixtures% )

host_service_fixture="%host_service_fixture%"
host_service_fixture_services="%host_service_fixture_services%"

test_suite_property_name='%test_suite_property_name%'

# Bazel-only test arguments for the device broker
bazel_only_argv=$(cat <<END
--install_test_services=true
END
)

argv=$(cat <<END
--aapt=${aapt} \
--adb=${adb} \
--device_broker_type=${device_broker_type} \
--device_script=${device_script} \
--data_deps=${data_deps} \
--test_label=${test_label} \
--apks_to_install=${apks_to_install} \
--fixture_scripts=$(printf "%s," "${!device_script_fixtures[@]}") \
--hermetic_server_script=${host_service_fixture} \
--hermetic_servers=${host_service_fixture_services} \
--data_deps=$(printf "%s," "${!device_script_fixtures[@]}") \
--test_filter=${ANDROID_TESTBRIDGE_TEST_ONLY} \
$@
END
)

# We pass in $argv via two channels here:
# 1) regular arguments: parsed normally by internal test entry point.
# 2) --jvm_flag: external AndroidDeviceTestSuite doesn't parse the argvs if
# passed in regularly, so we pass them in via a JVM flag hack and parse them
# at the AndroidDeviceTestSuite constructor.
$test_entry_point \
    --wrapper_script_flag=--jvm_flag=-D$test_suite_property_name=com.google.android.apps.common.testing.suite.AndroidDeviceTestSuite \
    --wrapper_script_flag=--jvm_flag=-Dargv="$bazel_only_argv $argv" \
    $argv