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 232488 ac5d23ce1ce9f8abbd563c70f5485ebd04b60236
parent 232487 9da8f4e52207a8e9f96618cd0d4ec3535e165e13
child 232489 827b92f481dd5fdd68cd70699396021d85b72c5e
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahal
bugs705864
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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