2017-12-08 14:07:25 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright 2017 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.
|
|
|
|
|
|
|
|
"""
|
|
|
|
Wrapper script for verify-predictable mode. D8 is expected to be compiled with
|
|
|
|
v8_enable_verify_predictable.
|
|
|
|
|
|
|
|
The actual test command is expected to be passed to this wraper as is. E.g.:
|
|
|
|
predictable_wrapper.py path/to/d8 --test --predictable --flag1 --flag2
|
|
|
|
|
|
|
|
The command is run up to three times and the printed allocation hash is
|
|
|
|
compared. Differences are reported as errors.
|
|
|
|
"""
|
|
|
|
|
2019-02-19 08:28:26 +00:00
|
|
|
|
|
|
|
# for py2/py3 compatibility
|
2020-06-23 21:40:47 +00:00
|
|
|
from __future__ import absolute_import
|
2019-02-19 08:28:26 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2017-12-08 14:07:25 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
from testrunner.local import command
|
2018-08-10 17:09:34 +00:00
|
|
|
from testrunner.local import utils
|
2017-12-08 14:07:25 +00:00
|
|
|
|
2019-02-19 08:28:26 +00:00
|
|
|
|
2017-12-08 14:07:25 +00:00
|
|
|
MAX_TRIES = 3
|
2018-03-14 08:29:17 +00:00
|
|
|
TIMEOUT = 120
|
2017-12-08 14:07:25 +00:00
|
|
|
|
2018-08-10 17:09:34 +00:00
|
|
|
# Predictable mode works only when run on the host os.
|
2019-02-05 17:53:52 +00:00
|
|
|
command.setup(utils.GuessOS(), None)
|
2018-08-10 17:09:34 +00:00
|
|
|
|
2017-12-08 14:07:25 +00:00
|
|
|
def main(args):
|
|
|
|
def allocation_str(stdout):
|
|
|
|
for line in reversed((stdout or '').splitlines()):
|
|
|
|
if line.startswith('### Allocations = '):
|
|
|
|
return line
|
|
|
|
return None
|
|
|
|
|
2020-01-15 19:38:25 +00:00
|
|
|
cmd = command.Command(
|
|
|
|
args[0], args[1:], timeout=TIMEOUT, handle_sigterm=True)
|
2017-12-08 14:07:25 +00:00
|
|
|
|
|
|
|
previous_allocations = None
|
|
|
|
for run in range(1, MAX_TRIES + 1):
|
2019-02-19 08:28:26 +00:00
|
|
|
print('### Predictable run #%d' % run)
|
2017-12-08 14:07:25 +00:00
|
|
|
output = cmd.execute()
|
|
|
|
if output.stdout:
|
2019-02-19 08:28:26 +00:00
|
|
|
print('### Stdout:')
|
|
|
|
print(output.stdout)
|
2017-12-08 14:07:25 +00:00
|
|
|
if output.stderr:
|
2019-02-19 08:28:26 +00:00
|
|
|
print('### Stderr:')
|
|
|
|
print(output.stderr)
|
|
|
|
print('### Return code: %s' % output.exit_code)
|
2017-12-08 14:07:25 +00:00
|
|
|
if output.HasTimedOut():
|
|
|
|
# If we get a timeout in any run, we are in an unpredictable state. Just
|
|
|
|
# report it as a failure and don't rerun.
|
2019-02-19 08:28:26 +00:00
|
|
|
print('### Test timed out')
|
2017-12-08 14:07:25 +00:00
|
|
|
return 1
|
|
|
|
allocations = allocation_str(output.stdout)
|
|
|
|
if not allocations:
|
|
|
|
print ('### Test had no allocation output. Ensure this is built '
|
|
|
|
'with v8_enable_verify_predictable and that '
|
|
|
|
'--verify-predictable is passed at the cmd line.')
|
|
|
|
return 2
|
|
|
|
if previous_allocations and previous_allocations != allocations:
|
2019-02-19 08:28:26 +00:00
|
|
|
print('### Allocations differ')
|
2017-12-08 14:07:25 +00:00
|
|
|
return 3
|
|
|
|
if run >= MAX_TRIES:
|
|
|
|
# No difference on the last run -> report a success.
|
|
|
|
return 0
|
|
|
|
previous_allocations = allocations
|
|
|
|
# Unreachable.
|
|
|
|
assert False
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main(sys.argv[1:]))
|