[llvm] [llvm][llvm-lit] Add option to create unique result file names if results already exist (PR #112729)

David Spickett via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 21 02:42:37 PDT 2024


https://github.com/DavidSpickett updated https://github.com/llvm/llvm-project/pull/112729

>From f212fdae4d24e15cc7f8a4b55d0853d347a8fa7b Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Thu, 17 Oct 2024 14:17:19 +0000
Subject: [PATCH 01/11] [llvm][llvm-lit] Add a base class for reports that are
 written to files

This is to later allow me to handle the choosing of the filename
in one place, so that we can write unique files across multiple
runs.
---
 llvm/utils/lit/lit/reports.py | 61 ++++++++++++++++++-----------------
 1 file changed, 31 insertions(+), 30 deletions(-)

diff --git a/llvm/utils/lit/lit/reports.py b/llvm/utils/lit/lit/reports.py
index 8ec83d698ae86a..b17f4d2460ed00 100755
--- a/llvm/utils/lit/lit/reports.py
+++ b/llvm/utils/lit/lit/reports.py
@@ -1,3 +1,4 @@
+import abc
 import base64
 import datetime
 import itertools
@@ -14,11 +15,22 @@ def by_suite_and_test_path(test):
     return (test.suite.name, id(test.suite), test.path_in_suite)
 
 
-class JsonReport(object):
+class Report(object):
     def __init__(self, output_file):
         self.output_file = output_file
 
     def write_results(self, tests, elapsed):
+        with open(self.output_file, "w") as file:
+            self._write_results_to_file(tests, elapsed, file)
+
+    @abc.abstractmethod
+    def _write_results_to_file(self, tests, elapsed, file):
+        """Write test results to the file object "file"."""
+        pass
+
+
+class JsonReport(Report):
+    def _write_results_to_file(self, tests, elapsed, file):
         unexecuted_codes = {lit.Test.EXCLUDED, lit.Test.SKIPPED}
         tests = [t for t in tests if t.result.code not in unexecuted_codes]
         # Construct the data we will write.
@@ -67,9 +79,8 @@ def write_results(self, tests, elapsed):
 
             tests_data.append(test_data)
 
-        with open(self.output_file, "w") as file:
-            json.dump(data, file, indent=2, sort_keys=True)
-            file.write("\n")
+        json.dump(data, file, indent=2, sort_keys=True)
+        file.write("\n")
 
 
 _invalid_xml_chars_dict = {
@@ -88,21 +99,18 @@ def remove_invalid_xml_chars(s):
     return s.translate(_invalid_xml_chars_dict)
 
 
-class XunitReport(object):
-    def __init__(self, output_file):
-        self.output_file = output_file
-        self.skipped_codes = {lit.Test.EXCLUDED, lit.Test.SKIPPED, lit.Test.UNSUPPORTED}
+class XunitReport(Report):
+    skipped_codes = {lit.Test.EXCLUDED, lit.Test.SKIPPED, lit.Test.UNSUPPORTED}
 
-    def write_results(self, tests, elapsed):
+    def _write_results_to_file(self, tests, elapsed, file):
         tests.sort(key=by_suite_and_test_path)
         tests_by_suite = itertools.groupby(tests, lambda t: t.suite)
 
-        with open(self.output_file, "w") as file:
-            file.write('<?xml version="1.0" encoding="UTF-8"?>\n')
-            file.write('<testsuites time="{time:.2f}">\n'.format(time=elapsed))
-            for suite, test_iter in tests_by_suite:
-                self._write_testsuite(file, suite, list(test_iter))
-            file.write("</testsuites>\n")
+        file.write('<?xml version="1.0" encoding="UTF-8"?>\n')
+        file.write('<testsuites time="{time:.2f}">\n'.format(time=elapsed))
+        for suite, test_iter in tests_by_suite:
+            self._write_testsuite(file, suite, list(test_iter))
+        file.write("</testsuites>\n")
 
     def _write_testsuite(self, file, suite, tests):
         skipped = 0
@@ -206,11 +214,8 @@ def gen_resultdb_test_entry(
     return test_data
 
 
-class ResultDBReport(object):
-    def __init__(self, output_file):
-        self.output_file = output_file
-
-    def write_results(self, tests, elapsed):
+class ResultDBReport(Report):
+    def _write_results_to_file(self, tests, elapsed, file):
         unexecuted_codes = {lit.Test.EXCLUDED, lit.Test.SKIPPED}
         tests = [t for t in tests if t.result.code not in unexecuted_codes]
         data = {}
@@ -249,17 +254,14 @@ def write_results(self, tests, elapsed):
                         )
                     )
 
-        with open(self.output_file, "w") as file:
-            json.dump(data, file, indent=2, sort_keys=True)
-            file.write("\n")
+        json.dump(data, file, indent=2, sort_keys=True)
+        file.write("\n")
 
 
-class TimeTraceReport(object):
-    def __init__(self, output_file):
-        self.output_file = output_file
-        self.skipped_codes = {lit.Test.EXCLUDED, lit.Test.SKIPPED, lit.Test.UNSUPPORTED}
+class TimeTraceReport(Report):
+    skipped_codes = {lit.Test.EXCLUDED, lit.Test.SKIPPED, lit.Test.UNSUPPORTED}
 
-    def write_results(self, tests, elapsed):
+    def _write_results_to_file(self, tests, elapsed, file):
         # Find when first test started so we can make start times relative.
         first_start_time = min([t.result.start for t in tests])
         events = [
@@ -270,8 +272,7 @@ def write_results(self, tests, elapsed):
 
         json_data = {"traceEvents": events}
 
-        with open(self.output_file, "w") as time_trace_file:
-            json.dump(json_data, time_trace_file, indent=2, sort_keys=True)
+        json.dump(json_data, time_trace_file, indent=2, sort_keys=True)
 
     def _get_test_event(self, test, first_start_time):
         test_name = test.getFullName()

>From 26f5f34776f46f22ae052f6d1b69def1abf0f96a Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Thu, 17 Oct 2024 14:35:01 +0000
Subject: [PATCH 02/11] [llvm][llvm-lit] Add option to create unique result
 file names if results already exist

When running a build like:
ninja check-clang check-llvm

Prior to my changes you ended up with one results file, in this specific case
Junit XML:
results.xml

This would only include the last set of tests lit ran, which were for llvm.
To get around this, many CI systems will run one check target, move the file
away, then run another.

for target in targets:
  ninja target
  mv results.xml results-${target}.xml

I want to use something like this Buildkite reporting plugin in CI,
which needs to have all the results available:
https://buildkite.com/docs/agent/v3/cli-annotate#using-annotations-to-report-test-results

Modifying CI's build scripts for Windows and Linux is a lot of work.
So my changes instead make lit detect an existing result file and modify the file name
until it finds a unique file name to write to.

Now you will get:
results.xml results.1.xml

This will work for all result file types since I'm doing it in the base Report
class. Now you've got separate files, it's easy to collect them with `<path>/*.xml`.

The number will increment as many times as needed until a useable name
is found.
---
 llvm/utils/lit/lit/cl_arguments.py         | 28 +++++++++++++++-------
 llvm/utils/lit/lit/reports.py              | 26 ++++++++++++++++++--
 llvm/utils/lit/tests/unique-output-file.py | 28 ++++++++++++++++++++++
 3 files changed, 72 insertions(+), 10 deletions(-)
 create mode 100644 llvm/utils/lit/tests/unique-output-file.py

diff --git a/llvm/utils/lit/lit/cl_arguments.py b/llvm/utils/lit/lit/cl_arguments.py
index 5ccae4be096796..3b11342dec2162 100644
--- a/llvm/utils/lit/lit/cl_arguments.py
+++ b/llvm/utils/lit/lit/cl_arguments.py
@@ -175,6 +175,13 @@ def parse_args():
         type=lit.reports.TimeTraceReport,
         help="Write Chrome tracing compatible JSON to the specified file",
     )
+    execution_group.add_argument(
+        "--use-unique-output-file-name",
+        help="When enabled, lit will not overwrite existing test report files. "
+        "Instead it will modify the file name until it finds a file name "
+        "that does not already exist. [Default: Off]",
+        action="store_true",
+    )
     execution_group.add_argument(
         "--timeout",
         dest="maxIndividualTestTime",
@@ -332,16 +339,21 @@ def parse_args():
     else:
         opts.shard = None
 
-    opts.reports = filter(
-        None,
-        [
-            opts.output,
-            opts.xunit_xml_output,
-            opts.resultdb_output,
-            opts.time_trace_output,
-        ],
+    opts.reports = list(
+        filter(
+            None,
+            [
+                opts.output,
+                opts.xunit_xml_output,
+                opts.resultdb_output,
+                opts.time_trace_output,
+            ],
+        )
     )
 
+    for report in opts.reports:
+        report.use_unique_output_file_name = opts.use_unique_output_file_name
+
     return opts
 
 
diff --git a/llvm/utils/lit/lit/reports.py b/llvm/utils/lit/lit/reports.py
index b17f4d2460ed00..45891d7156e011 100755
--- a/llvm/utils/lit/lit/reports.py
+++ b/llvm/utils/lit/lit/reports.py
@@ -3,6 +3,7 @@
 import datetime
 import itertools
 import json
+import os
 
 from xml.sax.saxutils import quoteattr as quo
 
@@ -18,10 +19,31 @@ def by_suite_and_test_path(test):
 class Report(object):
     def __init__(self, output_file):
         self.output_file = output_file
+        # Set by the option parser later.
+        self.use_unique_output_file_name = False
 
     def write_results(self, tests, elapsed):
-        with open(self.output_file, "w") as file:
-            self._write_results_to_file(tests, elapsed, file)
+        if self.use_unique_output_file_name:
+            file = None
+            filepath = self.output_file
+            attempt = 0
+            while file is None:
+                try:
+                    file = open(filepath, "x")
+                except FileExistsError:
+                    attempt += 1
+                    # If there is an extension insert before that because most
+                    # glob patterns for these will be '*.extension'. Otherwise
+                    # add to the end of the path.
+                    path, ext = os.path.splitext(self.output_file)
+                    filepath = path + f".{attempt}" + ext
+
+            with file:
+                self._write_results_to_file(tests, elapsed, file)
+        else:
+            # Overwrite if the results already exist.
+            with open(self.output_file, "w") as file:
+                self._write_results_to_file(tests, elapsed, file)
 
     @abc.abstractmethod
     def _write_results_to_file(self, tests, elapsed, file):
diff --git a/llvm/utils/lit/tests/unique-output-file.py b/llvm/utils/lit/tests/unique-output-file.py
new file mode 100644
index 00000000000000..e0ce21aebf6950
--- /dev/null
+++ b/llvm/utils/lit/tests/unique-output-file.py
@@ -0,0 +1,28 @@
+# Check that lit will not overwrite existing result files when given
+# --use-unique-output-file-name.
+
+# Files are overwritten without the option.
+# RUN: rm -rf %t.xunit*.xml
+# RUN: echo "test" > %t.xunit.xml
+# RUN: not %{lit} --xunit-xml-output %t.xunit.xml %{inputs}/xunit-output
+# RUN: FileCheck < %t.xunit.xml %s --check-prefix=NEW
+
+# RUN: rm -rf %t.xunit*.xml
+# RUN: echo "test" > %t.xunit.xml
+# Files should not be overwritten with the option.
+# RUN: not %{lit} --xunit-xml-output %t.xunit.xml --use-unique-output-file-name %{inputs}/xunit-output
+# RUN: FileCheck < %t.xunit.xml %s --check-prefix=EXISTING
+# EXISTING: test
+# Results in a new file with "1" added.
+# RUN: FileCheck < %t.xunit.1.xml %s --check-prefix=NEW
+# NEW:      <?xml version="1.0" encoding="UTF-8"?>
+# NEW-NEXT: <testsuites time="{{[0-9.]+}}">
+# (assuming that other tests check the whole contents of the file)
+
+# The number should increment as many times as needed.
+# RUN: touch %t.xunit.2.xml
+# RUN: touch %t.xunit.3.xml
+# RUN: touch %t.xunit.4.xml
+
+# RUN: not %{lit} --xunit-xml-output %t.xunit.xml --use-unique-output-file-name %{inputs}/xunit-output
+# RUN: FileCheck < %t.xunit.5.xml %s --check-prefix=NEW
\ No newline at end of file

>From 117636b09ee059f33cabe8a4e5d27706fb2a0611 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Thu, 17 Oct 2024 15:36:43 +0000
Subject: [PATCH 03/11] don't need to recurse rm

---
 llvm/utils/lit/tests/unique-output-file.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/utils/lit/tests/unique-output-file.py b/llvm/utils/lit/tests/unique-output-file.py
index e0ce21aebf6950..62e980cc90cd68 100644
--- a/llvm/utils/lit/tests/unique-output-file.py
+++ b/llvm/utils/lit/tests/unique-output-file.py
@@ -2,12 +2,12 @@
 # --use-unique-output-file-name.
 
 # Files are overwritten without the option.
-# RUN: rm -rf %t.xunit*.xml
+# RUN: rm -f %t.xunit*.xml
 # RUN: echo "test" > %t.xunit.xml
 # RUN: not %{lit} --xunit-xml-output %t.xunit.xml %{inputs}/xunit-output
 # RUN: FileCheck < %t.xunit.xml %s --check-prefix=NEW
 
-# RUN: rm -rf %t.xunit*.xml
+# RUN: rm -f %t.xunit*.xml
 # RUN: echo "test" > %t.xunit.xml
 # Files should not be overwritten with the option.
 # RUN: not %{lit} --xunit-xml-output %t.xunit.xml --use-unique-output-file-name %{inputs}/xunit-output

>From 6a54a5ae842b625cb15a871670bbb93b3af80b2d Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Thu, 17 Oct 2024 15:46:29 +0000
Subject: [PATCH 04/11] give an example in the help

---
 llvm/utils/lit/lit/cl_arguments.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/llvm/utils/lit/lit/cl_arguments.py b/llvm/utils/lit/lit/cl_arguments.py
index 3b11342dec2162..1306dbec6a9a3c 100644
--- a/llvm/utils/lit/lit/cl_arguments.py
+++ b/llvm/utils/lit/lit/cl_arguments.py
@@ -179,7 +179,11 @@ def parse_args():
         "--use-unique-output-file-name",
         help="When enabled, lit will not overwrite existing test report files. "
         "Instead it will modify the file name until it finds a file name "
-        "that does not already exist. [Default: Off]",
+        "that does not already exist. An incrementing number starting from 1 "
+        "will be added prior to the file extension, or for files without an "
+        "extension, on the end of the fle name. For example, if 'results.xml' "
+        "already exists, 'results.1.xml' will be used instead, if that exists, "
+        "'results.2.xml' and so on. [Default: Off]",
         action="store_true",
     )
     execution_group.add_argument(

>From 66c0c67a4b474a59b00276d5553193efdf90aabc Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Fri, 18 Oct 2024 09:56:04 +0000
Subject: [PATCH 05/11] cleanup test

---
 llvm/utils/lit/tests/unique-output-file.py | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/llvm/utils/lit/tests/unique-output-file.py b/llvm/utils/lit/tests/unique-output-file.py
index 62e980cc90cd68..aaa6326e043e98 100644
--- a/llvm/utils/lit/tests/unique-output-file.py
+++ b/llvm/utils/lit/tests/unique-output-file.py
@@ -1,7 +1,7 @@
-# Check that lit will not overwrite existing result files when given
-# --use-unique-output-file-name.
+## Check that lit will not overwrite existing result files when given
+## --use-unique-output-file-name.
 
-# Files are overwritten without the option.
+## Files are overwritten without the option.
 # RUN: rm -f %t.xunit*.xml
 # RUN: echo "test" > %t.xunit.xml
 # RUN: not %{lit} --xunit-xml-output %t.xunit.xml %{inputs}/xunit-output
@@ -9,20 +9,18 @@
 
 # RUN: rm -f %t.xunit*.xml
 # RUN: echo "test" > %t.xunit.xml
-# Files should not be overwritten with the option.
+## Files should not be overwritten with the option.
 # RUN: not %{lit} --xunit-xml-output %t.xunit.xml --use-unique-output-file-name %{inputs}/xunit-output
 # RUN: FileCheck < %t.xunit.xml %s --check-prefix=EXISTING
 # EXISTING: test
-# Results in a new file with "1" added.
+## Results in a new file with "1" added.
 # RUN: FileCheck < %t.xunit.1.xml %s --check-prefix=NEW
 # NEW:      <?xml version="1.0" encoding="UTF-8"?>
 # NEW-NEXT: <testsuites time="{{[0-9.]+}}">
-# (assuming that other tests check the whole contents of the file)
+## (assuming that other tests check the whole contents of the file)
 
-# The number should increment as many times as needed.
-# RUN: touch %t.xunit.2.xml
-# RUN: touch %t.xunit.3.xml
-# RUN: touch %t.xunit.4.xml
+## The number should increment as many times as needed.
+# RUN: touch %t.xunit.2.xml %t.xunit.3.xml %t.xunit.4.xml
 
 # RUN: not %{lit} --xunit-xml-output %t.xunit.xml --use-unique-output-file-name %{inputs}/xunit-output
 # RUN: FileCheck < %t.xunit.5.xml %s --check-prefix=NEW
\ No newline at end of file

>From 8ee1c44dbd317d193b2002d70e9c2712e2a9104e Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Fri, 18 Oct 2024 10:00:46 +0000
Subject: [PATCH 06/11] Refactor file opening

---
 llvm/utils/lit/lit/reports.py | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/llvm/utils/lit/lit/reports.py b/llvm/utils/lit/lit/reports.py
index 45891d7156e011..4a25c64c6327c8 100755
--- a/llvm/utils/lit/lit/reports.py
+++ b/llvm/utils/lit/lit/reports.py
@@ -24,12 +24,12 @@ def __init__(self, output_file):
 
     def write_results(self, tests, elapsed):
         if self.use_unique_output_file_name:
-            file = None
+            report_file = None
             filepath = self.output_file
             attempt = 0
-            while file is None:
+            while report_file is None:
                 try:
-                    file = open(filepath, "x")
+                    report_file = open(filepath, "x")
                 except FileExistsError:
                     attempt += 1
                     # If there is an extension insert before that because most
@@ -37,13 +37,12 @@ def write_results(self, tests, elapsed):
                     # add to the end of the path.
                     path, ext = os.path.splitext(self.output_file)
                     filepath = path + f".{attempt}" + ext
-
-            with file:
-                self._write_results_to_file(tests, elapsed, file)
         else:
             # Overwrite if the results already exist.
-            with open(self.output_file, "w") as file:
-                self._write_results_to_file(tests, elapsed, file)
+            report_file = open(self.output_file, "w")
+
+        with report_file:
+            self._write_results_to_file(tests, elapsed, report_file)
 
     @abc.abstractmethod
     def _write_results_to_file(self, tests, elapsed, file):

>From a202ecde7a612e42bc76069096b3687469d1444b Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Fri, 18 Oct 2024 10:01:33 +0000
Subject: [PATCH 07/11] newline at EOF

---
 llvm/utils/lit/tests/unique-output-file.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/utils/lit/tests/unique-output-file.py b/llvm/utils/lit/tests/unique-output-file.py
index aaa6326e043e98..a9f13c404ce102 100644
--- a/llvm/utils/lit/tests/unique-output-file.py
+++ b/llvm/utils/lit/tests/unique-output-file.py
@@ -23,4 +23,4 @@
 # RUN: touch %t.xunit.2.xml %t.xunit.3.xml %t.xunit.4.xml
 
 # RUN: not %{lit} --xunit-xml-output %t.xunit.xml --use-unique-output-file-name %{inputs}/xunit-output
-# RUN: FileCheck < %t.xunit.5.xml %s --check-prefix=NEW
\ No newline at end of file
+# RUN: FileCheck < %t.xunit.5.xml %s --check-prefix=NEW

>From a9f802dfc6176056b24f5377765558d9316af8cd Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Fri, 18 Oct 2024 10:18:11 +0000
Subject: [PATCH 08/11] use templfile instead of incrementing number

---
 llvm/utils/lit/lit/cl_arguments.py         |  8 ++------
 llvm/utils/lit/lit/reports.py              | 19 ++++++-------------
 llvm/utils/lit/tests/unique-output-file.py | 16 +++++-----------
 3 files changed, 13 insertions(+), 30 deletions(-)

diff --git a/llvm/utils/lit/lit/cl_arguments.py b/llvm/utils/lit/lit/cl_arguments.py
index 1306dbec6a9a3c..c24054b2c34f34 100644
--- a/llvm/utils/lit/lit/cl_arguments.py
+++ b/llvm/utils/lit/lit/cl_arguments.py
@@ -178,12 +178,8 @@ def parse_args():
     execution_group.add_argument(
         "--use-unique-output-file-name",
         help="When enabled, lit will not overwrite existing test report files. "
-        "Instead it will modify the file name until it finds a file name "
-        "that does not already exist. An incrementing number starting from 1 "
-        "will be added prior to the file extension, or for files without an "
-        "extension, on the end of the fle name. For example, if 'results.xml' "
-        "already exists, 'results.1.xml' will be used instead, if that exists, "
-        "'results.2.xml' and so on. [Default: Off]",
+        "Instead it will write to a new file named the same as the output file "
+        "name but with a extra part before the file extension. [Default: Off]",
         action="store_true",
     )
     execution_group.add_argument(
diff --git a/llvm/utils/lit/lit/reports.py b/llvm/utils/lit/lit/reports.py
index 4a25c64c6327c8..8312dcddc769ae 100755
--- a/llvm/utils/lit/lit/reports.py
+++ b/llvm/utils/lit/lit/reports.py
@@ -4,6 +4,7 @@
 import itertools
 import json
 import os
+import tempfile
 
 from xml.sax.saxutils import quoteattr as quo
 
@@ -24,19 +25,11 @@ def __init__(self, output_file):
 
     def write_results(self, tests, elapsed):
         if self.use_unique_output_file_name:
-            report_file = None
-            filepath = self.output_file
-            attempt = 0
-            while report_file is None:
-                try:
-                    report_file = open(filepath, "x")
-                except FileExistsError:
-                    attempt += 1
-                    # If there is an extension insert before that because most
-                    # glob patterns for these will be '*.extension'. Otherwise
-                    # add to the end of the path.
-                    path, ext = os.path.splitext(self.output_file)
-                    filepath = path + f".{attempt}" + ext
+            filename, ext = os.path.splitext(os.path.basename(self.output_file))
+            fd, _ = tempfile.mkstemp(
+                suffix=ext, prefix=f"{filename}.", dir=os.path.dirname(self.output_file)
+            )
+            report_file = os.fdopen(fd, "w")
         else:
             # Overwrite if the results already exist.
             report_file = open(self.output_file, "w")
diff --git a/llvm/utils/lit/tests/unique-output-file.py b/llvm/utils/lit/tests/unique-output-file.py
index a9f13c404ce102..fbdafeb7dee10f 100644
--- a/llvm/utils/lit/tests/unique-output-file.py
+++ b/llvm/utils/lit/tests/unique-output-file.py
@@ -6,6 +6,9 @@
 # RUN: echo "test" > %t.xunit.xml
 # RUN: not %{lit} --xunit-xml-output %t.xunit.xml %{inputs}/xunit-output
 # RUN: FileCheck < %t.xunit.xml %s --check-prefix=NEW
+# NEW:      <?xml version="1.0" encoding="UTF-8"?>
+# NEW-NEXT: <testsuites time="{{[0-9.]+}}">
+## (other tests will check the contents of the whole file)
 
 # RUN: rm -f %t.xunit*.xml
 # RUN: echo "test" > %t.xunit.xml
@@ -13,14 +16,5 @@
 # RUN: not %{lit} --xunit-xml-output %t.xunit.xml --use-unique-output-file-name %{inputs}/xunit-output
 # RUN: FileCheck < %t.xunit.xml %s --check-prefix=EXISTING
 # EXISTING: test
-## Results in a new file with "1" added.
-# RUN: FileCheck < %t.xunit.1.xml %s --check-prefix=NEW
-# NEW:      <?xml version="1.0" encoding="UTF-8"?>
-# NEW-NEXT: <testsuites time="{{[0-9.]+}}">
-## (assuming that other tests check the whole contents of the file)
-
-## The number should increment as many times as needed.
-# RUN: touch %t.xunit.2.xml %t.xunit.3.xml %t.xunit.4.xml
-
-# RUN: not %{lit} --xunit-xml-output %t.xunit.xml --use-unique-output-file-name %{inputs}/xunit-output
-# RUN: FileCheck < %t.xunit.5.xml %s --check-prefix=NEW
+## Results in a new file with some discriminator added.
+# RUN: FileCheck < %t.xunit.*.xml %s --check-prefix=NEW

>From cefa5770ca680a3e34b3ec723dea1bad582f381a Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Fri, 18 Oct 2024 10:29:25 +0000
Subject: [PATCH 09/11] example in help

---
 llvm/utils/lit/lit/cl_arguments.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/llvm/utils/lit/lit/cl_arguments.py b/llvm/utils/lit/lit/cl_arguments.py
index c24054b2c34f34..f3efcb380c1e08 100644
--- a/llvm/utils/lit/lit/cl_arguments.py
+++ b/llvm/utils/lit/lit/cl_arguments.py
@@ -179,7 +179,9 @@ def parse_args():
         "--use-unique-output-file-name",
         help="When enabled, lit will not overwrite existing test report files. "
         "Instead it will write to a new file named the same as the output file "
-        "name but with a extra part before the file extension. [Default: Off]",
+        "name but with a extra part before the file extension. For example "
+        "if results.xml already exists, results.<something>.xml will be written "
+        "to. The <something> is not ordered in any way. [Default: Off]",
         action="store_true",
     )
     execution_group.add_argument(

>From b2796c7dd37cb1e586410f34883b64a2fbb43d6c Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Fri, 18 Oct 2024 14:28:47 +0000
Subject: [PATCH 10/11] typo fix

---
 llvm/utils/lit/lit/cl_arguments.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/utils/lit/lit/cl_arguments.py b/llvm/utils/lit/lit/cl_arguments.py
index f3efcb380c1e08..c08c51b7b7a23e 100644
--- a/llvm/utils/lit/lit/cl_arguments.py
+++ b/llvm/utils/lit/lit/cl_arguments.py
@@ -179,7 +179,7 @@ def parse_args():
         "--use-unique-output-file-name",
         help="When enabled, lit will not overwrite existing test report files. "
         "Instead it will write to a new file named the same as the output file "
-        "name but with a extra part before the file extension. For example "
+        "name but with an extra part before the file extension. For example "
         "if results.xml already exists, results.<something>.xml will be written "
         "to. The <something> is not ordered in any way. [Default: Off]",
         action="store_true",

>From 020f9a448d8805ecffe7f1e78dec1012659e4ea3 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Mon, 21 Oct 2024 09:41:32 +0000
Subject: [PATCH 11/11] precheck that there are only 2 xml files

---
 llvm/utils/lit/tests/unique-output-file.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/utils/lit/tests/unique-output-file.py b/llvm/utils/lit/tests/unique-output-file.py
index fbdafeb7dee10f..fea57682d9fdab 100644
--- a/llvm/utils/lit/tests/unique-output-file.py
+++ b/llvm/utils/lit/tests/unique-output-file.py
@@ -17,4 +17,6 @@
 # RUN: FileCheck < %t.xunit.xml %s --check-prefix=EXISTING
 # EXISTING: test
 ## Results in a new file with some discriminator added.
+# RUN: ls -l %t.xunit*.xml | wc -l | FileCheck %s --check-prefix=NUMFILES
+# NUMFILES: 2
 # RUN: FileCheck < %t.xunit.*.xml %s --check-prefix=NEW



More information about the llvm-commits mailing list