Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/scripts/run_gtest_angle_test.py
1693 views
1
#!/usr/bin/env python
2
# Copyright 2020 The Chromium Authors. All rights reserved.
3
# Use of this source code is governed by a BSD-style license that can be
4
# found in the LICENSE file.
5
"""Runs an isolated non-Telemetry ANGLE test.
6
7
The main contract is that the caller passes the arguments:
8
9
--isolated-script-test-output=[FILENAME]
10
json is written to that file in the format:
11
https://chromium.googlesource.com/chromium/src/+/master/docs/testing/json_test_results_format.md
12
13
Optional argument:
14
15
--isolated-script-test-filter=[TEST_NAMES]
16
17
is a double-colon-separated ("::") list of test names, to run just that subset
18
of tests. This list is parsed by this harness and sent down via the
19
--gtest_filter argument.
20
21
This script is intended to be the base command invoked by the isolate,
22
followed by a subsequent non-python executable. For a similar script see
23
run_performance_test.py.
24
"""
25
26
import argparse
27
import json
28
import os
29
import shutil
30
import sys
31
import tempfile
32
import traceback
33
34
# Add //src/testing into sys.path for importing xvfb and test_env, and
35
# //src/testing/scripts for importing common.
36
d = os.path.dirname
37
THIS_DIR = d(os.path.abspath(__file__))
38
ANGLE_SRC_DIR = d(THIS_DIR)
39
sys.path.insert(0, os.path.join(ANGLE_SRC_DIR, 'testing'))
40
sys.path.insert(0, os.path.join(ANGLE_SRC_DIR, 'testing', 'scripts'))
41
CHROMIUM_SRC_DIR = d(d(ANGLE_SRC_DIR))
42
sys.path.insert(0, os.path.join(CHROMIUM_SRC_DIR, 'testing'))
43
sys.path.insert(0, os.path.join(CHROMIUM_SRC_DIR, 'testing', 'scripts'))
44
45
import common
46
import xvfb
47
import test_env
48
49
# Unfortunately we need to copy these variables from
50
# //src/testing/scripts/test_env.py. Importing it and using its
51
# get_sandbox_env breaks test runs on Linux (it seems to unset DISPLAY).
52
CHROME_SANDBOX_ENV = 'CHROME_DEVEL_SANDBOX'
53
CHROME_SANDBOX_PATH = '/opt/chromium/chrome_sandbox'
54
55
56
def IsWindows():
57
return sys.platform == 'cygwin' or sys.platform.startswith('win')
58
59
60
def main():
61
parser = argparse.ArgumentParser()
62
parser.add_argument('executable', help='Test executable.')
63
parser.add_argument('--isolated-script-test-output', type=str)
64
parser.add_argument('--isolated-script-test-filter', type=str)
65
parser.add_argument('--xvfb', help='Start xvfb.', action='store_true')
66
67
# Kept for compatiblity.
68
# TODO(jmadill): Remove when removed from the recipes. http://crbug.com/954415
69
parser.add_argument('--isolated-script-test-perf-output', type=str)
70
71
args, extra_flags = parser.parse_known_args()
72
73
env = os.environ.copy()
74
75
if 'GTEST_TOTAL_SHARDS' in env:
76
extra_flags += ['--shard-count=' + env['GTEST_TOTAL_SHARDS']]
77
env.pop('GTEST_TOTAL_SHARDS')
78
if 'GTEST_SHARD_INDEX' in env:
79
extra_flags += ['--shard-index=' + env['GTEST_SHARD_INDEX']]
80
env.pop('GTEST_SHARD_INDEX')
81
if 'ISOLATED_OUTDIR' in env:
82
extra_flags += ['--isolated-outdir=' + env['ISOLATED_OUTDIR']]
83
env.pop('ISOLATED_OUTDIR')
84
85
# Assume we want to set up the sandbox environment variables all the
86
# time; doing so is harmless on non-Linux platforms and is needed
87
# all the time on Linux.
88
env[CHROME_SANDBOX_ENV] = CHROME_SANDBOX_PATH
89
90
rc = 0
91
try:
92
# Consider adding stdio control flags.
93
if args.isolated_script_test_output:
94
extra_flags.append('--isolated-script-test-output=%s' %
95
args.isolated_script_test_output)
96
97
if args.isolated_script_test_filter:
98
filter_list = common.extract_filter_list(args.isolated_script_test_filter)
99
extra_flags.append('--gtest_filter=' + ':'.join(filter_list))
100
101
if IsWindows():
102
args.executable = '.\\%s.exe' % args.executable
103
else:
104
args.executable = './%s' % args.executable
105
with common.temporary_file() as tempfile_path:
106
env['CHROME_HEADLESS'] = '1'
107
cmd = [args.executable] + extra_flags
108
109
if args.xvfb:
110
rc = xvfb.run_executable(cmd, env, stdoutfile=tempfile_path)
111
else:
112
rc = test_env.run_command_with_output(cmd, env=env, stdoutfile=tempfile_path)
113
114
except Exception:
115
traceback.print_exc()
116
rc = 1
117
118
return rc
119
120
121
# This is not really a "script test" so does not need to manually add
122
# any additional compile targets.
123
def main_compile_targets(args):
124
json.dump([], args.output)
125
126
127
if __name__ == '__main__':
128
# Conform minimally to the protocol defined by ScriptTest.
129
if 'compile_targets' in sys.argv:
130
funcs = {
131
'run': None,
132
'compile_targets': main_compile_targets,
133
}
134
sys.exit(common.run_script(sys.argv[1:], funcs))
135
sys.exit(main())
136
137