forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a server side, non-blocking subprocess mechanism.
BUG=453679 Review URL: https://codereview.chromium.org/870103005 Cr-Commit-Position: refs/heads/master@{#316594}
- Loading branch information
mmeade
authored and
Commit bot
committed
Feb 17, 2015
1 parent
66c7eff
commit 759bbd2
Showing
7 changed files
with
258 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 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. | ||
|
||
{ | ||
'includes': [ | ||
'../../legion.isolate' | ||
], | ||
'conditions': [ | ||
['multi_machine == 1', { | ||
'variables': { | ||
'command': [ | ||
'python', | ||
'../../client_controller.py', | ||
], | ||
'files': [ | ||
'client.isolate' | ||
], | ||
}, | ||
}], | ||
], | ||
} |
22 changes: 22 additions & 0 deletions
22
testing/legion/examples/subprocess/subprocess_test.isolate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 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. | ||
|
||
{ | ||
'includes': [ | ||
'../../legion.isolate', | ||
'client.isolate' | ||
], | ||
'conditions': [ | ||
['multi_machine == 1', { | ||
'variables': { | ||
'command': [ | ||
'subprocess_test.py', | ||
], | ||
'files': [ | ||
'subprocess_test.py', | ||
], | ||
}, | ||
}], | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/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. | ||
|
||
"""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 logging | ||
import time | ||
import xmlrpclib | ||
|
||
import host_controller | ||
|
||
|
||
class ExampleController(host_controller.HostController): | ||
"""An example controller using the remote subprocess functions.""" | ||
|
||
def __init__(self): | ||
super(ExampleController, self).__init__() | ||
self.client = None | ||
|
||
def SetUp(self): | ||
"""Creates the client machine and waits until it connects.""" | ||
self.client = self.NewClient( | ||
isolate_file='client.isolate', | ||
config_vars={'multi_machine': '1'}, | ||
dimensions={'os': 'legion-linux'}, | ||
idle_timeout_secs=90, connection_timeout_secs=90, | ||
verbosity=logging.DEBUG) | ||
self.client.Create() | ||
self.client.WaitForConnection() | ||
|
||
def Task(self): | ||
"""Main method to run the task code.""" | ||
self.TestLs() | ||
self.TestTerminate() | ||
self.TestMultipleProcesses() | ||
|
||
def TestMultipleProcesses(self): | ||
start = time.time() | ||
|
||
sleep20 = self.client.rpc.subprocess.Popen(['sleep', '20']) | ||
sleep10 = self.client.rpc.subprocess.Popen(['sleep', '10']) | ||
|
||
self.client.rpc.subprocess.Wait(sleep10) | ||
elapsed = time.time() - start | ||
assert elapsed >= 10 and elapsed < 11 | ||
|
||
self.client.rpc.subprocess.Wait(sleep20) | ||
elapsed = time.time() - start | ||
assert elapsed >= 20 | ||
|
||
self.client.rpc.subprocess.Delete(sleep20) | ||
self.client.rpc.subprocess.Delete(sleep10) | ||
|
||
def TestTerminate(self): | ||
start = time.time() | ||
proc = self.client.rpc.subprocess.Popen(['sleep', '20']) | ||
self.client.rpc.subprocess.Terminate(proc) # Implicitly deleted | ||
try: | ||
self.client.rpc.subprocess.Wait(proc) | ||
except xmlrpclib.Fault: | ||
pass | ||
assert time.time() - start < 20 | ||
|
||
def TestLs(self): | ||
proc = self.client.rpc.subprocess.Popen(['ls']) | ||
self.client.rpc.subprocess.Wait(proc) | ||
assert self.client.rpc.subprocess.GetReturncode(proc) == 0 | ||
assert 'client.isolate' in self.client.rpc.subprocess.ReadStdout(proc) | ||
self.client.rpc.subprocess.Delete(proc) | ||
|
||
|
||
if __name__ == '__main__': | ||
ExampleController().RunController() |