Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

Commit

Permalink
Bug 690311 - clean and verify connectivity to a tegra before launchin…
Browse files Browse the repository at this point in the history
…g a job on it. r=armenzg,bear

Part 2 - Tie in cleanup.py and refactor it a bit to support being launched here as well
  • Loading branch information
Justin Wood committed Mar 28, 2012
1 parent 85dd82e commit e432036
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 67 deletions.
160 changes: 94 additions & 66 deletions sut_tools/cleanup.py
@@ -1,75 +1,103 @@
#!/usr/bin/env python #!/usr/bin/env python


# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import os, sys import os, sys
import time import time
import devicemanagerSUT as devicemanager import devicemanagerSUT as devicemanager


from sut_lib import clearFlag, setFlag, checkDeviceRoot, stopProcess, checkStalled, waitForDevice from sut_lib import clearFlag, setFlag, checkDeviceRoot, stopProcess, checkStalled, waitForDevice


if (len(sys.argv) <> 2): # main() RETURN CODES
print "usage: cleanup.py <ip address>" RETCODE_SUCCESS = 0
sys.exit(1) RETCODE_ERROR = 1

RETCODE_KILLSTALLED = 2
cwd = os.getcwd()
pidDir = os.path.join(cwd, '..') def main(tegra=None, dm=None):
flagFile = os.path.join(pidDir, 'proxy.flg') assert ((tegra is not None) or (dm is not None)) # Require one to be set
errorFile = os.path.join(pidDir, 'error.flg')

tegra_name = os.environ['SUT_NAME']
processNames = [ 'org.mozilla.fennec', pidDir = os.path.join('/builds/', tegra_name)
'org.mozilla.fennec_aurora', flagFile = os.path.join(pidDir, 'proxy.flg')
'org.mozilla.fennec_unofficial', errorFile = os.path.join(pidDir, 'error.flg')
'org.mozilla.firefox',
'org.mozilla.firefox_beta', processNames = [ 'org.mozilla.fennec',
'org.mozilla.roboexample.test', 'org.mozilla.fennec_aurora',
] 'org.mozilla.fennec_unofficial',

'org.mozilla.firefox',
if os.path.exists(flagFile): 'org.mozilla.firefox_beta',
print "Warning proxy.flg found during cleanup" 'org.mozilla.roboexample.test',
clearFlag(flagFile) ]


print "Connecting to: " + sys.argv[1] if os.path.exists(flagFile):
dm = devicemanager.DeviceManagerSUT(sys.argv[1]) print "Warning proxy.flg found during cleanup"

clearFlag(flagFile, dump=True)
dm.debug = 5
devRoot = checkDeviceRoot(dm) if dm is None:

print "Connecting to: " + tegra
if not str(devRoot).startswith("/mnt/sdcard"): dm = devicemanager.DeviceManagerSUT(tegra)
setFlag(errorFile, "Remote Device Error: devRoot from devicemanager [%s] is not correct" % str(devRoot)) dm.debug = 5
sys.exit(1)

for p in processNames:
if dm.dirExists(devRoot): if dm.dirExists('/data/data/%s' % p):
status = dm.removeDir(devRoot) print dm.uninstallAppAndReboot(p)
print "removeDir() returned [%s]" % status waitForDevice(dm)
if status is None or not status:
setFlag(errorFile, "Remote Device Error: call to removeDir() returned [%s]" % status) # Now Verify that they are all gone
sys.exit(1) for p in processNames:

if dm.dirExists('/data/data/%s' % p):
if not dm.fileExists('/system/etc/hosts'): setFlag(errorFile, "Unable to properly uninstall %s" % p)
print "restoring /system/etc/hosts file" return RETCODE_ERROR
try:
dm.sendCMD(['exec mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system']) devRoot = checkDeviceRoot(dm)
data = "127.0.0.1 localhost"
dm.verifySendCMD(['push /mnt/sdcard/hosts ' + str(len(data)) + '\r\n', data], newline=False) if not str(devRoot).startswith("/mnt/sdcard"):
dm.verifySendCMD(['exec dd if=/mnt/sdcard/hosts of=/system/etc/hosts']) setFlag(errorFile, "Remote Device Error: devRoot from devicemanager [%s] is not correct" % str(devRoot))
except devicemanager.DMError, e: return RETCODE_ERROR
print "Exception hit while trying to restore /system/etc/hosts: %s" % str(e)
setFlag(errorFile, "failed to restore /system/etc/hosts") if dm.dirExists(devRoot):
sys.exit(1) status = dm.removeDir(devRoot)
print "removeDir() returned [%s]" % status
if status is None or not status:
setFlag(errorFile, "Remote Device Error: call to removeDir() returned [%s]" % status)
return RETCODE_ERROR
if dm.dirExists(devRoot):
setFlag(errorFile, "Remote Device Error: Unable to properly remove %s" % devRoot)
return RETCODE_ERROR

if not dm.fileExists('/system/etc/hosts'): if not dm.fileExists('/system/etc/hosts'):
setFlag(errorFile, "failed to restore /system/etc/hosts") print "restoring /system/etc/hosts file"
sys.exit(1) try:
else: dm.sendCMD(['exec mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system'])
print "successfully restored hosts file, we can test!!!" data = "127.0.0.1 localhost"

dm.verifySendCMD(['push /mnt/sdcard/hosts ' + str(len(data)) + '\r\n', data], newline=False)
errcode = checkStalled(os.environ['SUT_NAME']) dm.verifySendCMD(['exec dd if=/mnt/sdcard/hosts of=/system/etc/hosts'])
if errcode > 1: except devicemanager.DMError, e:
if errcode == 2: print "Exception hit while trying to restore /system/etc/hosts: %s" % str(e)
print "processes from previous run were detected and cleaned up" setFlag(errorFile, "failed to restore /system/etc/hosts")
elif errocode == 3: return RETCODE_ERROR
setFlag(errorFile, "Remote Device Error: process from previous test run present") if not dm.fileExists('/system/etc/hosts'):
sys.exit(2) setFlag(errorFile, "failed to restore /system/etc/hosts")

return RETCODE_ERROR
for p in processNames: else:
if dm.dirExists('/data/data/%s' % p): print "successfully restored hosts file, we can test!!!"
print dm.uninstallAppAndReboot(p)
waitForDevice(dm) errcode = checkStalled(tegra_name)
if errcode > 1:
if errcode == 2:
print "processes from previous run were detected and cleaned up"
elif errocode == 3:
setFlag(errorFile, "Remote Device Error: process from previous test run present")
return RETCODE_KILLSTALLED

return RETCODE_SUCCESS

if __name__ == '__main__':
if (len(sys.argv) <> 2):
print "usage: cleanup.py <tegra name || ip address>"
sys.exit(RETCODE_ERROR)

retval = main(tegra=sys.argv[1])
sys.exit(retval)
7 changes: 6 additions & 1 deletion sut_tools/sut_lib.py
Expand Up @@ -370,8 +370,13 @@ def setFlag(flagfile, contents=None):
h.close() h.close()
time.sleep(30) time.sleep(30)


def clearFlag(flagfile): def clearFlag(flagfile, dump=False):
if os.path.exists(flagfile): if os.path.exists(flagfile):
if dump:
# Py 2.6 syntax
print "Contents of %s follow:" % flagfile
with open(flagfile, "r") as f:
print f.read()
os.remove(flagfile) os.remove(flagfile)


def calculatePort(): def calculatePort():
Expand Down
26 changes: 26 additions & 0 deletions sut_tools/verify.py
@@ -1,5 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python


# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import sys import sys
import os import os
import time import time
Expand Down Expand Up @@ -149,6 +153,25 @@ def checkSDCard(dm):
return False return False
return True return True


def cleanupTegra(dm):
""" Do cleanup actions necessary to ensure starting in a good state
Returns False on failure, True on Success
"""
if not dmAlive(dm):
return False

import cleanup
try:
retval = cleanup.main(dm=dm)
if retval == cleanup.RETCODE_SUCCESS:
# All is good
return True
except:
pass
# Some sort of error happened above
return False

def main(tegra): def main(tegra):
# Returns False on failure, True on Success # Returns False on failure, True on Success
global dm, errorFile global dm, errorFile
Expand All @@ -173,6 +196,9 @@ def main(tegra):
if not checkSDCard(dm): if not checkSDCard(dm):
return False return False


if not cleanupTegra(dm):
return False

return True return True


if __name__ == '__main__': if __name__ == '__main__':
Expand Down

0 comments on commit e432036

Please sign in to comment.