| Index: tools/browser_tester/browsertester/browserprocess.py
|
| ===================================================================
|
| --- tools/browser_tester/browsertester/browserprocess.py (revision 6635)
|
| +++ tools/browser_tester/browsertester/browserprocess.py (working copy)
|
| @@ -1,85 +0,0 @@
|
| -#!/usr/bin/python
|
| -# Copyright (c) 2011 The Native Client Authors. All rights reserved.
|
| -# Use of this source code is governed by a BSD-style license that can be
|
| -# found in the LICENSE file.
|
| -
|
| -import os
|
| -import signal
|
| -import subprocess
|
| -import time
|
| -
|
| -# mozrunner is needed as long as we are supporting versions of Python
|
| -# before 2.6.
|
| -import mozrunner
|
| -
|
| -class BrowserProcessBase(object):
|
| -
|
| - def __init__(self, handle):
|
| - self.handle = handle
|
| - print 'PID', self.handle.pid
|
| -
|
| - def GetReturnCode(self):
|
| - return self.handle.returncode
|
| -
|
| - def IsRunning(self):
|
| - return self.handle.poll() is None
|
| -
|
| - def Wait(self, wait_steps, sleep_time):
|
| - self.term()
|
| - i = 0
|
| - # subprocess.wait() doesn't have a timeout, unfortunately.
|
| - while self.IsRunning() and i < wait_steps:
|
| - time.sleep(sleep_time)
|
| - i += 1
|
| -
|
| - def Kill(self):
|
| - if self.IsRunning():
|
| - print 'KILLING the browser'
|
| - try:
|
| - self.kill()
|
| - # If it doesn't die, we hang. Oh well.
|
| - self.handle.wait()
|
| - except Exception:
|
| - # If it is already dead, then it's ok.
|
| - # This may happen if the browser dies after the first poll, but
|
| - # before the kill.
|
| - if self.IsRunning():
|
| - raise
|
| -
|
| -class BrowserProcess(BrowserProcessBase):
|
| -
|
| - def term(self):
|
| - self.handle.terminate()
|
| -
|
| - def kill(self):
|
| - self.handle.kill()
|
| -
|
| -
|
| -class BrowserProcessPosix(BrowserProcessBase):
|
| - """ This variant of BrowserProcess uses process groups to manage browser
|
| - life time. """
|
| -
|
| - def term(self):
|
| - os.killpg(self.handle.pid, signal.SIGTERM)
|
| -
|
| - def kill(self):
|
| - os.killpg(self.handle.pid, signal.SIGKILL)
|
| -
|
| -
|
| -def RunCommandWithSubprocess(cmd, env=None):
|
| - handle = subprocess.Popen(cmd, env=env)
|
| - return BrowserProcess(handle)
|
| -
|
| -
|
| -def RunCommandWithMozrunner(cmd, env=None):
|
| - handle = mozrunner.run_command(cmd, env=env)
|
| - return BrowserProcess(handle)
|
| -
|
| -
|
| -def RunCommandInProcessGroup(cmd, env=None):
|
| - def SetPGrp():
|
| - os.setpgrp()
|
| - print 'I\'M THE SESSION LEADER!'
|
| - handle = subprocess.Popen(cmd, env=env, preexec_fn=SetPGrp)
|
| - return BrowserProcessPosix(handle)
|
| -
|
|
|