• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /bin/bash
2#
3# Copyright (C) 2018 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Push ART artifacts and its dependencies to a chroot directory for on-device testing.
18
19set -e
20
21. "$(dirname $0)/buildbot-utils.sh"
22
23if [[ -z "$ART_TEST_ON_VM" ]]; then
24  # Setup as root, as some actions performed here require it.
25  adb root
26  adb wait-for-device
27fi
28
29if [[ -z "$ANDROID_BUILD_TOP" ]]; then
30  msgfatal 'ANDROID_BUILD_TOP environment variable is empty; did you forget to run `lunch`?'
31elif [[ -z "$ANDROID_PRODUCT_OUT" ]]; then
32  msgfatal 'ANDROID_PRODUCT_OUT environment variable is empty; did you forget to run `lunch`?'
33elif [[ -z "$ART_TEST_CHROOT" ]]; then
34  msgfatal 'ART_TEST_CHROOT environment variable is empty; ' \
35      'please set it before running this script.'
36fi
37
38# Sync relevant product directories
39# ---------------------------------
40
41(
42  cd $ANDROID_PRODUCT_OUT
43  for dir in system/* linkerconfig data; do
44    [ -d $dir ] || continue
45    if [ $dir == system/apex ]; then
46      # We sync the APEXes later.
47      continue
48    fi
49    msginfo "Syncing $dir directory..."
50    if [[ -n "$ART_TEST_ON_VM" ]]; then
51      $ART_RSYNC_CMD -R $dir "$ART_TEST_SSH_USER@$ART_TEST_SSH_HOST:$ART_TEST_CHROOT"
52    else
53      adb shell mkdir -p "$ART_TEST_CHROOT/$dir"
54      adb push $dir "$ART_TEST_CHROOT/$(dirname $dir)"
55    fi
56  done
57)
58
59# Overwrite the default public.libraries.txt file with a smaller one that
60# contains only the public libraries pushed to the chroot directory.
61if [[ -n "$ART_TEST_ON_VM" ]]; then
62  $ART_RSYNC_CMD "$ANDROID_BUILD_TOP/art/tools/public.libraries.buildbot.txt" \
63    "$ART_TEST_SSH_USER@$ART_TEST_SSH_HOST:$ART_TEST_CHROOT/system/etc/public.libraries.txt"
64else
65  adb push "$ANDROID_BUILD_TOP/art/tools/public.libraries.buildbot.txt" \
66    "$ART_TEST_CHROOT/system/etc/public.libraries.txt"
67fi
68
69# Create the framework directory if it doesn't exist. Some gtests need it.
70if [[ -n "$ART_TEST_ON_VM" ]]; then
71  $ART_SSH_CMD "$ART_CHROOT_CMD mkdir -p $ART_TEST_CHROOT/system/framework"
72else
73  adb shell mkdir -p "$ART_TEST_CHROOT/system/framework"
74fi
75
76# APEX packages activation.
77# -------------------------
78
79if [[ -n "$ART_TEST_ON_VM" ]]; then
80  $ART_SSH_CMD "$ART_CHROOT_CMD mkdir -p $ART_TEST_CHROOT/apex"
81else
82  adb shell mkdir -p "$ART_TEST_CHROOT/apex"
83fi
84
85# Manually "activate" the flattened APEX $1 by syncing it to /apex/$2 in the
86# chroot. $2 defaults to $1.
87activate_apex() {
88  local src_apex=${1}
89  local dst_apex=${2:-${src_apex}}
90
91  # Unpack the .apex or .capex file in the product directory, but if we already
92  # see a directory we assume buildbot-build.sh has already done it for us and
93  # just use it.
94  src_apex_path=$ANDROID_PRODUCT_OUT/system/apex/${src_apex}
95  if [ ! -d $src_apex_path ]; then
96    unset src_apex_file
97    if [ -f "${src_apex_path}.apex" ]; then
98      src_apex_file="${src_apex_path}.apex"
99    elif [ -f "${src_apex_path}.capex" ]; then
100      src_apex_file="${src_apex_path}.capex"
101    fi
102    if [ -z "${src_apex_file}" ]; then
103      msgerror "Failed to find .apex or .capex file to extract for ${src_apex_path}"
104      exit 1
105    fi
106    msginfo "Extracting APEX ${src_apex_file}..."
107    mkdir -p $src_apex_path
108    $ANDROID_HOST_OUT/bin/deapexer --debugfs_path $ANDROID_HOST_OUT/bin/debugfs_static \
109      --fsckerofs_path $ANDROID_HOST_OUT/bin/fsck.erofs \
110      --blkid_path $ANDROID_HOST_OUT/bin/blkid_static \
111      extract ${src_apex_file} $src_apex_path
112  fi
113
114  msginfo "Activating APEX ${src_apex} as ${dst_apex}..."
115  if [[ -n "$ART_TEST_ON_VM" ]]; then
116    $ART_RSYNC_CMD $src_apex_path/* \
117      "$ART_TEST_SSH_USER@$ART_TEST_SSH_HOST:$ART_TEST_CHROOT/apex/${dst_apex}"
118  else
119    adb shell rm -rf "$ART_TEST_CHROOT/apex/${dst_apex}"
120    adb push $src_apex_path "$ART_TEST_CHROOT/apex/${dst_apex}"
121  fi
122}
123
124# "Activate" the required APEX modules.
125activate_apex com.android.art.testing com.android.art
126activate_apex com.android.i18n
127activate_apex com.android.runtime
128activate_apex com.android.tzdata
129activate_apex com.android.conscrypt
130activate_apex com.android.os.statsd
131
132if [[ "$TARGET_ARCH" = "riscv64" ]]; then
133  true # Skip boot image generation for RISC-V; it's not supported.
134else
135  # Generate primary boot images on device for testing.
136  for b in {32,64}; do
137    basename="generate-boot-image$b"
138    bin_on_host="$ANDROID_PRODUCT_OUT/system/bin/$basename"
139    bin_on_device="/data/local/tmp/$basename"
140    output_dir="/system/framework/art_boot_images"
141    if [ -f $bin_on_host ]; then
142      msginfo "Generating the primary boot image ($b-bit)..."
143      if [[ -n "$ART_TEST_ON_VM" ]]; then
144        $ART_RSYNC_CMD "$bin_on_host" \
145          "$ART_TEST_SSH_USER@$ART_TEST_SSH_HOST:$ART_TEST_CHROOT$bin_on_device"
146        $ART_SSH_CMD "mkdir -p $ART_TEST_CHROOT$output_dir"
147      else
148        adb push "$bin_on_host" "$ART_TEST_CHROOT$bin_on_device"
149        adb shell mkdir -p "$ART_TEST_CHROOT$output_dir"
150      fi
151      # `compiler-filter=speed-profile` is required because OatDumpTest checks the compiled code in
152      # the boot image.
153      if [[ -n "$ART_TEST_ON_VM" ]]; then
154        $ART_SSH_CMD \
155          "$ART_CHROOT_CMD $bin_on_device --output-dir=$output_dir --compiler-filter=speed-profile"
156      else
157        adb shell chroot "$ART_TEST_CHROOT" \
158          "$bin_on_device" --output-dir=$output_dir --compiler-filter=speed-profile
159      fi
160    fi
161  done
162fi
163