| 1 |
# Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 |
# Use of this source code is governed by a BSD-style license that can be |
| 3 |
# found in the LICENSE file. |
| 4 |
|
| 5 |
|
| 6 |
# pylint: disable=W0201 |
| 7 |
|
| 8 |
|
| 9 |
"""Default flavor, used for running code on desktop machines.""" |
| 10 |
|
| 11 |
|
| 12 |
import collections |
| 13 |
|
| 14 |
|
| 15 |
WIN_TOOLCHAIN_DIR = 't' |
| 16 |
|
| 17 |
|
| 18 |
# Notes: |
| 19 |
# dm_dir: Where DM writes. |
| 20 |
# skp_dir: Holds SKP files that are consumed by RenderSKPs and BenchPictures. |
| 21 |
DeviceDirs = collections.namedtuple( |
| 22 |
'DeviceDirs', ['bin_dir', 'dm_dir', 'perf_data_dir', 'resource_dir', 'images_dir', 'fonts_dir', |
| 23 |
'lotties_dir', 'skp_dir', 'svg_dir', 'tmp_dir', 'texttraces_dir']) |
| 24 |
|
| 25 |
|
| 26 |
class DefaultFlavor(object): |
| 27 |
def __init__(self, module, app_name): |
| 28 |
# Name of the app we're going to run. May be used in various ways by |
| 29 |
# different flavors. |
| 30 |
self.app_name = app_name |
| 31 |
|
| 32 |
# Store a pointer to the parent recipe module (SkiaFlavorApi) so that |
| 33 |
# FlavorUtils objects can do recipe module-like things, like run steps or |
| 34 |
# access module-level resources. |
| 35 |
self.module = module |
| 36 |
|
| 37 |
# self.m is just a shortcut so that Flavor objects can use the same |
| 38 |
# syntax as regular recipe modules to run steps, eg: self.m.step(...) |
| 39 |
self.m = module.m |
| 40 |
self._chrome_path = None |
| 41 |
self.device_dirs = DeviceDirs( |
| 42 |
bin_dir=self.m.vars.build_dir, |
| 43 |
dm_dir=self.m.vars.swarming_out_dir, |
| 44 |
perf_data_dir=self.m.vars.swarming_out_dir, |
| 45 |
resource_dir=self.m.path.start_dir.joinpath('skia', 'resources'), |
| 46 |
images_dir=self.m.path.start_dir.joinpath('skimage'), |
| 47 |
fonts_dir=self.m.path.start_dir.joinpath('googlefonts_testdata', 'data'), |
| 48 |
lotties_dir=self.m.path.start_dir.joinpath('lottie-samples'), |
| 49 |
skp_dir=self.m.path.start_dir.joinpath('skp'), |
| 50 |
svg_dir=self.m.path.start_dir.joinpath('svg'), |
| 51 |
tmp_dir=self.m.vars.tmp_dir, |
| 52 |
texttraces_dir=self.m.path.start_dir.joinpath('text_blob_traces')) |
| 53 |
self.host_dirs = self.device_dirs |
| 54 |
|
| 55 |
def device_path_join(self, *args): |
| 56 |
"""Like os.path.join(), but for paths on a connected device.""" |
| 57 |
return self.m.path.join(*args) |
| 58 |
|
| 59 |
def copy_directory_contents_to_device(self, host_dir, device_dir): |
| 60 |
"""Like shutil.copytree(), but for copying to a connected device.""" |
| 61 |
# For "normal" builders who don't have an attached device, we expect |
| 62 |
# host_dir and device_dir to be the same. |
| 63 |
if str(host_dir) != str(device_dir): |
| 64 |
raise ValueError('For builders who do not have attached devices, copying ' |
| 65 |
'from host to device is undefined and only allowed if ' |
| 66 |
'host_path and device_path are the same (%s vs %s).' % ( |
| 67 |
str(host_dir), str(device_dir))) |
| 68 |
|
| 69 |
def copy_directory_contents_to_host(self, device_dir, host_dir): |
| 70 |
"""Like shutil.copytree(), but for copying from a connected device.""" |
| 71 |
# For "normal" builders who don't have an attached device, we expect |
| 72 |
# host_dir and device_dir to be the same. |
| 73 |
if str(host_dir) != str(device_dir): |
| 74 |
raise ValueError('For builders who do not have attached devices, copying ' |
| 75 |
'from device to host is undefined and only allowed if ' |
| 76 |
'host_path and device_path are the same (%s vs %s).' % ( |
| 77 |
str(host_dir), str(device_dir))) |
| 78 |
|
| 79 |
def copy_file_to_device(self, host_path, device_path): |
| 80 |
"""Like shutil.copyfile, but for copying to a connected device.""" |
| 81 |
# For "normal" builders who don't have an attached device, we expect |
| 82 |
# host_dir and device_dir to be the same. |
| 83 |
if str(host_path) != str(device_path): |
| 84 |
raise ValueError('For builders who do not have attached devices, copying ' |
| 85 |
'from host to device is undefined and only allowed if ' |
| 86 |
'host_path and device_path are the same (%s vs %s).' % ( |
| 87 |
str(host_path), str(device_path))) |
| 88 |
|
| 89 |
def create_clean_device_dir(self, path): |
| 90 |
"""Like shutil.rmtree() + os.makedirs(), but on a connected device.""" |
| 91 |
self.create_clean_host_dir(path) |
| 92 |
|
| 93 |
def create_clean_host_dir(self, path): |
| 94 |
"""Convenience function for creating a clean directory.""" |
| 95 |
self.m.run.rmtree(path) |
| 96 |
self.m.file.ensure_directory( |
| 97 |
'makedirs %s' % self.m.path.basename(path), path) |
| 98 |
|
| 99 |
def read_file_on_device(self, path, **kwargs): |
| 100 |
"""Reads the specified file.""" |
| 101 |
return self.m.file.read_text('read %s' % path, path) |
| 102 |
|
| 103 |
def remove_file_on_device(self, path): |
| 104 |
"""Removes the specified file.""" |
| 105 |
return self.m.file.remove('remove %s' % path, path) |
| 106 |
|
| 107 |
def install(self): |
| 108 |
"""Run device-specific installation steps.""" |
| 109 |
pass |
| 110 |
|
| 111 |
def cleanup_steps(self): |
| 112 |
"""Run any device-specific cleanup steps.""" |
| 113 |
pass |
| 114 |
|
| 115 |
def _run(self, title, cmd, infra_step=False, **kwargs): |
| 116 |
return self.m.run(self.m.step, title, cmd=cmd, |
| 117 |
infra_step=infra_step, **kwargs) |
| 118 |
|
| 119 |
def _py(self, title, script, infra_step=True, args=()): |
| 120 |
return self.m.run(self.m.step, title, cmd=['python3', script]+args, |
| 121 |
infra_step=infra_step) |
| 122 |
|
| 123 |
def step(self, name, cmd, **unused_kwargs): |
| 124 |
app = self.device_dirs.bin_dir.joinpath(cmd[0]) |
| 125 |
cmd = [app] + cmd[1:] |
| 126 |
env = self.m.context.env |
| 127 |
path = [] |
| 128 |
ld_library_path = [] |
| 129 |
|
| 130 |
workdir = self.m.vars.workdir |
| 131 |
extra_tokens = self.m.vars.extra_tokens |
| 132 |
clang_linux = workdir.joinpath('clang_linux') |
| 133 |
if 'MSAN' in extra_tokens: |
| 134 |
clang_linux = workdir.joinpath('clang_ubuntu_noble') |
| 135 |
|
| 136 |
if self.m.vars.is_linux: |
| 137 |
if (self.m.vars.builder_cfg.get('cpu_or_gpu', '') == 'GPU' |
| 138 |
and 'Intel' in self.m.vars.builder_cfg.get('cpu_or_gpu_value', '')): |
| 139 |
dri_path = workdir.joinpath('mesa_intel_driver_linux') |
| 140 |
if ('IntelIrisXe' in self.m.vars.builder_cfg.get('cpu_or_gpu_value', '')): |
| 141 |
dri_path = workdir.joinpath('mesa_intel_driver_linux_22') |
| 142 |
ld_library_path.append(dri_path) |
| 143 |
env['LIBGL_DRIVERS_PATH'] = str(dri_path) |
| 144 |
env['VK_ICD_FILENAMES'] = str(dri_path.joinpath('intel_icd.x86_64.json')) |
| 145 |
|
| 146 |
if 'Vulkan' in extra_tokens: |
| 147 |
env['VULKAN_SDK'] = str(workdir.joinpath('linux_vulkan_sdk')) |
| 148 |
path.append(workdir.joinpath('linux_vulkan_sdk', 'bin')) |
| 149 |
ld_library_path.append(workdir.joinpath('linux_vulkan_sdk', 'lib')) |
| 150 |
# Enable layers for Debug only to avoid affecting perf results on |
| 151 |
# Release. |
| 152 |
# ASAN reports leaks in the Vulkan SDK when the debug layer is enabled. |
| 153 |
# TSAN runs out of memory. |
| 154 |
if (self.m.vars.builder_cfg.get('configuration', '') != 'Release' and |
| 155 |
'ASAN' not in extra_tokens and |
| 156 |
'TSAN' not in extra_tokens): |
| 157 |
env['VK_LAYER_PATH'] = str(workdir.joinpath( |
| 158 |
'linux_vulkan_sdk', 'etc', 'vulkan', 'explicit_layer.d')) |
| 159 |
|
| 160 |
if 'SwiftShader' in extra_tokens: |
| 161 |
ld_library_path.append(self.host_dirs.bin_dir.joinpath('swiftshader_out')) |
| 162 |
|
| 163 |
# Find the MSAN/TSAN-built libc++. |
| 164 |
if 'MSAN' in extra_tokens: |
| 165 |
ld_library_path.append(clang_linux.joinpath('msan')) |
| 166 |
elif 'TSAN' in extra_tokens: |
| 167 |
ld_library_path.append(clang_linux.joinpath('tsan')) |
| 168 |
|
| 169 |
if any('SAN' in t for t in extra_tokens): |
| 170 |
# Sanitized binaries may want to run clang_linux/bin/llvm-symbolizer. |
| 171 |
path.append(clang_linux.joinpath('bin')) |
| 172 |
# We find that testing sanitizer builds with libc++ uncovers more issues |
| 173 |
# than with the system-provided C++ standard library, which is usually |
| 174 |
# libstdc++. libc++ proactively hooks into sanitizers to help their |
| 175 |
# analyses. We ship a copy of libc++ with our Linux toolchain in /lib. |
| 176 |
ld_library_path.append(clang_linux.joinpath('lib', 'x86_64-unknown-linux-gnu')) |
| 177 |
|
| 178 |
if 'ASAN' in extra_tokens: |
| 179 |
os = self.m.vars.builder_cfg.get('os', '') |
| 180 |
if 'Mac' in os or 'Win' in os: |
| 181 |
# Mac and Win don't support detect_leaks. |
| 182 |
env['ASAN_OPTIONS'] = 'symbolize=1' |
| 183 |
else: |
| 184 |
env['ASAN_OPTIONS'] = 'symbolize=1 detect_leaks=1' |
| 185 |
env['ASAN_SYMBOLIZER_PATH'] = clang_linux.joinpath('bin', 'llvm-symbolizer') |
| 186 |
env[ 'LSAN_OPTIONS'] = 'symbolize=1 print_suppressions=1' |
| 187 |
env['UBSAN_OPTIONS'] = 'symbolize=1 print_stacktrace=1' |
| 188 |
|
| 189 |
# If you see <unknown module> in stacktraces, try fast_unwind_on_malloc=0. |
| 190 |
# This may cause a 2-25x slowdown, so use it only when you really need it. |
| 191 |
if name == 'dm' and 'Vulkan' in extra_tokens: |
| 192 |
env['ASAN_OPTIONS'] += ' fast_unwind_on_malloc=0' |
| 193 |
env['LSAN_OPTIONS'] += ' fast_unwind_on_malloc=0' |
| 194 |
|
| 195 |
if 'MSAN' in extra_tokens: |
| 196 |
env['MSAN_OPTIONS'] = 'symbolize=1 print_suppressions=1' |
| 197 |
env['MSAN_SYMBOLIZER_PATH'] = clang_linux.joinpath('bin', 'llvm-symbolizer') |
| 198 |
|
| 199 |
|
| 200 |
if 'TSAN' in extra_tokens: |
| 201 |
# We don't care about malloc(), fprintf, etc. used in signal handlers. |
| 202 |
# If we're in a signal handler, we're already crashing... |
| 203 |
env['TSAN_OPTIONS'] = 'report_signal_unsafe=0' |
| 204 |
if self.m.vars.is_linux: |
| 205 |
# Running through setarch with '-R' disables address randomization, |
| 206 |
# which would otherwise cause TSAN to error out. |
| 207 |
|
| 208 |
# First, find the appropriate architecture setting. Note: newer versions |
| 209 |
# of setarch support using the default, so once we stop running on |
| 210 |
# Ubuntu 18 we can remove this. |
| 211 |
arch = self.m.run( |
| 212 |
self.m.step, 'get arch', cmd=['arch'], infra_step=True, |
| 213 |
stdout=self.m.raw_io.output(), |
| 214 |
step_test_data=(lambda: self.m.raw_io.test_api.stream_output('x86_64')) |
| 215 |
).stdout.decode('utf-8').rstrip() |
| 216 |
cmd = ['setarch', arch, '-R'] + cmd |
| 217 |
|
| 218 |
if 'Coverage' in extra_tokens: |
| 219 |
# This is the output file for the coverage data. Just running the binary |
| 220 |
# will produce the output. The output_file is in the swarming_out_dir and |
| 221 |
# thus will be an isolated output of the Test step. |
| 222 |
profname = '%s.profraw' % self.m.vars.builder_cfg.get('test_filter','o') |
| 223 |
env['LLVM_PROFILE_FILE'] = self.m.path.join(self.m.vars.swarming_out_dir, |
| 224 |
profname) |
| 225 |
|
| 226 |
if 'DWriteCore' in extra_tokens: |
| 227 |
path.append(workdir.joinpath('dwritecore', 'bin')) |
| 228 |
|
| 229 |
if path: |
| 230 |
env['PATH'] = self.m.path.pathsep.join( |
| 231 |
['%(PATH)s'] + ['%s' % p for p in path]) |
| 232 |
if ld_library_path: |
| 233 |
env['LD_LIBRARY_PATH'] = self.m.path.pathsep.join( |
| 234 |
'%s' % p for p in ld_library_path) |
| 235 |
|
| 236 |
to_symbolize = ['dm', 'nanobench'] |
| 237 |
if name in to_symbolize and self.m.vars.is_linux and 'MSAN' not in extra_tokens and 'ASAN' not in extra_tokens: |
| 238 |
# Convert path objects or placeholders into strings such that they can |
| 239 |
# be passed to symbolize_stack_trace.py |
| 240 |
args = [workdir] + [str(x) for x in cmd] |
| 241 |
with self.m.context(cwd=self.m.path.start_dir.joinpath('skia'), env=env): |
| 242 |
self._py('symbolized %s' % name, |
| 243 |
self.module.resource('symbolize_stack_trace.py'), |
| 244 |
args=args, |
| 245 |
infra_step=False) |
| 246 |
elif 'Win' in self.m.vars.builder_cfg.get('os', ''): |
| 247 |
with self.m.context(env=env): |
| 248 |
wrapped_cmd = ['powershell', '-ExecutionPolicy', 'Unrestricted', |
| 249 |
'-File', |
| 250 |
self.module.resource('win_run_and_check_log.ps1')] + cmd |
| 251 |
self._run(name, wrapped_cmd) |
| 252 |
else: |
| 253 |
with self.m.context(env=env): |
| 254 |
self._run(name, cmd) |