| 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 os | 5 import os |
| 6 import re | 6 import re |
| 7 | 7 |
| 8 from autotest_lib.client.bin import test, utils | 8 from autotest_lib.client.bin import test, utils |
| 9 from autotest_lib.client.common_lib import error | 9 from autotest_lib.client.common_lib import error |
| 10 | 10 |
| 11 class hardware_SsdDetection(test.test): | 11 class hardware_SsdDetection(test.test): |
| 12 version = 1 | 12 version = 1 |
| 13 | 13 |
| 14 def setup(self): | 14 def setup(self): |
| 15 self.job.setup_dep(['hdparm']) | 15 self.job.setup_dep(['hdparm']) |
| 16 # create a empty srcdir to prevent the error that checks .version file | 16 # create a empty srcdir to prevent the error that checks .version file |
| 17 if not os.path.exists(self.srcdir): | 17 if not os.path.exists(self.srcdir): |
| 18 utils.system('mkdir %s' % self.srcdir) | 18 utils.system('mkdir %s' % self.srcdir) |
| 19 | 19 |
| 20 | 20 |
| 21 def run_once(self): | 21 def run_once(self): |
| 22 # TODO(ericli): need to find a general solution to install dep packages | 22 # TODO(ericli): need to find a general solution to install dep packages |
| 23 # when tests are pre-compiled, so setup() is not called from client any | 23 # when tests are pre-compiled, so setup() is not called from client any |
| 24 # more. | 24 # more. |
| 25 |
| 25 dep = 'hdparm' | 26 dep = 'hdparm' |
| 26 dep_dir = os.path.join(self.autodir, 'deps', dep) | 27 dep_dir = os.path.join(self.autodir, 'deps', dep) |
| 27 self.job.install_pkg(dep, 'dep', dep_dir) | 28 self.job.install_pkg(dep, 'dep', dep_dir) |
| 28 | 29 |
| 29 cmdline = file('/proc/cmdline').read() | 30 # Use rootdev to find the underlying block device even if the |
| 30 match = re.search(r'root=([^ ]+)', cmdline) | 31 # system booted to /dev/dm-0. |
| 31 if not match: | 32 device = utils.system_output('rootdev -s -d') |
| 32 raise error.TestError('Unable to find the root partition') | |
| 33 device = match.group(1)[:-1] | |
| 34 | |
| 35 path = self.autodir + '/deps/hdparm/sbin/' | 33 path = self.autodir + '/deps/hdparm/sbin/' |
| 36 hdparm = utils.run(path + 'hdparm -I %s' % device) | 34 hdparm = utils.run(path + 'hdparm -I %s' % device) |
| 37 | 35 |
| 38 # Check if device is a SSD | 36 # Check if device is a SSD |
| 39 match = re.search(r'Nominal Media Rotation Rate: (.+)$', | 37 match = re.search(r'Nominal Media Rotation Rate: (.+)$', |
| 40 hdparm.stdout, re.MULTILINE) | 38 hdparm.stdout, re.MULTILINE) |
| 41 if match and match.group(1): | 39 if match and match.group(1): |
| 42 if match.group(1) != 'Solid State Device': | 40 if match.group(1) != 'Solid State Device': |
| 43 raise error.TestFail('The main disk is not a SSD, ' | 41 raise error.TestFail('The main disk is not a SSD, ' |
| 44 'Rotation Rate: %s' % match.group(1)) | 42 'Rotation Rate: %s' % match.group(1)) |
| 45 else: | 43 else: |
| 46 raise error.TestFail( | 44 raise error.TestFail( |
| 47 'Rotation Rate not reported from the device, ' | 45 'Rotation Rate not reported from the device, ' |
| 48 'unable to ensure it is a SSD') | 46 'unable to ensure it is a SSD') |
| 49 | |
| 50 | 47 |
| 51 # Check if SSD is > 8GB in size | 48 # Check if SSD is > 8GB in size |
| 52 match = re.search("device size with M = 1000\*1000: (.+) MBytes", | 49 match = re.search("device size with M = 1000\*1000: (.+) MBytes", |
| 53 hdparm.stdout, re.MULTILINE) | 50 hdparm.stdout, re.MULTILINE) |
| 54 | 51 |
| 55 if match and match.group(1): | 52 if match and match.group(1): |
| 56 size = int(match.group(1)) | 53 size = int(match.group(1)) |
| 57 self.write_perf_keyval({"mb_ssd_device_size" : size}) | 54 self.write_perf_keyval({"mb_ssd_device_size" : size}) |
| 58 else: | 55 else: |
| 59 raise error.TestFail( | 56 raise error.TestFail( |
| 60 'Device size info missing from the device') | 57 'Device size info missing from the device') |
| 61 | |
| 62 | |
| 63 | |
| OLD | NEW |