OLD | NEW |
| (Empty) |
1 # Copyright 2015 The Chromium 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 | |
5 """Defines the test controller base library. | |
6 | |
7 This module is the basis on which test controllers are built and executed. | |
8 """ | |
9 | |
10 import logging | |
11 import sys | |
12 | |
13 #pylint: disable=relative-import | |
14 import common_lib | |
15 import task_controller | |
16 import task_registration_server | |
17 | |
18 | |
19 class TestController(object): | |
20 """The base test controller class.""" | |
21 | |
22 def __init__(self): | |
23 self._registration_server = ( | |
24 task_registration_server.TaskRegistrationServer()) | |
25 | |
26 def SetUp(self): | |
27 """Setup method used by the subclass.""" | |
28 pass | |
29 | |
30 def RunTest(self): | |
31 """Main test method used by the subclass.""" | |
32 raise NotImplementedError() | |
33 | |
34 def TearDown(self): | |
35 """Teardown method used by the subclass.""" | |
36 pass | |
37 | |
38 def CreateNewTask(self, *args, **kwargs): | |
39 task = task_controller.TaskController(*args, **kwargs) | |
40 self._registration_server.RegisterTaskCallback( | |
41 task.otp, task.OnConnect) | |
42 return task | |
43 | |
44 def RunController(self): | |
45 """Main entry point for the controller.""" | |
46 print ' '.join(sys.argv) | |
47 common_lib.InitLogging() | |
48 self._registration_server.Start() | |
49 | |
50 error = None | |
51 tb = None | |
52 try: | |
53 self.SetUp() | |
54 self.RunTest() | |
55 except Exception as e: | |
56 # Defer raising exceptions until after TearDown is called. | |
57 error = e | |
58 tb = sys.exc_info()[-1] | |
59 try: | |
60 self.TearDown() | |
61 except Exception as e: | |
62 if not tb: | |
63 error = e | |
64 tb = sys.exc_info()[-1] | |
65 | |
66 self._registration_server.Shutdown() | |
67 task_controller.TaskController.ReleaseAllTasks() | |
68 if error: | |
69 raise error, None, tb #pylint: disable=raising-bad-type | |
OLD | NEW |