Commit 1bf046db authored by Yuke Liao's avatar Yuke Liao Committed by Chromium LUCI CQ

Lacros: support --deploy-lacros in build/chromeos/test_runner.py

This CL supports running lacros tast tests in
build/chromeos/test_runner.py, and the main motivation is to run lacros
tast tests on Chromium CI.

Bug: 1158590
Change-Id: I8c63c57b95aee5b4c75a4e4561d4afda9d9f3432
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2605239
Commit-Queue: Yuke Liao <liaoyuke@chromium.org>
Reviewed-by: default avatarBen Pastene <bpastene@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841256}
parent 6a581d5c
......@@ -264,6 +264,13 @@ class TastTest(RemoteTest):
self._tests = args.tests
self._conditional = args.conditional
self._should_strip = args.strip_chrome
self._deploy_lacros = args.deploy_lacros
if self._deploy_lacros and self._should_strip:
raise TestFormatError(
'--strip-chrome is only applicable to ash-chrome because '
'lacros-chrome deployment uses --nostrip by default, so it cannot '
'be specificed with --deploy-lacros.')
if not self._llvm_profile_var and not self._logs_dir:
# The host-side Tast bin returns 0 when tests fail, so we need to capture
......@@ -290,11 +297,12 @@ class TastTest(RemoteTest):
if not arg.startswith('--gtest_repeat')
]
# Lacros deployment mounts itself by default.
self._test_cmd.extend(
['--deploy-lacros'] if self._deploy_lacros else ['--deploy', '--mount'])
self._test_cmd += [
'--deploy',
'--mount',
'--build-dir',
os.path.relpath(self._path_to_outdir, CHROMIUM_SRC_PATH),
os.path.relpath(self._path_to_outdir, CHROMIUM_SRC_PATH)
] + self._additional_args
# Coverage tests require some special pre-test setup, so use an
......@@ -329,10 +337,6 @@ class TastTest(RemoteTest):
'./' + os.path.relpath(self._on_device_script, self._path_to_outdir)
]
else:
# Mounting the browser gives it enough disk space to not need stripping,
# but only for browsers not instrumented with code coverage.
if not self._should_strip:
self._test_cmd.append('--nostrip')
# Capture tast's results in the logs dir as well.
if self._logs_dir:
self._test_cmd += [
......@@ -356,6 +360,12 @@ class TastTest(RemoteTest):
for v in self._tast_vars or []:
self._test_cmd.extend(['--tast-var', v])
# Mounting ash-chrome gives it enough disk space to not need stripping,
# but only for one not instrumented with code coverage.
# Lacros uses --nostrip by default, so there is no need to specify.
if not self._deploy_lacros and not self._should_strip:
self._test_cmd.append('--nostrip')
def post_run(self, return_code):
# If we don't need to parse the host-side Tast tool's results, fall back to
# the parent method's default behavior.
......@@ -705,7 +715,7 @@ def host_cmd(args, cmd_args):
if args.deploy_chrome:
cros_run_test_cmd += [
'--deploy',
# Mounting the browser gives it enough disk space to not need stripping.
# Mounting ash-chrome gives it enough disk space to not need stripping.
'--mount',
'--nostrip',
'--build-dir',
......@@ -822,8 +832,9 @@ def main():
host_cmd_parser.add_argument(
'--deploy-chrome',
action='store_true',
help='Will deploy a locally built Chrome binary to the device before '
help='Will deploy a locally built ash-chrome binary to the device before '
'running the host-cmd.')
# GTest args.
# TODO(bpastene): Rename 'vm-test' arg to 'gtest'.
gtest_parser = subparsers.add_parser(
......@@ -890,7 +901,11 @@ def main():
tast_test_parser.add_argument(
'--strip-chrome',
action='store_true',
help='Strips symbols from the browser before deploying to the device.')
help='Strips symbols from ash-chrome before deploying to the device.')
tast_test_parser.add_argument(
'--deploy-lacros',
action='store_true',
help='Deploy a lacros-chrome instead of ash-chrome.')
tast_test_parser.add_argument(
'--tast-var',
action='append',
......
......@@ -34,7 +34,12 @@ class TestRunnerTest(unittest.TestCase):
test_runner.result_sink, 'TryInitClient', return_value=None)
self.mock_rdb.start()
self.common_tast_args = [
def tearDown(self):
shutil.rmtree(self._tmp_dir, ignore_errors=True)
self.mock_rdb.stop()
def get_common_tast_args(self, use_vm):
return [
'script_name',
'tast',
'--suite-name=chrome_all_tast_tests',
......@@ -42,8 +47,11 @@ class TestRunnerTest(unittest.TestCase):
'--flash',
'--path-to-outdir=out_eve/Release',
'--logs-dir=%s' % self._tmp_dir,
'--use-vm' if use_vm else '--device=localhost:2222',
]
self.common_tast_expectations = [
def get_common_tast_expectations(self, use_vm, is_lacros=False):
expectation = [
test_runner.CROS_RUN_TEST_PATH,
'--board',
'eve',
......@@ -51,9 +59,6 @@ class TestRunnerTest(unittest.TestCase):
test_runner.DEFAULT_CROS_CACHE,
'--results-dest-dir',
'%s/system_logs' % self._tmp_dir,
'--mount',
'--deploy',
'--nostrip',
'--flash',
'--build-dir',
'out_eve/Release',
......@@ -62,10 +67,18 @@ class TestRunnerTest(unittest.TestCase):
'--tast-total-shards=1',
'--tast-shard-index=0',
]
def tearDown(self):
shutil.rmtree(self._tmp_dir, ignore_errors=True)
self.mock_rdb.stop()
expectation.extend(['--start', '--copy-on-write']
if use_vm else ['--device', 'localhost:2222'])
for p in test_runner.SYSTEM_LOG_LOCATIONS:
expectation.extend(['--results-src', p])
if not is_lacros:
expectation += [
'--mount',
'--deploy',
'--nostrip',
]
return expectation
@parameterized.expand([
[True],
......@@ -121,22 +134,17 @@ class TestRunnerTest(unittest.TestCase):
with open(os.path.join(self._tmp_dir, 'streamed_results.jsonl'), 'w') as f:
json.dump(_TAST_TEST_RESULTS_JSON, f)
args = self.common_tast_args + [
args = self.get_common_tast_args(use_vm) + [
'-t=ui.ChromeLogin',
'--use-vm' if use_vm else '--device=localhost:2222',
]
with mock.patch.object(sys, 'argv', args),\
mock.patch.object(test_runner.subprocess, 'Popen') as mock_popen:
mock_popen.return_value.returncode = 0
test_runner.main()
expected_cmd = self.common_tast_expectations + [
expected_cmd = self.get_common_tast_expectations(use_vm) + [
'--tast', 'ui.ChromeLogin'
]
expected_cmd.extend(['--start', '--copy-on-write']
if use_vm else ['--device', 'localhost:2222'])
for p in test_runner.SYSTEM_LOG_LOCATIONS:
expected_cmd.extend(['--results-src', p])
self.assertItemsEqual(expected_cmd, mock_popen.call_args[0][0])
......@@ -149,25 +157,47 @@ class TestRunnerTest(unittest.TestCase):
with open(os.path.join(self._tmp_dir, 'streamed_results.jsonl'), 'w') as f:
json.dump(_TAST_TEST_RESULTS_JSON, f)
args = self.common_tast_args + [
args = self.get_common_tast_args(use_vm) + [
'--attr-expr=( "group:mainline" && "dep:chrome" && !informational)',
'--use-vm' if use_vm else '--device=localhost:2222',
]
with mock.patch.object(sys, 'argv', args),\
mock.patch.object(test_runner.subprocess, 'Popen') as mock_popen:
mock_popen.return_value.returncode = 0
test_runner.main()
expected_cmd = self.common_tast_expectations + [
expected_cmd = self.get_common_tast_expectations(use_vm) + [
'--tast=( "group:mainline" && "dep:chrome" && !informational)',
]
expected_cmd.extend(['--start', '--copy-on-write']
if use_vm else ['--device', 'localhost:2222'])
for p in test_runner.SYSTEM_LOG_LOCATIONS:
expected_cmd.extend(['--results-src', p])
self.assertItemsEqual(expected_cmd, mock_popen.call_args[0][0])
@parameterized.expand([
[True],
[False],
])
def test_tast_lacros(self, use_vm):
"""Tests running a tast tests for Lacros."""
with open(os.path.join(self._tmp_dir, 'streamed_results.jsonl'), 'w') as f:
json.dump(_TAST_TEST_RESULTS_JSON, f)
args = self.get_common_tast_args(use_vm) + [
'-t=lacros.Basic',
'--deploy-lacros',
]
with mock.patch.object(sys, 'argv', args),\
mock.patch.object(test_runner.subprocess, 'Popen') as mock_popen:
mock_popen.return_value.returncode = 0
test_runner.main()
expected_cmd = self.get_common_tast_expectations(
use_vm, is_lacros=True) + [
'--tast',
'lacros.Basic',
'--deploy-lacros',
]
self.assertItemsEqual(expected_cmd, mock_popen.call_args[0][0])
@parameterized.expand([
[True],
......@@ -178,22 +208,17 @@ class TestRunnerTest(unittest.TestCase):
with open(os.path.join(self._tmp_dir, 'streamed_results.jsonl'), 'w') as f:
json.dump(_TAST_TEST_RESULTS_JSON, f)
args = self.common_tast_args + [
args = self.get_common_tast_args(use_vm) + [
'-t=ui.ChromeLogin',
'--tast-var=key=value',
'--use-vm' if use_vm else '--device=localhost:2222',
]
with mock.patch.object(sys, 'argv', args),\
mock.patch.object(test_runner.subprocess, 'Popen') as mock_popen:
mock_popen.return_value.returncode = 0
test_runner.main()
expected_cmd = self.common_tast_expectations + [
expected_cmd = self.get_common_tast_expectations(use_vm) + [
'--tast', 'ui.ChromeLogin', '--tast-var', 'key=value'
]
expected_cmd.extend(['--start', '--copy-on-write']
if use_vm else ['--device', 'localhost:2222'])
for p in test_runner.SYSTEM_LOG_LOCATIONS:
expected_cmd.extend(['--results-src', p])
self.assertItemsEqual(expected_cmd, mock_popen.call_args[0][0])
......
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