Revert "[lit] Stop supporting triple substrings in UNSUPPORTED and XFAIL"
authorPaul Robinson <paul.robinson@sony.com>
Thu, 19 Jan 2023 17:26:33 +0000 (09:26 -0800)
committerPaul Robinson <paul.robinson@sony.com>
Thu, 19 Jan 2023 17:28:14 +0000 (09:28 -0800)
This reverts commit a0f8bdbb18a82ec150515d24f6eefb3519d4459a.

Several bots are failing in shtest-format.py, likely because of this.

llvm/docs/ReleaseNotes.rst
llvm/utils/lit/lit/BooleanExpression.py
llvm/utils/lit/lit/Test.py

index 783e8f5..6dc2dad 100644 (file)
@@ -309,13 +309,6 @@ Changes to Sanitizers
 Other Changes
 -------------
 
-* lit no longer supports using substrings of the default target triple as
-  feature names in ``UNSUPPORTED:`` and ``XFAIL:`` directives. These have been
-  replaced by the ``target=<triple>`` feature, and tests can use regex
-  matching to achieve the same effect. For example, ``UNSUPPORTED: arm``
-  would now be ``UNSUPPORTED: target=arm{{.*}}`` and ``XFAIL: windows``
-  would now be ``XFAIL: target={{.*}}-windows{{.*}}``.
-
 External Open Source Projects Using LLVM 15
 ===========================================
 
index ba8453d..ff53527 100644 (file)
@@ -22,22 +22,24 @@ class BooleanExpression:
     #
     # Variables in `variables` are true.
     # Regexes that match any variable in `variables` are true.
+    # Substrings of `triple` are true.
     # 'true' is true.
     # All other identifiers are false.
     @staticmethod
-    def evaluate(string, variables):
+    def evaluate(string, variables, triple=""):
         try:
-            parser = BooleanExpression(string, set(variables))
+            parser = BooleanExpression(string, set(variables), triple)
             return parser.parseAll()
         except ValueError as e:
             raise ValueError(str(e) + ('\nin expression: %r' % string))
 
     #####
 
-    def __init__(self, string, variables):
+    def __init__(self, string, variables, triple=""):
         self.tokens = BooleanExpression.tokenize(string)
         self.variables = variables
         self.variables.add('true')
+        self.triple = triple
         self.value = None
         self.token = None
 
@@ -99,7 +101,7 @@ class BooleanExpression:
             else:
                 regex += re.escape(part)
         regex = re.compile(regex)
-        self.value = any(regex.fullmatch(var) for var in self.variables)
+        self.value = self.token in self.triple or any(regex.fullmatch(var) for var in self.variables)
         self.token = next(self.tokens)
 
     def parseNOT(self):
@@ -172,6 +174,20 @@ class TestBooleanExpression(unittest.TestCase):
         self.assertFalse(BooleanExpression.evaluate('tru', variables))
         self.assertFalse(BooleanExpression.evaluate('{{its-true.+}}', variables))
 
+    def test_triple(self):
+        triple = 'arch-vendor-os'
+        self.assertTrue(BooleanExpression.evaluate('arch-', {}, triple))
+        self.assertTrue(BooleanExpression.evaluate('ar', {}, triple))
+        self.assertTrue(BooleanExpression.evaluate('ch-vend', {}, triple))
+        self.assertTrue(BooleanExpression.evaluate('-vendor-', {}, triple))
+        self.assertTrue(BooleanExpression.evaluate('-os', {}, triple))
+        self.assertFalse(BooleanExpression.evaluate('arch-os', {}, triple))
+
+        # When matching against the triple, a regex is treated as an identifier and checked
+        # for a literal match. This preserves existing behavior before regexes were introduced.
+        self.assertFalse(BooleanExpression.evaluate('arch-{{vendor}}-os', {}, triple))
+        self.assertTrue(BooleanExpression.evaluate('arch-{{vendor}}-os', {}, 'arch-{{vendor}}-os'))
+
     def test_matching(self):
         expr1 = 'linux && (target={{aarch64-.+}} || target={{x86_64-.+}})'
         self.assertTrue(BooleanExpression.evaluate(expr1, {'linux', 'target=x86_64-unknown-linux-gnu'}))
index 6c72359..dc1c66e 100644 (file)
@@ -227,9 +227,9 @@ class Test:
         self.gtest_json_file = gtest_json_file
 
         # A list of conditions under which this test is expected to fail.
-        # Each condition is a boolean expression of features, or '*'.
-        # These can optionally be provided by test format handlers,
-        # and will be honored when the test result is supplied.
+        # Each condition is a boolean expression of features and target
+        # triple parts. These can optionally be provided by test format
+        # handlers, and will be honored when the test result is supplied.
         self.xfails = []
 
         # If true, ignore all items in self.xfails.
@@ -238,11 +238,12 @@ class Test:
         # A list of conditions that must be satisfied before running the test.
         # Each condition is a boolean expression of features. All of them
         # must be True for the test to run.
+        # FIXME should target triple parts count here too?
         self.requires = []
 
         # A list of conditions that prevent execution of the test.
-        # Each condition is a boolean expression of features. All of them
-        # must be False for the test to run.
+        # Each condition is a boolean expression of features and target
+        # triple parts. All of them must be False for the test to run.
         self.unsupported = []
 
         # An optional number of retries allowed before the test finally succeeds.
@@ -316,16 +317,18 @@ class Test:
           return False
 
         features = self.config.available_features
+        triple = getattr(self.suite.config, 'target_triple', "")
 
-        # Check if any of the xfails match an available feature.
+        # Check if any of the xfails match an available feature or the target.
         for item in self.xfails:
             # If this is the wildcard, it always fails.
             if item == '*':
                 return True
 
-            # If this is a True expression of features, it fails.
+            # If this is a True expression of features and target triple parts,
+            # it fails.
             try:
-                if BooleanExpression.evaluate(item, features):
+                if BooleanExpression.evaluate(item, features, triple):
                     return True
             except ValueError as e:
                 raise ValueError('Error in XFAIL list:\n%s' % str(e))
@@ -382,15 +385,16 @@ class Test:
         getUnsupportedFeatures() -> list of strings
 
         Returns a list of features from UNSUPPORTED that are present
-        in the test configuration's features.
+        in the test configuration's features or target triple.
         Throws ValueError if an UNSUPPORTED line has a syntax error.
         """
 
         features = self.config.available_features
+        triple = getattr(self.suite.config, 'target_triple', "")
 
         try:
             return [item for item in self.unsupported
-                    if BooleanExpression.evaluate(item, features)]
+                    if BooleanExpression.evaluate(item, features, triple)]
         except ValueError as e:
             raise ValueError('Error in UNSUPPORTED list:\n%s' % str(e))