Ian Zerny | 9f0345d | 2023-09-07 11:15:00 +0200 | [diff] [blame^] | 1 | #!/usr/bin/env python3 |
| 2 | # Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file |
| 3 | # for details. All rights reserved. Use of this source code is governed by a |
| 4 | # BSD-style license that can be found in the LICENSE file. |
| 5 | |
| 6 | import utils |
| 7 | |
| 8 | import datetime |
| 9 | import os |
| 10 | |
| 11 | def set_up_test_state(gradle_args, testing_state_path): |
| 12 | # In the new build the test state directory must be passed explictitly. |
| 13 | # TODO(b/297316723): Simplify this and just support a single flag: --testing-state <path> |
| 14 | if not testing_state_path: |
| 15 | testing_state_path = "%s/test-state/%s" % (utils.BUILD, utils.get_HEAD_branch()) |
| 16 | gradle_args.append('-Ptesting-state=%s' % testing_state_path) |
| 17 | prepare_testing_index(testing_state_path) |
| 18 | |
| 19 | def fresh_testing_index(testing_state_dir): |
| 20 | number = 0 |
| 21 | while True: |
| 22 | freshIndex = os.path.join(testing_state_dir, "index.%d.html" % number) |
| 23 | number += 1 |
| 24 | if not os.path.exists(freshIndex): |
| 25 | return freshIndex |
| 26 | |
| 27 | def prepare_testing_index(testing_state_dir): |
| 28 | if not os.path.exists(testing_state_dir): |
| 29 | os.makedirs(testing_state_dir) |
| 30 | index_path = os.path.join(testing_state_dir, "index.html") |
| 31 | parent_report = None |
| 32 | resuming = os.path.exists(index_path) |
| 33 | if (resuming): |
| 34 | parent_report = fresh_testing_index(testing_state_dir) |
| 35 | os.rename(index_path, parent_report) |
| 36 | index = open(index_path, "a") |
| 37 | run_prefix = "Resuming" if resuming else "Starting" |
| 38 | relative_state_dir = os.path.relpath(testing_state_dir) |
| 39 | title = f"{run_prefix} @ {relative_state_dir}" |
| 40 | # Print a console link to the test report for easy access. |
| 41 | print("=" * 70) |
| 42 | print(f"{run_prefix} test, report written to:") |
| 43 | print(f" file://{index_path}") |
| 44 | print("=" * 70) |
| 45 | # Print the new index content. |
| 46 | index.write(f"<html><head><title>{title}</title>") |
| 47 | index.write("<style> * { font-family: monospace; }</style>") |
| 48 | index.write("<meta http-equiv='refresh' content='10' />") |
| 49 | index.write(f"</head><body><h1>{title}</h1>") |
| 50 | # write index links first to avoid jumping when browsing. |
| 51 | if parent_report: |
| 52 | index.write(f"<p><a href=\"file://{parent_report}\">Previous result index</a></p>") |
| 53 | index.write(f"<p><a href=\"file://{index_path}\">Most recent result index</a></p>") |
| 54 | index.write(f"<p><a href=\"file://{testing_state_dir}\">Test directories</a></p>") |
| 55 | # git branch/hash and diff for future reference |
| 56 | index.write(f"<p>Run on: {datetime.datetime.now()}</p>") |
| 57 | index.write(f"<p>Git branch: {utils.get_HEAD_branch()}") |
| 58 | index.write(f"</br>Git SHA: {utils.get_HEAD_sha1()}") |
| 59 | index.write(f'</br>Git diff summary:\n') |
| 60 | index.write(f'<pre style="background-color: lightgray">{utils.get_HEAD_diff_stat()}</pre></p>') |
| 61 | # header for the failing tests |
| 62 | index.write("<h2>Failing tests (refreshing automatically every 10 seconds)</h2><ul>") |