Commit 7c4a2d84 authored by Ben Pastene's avatar Ben Pastene Committed by Commit Bot

Generalize on_device_script logic for cros remote tests.

This will let us call tast and sanity tests via a shell script on the
device. (Actually switching them will come in a follow-up CL.)

This will be useful for coverage tests, since they need special
setup on the device's filesystem prior to the tests.

Bug: 934059
Change-Id: I2a907d176faf4ce12411bd2157188f909e494cc5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1534857Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Commit-Queue: Ben Pastene <bpastene@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644398}
parent a30d510e
......@@ -75,6 +75,11 @@ class RemoteTest(object):
self._retries = 0
self._timeout = None
# The location on disk of a shell script that can be optionally used to
# invoke the test on the device. If it's not set, we assume self._test_cmd
# contains the test invocation.
self._on_device_script = None
self._test_cmd = [
CROS_RUN_TEST_PATH,
'--board', args.board,
......@@ -123,6 +128,15 @@ class RemoteTest(object):
def test_cmd(self):
return self._test_cmd
def write_test_script_to_disk(self, script_contents):
logging.info('Running the following command on the device:')
logging.info('\n' + '\n'.join(script_contents))
fd, tmp_path = tempfile.mkstemp(suffix='.sh', dir=self._path_to_outdir)
os.fchmod(fd, 0755)
with os.fdopen(fd, 'wb') as f:
f.write('\n'.join(script_contents))
return tmp_path
def run_test(self):
# Traps SIGTERM and kills all child processes of cros_run_test when it's
# caught. This will allow us to capture logs from the device if a test hangs
......@@ -171,6 +185,8 @@ class RemoteTest(object):
return test_proc.returncode
def post_run(self, return_code):
if self._on_device_script:
os.remove(self._on_device_script)
# Create a simple json results file for a test run. The results will contain
# only one test (suite_name), and will either be a PASS or FAIL depending on
# return_code.
......@@ -327,13 +343,8 @@ class GTestTest(RemoteTest):
test_invocation += ' %s' % ' '.join(self._additional_args)
device_test_script_contents.append(test_invocation)
logging.info('Running the following command on the device:')
logging.info('\n' + '\n'.join(device_test_script_contents))
fd, tmp_path = tempfile.mkstemp(suffix='.sh', dir=self._path_to_outdir)
os.fchmod(fd, 0755)
with os.fdopen(fd, 'wb') as f:
f.write('\n'.join(device_test_script_contents))
self._on_device_script = tmp_path
self._on_device_script = self.write_test_script_to_disk(
device_test_script_contents)
runtime_files = [os.path.relpath(self._on_device_script)]
runtime_files += self._read_runtime_files()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment