Files
android_external_libcxx/test/libcxx/android/executors.py
Dan Albert 5d8e4e3581 Update Android's test configuration for new APIs.
The upstream test runner has changed enough that the way Android was
shimmed into it was no longer compatible. This adapts our test runner
to the new APIs for cross-compiling and remote execution.

There's probably a fair amount of dead code in the Android test
runners now (or at least some code that should be made dead). I'll
clean it up in a later patch, but want to get us up and running for
now.

The NDK test runner will need to be updated as well. There aren't any
continuous runs for that, so that will be fixed in a follow up as
well.

Change-Id: I1756f538aa6c7136ebd26d1e81c8299b87f0c6b2
2015-03-12 11:00:36 -07:00

56 lines
2.0 KiB
Python

import time
import libcxx.test.executor
from libcxx.android import adb
from lit.util import executeCommand # pylint: disable=import-error
class AdbExecutor(libcxx.test.executor.RemoteExecutor):
def __init__(self, serial=None):
# TODO(danalbert): Should factor out the shared pieces of SSHExecutor
# so we don't have this ugly parent constructor...
super(AdbExecutor, self).__init__()
self.serial = serial
self.local_run = executeCommand
def _remote_temp(self, is_dir):
dir_arg = '-d' if is_dir else ''
cmd = 'mktemp -q {} /data/local/tmp/libcxx.XXXXXXXXXX'.format(dir_arg)
temp_path, err, exitCode = self._execute_command_remote([cmd])
temp_path = temp_path.strip()
if exitCode != 0:
raise RuntimeError(err)
return temp_path
def _copy_in_file(self, src, dst): # pylint: disable=no-self-use
adb.push(src, dst)
def _execute_command_remote(self, cmd, remote_work_dir='.', env=None):
adb_cmd = ['adb', 'shell']
if self.serial:
adb_cmd.extend(['-s', self.serial])
if env:
env_cmd = ['env'] + ['%s=%s' % (k, v) for k, v in env.items()]
else:
env_cmd = []
remote_cmd = ' '.join(env_cmd + cmd + ['; echo $?'])
if remote_work_dir != '.':
remote_cmd = 'cd {} && {}'.format(remote_work_dir, remote_cmd)
adb_cmd.append(remote_cmd)
# Tests will commonly fail with ETXTBSY. Possibly related to this bug:
# https://code.google.com/p/android/issues/detail?id=65857. Work around
# it by just waiting a second and then retrying.
for _ in range(10):
out, err, exit_code = self.local_run(adb_cmd)
if 'Text file busy' in out:
time.sleep(1)
else:
out = out.strip().split('\r\n')
status_line = out[-1:][0]
out = '\n'.join(out[:-1])
exit_code = int(status_line)
break
return out, err, exit_code