webkitpy should verify timestamp from CrashLogs while collecting all crash logs
authoraakash_jain@apple.com <aakash_jain@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 Mar 2016 21:40:38 +0000 (21:40 +0000)
committeraakash_jain@apple.com <aakash_jain@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 Mar 2016 21:40:38 +0000 (21:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=155000
<rdar://problem/24860219>

Reviewed by Alexey Proskuryakov.

* Scripts/webkitpy/common/system/crashlogs.py:
(CrashLogs._find_all_logs_darwin): Make sure that crash log timestamp is within expected
time range, because file modification time is not always accurate.
(CrashLogs.get_timestamp_from_logs): Parse the timestamp from logs.
* Scripts/webkitpy/common/system/crashlogs_unittest.py:
(CrashLogsTest.test_get_timestamp_from_logs_darwin): Testcase for above function.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197704 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/common/system/crashlogs.py
Tools/Scripts/webkitpy/common/system/crashlogs_unittest.py

index 3d7e4c8..d21601e 100644 (file)
@@ -1,3 +1,18 @@
+2016-03-07  Aakash Jain  <aakash_jain@apple.com>
+
+        webkitpy should verify timestamp from CrashLogs while collecting all crash logs
+        https://bugs.webkit.org/show_bug.cgi?id=155000
+        <rdar://problem/24860219>
+
+        Reviewed by Alexey Proskuryakov.
+
+        * Scripts/webkitpy/common/system/crashlogs.py:
+        (CrashLogs._find_all_logs_darwin): Make sure that crash log timestamp is within expected 
+        time range, because file modification time is not always accurate.
+        (CrashLogs.get_timestamp_from_logs): Parse the timestamp from logs.
+        * Scripts/webkitpy/common/system/crashlogs_unittest.py:
+        (CrashLogsTest.test_get_timestamp_from_logs_darwin): Testcase for above function.
+
 2016-03-06  Alexey Proskuryakov  <ap@apple.com>
 
         build-webkit prints an error on iOS simulator bots
index 33ef689..879a4b1 100644 (file)
@@ -29,6 +29,7 @@
 
 import codecs
 import re
+import datetime
 
 
 class CrashLogs(object):
@@ -139,6 +140,13 @@ class CrashLogs(object):
                     result_name = "Unknown"
                     pid = 0
                     log_contents = self._host.filesystem.read_text_file(path)
+                    # Verify timestamp from log contents
+                    crash_time = self.get_timestamp_from_log(log_contents)
+                    if crash_time is not None and newer_than is not None:
+                        start_time = datetime.datetime.fromtimestamp(float(newer_than))
+                        if crash_time < start_time:
+                            continue
+
                     match = first_line_regex.match(log_contents[0:log_contents.find('\n')])
                     if match:
                         process_name = match.group('process_name')
@@ -158,3 +166,14 @@ class CrashLogs(object):
         if include_errors and errors and len(crash_logs) == 0:
             return errors
         return crash_logs
+
+    def get_timestamp_from_log(self, log_contents):
+        date_match = re.search('Date/Time:\s+(.+?)\n', log_contents)
+        if not date_match:
+            return None
+        try:
+            crash_time_str = ' '.join(date_match.group(1).split(" ")[0:2])
+            crash_time = datetime.datetime.strptime(crash_time_str, '%Y-%m-%d %H:%M:%S.%f')
+        except ValueError:
+            return None
+        return crash_time
index cfc6053..6d68f08 100644 (file)
@@ -336,3 +336,16 @@ class CrashLogsTest(unittest.TestCase):
         filesystem.read_binary_file = bad_read
         log = crash_logs.find_newest_log("DumpRenderTree", 28531, include_errors=True)
         self.assertIn('IOError: No such file or directory', log)
+
+    def test_get_timestamp_from_logs_darwin(self):
+        if not SystemHost().platform.is_mac():
+            return
+
+        crash_report = make_mock_crash_report_darwin('DumpRenderTree', 28528)
+        crash_logs = CrashLogs(MockSystemHost())
+        crash_timestamp = crash_logs.get_timestamp_from_log(crash_report)
+        self.assertIn('2011-12-07 13:27:34.816', str(crash_timestamp))
+
+        crash_report = crash_report.replace("Date/Time", "")
+        crash_timestamp = crash_logs.get_timestamp_from_log(crash_report)
+        self.assertIsNone(crash_timestamp)