Title: [275211] trunk/Tools
Revision
275211
Author
[email protected]
Date
2021-03-30 10:13:57 -0700 (Tue, 30 Mar 2021)

Log Message

[ews] Add build step to find list of layout tests modified by a patch
https://bugs.webkit.org/show_bug.cgi?id=223890

Reviewed by Jonathan Bedard.

* CISupport/ews-build/steps.py:
(AnalyzePatch): Created common base class for CheckPatchRelevance and FindModifiedLayoutTests.
(AnalyzePatch._get_patch): Moved to base class.
(AnalyzePatch._addToLog): Ditto.
(AnalyzePatch.getResultSummary): Ditto.
(CheckPatchRelevance):
(FindModifiedLayoutTests): Build step to find list of layout tests modified by the patch being processed.
(FindModifiedLayoutTests.find_test_names_from_patch):
(FindModifiedLayoutTests.start):
* CISupport/ews-build/steps_unittest.py: Added unit-tests.

Modified Paths

Diff

Modified: trunk/Tools/CISupport/ews-build/steps.py (275210 => 275211)


--- trunk/Tools/CISupport/ews-build/steps.py	2021-03-30 17:10:11 UTC (rev 275210)
+++ trunk/Tools/CISupport/ews-build/steps.py	2021-03-30 17:13:57 UTC (rev 275211)
@@ -333,12 +333,36 @@
         return rc
 
 
-class CheckPatchRelevance(buildstep.BuildStep):
+class AnalyzePatch(buildstep.BuildStep):
+    flunkOnFailure = True
+    haltOnFailure = True
+
+    def _get_patch(self):
+        sourcestamp = self.build.getSourceStamp(self.getProperty('codebase', ''))
+        if not sourcestamp or not sourcestamp.patch:
+            return None
+        return sourcestamp.patch[1]
+
+    @defer.inlineCallbacks
+    def _addToLog(self, logName, message):
+        try:
+            log = self.getLog(logName)
+        except KeyError:
+            log = yield self.addLog(logName)
+        log.addStdout(message)
+
+    def getResultSummary(self):
+        if self.results == FAILURE:
+            return {'step': 'Patch doesn\'t have relevant changes'}
+        if self.results == SUCCESS:
+            return {'step': 'Patch contains relevant changes'}
+        return buildstep.BuildStep.getResultSummary(self)
+
+
+class CheckPatchRelevance(AnalyzePatch):
     name = 'check-patch-relevance'
     description = ['check-patch-relevance running']
     descriptionDone = ['Patch contains relevant changes']
-    flunkOnFailure = True
-    haltOnFailure = True
 
     bindings_paths = [
         'Source/WebCore',
@@ -415,20 +439,6 @@
                     return True
         return False
 
-    def _get_patch(self):
-        sourcestamp = self.build.getSourceStamp(self.getProperty('codebase', ''))
-        if not sourcestamp or not sourcestamp.patch:
-            return None
-        return sourcestamp.patch[1]
-
-    @defer.inlineCallbacks
-    def _addToLog(self, logName, message):
-        try:
-            log = self.getLog(logName)
-        except KeyError:
-            log = yield self.addLog(logName)
-        log.addStdout(message)
-
     def start(self):
         patch = self._get_patch()
         if not patch:
@@ -447,12 +457,47 @@
         self.build.buildFinished(['Patch {} doesn\'t have relevant changes'.format(self.getProperty('patch_id', ''))], SKIPPED)
         return None
 
-    def getResultSummary(self):
-        if self.results == FAILURE:
-            return {'step': 'Patch doesn\'t have relevant changes'}
-        return super(CheckPatchRelevance, self).getResultSummary()
 
+class FindModifiedLayoutTests(AnalyzePatch):
+    name = 'find-modified-layout-tests'
+    RE_LAYOUT_TEST = b'^(\+\+\+).*(LayoutTests.*\.html)'
+    DIRECTORIES_TO_IGNORE = ['reference', 'reftest', 'resources', 'support', 'script-tests', 'tools']
+    SUFFIXES_TO_IGNORE = ['-expected', '-expected-mismatch', '-ref', '-notref']
 
+    def find_test_names_from_patch(self, patch):
+        tests = []
+        for line in patch.splitlines():
+            match = re.search(self.RE_LAYOUT_TEST, line, re.IGNORECASE)
+            if match:
+                if any((suffix + '.html').encode('utf-8') in line for suffix in self.SUFFIXES_TO_IGNORE):
+                    continue
+                test_name = match.group(2).decode('utf-8')
+                if any(directory in test_name.split('/') for directory in self.DIRECTORIES_TO_IGNORE):
+                    continue
+                tests.append(test_name)
+        return list(set(tests))
+
+    def start(self):
+        patch = self._get_patch()
+        if not patch:
+            self.finished(SUCCESS)
+            return None
+
+        tests = self.find_test_names_from_patch(patch)
+
+        if tests:
+            self._addToLog('stdio', 'This patch modifies following tests: {}'.format(tests))
+            self.setProperty('modified_tests', tests)
+            self.finished(SUCCESS)
+            return None
+
+        self._addToLog('stdio', 'This patch does not modify any layout tests')
+        self.finished(FAILURE)
+        self.build.results = SKIPPED
+        self.build.buildFinished(['Patch {} doesn\'t have relevant changes'.format(self.getProperty('patch_id', ''))], SKIPPED)
+        return None
+
+
 class Bugzilla(object):
     @classmethod
     def bug_url(cls, bug_id):

Modified: trunk/Tools/CISupport/ews-build/steps_unittest.py (275210 => 275211)


--- trunk/Tools/CISupport/ews-build/steps_unittest.py	2021-03-30 17:10:11 UTC (rev 275210)
+++ trunk/Tools/CISupport/ews-build/steps_unittest.py	2021-03-30 17:13:57 UTC (rev 275211)
@@ -46,8 +46,8 @@
                    CleanBuild, CleanUpGitIndexLock, CleanWorkingDirectory, CompileJSC, CompileJSCWithoutPatch, CompileWebKit,
                    CompileWebKitWithoutPatch, ConfigureBuild, CreateLocalGITCommit,
                    DownloadBuiltProduct, DownloadBuiltProductFromMaster, EWS_BUILD_HOSTNAME, ExtractBuiltProduct, ExtractTestResults,
-                   FetchBranches, FindModifiedChangeLogs, InstallGtkDependencies, InstallWpeDependencies, KillOldProcesses,
-                   PrintConfiguration, PushCommitToWebKitRepo, ReRunAPITests, ReRunJavaScriptCoreTests, ReRunWebKitPerlTests,
+                   FetchBranches, FindModifiedChangeLogs, FindModifiedLayoutTests, InstallGtkDependencies, InstallWpeDependencies,
+                   KillOldProcesses, PrintConfiguration, PushCommitToWebKitRepo, ReRunAPITests, ReRunJavaScriptCoreTests, ReRunWebKitPerlTests,
                    ReRunWebKitTests, RunAPITests, RunAPITestsWithoutPatch, RunBindingsTests, RunBuildWebKitOrgUnitTests,
                    RunBuildbotCheckConfigForBuildWebKit, RunBuildbotCheckConfigForEWS, RunEWSUnitTests, RunResultsdbpyTests,
                    RunJavaScriptCoreTests, RunJSCTestsWithoutPatch, RunWebKit1Tests, RunWebKitPerlTests, RunWebKitPyPython2Tests,
@@ -2637,6 +2637,61 @@
         return rc
 
 
+class TestFindModifiedLayoutTests(BuildStepMixinAdditions, unittest.TestCase):
+    def setUp(self):
+        self.longMessage = True
+        return self.setUpBuildStep()
+
+    def tearDown(self):
+        return self.tearDownBuildStep()
+
+    def test_relevant_patch(self):
+        self.setupStep(FindModifiedLayoutTests())
+        self.assertEqual(FindModifiedLayoutTests.haltOnFailure, True)
+        self.assertEqual(FindModifiedLayoutTests.flunkOnFailure, True)
+        FindModifiedLayoutTests._get_patch = lambda x: b'+++ LayoutTests/http/tests/events/device-orientation-motion-insecure-context.html'
+        self.expectOutcome(result=SUCCESS, state_string='Patch contains relevant changes')
+        rc = self.runStep()
+        self.assertEqual(self.getProperty('modified_tests'), ['LayoutTests/http/tests/events/device-orientation-motion-insecure-context.html'])
+        return rc
+
+    def test_ignore_certain_directories(self):
+        self.setupStep(FindModifiedLayoutTests())
+        dir_names = ['reference', 'reftest', 'resources', 'support', 'script-tests', 'tools']
+        for dir_name in dir_names:
+            FindModifiedLayoutTests._get_patch = lambda x: '+++ LayoutTests/{}/test-name.html'.format(dir_name).encode('utf-8')
+            self.expectOutcome(result=FAILURE, state_string='Patch doesn\'t have relevant changes')
+            rc = self.runStep()
+            self.assertEqual(self.getProperty('modified_tests'), None)
+        return rc
+
+    def test_ignore_certain_suffixes(self):
+        self.setupStep(FindModifiedLayoutTests())
+        suffixes = ['-expected', '-expected-mismatch', '-ref', '-notref']
+        for suffix in suffixes:
+            FindModifiedLayoutTests._get_patch = lambda x: '+++ LayoutTests/http/tests/events/device-motion-{}.html'.format(suffix).encode('utf-8')
+            self.expectOutcome(result=FAILURE, state_string='Patch doesn\'t have relevant changes')
+            rc = self.runStep()
+            self.assertEqual(self.getProperty('modified_tests'), None)
+        return rc
+
+    def test_ignore_non_layout_test_in_html_directory(self):
+        self.setupStep(FindModifiedLayoutTests())
+        FindModifiedLayoutTests._get_patch = lambda x: '+++ LayoutTests/html/test.txt'.encode('utf-8')
+        self.expectOutcome(result=FAILURE, state_string='Patch doesn\'t have relevant changes')
+        rc = self.runStep()
+        self.assertEqual(self.getProperty('modified_tests'), None)
+        return rc
+
+    def test_non_relevant_patch(self):
+        self.setupStep(FindModifiedLayoutTests())
+        FindModifiedLayoutTests._get_patch = lambda x: b'Sample patch which does not modify any layout test'
+        self.expectOutcome(result=FAILURE, state_string='Patch doesn\'t have relevant changes')
+        rc = self.runStep()
+        self.assertEqual(self.getProperty('modified_tests'), None)
+        return rc
+
+
 class TestArchiveBuiltProduct(BuildStepMixinAdditions, unittest.TestCase):
     def setUp(self):
         self.longMessage = True

Modified: trunk/Tools/ChangeLog (275210 => 275211)


--- trunk/Tools/ChangeLog	2021-03-30 17:10:11 UTC (rev 275210)
+++ trunk/Tools/ChangeLog	2021-03-30 17:13:57 UTC (rev 275211)
@@ -1,3 +1,21 @@
+2021-03-30  Aakash Jain  <[email protected]>
+
+        [ews] Add build step to find list of layout tests modified by a patch
+        https://bugs.webkit.org/show_bug.cgi?id=223890
+
+        Reviewed by Jonathan Bedard.
+
+        * CISupport/ews-build/steps.py:
+        (AnalyzePatch): Created common base class for CheckPatchRelevance and FindModifiedLayoutTests.
+        (AnalyzePatch._get_patch): Moved to base class.
+        (AnalyzePatch._addToLog): Ditto.
+        (AnalyzePatch.getResultSummary): Ditto.
+        (CheckPatchRelevance):
+        (FindModifiedLayoutTests): Build step to find list of layout tests modified by the patch being processed.
+        (FindModifiedLayoutTests.find_test_names_from_patch):
+        (FindModifiedLayoutTests.start):
+        * CISupport/ews-build/steps_unittest.py: Added unit-tests.
+
 2021-03-29  Cameron McCormack  <[email protected]>
 
         Avoid calling `xcodebuild -showsdks` where possible.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to