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 5import logging, os 6from autotest_lib.client.bin import test, utils 7from autotest_lib.client.common_lib import error 8 9 10class hardware_StorageTrim(test.test): 11 """ 12 Measure write performance before and after trim. 13 14 Use fio to measure write performance. 15 Use mkfs.ext4 to trim device. 16 """ 17 18 version = 1 19 20 21 def run_once(self, dev='/dev/sda'): 22 """ 23 Measure write performance before and after trim. 24 25 This test use an entire disk so we need to boot from usb. 26 27 @param dev: block device to test 28 """ 29 logging.info('Target device: %s', dev) 30 31 # Check that device exist. 32 if not os.path.exists(dev): 33 msg = 'Test failed with error: %s not exist' % dev 34 raise error.TestFail(msg) 35 36 # Check that device is not rootdev. 37 rootdev = utils.get_root_device() 38 if dev == rootdev: 39 raise error.TestFail('Can not test on root device') 40 41 # Use fio to fill device first. 42 self.job.run_test('hardware_StorageFio', 43 disable_sysinfo=True, 44 dev=dev, 45 filesize=0, 46 requirements=[('disk_fill', [])], 47 tag='disk_fill') 48 49 # Use 4k random write with queue depth = 32 because manufacture usually 50 # uses this use case in the SSD specification. 51 # Also, print result every minute to look at the performance drop trend 52 # over time. Result reported by autotest will be the last minute one. 53 requirements = [('4k_write_qd32', ['--status-interval=60'])] 54 55 # Check write performance 56 self.job.run_test('hardware_StorageFio', 57 disable_sysinfo=True, 58 dev=dev, 59 filesize=0, 60 requirements=requirements, 61 tag='before_trim') 62 63 # Unmount drive to make it possible to format. 64 utils.run('umount %s*' % dev, ignore_status=True) 65 # Format whole drive to ext4. Mkfs will trim the drive before format. 66 utils.run('mkfs.ext4 -F %s' % dev, ignore_status=True) 67 68 # Check write performance 69 self.job.run_test('hardware_StorageFio', 70 disable_sysinfo=True, 71 dev=dev, 72 filesize=0, 73 requirements=requirements, 74 tag='after_trim') 75 76