blob: e9fb6735f2a84842faf739869353656bf0f36d30 [file] [log] [blame]
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import re
from autotest_lib.client.bin import test, utils
from autotest_lib.client.common_lib import error
class hardware_SsdDetection(test.test):
"""Verify that a flash device is present. """
version = 1
# Keep a list of boards that are expected to ship with hard drive.
boards_with_hdd = ['butterfly', 'kiev', 'parrot', 'stout']
def setup(self):
create a empty srcdir to prevent the error that checks
.version file
if not os.path.exists(self.srcdir):
utils.system('mkdir %s' % self.srcdir)
def run_once(self, check_link_speed=()):
Use rootdev to find the underlying block device even if the
system booted to /dev/dm-0.
device = utils.get_root_device()
def is_fixed(dev):
""" Check the device is fixed.
@param dev: device to check, i.e. 'sda'.
sysfs_path = '/sys/block/%s/removable' % dev
return (os.path.exists(sysfs_path) and
open(sysfs_path).read().strip() == '0')
# Catch device name like sda, mmcblk0, nvme0n1.
device_re = re.compile(r'^/dev/([a-zA-Z0-9]+)$')
dev = device_re.findall(device)
if len(dev) != 1 or not is_fixed(dev[0]):
raise error.TestFail('The main disk %s is not fixed' % dev)
# If it is an mmcblk or nvme device, then it is SSD.
# Else run hdparm to check for SSD.
if"nvme", device):
if"mmcblk", device):
type_path = '/sys/block/%s/device/type' % dev[0]
type = os.path.realpath(type_path)
if"ufs", type):
hdparm ='/sbin/hdparm -I %s' % device)
# Check if device is a SSD
match ='Nominal Media Rotation Rate: (.+)$',
hdparm.stdout, re.MULTILINE)
if match and
if != 'Solid State Device':
if utils.get_board() in self.boards_with_hdd:
raise error.TestFail('The main disk is not a SSD, '
'Rotation Rate: %s' %
raise error.TestFail(
'Rotation Rate not reported from the device, '
'unable to ensure it is a SSD')
# Check if SSD is > 8GB in size
match ="device size with M = 1000\*1000: (.+) MBytes",
hdparm.stdout, re.MULTILINE)
if match and
size = int(
self.write_perf_keyval({"mb_ssd_device_size" : size})
raise error.TestFail(
'Device size info missing from the device')
# Check supported link speed.
# check_link_speed is an empty tuple by default, which does not perform
# link speed checking. You can run the test while specifying
# check_link_speed=('1.5Gb/s', '3.0Gb/s') to check the 2 signaling
# speeds are both supported.
for link_speed in check_link_speed:
if not'Gen. signaling speed \(%s\)' % link_speed,
hdparm.stdout, re.MULTILINE):
raise error.TestFail('Link speed %s not supported' % link_speed)