Commit 0ccddac8 authored by Yuke Liao's avatar Yuke Liao Committed by Commit Bot

[lacros] Make test runner differentiate different test targets

Different test targets should be handled differently depending on
whether they require a display server:
* If they do, download and starts an ash-chrome before running tests.
* Otherwise, run them directly like a regular Linux build.

Bug: 1104318
Change-Id: I10e15bc31efbb502c60cd797f59c1a5c2613631a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2303973Reviewed-by: default avatarDirk Pranke <dpranke@google.com>
Reviewed-by: default avatarSven Zheng <svenzheng@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Commit-Queue: Yuke Liao <liaoyuke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789731}
parent 046ea7f6
......@@ -58,6 +58,13 @@ wheel: <
version: "version:5.2.2"
>
# Used by:
# build/lacros/test_runner.py
wheel: <
name: "infra/python/wheels/parameterized-py2_py3"
version: "version:0.7.1"
>
# Used by:
# third_party/catapult
#
......
......@@ -42,6 +42,15 @@ _GS_ASH_CHROME_PATH = 'linux-chromeos/chrome-linux-chromeos.zip'
_PREBUILT_ASH_CHROME_DIR = os.path.join(os.path.dirname(__file__),
'prebuilt_ash_chrome')
# TODO(crbug.com/1104291): Complete this list once the lacros FYI builder is
# running all the test targets.
# List of targets that require ash-chrome as a Wayland server in order to run.
_TARGETS_REQUIRE_ASH_CHROME = [
'browser_tests',
'components_unittests',
'unit_tests',
]
def _GetAshChromeDirPath(version):
"""Returns a path to the dir storing the downloaded version of ash-chrome."""
......@@ -153,6 +162,13 @@ def _ParseArguments():
'"./url_unittests". Any argument unknown to this test runner script will '
'be forwarded to the command, for example: "--gtest_filter=Suite.Test"')
arg_parser.add_argument(
'-a',
'--ash-chrome-version',
type=str,
help='Version of ash_chrome to use for testing, for example: '
'"86.0.4187.0". If not specified, will use the latest version')
args = arg_parser.parse_known_args()
return args[0], args[1]
......@@ -160,7 +176,8 @@ def _ParseArguments():
def Main():
logging.basicConfig(level=logging.INFO)
args, forward_args = _ParseArguments()
return subprocess.call([args.command] + forward_args)
if os.path.basename(args.command) not in _TARGETS_REQUIRE_ASH_CHROME:
return subprocess.call([args.command] + forward_args)
if __name__ == '__main__':
......
#!/usr/bin/env vpython
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import subprocess
import sys
import unittest
import mock
from parameterized import parameterized
import test_runner
class TestRunnerTest(unittest.TestCase):
@parameterized.expand([
'url_unittests',
'./url_unittests',
'out/release/url_unittests',
'./out/release/url_unittests',
])
@mock.patch.object(test_runner, '_DownloadAshChromeIfNecessary')
@mock.patch.object(subprocess, 'call')
# Tests that the test runner doesn't attempt to download ash-chrome if not
# required.
def test_do_not_require_ash_chrome(self, command, mock_subprocess,
mock_download):
args = ['script_name', command]
with mock.patch.object(sys, 'argv', args):
test_runner.Main()
mock_subprocess.assert_called_with([command])
self.assertFalse(mock_download.called)
@mock.patch.object(subprocess, 'call')
# Tests that arguments not known to the test runner are forwarded to the
# command that invokes tests.
def test_command_arguments(self, mock_subprocess):
args = ['script_name', './url_unittests', '--gtest_filter=Suite.Test']
with mock.patch.object(sys, 'argv', args):
test_runner.Main()
mock_subprocess.assert_called_with(
['./url_unittests', '--gtest_filter=Suite.Test'])
if __name__ == '__main__':
unittest.main()
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