[Lldb-commits] [PATCH] D58219: [dotest] Fix compiler version number comparison

Frederic Riss via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Feb 13 16:49:09 PST 2019


friss created this revision.
friss added reviewers: zturner, labath.
Herald added a reviewer: serge-sans-paille.
Herald added a subscriber: jdoerfert.

dotest's version comparision function is just a lexicographical compare
of the version strings. This is obviously wrong. This patch implements
a numerical comparision of the individual version components instead.

Python is not my language of choice, please suggest a better implementation!


https://reviews.llvm.org/D58219

Files:
  packages/Python/lldbsuite/test/lldbtest.py


Index: packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- packages/Python/lldbsuite/test/lldbtest.py
+++ packages/Python/lldbsuite/test/lldbtest.py
@@ -1351,14 +1351,31 @@
 
         if (version is None):
             return True
+
+        def compare_version_strings(v1, v2):
+            split1 = v1.split('.')
+            split2 = v2.split('.')
+            while len(split1) > len(split2):
+                split2.append("0")
+            while len(split2) > len(split1):
+                split1.append("0")
+
+            versions = zip(split1, split2)
+            for (subv1, subv2) in versions:
+                diff = int(subv1) - int(subv2)
+                if diff != 0:
+                    return diff
+
+            return 0
+
         if (operator == '>'):
-            return self.getCompilerVersion() > version
+            return compare_version_strings(self.getCompilerVersion(), version) > 0
         if (operator == '>=' or operator == '=>'):
-            return self.getCompilerVersion() >= version
+            return compare_version_strings(self.getCompilerVersion(), version) >= 0
         if (operator == '<'):
-            return self.getCompilerVersion() < version
+            return compare_version_strings(self.getCompilerVersion(), version) < 0
         if (operator == '<=' or operator == '=<'):
-            return self.getCompilerVersion() <= version
+            return compare_version_strings(self.getCompilerVersion(), version) <= 0
         if (operator == '!=' or operator == '!' or operator == 'not'):
             return str(version) not in str(self.getCompilerVersion())
         return str(version) in str(self.getCompilerVersion())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58219.186777.patch
Type: text/x-patch
Size: 1743 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190214/7cba78c3/attachment.bin>


More information about the lldb-commits mailing list