OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 """The test controller for the chromoting localhost browser_tests. | |
7 | |
8 This test uses the legion framework to setup this controller which will run | |
9 the chromoting_integration_tests on a task machine. This is intended to be an | |
10 example Legion-based test for the chromoting team. | |
11 | |
12 The controller will start a task machine to run browser_tests_launcher on. The | |
13 output of these tests are streamed back to the test controller to be output | |
14 on the controller's stdout and stderr channels. The final test output is then | |
15 read and becomes the final output of the controller, mirroring the test's | |
16 pass/fail result. | |
17 """ | |
18 | |
19 import argparse | |
20 import logging | |
21 import os | |
22 import sys | |
23 import time | |
24 | |
25 # Map the legion directory so we can import the host controller. | |
26 SRC_DIR = os.path.join('..', '..', '..') | |
27 sys.path.append(os.path.join(SRC_DIR, 'testing')) | |
28 from legion import test_controller | |
29 | |
30 | |
31 class ExampleController(test_controller.TestController): | |
32 """The test controller for the Chromoting browser_tests.""" | |
33 | |
34 def __init__(self): | |
35 super(ExampleController, self).__init__() | |
36 self.task = None | |
37 self.args = None | |
38 | |
39 def RunTest(self): | |
40 """Main method to run the test code.""" | |
41 self.ParseArgs() | |
42 self.CreateTask() | |
43 self.TestIntegrationTests() | |
44 | |
45 def CreateBrowserTestsLauncherCommand(self): | |
46 return [ | |
47 'python', | |
48 self.TaskAbsPath('../browser_tests_launcher.py'), | |
49 '--commands_file', self.TaskAbsPath(self.args.commands_file), | |
50 '--prod_dir', self.TaskAbsPath(self.args.prod_dir), | |
51 '--cfg_file', self.TaskAbsPath(self.args.cfg_file), | |
52 '--me2me_manifest_file', self.TaskAbsPath( | |
53 self.args.me2me_manifest_file), | |
54 '--it2me_manifest_file', self.TaskAbsPath( | |
55 self.args.it2me_manifest_file), | |
56 '--user_profile_dir', self.args.user_profile_dir, | |
57 ] | |
58 | |
59 def TaskAbsPath(self, path): | |
anandc
2015/03/16 23:24:46
Add an Args section for 'path'?
Mike Meade
2015/03/16 23:35:50
Done.
| |
60 """Returns the absolute path to the resource on the task machine. | |
61 | |
62 Since the test controller and the task machines run in different tmp dirs | |
63 on different machines the absolute path cannot be calculated correctly on | |
64 this machine. This function maps the relative path (from this directory) | |
65 to an absolute path on the task machine. | |
66 """ | |
67 return self.task.rpc.AbsPath(path) | |
68 | |
69 def CreateTask(self): | |
70 """Creates a task object and sets the proper values.""" | |
71 self.task = self.CreateNewTask( | |
72 isolated_hash=self.args.task_machine, | |
73 dimensions={'os': 'Ubuntu-14.04', 'pool': 'Chromoting'}) | |
74 self.task.Create() | |
75 self.task.WaitForConnection() | |
76 | |
77 def ParseArgs(self): | |
78 """Gets the command line args.""" | |
79 parser = argparse.ArgumentParser() | |
80 parser.add_argument('--task_machine', | |
81 help='isolated hash of the task machine.') | |
82 # The rest of the args are taken from | |
83 # testing/chromoting/browser_tests_launcher.py. | |
84 parser.add_argument('-f', '--commands_file', | |
85 help='path to file listing commands to be launched.') | |
86 parser.add_argument('-p', '--prod_dir', | |
87 help='path to folder having product and test binaries.') | |
88 parser.add_argument('-c', '--cfg_file', | |
89 help='path to test host config file.') | |
90 parser.add_argument('--me2me_manifest_file', | |
91 help='path to me2me host manifest file.') | |
92 parser.add_argument('--it2me_manifest_file', | |
93 help='path to it2me host manifest file.') | |
94 parser.add_argument( | |
95 '-u', '--user_profile_dir', | |
96 help='path to user-profile-dir, used by connect-to-host tests.') | |
97 self.args, _ = parser.parse_known_args() | |
98 | |
99 def TestIntegrationTests(self): | |
100 """Runs the integration tests (via browser_tests_launcher.py.""" | |
anandc
2015/03/16 23:24:46
Missing ), or remove (
Mike Meade
2015/03/16 23:35:50
Good catch.
| |
101 # Create a process object, configure it, and start it. | |
102 # All interactions with the process are based on this "proc" key. | |
103 proc = self.task.rpc.subprocess.Process( | |
104 self.CreateBrowserTestsLauncherCommand()) | |
105 # Set the cwd to browser_tests_launcher relative to this directory. | |
106 # This allows browser_test_launcher to use relative paths. | |
107 self.task.rpc.subprocess.SetCwd(proc, '../') | |
108 # Set the task verbosity to true to allow stdout/stderr to be echo'ed to | |
109 # run_task's stdout/stderr on the task machine. This can assist in | |
110 # debugging. | |
111 self.task.rpc.subprocess.SetVerbose(proc) | |
112 # Set the process as detached to create it in a new process group. | |
113 self.task.rpc.subprocess.SetDetached(proc) | |
114 # Start the actual process on the task machine. | |
115 self.task.rpc.subprocess.Start(proc) | |
116 | |
117 # Collect the stdout/stderr and emit it from this controller while the | |
118 # process is running. | |
119 while self.task.rpc.subprocess.Poll(proc) is None: | |
120 # Output the test's stdout and stderr in semi-realtime. | |
anandc
2015/03/16 23:24:46
It would help to explain a bit why it is not fully
Mike Meade
2015/03/16 23:35:50
I added it. There are 2 RPC calls (Poll and ReadOu
| |
121 stdout, stderr = self.task.rpc.subprocess.ReadOutput(proc) | |
122 if stdout: | |
123 sys.stdout.write(stdout) | |
124 if stderr: | |
125 sys.stderr.write(stderr) | |
126 time.sleep(1) | |
127 | |
128 # Get the return code, clean up the process object. | |
129 returncode = self.task.rpc.subprocess.GetReturncode(proc) | |
130 self.task.rpc.subprocess.Delete(proc) | |
131 | |
132 # Pass or fail depending on the return code from the browser_tests_launcher. | |
133 if returncode != 0: | |
134 raise AssertionError('browser_tests_launcher failed with return code ' | |
135 '%i' % returncode) | |
136 | |
137 | |
138 if __name__ == '__main__': | |
139 ExampleController().RunController() | |
OLD | NEW |