Merge "Run bugreport unit test without script"

This commit is contained in:
Dieter Hsu
2020-06-25 15:12:04 +00:00
committed by Android (Google) Code Review
4 changed files with 15 additions and 65 deletions

View File

@@ -15,12 +15,18 @@
android_test {
name: "BugreportManagerTestCases",
srcs: ["src/**/*.java"],
data: [":bugreport_artifacts"],
libs: [
"android.test.runner",
"android.test.base",
],
static_libs: ["androidx.test.rules", "truth-prebuilt"],
test_suites: ["general-tests"],
sdk_version: "test_current",
platform_apis: true,
}
filegroup {
name: "bugreport_artifacts",
srcs: ["config/test-sysconfig.xml"],
}

View File

@@ -21,11 +21,16 @@
<option name="config-descriptor:metadata" key="parameter" value="not_instant_app" />
<option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" />
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true"/>
<option name="test-file-name" value="BugreportManagerTestCases.apk"/>
<target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer" />
<target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
<option name="push-file" key="test-sysconfig.xml" value="/system/etc/sysconfig/allow-br-from-tests.xml" />
<option name="push-file" key="BugreportManagerTestCases.apk" value="/system/priv-app/BugreportManagerTestCases.apk" />
<option name="abort-on-push-failure" value="true" />
<option name="cleanup" value="true" />
<option name="remount-system" value="true" />
</target_preparer>
<target_preparer class="com.android.tradefed.targetprep.RebootTargetPreparer" />
<test class="com.android.tradefed.testtype.AndroidJUnitTest">
<option name="package" value="com.android.os.bugreports.tests"/>
<!-- test-timeout unit is ms, value = 30 min -->

View File

@@ -1,61 +0,0 @@
#!/bin/bash
# Copyright (C) 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Script to run bugreport unitests
# Must run on a rooted device.
# Must run lunch before running the script
# Usage: ${ANDROID_BUILD_TOP}/frameworks/base/core/tests/bugreports/run.sh
# NOTE: This script replaces the framework-sysconfig.xml on your device, so use with caution.
# It tries to replace it when done, but if the script does not finish cleanly
# (for e.g. force stopped mid-way) your device will be left in an inconsistent state.
# Reflashing will restore the right config.
TMP_SYS_CONFIG=/var/tmp/framework-sysconfig.xml
if [[ -z $ANDROID_PRODUCT_OUT ]]; then
echo "Please lunch before running this test."
exit 0
fi
# Print every command to console.
set -x
make -j BugreportManagerTestCases &&
adb root &&
adb remount &&
adb wait-for-device &&
# Save the sysconfig file in a tmp location and push the test config in
adb pull /system/etc/sysconfig/framework-sysconfig.xml "${TMP_SYS_CONFIG}" &&
adb push $ANDROID_BUILD_TOP/frameworks/base/core/tests/bugreports/config/test-sysconfig.xml /system/etc/sysconfig/framework-sysconfig.xml &&
# The test app needs to be a priv-app.
adb push $OUT/testcases/BugreportManagerTestCases/*/BugreportManagerTestCases.apk /system/priv-app ||
exit 1
adb reboot &&
adb wait-for-device &&
atest BugreportManagerTest || echo "Tests FAILED!"
# Restore the saved config file
if [ -f "${TMP_SYS_CONFIG}" ]; then
SIZE=$(stat --printf="%s" "${TMP_SYS_CONFIG}")
if [ SIZE > 0 ]; then
adb remount &&
adb wait-for-device &&
adb push "${TMP_SYS_CONFIG}" /system/etc/sysconfig/framework-sysconfig.xml &&
rm "${TMP_SYS_CONFIG}"
fi
fi