2014-09-02 09:17:26 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
2019-02-19 08:28:26 +00:00
|
|
|
# for py2/py3 compatibility
|
|
|
|
from __future__ import print_function
|
|
|
|
|
2014-09-02 09:17:26 +00:00
|
|
|
from collections import namedtuple
|
|
|
|
import json
|
|
|
|
import os
|
2015-09-15 08:15:54 +00:00
|
|
|
import platform
|
2014-09-02 09:17:26 +00:00
|
|
|
import shutil
|
2015-09-15 08:15:54 +00:00
|
|
|
import subprocess
|
2019-04-12 11:00:18 +00:00
|
|
|
import sys
|
2014-09-02 09:17:26 +00:00
|
|
|
import tempfile
|
|
|
|
import unittest
|
|
|
|
|
2019-05-09 09:05:37 +00:00
|
|
|
import coverage
|
|
|
|
import mock
|
|
|
|
|
2014-09-02 09:17:26 +00:00
|
|
|
# Requires python-coverage and python-mock. Native python coverage
|
|
|
|
# version >= 3.7.1 should be installed to get the best speed.
|
|
|
|
|
2017-02-16 13:48:31 +00:00
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
RUN_PERF = os.path.join(BASE_DIR, 'run_perf.py')
|
|
|
|
TEST_DATA = os.path.join(BASE_DIR, 'unittests', 'testdata')
|
|
|
|
|
2019-04-12 11:00:18 +00:00
|
|
|
TEST_WORKSPACE = os.path.join(tempfile.gettempdir(), 'test-v8-run-perf')
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
V8_JSON = {
|
2019-04-12 11:00:18 +00:00
|
|
|
'path': ['.'],
|
|
|
|
'owners': ['username@chromium.org'],
|
|
|
|
'binary': 'd7',
|
2019-04-23 16:07:52 +00:00
|
|
|
'timeout': 60,
|
2019-04-12 11:00:18 +00:00
|
|
|
'flags': ['--flag'],
|
|
|
|
'main': 'run.js',
|
|
|
|
'run_count': 1,
|
|
|
|
'results_regexp': '^%s: (.+)$',
|
|
|
|
'tests': [
|
|
|
|
{'name': 'Richards'},
|
|
|
|
{'name': 'DeltaBlue'},
|
2014-09-02 09:17:26 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
V8_NESTED_SUITES_JSON = {
|
2019-04-12 11:00:18 +00:00
|
|
|
'path': ['.'],
|
|
|
|
'owners': ['username@chromium.org'],
|
|
|
|
'flags': ['--flag'],
|
|
|
|
'run_count': 1,
|
|
|
|
'units': 'score',
|
|
|
|
'tests': [
|
|
|
|
{'name': 'Richards',
|
|
|
|
'path': ['richards'],
|
|
|
|
'binary': 'd7',
|
|
|
|
'main': 'run.js',
|
|
|
|
'resources': ['file1.js', 'file2.js'],
|
|
|
|
'run_count': 2,
|
|
|
|
'results_regexp': '^Richards: (.+)$'},
|
|
|
|
{'name': 'Sub',
|
|
|
|
'path': ['sub'],
|
|
|
|
'tests': [
|
|
|
|
{'name': 'Leaf',
|
|
|
|
'path': ['leaf'],
|
|
|
|
'run_count_x64': 3,
|
|
|
|
'units': 'ms',
|
|
|
|
'main': 'run.js',
|
|
|
|
'results_regexp': '^Simple: (.+) ms.$'},
|
2014-09-02 09:17:26 +00:00
|
|
|
]
|
|
|
|
},
|
2019-04-12 11:00:18 +00:00
|
|
|
{'name': 'DeltaBlue',
|
|
|
|
'path': ['delta_blue'],
|
|
|
|
'main': 'run.js',
|
|
|
|
'flags': ['--flag2'],
|
|
|
|
'results_regexp': '^DeltaBlue: (.+)$'},
|
|
|
|
{'name': 'ShouldntRun',
|
|
|
|
'path': ['.'],
|
|
|
|
'archs': ['arm'],
|
|
|
|
'main': 'run.js'},
|
2014-09-02 09:17:26 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
V8_GENERIC_JSON = {
|
2019-04-12 11:00:18 +00:00
|
|
|
'path': ['.'],
|
|
|
|
'owners': ['username@chromium.org'],
|
|
|
|
'binary': 'cc',
|
|
|
|
'flags': ['--flag'],
|
|
|
|
'generic': True,
|
|
|
|
'run_count': 1,
|
|
|
|
'units': 'ms',
|
2014-09-02 09:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class PerfTest(unittest.TestCase):
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2019-04-12 11:00:18 +00:00
|
|
|
sys.path.insert(0, BASE_DIR)
|
2014-09-02 09:17:26 +00:00
|
|
|
cls._cov = coverage.coverage(
|
2019-04-12 11:00:18 +00:00
|
|
|
include=([os.path.join(BASE_DIR, 'run_perf.py')]))
|
2014-09-02 09:17:26 +00:00
|
|
|
cls._cov.start()
|
|
|
|
import run_perf
|
2017-11-30 12:57:45 +00:00
|
|
|
from testrunner.local import command
|
2019-04-23 11:32:13 +00:00
|
|
|
from testrunner.objects.output import Output, NULL_OUTPUT
|
|
|
|
global command, run_perf, Output, NULL_OUTPUT
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
cls._cov.stop()
|
2019-04-12 11:00:18 +00:00
|
|
|
print('')
|
2019-02-19 08:28:26 +00:00
|
|
|
print(cls._cov.report())
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.maxDiff = None
|
2019-04-12 11:00:18 +00:00
|
|
|
if os.path.exists(TEST_WORKSPACE):
|
2014-09-02 09:17:26 +00:00
|
|
|
shutil.rmtree(TEST_WORKSPACE)
|
|
|
|
os.makedirs(TEST_WORKSPACE)
|
|
|
|
|
|
|
|
def tearDown(self):
|
2019-04-12 11:00:18 +00:00
|
|
|
mock.patch.stopall()
|
|
|
|
if os.path.exists(TEST_WORKSPACE):
|
2014-09-02 09:17:26 +00:00
|
|
|
shutil.rmtree(TEST_WORKSPACE)
|
|
|
|
|
|
|
|
def _WriteTestInput(self, json_content):
|
2019-04-12 11:00:18 +00:00
|
|
|
self._test_input = os.path.join(TEST_WORKSPACE, 'test.json')
|
|
|
|
with open(self._test_input, 'w') as f:
|
2014-09-02 09:17:26 +00:00
|
|
|
f.write(json.dumps(json_content))
|
|
|
|
|
2014-09-15 13:00:32 +00:00
|
|
|
def _MockCommand(self, *args, **kwargs):
|
2014-09-02 09:17:26 +00:00
|
|
|
# Fake output for each test run.
|
2014-09-15 13:00:32 +00:00
|
|
|
test_outputs = [Output(stdout=arg,
|
2019-04-12 11:00:18 +00:00
|
|
|
timed_out=kwargs.get('timed_out', False),
|
2019-04-23 16:07:52 +00:00
|
|
|
exit_code=kwargs.get('exit_code', 0),
|
|
|
|
duration=42)
|
2014-09-15 13:00:32 +00:00
|
|
|
for arg in args[1]]
|
2017-11-30 12:57:45 +00:00
|
|
|
def create_cmd(*args, **kwargs):
|
2019-04-12 11:00:18 +00:00
|
|
|
cmd = mock.MagicMock()
|
2017-11-30 12:57:45 +00:00
|
|
|
def execute(*args, **kwargs):
|
|
|
|
return test_outputs.pop()
|
2019-04-12 11:00:18 +00:00
|
|
|
cmd.execute = mock.MagicMock(side_effect=execute)
|
2017-11-30 12:57:45 +00:00
|
|
|
return cmd
|
|
|
|
|
2019-04-12 11:00:18 +00:00
|
|
|
mock.patch.object(
|
2018-10-30 14:23:38 +00:00
|
|
|
run_perf.command, 'PosixCommand',
|
2019-04-12 11:00:18 +00:00
|
|
|
mock.MagicMock(side_effect=create_cmd)).start()
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
# Check that d8 is called from the correct cwd for each test run.
|
2019-04-12 11:00:18 +00:00
|
|
|
dirs = [os.path.join(TEST_WORKSPACE, arg) for arg in args[0]]
|
2014-09-02 09:17:26 +00:00
|
|
|
def chdir(*args, **kwargs):
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(dirs.pop(), args[0])
|
2019-04-12 11:00:18 +00:00
|
|
|
os.chdir = mock.MagicMock(side_effect=chdir)
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2019-04-12 11:00:18 +00:00
|
|
|
subprocess.check_call = mock.MagicMock()
|
|
|
|
platform.system = mock.MagicMock(return_value='Linux')
|
2015-09-15 08:15:54 +00:00
|
|
|
|
2014-09-02 09:17:26 +00:00
|
|
|
def _CallMain(self, *args):
|
2019-04-12 11:00:18 +00:00
|
|
|
self._test_output = os.path.join(TEST_WORKSPACE, 'results.json')
|
2014-09-02 09:17:26 +00:00
|
|
|
all_args=[
|
2019-04-12 11:00:18 +00:00
|
|
|
'--json-test-results',
|
2014-09-02 09:17:26 +00:00
|
|
|
self._test_output,
|
|
|
|
self._test_input,
|
|
|
|
]
|
|
|
|
all_args += args
|
|
|
|
return run_perf.Main(all_args)
|
|
|
|
|
2015-07-10 13:02:09 +00:00
|
|
|
def _LoadResults(self, file_name=None):
|
|
|
|
with open(file_name or self._test_output) as f:
|
2014-09-02 09:17:26 +00:00
|
|
|
return json.load(f)
|
|
|
|
|
2015-07-10 13:02:09 +00:00
|
|
|
def _VerifyResults(self, suite, units, traces, file_name=None):
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertListEqual(sorted([
|
2019-04-12 11:00:18 +00:00
|
|
|
{'units': units,
|
|
|
|
'graphs': [suite, trace['name']],
|
|
|
|
'results': trace['results'],
|
2019-04-25 17:23:45 +00:00
|
|
|
'stddev': trace['stddev']} for trace in traces]),
|
|
|
|
sorted(self._LoadResults(file_name)['traces']))
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2019-04-23 16:07:52 +00:00
|
|
|
def _VerifyRunnableDurations(self, runs, timeout, file_name=None):
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertListEqual([
|
|
|
|
{
|
|
|
|
'graphs': ['test'],
|
|
|
|
'durations': [42] * runs,
|
|
|
|
'timeout': timeout,
|
|
|
|
},
|
|
|
|
], self._LoadResults(file_name)['runnables'])
|
2019-04-23 16:07:52 +00:00
|
|
|
|
2014-09-02 09:17:26 +00:00
|
|
|
def _VerifyErrors(self, errors):
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertListEqual(errors, self._LoadResults()['errors'])
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2014-09-15 13:00:32 +00:00
|
|
|
def _VerifyMock(self, binary, *args, **kwargs):
|
2019-04-12 11:00:18 +00:00
|
|
|
shell = os.path.join(os.path.dirname(BASE_DIR), binary)
|
2017-11-30 12:57:45 +00:00
|
|
|
command.Command.assert_called_with(
|
|
|
|
cmd_prefix=[],
|
|
|
|
shell=shell,
|
|
|
|
args=list(args),
|
|
|
|
timeout=kwargs.get('timeout', 60))
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2014-09-15 13:00:32 +00:00
|
|
|
def _VerifyMockMultiple(self, *args, **kwargs):
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(len(args), len(command.Command.call_args_list))
|
2017-11-30 12:57:45 +00:00
|
|
|
for arg, actual in zip(args, command.Command.call_args_list):
|
|
|
|
expected = {
|
|
|
|
'cmd_prefix': [],
|
2019-04-12 11:00:18 +00:00
|
|
|
'shell': os.path.join(os.path.dirname(BASE_DIR), arg[0]),
|
2017-11-30 12:57:45 +00:00
|
|
|
'args': list(arg[1:]),
|
|
|
|
'timeout': kwargs.get('timeout', 60)
|
|
|
|
}
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertTupleEqual((expected, ), actual)
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
def testOneRun(self):
|
|
|
|
self._WriteTestInput(V8_JSON)
|
2019-04-12 11:00:18 +00:00
|
|
|
self._MockCommand(['.'], ['x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n'])
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(0, self._CallMain())
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyResults('test', 'score', [
|
2019-05-09 09:05:37 +00:00
|
|
|
{'name': 'Richards', 'results': [1.234], 'stddev': ''},
|
|
|
|
{'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
|
2014-09-02 09:17:26 +00:00
|
|
|
])
|
2019-04-23 16:07:52 +00:00
|
|
|
self._VerifyRunnableDurations(1, 60)
|
2014-09-02 09:17:26 +00:00
|
|
|
self._VerifyErrors([])
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyMock(
|
|
|
|
os.path.join('out', 'x64.release', 'd7'), '--flag', 'run.js')
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2014-11-28 10:34:28 +00:00
|
|
|
def testOneRunWithTestFlags(self):
|
|
|
|
test_input = dict(V8_JSON)
|
2019-04-12 11:00:18 +00:00
|
|
|
test_input['test_flags'] = ['2', 'test_name']
|
2014-11-28 10:34:28 +00:00
|
|
|
self._WriteTestInput(test_input)
|
2019-04-12 11:00:18 +00:00
|
|
|
self._MockCommand(['.'], ['Richards: 1.234\nDeltaBlue: 10657567'])
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(0, self._CallMain())
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyResults('test', 'score', [
|
2019-05-09 09:05:37 +00:00
|
|
|
{'name': 'Richards', 'results': [1.234], 'stddev': ''},
|
|
|
|
{'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
|
2014-11-28 10:34:28 +00:00
|
|
|
])
|
|
|
|
self._VerifyErrors([])
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyMock(os.path.join(
|
|
|
|
'out', 'x64.release', 'd7'), '--flag', 'run.js', '--', '2', 'test_name')
|
2014-11-28 10:34:28 +00:00
|
|
|
|
2014-09-02 09:17:26 +00:00
|
|
|
def testTwoRuns_Units_SuiteName(self):
|
|
|
|
test_input = dict(V8_JSON)
|
2019-04-12 11:00:18 +00:00
|
|
|
test_input['run_count'] = 2
|
|
|
|
test_input['name'] = 'v8'
|
|
|
|
test_input['units'] = 'ms'
|
2014-09-02 09:17:26 +00:00
|
|
|
self._WriteTestInput(test_input)
|
2019-04-12 11:00:18 +00:00
|
|
|
self._MockCommand(['.', '.'],
|
|
|
|
['Richards: 100\nDeltaBlue: 200\n',
|
|
|
|
'Richards: 50\nDeltaBlue: 300\n'])
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(0, self._CallMain())
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyResults('v8', 'ms', [
|
2019-05-09 09:05:37 +00:00
|
|
|
{'name': 'Richards', 'results': [50.0, 100.0], 'stddev': ''},
|
|
|
|
{'name': 'DeltaBlue', 'results': [300.0, 200.0], 'stddev': ''},
|
2014-09-02 09:17:26 +00:00
|
|
|
])
|
|
|
|
self._VerifyErrors([])
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyMock(os.path.join(
|
|
|
|
'out', 'x64.release', 'd7'), '--flag', 'run.js')
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
def testTwoRuns_SubRegexp(self):
|
|
|
|
test_input = dict(V8_JSON)
|
2019-04-12 11:00:18 +00:00
|
|
|
test_input['run_count'] = 2
|
|
|
|
del test_input['results_regexp']
|
|
|
|
test_input['tests'][0]['results_regexp'] = '^Richards: (.+)$'
|
|
|
|
test_input['tests'][1]['results_regexp'] = '^DeltaBlue: (.+)$'
|
2014-09-02 09:17:26 +00:00
|
|
|
self._WriteTestInput(test_input)
|
2019-04-12 11:00:18 +00:00
|
|
|
self._MockCommand(['.', '.'],
|
|
|
|
['Richards: 100\nDeltaBlue: 200\n',
|
|
|
|
'Richards: 50\nDeltaBlue: 300\n'])
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(0, self._CallMain())
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyResults('test', 'score', [
|
2019-05-09 09:05:37 +00:00
|
|
|
{'name': 'Richards', 'results': [50.0, 100.0], 'stddev': ''},
|
|
|
|
{'name': 'DeltaBlue', 'results': [300.0, 200.0], 'stddev': ''},
|
|
|
|
])
|
|
|
|
self._VerifyErrors([])
|
|
|
|
self._VerifyMock(os.path.join(
|
|
|
|
'out', 'x64.release', 'd7'), '--flag', 'run.js')
|
|
|
|
|
|
|
|
def testPerfectConfidenceRuns(self):
|
|
|
|
self._WriteTestInput(V8_JSON)
|
|
|
|
self._MockCommand(
|
|
|
|
['.'], ['x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n'] * 10)
|
|
|
|
self.assertEqual(0, self._CallMain('--confidence-level', '1'))
|
|
|
|
self._VerifyResults('test', 'score', [
|
|
|
|
{'name': 'Richards', 'results': [1.234] * 10, 'stddev': ''},
|
|
|
|
{'name': 'DeltaBlue', 'results': [10657567.0] * 10, 'stddev': ''},
|
|
|
|
])
|
|
|
|
self._VerifyErrors([])
|
|
|
|
self._VerifyMock(os.path.join(
|
|
|
|
'out', 'x64.release', 'd7'), '--flag', 'run.js')
|
|
|
|
|
|
|
|
def testNoisyConfidenceRuns(self):
|
|
|
|
self._WriteTestInput(V8_JSON)
|
|
|
|
self._MockCommand(
|
|
|
|
['.'],
|
|
|
|
reversed([
|
|
|
|
# First 10 runs are mandatory. DeltaBlue is slightly noisy.
|
|
|
|
'x\nRichards: 1.234\nDeltaBlue: 10757567\ny\n',
|
|
|
|
'x\nRichards: 1.234\nDeltaBlue: 10557567\ny\n',
|
|
|
|
'x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n',
|
|
|
|
'x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n',
|
|
|
|
'x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n',
|
|
|
|
'x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n',
|
|
|
|
'x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n',
|
|
|
|
'x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n',
|
|
|
|
'x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n',
|
|
|
|
'x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n',
|
|
|
|
# Need 4 more runs for confidence in DeltaBlue results.
|
|
|
|
'x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n',
|
|
|
|
'x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n',
|
|
|
|
'x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n',
|
|
|
|
'x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n',
|
|
|
|
]),
|
|
|
|
)
|
|
|
|
self.assertEqual(0, self._CallMain('--confidence-level', '1'))
|
|
|
|
self._VerifyResults('test', 'score', [
|
|
|
|
{'name': 'Richards', 'results': [1.234] * 14, 'stddev': ''},
|
|
|
|
{
|
|
|
|
'name': 'DeltaBlue',
|
|
|
|
'results': [10757567.0, 10557567.0] + [10657567.0] * 12,
|
|
|
|
'stddev': '',
|
|
|
|
},
|
2014-09-02 09:17:26 +00:00
|
|
|
])
|
|
|
|
self._VerifyErrors([])
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyMock(os.path.join(
|
|
|
|
'out', 'x64.release', 'd7'), '--flag', 'run.js')
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
def testNestedSuite(self):
|
|
|
|
self._WriteTestInput(V8_NESTED_SUITES_JSON)
|
2019-04-12 11:00:18 +00:00
|
|
|
self._MockCommand(['delta_blue', 'sub/leaf', 'richards'],
|
|
|
|
['DeltaBlue: 200\n',
|
|
|
|
'Simple: 1 ms.\n',
|
|
|
|
'Simple: 2 ms.\n',
|
|
|
|
'Simple: 3 ms.\n',
|
|
|
|
'Richards: 100\n',
|
|
|
|
'Richards: 50\n'])
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(0, self._CallMain())
|
|
|
|
self.assertListEqual(sorted([
|
2019-04-12 11:00:18 +00:00
|
|
|
{'units': 'score',
|
|
|
|
'graphs': ['test', 'Richards'],
|
2019-05-09 09:05:37 +00:00
|
|
|
'results': [50.0, 100.0],
|
2019-04-12 11:00:18 +00:00
|
|
|
'stddev': ''},
|
|
|
|
{'units': 'ms',
|
|
|
|
'graphs': ['test', 'Sub', 'Leaf'],
|
2019-05-09 09:05:37 +00:00
|
|
|
'results': [3.0, 2.0, 1.0],
|
2019-04-12 11:00:18 +00:00
|
|
|
'stddev': ''},
|
|
|
|
{'units': 'score',
|
|
|
|
'graphs': ['test', 'DeltaBlue'],
|
2019-05-09 09:05:37 +00:00
|
|
|
'results': [200.0],
|
2019-04-12 11:00:18 +00:00
|
|
|
'stddev': ''},
|
2019-04-25 17:23:45 +00:00
|
|
|
]), sorted(self._LoadResults()['traces']))
|
2014-09-02 09:17:26 +00:00
|
|
|
self._VerifyErrors([])
|
|
|
|
self._VerifyMockMultiple(
|
2019-04-12 11:00:18 +00:00
|
|
|
(os.path.join('out', 'x64.release', 'd7'), '--flag', 'run.js'),
|
|
|
|
(os.path.join('out', 'x64.release', 'd7'), '--flag', 'run.js'),
|
|
|
|
(os.path.join('out', 'x64.release', 'd8'), '--flag', 'run.js'),
|
|
|
|
(os.path.join('out', 'x64.release', 'd8'), '--flag', 'run.js'),
|
|
|
|
(os.path.join('out', 'x64.release', 'd8'), '--flag', 'run.js'),
|
|
|
|
(os.path.join('out', 'x64.release', 'd8'),
|
|
|
|
'--flag', '--flag2', 'run.js'))
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
def testOneRunStdDevRegExp(self):
|
|
|
|
test_input = dict(V8_JSON)
|
2019-04-12 11:00:18 +00:00
|
|
|
test_input['stddev_regexp'] = '^%s\-stddev: (.+)$'
|
2014-09-02 09:17:26 +00:00
|
|
|
self._WriteTestInput(test_input)
|
2019-04-12 11:00:18 +00:00
|
|
|
self._MockCommand(['.'], ['Richards: 1.234\nRichards-stddev: 0.23\n'
|
|
|
|
'DeltaBlue: 10657567\nDeltaBlue-stddev: 106\n'])
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(0, self._CallMain())
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyResults('test', 'score', [
|
2019-05-09 09:05:37 +00:00
|
|
|
{'name': 'Richards', 'results': [1.234], 'stddev': '0.23'},
|
|
|
|
{'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': '106'},
|
2014-09-02 09:17:26 +00:00
|
|
|
])
|
|
|
|
self._VerifyErrors([])
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyMock(
|
|
|
|
os.path.join('out', 'x64.release', 'd7'), '--flag', 'run.js')
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
def testTwoRunsStdDevRegExp(self):
|
|
|
|
test_input = dict(V8_JSON)
|
2019-04-12 11:00:18 +00:00
|
|
|
test_input['stddev_regexp'] = '^%s\-stddev: (.+)$'
|
|
|
|
test_input['run_count'] = 2
|
2014-09-02 09:17:26 +00:00
|
|
|
self._WriteTestInput(test_input)
|
2019-04-12 11:00:18 +00:00
|
|
|
self._MockCommand(['.'], ['Richards: 3\nRichards-stddev: 0.7\n'
|
|
|
|
'DeltaBlue: 6\nDeltaBlue-boom: 0.9\n',
|
|
|
|
'Richards: 2\nRichards-stddev: 0.5\n'
|
|
|
|
'DeltaBlue: 5\nDeltaBlue-stddev: 0.8\n'])
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(1, self._CallMain())
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyResults('test', 'score', [
|
2019-05-09 09:05:37 +00:00
|
|
|
{'name': 'Richards', 'results': [2.0, 3.0], 'stddev': '0.7'},
|
|
|
|
{'name': 'DeltaBlue', 'results': [5.0, 6.0], 'stddev': '0.8'},
|
2014-09-02 09:17:26 +00:00
|
|
|
])
|
|
|
|
self._VerifyErrors(
|
2019-04-12 11:00:18 +00:00
|
|
|
['Test test/Richards should only run once since a stddev is provided '
|
|
|
|
'by the test.',
|
|
|
|
'Test test/DeltaBlue should only run once since a stddev is provided '
|
|
|
|
'by the test.',
|
|
|
|
'Regexp "^DeltaBlue\-stddev: (.+)$" did not match for test '
|
|
|
|
'test/DeltaBlue.'])
|
|
|
|
self._VerifyMock(
|
|
|
|
os.path.join('out', 'x64.release', 'd7'), '--flag', 'run.js')
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
def testBuildbot(self):
|
|
|
|
self._WriteTestInput(V8_JSON)
|
2019-04-12 11:00:18 +00:00
|
|
|
self._MockCommand(['.'], ['Richards: 1.234\nDeltaBlue: 10657567\n'])
|
|
|
|
mock.patch.object(
|
|
|
|
run_perf.Platform, 'ReadBuildConfig',
|
|
|
|
mock.MagicMock(return_value={'is_android': False})).start()
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(0, self._CallMain('--buildbot'))
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyResults('test', 'score', [
|
2019-05-09 09:05:37 +00:00
|
|
|
{'name': 'Richards', 'results': [1.234], 'stddev': ''},
|
|
|
|
{'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
|
2014-09-02 09:17:26 +00:00
|
|
|
])
|
|
|
|
self._VerifyErrors([])
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyMock(os.path.join('out', 'Release', 'd7'), '--flag', 'run.js')
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
def testBuildbotWithTotal(self):
|
|
|
|
test_input = dict(V8_JSON)
|
2019-04-12 11:00:18 +00:00
|
|
|
test_input['total'] = True
|
2014-09-02 09:17:26 +00:00
|
|
|
self._WriteTestInput(test_input)
|
2019-04-12 11:00:18 +00:00
|
|
|
self._MockCommand(['.'], ['Richards: 1.234\nDeltaBlue: 10657567\n'])
|
|
|
|
mock.patch.object(
|
|
|
|
run_perf.Platform, 'ReadBuildConfig',
|
|
|
|
mock.MagicMock(return_value={'is_android': False})).start()
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(0, self._CallMain('--buildbot'))
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyResults('test', 'score', [
|
2019-05-09 09:05:37 +00:00
|
|
|
{'name': 'Richards', 'results': [1.234], 'stddev': ''},
|
|
|
|
{'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
|
|
|
|
{'name': 'Total', 'results': [3626.491097190233], 'stddev': ''},
|
2014-09-02 09:17:26 +00:00
|
|
|
])
|
|
|
|
self._VerifyErrors([])
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyMock(os.path.join('out', 'Release', 'd7'), '--flag', 'run.js')
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
def testBuildbotWithTotalAndErrors(self):
|
|
|
|
test_input = dict(V8_JSON)
|
2019-04-12 11:00:18 +00:00
|
|
|
test_input['total'] = True
|
2014-09-02 09:17:26 +00:00
|
|
|
self._WriteTestInput(test_input)
|
2019-04-12 11:00:18 +00:00
|
|
|
self._MockCommand(['.'], ['x\nRichards: bla\nDeltaBlue: 10657567\ny\n'])
|
|
|
|
mock.patch.object(
|
|
|
|
run_perf.Platform, 'ReadBuildConfig',
|
|
|
|
mock.MagicMock(return_value={'is_android': False})).start()
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(1, self._CallMain('--buildbot'))
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyResults('test', 'score', [
|
2019-05-09 09:05:37 +00:00
|
|
|
{'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
|
2014-09-02 09:17:26 +00:00
|
|
|
])
|
|
|
|
self._VerifyErrors(
|
2019-04-12 11:00:18 +00:00
|
|
|
['Regexp "^Richards: (.+)$" '
|
|
|
|
'returned a non-numeric for test test/Richards.',
|
2019-04-26 13:05:52 +00:00
|
|
|
'Not all traces have produced results. Can not compute total for '
|
|
|
|
'test.'])
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyMock(os.path.join('out', 'Release', 'd7'), '--flag', 'run.js')
|
2014-09-02 09:17:26 +00:00
|
|
|
|
|
|
|
def testRegexpNoMatch(self):
|
|
|
|
self._WriteTestInput(V8_JSON)
|
2019-04-12 11:00:18 +00:00
|
|
|
self._MockCommand(['.'], ['x\nRichaards: 1.234\nDeltaBlue: 10657567\ny\n'])
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(1, self._CallMain())
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyResults('test', 'score', [
|
2019-05-09 09:05:37 +00:00
|
|
|
{'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
|
2014-09-02 09:17:26 +00:00
|
|
|
])
|
|
|
|
self._VerifyErrors(
|
2019-04-12 11:00:18 +00:00
|
|
|
['Regexp "^Richards: (.+)$" did not match for test test/Richards.'])
|
|
|
|
self._VerifyMock(
|
|
|
|
os.path.join('out', 'x64.release', 'd7'), '--flag', 'run.js')
|
2014-09-02 09:17:26 +00:00
|
|
|
|
2018-10-30 14:23:38 +00:00
|
|
|
def testOneRunCrashed(self):
|
2019-05-02 20:49:36 +00:00
|
|
|
test_input = dict(V8_JSON)
|
|
|
|
test_input['retry_count'] = 1
|
|
|
|
self._WriteTestInput(test_input)
|
2018-10-30 14:23:38 +00:00
|
|
|
self._MockCommand(
|
2019-05-02 20:49:36 +00:00
|
|
|
['.'], ['x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n', ''],
|
|
|
|
exit_code=-1)
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(1, self._CallMain())
|
2019-04-26 13:05:52 +00:00
|
|
|
self._VerifyResults('test', 'score', [])
|
2018-10-30 14:23:38 +00:00
|
|
|
self._VerifyErrors([])
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyMock(
|
|
|
|
os.path.join('out', 'x64.release', 'd7'), '--flag', 'run.js')
|
2018-10-30 14:23:38 +00:00
|
|
|
|
2014-09-15 13:00:32 +00:00
|
|
|
def testOneRunTimingOut(self):
|
|
|
|
test_input = dict(V8_JSON)
|
2019-04-12 11:00:18 +00:00
|
|
|
test_input['timeout'] = 70
|
2019-05-02 20:49:36 +00:00
|
|
|
test_input['retry_count'] = 0
|
2014-09-15 13:00:32 +00:00
|
|
|
self._WriteTestInput(test_input)
|
2019-04-12 11:00:18 +00:00
|
|
|
self._MockCommand(['.'], [''], timed_out=True)
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(1, self._CallMain())
|
2019-04-26 13:05:52 +00:00
|
|
|
self._VerifyResults('test', 'score', [])
|
2018-10-30 14:23:38 +00:00
|
|
|
self._VerifyErrors([])
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyMock(os.path.join('out', 'x64.release', 'd7'),
|
|
|
|
'--flag', 'run.js', timeout=70)
|
2014-12-02 14:23:51 +00:00
|
|
|
|
|
|
|
def testAndroid(self):
|
|
|
|
self._WriteTestInput(V8_JSON)
|
2019-04-12 11:00:18 +00:00
|
|
|
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.AndroidPlatform.Run',
|
2019-04-23 11:32:13 +00:00
|
|
|
return_value=(Output(stdout='Richards: 1.234\nDeltaBlue: 10657567\n'),
|
|
|
|
NULL_OUTPUT)).start()
|
2019-04-12 11:00:18 +00:00
|
|
|
mock.patch('testrunner.local.android._Driver', autospec=True).start()
|
|
|
|
mock.patch(
|
|
|
|
'run_perf.Platform.ReadBuildConfig',
|
|
|
|
return_value={'is_android': True}).start()
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(0, self._CallMain('--arch', 'arm'))
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyResults('test', 'score', [
|
2019-05-09 09:05:37 +00:00
|
|
|
{'name': 'Richards', 'results': [1.234], 'stddev': ''},
|
|
|
|
{'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
|
2014-12-02 14:23:51 +00:00
|
|
|
])
|
2015-07-10 13:02:09 +00:00
|
|
|
|
|
|
|
def testTwoRuns_Trybot(self):
|
|
|
|
test_input = dict(V8_JSON)
|
2019-04-12 11:00:18 +00:00
|
|
|
test_input['run_count'] = 2
|
2015-07-10 13:02:09 +00:00
|
|
|
self._WriteTestInput(test_input)
|
2019-04-12 11:00:18 +00:00
|
|
|
self._MockCommand(['.', '.', '.', '.'],
|
|
|
|
['Richards: 100\nDeltaBlue: 200\n',
|
|
|
|
'Richards: 200\nDeltaBlue: 20\n',
|
|
|
|
'Richards: 50\nDeltaBlue: 200\n',
|
|
|
|
'Richards: 100\nDeltaBlue: 20\n'])
|
|
|
|
test_output_secondary = os.path.join(
|
|
|
|
TEST_WORKSPACE, 'results_secondary.json')
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(0, self._CallMain(
|
2019-04-12 11:00:18 +00:00
|
|
|
'--outdir-secondary', 'out-secondary',
|
|
|
|
'--json-test-results-secondary', test_output_secondary,
|
2015-07-10 13:02:09 +00:00
|
|
|
))
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyResults('test', 'score', [
|
2019-05-09 09:05:37 +00:00
|
|
|
{'name': 'Richards', 'results': [100.0, 200.0], 'stddev': ''},
|
|
|
|
{'name': 'DeltaBlue', 'results': [20.0, 20.0], 'stddev': ''},
|
2015-07-10 13:02:09 +00:00
|
|
|
])
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyResults('test', 'score', [
|
2019-05-09 09:05:37 +00:00
|
|
|
{'name': 'Richards', 'results': [50.0, 100.0], 'stddev': ''},
|
|
|
|
{'name': 'DeltaBlue', 'results': [200.0, 200.0], 'stddev': ''},
|
2017-11-21 16:10:50 +00:00
|
|
|
], test_output_secondary)
|
2019-04-23 16:07:52 +00:00
|
|
|
self._VerifyRunnableDurations(2, 60, test_output_secondary)
|
2015-07-10 13:02:09 +00:00
|
|
|
self._VerifyErrors([])
|
|
|
|
self._VerifyMockMultiple(
|
2019-04-12 11:00:18 +00:00
|
|
|
(os.path.join('out', 'x64.release', 'd7'), '--flag', 'run.js'),
|
|
|
|
(os.path.join('out-secondary', 'x64.release', 'd7'),
|
|
|
|
'--flag', 'run.js'),
|
|
|
|
(os.path.join('out', 'x64.release', 'd7'), '--flag', 'run.js'),
|
|
|
|
(os.path.join('out-secondary', 'x64.release', 'd7'),
|
|
|
|
'--flag', 'run.js'),
|
2015-07-10 13:02:09 +00:00
|
|
|
)
|
|
|
|
|
2015-09-15 08:15:54 +00:00
|
|
|
def testWrongBinaryWithProf(self):
|
|
|
|
test_input = dict(V8_JSON)
|
|
|
|
self._WriteTestInput(test_input)
|
2019-04-12 11:00:18 +00:00
|
|
|
self._MockCommand(['.'], ['x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n'])
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertEqual(0, self._CallMain('--extra-flags=--prof'))
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyResults('test', 'score', [
|
2019-05-09 09:05:37 +00:00
|
|
|
{'name': 'Richards', 'results': [1.234], 'stddev': ''},
|
|
|
|
{'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
|
2015-09-15 08:15:54 +00:00
|
|
|
])
|
|
|
|
self._VerifyErrors([])
|
2019-04-12 11:00:18 +00:00
|
|
|
self._VerifyMock(os.path.join('out', 'x64.release', 'd7'),
|
|
|
|
'--flag', '--prof', 'run.js')
|
2015-09-15 08:15:54 +00:00
|
|
|
|
2017-02-16 13:48:31 +00:00
|
|
|
#############################################################################
|
|
|
|
### System tests
|
|
|
|
|
|
|
|
def _RunPerf(self, mocked_d8, test_json):
|
2019-04-12 11:00:18 +00:00
|
|
|
output_json = os.path.join(TEST_WORKSPACE, 'output.json')
|
2017-02-16 13:48:31 +00:00
|
|
|
args = [
|
2019-04-12 11:00:18 +00:00
|
|
|
os.sys.executable, RUN_PERF,
|
|
|
|
'--binary-override-path', os.path.join(TEST_DATA, mocked_d8),
|
|
|
|
'--json-test-results', output_json,
|
2017-02-16 13:48:31 +00:00
|
|
|
os.path.join(TEST_DATA, test_json),
|
|
|
|
]
|
|
|
|
subprocess.check_output(args)
|
|
|
|
return self._LoadResults(output_json)
|
|
|
|
|
|
|
|
def testNormal(self):
|
2019-04-12 11:00:18 +00:00
|
|
|
results = self._RunPerf('d8_mocked1.py', 'test1.json')
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertListEqual([], results['errors'])
|
|
|
|
self.assertListEqual(sorted([
|
2017-02-16 13:48:31 +00:00
|
|
|
{
|
|
|
|
'units': 'score',
|
|
|
|
'graphs': ['test1', 'Richards'],
|
2019-05-09 09:05:37 +00:00
|
|
|
'results': [1.2, 1.2],
|
2017-02-16 13:48:31 +00:00
|
|
|
'stddev': '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'units': 'score',
|
|
|
|
'graphs': ['test1', 'DeltaBlue'],
|
2019-05-09 09:05:37 +00:00
|
|
|
'results': [2.1, 2.1],
|
2017-02-16 13:48:31 +00:00
|
|
|
'stddev': '',
|
|
|
|
},
|
2019-04-25 17:23:45 +00:00
|
|
|
]), sorted(results['traces']))
|
2017-02-16 13:48:31 +00:00
|
|
|
|
|
|
|
def testResultsProcessor(self):
|
2019-04-12 11:00:18 +00:00
|
|
|
results = self._RunPerf('d8_mocked2.py', 'test2.json')
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertListEqual([], results['errors'])
|
|
|
|
self.assertListEqual([
|
2017-02-16 13:48:31 +00:00
|
|
|
{
|
|
|
|
'units': 'score',
|
|
|
|
'graphs': ['test2', 'Richards'],
|
2019-05-09 09:05:37 +00:00
|
|
|
'results': [1.2, 1.2],
|
2017-02-16 13:48:31 +00:00
|
|
|
'stddev': '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'units': 'score',
|
|
|
|
'graphs': ['test2', 'DeltaBlue'],
|
2019-05-09 09:05:37 +00:00
|
|
|
'results': [2.1, 2.1],
|
2017-02-16 13:48:31 +00:00
|
|
|
'stddev': '',
|
|
|
|
},
|
|
|
|
], results['traces'])
|
|
|
|
|
|
|
|
def testResultsProcessorNested(self):
|
2019-04-12 11:00:18 +00:00
|
|
|
results = self._RunPerf('d8_mocked2.py', 'test3.json')
|
2019-04-25 17:23:45 +00:00
|
|
|
self.assertListEqual([], results['errors'])
|
|
|
|
self.assertListEqual([
|
2017-02-16 13:48:31 +00:00
|
|
|
{
|
|
|
|
'units': 'score',
|
|
|
|
'graphs': ['test3', 'Octane', 'Richards'],
|
2019-05-09 09:05:37 +00:00
|
|
|
'results': [1.2],
|
2017-02-16 13:48:31 +00:00
|
|
|
'stddev': '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'units': 'score',
|
|
|
|
'graphs': ['test3', 'Octane', 'DeltaBlue'],
|
2019-05-09 09:05:37 +00:00
|
|
|
'results': [2.1],
|
2017-02-16 13:48:31 +00:00
|
|
|
'stddev': '',
|
|
|
|
},
|
|
|
|
], results['traces'])
|
2017-11-21 16:10:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|