Skip to content

Commit d8714f7

Browse files
authored
Include logcat for failed Android emulator tests (#1057)
1 parent ea2f3ff commit d8714f7

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

.github/workflows/integration_tests.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,13 @@ jobs:
10501050
name: mobile-simulator-test-video-artifact
10511051
path: testapps/video-*-android-${{ matrix.build_os }}-${{ matrix.android_device }}-${{ matrix.test_type }}.mp4
10521052
retention-days: ${{ env.artifactRetentionDays }}
1053+
- name: Upload Android test logcat artifact
1054+
if: ${{ steps.get-device-type.outputs.device_type == 'virtual' && !cancelled() }}
1055+
uses: actions/upload-artifact@v3
1056+
with:
1057+
name: mobile-simulator-test-logcat-artifact
1058+
path: testapps/logcat-*-android-${{ matrix.build_os }}-${{ matrix.android_device }}-${{ matrix.test_type }}.txt
1059+
retention-days: ${{ env.artifactRetentionDays }}
10531060
- name: Download log artifacts
10541061
if: ${{ needs.check_and_prepare.outputs.pr_number && failure() && !cancelled() }}
10551062
uses: actions/download-artifact@v3

scripts/gha/test_simulator.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,9 @@ def _run_android_test(testapp_dir, package_name, app_path, helper_project, retry
677677
logging.info("Running android helper test: %s, %s, %s", package_name, app_path, helper_project)
678678
_install_android_app(app_path)
679679
video_name = "video-%s-%s-%s.mp4" % (package_name, retry, FLAGS.logfile_name)
680+
logcat_name = "logcat-%s-%s-%s.txt" % (package_name, retry, FLAGS.logfile_name)
680681
record_process = _record_android_tests(video_name)
682+
_clear_android_logcat()
681683
_run_instrumented_test()
682684
_stop_recording(record_process)
683685
log = _get_android_test_log(package_name)
@@ -686,6 +688,7 @@ def _run_android_test(testapp_dir, package_name, app_path, helper_project, retry
686688
result = test_validation.validate_results(log, test_validation.CPP)
687689
if not result.complete or (FLAGS.test_type=="uitest" and result.fails>0):
688690
_save_recorded_android_video(video_name, testapp_dir)
691+
_save_android_logcat(logcat_name, testapp_dir)
689692
if retry > 1:
690693
logging.info("Retry _run_android_test. Remaining retry: %s", retry-1)
691694
return _run_android_test(testapp_dir, package_name, app_path, helper_project, retry=retry-1)
@@ -734,6 +737,20 @@ def _save_recorded_android_video(video_name, summary_dir):
734737
subprocess.run(args=args, capture_output=True, text=True, check=False)
735738

736739

740+
def _save_android_logcat(logcat_name, summary_dir):
741+
logcat_file = os.path.join(summary_dir, logcat_name)
742+
args = ["adb", "logcat", "-d"]
743+
logging.info("Save logcat to %s: %s", logcat_file, " ".join(args))
744+
with open(logcat_file, "wb") as f:
745+
subprocess.run(args=args, stdout=f, check=False)
746+
747+
748+
def _clear_android_logcat():
749+
args = ["adb", "logcat", "-c"]
750+
logging.info("Clear logcat: %s", " ".join(args))
751+
subprocess.run(args=args, check=False)
752+
753+
737754
def _run_instrumented_test():
738755
"""Run the helper app.
739756
This helper app can run integration_test app automatically.

0 commit comments

Comments
 (0)