Hash :
46ff02f8
Author :
Date :
2023-05-18T13:52:29
Capture/Replay: Initial setup for angle_capture_tests Implements the first part (FrameCapture) of the proposal go/frame-capture-and-interpreter-testing Adds a basic test (CapturedTest) with a few frames. This test gets captured by capture_tests.py into a temporary directory and the resulting files are diff'ed with the files under expected/ A diff fails the test. When capture changes, the workflow would be to run the command indicated by the error message in the test which will overwrite the files with new ones so that they can be added to the CL. Example test failure on capture change: https://chromium-swarm.appspot.com/task?id=62b5f4034527c610 when testing https://crrev.com/c/4598046/3 Tests in CI: https://screenshot.googleplex.com/77o8vZVuj8AbFRj Also adds a "angle_capture_tests_trace" lib with the trace just to test that this capture also builds, the lib is not currently loaded by anything. Bug: b/286067106 Change-Id: I7d5f6eed088d84f9e3eb8a72b24b1d92515fff38 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4545408 Reviewed-by: Cody Northrop <cnorthrop@google.com> Commit-Queue: Roman Lavrov <romanl@google.com> Reviewed-by: Yuly Novikov <ynovikov@chromium.org>
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
#! /usr/bin/env python3
#
# 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:
exe = angle_test_util.ExecutablePathInCurrentDir('angle_end2end_tests')
test_args = ['--gtest_filter=%s' % test_name, '--angle-per-test-capture-label']
extra_env = {
'ANGLE_FEATURE_OVERRIDES_ENABLED': 'forceRobustResourceInit:forceInitShaderVariables',
'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([exe] + 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())
test_name = 'CapturedTest.MultiFrame/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())