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 | |
Ian Zerny | f271e8d | 2023-09-11 12:30:41 +0200 | [diff] [blame] | 11 | CHOICES = ["all", "failing", "past-failing", "outstanding"] |
| 12 | DEFAULT_REPORTS_ROOT = os.path.join(utils.BUILD, "testing-state") |
| 13 | |
| 14 | def set_up_test_state(gradle_args, testing_state_mode, testing_state_path): |
| 15 | if not testing_state_mode: |
| 16 | return |
Ian Zerny | 9f0345d | 2023-09-07 11:15:00 +0200 | [diff] [blame] | 17 | if not testing_state_path: |
Ian Zerny | f271e8d | 2023-09-11 12:30:41 +0200 | [diff] [blame] | 18 | testing_state_path = os.path.join(DEFAULT_REPORTS_ROOT, utils.get_HEAD_branch()) |
| 19 | gradle_args.append('-Ptesting-state-mode=%s' % testing_state_mode) |
| 20 | gradle_args.append('-Ptesting-state-path=%s' % testing_state_path) |
| 21 | prepare_testing_index(testing_state_mode, testing_state_path) |
Ian Zerny | 9f0345d | 2023-09-07 11:15:00 +0200 | [diff] [blame] | 22 | |
| 23 | def fresh_testing_index(testing_state_dir): |
| 24 | number = 0 |
| 25 | while True: |
| 26 | freshIndex = os.path.join(testing_state_dir, "index.%d.html" % number) |
| 27 | number += 1 |
| 28 | if not os.path.exists(freshIndex): |
| 29 | return freshIndex |
| 30 | |
Ian Zerny | f271e8d | 2023-09-11 12:30:41 +0200 | [diff] [blame] | 31 | def prepare_testing_index(testing_state_mode, testing_state_dir): |
Ian Zerny | 9f0345d | 2023-09-07 11:15:00 +0200 | [diff] [blame] | 32 | if not os.path.exists(testing_state_dir): |
| 33 | os.makedirs(testing_state_dir) |
| 34 | index_path = os.path.join(testing_state_dir, "index.html") |
| 35 | parent_report = None |
| 36 | resuming = os.path.exists(index_path) |
Ian Zerny | f271e8d | 2023-09-11 12:30:41 +0200 | [diff] [blame] | 37 | mode = testing_state_mode if resuming else f"starting (flag: {testing_state_mode})" |
Ian Zerny | 9f0345d | 2023-09-07 11:15:00 +0200 | [diff] [blame] | 38 | if (resuming): |
| 39 | parent_report = fresh_testing_index(testing_state_dir) |
| 40 | os.rename(index_path, parent_report) |
| 41 | index = open(index_path, "a") |
Ian Zerny | 9f0345d | 2023-09-07 11:15:00 +0200 | [diff] [blame] | 42 | relative_state_dir = os.path.relpath(testing_state_dir) |
Ian Zerny | f271e8d | 2023-09-11 12:30:41 +0200 | [diff] [blame] | 43 | title = relative_state_dir |
Ian Zerny | 9f0345d | 2023-09-07 11:15:00 +0200 | [diff] [blame] | 44 | # Print a console link to the test report for easy access. |
| 45 | print("=" * 70) |
Ian Zerny | f271e8d | 2023-09-11 12:30:41 +0200 | [diff] [blame] | 46 | print("Test report written to:") |
Ian Zerny | 9f0345d | 2023-09-07 11:15:00 +0200 | [diff] [blame] | 47 | print(f" file://{index_path}") |
| 48 | print("=" * 70) |
| 49 | # Print the new index content. |
| 50 | index.write(f"<html><head><title>{title}</title>") |
| 51 | index.write("<style> * { font-family: monospace; }</style>") |
| 52 | index.write("<meta http-equiv='refresh' content='10' />") |
| 53 | index.write(f"</head><body><h1>{title}</h1>") |
Ian Zerny | f271e8d | 2023-09-11 12:30:41 +0200 | [diff] [blame] | 54 | index.write(f"<h2>Mode: {mode}</h2>") |
Ian Zerny | 9f0345d | 2023-09-07 11:15:00 +0200 | [diff] [blame] | 55 | # write index links first to avoid jumping when browsing. |
| 56 | if parent_report: |
| 57 | index.write(f"<p><a href=\"file://{parent_report}\">Previous result index</a></p>") |
| 58 | index.write(f"<p><a href=\"file://{index_path}\">Most recent result index</a></p>") |
| 59 | index.write(f"<p><a href=\"file://{testing_state_dir}\">Test directories</a></p>") |
| 60 | # git branch/hash and diff for future reference |
| 61 | index.write(f"<p>Run on: {datetime.datetime.now()}</p>") |
| 62 | index.write(f"<p>Git branch: {utils.get_HEAD_branch()}") |
| 63 | index.write(f"</br>Git SHA: {utils.get_HEAD_sha1()}") |
| 64 | index.write(f'</br>Git diff summary:\n') |
| 65 | index.write(f'<pre style="background-color: lightgray">{utils.get_HEAD_diff_stat()}</pre></p>') |
| 66 | # header for the failing tests |
| 67 | index.write("<h2>Failing tests (refreshing automatically every 10 seconds)</h2><ul>") |