• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2010 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
6from autotest_lib.client.bin import test
7from autotest_lib.client.common_lib import error
8
9# A global variable to track how many times the test has been run.
10global retry_count
11retry_count = 0
12
13class dummy_Fail(test.test):
14    """The test fails by raising given exception, or succeeds at given retry."""
15    version = 1
16
17    def run_once(self, to_throw=None, retry_success_count=0):
18        """Run test with argument to_throw, retry_count and retry_success_count.
19
20        @param to_throw: Exception to throw in the test.
21        @param retry_success_count: The number of times to fail before test is
22                    completed successfully. 0 means the test will never complete
23                    successfully with reties.
24
25        """
26        global retry_count
27        retry_count += 1
28        if retry_count == retry_success_count:
29            return
30        if to_throw:
31            if to_throw == 'TestFail': logging.error('It is an error!')
32            raise getattr(error, to_throw)('always fail')
33        else:  # Generate a crash to test that behavior.
34            self.write_perf_keyval({'perf_key': 102.7})
35            self.job.record('INFO', self.tagged_testname,
36                            'Received crash notification for sleep[273] sig 6')
37