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