def RestartUsb(): if not os.path.isfile('/usr/bin/restart_usb'): print( 'ERROR: Could not restart usb. /usr/bin/restart_usb not installed ' 'on host (see BUG=305769).') return False lsusb_proc = bb_utils.SpawnCmd(['lsusb'], stdout=subprocess.PIPE) lsusb_output, _ = lsusb_proc.communicate() if lsusb_proc.returncode: print('Error: Could not get list of USB ports (i.e. lsusb).') return lsusb_proc.returncode usb_devices = [ re.findall('Bus (\d\d\d) Device (\d\d\d)', lsusb_line)[0] for lsusb_line in lsusb_output.strip().split('\n') ] all_restarted = True # Walk USB devices from leaves up (i.e reverse sorted) restarting the # connection. If a parent node (e.g. usb hub) is restarted before the # devices connected to it, the (bus, dev) for the hub can change, making the # output we have wrong. This way we restart the devices before the hub. for (bus, dev) in reversed(sorted(usb_devices)): # Can not restart root usb connections if dev != '001': return_code = bb_utils.RunCmd(['/usr/bin/restart_usb', bus, dev]) if return_code: print 'Error restarting USB device /dev/bus/usb/%s/%s' % (bus, dev) all_restarted = False else: print 'Restarted USB device /dev/bus/usb/%s/%s' % (bus, dev) return all_restarted
def SpawnLogcatMonitor(): shutil.rmtree(LOGCAT_DIR, ignore_errors=True) bb_utils.SpawnCmd([ os.path.join(CHROME_SRC_DIR, 'build', 'android', 'adb_logcat_monitor.py'), LOGCAT_DIR]) # Wait for logcat_monitor to pull existing logcat RunCmd(['sleep', '5'])
def MainTestWrapper(options): # Restart adb to work around bugs, sleep to wait for usb discovery. RunCmd(['adb', 'kill-server']) RunCmd(['adb', 'start-server']) RunCmd(['sleep', '1']) # Spawn logcat monitor logcat_dir = os.path.join(CHROME_SRC, 'out/logcat') shutil.rmtree(logcat_dir, ignore_errors=True) bb_utils.SpawnCmd(['build/android/adb_logcat_monitor.py', logcat_dir]) # Wait for logcat_monitor to pull existing logcat RunCmd(['sleep', '5']) # Provision devices buildbot_report.PrintNamedStep('provision_devices') if options.reboot: RebootDevices() RunCmd(['build/android/provision_devices.py', '-t', options.target]) # Device check and alert emails buildbot_report.PrintNamedStep('device_status_check') RunCmd(['build/android/device_status_check.py'], halt_on_failure=True) if options.install: test_obj = INSTRUMENTATION_TESTS[options.install] InstallApk(options, test_obj, print_step=True) if 'chromedriver' in options.test_filter: RunChromeDriverTests() if 'unit' in options.test_filter: RunTestSuites(options, gtest_config.STABLE_TEST_SUITES) if 'ui' in options.test_filter: for test in INSTRUMENTATION_TESTS.itervalues(): RunInstrumentationSuite(options, test) if 'webkit' in options.test_filter: RunTestSuites(options, [ gtest_config.Apk('webkit_unit_tests'), ]) RunWebkitLint(options.target) if 'webkit_layout' in options.test_filter: RunWebkitLayoutTests(options) if options.experimental: RunTestSuites(options, gtest_config.EXPERIMENTAL_TEST_SUITES) RunBrowserTestSuite(options) # Print logcat, kill logcat monitor buildbot_report.PrintNamedStep('logcat_dump') RunCmd(['build/android/adb_logcat_printer.py', logcat_dir]) buildbot_report.PrintNamedStep('test_report') for report in glob.glob( os.path.join(CHROME_SRC, 'out', options.target, 'test_logs', '*.log')): RunCmd(['cat', report]) os.remove(report)