Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: build/android/pylib/local/device/local_device_environment.py

Issue 2130863002: Check environment (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Delete unnecessary line breaks. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | build/android/test_runner.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import datetime 5 import datetime
6 import logging 6 import logging
7 import os 7 import os
8 import shutil 8 import shutil
9 import tempfile 9 import tempfile
10 import threading 10 import threading
11 11
12 from devil.android import device_blacklist 12 from devil.android import device_blacklist
13 from devil.android import device_errors 13 from devil.android import device_errors
14 from devil.android import device_list 14 from devil.android import device_list
15 from devil.android import device_utils 15 from devil.android import device_utils
16 from devil.android import logcat_monitor 16 from devil.android import logcat_monitor
17 from devil.utils import cmd_helper
17 from devil.utils import file_utils 18 from devil.utils import file_utils
18 from devil.utils import parallelizer 19 from devil.utils import parallelizer
19 from pylib import constants 20 from pylib import constants
20 from pylib.base import environment 21 from pylib.base import environment
21 22
22 23
23 def _DeviceCachePath(device): 24 def _DeviceCachePath(device):
24 file_name = 'device_cache_%s.json' % device.adb.GetDeviceSerial() 25 file_name = 'device_cache_%s.json' % device.adb.GetDeviceSerial()
25 return os.path.join(constants.GetOutDirectory(), file_name) 26 return os.path.join(constants.GetOutDirectory(), file_name)
26 27
(...skipping 10 matching lines...) Expand all
37 self._devices = [] 38 self._devices = []
38 self._concurrent_adb = args.enable_concurrent_adb 39 self._concurrent_adb = args.enable_concurrent_adb
39 self._enable_device_cache = args.enable_device_cache 40 self._enable_device_cache = args.enable_device_cache
40 self._logcat_monitors = [] 41 self._logcat_monitors = []
41 self._logcat_output_dir = args.logcat_output_dir 42 self._logcat_output_dir = args.logcat_output_dir
42 self._logcat_output_file = args.logcat_output_file 43 self._logcat_output_file = args.logcat_output_file
43 self._max_tries = 1 + args.num_retries 44 self._max_tries = 1 + args.num_retries
44 self._skip_clear_data = args.skip_clear_data 45 self._skip_clear_data = args.skip_clear_data
45 self._target_devices_file = args.target_devices_file 46 self._target_devices_file = args.target_devices_file
46 self._tool_name = args.tool 47 self._tool_name = args.tool
48 self._logdog_file = args.logdog_file
47 49
48 #override 50 #override
49 def SetUp(self): 51 def SetUp(self):
50 device_arg = 'default' 52 device_arg = 'default'
51 if self._target_devices_file: 53 if self._target_devices_file:
52 device_arg = device_list.GetPersistentDeviceList( 54 device_arg = device_list.GetPersistentDeviceList(
53 self._target_devices_file) 55 self._target_devices_file)
54 if not device_arg: 56 if not device_arg:
55 logging.warning('No target devices specified. Falling back to ' 57 logging.warning('No target devices specified. Falling back to '
56 'running on all available devices.') 58 'running on all available devices.')
(...skipping 12 matching lines...) Expand all
69 71
70 if self._enable_device_cache: 72 if self._enable_device_cache:
71 for d in self._devices: 73 for d in self._devices:
72 cache_path = _DeviceCachePath(d) 74 cache_path = _DeviceCachePath(d)
73 if os.path.exists(cache_path): 75 if os.path.exists(cache_path):
74 logging.info('Using device cache: %s', cache_path) 76 logging.info('Using device cache: %s', cache_path)
75 with open(cache_path) as f: 77 with open(cache_path) as f:
76 d.LoadCacheData(f.read()) 78 d.LoadCacheData(f.read())
77 # Delete cached file so that any exceptions cause it to be cleared. 79 # Delete cached file so that any exceptions cause it to be cleared.
78 os.unlink(cache_path) 80 os.unlink(cache_path)
79 if self._logcat_output_file: 81 if self._logcat_output_file or self._logdog_file:
80 self._logcat_output_dir = tempfile.mkdtemp() 82 self._logcat_output_dir = tempfile.mkdtemp()
81 if self._logcat_output_dir: 83 if self._logcat_output_dir:
82 for d in self._devices: 84 for d in self._devices:
83 logcat_file = os.path.join( 85 logcat_file = os.path.join(
84 self._logcat_output_dir, 86 self._logcat_output_dir,
85 '%s_%s' % (d.adb.GetDeviceSerial(), 87 '%s_%s' % (d.adb.GetDeviceSerial(),
86 datetime.datetime.utcnow().strftime('%Y%m%dT%H%M%S'))) 88 datetime.datetime.utcnow().strftime('%Y%m%dT%H%M%S')))
87 monitor = logcat_monitor.LogcatMonitor( 89 monitor = logcat_monitor.LogcatMonitor(
88 d.adb, clear=True, output_file=logcat_file) 90 d.adb, clear=True, output_file=logcat_file)
89 self._logcat_monitors.append(monitor) 91 self._logcat_monitors.append(monitor)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 f.write(d.DumpCacheData()) 128 f.write(d.DumpCacheData())
127 logging.info('Wrote device cache: %s', cache_path) 129 logging.info('Wrote device cache: %s', cache_path)
128 for m in self._logcat_monitors: 130 for m in self._logcat_monitors:
129 m.Stop() 131 m.Stop()
130 m.Close() 132 m.Close()
131 if self._logcat_output_file: 133 if self._logcat_output_file:
132 file_utils.MergeFiles( 134 file_utils.MergeFiles(
133 self._logcat_output_file, 135 self._logcat_output_file,
134 [m.output_file for m in self._logcat_monitors]) 136 [m.output_file for m in self._logcat_monitors])
135 shutil.rmtree(self._logcat_output_dir) 137 shutil.rmtree(self._logcat_output_dir)
138 if self._logdog_file:
139 for m in self._logcat_monitors:
140 add_device_args = ['sed', '-i', '-e',
141 's/^/device({0}) /'.format(m.get_device_serial),
142 m.output_file]
143 cmd_helper.RunCmd(add_device_args)
144 file_utils.MergeFiles(
145 self._logdog_file,
146 [m.output_file for m in self._logcat_monitors])
136 147
137 def BlacklistDevice(self, device, reason='local_device_failure'): 148 def BlacklistDevice(self, device, reason='local_device_failure'):
138 device_serial = device.adb.GetDeviceSerial() 149 device_serial = device.adb.GetDeviceSerial()
139 if self._blacklist: 150 if self._blacklist:
140 self._blacklist.Extend([device_serial], reason=reason) 151 self._blacklist.Extend([device_serial], reason=reason)
141 with self._devices_lock: 152 with self._devices_lock:
142 self._devices = [d for d in self._devices if str(d) != device_serial] 153 self._devices = [d for d in self._devices if str(d) != device_serial]
143 154
OLDNEW
« no previous file with comments | « no previous file | build/android/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698