Bug 711102 Ensure build environments have logging modules for peptest r=ctalbert
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Thu, 15 Dec 2011 12:58:37 -0600
changeset 84326 4963f2ae738073fb221b45f9bb78e864a43c2574
parent 84325 5b318156118fbeb9e703a18b907e9a8320174abf
child 84327 e27edbae265e64095c14bd04c64cd508e83043a0
push idunknown
push userunknown
push dateunknown
Bug 711102 Ensure build environments have logging modules for peptest r=ctalbert
--- a/testing/mozbase/mozhttpd/mozhttpd/mozhttpd.py
+++ b/testing/mozbase/mozhttpd/mozhttpd/mozhttpd.py
@@ -43,19 +43,19 @@ import threading
 import sys
 import os
 import urllib
 import re
 from SocketServer import ThreadingMixIn
 class EasyServer(ThreadingMixIn, BaseHTTPServer.HTTPServer):
     allow_reuse_address = True
 class MozRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
-    docroot = os.getcwd()
+    docroot = os.getcwd() # current working directory at time of import
     def parse_request(self):
         retval = SimpleHTTPServer.SimpleHTTPRequestHandler.parse_request(self)
         if '?' in self.path:
             # ignore query string, otherwise SimpleHTTPRequestHandler 
             # will treat it as PATH_INFO for `translate_path`
             self.path = self.path.split('?', 1)[0]
         return retval
--- a/testing/mozbase/mozhttpd/setup.py
+++ b/testing/mozbase/mozhttpd/setup.py
@@ -53,17 +53,16 @@ setup(name='mozhttpd',
       description="basic python webserver, tested with talos",
       classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
       author='Joel Maher',
-      py_modules=['mozhttpd'],
       packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
       # -*- Entry points: -*-
       mozhttpd = mozhttpd:main
--- a/testing/mozbase/mozlog/mozlog/logger.py
+++ b/testing/mozbase/mozlog/mozlog/logger.py
@@ -30,16 +30,20 @@
 # decision by deleting the provisions above and replace them with the notice
 # and other provisions required by the GPL or the LGPL. If you do not delete
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 # ***** END LICENSE BLOCK *****
 from logging import getLogger as getSysLogger
 from logging import *
+# Some of the build slave environments don't see the following when doing
+# 'from logging import *'
+# see https://bugzilla.mozilla.org/show_bug.cgi?id=700415#c35
+from logging import getLoggerClass, addLevelName, setLoggerClass
 _default_level = INFO
 _LoggerClass = getLoggerClass()
 # Define mozlog specific log levels
 START      = _default_level + 1
 END        = _default_level + 2
 PASS       = _default_level + 3
--- a/testing/mozbase/mozprocess/README.md
+++ b/testing/mozbase/mozprocess/README.md
@@ -1,10 +1,10 @@
-provides python process management via an operating system 
+provides python process management via an operating system
 and platform transparent interface to Mozilla platforms of interest.
 Mozprocess aims to provide the ability
 to robustly terminate a process (by timeout or otherwise), along with
 any child processes, on Windows, OS X, and Linux. Mozprocess utilizes
 and extends `subprocess.Popen` to these ends.
 # API
@@ -14,21 +14,92 @@ is the central exposed API for mozproces
 a contained subclass of [subprocess.Popen](http://docs.python.org/library/subprocess.html),
 `Process`, which does the brunt of the process management.
 Basic usage:
     process = ProcessHandler(['command', '-line', 'arguments'],
                              cwd=None, # working directory for cmd; defaults to None
                              env={},   # environment to use for the process; defaults to os.environ
-                             )         
+                             )
     exit_code = process.waitForFinish(timeout=60) # seconds
-See an example in https://github.com/mozilla/mozbase/blob/master/mutt/mutt/tests/python/testprofilepath.py
+`ProcessHandler` offers several other properties and methods as part of its API:
+    @property
+    def timedOut(self):
+        """True if the process has timed out."""
+    def run(self):
+        """
+        Starts the process. waitForFinish must be called to allow the
+        process to complete.
+        """
+    def kill(self):
+        """
+        Kills the managed process and if you created the process with
+        'ignore_children=False' (the default) then it will also
+        also kill all child processes spawned by it.
+        If you specified 'ignore_children=True' when creating the process,
+        only the root process will be killed.
+        Note that this does not manage any state, save any output etc,
+        it immediately kills the process.
+        """
+    def readWithTimeout(self, f, timeout):
+        """
+        Try to read a line of output from the file object |f|.
+        |f| must be a pipe, like the |stdout| member of a subprocess.Popen
+        object created with stdout=PIPE. If no output
+        is received within |timeout| seconds, return a blank line.
+        Returns a tuple (line, did_timeout), where |did_timeout| is True
+        if the read timed out, and False otherwise.
+        Calls a private member because this is a different function based on
+        the OS
+        """
+    def processOutputLine(self, line):
+        """Called for each line of output that a process sends to stdout/stderr."""
+        for handler in self.processOutputLineHandlers:
+            handler(line)
+    def onTimeout(self):
+        """Called when a process times out."""
+        for handler in self.onTimeoutHandlers:
+            handler()
+    def onFinish(self):
+        """Called when a process finishes without a timeout."""
+        for handler in self.onFinishHandlers:
+            handler()
+    def waitForFinish(self, timeout=None, outputTimeout=None):
+        """
+        Handle process output until the process terminates or times out.
+        If timeout is not None, the process will be allowed to continue for
+        that number of seconds before being killed.
+        If outputTimeout is not None, the process will be allowed to continue
+        for that number of seconds without producing any output before
+        being killed.
+        """
+See https://github.com/mozilla/mozbase/blob/master/mozprocess/mozprocess/processhandler.py
+for the python implementation.
+`ProcessHandler` extends `ProcessHandlerMixin` which by default prints the
+output, logs to a file (if specified), and stores the output (if specified, by
+default `True`).  `ProcessHandlerMixin`, by default, does none of these things
+and has no handlers for `onTimeout`, `processOutput`, or `onFinish`.
 `ProcessHandler` may be subclassed to handle process timeouts (by overriding
-the `onTimeout()` method), process completion (by overriding 
-`onFinish()`), and to process the command output (by overriding 
+the `onTimeout()` method), process completion (by overriding
+`onFinish()`), and to process the command output (by overriding
 - Document improvements over `subprocess.Popen.kill`
+- Introduce test the show improvements over `subprocess.Popen.kill`