summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid <dyu@google.com>2017-03-18 00:59:59 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-03-18 00:59:59 +0000
commit191f9aa8024c95a957c7992035d6d1235a678d64 (patch)
treeedccae0db01ecd677af6fddd9be0835c1fb9515d
parent1716f3689fe0de5f42349643af45b393d2a534e7 (diff)
parent7193ecc6b626ce5d0f04cb847c1b4a41f1aced51 (diff)
downloadadt-infra-191f9aa8024c95a957c7992035d6d1235a678d64.tar.gz
Add test run length for adb stress tests.
am: 7193ecc6b6 Change-Id: I9e22a588f41d9152f9b39024c1db99dfa8ddfe16
-rw-r--r--adb_stress_tests/util.py55
1 files changed, 36 insertions, 19 deletions
diff --git a/adb_stress_tests/util.py b/adb_stress_tests/util.py
index 73cf6573..6d6b70b7 100644
--- a/adb_stress_tests/util.py
+++ b/adb_stress_tests/util.py
@@ -32,6 +32,19 @@ def print_progress(perc, prefix='',
sys.stdout.flush()
+def get_connected_devices():
+ """Returns list of adb device ids that are connected."""
+ proc = subprocess.Popen('adb devices'.split(), stdout=subprocess.PIPE)
+ output, error = proc.communicate()
+ connected = []
+ # Collect connected devices.
+ for emulator_entry in output.split('\n')[1:]:
+ if emulator_entry != '':
+ connected.append(emulator_entry.split('\t')[0])
+
+ return connected
+
+
def test_connected(devices):
"""Verify that the expected number of devices/emulators are still connected.
@@ -45,21 +58,9 @@ def test_connected(devices):
The connected member contains a list of device serial numbers
identifying the connected devices.
"""
- proc = subprocess.Popen('adb devices'.split(), stdout=subprocess.PIPE)
- output, error = proc.communicate()
- connected = []
# verify expected emulators/devices are present
- # Note that since Windows includes a carriage return, we
- # do it in a seperate loop.
- if platform.system() is not 'Windows':
- for emulator_entry in output.split('\n')[1:]:
- if emulator_entry != '':
- connected.append(emulator_entry.split('\t')[0])
- else:
- for emulator_entry in output.split('\r\n')[1:]:
- if emulator_entry != '':
- connected.append(emulator_entry.split('\t')[0])
-
+ # Note that since Windows includes a carriage return, we do it in a seperate loop.
+ connected = get_connected_devices()
success = True
if len(connected) != devices:
print('\n\nERROR:\nExpected number of connections: ' +
@@ -105,6 +106,7 @@ def launcher(test_fn, duration, devices, setup=noop, cleanup=noop, is_print_prog
# ThreadPool for running the tests in parallel.
# We choose the size to match the number of devices, so that every device can execute in parallel.
thread_pool = pool.ThreadPool(processes = devices)
+ connected_devices = get_connected_devices()
try:
setup()
@@ -122,7 +124,18 @@ def launcher(test_fn, duration, devices, setup=noop, cleanup=noop, is_print_prog
connection_success, connected = test_connected(devices)
if not connection_success:
- return False
+ failure_time = time.time() - start
+ for device in connected_devices:
+ if device not in connected:
+ filename = os.path.join(log_dir, device, str(iteration) + '.txt')
+ msg = ("Device failed connection test for interation "
+ + str(iteration)
+ + "(at " + str(failure_time) + " seconds)")
+ spit(filename, msg)
+
+ # if no devices are connected, then end test with failure.
+ if not connected:
+ return False
# Run one iteration of the test against every device in parallel
iteration += 1
@@ -136,8 +149,9 @@ def launcher(test_fn, duration, devices, setup=noop, cleanup=noop, is_print_prog
# Capture logcat.
logs = thread_pool.map(logcat, connected)
for device,log in zip(connected, logs):
- filename = os.path.join(log_dir, device, str(iteration) + '.txt')
- spit(filename, log)
+ if log:
+ filename = os.path.join(log_dir, device, str(iteration) + '.txt')
+ spit(filename, log)
# If we get here, the test completed successfully.
if is_print_progress:
@@ -192,8 +206,11 @@ def logcat(dut):
Returns:
String containing the command's output.
"""
- cmd = ['shell', 'logcat', '-d', '-v', 'threadtime']
- return adb(dut, cmd)
+ try:
+ cmd = ['shell', 'logcat', '-d', '-v', 'threadtime']
+ return adb(dut, cmd)
+ except:
+ return None
def spit(filename, text):