def main(argv): global ip_addr if (len(argv) < 4): log.info( "usage: logcat.py <device ip address> <output filename> <logcat options>" ) return 1 ip_addr = argv[1] output_filename = argv[2] logcat_options = argv[3] max_runtime = 3600 # 3600 seconds == 1 hour status = 0 dm = devicemanager.DeviceManagerSUT(ip_addr) if not dm: log.error("logcat.py: unable to open device manager") return 2 command = 'execext su t=%d logcat %s' % (max_runtime, logcat_options) log.debug('logcat.py running SUT command: %s' % command) try: with open(output_filename, 'w') as f: dm._sendCmds([{'cmd': command}], f) except devicemanager.DMError, e: log.error("Remote Device Error: Exception caught running logcat: %s" % str(e)) status = -1
def isMozpoolReady(device): """ Checks if the mozpool server is available and the device is in 'ready' state Returns MOZPOOL_STATE_READY if Mozpool is indeed listing device as ready Returns MOZPOOL_STATE_UNKNOWN if Mozpool claims the device is in a non-ready state Returns MOZPOOL_STATE_ERROR if Mozpool reports some other error. Returns MOZPOOL_STATE_MISSING if there is no Mozpool server found in DNS. """ import socket default_timeout = socket.getdefaulttimeout() socket.setdefaulttimeout(5) # Don't let networking delay us too long try: socket.gethostbyname(MOZPOOL_CNAME) except: log.info("No mozpool server in this VLAN") return MOZPOOL_STATE_MISSING finally: # Set socket timeout back socket.setdefaulttimeout(default_timeout) mpc = MozpoolHandler("http://%s" % MOZPOOL_CNAME, log) try: result = mpc.query_device_state(device) except MozpoolException as e: log.error("Unable to get mozpool state, mozpool returned error: %s" % sys.exc_info()[1]) return MOZPOOL_STATE_ERROR if result['state'] == "ready": log.debug("Mozpool state is 'ready'") return MOZPOOL_STATE_READY else: log.error("Mozpool state is '%s'" % result['state']) return MOZPOOL_STATE_UNKNOWN
def handlesig(signum, frame): log.debug('logcat.py received SIGINT; cleaning up and exiting...') # restore the original signal handler signal.signal(signal.SIGINT, original_sigint) cleanup() sys.exit(0)
def cleanup(): # Kill remote logcat process. Most process operations in devicemanager # work on applications, like org.mozilla.fennec, but not on native # processes like logcat. We work around that by directly executing # ps and kill. dm = devicemanager.DeviceManagerSUT(ip_addr) pid = findpid(dm, "logcat") if pid and pid > 0: log.debug('logcat.py killing logcat with pid %d' % pid) try: dm.shellCheckOutput(['kill', str(pid)], root=True) except devicemanager.DMError, e: log.error("Error killing logcat (pid %s): %s" % (str(pid), str(e)))
def runTests(device, proc_name, number): numfailed = -1 log.info("Starting to run tests") httpport = 8000 + int(number) # TODO: fix the host/port information so we don't have conflicts in # parallel runs cmd = [ "python", os.path.join(os.path.dirname(__file__), "tests/mochitest/runtestsremote.py"), "--app=%s" % proc_name, "--deviceIP=%s" % device, "--xre-path=%s" % os.path.join(os.path.dirname(__file__), "xre"), "--utility-path=%s" % os.path.join(os.path.dirname(__file__), "bin"), # "--test-path=dom/tests/mochitest/dom-level0", "--test-path=dom/tests/mochitest", "--http-port=%s" % httpport ] log.info("Going to run test: %s" % subprocess.list2cmdline(cmd)) proc = "" try: p = subprocess.Popen(cmd, stdout=subprocess.PIPE) proc = p.communicate()[0] except: log.error("Exception found while running unittests: %s" % sys.exc_info()[1]) log.info("Finished running mochitests") refinished = re.compile('([0-9]+) INFO SimpleTest FINISHED') refailed = re.compile('([0-9]+) INFO Failed: ([0-9]+)') for line in proc.split('\n'): log.debug(line) finished = refinished.match(line) failed = refailed.match(line) if failed: numfailed = int(failed.group(2)) if finished: if numfailed > 0: log.error("Found %s failures while running mochitest" % numfailed) return False return True return False
def runTests(device, proc_name, number): numfailed = -1 log.info("Starting to run tests") httpport = 8000 + int(number) # TODO: fix the host/port information so we don't have conflicts in # parallel runs cmd = ["python", os.path.join(os.path.dirname(__file__), "tests/mochitest/runtestsremote.py"), "--app=%s" % proc_name, "--deviceIP=%s" % device, "--xre-path=%s" % os.path.join(os.path.dirname(__file__), "xre"), "--utility-path=%s" % os.path.join(os.path.dirname(__file__), "bin"), # "--test-path=dom/tests/mochitest/dom-level0", "--test-path=dom/tests/mochitest", "--http-port=%s" % httpport] log.info("Going to run test: %s" % subprocess.list2cmdline(cmd)) proc = "" try: p = subprocess.Popen(cmd, stdout=subprocess.PIPE) proc = p.communicate()[0] except: log.error("Exception found while running unittests: %s" % sys.exc_info()[1]) log.info("Finished running mochitests") refinished = re.compile('([0-9]+) INFO SimpleTest FINISHED') refailed = re.compile('([0-9]+) INFO Failed: ([0-9]+)') for line in proc.split('\n'): log.debug(line) finished = refinished.match(line) failed = refailed.match(line) if failed: numfailed = int(failed.group(2)) if finished: if numfailed > 0: log.error("Found %s failures while running mochitest" % numfailed) return False return True return False
def main(argv): global ip_addr if (len(argv) < 4): log.info("usage: logcat.py <device ip address> <output filename> <logcat options>") return 1 ip_addr = argv[1] output_filename = argv[2] logcat_options = argv[3] max_runtime = 3600 # 3600 seconds == 1 hour status = 0 dm = devicemanager.DeviceManagerSUT(ip_addr) if not dm: log.error("logcat.py: unable to open device manager") return 2 command = 'execext su t=%d logcat %s' % (max_runtime, logcat_options) log.debug('logcat.py running SUT command: %s' % command) try: with open(output_filename, 'w') as f: dm._sendCmds([{'cmd': command}], f) except devicemanager.DMError, e: log.error("Remote Device Error: Exception caught running logcat: %s" % str(e)) status = -1
local_file.close() f = open(local_file_name, 'rb') data = f.read() f.close() return data if __name__ == '__main__': if (len(sys.argv) != 2): if os.getenv('SUT_NAME') in (None, ''): print "usage: updateSUT.py [device name]" print " Must have $SUT_NAME set in environ to omit device name" sys.exit(1) else: print "INFO: Using device '%s' found in env variable" % device_name else: device_name = sys.argv[1] apkFoopyDir = apkFoopyDirPattern % {'device_name': device_name} # Exit 5 if an error, for buildbot RETRY ret = 0 if main(device_name): ret = 5 sys.stdout.flush() sys.exit(ret) else: if device_name in (None, ''): raise ImportError("To use updateSUT.py non-standalone you need SUT_NAME defined in environment") else: log.debug("updateSUT: Using device '%s' found in env variable" % device_name)
data = f.read() f.close() return data if __name__ == '__main__': if (len(sys.argv) <> 2): if os.getenv('SUT_NAME') in (None, ''): print "usage: updateSUT.py [device name]" print " Must have $SUT_NAME set in environ to omit device name" sys.exit(1) else: print "INFO: Using device '%s' found in env variable" % device_name else: device_name = sys.argv[1] apkFoopyDir = apkFoopyDirPattern % {'device_name': device_name} # Exit 5 if an error, for buildbot RETRY ret = 0 if main(device_name): ret = 5 sys.stdout.flush() sys.exit(ret) else: if device_name in (None, ''): raise ImportError( "To use updateSUT.py non-standalone you need SUT_NAME defined in environment" ) else: log.debug("updateSUT: Using device '%s' found in env variable" % device_name)