Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """A simple host test module. | 6 """A simple host test module. |
| 7 | 7 |
| 8 This module runs on the host machine and is responsible for creating 2 | 8 This module runs on the host machine and is responsible for creating 2 |
| 9 task machines, waiting for them, and running RPC calls on them. | 9 task machines, waiting for them, and running RPC calls on them. |
| 10 """ | 10 """ |
| 11 | 11 |
| 12 import argparse | 12 import argparse |
| 13 import logging | 13 import logging |
| 14 import os | 14 import os |
| 15 import sys | 15 import sys |
| 16 import time | 16 import time |
| 17 | 17 |
| 18 # Map the testing directory so we can import legion.legion_test. | 18 # Map the testing directory so we can import legion.legion_test. |
| 19 TESTING_DIR = os.path.join( | 19 TESTING_DIR = os.path.join( |
| 20 os.path.dirname(os.path.abspath(__file__)), | 20 os.path.dirname(os.path.abspath(__file__)), |
| 21 '..', '..', '..', '..', 'testing') | 21 '..', '..', '..', '..', 'testing') |
| 22 sys.path.append(TESTING_DIR) | 22 sys.path.append(TESTING_DIR) |
| 23 | 23 |
| 24 from legion import legion_test_case | 24 from legion import legion_test_case |
| 25 from legion.lib import common_lib | |
| 25 | 26 |
| 26 | 27 |
| 27 class ExampleTestController(legion_test_case.TestCase): | 28 class EventTestController(legion_test_case.TestCase): |
| 28 """A simple example controller for a test.""" | 29 """A simple example controller for a test.""" |
| 29 | 30 |
| 30 @classmethod | 31 @classmethod |
| 31 def CreateTestTask(cls): | 32 def CreateTestTask(cls): |
| 32 """Create a new task.""" | 33 """Create a new task.""" |
| 33 parser = argparse.ArgumentParser() | 34 parser = argparse.ArgumentParser() |
| 34 parser.add_argument('--task-hash') | 35 parser.add_argument('--task') |
|
M-A Ruel
2016/01/15 14:07:13
I think it'd be a good idea to have a description
Mike Meade
2016/01/18 20:25:51
Changed to task-hash to be more descriptive and mo
| |
| 35 parser.add_argument('--os', default='Ubuntu-14.04') | 36 parser.add_argument('--os', default='Ubuntu-14.04') |
|
M-A Ruel
2016/01/15 14:07:13
You should make it a --dimension flag and permits
Mike Meade
2016/01/18 20:25:51
These are defined by the test case author, not the
| |
| 36 args, _ = parser.parse_known_args() | 37 args, _ = parser.parse_known_args() |
| 37 | 38 |
| 38 task = cls.CreateTask( | 39 task = cls.CreateTask( |
| 39 isolated_hash=args.task_hash, | 40 isolated_hash=args.task, |
| 40 dimensions={'os': args.os}, | 41 dimensions={'os': args.os}, |
| 41 idle_timeout_secs=90, | 42 idle_timeout_secs=90, |
| 42 connection_timeout_secs=90, | 43 connection_timeout_secs=90, |
| 43 verbosity=logging.DEBUG) | 44 verbosity=logging.DEBUG) |
| 44 task.Create() | 45 task.Create() |
| 45 return task | 46 return task |
| 46 | 47 |
| 47 @classmethod | 48 @classmethod |
| 48 def setUpClass(cls): | 49 def setUpClass(cls): |
| 49 """Creates the task machines and waits until they connect.""" | 50 """Creates the task machines and waits until they connect.""" |
| 50 cls.task1 = cls.CreateTestTask() | 51 cls.task = cls.CreateTestTask() |
| 51 cls.task2 = cls.CreateTestTask() | 52 cls.task.WaitForConnection() |
| 52 cls.task1.WaitForConnection() | |
| 53 cls.task2.WaitForConnection() | |
| 54 | 53 |
| 55 def testCallEcho(self): | 54 def testEventTest(self): |
| 56 """Tests rpc.Echo on a task.""" | 55 cmd = [ |
| 57 logging.info('Calling Echo on %s', self.task2.name) | 56 'python', |
| 58 self.assertEqual(self.task2.rpc.Echo('foo'), 'echo foo') | 57 'task.py', |
| 59 | 58 '--address', str(common_lib.MY_IP), |
| 60 def testLaunchTaskBinary(self): | 59 '--port', str(self.event_server.port) |
| 61 """Call task_test.py 'name' on the tasks.""" | 60 ] |
| 62 self.VerifyTaskBinaryLaunched(self.task1) | 61 process = self.task.Process(cmd) |
| 63 self.VerifyTaskBinaryLaunched(self.task2) | 62 process.Wait() |
| 64 | 63 retcode = process.GetReturncode() |
| 65 def VerifyTaskBinaryLaunched(self, task): | 64 if retcode != 0: |
| 66 logging.info( | 65 logging.info('STDOUT:\n%s', process.ReadStdout()) |
| 67 'Calling Process to run "task_test.py %s"', task.name) | 66 logging.info('STDERR:\n%s', process.ReadStderr()) |
| 68 proc = task.Process(['python', 'task_test.py', task.name]) | 67 self.assertEqual(retcode, 0) |
| 69 proc.Wait() | |
| 70 self.assertEqual(proc.GetReturncode(), 0) | |
| 71 self.assertIn(task.name, proc.ReadStdout()) | |
| 72 self.assertEquals(proc.ReadStderr(), '') | |
| 73 proc.Delete() | |
| 74 | 68 |
| 75 | 69 |
| 76 if __name__ == '__main__': | 70 if __name__ == '__main__': |
| 77 legion_test_case.main() | 71 legion_test_case.main() |
| OLD | NEW |