Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mauro.chehab@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t v5 7/7] scripts/test_list.py: optimize check regex
Date: Mon, 10 Jul 2023 13:53:54 +0200	[thread overview]
Message-ID: <20230710115354.699245-8-mauro.chehab@linux.intel.com> (raw)
In-Reply-To: <20230710115354.699245-1-mauro.chehab@linux.intel.com>

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

Running re.sub() for an already compiled regex makes it recompile
again. Change the logic to use the right syntax. While here, also use
rstrip() to remove \n at the end of read files.

Before:

	$ time ./scripts/igt_doc.py --config tests/i915/i915_*json --check --igt build/

	real	0m1.492s
	user	0m1.457s
	sys	0m0.030s

After:
	$ time ./scripts/igt_doc.py --config tests/i915/i915_*json --check --igt build/

	real	0m0.492s
	user	0m0.473s
	sys	0m0.017s

It is now 3 times faster (measured for i915 driver, which has
more IGT tests).

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
---
 scripts/test_list.py | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/scripts/test_list.py b/scripts/test_list.py
index 2c1a6f230fb5..19ed5e5467f5 100755
--- a/scripts/test_list.py
+++ b/scripts/test_list.py
@@ -401,10 +401,10 @@ class TestList:
 
         for filter_field, regex in self.filters.items():
             if filter_field in subtest:
-                if not re.match(regex, subtest[filter_field]):
+                if not regex.match(subtest[filter_field]):
                     return True
             elif filter_field in test:
-                if not re.match(regex, test[filter_field]):
+                if not regex.match(test[filter_field]):
                     return True
             else:
                 return field_not_found_value
@@ -919,7 +919,7 @@ class TestList:
 
             with open(fname, 'r', encoding='utf8') as handle:
                 for line in handle:
-                    tests.append(line)
+                    tests.append(line.rstrip("\n"))
 
         return sorted(tests)
 
@@ -938,9 +938,11 @@ class TestList:
 
         doc_subtests = set()
 
+        args_regex = re.compile(r'\<[^\>]+\>')
+
         for subtest in self.get_subtests()[""]:
             subtest = "@".join(subtest.split("@")[:3])
-            subtest = re.sub(r'\<[^\>]+\>', r'\\d+', subtest)
+            subtest = args_regex.sub(r'\\d+', subtest)
             doc_subtests.add(subtest)
 
         doc_subtests = list(sorted(doc_subtests))
@@ -957,14 +959,14 @@ class TestList:
         for doc_test in doc_subtests:
             if test_regex != r"":
                 test_regex += r"|"
-            test_regex += r'^' + doc_test + r'$'
+            test_regex += doc_test
 
-        test_regex = re.compile(test_regex)
+        test_regex = re.compile(r'^(' + test_regex + r')$')
 
         for doc_test in doc_subtests:
             found = False
             for run_test in run_subtests:
-                if re.match(test_regex, run_test):
+                if test_regex.match(run_test):
                     found = True
                     break
             if not found:
@@ -972,7 +974,7 @@ class TestList:
 
         for run_test in run_subtests:
             found = False
-            if re.match(test_regex, run_test):
+            if test_regex.match(run_test):
                 found = True
             if not found:
                 run_missing.append(run_test)
@@ -1101,7 +1103,7 @@ class TestList:
                     continue
 
                 # It is a known section. Parse its contents
-                match = re.match(field_re, file_line)
+                match = field_re.match(file_line)
                 if match:
                     current_field = self.field_list[match.group(1).lower()]
                     match_val = match.group(2)
@@ -1198,7 +1200,7 @@ class TestList:
                             self.doc[current_test]["arg"][arg_ref][cur_arg][cur_arg_element] += match_val
                     continue
 
-                re.sub(r"\n$","", file_line)
+                file_line.rstrip(r"\n")
                 sys.exit(f"{fname}:{file_ln + 1}: Error: unrecognized line. Need to add field at %s?\n\t==> %s" %
                          (self.config_fname, file_line))
 
-- 
2.40.1

  parent reply	other threads:[~2023-07-10 11:54 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-10 11:53 [igt-dev] [PATCH i-g-t v5 0/7] Speedup IGT build time Mauro Carvalho Chehab
2023-07-10 11:53 ` [igt-dev] [PATCH i-g-t v5 1/7] tests/meson.build: Simplify builds for core and i915 targets Mauro Carvalho Chehab
2023-07-10 17:51   ` Kamil Konieczny
2023-07-10 11:53 ` [igt-dev] [PATCH i-g-t v5 2/7] lib/igt_core: use the macro when checking for list_subtests Mauro Carvalho Chehab
2023-07-10 17:58   ` Kamil Konieczny
2023-07-10 11:53 ` [igt-dev] [PATCH i-g-t v5 3/7] lib/igt_core: add an option to show the testlist Mauro Carvalho Chehab
2023-07-10 18:11   ` Kamil Konieczny
2023-07-10 11:53 ` [igt-dev] [PATCH i-g-t v5 4/7] tests/meson.build: create testlists for tests Mauro Carvalho Chehab
2023-07-10 18:17   ` Kamil Konieczny
2023-08-30 21:41     ` Mark Yacoub
     [not found]       ` <CAAea8Y3a_RjknGcn6-v9CVUVpcmMuASnJKfn73KGtQzbXo0TcA@mail.gmail.com>
2023-08-31  9:28         ` Mauro Carvalho Chehab
     [not found]           ` <CAAea8Y13=CguTipLJjJJt_pBvaiv92DViWJBZwvtjm7W-SU+vw@mail.gmail.com>
2023-09-01  7:45             ` Mauro Carvalho Chehab
2023-09-01  8:34               ` Mauro Carvalho Chehab
2023-09-01 11:01               ` Mauro Carvalho Chehab
     [not found]               ` <CAAea8Y2hX2=TjXmGJN=tFBSgFPqe8J5EgDCkoR7OMVy+J2t+cA@mail.gmail.com>
2023-09-04  6:53                 ` Mauro Carvalho Chehab
2023-07-10 11:53 ` [igt-dev] [PATCH i-g-t v5 5/7] scripts/test_list.py: speedup testlist check logic Mauro Carvalho Chehab
2023-07-10 18:23   ` Kamil Konieczny
2023-07-10 11:53 ` [igt-dev] [PATCH i-g-t v5 6/7] tests/build: Generate and store an intel-ci.testlist Mauro Carvalho Chehab
2023-07-10 18:26   ` Kamil Konieczny
2023-07-10 11:53 ` Mauro Carvalho Chehab [this message]
2023-07-10 18:27   ` [igt-dev] [PATCH i-g-t v5 7/7] scripts/test_list.py: optimize check regex Kamil Konieczny
2023-07-10 13:50 ` [igt-dev] ✓ Fi.CI.BAT: success for Speedup IGT build time Patchwork
2023-07-10 14:00 ` [igt-dev] ○ CI.xeBAT: info " Patchwork
2023-07-10 17:02 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2023-08-31 11:36 ` [igt-dev] ✗ Fi.CI.BUILD: failure for Speedup IGT build time (rev2) Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230710115354.699245-8-mauro.chehab@linux.intel.com \
    --to=mauro.chehab@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox