1 //===-- PlatformDarwinTest.cpp --------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "gtest/gtest.h" 10 11 #include "Plugins/Platform/MacOSX/PlatformDarwin.h" 12 13 #include "llvm/ADT/StringRef.h" 14 15 #include <tuple> 16 17 using namespace lldb; 18 using namespace lldb_private; 19 20 struct PlatformDarwinTester : public PlatformDarwin { 21 public: 22 using PlatformDarwin::FindComponentInPath; 23 using PlatformDarwin::GetCompatibleArch; 24 }; 25 26 TEST(PlatformDarwinTest, TestParseVersionBuildDir) { 27 llvm::VersionTuple V; 28 llvm::StringRef D; 29 30 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("1.2.3 (test1)"); 31 EXPECT_EQ(llvm::VersionTuple(1, 2, 3), V); 32 EXPECT_EQ("test1", D); 33 34 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("2.3 (test2)"); 35 EXPECT_EQ(llvm::VersionTuple(2, 3), V); 36 EXPECT_EQ("test2", D); 37 38 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("3 (test3)"); 39 EXPECT_EQ(llvm::VersionTuple(3), V); 40 EXPECT_EQ("test3", D); 41 42 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("1.2.3 (test"); 43 EXPECT_EQ(llvm::VersionTuple(1, 2, 3), V); 44 EXPECT_EQ("test", D); 45 46 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("2.3.4 test"); 47 EXPECT_EQ(llvm::VersionTuple(2, 3, 4), V); 48 EXPECT_EQ("", D); 49 50 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("3.4.5"); 51 EXPECT_EQ(llvm::VersionTuple(3, 4, 5), V); 52 } 53 54 TEST(PlatformDarwinTest, FindComponentInPath) { 55 EXPECT_EQ("/path/to/foo", 56 PlatformDarwinTester::FindComponentInPath("/path/to/foo/", "foo")); 57 58 EXPECT_EQ("/path/to/foo", 59 PlatformDarwinTester::FindComponentInPath("/path/to/foo", "foo")); 60 61 EXPECT_EQ("/path/to/foobar", PlatformDarwinTester::FindComponentInPath( 62 "/path/to/foobar", "foo")); 63 64 EXPECT_EQ("/path/to/foobar", PlatformDarwinTester::FindComponentInPath( 65 "/path/to/foobar", "bar")); 66 67 EXPECT_EQ("", 68 PlatformDarwinTester::FindComponentInPath("/path/to/foo", "bar")); 69 } 70 71 TEST(PlatformDarwinTest, GetCompatibleArchARM64) { 72 const ArchSpec::Core core = ArchSpec::eCore_arm_arm64; 73 EXPECT_STREQ("arm64", PlatformDarwinTester::GetCompatibleArch(core, 0)); 74 EXPECT_STREQ("armv7", PlatformDarwinTester::GetCompatibleArch(core, 1)); 75 EXPECT_STREQ("armv4", PlatformDarwinTester::GetCompatibleArch(core, 10)); 76 EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 11)); 77 EXPECT_STREQ("thumbv7", PlatformDarwinTester::GetCompatibleArch(core, 12)); 78 EXPECT_STREQ("thumbv4t", PlatformDarwinTester::GetCompatibleArch(core, 21)); 79 EXPECT_STREQ("thumb", PlatformDarwinTester::GetCompatibleArch(core, 22)); 80 EXPECT_EQ(nullptr, PlatformDarwinTester::GetCompatibleArch(core, 23)); 81 } 82 83 TEST(PlatformDarwinTest, GetCompatibleArchARMv7f) { 84 const ArchSpec::Core core = ArchSpec::eCore_arm_armv7f; 85 EXPECT_STREQ("armv7f", PlatformDarwinTester::GetCompatibleArch(core, 0)); 86 EXPECT_STREQ("armv7", PlatformDarwinTester::GetCompatibleArch(core, 1)); 87 EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 6)); 88 EXPECT_STREQ("thumbv7f", PlatformDarwinTester::GetCompatibleArch(core, 7)); 89 } 90 91 TEST(PlatformDarwinTest, GetCompatibleArchARMv7k) { 92 const ArchSpec::Core core = ArchSpec::eCore_arm_armv7k; 93 EXPECT_STREQ("armv7k", PlatformDarwinTester::GetCompatibleArch(core, 0)); 94 EXPECT_STREQ("armv7", PlatformDarwinTester::GetCompatibleArch(core, 1)); 95 EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 6)); 96 EXPECT_STREQ("thumbv7k", PlatformDarwinTester::GetCompatibleArch(core, 7)); 97 } 98 99 TEST(PlatformDarwinTest, GetCompatibleArchARMv7s) { 100 const ArchSpec::Core core = ArchSpec::eCore_arm_armv7s; 101 EXPECT_STREQ("armv7s", PlatformDarwinTester::GetCompatibleArch(core, 0)); 102 EXPECT_STREQ("armv7", PlatformDarwinTester::GetCompatibleArch(core, 1)); 103 EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 6)); 104 EXPECT_STREQ("thumbv7s", PlatformDarwinTester::GetCompatibleArch(core, 7)); 105 } 106 107 TEST(PlatformDarwinTest, GetCompatibleArchARMv7m) { 108 const ArchSpec::Core core = ArchSpec::eCore_arm_armv7m; 109 EXPECT_STREQ("armv7m", PlatformDarwinTester::GetCompatibleArch(core, 0)); 110 EXPECT_STREQ("armv7", PlatformDarwinTester::GetCompatibleArch(core, 1)); 111 EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 6)); 112 EXPECT_STREQ("thumbv7m", PlatformDarwinTester::GetCompatibleArch(core, 7)); 113 } 114 115 TEST(PlatformDarwinTest, GetCompatibleArchARMv7em) { 116 const ArchSpec::Core core = ArchSpec::eCore_arm_armv7em; 117 EXPECT_STREQ("armv7em", PlatformDarwinTester::GetCompatibleArch(core, 0)); 118 EXPECT_STREQ("armv7", PlatformDarwinTester::GetCompatibleArch(core, 1)); 119 EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 6)); 120 EXPECT_STREQ("thumbv7em", PlatformDarwinTester::GetCompatibleArch(core, 7)); 121 } 122 123 TEST(PlatformDarwinTest, GetCompatibleArchARMv7) { 124 const ArchSpec::Core core = ArchSpec::eCore_arm_armv7; 125 EXPECT_STREQ("armv7", PlatformDarwinTester::GetCompatibleArch(core, 0)); 126 EXPECT_STREQ("armv6m", PlatformDarwinTester::GetCompatibleArch(core, 1)); 127 EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 5)); 128 EXPECT_STREQ("thumbv7", PlatformDarwinTester::GetCompatibleArch(core, 6)); 129 } 130 131 TEST(PlatformDarwinTest, GetCompatibleArchARMv6m) { 132 const ArchSpec::Core core = ArchSpec::eCore_arm_armv6m; 133 EXPECT_STREQ("armv6m", PlatformDarwinTester::GetCompatibleArch(core, 0)); 134 EXPECT_STREQ("armv6", PlatformDarwinTester::GetCompatibleArch(core, 1)); 135 EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 4)); 136 EXPECT_STREQ("thumbv6m", PlatformDarwinTester::GetCompatibleArch(core, 5)); 137 } 138 139 TEST(PlatformDarwinTest, GetCompatibleArchARMv6) { 140 const ArchSpec::Core core = ArchSpec::eCore_arm_armv6; 141 EXPECT_STREQ("armv6", PlatformDarwinTester::GetCompatibleArch(core, 0)); 142 EXPECT_STREQ("armv5", PlatformDarwinTester::GetCompatibleArch(core, 1)); 143 EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 3)); 144 EXPECT_STREQ("thumbv6", PlatformDarwinTester::GetCompatibleArch(core, 4)); 145 } 146 147 TEST(PlatformDarwinTest, GetCompatibleArchARMv5) { 148 const ArchSpec::Core core = ArchSpec::eCore_arm_armv5; 149 EXPECT_STREQ("armv5", PlatformDarwinTester::GetCompatibleArch(core, 0)); 150 EXPECT_STREQ("armv4", PlatformDarwinTester::GetCompatibleArch(core, 1)); 151 EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 2)); 152 EXPECT_STREQ("thumbv5", PlatformDarwinTester::GetCompatibleArch(core, 3)); 153 } 154 155 TEST(PlatformDarwinTest, GetCompatibleArchARMv4) { 156 const ArchSpec::Core core = ArchSpec::eCore_arm_armv4; 157 EXPECT_STREQ("armv4", PlatformDarwinTester::GetCompatibleArch(core, 0)); 158 EXPECT_STREQ("arm", PlatformDarwinTester::GetCompatibleArch(core, 1)); 159 EXPECT_STREQ("thumbv4t", PlatformDarwinTester::GetCompatibleArch(core, 2)); 160 EXPECT_STREQ("thumb", PlatformDarwinTester::GetCompatibleArch(core, 3)); 161 } 162