150618caef7d4ca20532f505013cae19e0f78600dSean O'Connor# Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 250618caef7d4ca20532f505013cae19e0f78600dSean O'Connor# Use of this source code is governed by a BSD-style license that can be 350618caef7d4ca20532f505013cae19e0f78600dSean O'Connor# found in the LICENSE file. 450618caef7d4ca20532f505013cae19e0f78600dSean O'Connor 550618caef7d4ca20532f505013cae19e0f78600dSean O'Connor 650618caef7d4ca20532f505013cae19e0f78600dSean O'Connorimport os, random, subprocess, time 750618caef7d4ca20532f505013cae19e0f78600dSean O'Connorimport commands, logging, random, time, utils 850618caef7d4ca20532f505013cae19e0f78600dSean O'Connorfrom autotest_lib.client.bin import site_utils, test 950618caef7d4ca20532f505013cae19e0f78600dSean O'Connorfrom autotest_lib.client.common_lib import error 1050618caef7d4ca20532f505013cae19e0f78600dSean O'Connor 1150618caef7d4ca20532f505013cae19e0f78600dSean O'ConnorSUSPEND_START = '/tmp/power_state_cycle_begin' 1250618caef7d4ca20532f505013cae19e0f78600dSean O'ConnorSUSPEND_END = '/tmp/power_state_cycle_end' 1350618caef7d4ca20532f505013cae19e0f78600dSean O'ConnorCRYPTOHOMESTRESS_START = '/tmp/cryptohomestress_begin' 1450618caef7d4ca20532f505013cae19e0f78600dSean O'ConnorCRYPTOHOMESTRESS_END = '/tmp/cryptohomestress_end' 1550618caef7d4ca20532f505013cae19e0f78600dSean O'Connor 1650618caef7d4ca20532f505013cae19e0f78600dSean O'Connorclass platform_CryptohomeStress(test.test): 1750618caef7d4ca20532f505013cae19e0f78600dSean O'Connor version = 1 1850618caef7d4ca20532f505013cae19e0f78600dSean O'Connor def initialize(self): 1950618caef7d4ca20532f505013cae19e0f78600dSean O'Connor for signal_file in [SUSPEND_END, CRYPTOHOMESTRESS_END]: 2050618caef7d4ca20532f505013cae19e0f78600dSean O'Connor if os.path.exists(signal_file): 2150618caef7d4ca20532f505013cae19e0f78600dSean O'Connor logging.warning('removing existing stop file %s' % signal_file) 2250618caef7d4ca20532f505013cae19e0f78600dSean O'Connor os.unlink(signal_file) 2350618caef7d4ca20532f505013cae19e0f78600dSean O'Connor random.seed() # System time is fine. 2450618caef7d4ca20532f505013cae19e0f78600dSean O'Connor 2550618caef7d4ca20532f505013cae19e0f78600dSean O'Connor 2650618caef7d4ca20532f505013cae19e0f78600dSean O'Connor def run_once(self, runtime=300): 2750618caef7d4ca20532f505013cae19e0f78600dSean O'Connor # check that fio has started, waiting for up to TIMEOUT 2850618caef7d4ca20532f505013cae19e0f78600dSean O'Connor site_utils.poll_for_condition( 2950618caef7d4ca20532f505013cae19e0f78600dSean O'Connor lambda: os.path.exists(CRYPTOHOMESTRESS_START), 3050618caef7d4ca20532f505013cae19e0f78600dSean O'Connor error.TestFail('fiostress not triggered.'), 3150618caef7d4ca20532f505013cae19e0f78600dSean O'Connor timeout=30, sleep_interval=1) 3250618caef7d4ca20532f505013cae19e0f78600dSean O'Connor open(SUSPEND_START, 'w').close() 3350618caef7d4ca20532f505013cae19e0f78600dSean O'Connor # Pad disk stress runtime by 60s for safety. 3450618caef7d4ca20532f505013cae19e0f78600dSean O'Connor runtime = runtime + 60 3550618caef7d4ca20532f505013cae19e0f78600dSean O'Connor site_utils.poll_for_condition( 3650618caef7d4ca20532f505013cae19e0f78600dSean O'Connor lambda: os.path.exists(CRYPTOHOMESTRESS_END), 3750618caef7d4ca20532f505013cae19e0f78600dSean O'Connor error.TestFail('fiostress runtime exceeded.'), 3850618caef7d4ca20532f505013cae19e0f78600dSean O'Connor timeout=runtime, sleep_interval=10) 3950618caef7d4ca20532f505013cae19e0f78600dSean O'Connor 4050618caef7d4ca20532f505013cae19e0f78600dSean O'Connor def cleanup(self): 4150618caef7d4ca20532f505013cae19e0f78600dSean O'Connor open(SUSPEND_END, 'w').close() 4250618caef7d4ca20532f505013cae19e0f78600dSean O'Connor 43