bug 460515 - Remove assumption that xpcshell etc in same directory as app executable. r=jwalden

This commit is contained in:
Ted Mielczarek 2009-02-09 13:57:27 -05:00
Родитель 7d78f40925
Коммит e2b921b2c4
3 изменённых файлов: 102 добавлений и 47 удалений

Просмотреть файл

@ -65,6 +65,7 @@ __all__ = [
"initializeProfile",
"DIST_BIN",
"DEFAULT_APP",
"CERTS_SRC_DIR",
"environment",
]
@ -83,7 +84,6 @@ IS_CYGWIN = False
UNIXISH = not IS_WIN32 and not IS_MAC
#expand DEFAULT_APP = "./" + __BROWSER_PATH__
#expand PROFILE_DIR = __PROFILE_DIR__
#expand CERTS_SRC_DIR = __CERTS_SRC_DIR__
#expand IS_TEST_BUILD = __IS_TEST_BUILD__
#expand IS_DEBUG_BUILD = __IS_DEBUG_BUILD__
@ -318,8 +318,7 @@ user_pref("camino.use_system_proxy_settings", false); // Camino-only, harmless t
prefsFile.write("".join(prefs))
prefsFile.close()
def fillCertificateDB(profileDir):
def fillCertificateDB(profileDir, certPath, utilityPath, xrePath):
pwfilePath = os.path.join(profileDir, ".crtdbpw")
pwfile = open(pwfilePath, "w")
@ -327,11 +326,11 @@ def fillCertificateDB(profileDir):
pwfile.close()
# Create head of the ssltunnel configuration file
sslTunnelConfigPath = os.path.join(PROFILE_DIR, "ssltunnel.cfg")
sslTunnelConfigPath = os.path.join(profileDir, "ssltunnel.cfg")
sslTunnelConfig = open(sslTunnelConfigPath, "w")
sslTunnelConfig.write("httpproxy:1\n")
sslTunnelConfig.write("certdbdir:%s\n" % CERTS_SRC_DIR)
sslTunnelConfig.write("certdbdir:%s\n" % certPath)
sslTunnelConfig.write("forward:127.0.0.1:8888\n")
sslTunnelConfig.write("listen:*:4443:pgo server certificate\n")
@ -358,41 +357,47 @@ def fillCertificateDB(profileDir):
sslTunnelConfig.close()
# Pre-create the certification database for the profile
certutil = DIST_BIN + "/certutil" + BIN_SUFFIX
pk12util = DIST_BIN + "/pk12util" + BIN_SUFFIX
env = environment(xrePath = xrePath)
certutil = os.path.join(utilityPath, "certutil" + BIN_SUFFIX)
pk12util = os.path.join(utilityPath, "pk12util" + BIN_SUFFIX)
status = Process([certutil, "-N", "-d", profileDir, "-f", pwfilePath], env = environment()).wait()
status = Process([certutil, "-N", "-d", profileDir, "-f", pwfilePath], env = env).wait()
if status != 0:
return status
# Walk the cert directory and add custom CAs and client certs
files = os.listdir(CERTS_SRC_DIR)
files = os.listdir(certPath)
for item in files:
root, ext = os.path.splitext(item)
if ext == ".ca":
trustBits = "CT,,"
if root.endswith("-object"):
trustBits = "CT,,CT"
Process([certutil, "-A", "-i", os.path.join(CERTS_SRC_DIR, item),
Process([certutil, "-A", "-i", os.path.join(certPath, item),
"-d", profileDir, "-f", pwfilePath, "-n", root, "-t", trustBits],
env = environment()).wait()
env = env).wait()
if ext == ".client":
Process([pk12util, "-i", os.path.join(CERTS_SRC_DIR, item), "-w",
Process([pk12util, "-i", os.path.join(certPath, item), "-w",
pwfilePath, "-d", profileDir],
env = environment()).wait()
env = env).wait()
os.unlink(pwfilePath)
return 0
def environment(env = None):
def environment(env = None, xrePath = DIST_BIN):
if env == None:
env = dict(os.environ)
if UNIXISH:
ldLibraryPath = os.path.join(SCRIPT_DIR, DIST_BIN)
if "LD_LIBRARY_PATH" in env:
ldLibraryPath = ldLibraryPath + ":" + env["LD_LIBRARY_PATH"]
env["LD_LIBRARY_PATH"] = ldLibraryPath
ldLibraryPath = os.path.abspath(os.path.join(SCRIPT_DIR, xrePath))
if UNIXISH or IS_MAC:
envVar = "LD_LIBRARY_PATH"
if IS_MAC:
envVar = "DYLD_LIBRARY_PATH"
if envVar in env:
ldLibraryPath = ldLibraryPath + ":" + env[envVar]
env[envVar] = ldLibraryPath
elif IS_WIN32:
env["PATH"] = env["PATH"] + ";" + ldLibraryPath
return env
@ -400,18 +405,18 @@ def environment(env = None):
# RUN THE APP #
###############
def runApp(testURL, env, app, profileDir, extraArgs):
def runApp(testURL, env, app, profileDir, extraArgs, utilityPath = DIST_BIN, xrePath = DIST_BIN, certPath = CERTS_SRC_DIR):
"Run the app, returning a tuple containing the status code and the time at which it was started."
if (IS_TEST_BUILD):
# create certificate database for the profile
certificateStatus = fillCertificateDB(profileDir)
certificateStatus = fillCertificateDB(profileDir, certPath, utilityPath, xrePath)
if certificateStatus != 0:
log.info("ERROR FAIL Certificate integration")
return certificateStatus
# start ssltunnel to provide https:// URLs capability
ssltunnel = DIST_BIN + "/ssltunnel" + BIN_SUFFIX
ssltunnelProcess = Process([ssltunnel, os.path.join(PROFILE_DIR, "ssltunnel.cfg")], env = environment())
ssltunnel = os.path.join(utilityPath, "ssltunnel" + BIN_SUFFIX)
ssltunnelProcess = Process([ssltunnel, os.path.join(profileDir, "ssltunnel.cfg")], env = environment(xrePath = xrePath))
log.info("SSL tunnel pid: %d", ssltunnelProcess.pid)
"Run the app, returning the time at which it was started."

Просмотреть файл

@ -49,6 +49,7 @@ import os.path
import re
import sys
import time
import shutil
from urllib import quote_plus as encodeURIComponent
import urllib2
import commands
@ -106,7 +107,23 @@ class MochitestOptions(optparse.OptionParser):
self.add_option("--appname",
action = "store", type = "string", dest = "app",
help = "absolute path to application, overriding default")
defaults["app"] = automation.DEFAULT_APP
defaults["app"] = os.path.join(SCRIPT_DIRECTORY, automation.DEFAULT_APP)
self.add_option("--xre-path",
action = "store", type = "string", dest = "xrePath",
help = "absolute path to directory containing XRE (probably xulrunner)")
# we'll default this to the directory of app below
defaults["xrePath"] = None
self.add_option("--utility-path",
action = "store", type = "string", dest = "utilityPath",
help = "absolute path to directory containing utility programs (xpcshell, ssltunnel, certutil)")
defaults["utilityPath"] = automation.DIST_BIN
self.add_option("--certificate-path",
action = "store", type = "string", dest = "certPath",
help = "absolute path to directory containing certificate store to use testing profile")
defaults["certPath"] = automation.CERTS_SRC_DIR
self.add_option("--log-file",
action = "store", type = "string",
@ -184,6 +201,11 @@ class MochitestOptions(optparse.OptionParser):
"(requires a debug build to be effective)")
defaults["fatalAssertions"] = False
self.add_option("--extra-profile-file",
action = "append", dest = "extraProfileFiles",
help = "copy specified files/dirs to testing profile")
defaults["extraProfileFiles"] = []
# -h, --help are automatically handled by OptionParser
self.set_defaults(**defaults)
@ -207,21 +229,29 @@ class MochitestServer:
def __init__(self, options):
self._closeWhenDone = options.closeWhenDone
self._utilityPath = options.utilityPath
self._xrePath = options.xrePath
def start(self):
"Run the Mochitest server, returning the process ID of the server."
env = dict(os.environ)
if automation.UNIXISH:
env["LD_LIBRARY_PATH"] = automation.DIST_BIN
env["MOZILLA_FIVE_HOME"] = automation.DIST_BIN
env["LD_LIBRARY_PATH"] = self._xrePath
env["MOZILLA_FIVE_HOME"] = self._xrePath
env["XPCOM_DEBUG_BREAK"] = "warn"
if automation.IS_MAC:
env["DYLD_LIBRARY_PATH"] = self._xrePath
elif automation.IS_WIN32:
env["PATH"] = env["PATH"] + ";" + self._xrePath
args = ["-v", "170",
args = ["-g", self._xrePath,
"-v", "170",
"-f", "./" + "httpd.js",
"-f", "./" + "server.js"]
xpcshell = automation.DIST_BIN + "/" + "xpcshell";
xpcshell = os.path.join(self._utilityPath,
"xpcshell" + automation.BIN_SUFFIX)
self._process = automation.Process([xpcshell] + args, env = env)
pid = self._process.pid
if pid < 0:
@ -233,7 +263,7 @@ class MochitestServer:
def ensureReady(self, timeout):
assert timeout >= 0
aliveFile = PROFILE_DIRECTORY + "/" + "server_alive.txt"
aliveFile = os.path.join(PROFILE_DIRECTORY, "server_alive.txt")
i = 0
while i < timeout:
if os.path.exists(aliveFile):
@ -254,6 +284,9 @@ class MochitestServer:
except:
self._process.kill()
def getFullPath(path):
"Get an absolute path relative to oldcwd."
return os.path.normpath(os.path.join(oldcwd, os.path.expanduser(path)))
#################
# MAIN FUNCTION #
@ -269,6 +302,7 @@ def main():
# enforced, just pass an explicit --leak-threshold=N to prevent the override.
maybeForceLeakThreshold(options)
options.app = getFullPath(options.app)
if not os.path.exists(options.app):
msg = """\
Error: Path %(app)s doesn't exist.
@ -276,6 +310,16 @@ Are you executing $objdir/_tests/testing/mochitest/runtests.py?"""
print msg % {"app": options.app}
sys.exit(1)
# default xrePath to the app path if not provided
if options.xrePath is None:
options.xrePath = os.path.dirname(options.app)
else:
# allow relative paths
options.xrePath = getFullPath(options.xrePath)
options.utilityPath = getFullPath(options.utilityPath)
options.certPath = getFullPath(options.certPath)
# browser environment
browserEnv = dict(os.environ)
@ -283,9 +327,10 @@ Are you executing $objdir/_tests/testing/mochitest/runtests.py?"""
# via the commandline at your own risk.
browserEnv["NO_EM_RESTART"] = "1"
browserEnv["XPCOM_DEBUG_BREAK"] = "warn"
appDir = os.path.dirname(options.app)
if automation.UNIXISH:
browserEnv["LD_LIBRARY_PATH"] = automation.DIST_BIN
browserEnv["MOZILLA_FIVE_HOME"] = automation.DIST_BIN
browserEnv["LD_LIBRARY_PATH"] = appDir
browserEnv["MOZILLA_FIVE_HOME"] = appDir
browserEnv["GNOME_DISABLE_CRASH_DIALOG"] = "1"
for v in options.environment:
@ -297,6 +342,7 @@ Are you executing $objdir/_tests/testing/mochitest/runtests.py?"""
automation.initializeProfile(PROFILE_DIRECTORY)
manifest = addChromeToProfile(options)
copyExtraFilesToProfile(options)
server = MochitestServer(options)
server.start()
@ -333,8 +379,7 @@ Are you executing $objdir/_tests/testing/mochitest/runtests.py?"""
# allow relative paths for logFile
if options.logFile:
logpath = os.path.join(oldcwd, os.path.expanduser(options.logFile))
options.logFile = os.path.normpath(logpath)
options.logFile = getFullPath(options.logFile)
if options.browserChrome:
makeTestConfig(options)
else:
@ -356,7 +401,10 @@ Are you executing $objdir/_tests/testing/mochitest/runtests.py?"""
browserEnv["XPCOM_DEBUG_BREAK"] = "stack-and-abort"
(status, start) = automation.runApp(testURL, browserEnv, options.app,
PROFILE_DIRECTORY, options.browserArgs)
PROFILE_DIRECTORY, options.browserArgs,
utilityPath=options.utilityPath,
xrePath=options.xrePath,
certPath=options.certPath)
# Server's no longer needed, and perhaps more importantly, anything it might
# spew to console shouldn't disrupt the leak information table we print next.
@ -494,7 +542,7 @@ def makeTestConfig(options):
"logPath": logFile,
"testPath": testPath}
config = open(PROFILE_DIRECTORY + "/" + "testConfig.js", "w")
config = open(os.path.join(PROFILE_DIRECTORY, "testConfig.js"), "w")
config.write(content)
config.close()
@ -502,7 +550,7 @@ def makeTestConfig(options):
def addChromeToProfile(options):
"Adds MochiKit chrome tests to the profile."
chromedir = PROFILE_DIRECTORY + "/" + "chrome"
chromedir = os.path.join(PROFILE_DIRECTORY, "chrome")
os.mkdir(chromedir)
chrome = []
@ -522,7 +570,7 @@ toolbar#nav-bar {
# write userChrome.css
chromeFile = open(PROFILE_DIRECTORY + "/" + "userChrome.css", "a")
chromeFile = open(os.path.join(PROFILE_DIRECTORY, "userChrome.css"), "a")
chromeFile.write("".join(chrome))
chromeFile.close()
@ -534,7 +582,7 @@ toolbar#nav-bar {
(path, leaf) = os.path.split(options.app)
manifest = path + "/" + "chrome/mochikit.manifest"
manifest = os.path.join(path, "chrome", "mochikit.manifest")
manifestFile = open(manifest, "w")
manifestFile.write("content mochikit " + chrometestDir + " contentaccessible=yes\n")
if options.browserChrome:
@ -545,6 +593,16 @@ toolbar#nav-bar {
return manifest
def copyExtraFilesToProfile(options):
"Copy extra files or dirs specified on the command line to the testing profile."
for f in options.extraProfileFiles:
abspath = getFullPath(f)
dest = os.path.join(PROFILE_DIRECTORY, os.path.basename(abspath))
if os.path.isdir(abspath):
shutil.copytree(abspath, dest)
else:
shutil.copy(abspath, dest)
#########
# DO IT #
#########

Просмотреть файл

@ -134,15 +134,7 @@ var serverBasePath;
//
function runServer()
{
serverBasePath = Cc["@mozilla.org/file/local;1"]
.createInstance(Ci.nsILocalFile);
var procDir = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties).get("CurProcD", Ci.nsIFile);
serverBasePath.initWithPath(procDir.parent.parent.path);
serverBasePath.append("_tests");
serverBasePath.append("testing");
serverBasePath.append("mochitest");
serverBasePath = __LOCATION__.parent;
server = createMochitestServer(serverBasePath);
server.start(SERVER_PORT);