Bug 705864 - [mozprocess] mozprocess tests should use mozprocess.pid. r=ahal
authorDaniel Lee <devty1023@gmail.com>
Tue, 07 Oct 2014 07:00:40 -0700
changeset 209273 ac5d23ce1ce9f8abbd563c70f5485ebd04b60236
parent 209272 9da8f4e52207a8e9f96618cd0d4ec3535e165e13
child 209274 827b92f481dd5fdd68cd70699396021d85b72c5e
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersahal
bugs705864
milestone35.0a1
Bug 705864 - [mozprocess] mozprocess tests should use mozprocess.pid. r=ahal
testing/mozbase/mozprocess/mozprocess/pid.py
testing/mozbase/mozprocess/tests/proctest.py
--- 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