Title: [213562] trunk/Tools
Revision
213562
Author
[email protected]
Date
2017-03-07 19:46:19 -0800 (Tue, 07 Mar 2017)

Log Message

Perf and layout test results should report using correct scm revision.
https://bugs.webkit.org/show_bug.cgi?id=169171

Patch by Kocsen Chung <[email protected]> on 2017-03-07
Reviewed by Ryosuke Niwa.

For accurate record keeping, perf test and layout test results should
report using the native scm revision as an identifier.
To do so we introduce a new scm functions:
    `native_revision()` and `timestamp_of_native_revision()`.
The former is responsible for returning a git hash if scm.git or an
svn revision if scm.svn. The latter is responsible for retrieving the correct timestamp.
We also add the corresponding tests and a helper function `_most_recent_log_for_revision`.

* Scripts/webkitpy/common/checkout/scm/scm.py:
(SCM.run):
Drive-by indentation fix to adhere to WebKit style conventions.
(SCM.svn_revision):
Remove superfluous comment.
(SCM.native_revision):
Add new abstract function `native_revision` and make it a `_subclass_must_implement()`
as we want to closely mimic `svn_revision()` function due to their similar behavior.
(SCM.timestamp_of_native_revision):
Add new abstract function `timestamp_of_native_revision` to closely mimic `timestamp_of_revision`.

* Scripts/webkitpy/common/checkout/scm/git.py:
(Git._most_recent_log_for_revision):
New helper function similar to `_most_recent_log_matching` that is git hash friendly.
(Git.native_revision):
Implement new function `native_revision()`. Get the native_revision by running:

    `git log -1 --pretty=format:%H`

and thus returning the latest git hash (in long format).
(Git.timestamp_of_native_revision):
Since perftestrunner and layout_test.controllers.manager use the new native_revision
function, we create a new native_revision timestamp retriever.
You will notice this uses a far more simplified way to retrieve UTC strict-ISO timestamp
than its non-native counterpart: `timestamp_of_revision()`.
* Scripts/webkitpy/common/checkout/scm/svn.py:
(SVN.native_revision):
Implement native_revision for SVN: simply return self.svn_revision()
(SVN.timestamp_of_native_revision):
Implement timestamp_of_native_revision for SVN: simply return self.timestamp_of_revision()

* Scripts/webkitpy/common/checkout/scm/scm_unittest.py:
(test_native_revision):
[SVN] Confirm that svn_revision == native_revision. And that native_revision returns 5.
Use '.' as the path parameter instead of svn_checkout_path to avoid violating pylint/E1101
and since we are guaranteed by test setUp to be in the correct SVN dir.
(GitTest.test_native_revision):
[Git] Confirm that `git rev-parse HEAD` is equal to newly implemented native_revision().
(GitSVNTest.test_native_revision):
[Git] Confirm that `git rev-parse HEAD` is equal to newly implemented native_revision().
(test_timestamp_of_native_revision):
Test new function `timestamp_of_native_revision`. Very similar fashion to
`test_timestamp_of_revision`.

* Scripts/webkitpy/common/checkout/scm/scm_mock.py:
(MockSCM.native_revision):
Add MockSCM.native_revision to behave like svn.py (default).
(MockSCM.test_native_revision):
Add MockSCM.test_native_revision to behave like its non-native counterpart.

* Scripts/webkitpy/layout_tests/controllers/manager.py:
(Manager.upload_results):
When iterating through a list of projects, make sure we use the project's new native revision.
* Scripts/webkitpy/performance_tests/perftestsrunner.py:
(_generate_results_dict):
As per the FIXME in manager.py, we have duplicate code in perftestsrunner.py.
So make the same exact change here.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (213561 => 213562)


--- trunk/Tools/ChangeLog	2017-03-08 03:15:02 UTC (rev 213561)
+++ trunk/Tools/ChangeLog	2017-03-08 03:46:19 UTC (rev 213562)
@@ -1,3 +1,76 @@
+2017-03-07  Kocsen Chung  <[email protected]>
+
+        Perf and layout test results should report using correct scm revision.
+        https://bugs.webkit.org/show_bug.cgi?id=169171
+
+        Reviewed by Ryosuke Niwa.
+
+        For accurate record keeping, perf test and layout test results should
+        report using the native scm revision as an identifier.
+        To do so we introduce a new scm functions:
+            `native_revision()` and `timestamp_of_native_revision()`.
+        The former is responsible for returning a git hash if scm.git or an
+        svn revision if scm.svn. The latter is responsible for retrieving the correct timestamp.
+        We also add the corresponding tests and a helper function `_most_recent_log_for_revision`.
+
+        * Scripts/webkitpy/common/checkout/scm/scm.py:
+        (SCM.run):
+        Drive-by indentation fix to adhere to WebKit style conventions.
+        (SCM.svn_revision):
+        Remove superfluous comment.
+        (SCM.native_revision):
+        Add new abstract function `native_revision` and make it a `_subclass_must_implement()`
+        as we want to closely mimic `svn_revision()` function due to their similar behavior.
+        (SCM.timestamp_of_native_revision):
+        Add new abstract function `timestamp_of_native_revision` to closely mimic `timestamp_of_revision`.
+
+        * Scripts/webkitpy/common/checkout/scm/git.py:
+        (Git._most_recent_log_for_revision):
+        New helper function similar to `_most_recent_log_matching` that is git hash friendly.
+        (Git.native_revision):
+        Implement new function `native_revision()`. Get the native_revision by running:
+
+            `git log -1 --pretty=format:%H`
+
+        and thus returning the latest git hash (in long format).
+        (Git.timestamp_of_native_revision):
+        Since perftestrunner and layout_test.controllers.manager use the new native_revision
+        function, we create a new native_revision timestamp retriever.
+        You will notice this uses a far more simplified way to retrieve UTC strict-ISO timestamp
+        than its non-native counterpart: `timestamp_of_revision()`.
+        * Scripts/webkitpy/common/checkout/scm/svn.py:
+        (SVN.native_revision):
+        Implement native_revision for SVN: simply return self.svn_revision()
+        (SVN.timestamp_of_native_revision):
+        Implement timestamp_of_native_revision for SVN: simply return self.timestamp_of_revision()
+
+        * Scripts/webkitpy/common/checkout/scm/scm_unittest.py:
+        (test_native_revision):
+        [SVN] Confirm that svn_revision == native_revision. And that native_revision returns 5.
+        Use '.' as the path parameter instead of svn_checkout_path to avoid violating pylint/E1101
+        and since we are guaranteed by test setUp to be in the correct SVN dir.
+        (GitTest.test_native_revision):
+        [Git] Confirm that `git rev-parse HEAD` is equal to newly implemented native_revision().
+        (GitSVNTest.test_native_revision):
+        [Git] Confirm that `git rev-parse HEAD` is equal to newly implemented native_revision().
+        (test_timestamp_of_native_revision):
+        Test new function `timestamp_of_native_revision`. Very similar fashion to
+        `test_timestamp_of_revision`.
+
+        * Scripts/webkitpy/common/checkout/scm/scm_mock.py:
+        (MockSCM.native_revision):
+        Add MockSCM.native_revision to behave like svn.py (default).
+        (MockSCM.test_native_revision):
+        Add MockSCM.test_native_revision to behave like its non-native counterpart.
+
+        * Scripts/webkitpy/layout_tests/controllers/manager.py:
+        (Manager.upload_results):
+        When iterating through a list of projects, make sure we use the project's new native revision.
+        * Scripts/webkitpy/performance_tests/perftestsrunner.py:
+        (_generate_results_dict):
+        As per the FIXME in manager.py, we have duplicate code in perftestsrunner.py.
+        So make the same exact change here.
+
 2017-03-07  Tim Horton  <[email protected]>
 
         Fix the TestWebKitAPI build

Modified: trunk/Tools/Scripts/webkitpy/common/checkout/scm/git.py (213561 => 213562)


--- trunk/Tools/Scripts/webkitpy/common/checkout/scm/git.py	2017-03-08 03:15:02 UTC (rev 213561)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/scm/git.py	2017-03-08 03:46:19 UTC (rev 213562)
@@ -270,6 +270,9 @@
         # git 1.7.0.4 (and earlier) didn't support the separate arg.
         return self._run_git(['log', '-1', '--grep=' + grep_str, '--date=iso', self.find_checkout_root(path)])
 
+    def _most_recent_log_for_revision(self, revision, path):
+        return self._run_git(['log', '-1', revision, '--date=iso', self.find_checkout_root(path)])
+
     def svn_revision(self, path):
         git_log = self._most_recent_log_matching('git-svn-id:', path)
         match = re.search("^\s*git-svn-id:.*@(?P<svn_revision>\d+)\ ", git_log, re.MULTILINE)
@@ -277,6 +280,9 @@
             return ""
         return str(match.group('svn_revision'))
 
+    def native_revision(self, path):
+        return self._run_git(['log', '-1', '--pretty=format:%H', self.find_checkout_root(path)])
+
     def svn_url(self):
         git_command = ['svn', 'info']
         status = self._run_git(git_command)
@@ -300,6 +306,11 @@
         time_without_timezone = time_with_timezone - datetime.timedelta(hours=sign * int(match.group(8)), minutes=int(match.group(9)))
         return time_without_timezone.strftime('%Y-%m-%dT%H:%M:%SZ')
 
+    def timestamp_of_native_revision(self, path, sha):
+        unix_timestamp = self._run_git(['log', '-1', sha, '--pretty="format:%ct"', self.find_checkout_root(path)]).rstrip()
+        commit_timestamp = datetime.datetime.utcfromtimestamp(float(unix_timestamp))
+        return commit_timestamp.strftime('%Y-%m-%dT%H:%M:%SZ')
+
     def prepend_svn_revision(self, diff):
         revision = self.head_svn_revision()
         if not revision:

Modified: trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm.py (213561 => 213562)


--- trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm.py	2017-03-08 03:15:02 UTC (rev 213561)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm.py	2017-03-08 03:46:19 UTC (rev 213562)
@@ -69,12 +69,12 @@
     def run(self, args, cwd=None, input=None, error_handler=None, return_exit_code=False, return_stderr=True, decode_output=True):
         # FIXME: We should set cwd appropriately.
         return self._executive.run_command(args,
-                           cwd=cwd,
-                           input=input,
-                           error_handler=error_handler,
-                           return_exit_code=return_exit_code,
-                           return_stderr=return_stderr,
-                           decode_output=decode_output)
+            cwd=cwd,
+            input=input,
+            error_handler=error_handler,
+            return_exit_code=return_exit_code,
+            return_stderr=return_stderr,
+            decode_output=decode_output)
 
     # SCM always returns repository relative path, but sometimes we need
     # absolute paths to pass to rm, etc.
@@ -158,12 +158,17 @@
         return self.svn_revision(self.checkout_root)
 
     def svn_revision(self, path):
-        """Returns the latest svn revision found in the checkout."""
         self._subclass_must_implement()
 
+    def native_revision(self, path):
+        self._subclass_must_implement()
+
     def timestamp_of_revision(self, path, revision):
         self._subclass_must_implement()
 
+    def timestamp_of_native_revision(self, path, revision):
+        self._subclass_must_implement()
+
     def create_patch(self, git_commit=None, changed_files=None):
         self._subclass_must_implement()
 

Modified: trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm_mock.py (213561 => 213562)


--- trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm_mock.py	2017-03-08 03:15:02 UTC (rev 213561)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm_mock.py	2017-03-08 03:46:19 UTC (rev 213562)
@@ -84,9 +84,15 @@
     def svn_revision(self, path):
         return '5678'
 
+    def native_revision(self, path):
+        return self.svn_revision(path)
+
     def timestamp_of_revision(self, path, revision):
         return '2013-02-01 08:48:05 +0000'
 
+    def timestamp_of_native_revision(self, path, revision):
+        return '2013-02-01 08:48:05 +0000'
+
     def create_patch(self, git_commit, changed_files=None):
         return "Patch1"
 

Modified: trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm_unittest.py (213561 => 213562)


--- trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm_unittest.py	2017-03-08 03:15:02 UTC (rev 213561)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm_unittest.py	2017-03-08 03:46:19 UTC (rev 213562)
@@ -902,6 +902,10 @@
     def test_head_svn_revision(self):
         self._shared_test_head_svn_revision()
 
+    def test_native_revision(self):
+        self.assertEqual(self.scm.head_svn_revision(), self.scm.native_revision('.'))
+        self.assertEqual(self.scm.native_revision('.'), '5')
+
     def test_propset_propget(self):
         filepath = os.path.join(self.svn_checkout_path, "test_file")
         expected_mime_type = "x-application/foo-bar"
@@ -1080,6 +1084,11 @@
         # self._shared_test_head_svn_revision().
         self.assertEqual(scm.head_svn_revision(), '')
 
+    def test_native_revision(self):
+        scm = self.tracking_scm
+        command = ['git', '-C', scm.checkout_root, 'rev-parse', 'HEAD']
+        self.assertEqual(scm.native_revision(scm.checkout_root), run_command(command).strip())
+
     def test_rename_files(self):
         scm = self.tracking_scm
 
@@ -1591,6 +1600,10 @@
     def test_head_svn_revision(self):
         self._shared_test_head_svn_revision()
 
+    def test_native_revision(self):
+        command = ['git', '-C', self.git_checkout_path, 'rev-parse', 'HEAD']
+        self.assertEqual(self.scm.native_revision(self.git_checkout_path), run_command(command).strip())
+
     def test_to_object_name(self):
         relpath = 'test_file_commit1'
         fullpath = os.path.realpath(os.path.join(self.git_checkout_path, relpath))
@@ -1672,3 +1685,15 @@
 
         scm._run_git = lambda args: 'Date: 2013-02-08 01:55:21 -0800'
         self.assertEqual(scm.timestamp_of_revision('some-path', '12345'), '2013-02-08T09:55:21Z')
+
+    def test_timestamp_of_native_revision(self):
+        scm = self.make_scm()
+        scm.find_checkout_root = lambda path: ''
+        scm._run_git = lambda args: '1360310749'
+        self.assertEqual(scm.timestamp_of_native_revision('some-path', '1a1c3b08814bc2a8c15b0f6db63cdce68f2aaa7a'), '2013-02-08T08:05:49Z')
+
+        scm._run_git = lambda args: '1360279923'
+        self.assertEqual(scm.timestamp_of_native_revision('some-path', '1a1c3b08814bc2a8c15b0f6db63cdce68f2aaa7a'), '2013-02-07T23:32:03Z')
+
+        scm._run_git = lambda args: '1360317321'
+        self.assertEqual(scm.timestamp_of_native_revision('some-path', '1a1c3b08814bc2a8c15b0f6db63cdce68f2aaa7a'), '2013-02-08T09:55:21Z')

Modified: trunk/Tools/Scripts/webkitpy/common/checkout/scm/svn.py (213561 => 213562)


--- trunk/Tools/Scripts/webkitpy/common/checkout/scm/svn.py	2017-03-08 03:15:02 UTC (rev 213561)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/scm/svn.py	2017-03-08 03:46:19 UTC (rev 213562)
@@ -268,6 +268,9 @@
     def svn_revision(self, path):
         return self.value_from_svn_info(path, 'Revision')
 
+    def native_revision(self, path):
+        return self.svn_revision(path)
+
     def timestamp_of_revision(self, path, revision):
         # We use --xml to get timestamps like 2013-02-08T08:18:04.964409Z
         repository_root = self.value_from_svn_info(self.checkout_root, 'Repository Root')
@@ -275,6 +278,9 @@
         match = re.search(r"^<date>(?P<value>.+)</date>\r?$", info_output, re.MULTILINE)
         return match.group('value')
 
+    def timestamp_of_native_revision(self, path, revision):
+        return self.timestamp_of_revision(path, revision)
+
     # FIXME: This method should be on Checkout.
     def create_patch(self, git_commit=None, changed_files=None, git_index=None):
         """Returns a byte array (str()) representing the patch file.

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/controllers/manager.py (213561 => 213562)


--- trunk/Tools/Scripts/webkitpy/layout_tests/controllers/manager.py	2017-03-08 03:15:02 UTC (rev 213561)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/controllers/manager.py	2017-03-08 03:46:19 UTC (rev 213562)
@@ -471,8 +471,8 @@
         # FIXME: This code is duplicated in PerfTestRunner._generate_results_dict
         for (name, path) in self._port.repository_paths():
             scm = SCMDetector(self._port.host.filesystem, self._port.host.executive).detect_scm_system(path) or self._port.host.scm()
-            revision = scm.svn_revision(path)
-            revisions[name] = {'revision': revision, 'timestamp': scm.timestamp_of_revision(path, revision)}
+            revision = scm.native_revision(path)
+            revisions[name] = {'revision': revision, 'timestamp': scm.timestamp_of_native_revision(path, revision)}
 
         _log.info("Uploading JSON files for master: %s builder: %s build: %s slave: %s to %s", master_name, builder_name, build_number, build_slave, hostname)
 

Modified: trunk/Tools/Scripts/webkitpy/performance_tests/perftestsrunner.py (213561 => 213562)


--- trunk/Tools/Scripts/webkitpy/performance_tests/perftestsrunner.py	2017-03-08 03:15:02 UTC (rev 213561)
+++ trunk/Tools/Scripts/webkitpy/performance_tests/perftestsrunner.py	2017-03-08 03:46:19 UTC (rev 213562)
@@ -270,8 +270,8 @@
         revisions = {}
         for (name, path) in self._port.repository_paths():
             scm = SCMDetector(self._host.filesystem, self._host.executive).detect_scm_system(path) or self._host.scm()
-            revision = scm.svn_revision(path)
-            revisions[name] = {'revision': revision, 'timestamp': scm.timestamp_of_revision(path, revision)}
+            revision = scm.native_revision(path)
+            revisions[name] = {'revision': revision, 'timestamp': scm.timestamp_of_native_revision(path, revision)}
 
         meta_info = {
             'description': description,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to