forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add buildbot JSON magic substitutions
Adds the ability to use magic substitution args when generating buildbot JSON files, i.e. magic values that will be expanded to different arguments depending on the test config. Also switches the CrOS Telemetry tests to use this to set different arguments for tests running on VMs and physical hardware instead of using test_suite_exceptions.pyl. This is a prerequisite for expanding GPU test coverage on CrOS, as the differing arguments between VMs and hardware will be difficult to maintain using test_suite_exceptions.pyl given the large number of GPU Telemetry tests. There may be other use cases for this feature, though. Bug: 1080424 Change-Id: Ifcbcb4ebab88f525f8b05640cdb18f431207cc79 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2204680 Reviewed-by: Kenneth Russell <kbr@chromium.org> Commit-Queue: Brian Sheedy <bsheedy@chromium.org> Cr-Commit-Position: refs/heads/master@{#769808}
- Loading branch information
Brian Sheedy
authored and
Commit Bot
committed
May 18, 2020
1 parent
4df6032
commit a31578e
Showing
7 changed files
with
244 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# 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. | ||
|
||
"""A set of functions to programmatically substitute test arguments. | ||
Arguments for a test that start with $$MAGIC_SUBSTITUTION_ will be replaced with | ||
the output of the corresponding function in this file. For example, | ||
$$MAGIC_SUBSTITUTION_Foo would be replaced with the return value of the Foo() | ||
function. | ||
This is meant as an alternative to many entries in test_suite_exceptions.pyl if | ||
the differentiation can be done programmatically. | ||
""" | ||
|
||
MAGIC_SUBSTITUTION_PREFIX = '$$MAGIC_SUBSTITUTION_' | ||
|
||
|
||
def ChromeOSTelemetryRemote(test_config): | ||
"""Substitutes the correct CrOS remote Telemetry arguments. | ||
VMs use a hard-coded remote address and port, while physical hardware use | ||
a magic hostname. | ||
Args: | ||
test_config: A dict containing a configuration for a specific test on a | ||
specific builder. | ||
""" | ||
def StringContainsSubstring(s, sub_strs): | ||
for sub_str in sub_strs: | ||
if sub_str in s: | ||
return True | ||
return False | ||
VM_POOLS = [ | ||
'chromium.tests.cros.vm', | ||
'chrome.tests.cros-vm', | ||
] | ||
HW_POOLS = [ | ||
'chrome-cros-dut', | ||
'chrome.cros-dut', | ||
] | ||
dimensions = test_config.get('swarming', {}).get('dimension_sets', []) | ||
assert len(dimensions) | ||
pool = dimensions[0].get('pool') | ||
if not pool: | ||
raise RuntimeError( | ||
'No pool set for CrOS test, unable to determine whether running on ' | ||
'a VM or physical hardware.') | ||
|
||
if StringContainsSubstring(pool, VM_POOLS): | ||
return [ | ||
'--remote=127.0.0.1', | ||
# By default, CrOS VMs' ssh servers listen on local port 9222. | ||
'--remote-ssh-port=9222', | ||
] | ||
if StringContainsSubstring(pool, HW_POOLS): | ||
return [ | ||
# Magic hostname that resolves to a CrOS device in the test lab. | ||
'--remote=variable_chromeos_device_hostname', | ||
] | ||
raise RuntimeError('Unknown CrOS pool %s' % pool) | ||
|
||
|
||
def TestOnlySubstitution(_): | ||
"""Magic substitution used for unittests.""" | ||
return ['--magic-substitution-success'] |
50 changes: 50 additions & 0 deletions
50
testing/buildbot/buildbot_json_magic_substitutions_unittest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/python | ||
# 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 unittest | ||
|
||
import buildbot_json_magic_substitutions as magic_substitutions | ||
|
||
|
||
def CreateConfigWithPool(pool): | ||
return { | ||
'swarming': { | ||
'dimension_sets': [ | ||
{ | ||
'pool': pool, | ||
}, | ||
], | ||
}, | ||
} | ||
|
||
|
||
class ChromeOSTelemetryRemoteTest(unittest.TestCase): | ||
|
||
def testVirtualMachineSubstitutions(self): | ||
test_config = CreateConfigWithPool('chromium.tests.cros.vm') | ||
self.assertEqual(magic_substitutions.ChromeOSTelemetryRemote(test_config), | ||
[ | ||
'--remote=127.0.0.1', | ||
'--remote-ssh-port=9222', | ||
]) | ||
|
||
def testPhysicalHardwareSubstitutions(self): | ||
test_config = CreateConfigWithPool('chrome-cros-dut') | ||
self.assertEqual(magic_substitutions.ChromeOSTelemetryRemote(test_config), | ||
['--remote=variable_chromeos_device_hostname']) | ||
|
||
def testNoPool(self): | ||
test_config = CreateConfigWithPool(None) | ||
with self.assertRaisesRegexp(RuntimeError, 'No pool *'): | ||
magic_substitutions.ChromeOSTelemetryRemote(test_config) | ||
|
||
def testUnknownPool(self): | ||
test_config = CreateConfigWithPool('totally-legit-pool') | ||
with self.assertRaisesRegexp(RuntimeError, 'Unknown CrOS pool *'): | ||
magic_substitutions.ChromeOSTelemetryRemote(test_config) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters