[llvm] r315697 - lit.py: Add new %{shared_output(LABEL)} substitution
Jordan Rose via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 13 09:12:23 PDT 2017
Author: jrose
Date: Fri Oct 13 09:12:23 2017
New Revision: 315697
URL: http://llvm.org/viewvc/llvm-project?rev=315697&view=rev
Log:
lit.py: Add new %{shared_output(LABEL)} substitution
This refers to a temporary path that can be shared across all tests,
identified by a particular label. This can be used for things like
caches.
At the moment, the character set for the LABEL is limited to C
identifier characters, plus '-', '+', '=', and '.'. This is the same
set of characters currently allowed in REQUIRES clause identifiers.
Added:
llvm/trunk/utils/lit/tests/Inputs/shared-output/
llvm/trunk/utils/lit/tests/Inputs/shared-output/lit.cfg
llvm/trunk/utils/lit/tests/Inputs/shared-output/primary.txt
llvm/trunk/utils/lit/tests/Inputs/shared-output/secondary.txt
llvm/trunk/utils/lit/tests/Inputs/shared-output/sub/
llvm/trunk/utils/lit/tests/Inputs/shared-output/sub/sub.txt
llvm/trunk/utils/lit/tests/shared-output.py
Modified:
llvm/trunk/docs/CommandGuide/lit.rst
llvm/trunk/docs/TestingGuide.rst
llvm/trunk/utils/lit/lit/TestRunner.py
llvm/trunk/utils/lit/lit/run.py
Modified: llvm/trunk/docs/CommandGuide/lit.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/lit.rst?rev=315697&r1=315696&r2=315697&view=diff
==============================================================================
--- llvm/trunk/docs/CommandGuide/lit.rst (original)
+++ llvm/trunk/docs/CommandGuide/lit.rst Fri Oct 13 09:12:23 2017
@@ -395,17 +395,18 @@ PRE-DEFINED SUBSTITUTIONS
:program:`lit` provides various patterns that can be used with the RUN command.
These are defined in TestRunner.py. The base set of substitutions are:
- ========== ==============
- Macro Substitution
- ========== ==============
- %s source path (path to the file currently being run)
- %S source dir (directory of the file currently being run)
- %p same as %S
- %{pathsep} path separator
- %t temporary file name unique to the test
- %T temporary directory unique to the test
- %% %
- ========== ==============
+ ======================= ==============
+ Macro Substitution
+ ======================= ==============
+ %s source path (path to the file currently being run)
+ %S source dir (directory of the file currently being run)
+ %p same as %S
+ %{pathsep} path separator
+ %t temporary file name unique to the test
+ %T temporary directory unique to the test
+ %{shared_output(LABEL)} temporary file name, identified by "LABEL", shared across all tests
+ %% %
+ ======================= ==============
Other substitutions are provided that are variations on this base set and
further substitution patterns can be defined by each test module. See the
Modified: llvm/trunk/docs/TestingGuide.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/TestingGuide.rst?rev=315697&r1=315696&r2=315697&view=diff
==============================================================================
--- llvm/trunk/docs/TestingGuide.rst (original)
+++ llvm/trunk/docs/TestingGuide.rst Fri Oct 13 09:12:23 2017
@@ -464,6 +464,12 @@ RUN lines:
Example: ``/home/user/llvm.build/test/MC/ELF/Output``
+``%{shared_output(LABEL)}``
+ File path to a temporary file name shared across all tests, identified by
+ LABEL. This is useful as a cache for generated resources.
+
+ Example: ``/home/user/llvm.build/test/Output/Shared/LABEL.tmp``
+
``%{pathsep}``
Expands to the path separator, i.e. ``:`` (or ``;`` on Windows).
Modified: llvm/trunk/utils/lit/lit/TestRunner.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/TestRunner.py?rev=315697&r1=315696&r2=315697&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/TestRunner.py (original)
+++ llvm/trunk/utils/lit/lit/TestRunner.py Fri Oct 13 09:12:23 2017
@@ -829,6 +829,9 @@ def getDefaultSubstitutions(test, tmpDir
sourcepath = test.getSourcePath()
sourcedir = os.path.dirname(sourcepath)
+ sharedOutputDir = os.path.join(test.suite.exec_root, 'Output', 'Shared')
+ sharedOutputDir += os.path.sep
+
# Normalize slashes, if requested.
if normalize_slashes:
sourcepath = sourcepath.replace('\\', '/')
@@ -849,6 +852,8 @@ def getDefaultSubstitutions(test, tmpDir
('%t', tmpName),
('%basename_t', baseName),
('%T', tmpDir),
+ ('%{shared_output\(([-+=._a-zA-Z0-9]+)\)}',
+ '%s\\1.tmp' % (sharedOutputDir,)),
('#_MARKER_#', '%')])
# "%/[STpst]" should be normalized.
Modified: llvm/trunk/utils/lit/lit/run.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/run.py?rev=315697&r1=315696&r2=315697&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/run.py (original)
+++ llvm/trunk/utils/lit/lit/run.py Fri Oct 13 09:12:23 2017
@@ -1,4 +1,5 @@
import os
+import shutil
import sys
import threading
import time
@@ -136,6 +137,13 @@ class Run(object):
return True
win32api.SetConsoleCtrlHandler(console_ctrl_handler, True)
+ # Make fresh shared output directories.
+ suites = set(test.suite for test in self.tests)
+ for suite in suites:
+ shared_dir = os.path.join(suite.exec_root, 'Output', 'Shared')
+ shutil.rmtree(shared_dir, ignore_errors=True)
+ lit.util.mkdir_p(shared_dir)
+
# Save the display object on the runner so that we can update it from
# our task completion callback.
self.display = display
Added: llvm/trunk/utils/lit/tests/Inputs/shared-output/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/shared-output/lit.cfg?rev=315697&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/Inputs/shared-output/lit.cfg (added)
+++ llvm/trunk/utils/lit/tests/Inputs/shared-output/lit.cfg Fri Oct 13 09:12:23 2017
@@ -0,0 +1,5 @@
+import lit.formats
+config.name = 'shared-output'
+config.suffixes = ['.txt']
+config.test_format = lit.formats.ShTest()
+config.test_source_root = os.path.dirname(os.path.realpath(__file__))
Added: llvm/trunk/utils/lit/tests/Inputs/shared-output/primary.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/shared-output/primary.txt?rev=315697&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/Inputs/shared-output/primary.txt (added)
+++ llvm/trunk/utils/lit/tests/Inputs/shared-output/primary.txt Fri Oct 13 09:12:23 2017
@@ -0,0 +1,2 @@
+RUN: echo "primary" >> %{shared_output(SHARED)}
+RUN: echo "other" >> %{shared_output(OTHER)}
Added: llvm/trunk/utils/lit/tests/Inputs/shared-output/secondary.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/shared-output/secondary.txt?rev=315697&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/Inputs/shared-output/secondary.txt (added)
+++ llvm/trunk/utils/lit/tests/Inputs/shared-output/secondary.txt Fri Oct 13 09:12:23 2017
@@ -0,0 +1 @@
+RUN: echo "secondary" >> %{shared_output(SHARED)}
Added: llvm/trunk/utils/lit/tests/Inputs/shared-output/sub/sub.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/shared-output/sub/sub.txt?rev=315697&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/Inputs/shared-output/sub/sub.txt (added)
+++ llvm/trunk/utils/lit/tests/Inputs/shared-output/sub/sub.txt Fri Oct 13 09:12:23 2017
@@ -0,0 +1 @@
+RUN: echo "sub" >> %{shared_output(SHARED)}
Added: llvm/trunk/utils/lit/tests/shared-output.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/shared-output.py?rev=315697&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/shared-output.py (added)
+++ llvm/trunk/utils/lit/tests/shared-output.py Fri Oct 13 09:12:23 2017
@@ -0,0 +1,13 @@
+# RUN: rm -rf %t && mkdir -p %t
+# RUN: echo 'lit_config.load_config(config, "%{inputs}/shared-output/lit.cfg")' > %t/lit.site.cfg
+# RUN: %{lit} %t
+# RUN: FileCheck %s < %t/Output/Shared/SHARED.tmp
+# RUN: FileCheck -check-prefix=NEGATIVE %s < %t/Output/Shared/SHARED.tmp
+# RUN: FileCheck -check-prefix=OTHER %s < %t/Output/Shared/OTHER.tmp
+
+# CHECK-DAG: primary
+# CHECK-DAG: secondary
+# CHECK-DAG: sub
+
+# NEGATIVE-NOT: other
+# OTHER: other
More information about the llvm-commits
mailing list