Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
firebase_testlab.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2#
3# Copyright 2013 The Flutter Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7import argparse
8import glob
9import re
10import os
11import subprocess
12import sys
13from compatibility_helper import byte_str_decode
14
15if 'STORAGE_BUCKET' not in os.environ:
16 print('The GCP storage bucket must be provided as an environment variable.')
17 sys.exit(1)
18BUCKET = os.environ['STORAGE_BUCKET']
19
20if 'GCP_PROJECT' not in os.environ:
21 print('The GCP project must be provided as an environment variable.')
22 sys.exit(1)
23PROJECT = os.environ['GCP_PROJECT']
24
25# Exit codes returned by the FTL command that signal an infrastructure failure.
26FTL_INFRA_FAILURE_CODES = [1, 15, 20]
27
28# Maximum number of retries done if an infrastructure failure occurs.
29MAX_RETRY_ATTEMPTS = 2
30
31script_dir = os.path.dirname(os.path.realpath(__file__))
32buildroot_dir = os.path.abspath(os.path.join(script_dir, '..', '..'))
33out_dir = os.path.join(buildroot_dir, 'out')
34error_re = re.compile(r'[EF]/flutter.+')
35
36
37def run_firebase_test(apk, results_dir):
38 # game-loop tests are meant for OpenGL apps.
39 # This type of test will give the application a handle to a file, and
40 # we'll write the timeline JSON to that file.
41 # See https://firebase.google.com/docs/test-lab/android/game-loop
42 # Pixel 5. As of this commit, this is a highly available device in FTL.
43 process = subprocess.Popen(
44 [
45 'gcloud',
46 '--project',
47 PROJECT,
48 'firebase',
49 'test',
50 'android',
51 'run',
52 '--type',
53 'game-loop',
54 '--app',
55 apk,
56 '--timeout',
57 '2m',
58 '--results-bucket',
59 BUCKET,
60 '--results-dir',
61 results_dir,
62 '--device',
63 'model=shiba,version=34',
64 ],
65 stdout=subprocess.PIPE,
66 stderr=subprocess.STDOUT,
67 universal_newlines=True,
68 )
69 return process
70
71
72def check_logcat(results_dir):
73 logcat = subprocess.check_output(['gsutil', 'cat', '%s/%s/*/logcat' % (BUCKET, results_dir)])
74 logcat = byte_str_decode(logcat)
75 if not logcat:
76 sys.exit(1)
77
78 logcat_matches = error_re.findall(logcat)
79 if logcat_matches:
80 print('Errors in logcat:')
81 print(logcat_matches)
82 sys.exit(1)
83
84
85def check_timeline(results_dir):
86 gsutil_du = subprocess.check_output([
87 'gsutil', 'du',
88 '%s/%s/*/game_loop_results/results_scenario_0.json' % (BUCKET, results_dir)
89 ])
90 gsutil_du = byte_str_decode(gsutil_du)
91 gsutil_du = gsutil_du.strip()
92 if gsutil_du == '0':
93 print('Failed to produce a timeline.')
94 sys.exit(1)
95
96
97def main():
98 parser = argparse.ArgumentParser()
99 parser.add_argument(
100 '--variant',
101 dest='variant',
102 action='store',
103 default='android_profile_arm64',
104 help='The engine variant to run tests for.'
105 )
106 parser.add_argument(
107 '--build-id',
108 default=os.environ.get('SWARMING_TASK_ID', 'local_test'),
109 help='A unique build identifier for this test. Used to sort results in the GCS bucket.'
110 )
111
112 args = parser.parse_args()
113
114 apks_dir = os.path.join(out_dir, args.variant, 'firebase_apks')
115 apks = set(glob.glob('%s/*.apk' % apks_dir))
116
117 if not apks:
118 print('No APKs found at %s' % apks_dir)
119 return 1
120
121 git_revision = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=script_dir)
122 git_revision = byte_str_decode(git_revision)
123 git_revision = git_revision.strip()
124
125 for retry in range(MAX_RETRY_ATTEMPTS):
126 if retry > 0:
127 print('Retrying %s' % apks)
128
129 results = []
130 for apk in sorted(apks):
131 results_dir = '%s/%s/%s' % (os.path.basename(apk), git_revision, args.build_id)
132 process = run_firebase_test(apk, results_dir)
133 results.append((apk, results_dir, process))
134
135 for apk, results_dir, process in results:
136 print('===== Test output for %s' % apk)
137 for line in iter(process.stdout.readline, ''):
138 print(line.strip())
139
140 return_code = process.wait()
141 if return_code in FTL_INFRA_FAILURE_CODES:
142 print('Firebase test %s failed with infrastructure error code: %s' % (apk, return_code))
143 continue
144 if return_code != 0:
145 print('Firebase test %s failed with code: %s' % (apk, return_code))
146 sys.exit(return_code)
147
148 print('Checking logcat for %s' % results_dir)
149 check_logcat(results_dir)
150 # scenario_app produces a timeline, but the android image test does not.
151 if 'scenario' in apk:
152 print('Checking timeline for %s' % results_dir)
153 check_timeline(results_dir)
154
155 apks.remove(apk)
156
157 if not apks:
158 break
159
160 return 0
161
162
163if __name__ == '__main__':
164 sys.exit(main())
void print(void *str)
Definition bridge.cpp:126
check_timeline(results_dir)
check_logcat(results_dir)
run_firebase_test(apk, results_dir)
Definition main.py:1