[igt-dev] [PATCH i-g-t v3 08/14] scripts/test_list.py: allow passing a config dict directly

Mauro Carvalho Chehab mauro.chehab at linux.intel.com
Thu Jul 13 07:50:48 UTC 2023


From: Mauro Carvalho Chehab <mchehab at kernel.org>

Make the logic more generic by allowing to pass a config dict
directly.

Reviewed-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab at kernel.org>
---
 scripts/test_list.py | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/scripts/test_list.py b/scripts/test_list.py
index 465c73c3bdef..27434a6d7471 100644
--- a/scripts/test_list.py
+++ b/scripts/test_list.py
@@ -245,8 +245,10 @@ class TestList:
     Description: test ioctls
     """
 
-    def __init__(self, config_fname, include_plan = False, file_list = False,
+    def __init__(self, config_fname = None,
+                 include_plan = False, file_list = None,
                  built_testlist = None,
+                 config_dict = None, sources_path = None,
                  test_tag = "TEST", subtest_tag = "SUBTESTS?",
                  main_name = "igt", subtest_separator = "@"):
         self.doc = {}
@@ -263,18 +265,34 @@ class TestList:
         self.subtest_separator = subtest_separator
         self.main_name = main_name
 
+        # Exclusive or: either one is needed
+        if bool(config_fname) == bool(config_dict):
+            sys.exit("Error: either config filename or config dict shall be used")
+
         if self.main_name:
             self.main_name += subtest_separator
 
-        driver_name = re.sub(r'(.*/)?([^\/]+)/.*', r'\2', config_fname).capitalize()
-
         implemented_class = None
 
-        with open(config_fname, 'r', encoding='utf8') as handle:
-            self.config = json.load(handle)
+        if config_fname:
+            with open(config_fname, 'r', encoding='utf8') as handle:
+                self.config = json.load(handle)
 
-        config_origin = config_fname
-        cfg_path = os.path.realpath(os.path.dirname(config_fname)) + "/"
+            config_origin = config_fname
+            cfg_path = os.path.realpath(os.path.dirname(config_fname)) + "/"
+            driver_name = re.sub(r'(.*/)?([^\/]+)/.*', r'\2', config_fname).capitalize()
+
+        else:
+            self.config = config_dict
+            config_origin = "config dict"
+            cfg_path = "./"
+            driver_name = main_name
+
+        if sources_path:
+            cfg_path = os.path.realpath(sources_path) + "/"
+
+        if not self.config:
+            sys.exit("Error: configuration is empty!")
 
         self.__add_field(None, 0, 0, self.config["fields"])
 
-- 
2.40.1



More information about the igt-dev mailing list