Index: build/android/pylib/exit_code.py |
diff --git a/build/android/pylib/exit_code.py b/build/android/pylib/exit_code.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d6afcbc5d9b88baef52c64ad6484b44ac930f50f |
--- /dev/null |
+++ b/build/android/pylib/exit_code.py |
@@ -0,0 +1,50 @@ |
+# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+"""Effectively a singleton for maintaining exit code state of tests.""" |
+ |
+import constants |
+ |
+_exit_code = constants.NORMAL_EXIT_CODE |
+ |
+VALID_EXIT_CODES = [constants.ERROR_EXIT_CODE, |
+ constants.WARNING_EXIT_CODE, |
+ constants.NORMAL_EXIT_CODE] |
+ |
+ |
+class InvalidExitCodeError(Exception): |
+ """Invalid exit code observed.""" |
+ |
+ |
+def UpdateExitCode(new_exit_code): |
+ """Updates the exit code with some checking and priority. |
+ |
+ Args: |
+ new_exit_code: The exit code to update to. |
+ |
+ Raises: |
+ InvalidExitCodeError: If |new_exit_code| is not in the set of |
+ valid exit codes. |
+ """ |
+ |
+ if new_exit_code not in VALID_EXIT_CODES: |
+ raise InvalidExitCodeError('Observed exit code: %s' % new_exit_code) |
+ |
+ # Only escalate exit codes |
+ global _exit_code |
+ if (_exit_code == constants.WARNING_EXIT_CODE and |
+ new_exit_code == constants.ERROR_EXIT_CODE): |
+ _exit_code = new_exit_code |
+ elif _exit_code == constants.NORMAL_EXIT_CODE: |
+ _exit_code = new_exit_code |
+ |
+ |
+def ResetExitCode(): |
+ global _exit_code |
+ _exit_code = constants.NORMAL_EXIT_CODE |
+ |
+ |
+def GetExitCode(): |
+ global _exit_code |
+ return _exit_code |