blob: 7c51790c64f97d396b86a1586cb01c67f955cc27 [file] [log] [blame]
Ian Zerny9f0345d2023-09-07 11:15:00 +02001#!/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
6import utils
7
8import datetime
9import os
10
Ian Zernyf271e8d2023-09-11 12:30:41 +020011CHOICES = ["all", "failing", "past-failing", "outstanding"]
12DEFAULT_REPORTS_ROOT = os.path.join(utils.BUILD, "testing-state")
13
14def set_up_test_state(gradle_args, testing_state_mode, testing_state_path):
15 if not testing_state_mode:
16 return
Ian Zerny9f0345d2023-09-07 11:15:00 +020017 if not testing_state_path:
Ian Zernyf271e8d2023-09-11 12:30:41 +020018 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 Zerny9f0345d2023-09-07 11:15:00 +020022
23def 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 Zernyf271e8d2023-09-11 12:30:41 +020031def prepare_testing_index(testing_state_mode, testing_state_dir):
Ian Zerny9f0345d2023-09-07 11:15:00 +020032 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 Zernyf271e8d2023-09-11 12:30:41 +020037 mode = testing_state_mode if resuming else f"starting (flag: {testing_state_mode})"
Ian Zerny9f0345d2023-09-07 11:15:00 +020038 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 Zerny9f0345d2023-09-07 11:15:00 +020042 relative_state_dir = os.path.relpath(testing_state_dir)
Ian Zernyf271e8d2023-09-11 12:30:41 +020043 title = relative_state_dir
Ian Zerny9f0345d2023-09-07 11:15:00 +020044 # Print a console link to the test report for easy access.
45 print("=" * 70)
Ian Zernyf271e8d2023-09-11 12:30:41 +020046 print("Test report written to:")
Ian Zerny9f0345d2023-09-07 11:15:00 +020047 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 Zernyf271e8d2023-09-11 12:30:41 +020054 index.write(f"<h2>Mode: {mode}</h2>")
Ian Zerny9f0345d2023-09-07 11:15:00 +020055 # 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>")