Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bug 690311 - clean and verify connectivity to a tegra before launchin…

…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...
commit e43203624ea1353cf247b2f3317579e4a63a0be4 1 parent 85dd82e
Justin Wood authored
Showing with 126 additions and 67 deletions.
  1. +94 −66 sut_tools/cleanup.py
  2. +6 −1 sut_tools/sut_lib.py
  3. +26 −0 sut_tools/verify.py
View
160 sut_tools/cleanup.py
@@ -1,75 +1,103 @@
#!/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 time
import devicemanagerSUT as devicemanager
from sut_lib import clearFlag, setFlag, checkDeviceRoot, stopProcess, checkStalled, waitForDevice
-if (len(sys.argv) <> 2):
- print "usage: cleanup.py <ip address>"
- sys.exit(1)
-
-cwd = os.getcwd()
-pidDir = os.path.join(cwd, '..')
-flagFile = os.path.join(pidDir, 'proxy.flg')
-errorFile = os.path.join(pidDir, 'error.flg')
-
-processNames = [ 'org.mozilla.fennec',
- 'org.mozilla.fennec_aurora',
- 'org.mozilla.fennec_unofficial',
- 'org.mozilla.firefox',
- 'org.mozilla.firefox_beta',
- 'org.mozilla.roboexample.test',
- ]
-
-if os.path.exists(flagFile):
- print "Warning proxy.flg found during cleanup"
- clearFlag(flagFile)
-
-print "Connecting to: " + sys.argv[1]
-dm = devicemanager.DeviceManagerSUT(sys.argv[1])
-
-dm.debug = 5
-devRoot = checkDeviceRoot(dm)
-
-if not str(devRoot).startswith("/mnt/sdcard"):
- setFlag(errorFile, "Remote Device Error: devRoot from devicemanager [%s] is not correct" % str(devRoot))
- sys.exit(1)
-
-if dm.dirExists(devRoot):
- 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)
- sys.exit(1)
-
-if not dm.fileExists('/system/etc/hosts'):
- print "restoring /system/etc/hosts file"
- try:
- dm.sendCMD(['exec mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system'])
- data = "127.0.0.1 localhost"
- dm.verifySendCMD(['push /mnt/sdcard/hosts ' + str(len(data)) + '\r\n', data], newline=False)
- dm.verifySendCMD(['exec dd if=/mnt/sdcard/hosts of=/system/etc/hosts'])
- except devicemanager.DMError, e:
- print "Exception hit while trying to restore /system/etc/hosts: %s" % str(e)
- setFlag(errorFile, "failed to restore /system/etc/hosts")
- sys.exit(1)
+# main() RETURN CODES
+RETCODE_SUCCESS = 0
+RETCODE_ERROR = 1
+RETCODE_KILLSTALLED = 2
+
+def main(tegra=None, dm=None):
+ assert ((tegra is not None) or (dm is not None)) # Require one to be set
+
+ tegra_name = os.environ['SUT_NAME']
+ pidDir = os.path.join('/builds/', tegra_name)
+ flagFile = os.path.join(pidDir, 'proxy.flg')
+ errorFile = os.path.join(pidDir, 'error.flg')
+
+ processNames = [ 'org.mozilla.fennec',
+ 'org.mozilla.fennec_aurora',
+ 'org.mozilla.fennec_unofficial',
+ 'org.mozilla.firefox',
+ 'org.mozilla.firefox_beta',
+ 'org.mozilla.roboexample.test',
+ ]
+
+ if os.path.exists(flagFile):
+ print "Warning proxy.flg found during cleanup"
+ clearFlag(flagFile, dump=True)
+
+ if dm is None:
+ print "Connecting to: " + tegra
+ dm = devicemanager.DeviceManagerSUT(tegra)
+ dm.debug = 5
+
+ for p in processNames:
+ if dm.dirExists('/data/data/%s' % p):
+ print dm.uninstallAppAndReboot(p)
+ waitForDevice(dm)
+
+ # Now Verify that they are all gone
+ for p in processNames:
+ if dm.dirExists('/data/data/%s' % p):
+ setFlag(errorFile, "Unable to properly uninstall %s" % p)
+ return RETCODE_ERROR
+
+ devRoot = checkDeviceRoot(dm)
+
+ if not str(devRoot).startswith("/mnt/sdcard"):
+ setFlag(errorFile, "Remote Device Error: devRoot from devicemanager [%s] is not correct" % str(devRoot))
+ return RETCODE_ERROR
+
+ if dm.dirExists(devRoot):
+ 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'):
- setFlag(errorFile, "failed to restore /system/etc/hosts")
- sys.exit(1)
- else:
- print "successfully restored hosts file, we can test!!!"
-
-errcode = checkStalled(os.environ['SUT_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")
- sys.exit(2)
-
-for p in processNames:
- if dm.dirExists('/data/data/%s' % p):
- print dm.uninstallAppAndReboot(p)
- waitForDevice(dm)
+ print "restoring /system/etc/hosts file"
+ try:
+ dm.sendCMD(['exec mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system'])
+ data = "127.0.0.1 localhost"
+ dm.verifySendCMD(['push /mnt/sdcard/hosts ' + str(len(data)) + '\r\n', data], newline=False)
+ dm.verifySendCMD(['exec dd if=/mnt/sdcard/hosts of=/system/etc/hosts'])
+ except devicemanager.DMError, e:
+ print "Exception hit while trying to restore /system/etc/hosts: %s" % str(e)
+ setFlag(errorFile, "failed to restore /system/etc/hosts")
+ return RETCODE_ERROR
+ if not dm.fileExists('/system/etc/hosts'):
+ setFlag(errorFile, "failed to restore /system/etc/hosts")
+ return RETCODE_ERROR
+ else:
+ print "successfully restored hosts file, we can test!!!"
+
+ 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)
View
7 sut_tools/sut_lib.py
@@ -370,8 +370,13 @@ def setFlag(flagfile, contents=None):
h.close()
time.sleep(30)
-def clearFlag(flagfile):
+def clearFlag(flagfile, dump=False):
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)
def calculatePort():
View
26 sut_tools/verify.py
@@ -1,5 +1,9 @@
#!/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 os
import time
@@ -149,6 +153,25 @@ def checkSDCard(dm):
return False
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):
# Returns False on failure, True on Success
global dm, errorFile
@@ -173,6 +196,9 @@ def main(tegra):
if not checkSDCard(dm):
return False
+ if not cleanupTegra(dm):
+ return False
+
return True
if __name__ == '__main__':
Please sign in to comment.
Something went wrong with that request. Please try again.