From 250120bde864c7a56d2017017f6bbce9d664776c Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 7 Nov 2011 10:42:28 -0500 Subject: [PATCH] Use mozhttpd for webserver and print tracebacks to debug --- peptest/pepserver.py | 54 ------------------------------------------ peptest/runpeptests.py | 37 +++++++++++++---------------- 2 files changed, 17 insertions(+), 74 deletions(-) delete mode 100644 peptest/pepserver.py diff --git a/peptest/pepserver.py b/peptest/pepserver.py deleted file mode 100644 index 51675ce..0000000 --- a/peptest/pepserver.py +++ /dev/null @@ -1,54 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ # -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is Peptest. -# -# The Initial Developer of the Original Code is -# Mozilla Corporation. -# Portions created by the Initial Developer are Copyright (C) 2011 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Andrew Halberstadt -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# 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 ***** - -import SimpleHTTPServer -import SocketServer - -class PepHTTPServer(SocketServer.TCPServer): - handler = None - port = None - stopped = False - - def __init__(self, port=8000): - handler = SimpleHTTPServer.SimpleHTTPRequestHandler - SocketServer.TCPServer.__init__(self, ("", port), handler) - - def serve_forever(self): - while not self.stopped: - self.handle_request() - - def stop(self): - self.stopped = True diff --git a/peptest/runpeptests.py b/peptest/runpeptests.py index 04f11bd..a54d889 100644 --- a/peptest/runpeptests.py +++ b/peptest/runpeptests.py @@ -37,18 +37,19 @@ from optparse import OptionParser from mozprofile import FirefoxProfile, ThunderbirdProfile, Profile from mozrunner import FirefoxRunner, ThunderbirdRunner, Runner +from mozhttpd import MozHttpd from manifestparser import TestManifest -from pepserver import PepHTTPServer from pepprocess import PepProcess from pepresults import Results import peputils as utils -import glob +import traceback import mozlog -import os +import glob import shutil -import sys import signal +import os +import sys results = Results() here = os.path.dirname(os.path.realpath(__file__)) @@ -64,7 +65,7 @@ class Peptest(): def __init__(self, options, **kwargs): self.options = options - self.child_pid = None + self.server = None self.logger = mozlog.getLogger('PEP') # create the profile @@ -140,15 +141,10 @@ def runServer(self): if not self.options.serverPath: self.logger.warning('Can\'t start HTTP server, --server-path not specified') return - pId = os.fork() - # if child process - if pId == 0: - os.chdir(os.path.dirname(self.options.serverPath)) - self.server = PepHTTPServer(self.options.serverPort) - self.logger.debug('Starting server on port ' + str(self.options.serverPort)) - self.server.serve_forever() - else: - self.child_pid = pId + self.logger.debug('Starting server on port ' + str(self.options.serverPort)) + self.server = MozHttpd(port=self.options.serverPort, + docroot=self.options.serverPath) + self.server.start(block=False) def stop(self): """Kill the app""" @@ -157,9 +153,8 @@ def stop(self): self.runner.stop() # kill the server process - if self.child_pid is not None: - # TODO Kill properly (?) - os.kill(self.child_pid, signal.SIGKILL) + if self.server: + self.server.stop() # remove harness related files files = ['manifest.json'] @@ -310,7 +305,7 @@ def __init__(self, **kwargs): self.add_option("--server-port", action="store", type="int", dest="serverPort", - default=8080, + default=8888, help="The port to host test related files on") self.add_option("--server-path", @@ -375,8 +370,10 @@ def main(args=sys.argv[1:]): try: peptest = applications[options.app](options) return peptest.start() - except Exception, e: - logger.error(str(type(e)) + ' ' + str(e)) + except Exception: + cla, exc = sys.exc_info()[:2] + logger.error("%s: %s" % (cla.__name__, exc)) + logger.debug("Traceback:\n%s" % (traceback.format_exc())) return 2 if __name__ == '__main__':