blob: 1359092e3a5725b7a30919774d38c3ec5d0f1f8f [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
Roland Levillain56049382018-05-23 18:26:22 +010017# The work does by this script is (mostly) undone by tools/teardown-buildbot-device.sh.
18# Make sure to keep these files in sync.
19
Nicolas Geoffrayd2d62d12015-03-18 11:23:56 +000020green='\033[0;32m'
21nc='\033[0m'
22
Martin Stjernholmc71aacb2019-02-18 16:35:44 +000023if [ "$1" = --verbose ]; then
24 verbose=true
25else
26 verbose=false
27fi
28
Roland Levillain56049382018-05-23 18:26:22 +010029# Setup as root, as some actions performed here require it.
Roland Levillain2aab06b2017-03-01 14:14:10 +000030adb root
31adb wait-for-device
32
33echo -e "${green}Date on host${nc}"
34date
35
Nicolas Geoffrayd2d62d12015-03-18 11:23:56 +000036echo -e "${green}Date on device${nc}"
37adb shell date
38
Roland Levillain2aab06b2017-03-01 14:14:10 +000039host_seconds_since_epoch=$(date -u +%s)
40device_seconds_since_epoch=$(adb shell date -u +%s)
41
42abs_time_difference_in_seconds=$(expr $host_seconds_since_epoch - $device_seconds_since_epoch)
43if [ $abs_time_difference_in_seconds -lt 0 ]; then
44 abs_time_difference_in_seconds=$(expr 0 - $abs_time_difference_in_seconds)
45fi
46
47seconds_per_hour=3600
48
Nicolas Geoffrayc2d199b2017-05-22 16:05:06 +010049# Kill logd first, so that when we set the adb buffer size later in this file,
50# it is brought up again.
51echo -e "${green}Killing logd, seen leaking on fugu/N${nc}"
Evgeny Astigeevich1d273602018-09-24 10:55:20 +010052adb shell pkill -9 -U logd logd && echo -e "${green}...logd killed${nc}"
Nicolas Geoffrayc2d199b2017-05-22 16:05:06 +010053
Roland Levillain2aab06b2017-03-01 14:14:10 +000054# Update date on device if the difference with host is more than one hour.
55if [ $abs_time_difference_in_seconds -gt $seconds_per_hour ]; then
56 echo -e "${green}Update date on device${nc}"
57 adb shell date -u @$host_seconds_since_epoch
58fi
59
Nicolas Geoffrayd2d62d12015-03-18 11:23:56 +000060echo -e "${green}Turn off selinux${nc}"
61adb shell setenforce 0
Martin Stjernholmc71aacb2019-02-18 16:35:44 +000062$verbose && adb shell getenforce
Nicolas Geoffrayd2d62d12015-03-18 11:23:56 +000063
Nicolas Geoffray0a38a0e2015-03-25 17:22:34 +000064echo -e "${green}Setting local loopback${nc}"
65adb shell ifconfig lo up
Martin Stjernholmc71aacb2019-02-18 16:35:44 +000066$verbose && adb shell ifconfig
Nicolas Geoffray0a38a0e2015-03-25 17:22:34 +000067
Roland Levillain30d26962018-03-29 19:36:29 +010068# Ensure netd is running, as otherwise the logcat would be spammed
69# with the following messages on devices running Android O:
Roland Levillain6f7d8b72018-03-15 15:45:00 +000070#
Roland Levillain30d26962018-03-29 19:36:29 +010071# E NetdConnector: Communications error: java.io.IOException: No such file or directory
72# E mDnsConnector: Communications error: java.io.IOException: No such file or directory
Roland Levillain6f7d8b72018-03-15 15:45:00 +000073#
Roland Levillain30d26962018-03-29 19:36:29 +010074# Netd was initially disabled as an attempt to solve issues with
75# network-related libcore and JDWP tests failing on devices running
76# Android O (MR1) (see b/74725685). These tests are currently
77# disabled. When a better solution has been found, we should remove
78# the following lines.
79echo -e "${green}Turning on netd${nc}"
80adb shell start netd
Martin Stjernholmc71aacb2019-02-18 16:35:44 +000081$verbose && adb shell getprop init.svc.netd
Roland Levillain6f7d8b72018-03-15 15:45:00 +000082
Martin Stjernholmc71aacb2019-02-18 16:35:44 +000083if $verbose; then
84 echo -e "${green}List properties${nc}"
85 adb shell getprop
Nicolas Geoffrayb8703d62015-10-30 11:18:52 +000086
Martin Stjernholmc71aacb2019-02-18 16:35:44 +000087 echo -e "${green}Uptime${nc}"
88 adb shell uptime
Nicolas Geoffrayb8703d62015-10-30 11:18:52 +000089
Martin Stjernholmc71aacb2019-02-18 16:35:44 +000090 echo -e "${green}Battery info${nc}"
91 adb shell dumpsys battery
92fi
Nicolas Geoffray7ea57472016-02-24 09:53:09 +000093
Nicolas Geoffrayff43ade2018-07-19 14:17:50 +010094# Fugu only handles buffer size up to 16MB.
95product_name=$(adb shell getprop ro.build.product)
96
97if [ "x$product_name" = xfugu ]; then
98 buffer_size=16MB
99else
100 buffer_size=32MB
101fi
102
103echo -e "${green}Setting adb buffer size to ${buffer_size}${nc}"
104adb logcat -G ${buffer_size}
Martin Stjernholmc71aacb2019-02-18 16:35:44 +0000105$verbose && adb logcat -g
Nicolas Geoffray80d9c852016-03-04 15:28:35 +0000106
107echo -e "${green}Removing adb spam filter${nc}"
108adb logcat -P ""
Martin Stjernholmc71aacb2019-02-18 16:35:44 +0000109$verbose && adb logcat -p
Nicolas Geoffray80d9c852016-03-04 15:28:35 +0000110
Nicolas Geoffrayb8703d62015-10-30 11:18:52 +0000111echo -e "${green}Kill stalled dalvikvm processes${nc}"
Nicolas Geoffrayfe6f0b62016-03-07 13:33:37 +0000112# 'ps' on M can sometimes hang.
Martin Stjernholmc71aacb2019-02-18 16:35:44 +0000113timeout 2s adb shell "ps" >/dev/null
Nicolas Geoffrayfe6f0b62016-03-07 13:33:37 +0000114if [ $? = 124 ]; then
115 echo -e "${green}Rebooting device to fix 'ps'${nc}"
116 adb reboot
117 adb wait-for-device root
118else
119 processes=$(adb shell "ps" | grep dalvikvm | awk '{print $2}')
120 for i in $processes; do adb shell kill -9 $i; done
121fi
Roland Levillaine4f1c512017-10-30 13:28:28 +0000122
123if [[ -n "$ART_TEST_CHROOT" ]]; then
124 # Prepare the chroot dir.
125 echo -e "${green}Prepare the chroot dir in $ART_TEST_CHROOT${nc}"
126
127 # Check that ART_TEST_CHROOT is correctly defined.
128 [[ "x$ART_TEST_CHROOT" = x/* ]] || { echo "$ART_TEST_CHROOT is not an absolute path"; exit 1; }
129
130 # Create chroot.
131 adb shell mkdir -p "$ART_TEST_CHROOT"
132
133 # Provide property_contexts file(s) in chroot.
134 # This is required to have Android system properties work from the chroot.
135 # Notes:
136 # - In Android N, only '/property_contexts' is expected.
137 # - In Android O, property_context files are expected under /system and /vendor.
138 # (See bionic/libc/bionic/system_properties.cpp for more information.)
139 property_context_files="/property_contexts \
140 /system/etc/selinux/plat_property_contexts \
141 /vendor/etc/selinux/nonplat_property_context \
142 /plat_property_contexts \
143 /nonplat_property_contexts"
144 for f in $property_context_files; do
145 adb shell test -f "$f" \
146 "&&" mkdir -p "$ART_TEST_CHROOT$(dirname $f)" \
147 "&&" cp -f "$f" "$ART_TEST_CHROOT$f"
148 done
149
150 # Create directories required for ART testing in chroot.
151 adb shell mkdir -p "$ART_TEST_CHROOT/tmp"
152 adb shell mkdir -p "$ART_TEST_CHROOT/data/dalvik-cache"
153 adb shell mkdir -p "$ART_TEST_CHROOT/data/local/tmp"
154
155 # Populate /etc in chroot with required files.
156 adb shell mkdir -p "$ART_TEST_CHROOT/system/etc"
157 adb shell "cd $ART_TEST_CHROOT && ln -s system/etc etc"
158
159 # Provide /proc in chroot.
160 adb shell mkdir -p "$ART_TEST_CHROOT/proc"
161 adb shell mount | grep -q "^proc on $ART_TEST_CHROOT/proc type proc " \
162 || adb shell mount -t proc proc "$ART_TEST_CHROOT/proc"
163
164 # Provide /sys in chroot.
165 adb shell mkdir -p "$ART_TEST_CHROOT/sys"
166 adb shell mount | grep -q "^sysfs on $ART_TEST_CHROOT/sys type sysfs " \
167 || adb shell mount -t sysfs sysfs "$ART_TEST_CHROOT/sys"
168 # Provide /sys/kernel/debug in chroot.
169 adb shell mount | grep -q "^debugfs on $ART_TEST_CHROOT/sys/kernel/debug type debugfs " \
170 || adb shell mount -t debugfs debugfs "$ART_TEST_CHROOT/sys/kernel/debug"
171
172 # Provide /dev in chroot.
173 adb shell mkdir -p "$ART_TEST_CHROOT/dev"
174 adb shell mount | grep -q "^tmpfs on $ART_TEST_CHROOT/dev type tmpfs " \
175 || adb shell mount -o bind /dev "$ART_TEST_CHROOT/dev"
Roland Levillain7b7ea792019-01-08 19:47:50 +0000176
177 # Create /apex tmpfs in chroot.
178 adb shell mkdir -p "$ART_TEST_CHROOT/apex"
179 adb shell mount | grep -q "^tmpfs on $ART_TEST_CHROOT/apex type tmpfs " \
180 || adb shell mount -t tmpfs -o nodev,noexec,nosuid tmpfs "$ART_TEST_CHROOT/apex"
Roland Levillaine4f1c512017-10-30 13:28:28 +0000181fi