dcoughlin created this revision.
dcoughlin added a reviewer: rizsotto.mailinglist.
dcoughlin added a subscriber: cfe-commits.

This patch improves compatibility with the perl version of scan-build.

The perl version of scan-build produces output report directories with 
increasing lexicographic ordering. This ordering is relied on by the CmpRuns.py 
tool in utils/analyzer  when comparing results for build commands with multiple 
steps. That tool tries to line up the output directory for each step between 
different runs of the analyzer based on the increasing directory name.

The python version of scan-build uses tmp file.mkdtemp() with a time stamp 
prefix to create report directories. The timestamp has a 1-second precision. 
This means that when analysis of a single build step takes less than a second 
the ordering property that CmpRuns.py expects will sometimes not hold, 
depending on the timing and the random suffix generated by mkdtemp(). 
Ultimately this causes CmpRuns to incorrectly correlate results from build 
steps and report spurious differences between runs.

To fix this, I propose increasing the precision of the timestamp used in 
scan-build-py to the microsecond level. This approach still has the same 
underlying issue -- but in practice, analysis of any build step is unlikely to 
take less than a millisecond.

What do you think?

https://reviews.llvm.org/D24163

Files:
  tools/scan-build-py/libscanbuild/report.py
  tools/scan-build-py/tests/unit/test_report.py

Index: tools/scan-build-py/tests/unit/test_report.py
===================================================================
--- tools/scan-build-py/tests/unit/test_report.py
+++ tools/scan-build-py/tests/unit/test_report.py
@@ -146,3 +146,16 @@
     def test_empty(self):
         self.assertEqual(
             sut.commonprefix([]), '')
+
+class ReportDirectoryTest(unittest.TestCase):
+
+    # Test that successive report directory names ascend in lexicographic
+    # order. This is required so that report directories from two runs of
+    # scan-build can be easily matched up to compare results.
+    def test_directory_name_comparison(self):
+        with libear.TemporaryDirectory() as tmpdir, \
+             sut.report_directory(tmpdir, False) as report_dir1, \
+             sut.report_directory(tmpdir, False) as report_dir2, \
+             sut.report_directory(tmpdir, False) as report_dir3:
+            self.assertLess(report_dir1, report_dir2)
+            self.assertLess(report_dir2, report_dir3)
Index: tools/scan-build-py/libscanbuild/report.py
===================================================================
--- tools/scan-build-py/libscanbuild/report.py
+++ tools/scan-build-py/libscanbuild/report.py
@@ -21,6 +21,7 @@
 import json
 import logging
 import contextlib
+import datetime
 from libscanbuild import duplicate_check
 from libscanbuild.clang import get_version
 
@@ -34,7 +35,7 @@
     hint -- could specify the parent directory of the output directory.
     keep -- a boolean value to keep or delete the empty report directory. """
 
-    stamp = time.strftime('scan-build-%Y-%m-%d-%H%M%S-', time.localtime())
+    stamp = 
datetime.datetime.now().strftime('scan-build-%Y-%m-%d-%H-%M-%S-%f-')
 
     parentdir = os.path.abspath(hint)
     if not os.path.exists(parentdir):


Index: tools/scan-build-py/tests/unit/test_report.py
===================================================================
--- tools/scan-build-py/tests/unit/test_report.py
+++ tools/scan-build-py/tests/unit/test_report.py
@@ -146,3 +146,16 @@
     def test_empty(self):
         self.assertEqual(
             sut.commonprefix([]), '')
+
+class ReportDirectoryTest(unittest.TestCase):
+
+    # Test that successive report directory names ascend in lexicographic
+    # order. This is required so that report directories from two runs of
+    # scan-build can be easily matched up to compare results.
+    def test_directory_name_comparison(self):
+        with libear.TemporaryDirectory() as tmpdir, \
+             sut.report_directory(tmpdir, False) as report_dir1, \
+             sut.report_directory(tmpdir, False) as report_dir2, \
+             sut.report_directory(tmpdir, False) as report_dir3:
+            self.assertLess(report_dir1, report_dir2)
+            self.assertLess(report_dir2, report_dir3)
Index: tools/scan-build-py/libscanbuild/report.py
===================================================================
--- tools/scan-build-py/libscanbuild/report.py
+++ tools/scan-build-py/libscanbuild/report.py
@@ -21,6 +21,7 @@
 import json
 import logging
 import contextlib
+import datetime
 from libscanbuild import duplicate_check
 from libscanbuild.clang import get_version
 
@@ -34,7 +35,7 @@
     hint -- could specify the parent directory of the output directory.
     keep -- a boolean value to keep or delete the empty report directory. """
 
-    stamp = time.strftime('scan-build-%Y-%m-%d-%H%M%S-', time.localtime())
+    stamp = datetime.datetime.now().strftime('scan-build-%Y-%m-%d-%H-%M-%S-%f-')
 
     parentdir = os.path.abspath(hint)
     if not os.path.exists(parentdir):
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to