summaryrefslogtreecommitdiffstats
path: root/Android/android.py
diff options
context:
space:
mode:
authorMalcolm Smith <smith@chaquo.com>2024-09-13 04:23:54 (GMT)
committerGitHub <noreply@github.com>2024-09-13 04:23:54 (GMT)
commit1f9d163850c43ba85193ef853986c5e96b168c8c (patch)
tree1d059c84fa407317404498b17d918283e44b97ef /Android/android.py
parenta47cd21890fee845d582b41ecf7d029801899ea5 (diff)
downloadcpython-1f9d163850c43ba85193ef853986c5e96b168c8c.zip
cpython-1f9d163850c43ba85193ef853986c5e96b168c8c.tar.gz
cpython-1f9d163850c43ba85193ef853986c5e96b168c8c.tar.bz2
gh-116622: Android test script improvements (#124012)
* Set Android test script stdout to line-buffered * Print warning logcat messages on stderr * Add a -vv option to display high-volume messages which are rarely useful * Documentation and comment improvements
Diffstat (limited to 'Android/android.py')
-rwxr-xr-xAndroid/android.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/Android/android.py b/Android/android.py
index bfa7832..8696d9e 100755
--- a/Android/android.py
+++ b/Android/android.py
@@ -259,8 +259,8 @@ def setup_testbed():
f"{temp_dir}/{outer_jar}", "gradle-wrapper.jar"])
-# run_testbed will build the app automatically, but it hides the Gradle output
-# by default, so it's useful to have this as a separate command for the buildbot.
+# run_testbed will build the app automatically, but it's useful to have this as
+# a separate command to allow running the app outside of this script.
def build_testbed(context):
setup_sdk()
setup_testbed()
@@ -376,6 +376,8 @@ async def find_pid(serial):
shown_error = False
while True:
try:
+ # `pidof` requires API level 24 or higher. The level 23 emulator
+ # includes it, but it doesn't work (it returns all processes).
pid = (await async_check_output(
adb, "-s", serial, "shell", "pidof", "-s", APP_ID
)).strip()
@@ -407,6 +409,7 @@ async def logcat_task(context, initial_devices):
serial = await wait_for(find_device(context, initial_devices), startup_timeout)
pid = await wait_for(find_pid(serial), startup_timeout)
+ # `--pid` requires API level 24 or higher.
args = [adb, "-s", serial, "logcat", "--pid", pid, "--format", "tag"]
hidden_output = []
async with async_process(
@@ -421,11 +424,15 @@ async def logcat_task(context, initial_devices):
# such messages, but other components might.
level, message = None, line
+ # Exclude high-volume messages which are rarely useful.
+ if context.verbose < 2 and "from python test_syslog" in message:
+ continue
+
# Put high-level messages on stderr so they're highlighted in the
# buildbot logs. This will include Python's own stderr.
stream = (
sys.stderr
- if level in ["E", "F"] # ERROR and FATAL (aka ASSERT)
+ if level in ["W", "E", "F"] # WARNING, ERROR, FATAL (aka ASSERT)
else sys.stdout
)
@@ -573,8 +580,9 @@ def parse_args():
test = subcommands.add_parser(
"test", help="Run the test suite")
test.add_argument(
- "-v", "--verbose", action="store_true",
- help="Show Gradle output, and non-Python logcat messages")
+ "-v", "--verbose", action="count", default=0,
+ help="Show Gradle output, and non-Python logcat messages. "
+ "Use twice to include high-volume messages which are rarely useful.")
device_group = test.add_mutually_exclusive_group(required=True)
device_group.add_argument(
"--connected", metavar="SERIAL", help="Run on a connected device. "
@@ -591,6 +599,13 @@ def parse_args():
def main():
install_signal_handler()
+
+ # Under the buildbot, stdout is not a TTY, but we must still flush after
+ # every line to make sure our output appears in the correct order relative
+ # to the output of our subprocesses.
+ for stream in [sys.stdout, sys.stderr]:
+ stream.reconfigure(line_buffering=True)
+
context = parse_args()
dispatch = {"configure-build": configure_build_python,
"make-build": make_build_python,