• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, time
6from autotest_lib.client.bin import utils
7from autotest_lib.client.common_lib import error
8from autotest_lib.server import autotest
9from autotest_lib.server import hosts
10from autotest_lib.server import test
11
12class hardware_MemoryIntegrity(test.test):
13    """
14    Integrity test for memory device
15    """
16    version = 1
17    suspend_fail = False
18
19    # Define default value for the test case
20
21    def _determine_usable_memory(self):
22        """
23        Determine size of memory to test.
24        """
25        self._client_at.run_test('hardware_RamFio', size=0, dry_run=True)
26
27        keyval_path = os.path.join(self.outputdir,
28                                   'hardware_RamFio',
29                                   'results',
30                                   'keyval')
31
32        return utils.read_keyval(keyval_path, type_tag='perf')['Size']
33
34
35    def _create_ramfs(self):
36        """
37        Create ramfs mount directory on client
38        """
39        self._client.run('mkdir -p /tmp/ramdisk')
40        self._client.run('mount -t ramfs ramfs /tmp/ramdisk')
41
42
43    def _write_test_data(self, size):
44        """
45        Write test data using hardware_StorageFio.
46        """
47        self._client_at.run_test('hardware_StorageFio',
48                                 tag='_write_test_data',
49                                 dev='/tmp/ramdisk/test_file',
50                                 size=size,
51                                 requirements=[('8k_async_randwrite', [])])
52
53
54    def _wait(self, seconds, suspend):
55        """
56        Wait for specifed time. Also suspend if specified.
57        """
58        if suspend:
59            self._client.suspend(suspend_time=seconds)
60        else:
61            time.sleep(seconds)
62
63
64    def _verify_test_data(self, size):
65        """
66        Verify integrity of written data using hardware_StorageFio.
67        """
68        # 'v' option means verify only
69        self._client_at.run_test('hardware_StorageFio',
70                                 tag='_verify_test_data',
71                                 dev='/tmp/ramdisk/test_file',
72                                 size=size,
73                                 wait=0,
74                                 requirements=[('8k_async_randwrite', ['v'])])
75
76    def _check_alive(self):
77        """
78        Check that client is still alived. Raise error if not.
79        """
80        if not self._client.ping_wait_up(30):
81            raise error.TestFail("Test fail: Client died")
82
83    def _clean_up(self):
84        """
85        Cleanup the system. Unmount the ram disk.
86        """
87        self._client.run('umount /tmp/ramdisk')
88
89
90    def run_once(self, client_ip=None, seconds=3600, size=0, suspend=True):
91        """
92        Run the test
93        Use ram drive and hardware_Storage fio verify feature to verify the
94        integrity of memory system. The test will write data to memory and then
95        idle or suspend for specify time and verify the integrity of that data.
96
97        @param client_ip: string of client's ip address (required)
98        @param seconds:   seconds to idle / suspend. default = 3600 (1 hour)
99        @param size:      size to used. 0 means use all tesable memory (default)
100        @param suspend:   set to suspend between write and verify phase.
101        """
102
103        if not client_ip:
104            error.TestError("Must provide client's IP address to test")
105
106        self._client = hosts.create_host(client_ip)
107        self._client_at = autotest.Autotest(self._client)
108
109        if size == 0:
110            size = self._determine_usable_memory()
111        logging.info('size: %d', size)
112
113        self._create_ramfs()
114
115        self._write_test_data(size)
116
117        self._check_alive()
118        self._wait(seconds, suspend)
119        self._check_alive()
120
121        self._verify_test_data(size)
122
123        self._check_alive()
124        self._clean_up()
125