| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 """Local testing cache for test results. |
| 5 |
| 6 The purpose of these functions is for the bisector to save some state between |
| 7 runs. Specifically, it is meant to save the results of running a specific test |
| 8 on a specific revision so that further bisections requiring them do not trigger |
| 9 a new test job every time. |
| 10 """ |
| 11 |
| 12 import hashlib |
| 13 import json |
| 14 import os |
| 15 import sys |
| 16 |
| 17 resultset_file = '/tmp/bisect/test_results_cache' |
| 18 |
| 19 def make_id(*params):# pragma: no cover |
| 20 id_string = json.dumps(params) |
| 21 return hashlib.sha1(id_string).hexdigest() |
| 22 |
| 23 def has_results(name):# pragma: no cover |
| 24 return name in _get_result_set() |
| 25 |
| 26 def save_results(name, value):# pragma: no cover |
| 27 rs = _get_result_set() |
| 28 rs[name] = value |
| 29 _write_result_set(rs) |
| 30 |
| 31 def _get_result_set():# pragma: no cover |
| 32 if os.path.isfile(resultset_file): |
| 33 contents = open(resultset_file).read() |
| 34 resultset = json.loads(contents) |
| 35 return resultset |
| 36 else: |
| 37 return {} |
| 38 |
| 39 def _write_result_set(resultset): # pragma: no cover |
| 40 _dir = os.path.dirname(resultset_file) |
| 41 if not os.path.exists(_dir): |
| 42 os.mkdir(_dir) |
| 43 with open(resultset_file, 'w') as of: |
| 44 contents = json.dumps(resultset) |
| 45 of.write(json.dumps(resultset)) |
| 46 |
| 47 def main(): # pragma: no cover |
| 48 some_id = make_id('dummy_string') |
| 49 if not has_results(some_id): |
| 50 save_results(some_id, 'dummy_value') |
| 51 |
| 52 if __name__ == '__main__': |
| 53 sys.exit(main()) # pragma: no cover |
| OLD | NEW |