Puthikorn Voravootivat | accfca6 | 2014-03-11 14:54:24 -0700 | [diff] [blame] | 1 | # 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 | |
| 5 | import logging, os, re |
Puthikorn Voravootivat | 68d4778 | 2014-06-12 17:45:22 -0700 | [diff] [blame] | 6 | from autotest_lib.client.bin import test, utils |
Puthikorn Voravootivat | accfca6 | 2014-03-11 14:54:24 -0700 | [diff] [blame] | 7 | from autotest_lib.client.common_lib import error |
| 8 | |
| 9 | |
| 10 | class 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. Friedel | a4a6ed8 | 2016-06-17 14:49:04 -0700 | [diff] [blame^] | 19 | - 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 Voravootivat | accfca6 | 2014-03-11 14:54:24 -0700 | [diff] [blame] | 22 | """ |
| 23 | |
| 24 | version = 1 |
| 25 | STORAGE_INFO_PATH = '/var/log/storage_info.txt' |
Puthikorn Voravootivat | 68d4778 | 2014-06-12 17:45:22 -0700 | [diff] [blame] | 26 | STORAGE_INFO_UPDATE_PATH = '/usr/share/userfeedback/scripts/storage_info' |
Puthikorn Voravootivat | accfca6 | 2014-03-11 14:54:24 -0700 | [diff] [blame] | 27 | |
| 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 Voravootivat | 68d4778 | 2014-06-12 17:45:22 -0700 | [diff] [blame] | 47 | def run_once(self, use_cached_result=True): |
Puthikorn Voravootivat | accfca6 | 2014-03-11 14:54:24 -0700 | [diff] [blame] | 48 | """ |
| 49 | Run the test |
Puthikorn Voravootivat | 68d4778 | 2014-06-12 17:45:22 -0700 | [diff] [blame] | 50 | |
| 51 | @param use_cached_result: Use the result that generated when machine |
| 52 | booted or generate new one. |
Puthikorn Voravootivat | accfca6 | 2014-03-11 14:54:24 -0700 | [diff] [blame] | 53 | """ |
Puthikorn Voravootivat | 68d4778 | 2014-06-12 17:45:22 -0700 | [diff] [blame] | 54 | |
| 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 Voravootivat | accfca6 | 2014-03-11 14:54:24 -0700 | [diff] [blame] | 62 | # 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 Voravootivat | b6cc2a9 | 2014-06-05 11:12:39 -0700 | [diff] [blame] | 79 | logging.info('Found SSD model %s', model) |
Puthikorn Voravootivat | accfca6 | 2014-03-11 14:54:24 -0700 | [diff] [blame] | 80 | |
| 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 Voravootivat | b6cc2a9 | 2014-06-05 11:12:39 -0700 | [diff] [blame] | 87 | logging.info('Found eMMC version %s', version) |
Puthikorn Voravootivat | accfca6 | 2014-03-11 14:54:24 -0700 | [diff] [blame] | 88 | |
| 89 | m = re.match(self.SSD_FAIL, line, re.X) |
| 90 | if m: |
| 91 | param = m.group('param') |
Kris Rambish | c8d5a52 | 2014-10-24 14:47:40 -0700 | [diff] [blame] | 92 | fail_msg += 'SSD failure ' + param |
Puthikorn Voravootivat | accfca6 | 2014-03-11 14:54:24 -0700 | [diff] [blame] | 93 | |
| 94 | m = re.match(self.MMC_FAIL, line) |
| 95 | if m: |
| 96 | param = m.group('param') |
Kris Rambish | c8d5a52 | 2014-10-24 14:47:40 -0700 | [diff] [blame] | 97 | fail_msg += 'MMC failure ' + param |
Puthikorn Voravootivat | accfca6 | 2014-03-11 14:54:24 -0700 | [diff] [blame] | 98 | |
| 99 | if not ssd_detect and not mmc_detect: |
Puthikorn Voravootivat | b6cc2a9 | 2014-06-05 11:12:39 -0700 | [diff] [blame] | 100 | raise error.TestFail('Can not detect storage device.') |
Puthikorn Voravootivat | accfca6 | 2014-03-11 14:54:24 -0700 | [diff] [blame] | 101 | |
| 102 | if fail_msg: |
Puthikorn Voravootivat | b6cc2a9 | 2014-06-05 11:12:39 -0700 | [diff] [blame] | 103 | msg = 'Detected wearout parameter:%s' % fail_msg |
Puthikorn Voravootivat | accfca6 | 2014-03-11 14:54:24 -0700 | [diff] [blame] | 104 | raise error.TestFail(msg) |
| 105 | |
| 106 | if legacy_mmc: |
Puthikorn Voravootivat | b6cc2a9 | 2014-06-05 11:12:39 -0700 | [diff] [blame] | 107 | msg = 'eMMC version %s detected. ' % version |
| 108 | msg += 'Wearout attributes are supported in eMMC 5.0 and later.' |
Kris Rambish | de9dc25 | 2014-07-31 14:38:39 -0700 | [diff] [blame] | 109 | logging.info(msg) |