Tighten DCHECK to clarify that users of syncable storage can't request more quota.
[chromium-blink-merge.git] / testing / scripts / host_info.py
blobb3131d8fb5c7ffd1ad077e24a20f55ee2c1ce5d1
1 #!/usr/bin/env python
2 # Copyright 2015 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.
6 import json
7 import multiprocessing
8 import os
9 import platform
10 import subprocess
11 import sys
14 import common
17 def is_linux():
18 return sys.platform.startswith('linux')
21 def get_free_disk_space(failures):
22 """Returns the amount of free space on the current disk, in GiB.
24 Returns:
25 The amount of free space on the current disk, measured in GiB.
26 """
27 if os.name == 'posix':
28 # Stat the current path for info on the current disk.
29 stat_result = os.statvfs('.')
30 # Multiply block size by number of free blocks, express in GiB.
31 return stat_result.f_frsize * stat_result.f_bavail / (
32 1024.0 / 1024.0 / 1024.0)
34 failures.append('get_free_disk_space: OS %s not supported.' % os.name)
35 return 0
38 def get_num_cpus(failures):
39 """Returns the number of logical CPUs on this machine.
41 Returns:
42 The number of logical CPUs on this machine, or 'unknown' if indeterminate.
43 """
44 try:
45 return multiprocessing.cpu_count()
46 except NotImplementedError:
47 failures.append('get_num_cpus')
48 return 'unknown'
51 def get_device_info(args, failures):
52 """Parses the device info for each attached device, and returns a summary
53 of the device info and any mismatches.
55 Returns:
56 A dict indicating the result.
57 """
58 if not is_linux():
59 return {}
61 with common.temporary_file() as tempfile_path:
62 rc = common.run_command([
63 sys.executable,
64 os.path.join(args.paths['checkout'],
65 'build',
66 'android',
67 'buildbot',
68 'bb_device_status_check.py'),
69 '--json-output', tempfile_path])
71 if rc:
72 failures.append('bb_device_status_check')
73 return {}
75 with open(tempfile_path, 'r') as src:
76 device_info = json.load(src)
78 results = {}
79 results['devices'] = sorted(v['serial'] for v in device_info)
81 details = [v['build_detail'] for v in device_info]
83 def unique_build_details(index):
84 return sorted(list(set([v.split(':')[index] for v in details])))
86 parsed_details = {
87 'device_names': unique_build_details(0),
88 'build_versions': unique_build_details(1),
89 'build_types': unique_build_details(2),
92 for k, v in parsed_details.iteritems():
93 if len(v) == 1:
94 results[k] = v[0]
95 else:
96 results[k] = 'MISMATCH'
97 results['%s_list' % k] = v
98 failures.append(k)
100 return results
103 def main_run(args):
104 failures = []
105 host_info = {}
106 host_info['os_system'] = platform.system()
107 host_info['os_release'] = platform.release()
109 host_info['processor'] = platform.processor()
110 host_info['num_cpus'] = get_num_cpus(failures)
111 host_info['free_disk_space'] = get_free_disk_space(failures)
113 host_info['python_version'] = platform.python_version()
114 host_info['python_path'] = sys.executable
116 host_info['devices'] = get_device_info(args, failures)
118 json.dump({
119 'valid': True,
120 'failures': failures,
121 '_host_info': host_info,
122 }, args.output)
124 return len(failures) != 0
127 def main_compile_targets(args):
128 json.dump([], args.output)
131 if __name__ == '__main__':
132 funcs = {
133 'run': main_run,
134 'compile_targets': main_compile_targets,
136 sys.exit(common.run_script(sys.argv[1:], funcs))