1 //===-- ArchSpecTest.cpp ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "gtest/gtest.h"
12 #include "lldb/Core/ArchSpec.h"
14 #include "llvm/Support/MachO.h"
17 using namespace lldb_private;
19 TEST(ArchSpecTest, TestParseMachCPUDashSubtypeTripleSimple) {
21 // Success conditions. Valid cpu/subtype combinations using both - and .
23 EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("12-10", AS));
24 EXPECT_EQ(12u, AS.GetMachOCPUType());
25 EXPECT_EQ(10u, AS.GetMachOCPUSubType());
28 EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("12-15", AS));
29 EXPECT_EQ(12u, AS.GetMachOCPUType());
30 EXPECT_EQ(15u, AS.GetMachOCPUSubType());
33 EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("12.15", AS));
34 EXPECT_EQ(12u, AS.GetMachOCPUType());
35 EXPECT_EQ(15u, AS.GetMachOCPUSubType());
37 // Failure conditions.
39 // Valid string, unknown cpu/subtype.
41 EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("13.11", AS));
42 EXPECT_EQ(0u, AS.GetMachOCPUType());
43 EXPECT_EQ(0u, AS.GetMachOCPUSubType());
45 // Missing / invalid cpu or subtype
47 EXPECT_FALSE(ParseMachCPUDashSubtypeTriple("13", AS));
50 EXPECT_FALSE(ParseMachCPUDashSubtypeTriple("13.A", AS));
53 EXPECT_FALSE(ParseMachCPUDashSubtypeTriple("A.13", AS));
57 EXPECT_FALSE(ParseMachCPUDashSubtypeTriple("", AS));
60 TEST(ArchSpecTest, TestParseMachCPUDashSubtypeTripleExtra) {
62 EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("12-15-vendor-os", AS));
63 EXPECT_EQ(12u, AS.GetMachOCPUType());
64 EXPECT_EQ(15u, AS.GetMachOCPUSubType());
65 EXPECT_EQ("vendor", AS.GetTriple().getVendorName());
66 EXPECT_EQ("os", AS.GetTriple().getOSName());
69 EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("12-10-vendor-os-name", AS));
70 EXPECT_EQ(12u, AS.GetMachOCPUType());
71 EXPECT_EQ(10u, AS.GetMachOCPUSubType());
72 EXPECT_EQ("vendor", AS.GetTriple().getVendorName());
73 EXPECT_EQ("os", AS.GetTriple().getOSName());
76 EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("12-15-vendor.os-name", AS));
77 EXPECT_EQ(12u, AS.GetMachOCPUType());
78 EXPECT_EQ(15u, AS.GetMachOCPUSubType());
79 EXPECT_EQ("vendor.os", AS.GetTriple().getVendorName());
80 EXPECT_EQ("name", AS.GetTriple().getOSName());
82 // These there should parse correctly, but the vendor / OS should be defaulted
83 // since they are unrecognized.
85 EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("12-10-vendor", AS));
86 EXPECT_EQ(12u, AS.GetMachOCPUType());
87 EXPECT_EQ(10u, AS.GetMachOCPUSubType());
88 EXPECT_EQ("apple", AS.GetTriple().getVendorName());
89 EXPECT_EQ("", AS.GetTriple().getOSName());
92 EXPECT_FALSE(ParseMachCPUDashSubtypeTriple("12.10.10", AS));
95 EXPECT_FALSE(ParseMachCPUDashSubtypeTriple("12-10.10", AS));
98 TEST(ArchSpecTest, TestSetTriple) {
101 // Various flavors of valid triples.
102 EXPECT_TRUE(AS.SetTriple("12-10-apple-darwin"));
103 EXPECT_EQ(uint32_t(llvm::MachO::CPU_TYPE_ARM), AS.GetMachOCPUType());
104 EXPECT_EQ(10u, AS.GetMachOCPUSubType());
105 EXPECT_TRUE(llvm::StringRef(AS.GetTriple().str())
106 .consume_front("armv7f-apple-darwin"));
107 EXPECT_EQ(ArchSpec::eCore_arm_armv7f, AS.GetCore());
110 EXPECT_TRUE(AS.SetTriple("18.100-apple-darwin"));
111 EXPECT_EQ(uint32_t(llvm::MachO::CPU_TYPE_POWERPC), AS.GetMachOCPUType());
112 EXPECT_EQ(100u, AS.GetMachOCPUSubType());
113 EXPECT_TRUE(llvm::StringRef(AS.GetTriple().str())
114 .consume_front("powerpc-apple-darwin"));
115 EXPECT_EQ(ArchSpec::eCore_ppc_ppc970, AS.GetCore());
118 EXPECT_TRUE(AS.SetTriple("i686-pc-windows"));
119 EXPECT_EQ(llvm::Triple::x86, AS.GetTriple().getArch());
120 EXPECT_EQ(llvm::Triple::PC, AS.GetTriple().getVendor());
121 EXPECT_EQ(llvm::Triple::Win32, AS.GetTriple().getOS());
123 llvm::StringRef(AS.GetTriple().str()).consume_front("i686-pc-windows"));
124 EXPECT_STREQ("i686", AS.GetArchitectureName());
125 EXPECT_EQ(ArchSpec::eCore_x86_32_i686, AS.GetCore());
127 // Various flavors of invalid triples.
129 EXPECT_FALSE(AS.SetTriple("unknown-unknown-unknown"));
132 EXPECT_FALSE(AS.SetTriple("unknown"));
135 EXPECT_FALSE(AS.SetTriple(""));
138 TEST(ArchSpecTest, MergeFrom) {
140 ArchSpec B("x86_64-pc-linux");
142 EXPECT_FALSE(A.IsValid());
143 ASSERT_TRUE(B.IsValid());
144 EXPECT_EQ(llvm::Triple::ArchType::x86_64, B.GetTriple().getArch());
145 EXPECT_EQ(llvm::Triple::VendorType::PC, B.GetTriple().getVendor());
146 EXPECT_EQ(llvm::Triple::OSType::Linux, B.GetTriple().getOS());
147 EXPECT_EQ(ArchSpec::eCore_x86_64_x86_64, B.GetCore());
150 ASSERT_TRUE(A.IsValid());
151 EXPECT_EQ(llvm::Triple::ArchType::x86_64, A.GetTriple().getArch());
152 EXPECT_EQ(llvm::Triple::VendorType::PC, A.GetTriple().getVendor());
153 EXPECT_EQ(llvm::Triple::OSType::Linux, A.GetTriple().getOS());
154 EXPECT_EQ(ArchSpec::eCore_x86_64_x86_64, A.GetCore());