blob: 5f7df2414a6df639d87cbfd30291c9d0741d74dc [file] [log] [blame]
Puthikorn Voravootivataccfca62014-03-11 14:54:24 -07001# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import logging, os, re
Puthikorn Voravootivat68d47782014-06-12 17:45:22 -07006from autotest_lib.client.bin import test, utils
Puthikorn Voravootivataccfca62014-03-11 14:54:24 -07007from autotest_lib.client.common_lib import error
8
9
10class hardware_StorageWearoutDetect(test.test):
11 """
12 Check wear out status for storage device available in SMART for SSD and
13 in ext_csd for eMMC version 5.0 or later. For previous version of eMMC,
14 it will be treat as data not available.
15
16 The test will be failed if:
17 - At least one SMART variable has value under its threshold
18 or
Ilja H. Friedela4a6ed82016-06-17 14:49:04 -070019 - eMMC wear out status variable is in 90-100% band or higher (
20 DEVICE_LIFE_TIME_EST_TYP_A). Seeing this consistently means the lab
21 device may have to be replaced.
Puthikorn Voravootivataccfca62014-03-11 14:54:24 -070022 """
23
24 version = 1
25 STORAGE_INFO_PATH = '/var/log/storage_info.txt'
Puthikorn Voravootivat68d47782014-06-12 17:45:22 -070026 STORAGE_INFO_UPDATE_PATH = '/usr/share/userfeedback/scripts/storage_info'
Puthikorn Voravootivataccfca62014-03-11 14:54:24 -070027
28 # Example " Model Number: LITEONIT LSS-32L6G-HP"
29 SSD_DETECT = r"\s*Model Number:\s*(?P<model>.*)\s*$"
30
31 # Example " Extended CSD rev 1.7 (MMC 5.0)"
32 MMC_DETECT = r"\s*Extended CSD rev.*MMC (?P<version>\d+.\d+)"
33
34 # Field meaning and example line that have failing attribute
35 # ID# ATTRIBUTE_NAME FLAGS VALUE WORST THRESH FAIL RAW_VALUE
36 # 184 End-to-End_Error PO--CK 001 001 097 NOW 135
37 SSD_FAIL = r"""\s*(?P<param>\S+\s\S+) # ID and attribute name
38 \s+[P-][O-][S-][R-][C-][K-] # flags
39 (\s+\d{3}){3} # three 3-digits numbers
40 \s+NOW # fail indicator"""
41
42 # Ex "Device life time estimation type A [DEVICE_LIFE_TIME_EST_TYP_A: 0x01]"
43 # 0x0a means 90-100% band, 0x0b means over 100% band -> find not digit
44 MMC_FAIL = r".*(?P<param>DEVICE_LIFE_TIME_EST_TYP_.): 0x0\D"
45
46
Puthikorn Voravootivat68d47782014-06-12 17:45:22 -070047 def run_once(self, use_cached_result=True):
Puthikorn Voravootivataccfca62014-03-11 14:54:24 -070048 """
49 Run the test
Puthikorn Voravootivat68d47782014-06-12 17:45:22 -070050
51 @param use_cached_result: Use the result that generated when machine
52 booted or generate new one.
Puthikorn Voravootivataccfca62014-03-11 14:54:24 -070053 """
Puthikorn Voravootivat68d47782014-06-12 17:45:22 -070054
55 if not use_cached_result:
56 if not os.path.exists(self.STORAGE_INFO_UPDATE_PATH):
57 msg = str('Test failed with error: %s not exist'
58 % self.STORAGE_INFO_UPDATE_PATH)
59 raise error.TestFail(msg)
60 utils.system(self.STORAGE_INFO_UPDATE_PATH)
61
Puthikorn Voravootivataccfca62014-03-11 14:54:24 -070062 # Check that storage_info file exist.
63 if not os.path.exists(self.STORAGE_INFO_PATH):
64 msg = str('Test failed with error: %s not exist'
65 % self.STORAGE_INFO_PATH)
66 raise error.TestFail(msg)
67
68 mmc_detect = False
69 ssd_detect = False
70 legacy_mmc = False
71 fail_msg = ''
72
73 with open(self.STORAGE_INFO_PATH) as f:
74 for line in f:
75 m = re.match(self.SSD_DETECT, line)
76 if m:
77 model = m.group('model')
78 ssd_detect = True
Puthikorn Voravootivatb6cc2a92014-06-05 11:12:39 -070079 logging.info('Found SSD model %s', model)
Puthikorn Voravootivataccfca62014-03-11 14:54:24 -070080
81 m = re.match(self.MMC_DETECT, line)
82 if m:
83 version = m.group('version')
84 if float(version) < 5.0:
85 legacy_mmc = True
86 mmc_detect = True
Puthikorn Voravootivatb6cc2a92014-06-05 11:12:39 -070087 logging.info('Found eMMC version %s', version)
Puthikorn Voravootivataccfca62014-03-11 14:54:24 -070088
89 m = re.match(self.SSD_FAIL, line, re.X)
90 if m:
91 param = m.group('param')
Kris Rambishc8d5a522014-10-24 14:47:40 -070092 fail_msg += 'SSD failure ' + param
Puthikorn Voravootivataccfca62014-03-11 14:54:24 -070093
94 m = re.match(self.MMC_FAIL, line)
95 if m:
96 param = m.group('param')
Kris Rambishc8d5a522014-10-24 14:47:40 -070097 fail_msg += 'MMC failure ' + param
Puthikorn Voravootivataccfca62014-03-11 14:54:24 -070098
99 if not ssd_detect and not mmc_detect:
Puthikorn Voravootivatb6cc2a92014-06-05 11:12:39 -0700100 raise error.TestFail('Can not detect storage device.')
Puthikorn Voravootivataccfca62014-03-11 14:54:24 -0700101
102 if fail_msg:
Puthikorn Voravootivatb6cc2a92014-06-05 11:12:39 -0700103 msg = 'Detected wearout parameter:%s' % fail_msg
Puthikorn Voravootivataccfca62014-03-11 14:54:24 -0700104 raise error.TestFail(msg)
105
106 if legacy_mmc:
Puthikorn Voravootivatb6cc2a92014-06-05 11:12:39 -0700107 msg = 'eMMC version %s detected. ' % version
108 msg += 'Wearout attributes are supported in eMMC 5.0 and later.'
Kris Rambishde9dc252014-07-31 14:38:39 -0700109 logging.info(msg)