[test] Make finding build directory more flexible

This prepares moving the build directory on bots to out/build. For a
smooth transition, the performance runner will dynamically check
for the build in several locations.

This prepares:
https://crrev.com/c/2426643

NOTREECHECKS=true

Bug: chromium:1132088
Change-Id: Ia12fcdedec0f4ac2bfe087e8154c0acb8771a43f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2431364
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Reviewed-by: Liviu Rau <liviurau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70158}
This commit is contained in:
Michael Achenbach 2020-09-25 19:10:03 +02:00 committed by Commit Bot
parent c55c00d488
commit 4f015e85fa
3 changed files with 68 additions and 16 deletions

View File

@ -575,6 +575,32 @@ def FlattenRunnables(node, node_cb):
raise Exception('Invalid suite configuration.')
def find_build_directory(base_path, arch):
"""Returns the location of d8 or node in the build output directory.
This supports a seamless transition between legacy build location
(out/Release) and new build location (out/build).
"""
def is_build(path):
# We support d8 or node as executables. We don't support testing on
# Windows.
return (os.path.isfile(os.path.join(path, 'd8')) or
os.path.isfile(os.path.join(path, 'node')))
possible_paths = [
# Location developer wrapper scripts is using.
'%s.release' % arch,
# Current build location on bots.
'build',
# Legacy build location on bots.
'Release',
]
possible_paths = [os.path.join(base_path, p) for p in possible_paths]
actual_paths = filter(is_build, possible_paths)
assert actual_paths, 'No build directory found.'
assert len(actual_paths) == 1, 'Found ambiguous build directories.'
return actual_paths[0]
class Platform(object):
def __init__(self, args):
self.shell_dir = args.shell_dir
@ -881,8 +907,7 @@ def Main(argv):
'to auto-detect.', default='x64',
choices=SUPPORTED_ARCHS + ['auto'])
parser.add_argument('--buildbot',
help='Adapt to path structure used on buildbots and adds '
'timestamps/level to all logged status messages',
help='Deprecated',
default=False, action='store_true')
parser.add_argument('-d', '--device',
help='The device ID to run Android tests on. If not '
@ -978,13 +1003,9 @@ def Main(argv):
workspace = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
if args.buildbot:
build_config = 'Release'
else:
build_config = '%s.release' % args.arch
if args.binary_override_path == None:
args.shell_dir = os.path.join(workspace, args.outdir, build_config)
args.shell_dir = find_build_directory(
os.path.join(workspace, args.outdir), args.arch)
default_binary_name = 'd8'
else:
if not os.path.isfile(args.binary_override_path):
@ -998,8 +1019,8 @@ def Main(argv):
default_binary_name = os.path.basename(args.binary_override_path)
if args.outdir_secondary:
args.shell_dir_secondary = os.path.join(
workspace, args.outdir_secondary, build_config)
args.shell_dir_secondary = find_build_directory(
os.path.join(workspace, args.outdir_secondary), args.arch)
else:
args.shell_dir_secondary = None

View File

@ -90,6 +90,21 @@ V8_GENERIC_JSON = {
'units': 'ms',
}
class UnitTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
sys.path.insert(0, BASE_DIR)
import run_perf
global run_perf
def testBuildDirectory(self):
base_path = os.path.join(TEST_DATA, 'builddirs', 'dir1', 'out')
expected_path = os.path.join(base_path, 'build')
self.assertEquals(
expected_path, run_perf.find_build_directory(base_path, 'x64'))
class PerfTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
@ -125,6 +140,7 @@ class PerfTest(unittest.TestCase):
f.write(json.dumps(json_content))
def _MockCommand(self, *args, **kwargs):
on_bots = kwargs.pop('on_bots', False)
# Fake output for each test run.
test_outputs = [Output(stdout=arg,
timed_out=kwargs.get('timed_out', False),
@ -142,6 +158,16 @@ class PerfTest(unittest.TestCase):
run_perf.command, 'PosixCommand',
mock.MagicMock(side_effect=create_cmd)).start()
build_dir = 'Release' if on_bots else 'x64.release'
out_dirs = ['out', 'out-secondary']
return_values = [
os.path.join(os.path.dirname(BASE_DIR), out, build_dir)
for out in out_dirs
]
mock.patch.object(
run_perf, 'find_build_directory',
mock.MagicMock(side_effect=return_values)).start()
# Check that d8 is called from the correct cwd for each test run.
dirs = [os.path.join(TEST_WORKSPACE, arg) for arg in args[0]]
def chdir(*args, **kwargs):
@ -394,11 +420,12 @@ class PerfTest(unittest.TestCase):
def testBuildbot(self):
self._WriteTestInput(V8_JSON)
self._MockCommand(['.'], ['Richards: 1.234\nDeltaBlue: 10657567\n'])
self._MockCommand(['.'], ['Richards: 1.234\nDeltaBlue: 10657567\n'],
on_bots=True)
mock.patch.object(
run_perf.Platform, 'ReadBuildConfig',
mock.MagicMock(return_value={'is_android': False})).start()
self.assertEqual(0, self._CallMain('--buildbot'))
self.assertEqual(0, self._CallMain())
self._VerifyResults('test', 'score', [
{'name': 'Richards', 'results': [1.234], 'stddev': ''},
{'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
@ -410,11 +437,12 @@ class PerfTest(unittest.TestCase):
test_input = dict(V8_JSON)
test_input['total'] = True
self._WriteTestInput(test_input)
self._MockCommand(['.'], ['Richards: 1.234\nDeltaBlue: 10657567\n'])
self._MockCommand(['.'], ['Richards: 1.234\nDeltaBlue: 10657567\n'],
on_bots=True)
mock.patch.object(
run_perf.Platform, 'ReadBuildConfig',
mock.MagicMock(return_value={'is_android': False})).start()
self.assertEqual(0, self._CallMain('--buildbot'))
self.assertEqual(0, self._CallMain())
self._VerifyResults('test', 'score', [
{'name': 'Richards', 'results': [1.234], 'stddev': ''},
{'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
@ -427,11 +455,12 @@ class PerfTest(unittest.TestCase):
test_input = dict(V8_JSON)
test_input['total'] = True
self._WriteTestInput(test_input)
self._MockCommand(['.'], ['x\nRichards: bla\nDeltaBlue: 10657567\ny\n'])
self._MockCommand(['.'], ['x\nRichards: bla\nDeltaBlue: 10657567\ny\n'],
on_bots=True)
mock.patch.object(
run_perf.Platform, 'ReadBuildConfig',
mock.MagicMock(return_value={'is_android': False})).start()
self.assertEqual(1, self._CallMain('--buildbot'))
self.assertEqual(1, self._CallMain())
self._VerifyResults('test', 'score', [
{'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
])
@ -484,6 +513,7 @@ class PerfTest(unittest.TestCase):
mock.patch('run_perf.AndroidPlatform.PreExecution').start()
mock.patch('run_perf.AndroidPlatform.PostExecution').start()
mock.patch('run_perf.AndroidPlatform.PreTests').start()
mock.patch('run_perf.find_build_directory').start()
mock.patch(
'run_perf.AndroidPlatform.Run',
return_value=(Output(stdout='Richards: 1.234\nDeltaBlue: 10657567\n'),

View File

@ -0,0 +1 @@
test