[Lldb-commits] [lldb] r348440 - Add a unit test for ArchSpec matching to document how it behaves (and test it).

Adrian Prantl via lldb-commits lldb-commits at lists.llvm.org
Wed Dec 5 16:43:55 PST 2018


Author: adrian
Date: Wed Dec  5 16:43:55 2018
New Revision: 348440

URL: http://llvm.org/viewvc/llvm-project?rev=348440&view=rev
Log:
Add a unit test for ArchSpec matching to document how it behaves (and test it).

Modified:
    lldb/trunk/source/Utility/ArchSpec.cpp
    lldb/trunk/unittests/Utility/ArchSpecTest.cpp

Modified: lldb/trunk/source/Utility/ArchSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/ArchSpec.cpp?rev=348440&r1=348439&r2=348440&view=diff
==============================================================================
--- lldb/trunk/source/Utility/ArchSpec.cpp (original)
+++ lldb/trunk/source/Utility/ArchSpec.cpp Wed Dec  5 16:43:55 2018
@@ -1019,7 +1019,7 @@ bool ArchSpec::IsCompatibleMatch(const A
   return IsEqualTo(rhs, false);
 }
 
-static bool isCompatibleEnvironment(llvm::Triple::EnvironmentType lhs,
+static bool IsCompatibleEnvironment(llvm::Triple::EnvironmentType lhs,
                                     llvm::Triple::EnvironmentType rhs) {
   if (lhs == rhs)
     return true;
@@ -1096,7 +1096,7 @@ bool ArchSpec::IsEqualTo(const ArchSpec
     const llvm::Triple::EnvironmentType rhs_triple_env =
         rhs_triple.getEnvironment();
 
-    if (!isCompatibleEnvironment(lhs_triple_env, rhs_triple_env))
+    if (!IsCompatibleEnvironment(lhs_triple_env, rhs_triple_env))
       return false;
     return true;
   }

Modified: lldb/trunk/unittests/Utility/ArchSpecTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/ArchSpecTest.cpp?rev=348440&r1=348439&r2=348440&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/ArchSpecTest.cpp (original)
+++ lldb/trunk/unittests/Utility/ArchSpecTest.cpp Wed Dec  5 16:43:55 2018
@@ -171,3 +171,53 @@ TEST(ArchSpecTest, MergeFromMachOUnknown
   A.MergeFrom(B);
   ASSERT_EQ(A.GetCore(), ArchSpec::eCore_uknownMach64);
 }
+
+TEST(ArchSpecTest, Compatibility) {
+  {
+    ArchSpec A("x86_64-apple-macosx10.12");
+    ArchSpec B("x86_64-apple-macosx10.12");
+    ASSERT_TRUE(A.IsExactMatch(B));
+    ASSERT_TRUE(A.IsCompatibleMatch(B));
+  }
+  {
+    // The version information is auxiliary to support availablity but
+    // doesn't affect compatibility.
+    ArchSpec A("x86_64-apple-macosx10.11");
+    ArchSpec B("x86_64-apple-macosx10.12");
+    ASSERT_TRUE(A.IsExactMatch(B));
+    ASSERT_TRUE(A.IsCompatibleMatch(B));
+  }
+  {
+    ArchSpec A("x86_64-apple-macosx10.13");
+    ArchSpec B("x86_64h-apple-macosx10.13");
+    ASSERT_FALSE(A.IsExactMatch(B));
+    ASSERT_TRUE(A.IsCompatibleMatch(B));
+  }
+  {
+    ArchSpec A("x86_64-apple-macosx");
+    ArchSpec B("x86_64-apple-ios-simulator");
+    ASSERT_FALSE(A.IsExactMatch(B));
+    ASSERT_FALSE(A.IsCompatibleMatch(B));
+  }
+  {
+    ArchSpec A("x86_64-*-*");
+    ArchSpec B("x86_64-apple-ios-simulator");
+    ASSERT_FALSE(A.IsExactMatch(B));
+    ASSERT_FALSE(A.IsCompatibleMatch(B));
+  }
+  {
+    ArchSpec A("arm64-*-*");
+    ArchSpec B("arm64-apple-ios");
+    ASSERT_FALSE(A.IsExactMatch(B));
+    // FIXME: This looks unintuitive and we should investigate whether
+    // thi is the desired behavior.
+    ASSERT_FALSE(A.IsCompatibleMatch(B));
+  }
+  {
+    ArchSpec A("x86_64-*-*");
+    ArchSpec B("x86_64-apple-ios-simulator");
+    ASSERT_FALSE(A.IsExactMatch(B));
+    // FIXME: See above, though the extra environment complicates things.
+    ASSERT_FALSE(A.IsCompatibleMatch(B));
+  }
+}




More information about the lldb-commits mailing list