Hash :
e43d3591
Author :
Date :
2024-11-01T16:23:27
Tests: allow choosing Chromium/our test runner + screen checks
Chromium test runner (build/android/test_runner.py) is currently the
default runner for most suites. One exception is angle_trace_tests where
we're always using our scripts instead (android_helper.py etc).
We do that by setting android_test_runner_script to our runner for that
angle_test instance.
This CL supports setting android_test_runner_script to our script but
then choose whether to run with the Chromium runner or android_helper
depending on the command-line arg (--angle-test-runner)
This CL also adds a check for the screen state which will be performed
regardless of the runner. This is to have a fast and clean failure when
the device wasn't properly initialized by the infra (see bug).
The check is based on the output of `dumpsys deviceidle | grep mScreen`
(this is the most generic check I found, I previously used nfc but that
depends on nfc and turns out the output is device-dependent)
This CL enables this mode for angle_end2end_tests. Bots will continue to
run with Chromium runner as before (but with the added screen checks).
Locally, we will now be able to switch to our scripts directly:
out/Android/angle_end2end_tests \
--gtest_filter='*ClearTextureEXT2DMSStencil*' \
--angle-test-runner
Now when running end2end tests locally (regardless of the runner) with
a locked device screen, we'll see the following error right away
instead of sporadic failures or stuckness during execution:
Exception: Unexpected device screen state: ['mScreenOn=false', 'mScreenLocked=true']; expected: ['mScreenOn=true', 'mScreenLocked=false']
The plan is to enable this mode for all suites, after which the current
local script run_angle_android_test.py will no longer be needed.
Bug: b/344849382
Change-Id: I77e7733804ab37e2f3d26bf3574a52a9553e4274
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5985232
Reviewed-by: Cody Northrop <cnorthrop@google.com>
Commit-Queue: Roman Lavrov <romanl@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
#! /usr/bin/env vpython3
#
# Copyright 2023 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
import argparse
import contextlib
import difflib
import json
import logging
import os
import pathlib
import shutil
import subprocess
import sys
import tempfile
import time
SCRIPT_DIR = str(pathlib.Path(__file__).resolve().parent)
PY_UTILS = str(pathlib.Path(SCRIPT_DIR) / '..' / 'py_utils')
if PY_UTILS not in sys.path:
os.stat(PY_UTILS) and sys.path.insert(0, PY_UTILS)
import angle_test_util
@contextlib.contextmanager
def temporary_dir(prefix=''):
path = tempfile.mkdtemp(prefix=prefix)
try:
yield path
finally:
logging.info("Removing temporary directory: %s" % path)
shutil.rmtree(path)
def file_content(path):
with open(path, 'rb') as f:
content = f.read()
if path.endswith('.json'):
info = json.loads(content)
info['TraceMetadata']['CaptureRevision'] = '<ignored>'
return json.dumps(info, indent=2).encode()
return content
def diff_files(path, expected_path):
content = file_content(path)
expected_content = file_content(expected_path)
fn = os.path.basename(path)
if content == expected_content:
return False
if fn.endswith('.angledata'):
logging.error('Checks failed. Binary file contents mismatch: %s', fn)
return True
# Captured files are expected to have LF line endings.
# Note that git's EOL conversion for these files is disabled via .gitattributes
assert b'\r\n' not in content
assert b'\r\n' not in expected_content
diff = list(
difflib.unified_diff(
expected_content.decode().splitlines(),
content.decode().splitlines(),
fromfile=fn,
tofile=fn,
))
logging.error('Checks failed. Found diff in %s:\n%s\n', fn, '\n'.join(diff))
return True
def run_test(test_name, overwrite_expected):
with temporary_dir() as temp_dir:
cmd = [angle_test_util.ExecutablePathInCurrentDir('angle_end2end_tests')]
if angle_test_util.IsAndroid():
cmd.append('--angle-test-runner')
test_args = ['--gtest_filter=%s' % test_name, '--angle-per-test-capture-label']
extra_env = {
'ANGLE_CAPTURE_ENABLED': '1',
'ANGLE_CAPTURE_FRAME_START': '2',
'ANGLE_CAPTURE_FRAME_END': '5',
'ANGLE_CAPTURE_OUT_DIR': temp_dir,
'ANGLE_CAPTURE_COMPRESSION': '0',
}
subprocess.check_call(cmd + test_args, env={**os.environ.copy(), **extra_env})
logging.info('Capture finished, comparing files')
files = sorted(fn for fn in os.listdir(temp_dir))
expected_dir = os.path.join(SCRIPT_DIR, 'expected')
expected_files = sorted(fn for fn in os.listdir(expected_dir) if not fn.startswith('.'))
if overwrite_expected:
for f in expected_files:
os.remove(os.path.join(expected_dir, f))
shutil.copytree(temp_dir, expected_dir, dirs_exist_ok=True)
return True
if files != expected_files:
logging.error(
'Checks failed. Capture produced a different set of files: %s\nDiff:\n%s\n', files,
'\n'.join(difflib.unified_diff(expected_files, files)))
return False
has_diffs = False
for fn in files:
has_diffs |= diff_files(os.path.join(temp_dir, fn), os.path.join(expected_dir, fn))
return not has_diffs
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--isolated-script-test-output', type=str)
parser.add_argument('--log', help='Logging level.', default='info')
parser.add_argument(
'--overwrite-expected', help='Overwrite contents of expected/', action='store_true')
args, extra_flags = parser.parse_known_args()
logging.basicConfig(level=args.log.upper())
angle_test_util.Initialize('angle_end2end_tests')
test_name = 'CapturedTest*/ES3_Vulkan'
had_error = False
try:
if not run_test(test_name, args.overwrite_expected):
had_error = True
logging.error(
'Found capture diffs. If diffs are expected, build angle_end2end_tests and run '
'(cd out/<build>; ../../src/tests/capture_tests/capture_tests.py --overwrite-expected)'
)
except Exception as e:
logging.exception(e)
had_error = True
if args.isolated_script_test_output:
results = {
'tests': {
'capture_test': {}
},
'interrupted': False,
'seconds_since_epoch': time.time(),
'path_delimiter': '.',
'version': 3,
'num_failures_by_type': {
'FAIL': 0,
'PASS': 0,
'SKIP': 0,
},
}
result = 'FAIL' if had_error else 'PASS'
results['tests']['capture_test'][test_name] = {'expected': 'PASS', 'actual': result}
results['num_failures_by_type'][result] += 1
with open(args.isolated_script_test_output, 'w') as f:
f.write(json.dumps(results, indent=2))
return 1 if had_error else 0
if __name__ == '__main__':
sys.exit(main())