Chromium Code Reviews| 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 """The host test module. | |
| 6 | |
| 7 This module runs on the host machine and is responsible for creating 2 | |
| 8 client machines, waiting for them, and running RPC calls on them. | |
| 9 """ | |
| 10 | |
| 11 # Map the legion directory so we can import the host controller. | |
| 12 import sys | |
| 13 sys.path.append('../../') | |
| 14 | |
| 15 import logging | |
| 16 import time | |
| 17 | |
| 18 import host_controller | |
| 19 | |
| 20 | |
| 21 class ExampleController(host_controller.HostController): | |
| 22 """A simple example controller for a test.""" | |
| 23 | |
| 24 def __init__(self): | |
| 25 super(ExampleController, self).__init__() | |
| 26 self.client1 = None | |
| 27 self.client2 = None | |
| 28 | |
| 29 def CreateClient(self): | |
| 30 """Create a client object and set the proper values.""" | |
| 31 client = self.NewClient('client_test.isolate') | |
| 32 client.AddConfigVars('os', 'Linux') | |
|
Marc-Antoine Ruel (Google)
2015/01/30 21:58:41
Why not pass all these in the constructor? It'd ma
Mike Meade
2015/02/03 01:18:09
Done.
| |
| 33 client.AddConfigVars('multi_machine', '1') | |
| 34 client.AddDimension('os', 'Linux') | |
| 35 client.priority = 0 | |
| 36 client.rpc_timeout = 90 | |
| 37 client.verbose = True | |
| 38 client.Create() | |
| 39 return client | |
| 40 | |
| 41 def SetUp(self): | |
| 42 """Create the client machines and wait until they connect. | |
| 43 | |
| 44 In this call the actual creation of the client machines is done in parallel | |
| 45 by the system. The WaitForConnect calls are performed in series but will | |
| 46 return as soon as the client connects. | |
| 47 """ | |
| 48 self.client1 = self.CreateClient() | |
| 49 self.client2 = self.CreateClient() | |
| 50 self.client1.WaitForConnection(120) | |
| 51 self.client2.WaitForConnection(120) | |
| 52 | |
| 53 def Test(self): | |
| 54 """Run the actual test.""" | |
| 55 self.CallEcho(self.client1) | |
| 56 self.CallEcho(self.client2) | |
| 57 self.CallClientTest(self.client1) | |
| 58 self.CallClientTest(self.client2) | |
| 59 | |
| 60 def CallEcho(self, client): | |
| 61 """Call rpc.Echo on a client.""" | |
| 62 logging.info('Calling Echo on %s', client.name) | |
| 63 logging.info(self.client1.rpc.Echo(client.name)) | |
| 64 | |
| 65 def CallClientTest(self, client): | |
| 66 """Call client_test.py name on a client.""" | |
| 67 logging.info('Calling Subprocess on %s to run "client_test.py %s"', | |
| 68 client.name, client.name) | |
| 69 retcode, stdout, stderr = client.rpc.Subprocess( | |
| 70 ['./client_test.py', client.name]) | |
| 71 logging.info('retcode: %s, stdout: %s, stderr: %s', retcode, stdout, stderr) | |
| 72 | |
| 73 | |
| 74 if __name__ == '__main__': | |
| 75 ExampleController().RunController() | |
| OLD | NEW |