| Index: testing/legion/examples/subprocess/subprocess_test.py
 | 
| diff --git a/testing/legion/examples/subprocess/subprocess_test.py b/testing/legion/examples/subprocess/subprocess_test.py
 | 
| index 1a28ddd5dabdc536568bf50f4348294dbea14835..cea871a4051f9fb28b950ae461b50dc47573cdcf 100755
 | 
| --- a/testing/legion/examples/subprocess/subprocess_test.py
 | 
| +++ b/testing/legion/examples/subprocess/subprocess_test.py
 | 
| @@ -5,85 +5,91 @@
 | 
|  
 | 
|  """A host test module demonstrating interacting with remote subprocesses."""
 | 
|  
 | 
| -# Map the legion directory so we can import the host controller.
 | 
| -import sys
 | 
| -sys.path.append('../../')
 | 
| -
 | 
|  import argparse
 | 
|  import logging
 | 
| +import os
 | 
| +import sys
 | 
|  import time
 | 
|  import xmlrpclib
 | 
|  
 | 
| -import test_controller
 | 
| +# Map the testing directory so we can import legion.legion_test.
 | 
| +TESTING_DIR = os.path.join(
 | 
| +    os.path.dirname(os.path.abspath(__file__)),
 | 
| +    '..', '..', '..', '..', 'testing')
 | 
| +sys.path.append(TESTING_DIR)
 | 
|  
 | 
| +from legion import legion_test_case
 | 
|  
 | 
| -class ExampleTestController(test_controller.TestController):
 | 
| -  """An example controller using the remote subprocess functions."""
 | 
|  
 | 
| -  def __init__(self):
 | 
| -    super(ExampleTestController, self).__init__()
 | 
| -    self.task = None
 | 
| +class ExampleTestController(legion_test_case.TestCase):
 | 
| +  """An example controller using the remote subprocess functions."""
 | 
|  
 | 
| -  def SetUp(self):
 | 
| +  @classmethod
 | 
| +  def setUpClass(cls):
 | 
|      """Creates the task machine and waits until it connects."""
 | 
|      parser = argparse.ArgumentParser()
 | 
|      parser.add_argument('--task-hash')
 | 
| +    parser.add_argument('--os', default='Ubuntu-14.04')
 | 
|      args, _ = parser.parse_known_args()
 | 
|  
 | 
| -    self.task = self.CreateNewTask(
 | 
| +    cls.task = cls.CreateTask(
 | 
|          isolated_hash=args.task_hash,
 | 
| -        dimensions={'os': 'Ubuntu-14.04', 'pool': 'Chromoting'},
 | 
| -        idle_timeout_secs=90, connection_timeout_secs=90,
 | 
| +        dimensions={'os': args.os},
 | 
| +        idle_timeout_secs=90,
 | 
| +        connection_timeout_secs=90,
 | 
|          verbosity=logging.DEBUG)
 | 
| -    self.task.Create()
 | 
| -    self.task.WaitForConnection()
 | 
| -
 | 
| -  def RunTest(self):
 | 
| -    """Main method to run the test code."""
 | 
| -    self.TestLs()
 | 
| -    self.TestTerminate()
 | 
| -    self.TestMultipleProcesses()
 | 
| +    cls.task.Create()
 | 
| +    cls.task.WaitForConnection()
 | 
|  
 | 
| -  def TestMultipleProcesses(self):
 | 
| +  def testMultipleProcesses(self):
 | 
| +    """Tests that processes can be run and controlled simultaneously."""
 | 
|      start = time.time()
 | 
| +    logging.info('Starting "sleep 10" and "sleep 20"')
 | 
| +    sleep10 = self.task.Process(['sleep', '10'])
 | 
| +    sleep20 = self.task.Process(['sleep', '20'])
 | 
|  
 | 
| -    sleep20 = self.task.rpc.subprocess.Process(['sleep', '20'])
 | 
| -    self.task.rpc.subprocess.Start(sleep20)
 | 
| -    sleep10 = self.task.rpc.subprocess.Process(['sleep', '10'])
 | 
| -    self.task.rpc.subprocess.Start(sleep10)
 | 
| -
 | 
| -    self.task.rpc.subprocess.Wait(sleep10)
 | 
| +    logging.info('Waiting for sleep 10 to finish and verifying timing')
 | 
| +    sleep10.Wait()
 | 
|      elapsed = time.time() - start
 | 
| -    assert elapsed >= 10 and elapsed < 11
 | 
| +    self.assertGreaterEqual(elapsed, 10)
 | 
| +    self.assertLess(elapsed, 11)
 | 
|  
 | 
| -    self.task.rpc.subprocess.Wait(sleep20)
 | 
| +    logging.info('Waiting for sleep 20 to finish and verifying timing')
 | 
| +    sleep20.Wait()
 | 
|      elapsed = time.time() - start
 | 
| -    assert elapsed >= 20
 | 
| +    self.assertGreaterEqual(elapsed, 20)
 | 
|  
 | 
| -    self.task.rpc.subprocess.Delete(sleep20)
 | 
| -    self.task.rpc.subprocess.Delete(sleep10)
 | 
| +    sleep10.Delete()
 | 
| +    sleep20.Delete()
 | 
|  
 | 
| -  def TestTerminate(self):
 | 
| +  def testTerminate(self):
 | 
| +    """Tests that a process can be correctly terminated."""
 | 
|      start = time.time()
 | 
| -    proc = self.task.rpc.subprocess.Process(['sleep', '20'])
 | 
| -    self.task.rpc.subprocess.Start(proc)
 | 
| -    self.task.rpc.subprocess.Terminate(proc)
 | 
| +
 | 
| +    logging.info('Starting "sleep 20"')
 | 
| +    sleep20 = self.task.Process(['sleep', '20'])
 | 
| +    logging.info('Calling Terminate()')
 | 
| +    sleep20.Terminate()
 | 
|      try:
 | 
| -      self.task.rpc.subprocess.Wait(proc)
 | 
| +      logging.info('Trying to wait for sleep 20 to complete')
 | 
| +      sleep20.Wait()
 | 
|      except xmlrpclib.Fault:
 | 
|        pass
 | 
|      finally:
 | 
| -      self.task.rpc.subprocess.Delete(proc)
 | 
| -    assert time.time() - start < 20
 | 
| +      sleep20.Delete()
 | 
| +    logging.info('Checking to make sure sleep 20 was actually terminated')
 | 
| +    self.assertLess(time.time() - start, 20)
 | 
|  
 | 
| -  def TestLs(self):
 | 
| -    proc = self.task.rpc.subprocess.Process(['ls'])
 | 
| -    self.task.rpc.subprocess.Start(proc)
 | 
| -    self.task.rpc.subprocess.Wait(proc)
 | 
| -    assert self.task.rpc.subprocess.GetReturncode(proc) == 0
 | 
| -    assert 'task.isolate' in self.task.rpc.subprocess.ReadStdout(proc)
 | 
| -    self.task.rpc.subprocess.Delete(proc)
 | 
| +  def testLs(self):
 | 
| +    """Tests that the returned results from a process are correct."""
 | 
| +    logging.info('Calling "ls"')
 | 
| +    ls = self.task.Process(['ls'])
 | 
| +    logging.info('Trying to wait for ls to complete')
 | 
| +    ls.Wait()
 | 
| +    logging.info('Checking that ls completed and returned the correct results')
 | 
| +    self.assertEqual(ls.GetReturncode(), 0)
 | 
| +    self.assertIn('task.isolate', ls.ReadStdout())
 | 
|  
 | 
|  
 | 
|  if __name__ == '__main__':
 | 
| -  ExampleTestController().RunController()
 | 
| +  legion_test_case.main()
 | 
| 
 |