blob: 6cda6ca66693cea76975f3d4b88b262904079ad3 [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())
Ian Zerny992ce742023-09-13 09:29:58 +020019 testing_state_path = os.path.abspath(testing_state_path)
Ian Zernyf271e8d2023-09-11 12:30:41 +020020 gradle_args.append('-Ptesting-state-mode=%s' % testing_state_mode)
21 gradle_args.append('-Ptesting-state-path=%s' % testing_state_path)
22 prepare_testing_index(testing_state_mode, testing_state_path)
Ian Zerny9f0345d2023-09-07 11:15:00 +020023
24def fresh_testing_index(testing_state_dir):
25 number = 0
26 while True:
27 freshIndex = os.path.join(testing_state_dir, "index.%d.html" % number)
28 number += 1
29 if not os.path.exists(freshIndex):
30 return freshIndex
31
Ian Zernyf271e8d2023-09-11 12:30:41 +020032def prepare_testing_index(testing_state_mode, testing_state_dir):
Ian Zerny9f0345d2023-09-07 11:15:00 +020033 if not os.path.exists(testing_state_dir):
34 os.makedirs(testing_state_dir)
35 index_path = os.path.join(testing_state_dir, "index.html")
36 parent_report = None
37 resuming = os.path.exists(index_path)
Ian Zernyf271e8d2023-09-11 12:30:41 +020038 mode = testing_state_mode if resuming else f"starting (flag: {testing_state_mode})"
Ian Zerny9f0345d2023-09-07 11:15:00 +020039 if (resuming):
40 parent_report = fresh_testing_index(testing_state_dir)
41 os.rename(index_path, parent_report)
42 index = open(index_path, "a")
Ian Zerny992ce742023-09-13 09:29:58 +020043 title = f"Testing: {os.path.basename(testing_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>")
Ian Zerny992ce742023-09-13 09:29:58 +020062 index.write(f"<p>State path: {testing_state_dir}</p>")
Ian Zerny9f0345d2023-09-07 11:15:00 +020063 index.write(f"<p>Git branch: {utils.get_HEAD_branch()}")
64 index.write(f"</br>Git SHA: {utils.get_HEAD_sha1()}")
65 index.write(f'</br>Git diff summary:\n')
66 index.write(f'<pre style="background-color: lightgray">{utils.get_HEAD_diff_stat()}</pre></p>')
67 # header for the failing tests
68 index.write("<h2>Failing tests (refreshing automatically every 10 seconds)</h2><ul>")