Nicolas Geoffray | d2d62d1 | 2015-03-18 11:23:56 +0000 | [diff] [blame] | 1 | #!/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 Levillain | 5604938 | 2018-05-23 18:26:22 +0100 | [diff] [blame] | 17 | # 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 Geoffray | d2d62d1 | 2015-03-18 11:23:56 +0000 | [diff] [blame] | 20 | green='\033[0;32m' |
| 21 | nc='\033[0m' |
| 22 | |
Roland Levillain | 5604938 | 2018-05-23 18:26:22 +0100 | [diff] [blame] | 23 | # Setup as root, as some actions performed here require it. |
Roland Levillain | 2aab06b | 2017-03-01 14:14:10 +0000 | [diff] [blame] | 24 | adb root |
| 25 | adb wait-for-device |
| 26 | |
| 27 | echo -e "${green}Date on host${nc}" |
| 28 | date |
| 29 | |
Nicolas Geoffray | d2d62d1 | 2015-03-18 11:23:56 +0000 | [diff] [blame] | 30 | echo -e "${green}Date on device${nc}" |
| 31 | adb shell date |
| 32 | |
Roland Levillain | 2aab06b | 2017-03-01 14:14:10 +0000 | [diff] [blame] | 33 | host_seconds_since_epoch=$(date -u +%s) |
| 34 | device_seconds_since_epoch=$(adb shell date -u +%s) |
| 35 | |
| 36 | abs_time_difference_in_seconds=$(expr $host_seconds_since_epoch - $device_seconds_since_epoch) |
| 37 | if [ $abs_time_difference_in_seconds -lt 0 ]; then |
| 38 | abs_time_difference_in_seconds=$(expr 0 - $abs_time_difference_in_seconds) |
| 39 | fi |
| 40 | |
| 41 | seconds_per_hour=3600 |
| 42 | |
Nicolas Geoffray | c2d199b | 2017-05-22 16:05:06 +0100 | [diff] [blame] | 43 | # Kill logd first, so that when we set the adb buffer size later in this file, |
| 44 | # it is brought up again. |
| 45 | echo -e "${green}Killing logd, seen leaking on fugu/N${nc}" |
Evgeny Astigeevich | 1d27360 | 2018-09-24 10:55:20 +0100 | [diff] [blame] | 46 | adb shell pkill -9 -U logd logd && echo -e "${green}...logd killed${nc}" |
Nicolas Geoffray | c2d199b | 2017-05-22 16:05:06 +0100 | [diff] [blame] | 47 | |
Roland Levillain | 2aab06b | 2017-03-01 14:14:10 +0000 | [diff] [blame] | 48 | # Update date on device if the difference with host is more than one hour. |
| 49 | if [ $abs_time_difference_in_seconds -gt $seconds_per_hour ]; then |
| 50 | echo -e "${green}Update date on device${nc}" |
| 51 | adb shell date -u @$host_seconds_since_epoch |
| 52 | fi |
| 53 | |
Nicolas Geoffray | d2d62d1 | 2015-03-18 11:23:56 +0000 | [diff] [blame] | 54 | echo -e "${green}Turn off selinux${nc}" |
| 55 | adb shell setenforce 0 |
| 56 | adb shell getenforce |
| 57 | |
Nicolas Geoffray | 0a38a0e | 2015-03-25 17:22:34 +0000 | [diff] [blame] | 58 | echo -e "${green}Setting local loopback${nc}" |
| 59 | adb shell ifconfig lo up |
| 60 | adb shell ifconfig |
| 61 | |
Roland Levillain | 30d2696 | 2018-03-29 19:36:29 +0100 | [diff] [blame] | 62 | # Ensure netd is running, as otherwise the logcat would be spammed |
| 63 | # with the following messages on devices running Android O: |
Roland Levillain | 6f7d8b7 | 2018-03-15 15:45:00 +0000 | [diff] [blame] | 64 | # |
Roland Levillain | 30d2696 | 2018-03-29 19:36:29 +0100 | [diff] [blame] | 65 | # E NetdConnector: Communications error: java.io.IOException: No such file or directory |
| 66 | # E mDnsConnector: Communications error: java.io.IOException: No such file or directory |
Roland Levillain | 6f7d8b7 | 2018-03-15 15:45:00 +0000 | [diff] [blame] | 67 | # |
Roland Levillain | 30d2696 | 2018-03-29 19:36:29 +0100 | [diff] [blame] | 68 | # Netd was initially disabled as an attempt to solve issues with |
| 69 | # network-related libcore and JDWP tests failing on devices running |
| 70 | # Android O (MR1) (see b/74725685). These tests are currently |
| 71 | # disabled. When a better solution has been found, we should remove |
| 72 | # the following lines. |
| 73 | echo -e "${green}Turning on netd${nc}" |
| 74 | adb shell start netd |
Roland Levillain | 6f7d8b7 | 2018-03-15 15:45:00 +0000 | [diff] [blame] | 75 | adb shell getprop init.svc.netd |
| 76 | |
Nicolas Geoffray | d2d62d1 | 2015-03-18 11:23:56 +0000 | [diff] [blame] | 77 | echo -e "${green}List properties${nc}" |
| 78 | adb shell getprop |
Nicolas Geoffray | b8703d6 | 2015-10-30 11:18:52 +0000 | [diff] [blame] | 79 | |
| 80 | echo -e "${green}Uptime${nc}" |
| 81 | adb shell uptime |
| 82 | |
Nicolas Geoffray | 7ea5747 | 2016-02-24 09:53:09 +0000 | [diff] [blame] | 83 | echo -e "${green}Battery info${nc}" |
| 84 | adb shell dumpsys battery |
| 85 | |
Nicolas Geoffray | ff43ade | 2018-07-19 14:17:50 +0100 | [diff] [blame] | 86 | # Fugu only handles buffer size up to 16MB. |
| 87 | product_name=$(adb shell getprop ro.build.product) |
| 88 | |
| 89 | if [ "x$product_name" = xfugu ]; then |
| 90 | buffer_size=16MB |
| 91 | else |
| 92 | buffer_size=32MB |
| 93 | fi |
| 94 | |
| 95 | echo -e "${green}Setting adb buffer size to ${buffer_size}${nc}" |
| 96 | adb logcat -G ${buffer_size} |
Nicolas Geoffray | 80d9c85 | 2016-03-04 15:28:35 +0000 | [diff] [blame] | 97 | adb logcat -g |
| 98 | |
| 99 | echo -e "${green}Removing adb spam filter${nc}" |
| 100 | adb logcat -P "" |
| 101 | adb logcat -p |
| 102 | |
Nicolas Geoffray | b8703d6 | 2015-10-30 11:18:52 +0000 | [diff] [blame] | 103 | echo -e "${green}Kill stalled dalvikvm processes${nc}" |
Nicolas Geoffray | fe6f0b6 | 2016-03-07 13:33:37 +0000 | [diff] [blame] | 104 | # 'ps' on M can sometimes hang. |
| 105 | timeout 2s adb shell "ps" |
| 106 | if [ $? = 124 ]; then |
| 107 | echo -e "${green}Rebooting device to fix 'ps'${nc}" |
| 108 | adb reboot |
| 109 | adb wait-for-device root |
| 110 | else |
| 111 | processes=$(adb shell "ps" | grep dalvikvm | awk '{print $2}') |
| 112 | for i in $processes; do adb shell kill -9 $i; done |
| 113 | fi |
Roland Levillain | e4f1c51 | 2017-10-30 13:28:28 +0000 | [diff] [blame] | 114 | |
| 115 | if [[ -n "$ART_TEST_CHROOT" ]]; then |
| 116 | # Prepare the chroot dir. |
| 117 | echo -e "${green}Prepare the chroot dir in $ART_TEST_CHROOT${nc}" |
| 118 | |
| 119 | # Check that ART_TEST_CHROOT is correctly defined. |
| 120 | [[ "x$ART_TEST_CHROOT" = x/* ]] || { echo "$ART_TEST_CHROOT is not an absolute path"; exit 1; } |
| 121 | |
| 122 | # Create chroot. |
| 123 | adb shell mkdir -p "$ART_TEST_CHROOT" |
| 124 | |
| 125 | # Provide property_contexts file(s) in chroot. |
| 126 | # This is required to have Android system properties work from the chroot. |
| 127 | # Notes: |
| 128 | # - In Android N, only '/property_contexts' is expected. |
| 129 | # - In Android O, property_context files are expected under /system and /vendor. |
| 130 | # (See bionic/libc/bionic/system_properties.cpp for more information.) |
| 131 | property_context_files="/property_contexts \ |
| 132 | /system/etc/selinux/plat_property_contexts \ |
| 133 | /vendor/etc/selinux/nonplat_property_context \ |
| 134 | /plat_property_contexts \ |
| 135 | /nonplat_property_contexts" |
| 136 | for f in $property_context_files; do |
| 137 | adb shell test -f "$f" \ |
| 138 | "&&" mkdir -p "$ART_TEST_CHROOT$(dirname $f)" \ |
| 139 | "&&" cp -f "$f" "$ART_TEST_CHROOT$f" |
| 140 | done |
| 141 | |
| 142 | # Create directories required for ART testing in chroot. |
| 143 | adb shell mkdir -p "$ART_TEST_CHROOT/tmp" |
| 144 | adb shell mkdir -p "$ART_TEST_CHROOT/data/dalvik-cache" |
| 145 | adb shell mkdir -p "$ART_TEST_CHROOT/data/local/tmp" |
| 146 | |
| 147 | # Populate /etc in chroot with required files. |
| 148 | adb shell mkdir -p "$ART_TEST_CHROOT/system/etc" |
| 149 | adb shell "cd $ART_TEST_CHROOT && ln -s system/etc etc" |
| 150 | |
| 151 | # Provide /proc in chroot. |
| 152 | adb shell mkdir -p "$ART_TEST_CHROOT/proc" |
| 153 | adb shell mount | grep -q "^proc on $ART_TEST_CHROOT/proc type proc " \ |
| 154 | || adb shell mount -t proc proc "$ART_TEST_CHROOT/proc" |
| 155 | |
| 156 | # Provide /sys in chroot. |
| 157 | adb shell mkdir -p "$ART_TEST_CHROOT/sys" |
| 158 | adb shell mount | grep -q "^sysfs on $ART_TEST_CHROOT/sys type sysfs " \ |
| 159 | || adb shell mount -t sysfs sysfs "$ART_TEST_CHROOT/sys" |
| 160 | # Provide /sys/kernel/debug in chroot. |
| 161 | adb shell mount | grep -q "^debugfs on $ART_TEST_CHROOT/sys/kernel/debug type debugfs " \ |
| 162 | || adb shell mount -t debugfs debugfs "$ART_TEST_CHROOT/sys/kernel/debug" |
| 163 | |
| 164 | # Provide /dev in chroot. |
| 165 | adb shell mkdir -p "$ART_TEST_CHROOT/dev" |
| 166 | adb shell mount | grep -q "^tmpfs on $ART_TEST_CHROOT/dev type tmpfs " \ |
| 167 | || adb shell mount -o bind /dev "$ART_TEST_CHROOT/dev" |
| 168 | fi |