blob: 54c928a678a1ffbaf8335122d12d97fb06498121 [file] [log] [blame]
Nicolas Geoffrayd2d62d12015-03-18 11:23:56 +00001#!/bin/bash
2#
3# Copyright (C) 2015 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
Orion Hodson1c5b1ea2020-01-22 15:34:33 +000017# The work does by this script is (mostly) undone by tools/buildbot-teardown-device.sh.
Roland Levillain56049382018-05-23 18:26:22 +010018# Make sure to keep these files in sync.
19
Orion Hodson5697fab2019-11-19 15:01:02 +000020if [ -t 1 ]; then
21 # Color sequences if terminal is a tty.
22 red='\033[0;31m'
23 green='\033[0;32m'
24 yellow='\033[0;33m'
25 nc='\033[0m'
26fi
Nicolas Geoffrayd2d62d12015-03-18 11:23:56 +000027
Martin Stjernholmc71aacb2019-02-18 16:35:44 +000028if [ "$1" = --verbose ]; then
29 verbose=true
30else
31 verbose=false
32fi
33
Roland Levillain56049382018-05-23 18:26:22 +010034# Setup as root, as some actions performed here require it.
Roland Levillain2aab06b2017-03-01 14:14:10 +000035adb root
36adb wait-for-device
37
38echo -e "${green}Date on host${nc}"
39date
40
Nicolas Geoffrayd2d62d12015-03-18 11:23:56 +000041echo -e "${green}Date on device${nc}"
42adb shell date
43
Roland Levillain2aab06b2017-03-01 14:14:10 +000044host_seconds_since_epoch=$(date -u +%s)
45device_seconds_since_epoch=$(adb shell date -u +%s)
46
47abs_time_difference_in_seconds=$(expr $host_seconds_since_epoch - $device_seconds_since_epoch)
48if [ $abs_time_difference_in_seconds -lt 0 ]; then
49 abs_time_difference_in_seconds=$(expr 0 - $abs_time_difference_in_seconds)
50fi
51
52seconds_per_hour=3600
53
Nicolas Geoffrayc2d199b2017-05-22 16:05:06 +010054# Kill logd first, so that when we set the adb buffer size later in this file,
55# it is brought up again.
56echo -e "${green}Killing logd, seen leaking on fugu/N${nc}"
Evgeny Astigeevich1d273602018-09-24 10:55:20 +010057adb shell pkill -9 -U logd logd && echo -e "${green}...logd killed${nc}"
Nicolas Geoffrayc2d199b2017-05-22 16:05:06 +010058
Roland Levillain2aab06b2017-03-01 14:14:10 +000059# Update date on device if the difference with host is more than one hour.
60if [ $abs_time_difference_in_seconds -gt $seconds_per_hour ]; then
61 echo -e "${green}Update date on device${nc}"
62 adb shell date -u @$host_seconds_since_epoch
63fi
64
Nicolas Geoffrayd2d62d12015-03-18 11:23:56 +000065echo -e "${green}Turn off selinux${nc}"
66adb shell setenforce 0
Martin Stjernholmc71aacb2019-02-18 16:35:44 +000067$verbose && adb shell getenforce
Nicolas Geoffrayd2d62d12015-03-18 11:23:56 +000068
Nicolas Geoffray0a38a0e2015-03-25 17:22:34 +000069echo -e "${green}Setting local loopback${nc}"
70adb shell ifconfig lo up
Martin Stjernholmc71aacb2019-02-18 16:35:44 +000071$verbose && adb shell ifconfig
Nicolas Geoffray0a38a0e2015-03-25 17:22:34 +000072
Martin Stjernholmc71aacb2019-02-18 16:35:44 +000073if $verbose; then
74 echo -e "${green}List properties${nc}"
75 adb shell getprop
Nicolas Geoffrayb8703d62015-10-30 11:18:52 +000076
Martin Stjernholmc71aacb2019-02-18 16:35:44 +000077 echo -e "${green}Uptime${nc}"
78 adb shell uptime
Nicolas Geoffrayb8703d62015-10-30 11:18:52 +000079
Martin Stjernholmc71aacb2019-02-18 16:35:44 +000080 echo -e "${green}Battery info${nc}"
81 adb shell dumpsys battery
82fi
Nicolas Geoffray7ea57472016-02-24 09:53:09 +000083
Nicolas Geoffrayff43ade2018-07-19 14:17:50 +010084# Fugu only handles buffer size up to 16MB.
85product_name=$(adb shell getprop ro.build.product)
86
87if [ "x$product_name" = xfugu ]; then
88 buffer_size=16MB
89else
90 buffer_size=32MB
91fi
92
93echo -e "${green}Setting adb buffer size to ${buffer_size}${nc}"
94adb logcat -G ${buffer_size}
Martin Stjernholmc71aacb2019-02-18 16:35:44 +000095$verbose && adb logcat -g
Nicolas Geoffray80d9c852016-03-04 15:28:35 +000096
97echo -e "${green}Removing adb spam filter${nc}"
98adb logcat -P ""
Martin Stjernholmc71aacb2019-02-18 16:35:44 +000099$verbose && adb logcat -p
Nicolas Geoffray80d9c852016-03-04 15:28:35 +0000100
Nicolas Geoffrayb8703d62015-10-30 11:18:52 +0000101echo -e "${green}Kill stalled dalvikvm processes${nc}"
Nicolas Geoffrayfe6f0b62016-03-07 13:33:37 +0000102# 'ps' on M can sometimes hang.
Martin Stjernholmc71aacb2019-02-18 16:35:44 +0000103timeout 2s adb shell "ps" >/dev/null
Nicolas Geoffrayfe6f0b62016-03-07 13:33:37 +0000104if [ $? = 124 ]; then
105 echo -e "${green}Rebooting device to fix 'ps'${nc}"
106 adb reboot
107 adb wait-for-device root
108else
109 processes=$(adb shell "ps" | grep dalvikvm | awk '{print $2}')
110 for i in $processes; do adb shell kill -9 $i; done
111fi
Roland Levillaine4f1c512017-10-30 13:28:28 +0000112
Roland Levillain72f67742019-03-06 15:48:08 +0000113# Chroot environment.
114# ===================
115
Roland Levillaine4f1c512017-10-30 13:28:28 +0000116if [[ -n "$ART_TEST_CHROOT" ]]; then
117 # Prepare the chroot dir.
118 echo -e "${green}Prepare the chroot dir in $ART_TEST_CHROOT${nc}"
119
120 # Check that ART_TEST_CHROOT is correctly defined.
121 [[ "x$ART_TEST_CHROOT" = x/* ]] || { echo "$ART_TEST_CHROOT is not an absolute path"; exit 1; }
122
123 # Create chroot.
124 adb shell mkdir -p "$ART_TEST_CHROOT"
125
126 # Provide property_contexts file(s) in chroot.
127 # This is required to have Android system properties work from the chroot.
128 # Notes:
129 # - In Android N, only '/property_contexts' is expected.
Roland Levillain72f67742019-03-06 15:48:08 +0000130 # - In Android O+, property_context files are expected under /system and /vendor.
131 # (See bionic/libc/bionic/system_properties.cpp or
132 # bionic/libc/system_properties/contexts_split.cpp for more information.)
Roland Levillaine4f1c512017-10-30 13:28:28 +0000133 property_context_files="/property_contexts \
134 /system/etc/selinux/plat_property_contexts \
135 /vendor/etc/selinux/nonplat_property_context \
136 /plat_property_contexts \
137 /nonplat_property_contexts"
138 for f in $property_context_files; do
139 adb shell test -f "$f" \
140 "&&" mkdir -p "$ART_TEST_CHROOT$(dirname $f)" \
141 "&&" cp -f "$f" "$ART_TEST_CHROOT$f"
142 done
143
144 # Create directories required for ART testing in chroot.
145 adb shell mkdir -p "$ART_TEST_CHROOT/tmp"
146 adb shell mkdir -p "$ART_TEST_CHROOT/data/dalvik-cache"
147 adb shell mkdir -p "$ART_TEST_CHROOT/data/local/tmp"
148
149 # Populate /etc in chroot with required files.
150 adb shell mkdir -p "$ART_TEST_CHROOT/system/etc"
Roland Levillain72f67742019-03-06 15:48:08 +0000151 adb shell "cd $ART_TEST_CHROOT && ln -sf system/etc etc"
Roland Levillaine4f1c512017-10-30 13:28:28 +0000152
153 # Provide /proc in chroot.
154 adb shell mkdir -p "$ART_TEST_CHROOT/proc"
155 adb shell mount | grep -q "^proc on $ART_TEST_CHROOT/proc type proc " \
156 || adb shell mount -t proc proc "$ART_TEST_CHROOT/proc"
157
158 # Provide /sys in chroot.
159 adb shell mkdir -p "$ART_TEST_CHROOT/sys"
160 adb shell mount | grep -q "^sysfs on $ART_TEST_CHROOT/sys type sysfs " \
161 || adb shell mount -t sysfs sysfs "$ART_TEST_CHROOT/sys"
162 # Provide /sys/kernel/debug in chroot.
163 adb shell mount | grep -q "^debugfs on $ART_TEST_CHROOT/sys/kernel/debug type debugfs " \
164 || adb shell mount -t debugfs debugfs "$ART_TEST_CHROOT/sys/kernel/debug"
165
166 # Provide /dev in chroot.
167 adb shell mkdir -p "$ART_TEST_CHROOT/dev"
168 adb shell mount | grep -q "^tmpfs on $ART_TEST_CHROOT/dev type tmpfs " \
169 || adb shell mount -o bind /dev "$ART_TEST_CHROOT/dev"
Roland Levillain7b7ea792019-01-08 19:47:50 +0000170
Roland Levillain0f9823e2019-06-18 16:49:24 +0100171 # Create /apex directory in chroot.
Roland Levillain7b7ea792019-01-08 19:47:50 +0000172 adb shell mkdir -p "$ART_TEST_CHROOT/apex"
Roland Levillain15ff34d2020-02-05 19:55:34 +0000173
174 # Create /linkerconfig directory in chroot.
175 adb shell mkdir -p "$ART_TEST_CHROOT/linkerconfig"
Roland Levillaine4f1c512017-10-30 13:28:28 +0000176fi