run_perf_test.py 21.7 KB
Newer Older
1 2 3 4 5
#!/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.

6 7 8
# for py2/py3 compatibility
from __future__ import print_function

9 10 11
from collections import namedtuple
import json
import os
12
import platform
13
import shutil
14
import subprocess
15
import sys
16 17 18
import tempfile
import unittest

19 20 21
import coverage
import mock

22 23 24
# Requires python-coverage and python-mock. Native python coverage
# version >= 3.7.1 should be installed to get the best speed.

25 26 27 28
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')

29
TEST_WORKSPACE = os.path.join(tempfile.gettempdir(), 'test-v8-run-perf')
30 31

V8_JSON = {
32 33 34
  'path': ['.'],
  'owners': ['username@chromium.org'],
  'binary': 'd7',
35
  'timeout': 60,
36 37 38 39 40 41 42
  'flags': ['--flag'],
  'main': 'run.js',
  'run_count': 1,
  'results_regexp': '^%s: (.+)$',
  'tests': [
    {'name': 'Richards'},
    {'name': 'DeltaBlue'},
43 44 45 46
  ]
}

V8_NESTED_SUITES_JSON = {
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  '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.$'},
69 70
     ]
    },
71 72 73 74 75 76 77 78 79
    {'name': 'DeltaBlue',
     'path': ['delta_blue'],
     'main': 'run.js',
     'flags': ['--flag2'],
     'results_regexp': '^DeltaBlue: (.+)$'},
    {'name': 'ShouldntRun',
     'path': ['.'],
     'archs': ['arm'],
     'main': 'run.js'},
80 81 82 83
  ]
}

V8_GENERIC_JSON = {
84 85 86 87 88 89 90
  'path': ['.'],
  'owners': ['username@chromium.org'],
  'binary': 'cc',
  'flags': ['--flag'],
  'generic': True,
  'run_count': 1,
  'units': 'ms',
91 92 93 94 95
}

class PerfTest(unittest.TestCase):
  @classmethod
  def setUpClass(cls):
96
    sys.path.insert(0, BASE_DIR)
97
    cls._cov = coverage.coverage(
98
        include=([os.path.join(BASE_DIR, 'run_perf.py')]))
99 100
    cls._cov.start()
    import run_perf
101
    from testrunner.local import command
102 103
    from testrunner.objects.output import Output, NULL_OUTPUT
    global command, run_perf, Output, NULL_OUTPUT
104 105 106 107

  @classmethod
  def tearDownClass(cls):
    cls._cov.stop()
108
    print('')
109
    print(cls._cov.report())
110 111 112

  def setUp(self):
    self.maxDiff = None
113
    if os.path.exists(TEST_WORKSPACE):
114 115 116 117
      shutil.rmtree(TEST_WORKSPACE)
    os.makedirs(TEST_WORKSPACE)

  def tearDown(self):
118 119
    mock.patch.stopall()
    if os.path.exists(TEST_WORKSPACE):
120 121 122
      shutil.rmtree(TEST_WORKSPACE)

  def _WriteTestInput(self, json_content):
123 124
    self._test_input = os.path.join(TEST_WORKSPACE, 'test.json')
    with open(self._test_input, 'w') as f:
125 126
      f.write(json.dumps(json_content))

127
  def _MockCommand(self, *args, **kwargs):
128
    # Fake output for each test run.
129
    test_outputs = [Output(stdout=arg,
130
                           timed_out=kwargs.get('timed_out', False),
131 132
                           exit_code=kwargs.get('exit_code', 0),
                           duration=42)
133
                    for arg in args[1]]
134
    def create_cmd(*args, **kwargs):
135
      cmd = mock.MagicMock()
136 137
      def execute(*args, **kwargs):
        return test_outputs.pop()
138
      cmd.execute = mock.MagicMock(side_effect=execute)
139 140
      return cmd

141
    mock.patch.object(
142
        run_perf.command, 'PosixCommand',
143
        mock.MagicMock(side_effect=create_cmd)).start()
144 145

    # Check that d8 is called from the correct cwd for each test run.
146
    dirs = [os.path.join(TEST_WORKSPACE, arg) for arg in args[0]]
147
    def chdir(*args, **kwargs):
148
      self.assertEqual(dirs.pop(), args[0])
149
    os.chdir = mock.MagicMock(side_effect=chdir)
150

151 152
    subprocess.check_call = mock.MagicMock()
    platform.system = mock.MagicMock(return_value='Linux')
153

154
  def _CallMain(self, *args):
155
    self._test_output = os.path.join(TEST_WORKSPACE, 'results.json')
156
    all_args=[
157
      '--json-test-results',
158 159 160 161 162 163
      self._test_output,
      self._test_input,
    ]
    all_args += args
    return run_perf.Main(all_args)

164 165
  def _LoadResults(self, file_name=None):
    with open(file_name or self._test_output) as f:
166 167
      return json.load(f)

168
  def _VerifyResults(self, suite, units, traces, file_name=None):
169
    self.assertListEqual(sorted([
170 171 172
      {'units': units,
       'graphs': [suite, trace['name']],
       'results': trace['results'],
173 174
       'stddev': trace['stddev']} for trace in traces]),
      sorted(self._LoadResults(file_name)['traces']))
175

176
  def _VerifyRunnableDurations(self, runs, timeout, file_name=None):
177 178 179 180 181 182 183
    self.assertListEqual([
      {
        'graphs': ['test'],
        'durations': [42] * runs,
        'timeout': timeout,
      },
    ], self._LoadResults(file_name)['runnables'])
184

185
  def _VerifyErrors(self, errors):
186
    self.assertListEqual(errors, self._LoadResults()['errors'])
187

188
  def _VerifyMock(self, binary, *args, **kwargs):
189
    shell = os.path.join(os.path.dirname(BASE_DIR), binary)
190 191 192 193
    command.Command.assert_called_with(
        cmd_prefix=[],
        shell=shell,
        args=list(args),
194 195
        timeout=kwargs.get('timeout', 60),
        handle_sigterm=True)
196

197
  def _VerifyMockMultiple(self, *args, **kwargs):
198
    self.assertEqual(len(args), len(command.Command.call_args_list))
199 200 201
    for arg, actual in zip(args, command.Command.call_args_list):
      expected = {
        'cmd_prefix': [],
202
        'shell': os.path.join(os.path.dirname(BASE_DIR), arg[0]),
203
        'args': list(arg[1:]),
204 205
        'timeout': kwargs.get('timeout', 60),
        'handle_sigterm': True,
206
      }
207
      self.assertTupleEqual((expected, ), actual)
208 209 210

  def testOneRun(self):
    self._WriteTestInput(V8_JSON)
211
    self._MockCommand(['.'], ['x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n'])
212
    self.assertEqual(0, self._CallMain())
213
    self._VerifyResults('test', 'score', [
214 215
      {'name': 'Richards', 'results': [1.234], 'stddev': ''},
      {'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
216
    ])
217
    self._VerifyRunnableDurations(1, 60)
218
    self._VerifyErrors([])
219 220
    self._VerifyMock(
        os.path.join('out', 'x64.release', 'd7'), '--flag', 'run.js')
221

222 223
  def testOneRunWithTestFlags(self):
    test_input = dict(V8_JSON)
224
    test_input['test_flags'] = ['2', 'test_name']
225
    self._WriteTestInput(test_input)
226
    self._MockCommand(['.'], ['Richards: 1.234\nDeltaBlue: 10657567'])
227
    self.assertEqual(0, self._CallMain())
228
    self._VerifyResults('test', 'score', [
229 230
      {'name': 'Richards', 'results': [1.234], 'stddev': ''},
      {'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
231 232
    ])
    self._VerifyErrors([])
233 234
    self._VerifyMock(os.path.join(
      'out', 'x64.release', 'd7'), '--flag', 'run.js', '--', '2', 'test_name')
235

236 237
  def testTwoRuns_Units_SuiteName(self):
    test_input = dict(V8_JSON)
238 239 240
    test_input['run_count'] = 2
    test_input['name'] = 'v8'
    test_input['units'] = 'ms'
241
    self._WriteTestInput(test_input)
242 243 244
    self._MockCommand(['.', '.'],
                      ['Richards: 100\nDeltaBlue: 200\n',
                       'Richards: 50\nDeltaBlue: 300\n'])
245
    self.assertEqual(0, self._CallMain())
246
    self._VerifyResults('v8', 'ms', [
247 248
      {'name': 'Richards', 'results': [50.0, 100.0], 'stddev': ''},
      {'name': 'DeltaBlue', 'results': [300.0, 200.0], 'stddev': ''},
249 250
    ])
    self._VerifyErrors([])
251 252
    self._VerifyMock(os.path.join(
      'out', 'x64.release', 'd7'), '--flag', 'run.js')
253 254 255

  def testTwoRuns_SubRegexp(self):
    test_input = dict(V8_JSON)
256 257 258 259
    test_input['run_count'] = 2
    del test_input['results_regexp']
    test_input['tests'][0]['results_regexp'] = '^Richards: (.+)$'
    test_input['tests'][1]['results_regexp'] = '^DeltaBlue: (.+)$'
260
    self._WriteTestInput(test_input)
261 262 263
    self._MockCommand(['.', '.'],
                      ['Richards: 100\nDeltaBlue: 200\n',
                       'Richards: 50\nDeltaBlue: 300\n'])
264
    self.assertEqual(0, self._CallMain())
265
    self._VerifyResults('test', 'score', [
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
      {'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': '',
      },
317 318
    ])
    self._VerifyErrors([])
319 320
    self._VerifyMock(os.path.join(
      'out', 'x64.release', 'd7'), '--flag', 'run.js')
321 322 323

  def testNestedSuite(self):
    self._WriteTestInput(V8_NESTED_SUITES_JSON)
324 325 326 327 328 329 330
    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'])
331 332
    self.assertEqual(0, self._CallMain())
    self.assertListEqual(sorted([
333 334
      {'units': 'score',
       'graphs': ['test', 'Richards'],
335
       'results': [50.0, 100.0],
336 337 338
       'stddev': ''},
      {'units': 'ms',
       'graphs': ['test', 'Sub', 'Leaf'],
339
       'results': [3.0, 2.0, 1.0],
340 341 342
       'stddev': ''},
      {'units': 'score',
       'graphs': ['test', 'DeltaBlue'],
343
       'results': [200.0],
344
       'stddev': ''},
345
      ]), sorted(self._LoadResults()['traces']))
346 347
    self._VerifyErrors([])
    self._VerifyMockMultiple(
348 349 350 351 352 353 354
        (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'))
355 356 357

  def testOneRunStdDevRegExp(self):
    test_input = dict(V8_JSON)
358
    test_input['stddev_regexp'] = '^%s\-stddev: (.+)$'
359
    self._WriteTestInput(test_input)
360 361
    self._MockCommand(['.'], ['Richards: 1.234\nRichards-stddev: 0.23\n'
                              'DeltaBlue: 10657567\nDeltaBlue-stddev: 106\n'])
362
    self.assertEqual(0, self._CallMain())
363
    self._VerifyResults('test', 'score', [
364 365
      {'name': 'Richards', 'results': [1.234], 'stddev': '0.23'},
      {'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': '106'},
366 367
    ])
    self._VerifyErrors([])
368 369
    self._VerifyMock(
        os.path.join('out', 'x64.release', 'd7'), '--flag', 'run.js')
370 371 372

  def testTwoRunsStdDevRegExp(self):
    test_input = dict(V8_JSON)
373 374
    test_input['stddev_regexp'] = '^%s\-stddev: (.+)$'
    test_input['run_count'] = 2
375
    self._WriteTestInput(test_input)
376 377 378 379
    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'])
380
    self.assertEqual(1, self._CallMain())
381
    self._VerifyResults('test', 'score', [
382 383
      {'name': 'Richards', 'results': [2.0, 3.0], 'stddev': '0.7'},
      {'name': 'DeltaBlue', 'results': [5.0, 6.0], 'stddev': '0.8'},
384 385
    ])
    self._VerifyErrors(
386 387 388 389 390 391 392 393
        ['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')
394 395 396

  def testBuildbot(self):
    self._WriteTestInput(V8_JSON)
397 398 399 400
    self._MockCommand(['.'], ['Richards: 1.234\nDeltaBlue: 10657567\n'])
    mock.patch.object(
        run_perf.Platform, 'ReadBuildConfig',
        mock.MagicMock(return_value={'is_android': False})).start()
401
    self.assertEqual(0, self._CallMain('--buildbot'))
402
    self._VerifyResults('test', 'score', [
403 404
      {'name': 'Richards', 'results': [1.234], 'stddev': ''},
      {'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
405 406
    ])
    self._VerifyErrors([])
407
    self._VerifyMock(os.path.join('out', 'Release', 'd7'), '--flag', 'run.js')
408 409 410

  def testBuildbotWithTotal(self):
    test_input = dict(V8_JSON)
411
    test_input['total'] = True
412
    self._WriteTestInput(test_input)
413 414 415 416
    self._MockCommand(['.'], ['Richards: 1.234\nDeltaBlue: 10657567\n'])
    mock.patch.object(
        run_perf.Platform, 'ReadBuildConfig',
        mock.MagicMock(return_value={'is_android': False})).start()
417
    self.assertEqual(0, self._CallMain('--buildbot'))
418
    self._VerifyResults('test', 'score', [
419 420 421
      {'name': 'Richards', 'results': [1.234], 'stddev': ''},
      {'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
      {'name': 'Total', 'results': [3626.491097190233], 'stddev': ''},
422 423
    ])
    self._VerifyErrors([])
424
    self._VerifyMock(os.path.join('out', 'Release', 'd7'), '--flag', 'run.js')
425 426 427

  def testBuildbotWithTotalAndErrors(self):
    test_input = dict(V8_JSON)
428
    test_input['total'] = True
429
    self._WriteTestInput(test_input)
430 431 432 433
    self._MockCommand(['.'], ['x\nRichards: bla\nDeltaBlue: 10657567\ny\n'])
    mock.patch.object(
        run_perf.Platform, 'ReadBuildConfig',
        mock.MagicMock(return_value={'is_android': False})).start()
434
    self.assertEqual(1, self._CallMain('--buildbot'))
435
    self._VerifyResults('test', 'score', [
436
      {'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
437 438
    ])
    self._VerifyErrors(
439 440
        ['Regexp "^Richards: (.+)$" '
         'returned a non-numeric for test test/Richards.',
441 442
         'Not all traces have produced results. Can not compute total for '
         'test.'])
443
    self._VerifyMock(os.path.join('out', 'Release', 'd7'), '--flag', 'run.js')
444 445 446

  def testRegexpNoMatch(self):
    self._WriteTestInput(V8_JSON)
447
    self._MockCommand(['.'], ['x\nRichaards: 1.234\nDeltaBlue: 10657567\ny\n'])
448
    self.assertEqual(1, self._CallMain())
449
    self._VerifyResults('test', 'score', [
450
      {'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
451 452
    ])
    self._VerifyErrors(
453 454 455
        ['Regexp "^Richards: (.+)$" did not match for test test/Richards.'])
    self._VerifyMock(
        os.path.join('out', 'x64.release', 'd7'), '--flag', 'run.js')
456

457
  def testOneRunCrashed(self):
458 459 460
    test_input = dict(V8_JSON)
    test_input['retry_count'] = 1
    self._WriteTestInput(test_input)
461
    self._MockCommand(
462 463
        ['.'], ['x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n', ''],
        exit_code=-1)
464
    self.assertEqual(1, self._CallMain())
465
    self._VerifyResults('test', 'score', [])
466
    self._VerifyErrors([])
467 468
    self._VerifyMock(
        os.path.join('out', 'x64.release', 'd7'), '--flag', 'run.js')
469

470 471
  def testOneRunTimingOut(self):
    test_input = dict(V8_JSON)
472
    test_input['timeout'] = 70
473
    test_input['retry_count'] = 0
474
    self._WriteTestInput(test_input)
475
    self._MockCommand(['.'], [''], timed_out=True)
476
    self.assertEqual(1, self._CallMain())
477
    self._VerifyResults('test', 'score', [])
478
    self._VerifyErrors([])
479 480
    self._VerifyMock(os.path.join('out', 'x64.release', 'd7'),
                     '--flag', 'run.js', timeout=70)
481 482 483

  def testAndroid(self):
    self._WriteTestInput(V8_JSON)
484 485 486 487 488
    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',
489 490
        return_value=(Output(stdout='Richards: 1.234\nDeltaBlue: 10657567\n'),
                      NULL_OUTPUT)).start()
491 492 493 494
    mock.patch('testrunner.local.android._Driver', autospec=True).start()
    mock.patch(
        'run_perf.Platform.ReadBuildConfig',
        return_value={'is_android': True}).start()
495
    self.assertEqual(0, self._CallMain('--arch', 'arm'))
496
    self._VerifyResults('test', 'score', [
497 498
      {'name': 'Richards', 'results': [1.234], 'stddev': ''},
      {'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
499
    ])
500 501 502

  def testTwoRuns_Trybot(self):
    test_input = dict(V8_JSON)
503
    test_input['run_count'] = 2
504
    self._WriteTestInput(test_input)
505 506 507 508 509 510 511
    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')
512
    self.assertEqual(0, self._CallMain(
513 514
        '--outdir-secondary', 'out-secondary',
        '--json-test-results-secondary', test_output_secondary,
515
    ))
516
    self._VerifyResults('test', 'score', [
517 518
      {'name': 'Richards', 'results': [100.0, 200.0], 'stddev': ''},
      {'name': 'DeltaBlue', 'results': [20.0, 20.0], 'stddev': ''},
519
    ])
520
    self._VerifyResults('test', 'score', [
521 522
      {'name': 'Richards', 'results': [50.0, 100.0], 'stddev': ''},
      {'name': 'DeltaBlue', 'results': [200.0, 200.0], 'stddev': ''},
523
    ], test_output_secondary)
524
    self._VerifyRunnableDurations(2, 60, test_output_secondary)
525 526
    self._VerifyErrors([])
    self._VerifyMockMultiple(
527 528 529 530 531 532
        (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'),
533 534
    )

535 536 537
  def testWrongBinaryWithProf(self):
    test_input = dict(V8_JSON)
    self._WriteTestInput(test_input)
538
    self._MockCommand(['.'], ['x\nRichards: 1.234\nDeltaBlue: 10657567\ny\n'])
539
    self.assertEqual(0, self._CallMain('--extra-flags=--prof'))
540
    self._VerifyResults('test', 'score', [
541 542
      {'name': 'Richards', 'results': [1.234], 'stddev': ''},
      {'name': 'DeltaBlue', 'results': [10657567.0], 'stddev': ''},
543 544
    ])
    self._VerifyErrors([])
545 546
    self._VerifyMock(os.path.join('out', 'x64.release', 'd7'),
                     '--flag', '--prof', 'run.js')
547

548 549 550 551
  #############################################################################
  ### System tests

  def _RunPerf(self, mocked_d8, test_json):
552
    output_json = os.path.join(TEST_WORKSPACE, 'output.json')
553
    args = [
554 555 556
      os.sys.executable, RUN_PERF,
      '--binary-override-path', os.path.join(TEST_DATA, mocked_d8),
      '--json-test-results', output_json,
557 558 559 560 561 562
      os.path.join(TEST_DATA, test_json),
    ]
    subprocess.check_output(args)
    return self._LoadResults(output_json)

  def testNormal(self):
563
    results = self._RunPerf('d8_mocked1.py', 'test1.json')
564 565
    self.assertListEqual([], results['errors'])
    self.assertListEqual(sorted([
566 567 568
      {
        'units': 'score',
        'graphs': ['test1', 'Richards'],
569
        'results': [1.2, 1.2],
570 571 572 573 574
        'stddev': '',
      },
      {
        'units': 'score',
        'graphs': ['test1', 'DeltaBlue'],
575
        'results': [2.1, 2.1],
576 577
        'stddev': '',
      },
578
    ]), sorted(results['traces']))
579 580

  def testResultsProcessor(self):
581
    results = self._RunPerf('d8_mocked2.py', 'test2.json')
582 583
    self.assertListEqual([], results['errors'])
    self.assertListEqual([
584 585 586
      {
        'units': 'score',
        'graphs': ['test2', 'Richards'],
587
        'results': [1.2, 1.2],
588 589 590 591 592
        'stddev': '',
      },
      {
        'units': 'score',
        'graphs': ['test2', 'DeltaBlue'],
593
        'results': [2.1, 2.1],
594 595 596 597 598
        'stddev': '',
      },
    ], results['traces'])

  def testResultsProcessorNested(self):
599
    results = self._RunPerf('d8_mocked2.py', 'test3.json')
600 601
    self.assertListEqual([], results['errors'])
    self.assertListEqual([
602 603 604
      {
        'units': 'score',
        'graphs': ['test3', 'Octane', 'Richards'],
605
        'results': [1.2],
606 607 608 609 610
        'stddev': '',
      },
      {
        'units': 'score',
        'graphs': ['test3', 'Octane', 'DeltaBlue'],
611
        'results': [2.1],
612 613 614
        'stddev': '',
      },
    ], results['traces'])
615 616 617 618


if __name__ == '__main__':
  unittest.main()