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 | |
Orion Hodson | 1c5b1ea | 2020-01-22 15:34:33 +0000 | [diff] [blame] | 17 | # The work does by this script is (mostly) undone by tools/buildbot-teardown-device.sh. |
Roland Levillain | 5604938 | 2018-05-23 18:26:22 +0100 | [diff] [blame] | 18 | # Make sure to keep these files in sync. |
| 19 | |
Ulya Trafimovich | 9597748 | 2021-11-09 14:05:14 +0000 | [diff] [blame] | 20 | . "$(dirname $0)/buildbot-utils.sh" |
Nicolas Geoffray | d2d62d1 | 2015-03-18 11:23:56 +0000 | [diff] [blame] | 21 | |
Martin Stjernholm | c71aacb | 2019-02-18 16:35:44 +0000 | [diff] [blame] | 22 | if [ "$1" = --verbose ]; then |
| 23 | verbose=true |
| 24 | else |
| 25 | verbose=false |
| 26 | fi |
| 27 | |
Roland Levillain | 5604938 | 2018-05-23 18:26:22 +0100 | [diff] [blame] | 28 | # Setup as root, as some actions performed here require it. |
Roland Levillain | 2aab06b | 2017-03-01 14:14:10 +0000 | [diff] [blame] | 29 | adb root |
| 30 | adb wait-for-device |
| 31 | |
Ulya Trafimovich | 5298bcd | 2021-11-09 14:46:22 +0000 | [diff] [blame] | 32 | msginfo "Date on host" |
Roland Levillain | 2aab06b | 2017-03-01 14:14:10 +0000 | [diff] [blame] | 33 | date |
| 34 | |
Ulya Trafimovich | 5298bcd | 2021-11-09 14:46:22 +0000 | [diff] [blame] | 35 | msginfo "Date on device" |
Nicolas Geoffray | d2d62d1 | 2015-03-18 11:23:56 +0000 | [diff] [blame] | 36 | adb shell date |
| 37 | |
Roland Levillain | 2aab06b | 2017-03-01 14:14:10 +0000 | [diff] [blame] | 38 | host_seconds_since_epoch=$(date -u +%s) |
| 39 | device_seconds_since_epoch=$(adb shell date -u +%s) |
| 40 | |
| 41 | abs_time_difference_in_seconds=$(expr $host_seconds_since_epoch - $device_seconds_since_epoch) |
| 42 | if [ $abs_time_difference_in_seconds -lt 0 ]; then |
| 43 | abs_time_difference_in_seconds=$(expr 0 - $abs_time_difference_in_seconds) |
| 44 | fi |
| 45 | |
| 46 | seconds_per_hour=3600 |
| 47 | |
David Srbecky | 06884de | 2021-05-05 16:00:37 +0100 | [diff] [blame] | 48 | # b/187295147 : Disable live-lock kill daemon. |
| 49 | # It can confuse long running processes for issues and kill them. |
| 50 | # This usually manifests as temporarily lost adb connection. |
Ulya Trafimovich | 5298bcd | 2021-11-09 14:46:22 +0000 | [diff] [blame] | 51 | msginfo "Killing llkd, seen killing adb" |
David Srbecky | 06884de | 2021-05-05 16:00:37 +0100 | [diff] [blame] | 52 | adb shell setprop ctl.stop llkd-0 |
| 53 | adb shell setprop ctl.stop llkd-1 |
| 54 | |
Peter Collingbourne | 93317bd | 2022-03-10 11:06:45 -0800 | [diff] [blame] | 55 | product_name=$(adb shell getprop ro.build.product) |
| 56 | |
| 57 | if [ "x$product_name" = xfugu ]; then |
| 58 | # Kill logd first, so that when we set the adb buffer size later in this file, |
| 59 | # it is brought up again. |
| 60 | msginfo "Killing logd, seen leaking on fugu/N" |
| 61 | adb shell pkill -9 -U logd logd && msginfo "...logd killed" |
| 62 | fi |
Nicolas Geoffray | c2d199b | 2017-05-22 16:05:06 +0100 | [diff] [blame] | 63 | |
Roland Levillain | 2aab06b | 2017-03-01 14:14:10 +0000 | [diff] [blame] | 64 | # Update date on device if the difference with host is more than one hour. |
| 65 | if [ $abs_time_difference_in_seconds -gt $seconds_per_hour ]; then |
Ulya Trafimovich | 5298bcd | 2021-11-09 14:46:22 +0000 | [diff] [blame] | 66 | msginfo "Update date on device" |
Roland Levillain | 2aab06b | 2017-03-01 14:14:10 +0000 | [diff] [blame] | 67 | adb shell date -u @$host_seconds_since_epoch |
| 68 | fi |
| 69 | |
Ulya Trafimovich | 5298bcd | 2021-11-09 14:46:22 +0000 | [diff] [blame] | 70 | msginfo "Turn off selinux" |
Nicolas Geoffray | d2d62d1 | 2015-03-18 11:23:56 +0000 | [diff] [blame] | 71 | adb shell setenforce 0 |
Martin Stjernholm | c71aacb | 2019-02-18 16:35:44 +0000 | [diff] [blame] | 72 | $verbose && adb shell getenforce |
Nicolas Geoffray | d2d62d1 | 2015-03-18 11:23:56 +0000 | [diff] [blame] | 73 | |
Ulya Trafimovich | 5298bcd | 2021-11-09 14:46:22 +0000 | [diff] [blame] | 74 | msginfo "Setting local loopback" |
Nicolas Geoffray | 0a38a0e | 2015-03-25 17:22:34 +0000 | [diff] [blame] | 75 | adb shell ifconfig lo up |
Martin Stjernholm | c71aacb | 2019-02-18 16:35:44 +0000 | [diff] [blame] | 76 | $verbose && adb shell ifconfig |
Nicolas Geoffray | 0a38a0e | 2015-03-25 17:22:34 +0000 | [diff] [blame] | 77 | |
Martin Stjernholm | c71aacb | 2019-02-18 16:35:44 +0000 | [diff] [blame] | 78 | if $verbose; then |
Ulya Trafimovich | 5298bcd | 2021-11-09 14:46:22 +0000 | [diff] [blame] | 79 | msginfo "List properties" |
Martin Stjernholm | c71aacb | 2019-02-18 16:35:44 +0000 | [diff] [blame] | 80 | adb shell getprop |
Nicolas Geoffray | b8703d6 | 2015-10-30 11:18:52 +0000 | [diff] [blame] | 81 | |
Ulya Trafimovich | 5298bcd | 2021-11-09 14:46:22 +0000 | [diff] [blame] | 82 | msginfo "Uptime" |
Martin Stjernholm | c71aacb | 2019-02-18 16:35:44 +0000 | [diff] [blame] | 83 | adb shell uptime |
Nicolas Geoffray | b8703d6 | 2015-10-30 11:18:52 +0000 | [diff] [blame] | 84 | |
Ulya Trafimovich | 5298bcd | 2021-11-09 14:46:22 +0000 | [diff] [blame] | 85 | msginfo "Battery info" |
Martin Stjernholm | c71aacb | 2019-02-18 16:35:44 +0000 | [diff] [blame] | 86 | adb shell dumpsys battery |
| 87 | fi |
Nicolas Geoffray | 7ea5747 | 2016-02-24 09:53:09 +0000 | [diff] [blame] | 88 | |
Nicolas Geoffray | ff43ade | 2018-07-19 14:17:50 +0100 | [diff] [blame] | 89 | # Fugu only handles buffer size up to 16MB. |
Nicolas Geoffray | ff43ade | 2018-07-19 14:17:50 +0100 | [diff] [blame] | 90 | if [ "x$product_name" = xfugu ]; then |
| 91 | buffer_size=16MB |
| 92 | else |
| 93 | buffer_size=32MB |
| 94 | fi |
| 95 | |
Ulya Trafimovich | 5298bcd | 2021-11-09 14:46:22 +0000 | [diff] [blame] | 96 | msginfo "Setting adb buffer size to ${buffer_size}" |
Nicolas Geoffray | ff43ade | 2018-07-19 14:17:50 +0100 | [diff] [blame] | 97 | adb logcat -G ${buffer_size} |
Martin Stjernholm | c71aacb | 2019-02-18 16:35:44 +0000 | [diff] [blame] | 98 | $verbose && adb logcat -g |
Nicolas Geoffray | 80d9c85 | 2016-03-04 15:28:35 +0000 | [diff] [blame] | 99 | |
Ulya Trafimovich | 5298bcd | 2021-11-09 14:46:22 +0000 | [diff] [blame] | 100 | msginfo "Removing adb spam filter" |
Nicolas Geoffray | 80d9c85 | 2016-03-04 15:28:35 +0000 | [diff] [blame] | 101 | adb logcat -P "" |
Martin Stjernholm | c71aacb | 2019-02-18 16:35:44 +0000 | [diff] [blame] | 102 | $verbose && adb logcat -p |
Nicolas Geoffray | 80d9c85 | 2016-03-04 15:28:35 +0000 | [diff] [blame] | 103 | |
Ulya Trafimovich | 5298bcd | 2021-11-09 14:46:22 +0000 | [diff] [blame] | 104 | msginfo "Kill stalled dalvikvm processes" |
Nicolas Geoffray | fe6f0b6 | 2016-03-07 13:33:37 +0000 | [diff] [blame] | 105 | # 'ps' on M can sometimes hang. |
Martin Stjernholm | c71aacb | 2019-02-18 16:35:44 +0000 | [diff] [blame] | 106 | timeout 2s adb shell "ps" >/dev/null |
Artem Serov | 381d35c | 2021-02-10 21:27:00 +0000 | [diff] [blame] | 107 | if [[ $? == 124 ]] && [[ "$ART_TEST_RUN_ON_ARM_FVP" != true ]]; then |
Ulya Trafimovich | 5298bcd | 2021-11-09 14:46:22 +0000 | [diff] [blame] | 108 | msginfo "Rebooting device to fix 'ps'" |
Nicolas Geoffray | fe6f0b6 | 2016-03-07 13:33:37 +0000 | [diff] [blame] | 109 | adb reboot |
| 110 | adb wait-for-device root |
| 111 | else |
| 112 | processes=$(adb shell "ps" | grep dalvikvm | awk '{print $2}') |
| 113 | for i in $processes; do adb shell kill -9 $i; done |
| 114 | fi |
Roland Levillain | e4f1c51 | 2017-10-30 13:28:28 +0000 | [diff] [blame] | 115 | |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 116 | # Chroot environment. |
| 117 | # =================== |
| 118 | |
Roland Levillain | e4f1c51 | 2017-10-30 13:28:28 +0000 | [diff] [blame] | 119 | if [[ -n "$ART_TEST_CHROOT" ]]; then |
| 120 | # Prepare the chroot dir. |
Ulya Trafimovich | 5298bcd | 2021-11-09 14:46:22 +0000 | [diff] [blame] | 121 | msginfo "Prepare the chroot dir in $ART_TEST_CHROOT" |
Roland Levillain | e4f1c51 | 2017-10-30 13:28:28 +0000 | [diff] [blame] | 122 | |
| 123 | # Check that ART_TEST_CHROOT is correctly defined. |
| 124 | [[ "x$ART_TEST_CHROOT" = x/* ]] || { echo "$ART_TEST_CHROOT is not an absolute path"; exit 1; } |
| 125 | |
| 126 | # Create chroot. |
| 127 | adb shell mkdir -p "$ART_TEST_CHROOT" |
| 128 | |
| 129 | # Provide property_contexts file(s) in chroot. |
| 130 | # This is required to have Android system properties work from the chroot. |
| 131 | # Notes: |
| 132 | # - In Android N, only '/property_contexts' is expected. |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 133 | # - In Android O+, property_context files are expected under /system and /vendor. |
| 134 | # (See bionic/libc/bionic/system_properties.cpp or |
| 135 | # bionic/libc/system_properties/contexts_split.cpp for more information.) |
Roland Levillain | e4f1c51 | 2017-10-30 13:28:28 +0000 | [diff] [blame] | 136 | property_context_files="/property_contexts \ |
| 137 | /system/etc/selinux/plat_property_contexts \ |
| 138 | /vendor/etc/selinux/nonplat_property_context \ |
| 139 | /plat_property_contexts \ |
| 140 | /nonplat_property_contexts" |
| 141 | for f in $property_context_files; do |
| 142 | adb shell test -f "$f" \ |
| 143 | "&&" mkdir -p "$ART_TEST_CHROOT$(dirname $f)" \ |
| 144 | "&&" cp -f "$f" "$ART_TEST_CHROOT$f" |
| 145 | done |
| 146 | |
| 147 | # Create directories required for ART testing in chroot. |
| 148 | adb shell mkdir -p "$ART_TEST_CHROOT/tmp" |
| 149 | adb shell mkdir -p "$ART_TEST_CHROOT/data/dalvik-cache" |
| 150 | adb shell mkdir -p "$ART_TEST_CHROOT/data/local/tmp" |
| 151 | |
| 152 | # Populate /etc in chroot with required files. |
| 153 | adb shell mkdir -p "$ART_TEST_CHROOT/system/etc" |
Roland Levillain | 433e49f | 2020-07-27 13:56:46 +0100 | [diff] [blame] | 154 | adb shell test -L "$ART_TEST_CHROOT/etc" \ |
| 155 | || adb shell ln -s system/etc "$ART_TEST_CHROOT/etc" |
Roland Levillain | e4f1c51 | 2017-10-30 13:28:28 +0000 | [diff] [blame] | 156 | |
| 157 | # Provide /proc in chroot. |
| 158 | adb shell mkdir -p "$ART_TEST_CHROOT/proc" |
| 159 | adb shell mount | grep -q "^proc on $ART_TEST_CHROOT/proc type proc " \ |
| 160 | || adb shell mount -t proc proc "$ART_TEST_CHROOT/proc" |
| 161 | |
| 162 | # Provide /sys in chroot. |
| 163 | adb shell mkdir -p "$ART_TEST_CHROOT/sys" |
| 164 | adb shell mount | grep -q "^sysfs on $ART_TEST_CHROOT/sys type sysfs " \ |
| 165 | || adb shell mount -t sysfs sysfs "$ART_TEST_CHROOT/sys" |
| 166 | # Provide /sys/kernel/debug in chroot. |
| 167 | adb shell mount | grep -q "^debugfs on $ART_TEST_CHROOT/sys/kernel/debug type debugfs " \ |
| 168 | || adb shell mount -t debugfs debugfs "$ART_TEST_CHROOT/sys/kernel/debug" |
| 169 | |
| 170 | # Provide /dev in chroot. |
| 171 | adb shell mkdir -p "$ART_TEST_CHROOT/dev" |
| 172 | adb shell mount | grep -q "^tmpfs on $ART_TEST_CHROOT/dev type tmpfs " \ |
| 173 | || adb shell mount -o bind /dev "$ART_TEST_CHROOT/dev" |
Peter Collingbourne | b2c68b3 | 2022-03-03 12:17:02 -0800 | [diff] [blame] | 174 | adb shell mount | grep -q "^devpts on $ART_TEST_CHROOT/dev/pts type devpts " \ |
| 175 | || adb shell mount -o bind /dev/pts "$ART_TEST_CHROOT/dev/pts" |
Roland Levillain | 7b7ea79 | 2019-01-08 19:47:50 +0000 | [diff] [blame] | 176 | |
Roland Levillain | 0f9823e | 2019-06-18 16:49:24 +0100 | [diff] [blame] | 177 | # Create /apex directory in chroot. |
Roland Levillain | 7b7ea79 | 2019-01-08 19:47:50 +0000 | [diff] [blame] | 178 | adb shell mkdir -p "$ART_TEST_CHROOT/apex" |
Roland Levillain | 15ff34d | 2020-02-05 19:55:34 +0000 | [diff] [blame] | 179 | |
| 180 | # Create /linkerconfig directory in chroot. |
| 181 | adb shell mkdir -p "$ART_TEST_CHROOT/linkerconfig" |
Martin Stjernholm | 8c7e219 | 2020-06-26 15:54:16 +0100 | [diff] [blame] | 182 | |
| 183 | # Create /bin symlink for shebang compatibility. |
Roland Levillain | 433e49f | 2020-07-27 13:56:46 +0100 | [diff] [blame] | 184 | adb shell test -L "$ART_TEST_CHROOT/bin" \ |
| 185 | || adb shell ln -s system/bin "$ART_TEST_CHROOT/bin" |
Roland Levillain | e4f1c51 | 2017-10-30 13:28:28 +0000 | [diff] [blame] | 186 | fi |