blob: f5ebfd138568dbd655ba3784751e0cfb816a6640 [file] [log] [blame]
simonhatch1730cec2015-02-17 21:05:391#!/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.
5
6import json
7import multiprocessing
8import os
9import platform
10import subprocess
11import sys
12
13
14import common
15
16
17def is_linux():
18 return sys.platform.startswith('linux')
19
20
21def get_free_disk_space(failures):
22 """Returns the amount of free space on the current disk, in GiB.
23
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)
33
34 failures.append('get_free_disk_space: OS %s not supported.' % os.name)
35 return 0
36
37
38def get_num_cpus(failures):
39 """Returns the number of logical CPUs on this machine.
40
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'
49
50
51def 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.
54
55 Returns:
56 A dict indicating the result.
57 """
58 if not is_linux():
59 return {}
60
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'),
jbudoricka583ba32015-09-11 17:23:1969 '--json-output', tempfile_path,
70 '--blacklist-file', os.path.join(
71 args.paths['checkout'], 'out', 'bad_devices.json')])
simonhatch1730cec2015-02-17 21:05:3972
73 if rc:
74 failures.append('bb_device_status_check')
75 return {}
76
77 with open(tempfile_path, 'r') as src:
78 device_info = json.load(src)
79
80 results = {}
81 results['devices'] = sorted(v['serial'] for v in device_info)
82
simonhatch08bab382015-12-15 17:04:2183 details = [v['build_detail'] for v in device_info if not v['blacklisted']]
simonhatch1730cec2015-02-17 21:05:3984
85 def unique_build_details(index):
86 return sorted(list(set([v.split(':')[index] for v in details])))
87
88 parsed_details = {
89 'device_names': unique_build_details(0),
90 'build_versions': unique_build_details(1),
91 'build_types': unique_build_details(2),
92 }
93
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)
101
simonhatch08bab382015-12-15 17:04:21102 for v in device_info:
103 if v['blacklisted']:
104 failures.append('Device %s blacklisted' % v['serial'])
105
simonhatch1730cec2015-02-17 21:05:39106 return results
107
108
109def main_run(args):
110 failures = []
111 host_info = {}
112 host_info['os_system'] = platform.system()
113 host_info['os_release'] = platform.release()
114
115 host_info['processor'] = platform.processor()
116 host_info['num_cpus'] = get_num_cpus(failures)
117 host_info['free_disk_space'] = get_free_disk_space(failures)
118
119 host_info['python_version'] = platform.python_version()
120 host_info['python_path'] = sys.executable
121
122 host_info['devices'] = get_device_info(args, failures)
123
124 json.dump({
125 'valid': True,
126 'failures': failures,
127 '_host_info': host_info,
128 }, args.output)
129
130 return len(failures) != 0
131
132
133def main_compile_targets(args):
134 json.dump([], args.output)
135
136
137if __name__ == '__main__':
138 funcs = {
139 'run': main_run,
140 'compile_targets': main_compile_targets,
141 }
142 sys.exit(common.run_script(sys.argv[1:], funcs))