Chromium Code Reviews| Index: testing/legion/examples/hello_world/host_test.py |
| diff --git a/testing/legion/examples/hello_world/host_test.py b/testing/legion/examples/hello_world/host_test.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..a741df5114b0e2d6ba7929c09320d6d580b1b998 |
| --- /dev/null |
| +++ b/testing/legion/examples/hello_world/host_test.py |
| @@ -0,0 +1,75 @@ |
| +#!/usr/bin/env python |
| +# Copyright 2015 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. |
| +"""The host test module. |
| + |
| +This module runs on the host machine and is responsible for creating 2 |
| +client machines, waiting for them, and running RPC calls on them. |
| +""" |
| + |
| +# Map the legion directory so we can import the host controller. |
| +import sys |
| +sys.path.append('../../') |
| + |
| +import logging |
| +import time |
| + |
| +import host_controller |
| + |
| + |
| +class ExampleController(host_controller.HostController): |
| + """A simple example controller for a test.""" |
| + |
| + def __init__(self): |
| + super(ExampleController, self).__init__() |
| + self.client1 = None |
| + self.client2 = None |
| + |
| + def CreateClient(self): |
| + """Create a client object and set the proper values.""" |
| + client = self.NewClient('client_test.isolate') |
| + 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.
|
| + client.AddConfigVars('multi_machine', '1') |
| + client.AddDimension('os', 'Linux') |
| + client.priority = 0 |
| + client.rpc_timeout = 90 |
| + client.verbose = True |
| + client.Create() |
| + return client |
| + |
| + def SetUp(self): |
| + """Create the client machines and wait until they connect. |
| + |
| + In this call the actual creation of the client machines is done in parallel |
| + by the system. The WaitForConnect calls are performed in series but will |
| + return as soon as the client connects. |
| + """ |
| + self.client1 = self.CreateClient() |
| + self.client2 = self.CreateClient() |
| + self.client1.WaitForConnection(120) |
| + self.client2.WaitForConnection(120) |
| + |
| + def Test(self): |
| + """Run the actual test.""" |
| + self.CallEcho(self.client1) |
| + self.CallEcho(self.client2) |
| + self.CallClientTest(self.client1) |
| + self.CallClientTest(self.client2) |
| + |
| + def CallEcho(self, client): |
| + """Call rpc.Echo on a client.""" |
| + logging.info('Calling Echo on %s', client.name) |
| + logging.info(self.client1.rpc.Echo(client.name)) |
| + |
| + def CallClientTest(self, client): |
| + """Call client_test.py name on a client.""" |
| + logging.info('Calling Subprocess on %s to run "client_test.py %s"', |
| + client.name, client.name) |
| + retcode, stdout, stderr = client.rpc.Subprocess( |
| + ['./client_test.py', client.name]) |
| + logging.info('retcode: %s, stdout: %s, stderr: %s', retcode, stdout, stderr) |
| + |
| + |
| +if __name__ == '__main__': |
| + ExampleController().RunController() |