Skip to content

Commit

Permalink
chromeos: Make the test runner and its tests py3-compatible.
Browse files Browse the repository at this point in the history
Bug: None
Change-Id: I6088329e4c53870d9e17d2beec5ec27dfd009a18
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2613356
Reviewed-by: Yuke Liao <liaoyuke@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@google.com>
Commit-Queue: Ben Pastene <bpastene@chromium.org>
Cr-Commit-Position: refs/heads/master@{#848370}
  • Loading branch information
bpastene authored and Chromium LUCI CQ committed Jan 29, 2021
1 parent 6f8fafd commit efdcb84
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
35 changes: 35 additions & 0 deletions .vpython3
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,38 @@ wheel: <
name: "infra/python/wheels/six-py2_py3"
version: "version:1.15.0"
>

# Common utilities.
wheel: <
name: "infra/python/wheels/psutil/${platform}_${py_python}_${py_abi}"
version: "version:5.7.2"
>
wheel: <
name: "infra/python/wheels/requests-py2_py3"
version: "version:2.13.0"
>

# Used by various python unit tests.
wheel: <
name: "infra/python/wheels/mock-py2_py3"
version: "version:2.0.0"
>
wheel: <
name: "infra/python/wheels/parameterized-py2_py3"
version: "version:0.7.1"
>
wheel: <
name: "infra/python/wheels/pbr-py2_py3"
version: "version:3.0.0"
>

# Used by:
# build/chromeos/test_runner.py
wheel: <
name: "infra/python/wheels/jsonlines-py2_py3"
version: "version:1.2.0"
>
wheel: <
name: "infra/python/wheels/python-dateutil-py2_py3"
version: "version:2.7.3"
>
14 changes: 9 additions & 5 deletions build/chromeos/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import dateutil.parser # pylint: disable=import-error
import jsonlines # pylint: disable=import-error
import psutil # pylint: disable=import-error
import six

CHROMIUM_SRC_PATH = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..'))
Expand All @@ -33,7 +34,10 @@
from pylib.base import result_sink # pylint: disable=import-error
from pylib.results import json_results # pylint: disable=import-error

import subprocess32 as subprocess # pylint: disable=import-error
if six.PY2:
import subprocess32 as subprocess # pylint: disable=import-error
else:
import subprocess # pylint: disable=import-error,wrong-import-order

DEFAULT_CROS_CACHE = os.path.abspath(
os.path.join(CHROMIUM_SRC_PATH, 'build', 'cros_cache'))
Expand Down Expand Up @@ -161,7 +165,7 @@ 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)
os.fchmod(fd, 0o755)
with os.fdopen(fd, 'wb') as f:
f.write('\n'.join(script_contents) + '\n')
return tmp_path
Expand All @@ -186,7 +190,7 @@ def _kill_child_procs(trapped_signal, _):

signal.signal(signal.SIGTERM, _kill_child_procs)

for i in xrange(self._retries + 1):
for i in range(self._retries + 1):
logging.info('########################################')
logging.info('Test attempt #%d', i)
logging.info('########################################')
Expand All @@ -197,13 +201,13 @@ def _kill_child_procs(trapped_signal, _):
env=self._test_env)
try:
test_proc.wait(timeout=self._timeout)
except subprocess.TimeoutExpired:
except subprocess.TimeoutExpired: # pylint: disable=no-member
logging.error('Test timed out. Sending SIGTERM.')
# SIGTERM the proc and wait 10s for it to close.
test_proc.terminate()
try:
test_proc.wait(timeout=10)
except subprocess.TimeoutExpired:
except subprocess.TimeoutExpired: # pylint: disable=no-member
# If it hasn't closed in 10s, SIGKILL it.
logging.error('Test did not exit in time. Sending SIGKILL.')
test_proc.kill()
Expand Down
21 changes: 16 additions & 5 deletions build/chromeos/test_runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# //.vpython
import mock # pylint: disable=import-error
from parameterized import parameterized # pylint: disable=import-error
import six

import test_runner

Expand Down Expand Up @@ -80,6 +81,16 @@ def get_common_tast_expectations(self, use_vm, is_lacros=False):
]
return expectation

def safeAssertItemsEqual(self, list1, list2):
"""A Py3 safe version of assertItemsEqual.
See https://bugs.python.org/issue17866.
"""
if six.PY3:
self.assertSetEqual(set(list1), set(list2))
else:
self.assertItemsEqual(list1, list2)

@parameterized.expand([
[True],
[False],
Expand Down Expand Up @@ -116,7 +127,7 @@ def test_gtest(self, use_vm):
expected_cmd.extend(['--start', '--copy-on-write']
if use_vm else ['--device', 'localhost:2222'])
expected_cmd.extend(['--', './device_script.sh'])
self.assertItemsEqual(expected_cmd, mock_popen.call_args[0][0])
self.safeAssertItemsEqual(expected_cmd, mock_popen.call_args[0][0])

fd_mock().write.assert_called_once_with(
'#!/bin/sh\nexport HOME=/usr/local/tmp\n'
Expand Down Expand Up @@ -146,7 +157,7 @@ def test_tast(self, use_vm):
'--tast', 'ui.ChromeLogin'
]

self.assertItemsEqual(expected_cmd, mock_popen.call_args[0][0])
self.safeAssertItemsEqual(expected_cmd, mock_popen.call_args[0][0])

@parameterized.expand([
[True],
Expand All @@ -169,7 +180,7 @@ def test_tast_attr_expr(self, use_vm):
'--tast=( "group:mainline" && "dep:chrome" && !informational)',
]

self.assertItemsEqual(expected_cmd, mock_popen.call_args[0][0])
self.safeAssertItemsEqual(expected_cmd, mock_popen.call_args[0][0])

@parameterized.expand([
[True],
Expand Down Expand Up @@ -197,7 +208,7 @@ def test_tast_lacros(self, use_vm):
'--deploy-lacros',
]

self.assertItemsEqual(expected_cmd, mock_popen.call_args[0][0])
self.safeAssertItemsEqual(expected_cmd, mock_popen.call_args[0][0])

@parameterized.expand([
[True],
Expand All @@ -220,7 +231,7 @@ def test_tast_with_vars(self, use_vm):
'--tast', 'ui.ChromeLogin', '--tast-var', 'key=value'
]

self.assertItemsEqual(expected_cmd, mock_popen.call_args[0][0])
self.safeAssertItemsEqual(expected_cmd, mock_popen.call_args[0][0])


if __name__ == '__main__':
Expand Down

0 comments on commit efdcb84

Please sign in to comment.