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