1 #!/bin/bash 2 3 # Copyright (C) 2019 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 # Script to run bugreport unitests 18 # Must run on a rooted device. 19 # Must run lunch before running the script 20 # Usage: ${ANDROID_BUILD_TOP}/frameworks/base/core/tests/bugreports/run.sh 21 22 # NOTE: This script replaces the framework-sysconfig.xml on your device, so use with caution. 23 # It tries to replace it when done, but if the script does not finish cleanly 24 # (for e.g. force stopped mid-way) your device will be left in an inconsistent state. 25 # Reflashing will restore the right config. 26 27 TMP_SYS_CONFIG=/var/tmp/framework-sysconfig.xml 28 29 if [[ -z $ANDROID_PRODUCT_OUT ]]; then 30 echo "Please lunch before running this test." 31 exit 0 32 fi 33 34 # Print every command to console. 35 set -x 36 37 make -j BugreportManagerTestCases && 38 adb root && 39 adb remount && 40 adb wait-for-device && 41 # Save the sysconfig file in a tmp location and push the test config in 42 adb pull /system/etc/sysconfig/framework-sysconfig.xml "${TMP_SYS_CONFIG}" && 43 adb push $ANDROID_BUILD_TOP/frameworks/base/core/tests/bugreports/config/test-sysconfig.xml /system/etc/sysconfig/framework-sysconfig.xml && 44 # The test app needs to be a priv-app. 45 adb push $OUT/testcases/BugreportManagerTestCases/*/BugreportManagerTestCases.apk /system/priv-app || 46 exit 1 47 48 adb reboot && 49 adb wait-for-device && 50 atest BugreportManagerTest || echo "Tests FAILED!" 51 52 # Restore the saved config file 53 if [ -f "${TMP_SYS_CONFIG}" ]; then 54 SIZE=$(stat --printf="%s" "${TMP_SYS_CONFIG}") 55 if [ SIZE > 0 ]; then 56 adb remount && 57 adb wait-for-device && 58 adb push "${TMP_SYS_CONFIG}" /system/etc/sysconfig/framework-sysconfig.xml && 59 rm "${TMP_SYS_CONFIG}" 60 fi 61 fi 62