Make app list recommendations ignore KnownResults.
[chromium-blink-merge.git] / testing / legion / test_controller.py
blob2703fadf09398794c1b72821610f3d4ffaf22b80
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.
5 """Defines the test controller base library.
7 This module is the basis on which test controllers are built and executed.
8 """
10 import logging
11 import sys
13 #pylint: disable=relative-import
14 import common_lib
15 import task_controller
16 import task_registration_server
19 class TestController(object):
20 """The base test controller class."""
22 def __init__(self):
23 self._registration_server = (
24 task_registration_server.TaskRegistrationServer())
26 def SetUp(self):
27 """Setup method used by the subclass."""
28 pass
30 def RunTest(self):
31 """Main test method used by the subclass."""
32 raise NotImplementedError()
34 def TearDown(self):
35 """Teardown method used by the subclass."""
36 pass
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
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()
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]
66 self._registration_server.Shutdown()
67 task_controller.TaskController.ReleaseAllTasks()
68 if error:
69 raise error, None, tb #pylint: disable=raising-bad-type