def startWebServer(self, options): """ Create the webserver on the host and start it up """ remoteXrePath = options.xrePath remoteProfilePath = self.remoteProfile remoteUtilityPath = options.utilityPath localAutomation = Automation() localAutomation.IS_WIN32 = False localAutomation.IS_LINUX = False localAutomation.IS_MAC = False localAutomation.UNIXISH = False hostos = sys.platform if hostos in ["mac", "darwin"]: localAutomation.IS_MAC = True elif hostos in ["linux", "linux2"]: localAutomation.IS_LINUX = True localAutomation.UNIXISH = True elif hostos in ["win32", "win64"]: localAutomation.BIN_SUFFIX = ".exe" localAutomation.IS_WIN32 = True paths = [ options.xrePath, localAutomation.DIST_BIN, self._automation._product, os.path.join("..", self._automation._product), ] options.xrePath = self.findPath(paths) if options.xrePath == None: print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % (os.name) sys.exit(1) paths.append("bin") paths.append(os.path.join("..", "bin")) xpcshell = "xpcshell" if os.name == "nt": xpcshell += ".exe" if options.utilityPath: paths.insert(0, options.utilityPath) options.utilityPath = self.findPath(paths, xpcshell) if options.utilityPath == None: print "ERROR: unable to find utility path for %s, please specify with --utility-path" % (os.name) sys.exit(1) options.serverProfilePath = tempfile.mkdtemp() self.server = ReftestServer(localAutomation, options, self.scriptDir) retVal = self.server.start() if retVal: return retVal if options.pidFile != "": f = open(options.pidFile + ".xpcshell.pid", "w") f.write("%s" % self.server._process.pid) f.close() retVal = self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT) if retVal: return retVal options.xrePath = remoteXrePath options.utilityPath = remoteUtilityPath options.profilePath = remoteProfilePath return 0
def startWebServer(self, options): """ Create the webserver on the host and start it up """ remoteXrePath = options.xrePath remoteProfilePath = self.remoteProfile remoteUtilityPath = options.utilityPath localAutomation = Automation() localAutomation.IS_WIN32 = False localAutomation.IS_LINUX = False localAutomation.IS_MAC = False localAutomation.UNIXISH = False hostos = sys.platform if hostos in ['mac', 'darwin']: localAutomation.IS_MAC = True elif hostos in ['linux', 'linux2']: localAutomation.IS_LINUX = True localAutomation.UNIXISH = True elif hostos in ['win32', 'win64']: localAutomation.BIN_SUFFIX = ".exe" localAutomation.IS_WIN32 = True paths = [options.xrePath, localAutomation.DIST_BIN, self._automation._product, os.path.join('..', self._automation._product)] options.xrePath = self.findPath(paths) if options.xrePath == None: print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % (os.name) sys.exit(1) paths.append("bin") paths.append(os.path.join("..", "bin")) xpcshell = "xpcshell" if (os.name == "nt"): xpcshell += ".exe" if (options.utilityPath): paths.insert(0, options.utilityPath) options.utilityPath = self.findPath(paths, xpcshell) if options.utilityPath == None: print "ERROR: unable to find utility path for %s, please specify with --utility-path" % (os.name) sys.exit(1) xpcshell = os.path.join(options.utilityPath, xpcshell) if self._automation.elf_arm(xpcshell): raise Exception('xpcshell at %s is an ARM binary; please use ' 'the --utility-path argument to specify the path ' 'to a desktop version.' % xpcshell) options.serverProfilePath = tempfile.mkdtemp() self.server = ReftestServer(localAutomation, options, self.scriptDir) retVal = self.server.start() if retVal: return retVal if (options.pidFile != ""): f = open(options.pidFile + ".xpcshell.pid", 'w') f.write("%s" % self.server._process.pid) f.close() retVal = self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT) if retVal: return retVal options.xrePath = remoteXrePath options.utilityPath = remoteUtilityPath options.profilePath = remoteProfilePath return 0
class B2GReftest(RefTest): _automation = None _devicemanager = None localProfile = None remoteApp = "" profile = None def __init__(self, automation, devicemanager, options, scriptDir): self._automation = automation RefTest.__init__(self, self._automation) self._devicemanager = devicemanager self.runSSLTunnel = False self.remoteTestRoot = options.remoteTestRoot self.remoteProfile = options.remoteProfile self._automation.setRemoteProfile(self.remoteProfile) self.localLogName = options.localLogName self.remoteLogFile = options.remoteLogFile self.bundlesDir = "/system/b2g/distribution/bundles" self.userJS = "/data/local/user.js" self.remoteMozillaPath = "/data/b2g/mozilla" self.remoteProfilesIniPath = os.path.join(self.remoteMozillaPath, "profiles.ini") self.originalProfilesIni = None self.scriptDir = scriptDir self.SERVER_STARTUP_TIMEOUT = 90 if self._automation.IS_DEBUG_BUILD: self.SERVER_STARTUP_TIMEOUT = 180 def cleanup(self, profileDir): # Pull results back from device if self.remoteLogFile: try: self._devicemanager.getFile(self.remoteLogFile, self.localLogName) except: print "ERROR: We were not able to retrieve the info from %s" % self.remoteLogFile sys.exit(5) # Delete any bundled extensions extensionDir = os.path.join(profileDir, "extensions", "staged") for filename in os.listdir(extensionDir): try: self._devicemanager._checkCmdAs(["shell", "rm", "-rf", os.path.join(self.bundlesDir, filename)]) except devicemanager.DMError: pass # Restore the original profiles.ini. if self.originalProfilesIni: try: if not self._automation._is_emulator: self.restoreProfilesIni() os.remove(self.originalProfilesIni) except: pass if not self._automation._is_emulator: self._devicemanager.removeFile(self.remoteLogFile) self._devicemanager.removeDir(self.remoteProfile) self._devicemanager.removeDir(self.remoteTestRoot) # Restore the original user.js. self._devicemanager._checkCmdAs(["shell", "rm", "-f", self.userJS]) if self._devicemanager._useDDCopy: self._devicemanager._checkCmdAs(["shell", "dd", "if=%s.orig" % self.userJS, "of=%s" % self.userJS]) else: self._devicemanager._checkCmdAs(["shell", "cp", "%s.orig" % self.userJS, self.userJS]) # We've restored the original profile, so reboot the device so that # it gets picked up. self._automation.rebootDevice() RefTest.cleanup(self, profileDir) if getattr(self, "pidFile", "") != "": try: os.remove(self.pidFile) os.remove(self.pidFile + ".xpcshell.pid") except: print "Warning: cleaning up pidfile '%s' was unsuccessful from the test harness" % self.pidFile def findPath(self, paths, filename=None): for path in paths: p = path if filename: p = os.path.join(p, filename) if os.path.exists(self.getFullPath(p)): return path return None def startWebServer(self, options): """ Create the webserver on the host and start it up """ remoteXrePath = options.xrePath remoteProfilePath = self.remoteProfile remoteUtilityPath = options.utilityPath localAutomation = Automation() localAutomation.IS_WIN32 = False localAutomation.IS_LINUX = False localAutomation.IS_MAC = False localAutomation.UNIXISH = False hostos = sys.platform if hostos in ["mac", "darwin"]: localAutomation.IS_MAC = True elif hostos in ["linux", "linux2"]: localAutomation.IS_LINUX = True localAutomation.UNIXISH = True elif hostos in ["win32", "win64"]: localAutomation.BIN_SUFFIX = ".exe" localAutomation.IS_WIN32 = True paths = [ options.xrePath, localAutomation.DIST_BIN, self._automation._product, os.path.join("..", self._automation._product), ] options.xrePath = self.findPath(paths) if options.xrePath == None: print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % (os.name) sys.exit(1) paths.append("bin") paths.append(os.path.join("..", "bin")) xpcshell = "xpcshell" if os.name == "nt": xpcshell += ".exe" if options.utilityPath: paths.insert(0, options.utilityPath) options.utilityPath = self.findPath(paths, xpcshell) if options.utilityPath == None: print "ERROR: unable to find utility path for %s, please specify with --utility-path" % (os.name) sys.exit(1) options.serverProfilePath = tempfile.mkdtemp() self.server = ReftestServer(localAutomation, options, self.scriptDir) retVal = self.server.start() if retVal: return retVal if options.pidFile != "": f = open(options.pidFile + ".xpcshell.pid", "w") f.write("%s" % self.server._process.pid) f.close() retVal = self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT) if retVal: return retVal options.xrePath = remoteXrePath options.utilityPath = remoteUtilityPath options.profilePath = remoteProfilePath return 0 def stopWebServer(self, options): if hasattr(self, "server"): self.server.stop() def restoreProfilesIni(self): # restore profiles.ini on the device to its previous state if not self.originalProfilesIni or not os.access(self.originalProfilesIni, os.F_OK): raise devicemanager.DMError( "Unable to install original profiles.ini; file not found: %s", self.originalProfilesIni ) self._devicemanager.pushFile(self.originalProfilesIni, self.remoteProfilesIniPath) def updateProfilesIni(self, profilePath): # update profiles.ini on the device to point to the test profile self.originalProfilesIni = tempfile.mktemp() self._devicemanager.getFile(self.remoteProfilesIniPath, self.originalProfilesIni) config = ProfileConfigParser() config.read(self.originalProfilesIni) for section in config.sections(): if "Profile" in section: config.set(section, "IsRelative", 0) config.set(section, "Path", profilePath) newProfilesIni = tempfile.mktemp() with open(newProfilesIni, "wb") as configfile: config.write(configfile) self._devicemanager.pushFile(newProfilesIni, self.remoteProfilesIniPath) try: os.remove(newProfilesIni) except: pass def createReftestProfile(self, options, profileDir, reftestlist): print "profileDir: " + str(profileDir) retVal = RefTest.createReftestProfile(self, options, profileDir, reftestlist, server=options.remoteWebServer) # Turn off the locale picker screen fhandle = open(os.path.join(profileDir, "user.js"), "a") fhandle.write( """ user_pref("browser.firstrun.show.localepicker", false); user_pref("browser.homescreenURL","app://system.gaiamobile.org");\n user_pref("browser.manifestURL","app://system.gaiamobile.org/manifest.webapp");\n user_pref("browser.tabs.remote", false);\n user_pref("dom.ipc.browser_frames.oop_by_default", true);\n user_pref("dom.ipc.tabs.disabled", false);\n user_pref("dom.mozBrowserFramesEnabled", true);\n user_pref("dom.mozBrowserFramesWhitelist","app://system.gaiamobile.org");\n user_pref("network.dns.localDomains","app://system.gaiamobile.org");\n user_pref("font.size.inflation.emPerLine", 0); user_pref("font.size.inflation.minTwips", 0); user_pref("reftest.browser.iframe.enabled", false); user_pref("reftest.remote", true); user_pref("reftest.uri", "%s"); // Set a future policy version to avoid the telemetry prompt. user_pref("toolkit.telemetry.prompted", 999); user_pref("toolkit.telemetry.notifiedOptOut", 999); """ % reftestlist ) # workaround for jsreftests. if getattr(options, "enablePrivilege", False): fhandle.write( """ user_pref("capability.principal.codebase.p2.granted", "UniversalXPConnect"); user_pref("capability.principal.codebase.p2.id", "http://%s:%s"); """ % (options.remoteWebServer, options.httpPort) ) # Close the file fhandle.close() # Copy the profile to the device. self._devicemanager.removeDir(self.remoteProfile) try: self._devicemanager.pushDir(profileDir, self.remoteProfile) except devicemanager.DMError: print "Automation Error: Unable to copy profile to device." raise # Copy the extensions to the B2G bundles dir. extensionDir = os.path.join(profileDir, "extensions", "staged") # need to write to read-only dir self._devicemanager._checkCmdAs(["remount"]) for filename in os.listdir(extensionDir): self._devicemanager._checkCmdAs(["shell", "rm", "-rf", os.path.join(self.bundlesDir, filename)]) try: self._devicemanager.pushDir(extensionDir, self.bundlesDir) except devicemanager.DMError: print "Automation Error: Unable to copy extensions to device." raise # In B2G, user.js is always read from /data/local, not the profile # directory. Backup the original user.js first so we can restore it. self._devicemanager._checkCmdAs(["shell", "rm", "-f", "%s.orig" % self.userJS]) if self._devicemanager._useDDCopy: self._devicemanager._checkCmdAs(["shell", "dd", "if=%s" % self.userJS, "of=%s.orig" % self.userJS]) else: self._devicemanager._checkCmdAs(["shell", "cp", self.userJS, "%s.orig" % self.userJS]) self._devicemanager.pushFile(os.path.join(profileDir, "user.js"), self.userJS) self.updateProfilesIni(self.remoteProfile) options.profilePath = self.remoteProfile return retVal def copyExtraFilesToProfile(self, options, profileDir): RefTest.copyExtraFilesToProfile(self, options, profileDir) try: self._devicemanager.pushDir(profileDir, options.remoteProfile) except devicemanager.DMError: print "Automation Error: Failed to copy extra files to device" raise def getManifestPath(self, path): return path
def startWebServer(self, options): """ Create the webserver on the host and start it up """ remoteXrePath = options.xrePath remoteProfilePath = self.remoteProfile remoteUtilityPath = options.utilityPath localAutomation = Automation() localAutomation.IS_WIN32 = False localAutomation.IS_LINUX = False localAutomation.IS_MAC = False localAutomation.UNIXISH = False hostos = sys.platform if hostos in ['mac', 'darwin']: localAutomation.IS_MAC = True elif hostos in ['linux', 'linux2']: localAutomation.IS_LINUX = True localAutomation.UNIXISH = True elif hostos in ['win32', 'win64']: localAutomation.BIN_SUFFIX = ".exe" localAutomation.IS_WIN32 = True paths = [ options.xrePath, localAutomation.DIST_BIN, self.automation._product, os.path.join('..', self.automation._product) ] options.xrePath = self.findPath(paths) if options.xrePath == None: print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % ( os.name) sys.exit(1) paths.append("bin") paths.append(os.path.join("..", "bin")) xpcshell = "xpcshell" if (os.name == "nt"): xpcshell += ".exe" if (options.utilityPath): paths.insert(0, options.utilityPath) options.utilityPath = self.findPath(paths, xpcshell) if options.utilityPath == None: print "ERROR: unable to find utility path for %s, please specify with --utility-path" % ( os.name) sys.exit(1) xpcshell = os.path.join(options.utilityPath, xpcshell) if self.automation.elf_arm(xpcshell): raise Exception('xpcshell at %s is an ARM binary; please use ' 'the --utility-path argument to specify the path ' 'to a desktop version.' % xpcshell) options.serverProfilePath = tempfile.mkdtemp() self.server = ReftestServer(localAutomation, options, self.scriptDir) retVal = self.server.start() if retVal: return retVal if (options.pidFile != ""): f = open(options.pidFile + ".xpcshell.pid", 'w') f.write("%s" % self.server._process.pid) f.close() retVal = self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT) if retVal: return retVal options.xrePath = remoteXrePath options.utilityPath = remoteUtilityPath options.profilePath = remoteProfilePath return 0
class B2GRemoteReftest(RefTest): _devicemanager = None localProfile = None remoteApp = '' profile = None def __init__(self, automation, devicemanager, options, scriptDir): RefTest.__init__(self) self.automation = automation self._devicemanager = devicemanager self.runSSLTunnel = False self.remoteTestRoot = options.remoteTestRoot self.remoteProfile = options.remoteProfile self.automation.setRemoteProfile(self.remoteProfile) self.localLogName = options.localLogName self.remoteLogFile = options.remoteLogFile self.bundlesDir = '/system/b2g/distribution/bundles' self.remoteMozillaPath = '/data/b2g/mozilla' self.remoteProfilesIniPath = os.path.join(self.remoteMozillaPath, 'profiles.ini') self.originalProfilesIni = None self.scriptDir = scriptDir self.SERVER_STARTUP_TIMEOUT = 90 if self.automation.IS_DEBUG_BUILD: self.SERVER_STARTUP_TIMEOUT = 180 def cleanup(self, profileDir): # Pull results back from device if (self.remoteLogFile): try: self._devicemanager.getFile(self.remoteLogFile, self.localLogName) except: print "ERROR: We were not able to retrieve the info from %s" % self.remoteLogFile sys.exit(5) # Delete any bundled extensions if profileDir: extensionDir = os.path.join(profileDir, 'extensions', 'staged') for filename in os.listdir(extensionDir): try: self._devicemanager._checkCmd([ 'shell', 'rm', '-rf', os.path.join(self.bundlesDir, filename) ]) except DMError: pass # Restore the original profiles.ini. if self.originalProfilesIni: try: if not self.automation._is_emulator: self.restoreProfilesIni() os.remove(self.originalProfilesIni) except: pass if not self.automation._is_emulator: self._devicemanager.removeFile(self.remoteLogFile) self._devicemanager.removeDir(self.remoteProfile) self._devicemanager.removeDir(self.remoteTestRoot) # We've restored the original profile, so reboot the device so that # it gets picked up. self.automation.rebootDevice() RefTest.cleanup(self, profileDir) if getattr(self, 'pidFile', '') != '': try: os.remove(self.pidFile) os.remove(self.pidFile + ".xpcshell.pid") except: print "Warning: cleaning up pidfile '%s' was unsuccessful from the test harness" % self.pidFile def findPath(self, paths, filename=None): for path in paths: p = path if filename: p = os.path.join(p, filename) if os.path.exists(self.getFullPath(p)): return path return None def startWebServer(self, options): """ Create the webserver on the host and start it up """ remoteXrePath = options.xrePath remoteProfilePath = self.remoteProfile remoteUtilityPath = options.utilityPath localAutomation = Automation() localAutomation.IS_WIN32 = False localAutomation.IS_LINUX = False localAutomation.IS_MAC = False localAutomation.UNIXISH = False hostos = sys.platform if hostos in ['mac', 'darwin']: localAutomation.IS_MAC = True elif hostos in ['linux', 'linux2']: localAutomation.IS_LINUX = True localAutomation.UNIXISH = True elif hostos in ['win32', 'win64']: localAutomation.BIN_SUFFIX = ".exe" localAutomation.IS_WIN32 = True paths = [ options.xrePath, localAutomation.DIST_BIN, self.automation._product, os.path.join('..', self.automation._product) ] options.xrePath = self.findPath(paths) if options.xrePath == None: print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % ( os.name) sys.exit(1) paths.append("bin") paths.append(os.path.join("..", "bin")) xpcshell = "xpcshell" if (os.name == "nt"): xpcshell += ".exe" if (options.utilityPath): paths.insert(0, options.utilityPath) options.utilityPath = self.findPath(paths, xpcshell) if options.utilityPath == None: print "ERROR: unable to find utility path for %s, please specify with --utility-path" % ( os.name) sys.exit(1) xpcshell = os.path.join(options.utilityPath, xpcshell) if self.automation.elf_arm(xpcshell): raise Exception('xpcshell at %s is an ARM binary; please use ' 'the --utility-path argument to specify the path ' 'to a desktop version.' % xpcshell) options.serverProfilePath = tempfile.mkdtemp() self.server = ReftestServer(localAutomation, options, self.scriptDir) retVal = self.server.start() if retVal: return retVal if (options.pidFile != ""): f = open(options.pidFile + ".xpcshell.pid", 'w') f.write("%s" % self.server._process.pid) f.close() retVal = self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT) if retVal: return retVal options.xrePath = remoteXrePath options.utilityPath = remoteUtilityPath options.profilePath = remoteProfilePath return 0 def stopWebServer(self, options): if hasattr(self, 'server'): self.server.stop() def restoreProfilesIni(self): # restore profiles.ini on the device to its previous state if not self.originalProfilesIni or not os.access( self.originalProfilesIni, os.F_OK): raise DMError( 'Unable to install original profiles.ini; file not found: %s', self.originalProfilesIni) self._devicemanager.pushFile(self.originalProfilesIni, self.remoteProfilesIniPath) def updateProfilesIni(self, profilePath): # update profiles.ini on the device to point to the test profile self.originalProfilesIni = tempfile.mktemp() self._devicemanager.getFile(self.remoteProfilesIniPath, self.originalProfilesIni) config = ProfileConfigParser() config.read(self.originalProfilesIni) for section in config.sections(): if 'Profile' in section: config.set(section, 'IsRelative', 0) config.set(section, 'Path', profilePath) newProfilesIni = tempfile.mktemp() with open(newProfilesIni, 'wb') as configfile: config.write(configfile) self._devicemanager.pushFile(newProfilesIni, self.remoteProfilesIniPath) try: os.remove(newProfilesIni) except: pass def createReftestProfile(self, options, reftestlist): profile = RefTest.createReftestProfile(self, options, reftestlist, server=options.remoteWebServer, special_powers=False) profileDir = profile.profile prefs = {} # Turn off the locale picker screen prefs["browser.firstrun.show.localepicker"] = False prefs[ "b2g.system_startup_url"] = "app://test-container.gaiamobile.org/index.html" prefs[ "b2g.system_manifest_url"] = "app://test-container.gaiamobile.org/manifest.webapp" prefs["dom.ipc.tabs.disabled"] = False prefs["dom.mozBrowserFramesEnabled"] = True prefs["font.size.inflation.emPerLine"] = 0 prefs["font.size.inflation.minTwips"] = 0 prefs[ "network.dns.localDomains"] = "app://test-container.gaiamobile.org" prefs["reftest.browser.iframe.enabled"] = False prefs["reftest.remote"] = True prefs["reftest.uri"] = "%s" % reftestlist # Set a future policy version to avoid the telemetry prompt. prefs["toolkit.telemetry.prompted"] = 999 prefs["toolkit.telemetry.notifiedOptOut"] = 999 if options.oop: prefs['browser.tabs.remote.autostart'] = True prefs['reftest.browser.iframe.enabled'] = True # Set the extra prefs. profile.set_preferences(prefs) # Copy the profile to the device. self._devicemanager.removeDir(self.remoteProfile) try: self._devicemanager.pushDir(profileDir, self.remoteProfile) except DMError: print "Automation Error: Unable to copy profile to device." raise # Copy the extensions to the B2G bundles dir. extensionDir = os.path.join(profileDir, 'extensions', 'staged') # need to write to read-only dir self._devicemanager._checkCmd(['remount']) for filename in os.listdir(extensionDir): self._devicemanager._checkCmd([ 'shell', 'rm', '-rf', os.path.join(self.bundlesDir, filename) ]) try: self._devicemanager.pushDir(extensionDir, self.bundlesDir) except DMError: print "Automation Error: Unable to copy extensions to device." raise self.updateProfilesIni(self.remoteProfile) options.profilePath = self.remoteProfile return profile def copyExtraFilesToProfile(self, options, profile): profileDir = profile.profile RefTest.copyExtraFilesToProfile(self, options, profile) try: self._devicemanager.pushDir(profileDir, options.remoteProfile) except DMError: print "Automation Error: Failed to copy extra files to device" raise def getManifestPath(self, path): return path def environment(self, **kwargs): return self.automation.environment(**kwargs) def runApp(self, profile, binary, cmdargs, env, timeout=None, debuggerInfo=None, symbolsPath=None, options=None): status = self.automation.runApp(None, env, binary, profile.profile, cmdargs, utilityPath=options.utilityPath, xrePath=options.xrePath, debuggerInfo=debuggerInfo, symbolsPath=symbolsPath, timeout=timeout) return status
class B2GRemoteReftest(RefTest): _devicemanager = None localProfile = None remoteApp = '' profile = None def __init__(self, automation, devicemanager, options, scriptDir): RefTest.__init__(self, automation) self._devicemanager = devicemanager self.runSSLTunnel = False self.remoteTestRoot = options.remoteTestRoot self.remoteProfile = options.remoteProfile self.automation.setRemoteProfile(self.remoteProfile) self.localLogName = options.localLogName self.remoteLogFile = options.remoteLogFile self.bundlesDir = '/system/b2g/distribution/bundles' self.remoteMozillaPath = '/data/b2g/mozilla' self.remoteProfilesIniPath = os.path.join(self.remoteMozillaPath, 'profiles.ini') self.originalProfilesIni = None self.scriptDir = scriptDir self.SERVER_STARTUP_TIMEOUT = 90 if self.automation.IS_DEBUG_BUILD: self.SERVER_STARTUP_TIMEOUT = 180 def cleanup(self, profileDir): # Pull results back from device if (self.remoteLogFile): try: self._devicemanager.getFile(self.remoteLogFile, self.localLogName) except: print "ERROR: We were not able to retrieve the info from %s" % self.remoteLogFile sys.exit(5) # Delete any bundled extensions if profileDir: extensionDir = os.path.join(profileDir, 'extensions', 'staged') for filename in os.listdir(extensionDir): try: self._devicemanager._checkCmd(['shell', 'rm', '-rf', os.path.join(self.bundlesDir, filename)]) except DMError: pass # Restore the original profiles.ini. if self.originalProfilesIni: try: if not self.automation._is_emulator: self.restoreProfilesIni() os.remove(self.originalProfilesIni) except: pass if not self.automation._is_emulator: self._devicemanager.removeFile(self.remoteLogFile) self._devicemanager.removeDir(self.remoteProfile) self._devicemanager.removeDir(self.remoteTestRoot) # We've restored the original profile, so reboot the device so that # it gets picked up. self.automation.rebootDevice() RefTest.cleanup(self, profileDir) if getattr(self, 'pidFile', '') != '': try: os.remove(self.pidFile) os.remove(self.pidFile + ".xpcshell.pid") except: print "Warning: cleaning up pidfile '%s' was unsuccessful from the test harness" % self.pidFile def findPath(self, paths, filename = None): for path in paths: p = path if filename: p = os.path.join(p, filename) if os.path.exists(self.getFullPath(p)): return path return None def startWebServer(self, options): """ Create the webserver on the host and start it up """ remoteXrePath = options.xrePath remoteProfilePath = self.remoteProfile remoteUtilityPath = options.utilityPath localAutomation = Automation() localAutomation.IS_WIN32 = False localAutomation.IS_LINUX = False localAutomation.IS_MAC = False localAutomation.UNIXISH = False hostos = sys.platform if hostos in ['mac', 'darwin']: localAutomation.IS_MAC = True elif hostos in ['linux', 'linux2']: localAutomation.IS_LINUX = True localAutomation.UNIXISH = True elif hostos in ['win32', 'win64']: localAutomation.BIN_SUFFIX = ".exe" localAutomation.IS_WIN32 = True paths = [options.xrePath, localAutomation.DIST_BIN, self.automation._product, os.path.join('..', self.automation._product)] options.xrePath = self.findPath(paths) if options.xrePath == None: print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % (os.name) sys.exit(1) paths.append("bin") paths.append(os.path.join("..", "bin")) xpcshell = "xpcshell" if (os.name == "nt"): xpcshell += ".exe" if (options.utilityPath): paths.insert(0, options.utilityPath) options.utilityPath = self.findPath(paths, xpcshell) if options.utilityPath == None: print "ERROR: unable to find utility path for %s, please specify with --utility-path" % (os.name) sys.exit(1) xpcshell = os.path.join(options.utilityPath, xpcshell) if self.automation.elf_arm(xpcshell): raise Exception('xpcshell at %s is an ARM binary; please use ' 'the --utility-path argument to specify the path ' 'to a desktop version.' % xpcshell) options.serverProfilePath = tempfile.mkdtemp() self.server = ReftestServer(localAutomation, options, self.scriptDir) retVal = self.server.start() if retVal: return retVal if (options.pidFile != ""): f = open(options.pidFile + ".xpcshell.pid", 'w') f.write("%s" % self.server._process.pid) f.close() retVal = self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT) if retVal: return retVal options.xrePath = remoteXrePath options.utilityPath = remoteUtilityPath options.profilePath = remoteProfilePath return 0 def stopWebServer(self, options): if hasattr(self, 'server'): self.server.stop() def restoreProfilesIni(self): # restore profiles.ini on the device to its previous state if not self.originalProfilesIni or not os.access(self.originalProfilesIni, os.F_OK): raise DMError('Unable to install original profiles.ini; file not found: %s', self.originalProfilesIni) self._devicemanager.pushFile(self.originalProfilesIni, self.remoteProfilesIniPath) def updateProfilesIni(self, profilePath): # update profiles.ini on the device to point to the test profile self.originalProfilesIni = tempfile.mktemp() self._devicemanager.getFile(self.remoteProfilesIniPath, self.originalProfilesIni) config = ProfileConfigParser() config.read(self.originalProfilesIni) for section in config.sections(): if 'Profile' in section: config.set(section, 'IsRelative', 0) config.set(section, 'Path', profilePath) newProfilesIni = tempfile.mktemp() with open(newProfilesIni, 'wb') as configfile: config.write(configfile) self._devicemanager.pushFile(newProfilesIni, self.remoteProfilesIniPath) try: os.remove(newProfilesIni) except: pass def createReftestProfile(self, options, reftestlist): profile = RefTest.createReftestProfile(self, options, reftestlist, server=options.remoteWebServer, special_powers=False) profileDir = profile.profile prefs = {} # Turn off the locale picker screen prefs["browser.firstrun.show.localepicker"] = False prefs["b2g.system_startup_url"] = "app://test-container.gaiamobile.org/index.html" prefs["b2g.system_manifest_url"] = "app://test-container.gaiamobile.org/manifest.webapp" prefs["browser.tabs.remote"] = False prefs["dom.ipc.tabs.disabled"] = False prefs["dom.mozBrowserFramesEnabled"] = True prefs["font.size.inflation.emPerLine"] = 0 prefs["font.size.inflation.minTwips"] = 0 prefs["network.dns.localDomains"] = "app://test-container.gaiamobile.org" prefs["reftest.browser.iframe.enabled"] = False prefs["reftest.remote"] = True prefs["reftest.uri"] = "%s" % reftestlist # Set a future policy version to avoid the telemetry prompt. prefs["toolkit.telemetry.prompted"] = 999 prefs["toolkit.telemetry.notifiedOptOut"] = 999 if options.oop: prefs['browser.tabs.remote'] = True prefs['browser.tabs.remote.autostart'] = True prefs['reftest.browser.iframe.enabled'] = True # Set the extra prefs. profile.set_preferences(prefs) # Copy the profile to the device. self._devicemanager.removeDir(self.remoteProfile) try: self._devicemanager.pushDir(profileDir, self.remoteProfile) except DMError: print "Automation Error: Unable to copy profile to device." raise # Copy the extensions to the B2G bundles dir. extensionDir = os.path.join(profileDir, 'extensions', 'staged') # need to write to read-only dir self._devicemanager._checkCmd(['remount']) for filename in os.listdir(extensionDir): self._devicemanager._checkCmd(['shell', 'rm', '-rf', os.path.join(self.bundlesDir, filename)]) try: self._devicemanager.pushDir(extensionDir, self.bundlesDir) except DMError: print "Automation Error: Unable to copy extensions to device." raise self.updateProfilesIni(self.remoteProfile) options.profilePath = self.remoteProfile return profile def copyExtraFilesToProfile(self, options, profile): profileDir = profile.profile RefTest.copyExtraFilesToProfile(self, options, profile) try: self._devicemanager.pushDir(profileDir, options.remoteProfile) except DMError: print "Automation Error: Failed to copy extra files to device" raise def getManifestPath(self, path): return path
class B2GReftest(RefTest): _automation = None _devicemanager = None localProfile = None remoteApp = '' profile = None def __init__(self, automation, devicemanager, options, scriptDir): self._automation = automation RefTest.__init__(self, self._automation) self._devicemanager = devicemanager self.runSSLTunnel = False self.remoteTestRoot = options.remoteTestRoot self.remoteProfile = options.remoteProfile self._automation.setRemoteProfile(self.remoteProfile) self.localLogName = options.localLogName self.remoteLogFile = options.remoteLogFile self.userJS = '/data/local/user.js' self.testDir = '/data/local/tests' self.remoteMozillaPath = '/data/b2g/mozilla' self.remoteProfilesIniPath = os.path.join(self.remoteMozillaPath, 'profiles.ini') self.originalProfilesIni = None self.scriptDir = scriptDir self.SERVER_STARTUP_TIMEOUT = 90 if self._automation.IS_DEBUG_BUILD: self.SERVER_STARTUP_TIMEOUT = 180 def cleanup(self, profileDir): # Pull results back from device if (self.remoteLogFile): try: self._devicemanager.getFile(self.remoteLogFile, self.localLogName) except: print "ERROR: We were not able to retrieve the info from %s" % self.remoteLogFile sys.exit(5) # Restore the original profiles.ini. if self.originalProfilesIni: try: if not self._automation._is_emulator: self.restoreProfilesIni() os.remove(self.originalProfilesIni) except: pass if not self._automation._is_emulator: self._devicemanager.removeFile(self.remoteLogFile) self._devicemanager.removeDir(self.remoteProfile) self._devicemanager.removeDir(self.remoteTestRoot) # Restore the original user.js. self._devicemanager._checkCmdAs(['shell', 'rm', '-f', self.userJS]) if self._devicemanager.useDDCopy: self._devicemanager._checkCmdAs([ 'shell', 'dd', 'if=%s.orig' % self.userJS, 'of=%s' % self.userJS ]) else: self._devicemanager._checkCmdAs( ['shell', 'cp', '%s.orig' % self.userJS, self.userJS]) # We've restored the original profile, so reboot the device so that # it gets picked up. self._automation.rebootDevice() RefTest.cleanup(self, profileDir) if getattr(self, 'pidFile', '') != '': try: os.remove(self.pidFile) os.remove(self.pidFile + ".xpcshell.pid") except: print "Warning: cleaning up pidfile '%s' was unsuccessful from the test harness" % self.pidFile def findPath(self, paths, filename=None): for path in paths: p = path if filename: p = os.path.join(p, filename) if os.path.exists(self.getFullPath(p)): return path return None def startWebServer(self, options): """ Create the webserver on the host and start it up """ remoteXrePath = options.xrePath remoteProfilePath = self.remoteProfile remoteUtilityPath = options.utilityPath localAutomation = Automation() localAutomation.IS_WIN32 = False localAutomation.IS_LINUX = False localAutomation.IS_MAC = False localAutomation.UNIXISH = False hostos = sys.platform if hostos in ['mac', 'darwin']: localAutomation.IS_MAC = True elif hostos in ['linux', 'linux2']: localAutomation.IS_LINUX = True localAutomation.UNIXISH = True elif hostos in ['win32', 'win64']: localAutomation.BIN_SUFFIX = ".exe" localAutomation.IS_WIN32 = True paths = [ options.xrePath, localAutomation.DIST_BIN, self._automation._product, os.path.join('..', self._automation._product) ] options.xrePath = self.findPath(paths) if options.xrePath == None: print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % ( os.name) sys.exit(1) paths.append("bin") paths.append(os.path.join("..", "bin")) xpcshell = "xpcshell" if (os.name == "nt"): xpcshell += ".exe" if (options.utilityPath): paths.insert(0, options.utilityPath) options.utilityPath = self.findPath(paths, xpcshell) if options.utilityPath == None: print "ERROR: unable to find utility path for %s, please specify with --utility-path" % ( os.name) sys.exit(1) options.serverProfilePath = tempfile.mkdtemp() self.server = ReftestServer(localAutomation, options, self.scriptDir) retVal = self.server.start() if retVal: return retVal if (options.pidFile != ""): f = open(options.pidFile + ".xpcshell.pid", 'w') f.write("%s" % self.server._process.pid) f.close() retVal = self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT) if retVal: return retVal options.xrePath = remoteXrePath options.utilityPath = remoteUtilityPath options.profilePath = remoteProfilePath return 0 def stopWebServer(self, options): if hasattr(self, 'server'): self.server.stop() def restoreProfilesIni(self): # restore profiles.ini on the device to its previous state if not self.originalProfilesIni or not os.access( self.originalProfilesIni, os.F_OK): raise devicemanager.DMError( 'Unable to install original profiles.ini; file not found: %s', self.originalProfilesIni) self._devicemanager.pushFile(self.originalProfilesIni, self.remoteProfilesIniPath) def updateProfilesIni(self, profilePath): # update profiles.ini on the device to point to the test profile self.originalProfilesIni = tempfile.mktemp() self._devicemanager.getFile(self.remoteProfilesIniPath, self.originalProfilesIni) config = ProfileConfigParser() config.read(self.originalProfilesIni) for section in config.sections(): if 'Profile' in section: config.set(section, 'IsRelative', 0) config.set(section, 'Path', profilePath) newProfilesIni = tempfile.mktemp() with open(newProfilesIni, 'wb') as configfile: config.write(configfile) self._devicemanager.pushFile(newProfilesIni, self.remoteProfilesIniPath) try: os.remove(newProfilesIni) except: pass def createReftestProfile(self, options, profileDir, reftestlist): print "profileDir: " + str(profileDir) retVal = RefTest.createReftestProfile(self, options, profileDir, reftestlist, server=options.remoteWebServer) # Turn off the locale picker screen fhandle = open(os.path.join(profileDir, "user.js"), 'a') fhandle.write(""" user_pref("browser.firstrun.show.localepicker", false); user_pref("browser.homescreenURL","app://system.gaiamobile.org");\n user_pref("browser.manifestURL","app://system.gaiamobile.org/manifest.webapp");\n user_pref("browser.tabs.remote", false);\n user_pref("dom.ipc.browser_frames.oop_by_default", true);\n user_pref("dom.ipc.tabs.disabled", false);\n user_pref("dom.mozBrowserFramesEnabled", true);\n user_pref("dom.mozBrowserFramesWhitelist","app://system.gaiamobile.org");\n user_pref("network.dns.localDomains","app://system.gaiamobile.org");\n user_pref("font.size.inflation.emPerLine", 0); user_pref("font.size.inflation.minTwips", 0); user_pref("reftest.browser.iframe.enabled", true); user_pref("reftest.remote", true); user_pref("reftest.uri", "%s"); user_pref("toolkit.telemetry.prompted", true); """ % reftestlist) #workaround for jsreftests. if getattr(options, 'enablePrivilege', False): fhandle.write(""" user_pref("capability.principal.codebase.p2.granted", "UniversalXPConnect"); user_pref("capability.principal.codebase.p2.id", "http://%s:%s"); """ % (options.remoteWebServer, options.httpPort)) # Close the file fhandle.close() # Copy the profile to the device. self._devicemanager.removeDir(self.remoteProfile) try: self._devicemanager.pushDir(profileDir, self.remoteProfile) except devicemanager.DMError: print "Automation Error: Unable to copy profile to device." raise # In B2G, user.js is always read from /data/local, not the profile # directory. Backup the original user.js first so we can restore it. self._devicemanager._checkCmdAs( ['shell', 'rm', '-f', '%s.orig' % self.userJS]) if self._devicemanager.useDDCopy: self._devicemanager._checkCmdAs([ 'shell', 'dd', 'if=%s' % self.userJS, 'of=%s.orig' % self.userJS ]) else: self._devicemanager._checkCmdAs( ['shell', 'cp', self.userJS, '%s.orig' % self.userJS]) self._devicemanager.pushFile(os.path.join(profileDir, "user.js"), self.userJS) self.updateProfilesIni(self.remoteProfile) options.profilePath = self.remoteProfile return retVal def copyExtraFilesToProfile(self, options, profileDir): RefTest.copyExtraFilesToProfile(self, options, profileDir) try: self._devicemanager.pushDir(profileDir, options.remoteProfile) except devicemanager.DMError: print "Automation Error: Failed to copy extra files to device" raise def getManifestPath(self, path): return path
class B2GReftest(RefTest): _automation = None _devicemanager = None localProfile = None remoteApp = '' profile = None def __init__(self, automation, devicemanager, options, scriptDir): self._automation = automation RefTest.__init__(self, self._automation) self._devicemanager = devicemanager self.runSSLTunnel = False self.remoteTestRoot = options.remoteTestRoot self.remoteProfile = options.remoteProfile self._automation.setRemoteProfile(self.remoteProfile) self.localLogName = options.localLogName self.remoteLogFile = options.remoteLogFile self.userJS = '/data/local/user.js' self.testDir = '/data/local/tests' self.remoteMozillaPath = '/data/b2g/mozilla' self.remoteProfilesIniPath = os.path.join(self.remoteMozillaPath, 'profiles.ini') self.originalProfilesIni = None self.scriptDir = scriptDir self.SERVER_STARTUP_TIMEOUT = 90 if self._automation.IS_DEBUG_BUILD: self.SERVER_STARTUP_TIMEOUT = 180 def cleanup(self, profileDir): # Pull results back from device if (self.remoteLogFile): try: self._devicemanager.getFile(self.remoteLogFile, self.localLogName) except: print "ERROR: We were not able to retrieve the info from %s" % self.remoteLogFile sys.exit(5) # Restore the original profiles.ini. if self.originalProfilesIni: try: if not self._automation._is_emulator: self.restoreProfilesIni() os.remove(self.originalProfilesIni) except: pass if not self._automation._is_emulator: self._devicemanager.removeFile(self.remoteLogFile) self._devicemanager.removeDir(self.remoteProfile) self._devicemanager.removeDir(self.remoteTestRoot) # Restore the original user.js. self._devicemanager.checkCmdAs(['shell', 'rm', '-f', self.userJS]) if self._devicemanager.useDDCopy: self._devicemanager.checkCmdAs(['shell', 'dd', 'if=%s.orig' % self.userJS, 'of=%s' % self.userJS]) else: self._devicemanager.checkCmdAs(['shell', 'cp', '%s.orig' % self.userJS, self.userJS]) # We've restored the original profile, so reboot the device so that # it gets picked up. self._automation.rebootDevice() RefTest.cleanup(self, profileDir) if getattr(self, 'pidFile', '') != '': try: os.remove(self.pidFile) os.remove(self.pidFile + ".xpcshell.pid") except: print "Warning: cleaning up pidfile '%s' was unsuccessful from the test harness" % self.pidFile def findPath(self, paths, filename = None): for path in paths: p = path if filename: p = os.path.join(p, filename) if os.path.exists(self.getFullPath(p)): return path return None def startWebServer(self, options): """ Create the webserver on the host and start it up """ remoteXrePath = options.xrePath remoteProfilePath = self.remoteProfile remoteUtilityPath = options.utilityPath localAutomation = Automation() localAutomation.IS_WIN32 = False localAutomation.IS_LINUX = False localAutomation.IS_MAC = False localAutomation.UNIXISH = False hostos = sys.platform if hostos in ['mac', 'darwin']: localAutomation.IS_MAC = True elif hostos in ['linux', 'linux2']: localAutomation.IS_LINUX = True localAutomation.UNIXISH = True elif hostos in ['win32', 'win64']: localAutomation.BIN_SUFFIX = ".exe" localAutomation.IS_WIN32 = True paths = [options.xrePath, localAutomation.DIST_BIN, self._automation._product, os.path.join('..', self._automation._product)] options.xrePath = self.findPath(paths) if options.xrePath == None: print "ERROR: unable to find xulrunner path for %s, please specify with --xre-path" % (os.name) sys.exit(1) paths.append("bin") paths.append(os.path.join("..", "bin")) xpcshell = "xpcshell" if (os.name == "nt"): xpcshell += ".exe" if (options.utilityPath): paths.insert(0, options.utilityPath) options.utilityPath = self.findPath(paths, xpcshell) if options.utilityPath == None: print "ERROR: unable to find utility path for %s, please specify with --utility-path" % (os.name) sys.exit(1) options.serverProfilePath = tempfile.mkdtemp() self.server = ReftestServer(localAutomation, options, self.scriptDir) retVal = self.server.start() if retVal: return retVal if (options.pidFile != ""): f = open(options.pidFile + ".xpcshell.pid", 'w') f.write("%s" % self.server._process.pid) f.close() retVal = self.server.ensureReady(self.SERVER_STARTUP_TIMEOUT) if retVal: return retVal options.xrePath = remoteXrePath options.utilityPath = remoteUtilityPath options.profilePath = remoteProfilePath return 0 def stopWebServer(self, options): if hasattr(self, 'server'): self.server.stop() def restoreProfilesIni(self): # restore profiles.ini on the device to its previous state if not self.originalProfilesIni or not os.access(self.originalProfilesIni, os.F_OK): raise DMError('Unable to install original profiles.ini; file not found: %s', self.originalProfilesIni) self._devicemanager.pushFile(self.originalProfilesIni, self.remoteProfilesIniPath) def updateProfilesIni(self, profilePath): # update profiles.ini on the device to point to the test profile self.originalProfilesIni = tempfile.mktemp() self._devicemanager.getFile(self.remoteProfilesIniPath, self.originalProfilesIni) config = ProfileConfigParser() config.read(self.originalProfilesIni) for section in config.sections(): if 'Profile' in section: config.set(section, 'IsRelative', 0) config.set(section, 'Path', profilePath) newProfilesIni = tempfile.mktemp() with open(newProfilesIni, 'wb') as configfile: config.write(configfile) self._devicemanager.pushFile(newProfilesIni, self.remoteProfilesIniPath) try: os.remove(newProfilesIni) except: pass def createReftestProfile(self, options, profileDir, reftestlist): print "profileDir: " + str(profileDir) retVal = RefTest.createReftestProfile(self, options, profileDir, reftestlist, server=options.remoteWebServer) # Turn off the locale picker screen fhandle = open(os.path.join(profileDir, "user.js"), 'a') fhandle.write(""" user_pref("browser.homescreenURL", "data:text/html,<h1>reftests should start soon</h1>"); user_pref("browser.manifestURL", "dummy (bug 772307)"); user_pref("browser.firstrun.show.localepicker", false); user_pref("browser.dom.window.dump.enabled", true); user_pref("font.size.inflation.emPerLine", 0); user_pref("font.size.inflation.minTwips", 0); user_pref("reftest.remote", true); user_pref("toolkit.telemetry.prompted", true); user_pref("reftest.uri", "%s"); """ % reftestlist) #workaround for jsreftests. if getattr(options, 'enablePrivilege', False): fhandle.write(""" user_pref("capability.principal.codebase.p2.granted", "UniversalXPConnect"); user_pref("capability.principal.codebase.p2.id", "http://%s:%s"); """ % (options.remoteWebServer, options.httpPort)) # Close the file fhandle.close() # Copy the profile to the device. self._devicemanager.removeDir(self.remoteProfile) if self._devicemanager.pushDir(profileDir, self.remoteProfile) == None: raise devicemanager.FileError("Unable to copy profile to device.") # In B2G, user.js is always read from /data/local, not the profile # directory. Backup the original user.js first so we can restore it. self._devicemanager.checkCmdAs(['shell', 'rm', '-f', '%s.orig' % self.userJS]) if self._devicemanager.useDDCopy: self._devicemanager.checkCmdAs(['shell', 'dd', 'if=%s' % self.userJS, 'of=%s.orig' % self.userJS]) else: self._devicemanager.checkCmdAs(['shell', 'cp', self.userJS, '%s.orig' % self.userJS]) self._devicemanager.pushFile(os.path.join(profileDir, "user.js"), self.userJS) self.updateProfilesIni(self.remoteProfile) options.profilePath = self.remoteProfile return retVal def copyExtraFilesToProfile(self, options, profileDir): RefTest.copyExtraFilesToProfile(self, options, profileDir) if (self._devicemanager.pushDir(profileDir, options.remoteProfile) == None): raise devicemanager.FileError("Failed to copy extra files to device") def getManifestPath(self, path): return path