OLD | NEW |
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS 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 logging | 5 import logging |
| 6 import os |
6 import re | 7 import re |
7 | 8 |
8 from autotest_lib.client.bin import test, utils | 9 from autotest_lib.client.bin import test, utils |
9 from autotest_lib.client.common_lib import error | 10 from autotest_lib.client.common_lib import error |
10 | 11 |
11 class hardware_DiskSize(test.test): | 12 class hardware_DiskSize(test.test): |
12 version = 1 | 13 version = 1 |
13 | 14 |
14 def run_once(self): | 15 def run_once(self): |
15 cmdline = file('/proc/cmdline').read() | 16 devnode = utils.system_output('rootdev -s -d -i') |
16 match = re.search(r'root=/dev/([^ ]+)', cmdline) | 17 device = os.path.basename(devnode) |
17 if not match: | |
18 raise error.TestError('Unable to find the root partition') | |
19 device = match.group(1)[:-1] | |
20 | 18 |
21 for line in file('/proc/partitions'): | 19 for line in file('/proc/partitions'): |
22 try: | 20 try: |
23 major, minor, blocks, name = re.split(r' +', line.strip()) | 21 major, minor, blocks, name = re.split(r' +', line.strip()) |
24 except ValueError: | 22 except ValueError: |
25 continue | 23 continue |
26 # TODO(waihong@): Check if this works on ARM. | 24 # TODO(waihong@): Check if this works on ARM. |
27 if name == device: | 25 if name == device: |
28 blocks = int(blocks) | 26 blocks = int(blocks) |
29 break | 27 break |
30 else: | 28 else: |
31 raise error.TestError('Unable to determine main disk size') | 29 raise error.TestError('Unable to determine main disk size') |
32 | 30 |
33 # Capacity of a hard disk is quoted with SI prefixes, incrementing by | 31 # Capacity of a hard disk is quoted with SI prefixes, incrementing by |
34 # powers of 1000, instead of powers of 1024. | 32 # powers of 1000, instead of powers of 1024. |
35 gb = blocks * 1024.0 / 1000.0 / 1000.0 / 1000.0 | 33 gb = blocks * 1024.0 / 1000.0 / 1000.0 / 1000.0 |
36 self.write_perf_keyval({"gb_main_disk_size": gb}) | 34 self.write_perf_keyval({"gb_main_disk_size": gb}) |
37 logging.info("DiskSize: %.3f GB" % gb) | 35 logging.info("DiskSize: %.3f GB" % gb) |
OLD | NEW |