michael@0: #literal #!/usr/bin/python michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import SimpleHTTPServer michael@0: import SocketServer michael@0: import threading michael@0: import os michael@0: import sys michael@0: import logging michael@0: from getopt import getopt michael@0: from automation import Automation michael@0: michael@0: PORT = 8888 michael@0: SCRIPT_DIR = os.path.abspath(os.path.realpath(os.path.dirname(sys.argv[0]))) michael@0: PROFILE_DIRECTORY = os.path.abspath(os.path.join(SCRIPT_DIR, "./leakprofile")) michael@0: os.chdir(SCRIPT_DIR) michael@0: michael@0: class EasyServer(SocketServer.TCPServer): michael@0: allow_reuse_address = True michael@0: michael@0: if __name__ == '__main__': michael@0: automation = Automation() michael@0: DIST_BIN = os.path.join(SCRIPT_DIR, automation.DIST_BIN) michael@0: opts, extraArgs = getopt(sys.argv[1:], 'l:') michael@0: if len(opts) > 0: michael@0: try: michael@0: automation.log.addHandler(logging.FileHandler(opts[0][1], "w")) michael@0: except: michael@0: automation.log.info("Unable to open logfile " + opts[0][1] + \ michael@0: "ONLY logging to stdout.") michael@0: michael@0: httpd = EasyServer(("", PORT), SimpleHTTPServer.SimpleHTTPRequestHandler) michael@0: t = threading.Thread(target=httpd.serve_forever) michael@0: t.setDaemon(True) michael@0: t.start() michael@0: michael@0: automation.setServerInfo("localhost", PORT) michael@0: michael@0: # keep a profile reference so that it is not cleaned up immediately via __del__ michael@0: profile = automation.initializeProfile(PROFILE_DIRECTORY) michael@0: michael@0: browserEnv = automation.environment() michael@0: michael@0: if not "XPCOM_DEBUG_BREAK" in browserEnv: michael@0: browserEnv["XPCOM_DEBUG_BREAK"] = "stack" michael@0: url = "http://localhost:%d/bloatcycle.html" % PORT michael@0: appPath = os.path.join(SCRIPT_DIR, automation.DEFAULT_APP) michael@0: status = automation.runApp(url, browserEnv, appPath, PROFILE_DIRECTORY, michael@0: extraArgs, timeout=1800) michael@0: sys.exit(status)