Skip to content

Commit

Permalink
Make all GPU unittests pass in Python 3
Browse files Browse the repository at this point in the history
Makes all the unittests under //content/test/gpu pass when run under
Python 3. Additionally, adds vpython3 shebangs to unittest files to
make them run under both Python 2 and 3 during presubmit.

Must be submitted after crrev.com/c/2966012, as otherwise the
unittests can hit a Python 3 incompatibility in Telemetry.

Bug: 1198237
Change-Id: I2252f4c0fe20da6decb9a6e33e6dac32526c5129
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2965142
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#893510}
  • Loading branch information
Brian Sheedy authored and Chromium LUCI CQ committed Jun 17, 2021
1 parent b72a78e commit cb1ba88
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 68 deletions.
23 changes: 23 additions & 0 deletions .vpython3
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,26 @@ wheel: <
name: "infra/python/wheels/coverage/${vpython_platform}"
version: "version:5.5"
>

# Used by:
# //content/test/gpu
wheel: <
name: "infra/python/wheels/pathos/${vpython_platform}"
version: "version:0.2.7.chromium.4"
not_match_tag <
abi: "cp27mu"
platform: "manylinux1_i686"
>
not_match_tag <
abi: "cp27mu"
platform: "linux_mips64"
>
not_match_tag <
abi: "cp27mu"
platform: "linux_armv6l"
>
not_match_tag <
abi: "cp27mu"
platform: "linux_armv7l"
>
>
2 changes: 1 addition & 1 deletion content/test/gpu/run_unittests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env vpython
#!/usr/bin/env vpython3
# Copyright 2015 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.
Expand Down
4 changes: 2 additions & 2 deletions content/test/gpu/unexpected_passes/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
],
}
FAKE_CI_BUILDERS = {}
for try_builder, ci_builder_list in FAKE_TRY_BUILDERS.iteritems():
for try_builder, ci_builder_list in FAKE_TRY_BUILDERS.items():
for ci in ci_builder_list:
FAKE_CI_BUILDERS[ci] = try_builder

Expand Down Expand Up @@ -97,7 +97,7 @@ def GetCiBuilders(suite):
if AUTOGENERATED_JSON_KEY not in buildbot_json:
continue

for builder, test_map in buildbot_json.iteritems():
for builder, test_map in buildbot_json.items():
# Remove compile-only builders and the auto-generated comments.
if 'Builder' in builder or 'AAAA' in builder:
continue
Expand Down
1 change: 1 addition & 0 deletions content/test/gpu/unexpected_passes/builders_unittest.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env vpython3
# 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.
Expand Down
1 change: 1 addition & 0 deletions content/test/gpu/unexpected_passes/data_types_unittest.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env vpython3
# 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.
Expand Down
14 changes: 7 additions & 7 deletions content/test/gpu/unexpected_passes/expectations.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ def FilterOutUnusedExpectations(test_expectation_map):
if not builder_map:
unused_expectations.append(expectation)
for unused in unused_expectations:
for _, expectation_map in test_expectation_map.iteritems():
for _, expectation_map in test_expectation_map.items():
if unused in expectation_map:
del expectation_map[unused]
logging.debug('Found %d unused expectations', len(unused_expectations))

empty_tests = []
for test_name, expectation_map in test_expectation_map.iteritems():
for test_name, expectation_map in test_expectation_map.items():
if not expectation_map:
empty_tests.append(test_name)
for empty in empty_tests:
Expand Down Expand Up @@ -132,8 +132,8 @@ def SplitExpectationsByStaleness(test_expectation_map):
# However, we need to reset state in different loops, and the alternative of
# keeping all the state outside the loop and resetting under certain
# conditions ends up being less readable than just using nested loops.
for test_name, expectation_map in test_expectation_map.iteritems():
for expectation, builder_map in expectation_map.iteritems():
for test_name, expectation_map in test_expectation_map.items():
for expectation, builder_map in expectation_map.items():
# A temporary map to hold data so we can later determine whether an
# expectation is stale, semi-stale, or active.
tmp_map = {
Expand All @@ -144,7 +144,7 @@ def SplitExpectationsByStaleness(test_expectation_map):

split_stats_map = builder_map.SplitBuildStatsByPass()
for builder_name, (fully_passed, never_passed,
partially_passed) in split_stats_map.iteritems():
partially_passed) in split_stats_map.items():
if fully_passed:
tmp_map[FULL_PASS][builder_name] = fully_passed
if never_passed:
Expand All @@ -154,7 +154,7 @@ def SplitExpectationsByStaleness(test_expectation_map):

def _CopyPassesIntoBuilderMap(builder_map, pass_types):
for pt in pass_types:
for builder, steps in tmp_map[pt].iteritems():
for builder, steps in tmp_map[pt].items():
builder_map.setdefault(builder,
data_types.StepBuildStatsMap()).update(steps)

Expand Down Expand Up @@ -485,7 +485,7 @@ def MergeExpectationMaps(base_map, merge_map, reference_map=None):
# expectation/builder/step combination. Use the reference map to determine
# if a particular BuildStats has already been updated or not.
reference_map = reference_map or copy.deepcopy(base_map)
for key, value in merge_map.iteritems():
for key, value in merge_map.items():
if key not in base_map:
base_map[key] = value
else:
Expand Down
5 changes: 3 additions & 2 deletions content/test/gpu/unexpected_passes/expectations_unittest.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env vpython3
# 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.
Expand Down Expand Up @@ -61,7 +62,7 @@ def testExclusiveOr(self):

def testExpectationFile(self):
"""Tests reading expectations from an expectation file."""
with tempfile.NamedTemporaryFile(delete=False) as f:
with tempfile.NamedTemporaryFile(delete=False, mode='w') as f:
filename = f.name
f.write(FAKE_EXPECTATION_FILE_CONTENTS)
expectation_map = expectations.CreateTestExpectationMap(filename, None)
Expand Down Expand Up @@ -1180,7 +1181,7 @@ def setUp(self):
self._input_mock = self._input_patcher.start()
self.addCleanup(self._input_patcher.stop)

with tempfile.NamedTemporaryFile(delete=False) as f:
with tempfile.NamedTemporaryFile(delete=False, mode='w') as f:
f.write(FAKE_EXPECTATION_FILE_CONTENTS)
self.filename = f.name

Expand Down
8 changes: 4 additions & 4 deletions content/test/gpu/unexpected_passes/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,8 @@ def _GenerateClauses(self):
def SplitFilter(self):
def _SplitListInHalf(l):
assert len(l) > 1
front = l[:len(l) / 2]
back = l[len(l) / 2:]
front = l[:len(l) // 2]
back = l[len(l) // 2:]
return front, back

tmp_test_id_lists = []
Expand Down Expand Up @@ -620,8 +620,8 @@ def _GenerateBigQueryCommand(project, parameters):
'--use_legacy_sql=false',
]

for parameter_type, parameter_pairs in parameters.iteritems():
for k, v in parameter_pairs.iteritems():
for parameter_type, parameter_pairs in parameters.items():
for k, v in parameter_pairs.items():
cmd.append('--parameter=%s:%s:%s' % (k, parameter_type, v))
return cmd

Expand Down
1 change: 1 addition & 0 deletions content/test/gpu/unexpected_passes/queries_unittest.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env vpython3
# 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.
Expand Down
22 changes: 12 additions & 10 deletions content/test/gpu/unexpected_passes/result_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import sys
import tempfile

import six

from unexpected_passes import data_types

FULL_PASS = 'Fully passed in the following'
Expand Down Expand Up @@ -261,10 +263,10 @@ def _RecursivePrintToFile(element, depth, file_handle):
"""
if element is None:
element = str(element)
if isinstance(element, str) or isinstance(element, unicode):
if isinstance(element, six.string_types):
file_handle.write((' ' * depth) + element + '\n')
elif isinstance(element, dict):
for k, v in element.iteritems():
for k, v in element.items():
_RecursivePrintToFile(k, depth, file_handle)
_RecursivePrintToFile(v, depth + 1, file_handle)
elif isinstance(element, list):
Expand All @@ -286,10 +288,10 @@ def _RecursiveHtmlToFile(element, file_handle):
element: A dict, list, or str/unicode to output.
file_handle: An open file-like object to output to.
"""
if isinstance(element, str) or isinstance(element, unicode):
if isinstance(element, six.string_types):
file_handle.write('<p>%s</p>\n' % _LinkifyString(element))
elif isinstance(element, dict):
for k, v in element.iteritems():
for k, v in element.items():
html_class = 'collapsible_group'
# This allows us to later (in JavaScript) recursively highlight sections
# that are likely of interest to the user, i.e. whose expectations can be
Expand Down Expand Up @@ -361,20 +363,20 @@ def _ConvertTestExpectationMapToStringDict(test_expectation_map):
# However, we need to reset state in different loops, and the alternative of
# keeping all the state outside the loop and resetting under certain
# conditions ends up being less readable than just using nested loops.
for test_name, expectation_map in test_expectation_map.iteritems():
for test_name, expectation_map in test_expectation_map.items():
output_dict[test_name] = {}

for expectation, builder_map in expectation_map.iteritems():
for expectation, builder_map in expectation_map.items():
expectation_str = _FormatExpectation(expectation)
output_dict[test_name][expectation_str] = {}

for builder_name, step_map in builder_map.iteritems():
for builder_name, step_map in builder_map.items():
output_dict[test_name][expectation_str][builder_name] = {}
fully_passed = []
partially_passed = {}
never_passed = []

for step_name, stats in step_map.iteritems():
for step_name, stats in step_map.items():
if stats.did_fully_pass:
fully_passed.append(AddStatsToStr(step_name, stats))
elif stats.did_never_pass:
Expand All @@ -389,7 +391,7 @@ def _ConvertTestExpectationMapToStringDict(test_expectation_map):
output_builder_map[FULL_PASS] = fully_passed
if partially_passed:
output_builder_map[PARTIAL_PASS] = {}
for step_name, stats in partially_passed.iteritems():
for step_name, stats in partially_passed.items():
s = AddStatsToStr(step_name, stats)
output_builder_map[PARTIAL_PASS][s] = list(stats.failure_links)
if never_passed:
Expand Down Expand Up @@ -423,7 +425,7 @@ def _ConvertUnmatchedResultsToStringDict(unmatched_results):
}
"""
output_dict = {}
for builder, results in unmatched_results.iteritems():
for builder, results in unmatched_results.items():
for r in results:
builder_map = output_dict.setdefault(r.test, {})
step_map = builder_map.setdefault(builder, {})
Expand Down
Loading

0 comments on commit cb1ba88

Please sign in to comment.