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, subprocess 7 8from autotest_lib.client.bin import test, utils 9from autotest_lib.client.common_lib import error 10 11class hardware_UnsafeMemory(test.test): 12 """ 13 This test runs for the specified number of seconds 14 checking for user-controllable memory corruption using 15 the rowhammer-test tools: 16 https://code.google.com/a/google.com/p/rowhammer-test 17 """ 18 19 version = 1 20 _DIR_NAME = 'rowhammer-test-4d619293e1c7' 21 22 def setup(self): 23 os.chdir(os.path.join(self.srcdir, self._DIR_NAME)) 24 utils.make('clean') 25 utils.make('all') 26 27 def get_thermals(self): 28 therm0 = '-' 29 therm1 = '-' 30 try: 31 therm0 = utils.read_file( 32 '/sys/devices/virtual/thermal/thermal_zone0/temp') 33 except: 34 pass 35 try: 36 therm1 = utils.read_file( 37 '/sys/devices/virtual/thermal/thermal_zone1/temp') 38 except: 39 pass 40 return ' '.join([therm0, therm1]) 41 42 def run_once(self, sec=(60*25)): 43 """ 44 Executes the test and logs the output. 45 46 @param sec: seconds to test memory 47 """ 48 self._hammer_path = os.path.join(self.srcdir, self._DIR_NAME, 49 'rowhammer_test') 50 logging.info('cmd: %s %d', self._hammer_path, sec) 51 # Grab the CPU temperature before hand if possible. 52 logging.info('start temp: %s', self.get_thermals()) 53 try: 54 output = subprocess.check_output([self._hammer_path, '%d' % sec]) 55 logging.info("run complete. Output below:") 56 logging.info(output) 57 except subprocess.CalledProcessError as e: 58 logging.error("Unsafe memory found!") 59 logging.error(e.output) 60 logging.info('end temp: %s', self.get_thermals()) 61 raise error.TestFail('Unsafe memory found!') 62 logging.info('end temp: %s', self.get_thermals()) 63 return True 64