Remove linux_chromium_gn_dbg from the chromium CQ.
[chromium-blink-merge.git] / testing / scripts / host_info.py
blob080437784b29bb7f96dafa3ec002c69cb36509f7
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,
70 '--blacklist-file', os.path.join(
71 args.paths['checkout'], 'out', 'bad_devices.json')])
73 if rc:
74 failures.append('bb_device_status_check')
75 return {}
77 with open(tempfile_path, 'r') as src:
78 device_info = json.load(src)
80 results = {}
81 results['devices'] = sorted(v['serial'] for v in device_info)
83 details = [v['build_detail'] for v in device_info]
85 def unique_build_details(index):
86 return sorted(list(set([v.split(':')[index] for v in details])))
88 parsed_details = {
89 'device_names': unique_build_details(0),
90 'build_versions': unique_build_details(1),
91 'build_types': unique_build_details(2),
94 for k, v in parsed_details.iteritems():
95 if len(v) == 1:
96 results[k] = v[0]
97 else:
98 results[k] = 'MISMATCH'
99 results['%s_list' % k] = v
100 failures.append(k)
102 return results
105 def main_run(args):
106 failures = []
107 host_info = {}
108 host_info['os_system'] = platform.system()
109 host_info['os_release'] = platform.release()
111 host_info['processor'] = platform.processor()
112 host_info['num_cpus'] = get_num_cpus(failures)
113 host_info['free_disk_space'] = get_free_disk_space(failures)
115 host_info['python_version'] = platform.python_version()
116 host_info['python_path'] = sys.executable
118 host_info['devices'] = get_device_info(args, failures)
120 json.dump({
121 'valid': True,
122 'failures': failures,
123 '_host_info': host_info,
124 }, args.output)
126 return len(failures) != 0
129 def main_compile_targets(args):
130 json.dump([], args.output)
133 if __name__ == '__main__':
134 funcs = {
135 'run': main_run,
136 'compile_targets': main_compile_targets,
138 sys.exit(common.run_script(sys.argv[1:], funcs))