Bug 705864 - [mozprocess] mozprocess tests should use mozprocess.pid. r=ahal
--- a/testing/mozbase/mozprocess/mozprocess/pid.py
+++ b/testing/mozbase/mozprocess/mozprocess/pid.py
@@ -6,22 +6,20 @@
import os
import mozinfo
import shlex
import subprocess
import sys
# determine the platform-specific invocation of `ps`
-if mozinfo.isMac:
- psarg = '-Acj'
-elif mozinfo.isLinux:
+if mozinfo.isWin:
+ psarg='ax'
+else:
psarg = 'axwww'
-else:
- psarg = 'ax'
def ps(arg=psarg):
"""
python front-end to `ps`
http://en.wikipedia.org/wiki/Ps_%28Unix%29
returns a list of process dicts based on the `ps` header
"""
retval = []
--- a/testing/mozbase/mozprocess/tests/proctest.py
+++ b/testing/mozbase/mozprocess/tests/proctest.py
@@ -1,52 +1,31 @@
import mozinfo
import os
import subprocess
import sys
import unittest
+from mozprocess.pid import get_pids
here = os.path.dirname(os.path.abspath(__file__))
def check_for_process(processName):
"""
Use to determine if process of the given name is still running.
Returns:
detected -- True if process is detected to exist, False otherwise
- output -- if process exists, stdout of the process, '' otherwise
+ output -- if process exists, stdout of the process, [] otherwise
"""
- # TODO: replace with
- # https://github.com/mozilla/mozbase/blob/master/mozprocess/mozprocess/pid.py
- # which should be augmented from talos
- # see https://bugzilla.mozilla.org/show_bug.cgi?id=705864
- output = ''
- if mozinfo.isWin:
- # On windows we use tasklist
- p1 = subprocess.Popen(["tasklist"], stdout=subprocess.PIPE)
- output = p1.communicate()[0]
- detected = False
- for line in output.splitlines():
- if processName in line:
- detected = True
- break
- else:
- p1 = subprocess.Popen(["ps", "-ef"], stdout=subprocess.PIPE)
- p2 = subprocess.Popen(["grep", processName], stdin=p1.stdout, stdout=subprocess.PIPE)
- p1.stdout.close()
- output = p2.communicate()[0]
- detected = False
- for line in output.splitlines():
- if "grep %s" % processName in line:
- continue
- elif processName in line and not 'defunct' in line:
- detected = True
- break
+ name = os.path.basename(processName)
+ process = get_pids(name)
- return detected, output
+ if process:
+ return True, process
+ return False, []
class ProcTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.proclaunch = os.path.join(here, "proclaunch.py")
cls.python = sys.executable