From 0daed16f214ef13c4da38807a276117e1ef95a9b Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Mon, 18 Mar 2024 12:01:18 -0700 Subject: [PATCH] Write recent logcat output to the LUCI log directory if an Android unit test fails (flutter/engine#51462) --- engine/src/flutter/testing/run_tests.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/testing/run_tests.py b/engine/src/flutter/testing/run_tests.py index 249705064c..25af03c2eb 100755 --- a/engine/src/flutter/testing/run_tests.py +++ b/engine/src/flutter/testing/run_tests.py @@ -734,7 +734,17 @@ def run_android_unittest(test_runner_name, android_variant, adb_path): remote_path = '/data/local/tmp' remote_tests_path = os.path.join(remote_path, test_runner_name) run_cmd([adb_path, 'push', tests_path, remote_path], cwd=BUILDROOT_DIR) - run_cmd([adb_path, 'shell', remote_tests_path]) + + try: + run_cmd([adb_path, 'shell', remote_tests_path]) + except: + luci_test_outputs_path = os.environ.get('FLUTTER_TEST_OUTPUTS_DIR') + if luci_test_outputs_path: + print('>>>>> Test %s failed. Capturing logcat.' % test_runner_name) + logcat_path = os.path.join(luci_test_outputs_path, '%s_logcat' % test_runner_name) + logcat_file = open(logcat_path, 'w') + subprocess.run([adb_path, 'logcat', '-d'], stdout=logcat_file, check=False) + raise def run_android_tests(android_variant='android_debug_unopt', adb_path=None):