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