[libcxx-commits] [libcxx] 78e266e - [libc++] Allow picking Lit parameters from the config

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 10 05:02:18 PDT 2020


Author: Louis Dionne
Date: 2020-06-10T08:02:07-04:00
New Revision: 78e266efaba64fee2c527bfe5328af2088a3483f

URL: https://github.com/llvm/llvm-project/commit/78e266efaba64fee2c527bfe5328af2088a3483f
DIFF: https://github.com/llvm/llvm-project/commit/78e266efaba64fee2c527bfe5328af2088a3483f.diff

LOG: [libc++] Allow picking Lit parameters from the config

Unlike parameters in litConfig.params, the config isn't shared across
all test suites. For example, if we want to enable exceptions in the
tests for libcxxabi, but not in the tests for libcxx, we can't set the
enable_exceptions parameter in the litConfig object, cause it will be
used by both. Instead, setting it inside the config object solves that
problem.

Added: 
    

Modified: 
    libcxx/test/libcxx/selftest/dsl/dsl.sh.py
    libcxx/utils/libcxx/test/dsl.py

Removed: 
    


################################################################################
diff  --git a/libcxx/test/libcxx/selftest/dsl/dsl.sh.py b/libcxx/test/libcxx/selftest/dsl/dsl.sh.py
index 9cf0ac95a0b8..5a8ae88e0531 100644
--- a/libcxx/test/libcxx/selftest/dsl/dsl.sh.py
+++ b/libcxx/test/libcxx/selftest/dsl/dsl.sh.py
@@ -263,11 +263,11 @@ def test_name_is_set_correctly(self):
         param = dsl.Parameter(name='std', choices=['c++03'], type=str, help='', feature=lambda _: None)
         self.assertEqual(param.name, 'std')
 
-    def test_no_value_provided_on_command_line_and_no_default_value(self):
+    def test_no_value_provided_and_no_default_value(self):
         param = dsl.Parameter(name='std', choices=['c++03'], type=str, help='', feature=lambda _: None)
         self.assertRaises(ValueError, lambda: param.getFeature(self.config, self.litConfig.params))
 
-    def test_no_value_provided_on_command_line_and_default_value(self):
+    def test_no_value_provided_and_default_value(self):
         param = dsl.Parameter(name='std', choices=['c++03'], type=str, help='', default='c++03',
                               feature=lambda std: dsl.Feature(name=std))
         param.getFeature(self.config, self.litConfig.params).enableIn(self.config)
@@ -281,6 +281,7 @@ def test_value_provided_on_command_line_and_no_default_value(self):
         self.assertIn('c++03', self.config.available_features)
 
     def test_value_provided_on_command_line_and_default_value(self):
+        """The value provided on the command line should override the default value"""
         self.litConfig.params['std'] = 'c++11'
         param = dsl.Parameter(name='std', choices=['c++03', 'c++11'], type=str, default='c++03', help='',
                               feature=lambda std: dsl.Feature(name=std))
@@ -288,6 +289,25 @@ def test_value_provided_on_command_line_and_default_value(self):
         self.assertIn('c++11', self.config.available_features)
         self.assertNotIn('c++03', self.config.available_features)
 
+    def test_value_provided_in_config_and_default_value(self):
+        """The value provided in the config should override the default value"""
+        self.config.std ='c++11'
+        param = dsl.Parameter(name='std', choices=['c++03', 'c++11'], type=str, default='c++03', help='',
+                              feature=lambda std: dsl.Feature(name=std))
+        param.getFeature(self.config, self.litConfig.params).enableIn(self.config)
+        self.assertIn('c++11', self.config.available_features)
+        self.assertNotIn('c++03', self.config.available_features)
+
+    def test_value_provided_in_config_and_on_command_line(self):
+        """The value on the command line should override the one in the config"""
+        self.config.std = 'c++11'
+        self.litConfig.params['std'] = 'c++03'
+        param = dsl.Parameter(name='std', choices=['c++03', 'c++11'], type=str, help='',
+                              feature=lambda std: dsl.Feature(name=std))
+        param.getFeature(self.config, self.litConfig.params).enableIn(self.config)
+        self.assertIn('c++03', self.config.available_features)
+        self.assertNotIn('c++11', self.config.available_features)
+
     def test_feature_is_None(self):
         self.litConfig.params['std'] = 'c++03'
         param = dsl.Parameter(name='std', choices=['c++03'], type=str, help='',

diff  --git a/libcxx/utils/libcxx/test/dsl.py b/libcxx/utils/libcxx/test/dsl.py
index 59329debecf8..d449c60359bf 100644
--- a/libcxx/utils/libcxx/test/dsl.py
+++ b/libcxx/utils/libcxx/test/dsl.py
@@ -250,15 +250,22 @@ class Parameter(object):
   Represents a parameter of a Lit test suite.
 
   Parameters are used to customize the behavior of test suites in a user
-  controllable way, more specifically by passing `--param <KEY>=<VALUE>`
-  when running Lit. Parameters have multiple possible values, and they can
-  have a default value when left unspecified.
-
-  Parameters can have a Feature associated to them, in which case the Feature
-  is added to the TestingConfig if the parameter is enabled. It is an error if
-  the Parameter is enabled but the Feature associated to it is not supported,
-  for example trying to set the compilation standard to C++17 when `-std=c++17`
-  is not supported by the compiler.
+  controllable way. There are two ways of setting the value of a Parameter.
+  The first one is to pass `--param <KEY>=<VALUE>` when running Lit (or
+  equivalenlty to set `litConfig.params[KEY] = VALUE` somewhere in the
+  Lit configuration files. This method will set the parameter globally for
+  all test suites being run.
+
+  The second method is to set `config.KEY = VALUE` somewhere in the Lit
+  configuration files, which sets the parameter only for the test suite(s)
+  that use that `config` object.
+
+  Parameters can have multiple possible values, and they can have a default
+  value when left unspecified. They can also have a Feature associated to them,
+  in which case the Feature is added to the TestingConfig if the parameter is
+  enabled. It is an error if the Parameter is enabled but the Feature associated
+  to it is not supported, for example trying to set the compilation standard to
+  C++17 when `-std=c++17` is not supported by the compiler.
 
   One important point is that Parameters customize the behavior of the test
   suite in a bounded way, i.e. there should be a finite set of possible choices
@@ -332,9 +339,10 @@ def name(self):
     return self._name
 
   def getFeature(self, config, litParams):
-    param = litParams.get(self.name, None)
+    param = getattr(config, self.name, None)
+    param = litParams.get(self.name, param)
     if param is None and self._default is None:
-      raise ValueError("Parameter {} doesn't have a default value, but it was not specified in the Lit parameters".format(self.name))
+      raise ValueError("Parameter {} doesn't have a default value, but it was not specified in the Lit parameters or in the Lit config".format(self.name))
     getDefault = lambda: self._default(config) if callable(self._default) else self._default
     value = self._parse(param) if param is not None else getDefault()
     if value not in self._choices:


        


More information about the libcxx-commits mailing list