1
# ***** BEGIN LICENSE BLOCK *****
2
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
# The contents of this file are subject to the Mozilla Public License Version
5
# 1.1 (the "License"); you may not use this file except in compliance with
6
# the License. You may obtain a copy of the License at
7
# http://www.mozilla.org/MPL/
9
# Software distributed under the License is distributed on an "AS IS" basis,
10
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
# for the specific language governing rights and limitations under the
14
# The Original Code is mozilla.org code.
16
# The Initial Developer of the Original Code is Joel Maher.
18
# Portions created by the Initial Developer are Copyright (C) 2010
19
# the Initial Developer. All Rights Reserved.
22
# Joel Maher <joel.maher@gmail.com> (Original Developer)
23
# Clint Talbert <cmtalbert@gmail.com>
25
# Alternatively, the contents of this file may be used under the terms of
26
# either the GNU General Public License Version 2 or later (the "GPL"), or
27
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
# in which case the provisions of the GPL or the LGPL are applicable instead
29
# of those above. If you wish to allow use of your version of this file only
30
# under the terms of either the GPL or the LGPL, and not to allow others to
31
# use your version of this file under the terms of the MPL, indicate your
32
# decision by deleting the provisions above and replace them with the notice
33
# and other provisions required by the GPL or the LGPL. If you do not delete
34
# the provisions above, a recipient may use your version of this file under
35
# the terms of any one of the MPL, the GPL or the LGPL.
37
# ***** END LICENSE BLOCK *****
44
from automation import Automation
45
from devicemanager import DeviceManager, NetworkTools
47
class RemoteAutomation(Automation):
50
def __init__(self, deviceManager, appName = '', remoteLog = None):
51
self._devicemanager = deviceManager
52
self._appName = appName
53
self._remoteProfile = None
54
self._remoteLog = remoteLog
56
# Default our product to fennec
57
self._product = "fennec"
58
Automation.__init__(self)
60
def setDeviceManager(self, deviceManager):
61
self._devicemanager = deviceManager
63
def setAppName(self, appName):
64
self._appName = appName
66
def setRemoteProfile(self, remoteProfile):
67
self._remoteProfile = remoteProfile
69
def setProduct(self, product):
70
self._product = product
72
def setRemoteLog(self, logfile):
73
self._remoteLog = logfile
75
# Set up what we need for the remote environment
76
def environment(self, env = None, xrePath = None, crashreporter = True):
77
# Because we are running remote, we don't want to mimic the local env
78
# so no copying of os.environ
83
env['MOZ_CRASHREPORTER_NO_REPORT'] = '1'
84
env['MOZ_CRASHREPORTER'] = '1'
86
env['MOZ_CRASHREPORTER_DISABLE'] = '1'
90
def waitForFinish(self, proc, utilityPath, timeout, maxTime, startTime, debuggerInfo, symbolsDir):
91
# maxTime is used to override the default timeout, we should honor that
92
status = proc.wait(timeout = maxTime)
96
if (status == 1 and self._devicemanager.processExist(proc.procName)):
97
# Then we timed out, make sure Fennec is dead
102
def buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs):
103
# If remote profile is specified, use that instead
104
if (self._remoteProfile):
105
profileDir = self._remoteProfile
107
cmd, args = Automation.buildCommandLine(self, app, debuggerInfo, profileDir, testURL, extraArgs)
108
# Remove -foreground if it exists, if it doesn't this just returns
110
args.remove('-foreground')
113
#TODO: figure out which platform require NO_EM_RESTART
114
# return app, ['--environ:NO_EM_RESTART=1'] + args
118
nettools = NetworkTools()
119
return nettools.getLanIp()
121
def Process(self, cmd, stdout = None, stderr = None, env = None, cwd = '.'):
122
if stdout == None or stdout == -1 or stdout == subprocess.PIPE:
123
stdout = self._remoteLog
125
return self.RProcess(self._devicemanager, cmd, stdout, stderr, env, cwd)
127
# be careful here as this inner class doesn't have access to outer class members
128
class RProcess(object):
129
# device manager process
131
def __init__(self, dm, cmd, stdout = None, stderr = None, env = None, cwd = '.'):
134
self.proc = dm.launchProcess(cmd, stdout, cwd, env, True)
135
if (self.proc is None):
136
raise Exception("unable to launch process")
138
name = exepath.split('/')[-1]
141
# Setting timeout at 1 hour since on a remote device this takes much longer
147
hexpid = self.dm.processExist(self.procName)
150
return int(hexpid, 0)
154
t = self.dm.getFile(self.proc)
155
if t == None: return ''
157
retVal = t[self.stdoutlen:]
158
self.stdoutlen = tlen
159
return retVal.strip('\n').strip()
161
def wait(self, timeout = None):
166
timeout = self.timeout
168
while (self.dm.processExist(self.procName)):
173
if (timer > timeout):
176
if (timer >= timeout):
181
self.dm.killProcess(self.procName)