xref: /aosp_15_r20/art/tools/buildbot-cleanup-device.sh (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1#!/bin/bash
2#
3# Copyright (C) 2017 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
17. "$(dirname $0)/buildbot-utils.sh"
18
19# Clean up local changes to avoid failing incremental `repo sync`.
20# TODO(b/286551985): Remove this after riscv64 support is added to mainline.
21if [[ $TARGET_ARCH = "riscv64" && ! ( -d frameworks/base ) ]]; then
22    msginfo "Reverting local changes to conscrypt and StatsD"
23    (cd $ANDROID_BUILD_TOP/prebuilts/module_sdk/conscrypt && git reset --hard )
24    (cd $ANDROID_BUILD_TOP/prebuilts/module_sdk/StatsD && git reset --hard )
25fi
26
27# Testing on a Linux VM requires special cleanup.
28if [[ -n "$ART_TEST_ON_VM" ]]; then
29  [[ -d "$ART_TEST_VM_DIR" ]] || { msgfatal "no VM found in $ART_TEST_VM_DIR"; }
30  $ART_SSH_CMD "true" || { msgfatal "VM not responding (tried \"$ART_SSH_CMD true\""; }
31  $ART_SSH_CMD "
32    sudo umount $ART_TEST_CHROOT/proc
33    sudo umount $ART_TEST_CHROOT/sys
34    sudo umount $ART_TEST_CHROOT/dev
35    sudo umount $ART_TEST_CHROOT/bin
36    sudo umount $ART_TEST_CHROOT/lib
37    sudo umount $ART_TEST_CHROOT/usr/lib
38    sudo umount $ART_TEST_CHROOT/usr/share/gdb
39    rm -rf $ART_TEST_CHROOT
40  "
41  exit 0
42fi
43
44# Regular Android device. Setup as root, as device cleanup requires it.
45adb root
46adb wait-for-device
47
48if [[ -n "$ART_TEST_CHROOT" ]]; then
49  # Check that ART_TEST_CHROOT is correctly defined.
50  if [[ "x$ART_TEST_CHROOT" != x/* ]]; then
51    echo "$ART_TEST_CHROOT is not an absolute path"
52    exit 1
53  fi
54
55  if adb shell test -d "$ART_TEST_CHROOT"; then
56    msginfo "Remove entire /linkerconfig directory from chroot directory"
57    adb shell rm -rf "$ART_TEST_CHROOT/linkerconfig"
58
59    msginfo "Remove entire /system directory from chroot directory"
60    adb shell rm -rf "$ART_TEST_CHROOT/system"
61
62    msginfo "Remove entire /data directory from chroot directory"
63    adb shell rm -rf "$ART_TEST_CHROOT/data"
64
65    msginfo "Remove entire chroot directory"
66    adb shell rmdir "$ART_TEST_CHROOT" || adb shell ls -la "$ART_TEST_CHROOT"
67  fi
68else
69  adb shell rm -rf \
70    /data/local/tmp /data/art-test /data/nativetest /data/nativetest64 '/data/misc/trace/*'
71fi
72