blob: b3a4ed4ee219e41829ea82c9a57053fc9c5deca0 [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
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020014
Ian Zernyf271e8d2023-09-11 12:30:41 +020015def set_up_test_state(gradle_args, testing_state_mode, testing_state_path):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020016 if not testing_state_mode:
17 return
18 if not testing_state_path:
19 testing_state_path = os.path.join(DEFAULT_REPORTS_ROOT,
20 utils.get_HEAD_branch())
21 testing_state_path = os.path.abspath(testing_state_path)
22 gradle_args.append('-Ptesting-state-mode=%s' % testing_state_mode)
23 gradle_args.append('-Ptesting-state-path=%s' % testing_state_path)
24 prepare_testing_index(testing_state_mode, testing_state_path)
25
Ian Zerny9f0345d2023-09-07 11:15:00 +020026
27def fresh_testing_index(testing_state_dir):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020028 number = 0
29 while True:
30 freshIndex = os.path.join(testing_state_dir, "index.%d.html" % number)
31 number += 1
32 if not os.path.exists(freshIndex):
33 return freshIndex
34
Ian Zerny9f0345d2023-09-07 11:15:00 +020035
Ian Zernyf271e8d2023-09-11 12:30:41 +020036def prepare_testing_index(testing_state_mode, testing_state_dir):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020037 if not os.path.exists(testing_state_dir):
38 os.makedirs(testing_state_dir)
39 index_path = os.path.join(testing_state_dir, "index.html")
40 parent_report = None
41 resuming = os.path.exists(index_path)
42 mode = testing_state_mode if resuming else f"starting (flag: {testing_state_mode})"
43 if (resuming):
44 parent_report = fresh_testing_index(testing_state_dir)
45 os.rename(index_path, parent_report)
46 index = open(index_path, "a")
47 title = f"Testing: {os.path.basename(testing_state_dir)}"
48 # Print a console link to the test report for easy access.
49 print("=" * 70)
50 print("Test report written to:")
51 print(f" file://{index_path}")
52 print("=" * 70)
53 # Print the new index content.
54 index.write(f"<html><head><title>{title}</title>")
55 index.write("<style> * { font-family: monospace; }</style>")
56 index.write("<meta http-equiv='refresh' content='10' />")
57 index.write(f"</head><body><h1>{title}</h1>")
58 index.write(f"<h2>Mode: {mode}</h2>")
59 # write index links first to avoid jumping when browsing.
60 if parent_report:
61 index.write(
62 f"<p><a href=\"file://{parent_report}\">Previous result index</a></p>"
63 )
64 index.write(
65 f"<p><a href=\"file://{index_path}\">Most recent result index</a></p>")
66 index.write(
67 f"<p><a href=\"file://{testing_state_dir}\">Test directories</a></p>")
68 # git branch/hash and diff for future reference
69 index.write(f"<p>Run on: {datetime.datetime.now()}</p>")
70 index.write(f"<p>State path: {testing_state_dir}</p>")
71 index.write(f"<p>Git branch: {utils.get_HEAD_branch()}")
72 index.write(f"</br>Git SHA: {utils.get_HEAD_sha1()}")
73 index.write(f'</br>Git diff summary:\n')
74 index.write(
75 f'<pre style="background-color: lightgray">{utils.get_HEAD_diff_stat()}</pre></p>'
76 )
77 # header for the failing tests
78 index.write(
79 "<h2>Failing tests (refreshing automatically every 10 seconds)</h2><ul>"
80 )