Path: blob/main_old/scripts/run_gtest_angle_test.py
1693 views
#!/usr/bin/env python1# Copyright 2020 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4"""Runs an isolated non-Telemetry ANGLE test.56The main contract is that the caller passes the arguments:78--isolated-script-test-output=[FILENAME]9json is written to that file in the format:10https://chromium.googlesource.com/chromium/src/+/master/docs/testing/json_test_results_format.md1112Optional argument:1314--isolated-script-test-filter=[TEST_NAMES]1516is a double-colon-separated ("::") list of test names, to run just that subset17of tests. This list is parsed by this harness and sent down via the18--gtest_filter argument.1920This script is intended to be the base command invoked by the isolate,21followed by a subsequent non-python executable. For a similar script see22run_performance_test.py.23"""2425import argparse26import json27import os28import shutil29import sys30import tempfile31import traceback3233# Add //src/testing into sys.path for importing xvfb and test_env, and34# //src/testing/scripts for importing common.35d = os.path.dirname36THIS_DIR = d(os.path.abspath(__file__))37ANGLE_SRC_DIR = d(THIS_DIR)38sys.path.insert(0, os.path.join(ANGLE_SRC_DIR, 'testing'))39sys.path.insert(0, os.path.join(ANGLE_SRC_DIR, 'testing', 'scripts'))40CHROMIUM_SRC_DIR = d(d(ANGLE_SRC_DIR))41sys.path.insert(0, os.path.join(CHROMIUM_SRC_DIR, 'testing'))42sys.path.insert(0, os.path.join(CHROMIUM_SRC_DIR, 'testing', 'scripts'))4344import common45import xvfb46import test_env4748# Unfortunately we need to copy these variables from49# //src/testing/scripts/test_env.py. Importing it and using its50# get_sandbox_env breaks test runs on Linux (it seems to unset DISPLAY).51CHROME_SANDBOX_ENV = 'CHROME_DEVEL_SANDBOX'52CHROME_SANDBOX_PATH = '/opt/chromium/chrome_sandbox'535455def IsWindows():56return sys.platform == 'cygwin' or sys.platform.startswith('win')575859def main():60parser = argparse.ArgumentParser()61parser.add_argument('executable', help='Test executable.')62parser.add_argument('--isolated-script-test-output', type=str)63parser.add_argument('--isolated-script-test-filter', type=str)64parser.add_argument('--xvfb', help='Start xvfb.', action='store_true')6566# Kept for compatiblity.67# TODO(jmadill): Remove when removed from the recipes. http://crbug.com/95441568parser.add_argument('--isolated-script-test-perf-output', type=str)6970args, extra_flags = parser.parse_known_args()7172env = os.environ.copy()7374if 'GTEST_TOTAL_SHARDS' in env:75extra_flags += ['--shard-count=' + env['GTEST_TOTAL_SHARDS']]76env.pop('GTEST_TOTAL_SHARDS')77if 'GTEST_SHARD_INDEX' in env:78extra_flags += ['--shard-index=' + env['GTEST_SHARD_INDEX']]79env.pop('GTEST_SHARD_INDEX')80if 'ISOLATED_OUTDIR' in env:81extra_flags += ['--isolated-outdir=' + env['ISOLATED_OUTDIR']]82env.pop('ISOLATED_OUTDIR')8384# Assume we want to set up the sandbox environment variables all the85# time; doing so is harmless on non-Linux platforms and is needed86# all the time on Linux.87env[CHROME_SANDBOX_ENV] = CHROME_SANDBOX_PATH8889rc = 090try:91# Consider adding stdio control flags.92if args.isolated_script_test_output:93extra_flags.append('--isolated-script-test-output=%s' %94args.isolated_script_test_output)9596if args.isolated_script_test_filter:97filter_list = common.extract_filter_list(args.isolated_script_test_filter)98extra_flags.append('--gtest_filter=' + ':'.join(filter_list))99100if IsWindows():101args.executable = '.\\%s.exe' % args.executable102else:103args.executable = './%s' % args.executable104with common.temporary_file() as tempfile_path:105env['CHROME_HEADLESS'] = '1'106cmd = [args.executable] + extra_flags107108if args.xvfb:109rc = xvfb.run_executable(cmd, env, stdoutfile=tempfile_path)110else:111rc = test_env.run_command_with_output(cmd, env=env, stdoutfile=tempfile_path)112113except Exception:114traceback.print_exc()115rc = 1116117return rc118119120# This is not really a "script test" so does not need to manually add121# any additional compile targets.122def main_compile_targets(args):123json.dump([], args.output)124125126if __name__ == '__main__':127# Conform minimally to the protocol defined by ScriptTest.128if 'compile_targets' in sys.argv:129funcs = {130'run': None,131'compile_targets': main_compile_targets,132}133sys.exit(common.run_script(sys.argv[1:], funcs))134sys.exit(main())135136137