diff options
| author | Zachary Turner <zturner@google.com> | 2016-09-13 20:40:26 +0000 | 
|---|---|---|
| committer | Zachary Turner <zturner@google.com> | 2016-09-13 20:40:26 +0000 | 
| commit | a8b668432d6c4517cd2326b259fb58842016bce5 (patch) | |
| tree | 65bce750233fc2e08ee293bbf3e0039dabc3bb9d | |
| parent | ab40f9d0ef9d8e8afefce9a4f44239fa23e76250 (diff) | |
| download | bcm5719-llvm-a8b668432d6c4517cd2326b259fb58842016bce5.tar.gz bcm5719-llvm-a8b668432d6c4517cd2326b259fb58842016bce5.zip  | |
Add some unit tests for ArchSpec.
I'm was trying to do some cleanup and code modernization and in
doing so I needed to change ParseMachCPUDashSubtypeTriple to take
a StringRef.  To ensure I don't break anything, I'm adding some
unit tests for this function.  As a side benefit, this also expands
test coverage of this function to all platforms, since in general
this code would rarely be exercised on non Mac platforms, and never
in the test suite.
llvm-svn: 281387
| -rw-r--r-- | lldb/include/lldb/Core/ArchSpec.h | 2 | ||||
| -rw-r--r-- | lldb/source/Core/ArchSpec.cpp | 4 | ||||
| -rw-r--r-- | lldb/unittests/Core/ArchSpecTest.cpp | 103 | ||||
| -rw-r--r-- | lldb/unittests/Core/CMakeLists.txt | 1 | 
4 files changed, 108 insertions, 2 deletions
diff --git a/lldb/include/lldb/Core/ArchSpec.h b/lldb/include/lldb/Core/ArchSpec.h index cd7449eff0a..18bf96e752f 100644 --- a/lldb/include/lldb/Core/ArchSpec.h +++ b/lldb/include/lldb/Core/ArchSpec.h @@ -625,6 +625,8 @@ protected:  //------------------------------------------------------------------  bool operator<(const ArchSpec &lhs, const ArchSpec &rhs); +bool ParseMachCPUDashSubtypeTriple(const char *triple_cstr, ArchSpec &arch); +  } // namespace lldb_private  #endif // #if defined(__cplusplus) diff --git a/lldb/source/Core/ArchSpec.cpp b/lldb/source/Core/ArchSpec.cpp index 285e30e3594..34e8545e4d5 100644 --- a/lldb/source/Core/ArchSpec.cpp +++ b/lldb/source/Core/ArchSpec.cpp @@ -821,8 +821,8 @@ bool ArchSpec::SetTriple(const llvm::Triple &triple) {    return IsValid();  } -static bool ParseMachCPUDashSubtypeTriple(const char *triple_cstr, -                                          ArchSpec &arch) { +bool lldb_private::ParseMachCPUDashSubtypeTriple(const char *triple_cstr, +                                                 ArchSpec &arch) {    // Accept "12-10" or "12.10" as cpu type/subtype    if (isdigit(triple_cstr[0])) {      char *end = nullptr; diff --git a/lldb/unittests/Core/ArchSpecTest.cpp b/lldb/unittests/Core/ArchSpecTest.cpp new file mode 100644 index 00000000000..995cd1af315 --- /dev/null +++ b/lldb/unittests/Core/ArchSpecTest.cpp @@ -0,0 +1,103 @@ +//===-- ArchSpecTest.cpp ----------------------------------------*- C++ -*-===// +// +//                     The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "gtest/gtest.h" + +#include "lldb/Core/ArchSpec.h" + +using namespace lldb; +using namespace lldb_private; + +TEST(ArchSpecTest, TestParseMachCPUDashSubtypeTripleSimple) { + +  // Success conditions.  Valid cpu/subtype combinations using both - and . +  ArchSpec AS; +  EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("12-10", AS)); +  EXPECT_EQ(12, AS.GetMachOCPUType()); +  EXPECT_EQ(10, AS.GetMachOCPUSubType()); + +  AS = ArchSpec(); +  EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("12-15", AS)); +  EXPECT_EQ(12, AS.GetMachOCPUType()); +  EXPECT_EQ(15, AS.GetMachOCPUSubType()); + +  AS = ArchSpec(); +  EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("12.15", AS)); +  EXPECT_EQ(12, AS.GetMachOCPUType()); +  EXPECT_EQ(15, AS.GetMachOCPUSubType()); + +  // Failure conditions. + +  // Valid string, unknown cpu/subtype. +  AS = ArchSpec(); +  EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("13.11", AS)); +  EXPECT_EQ(0, AS.GetMachOCPUType()); +  EXPECT_EQ(0, AS.GetMachOCPUSubType()); + +  // Missing / invalid cpu or subtype +  AS = ArchSpec(); +  EXPECT_FALSE(ParseMachCPUDashSubtypeTriple("13", AS)); + +  AS = ArchSpec(); +  EXPECT_FALSE(ParseMachCPUDashSubtypeTriple("13.A", AS)); + +  AS = ArchSpec(); +  EXPECT_FALSE(ParseMachCPUDashSubtypeTriple("A.13", AS)); + +  // Empty string. +  AS = ArchSpec(); +  EXPECT_FALSE(ParseMachCPUDashSubtypeTriple("", AS)); +} + +TEST(ArchSpecTest, TestParseMachCPUDashSubtypeTripleExtra) { +  ArchSpec AS; +  EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("12-15-vendor-os", AS)); +  EXPECT_EQ(12, AS.GetMachOCPUType()); +  EXPECT_EQ(15, AS.GetMachOCPUSubType()); +  EXPECT_EQ("vendor", AS.GetTriple().getVendorName()); +  EXPECT_EQ("os", AS.GetTriple().getOSName()); + +  AS = ArchSpec(); +  EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("12-10-vendor-os-name", AS)); +  EXPECT_EQ(12, AS.GetMachOCPUType()); +  EXPECT_EQ(10, AS.GetMachOCPUSubType()); +  EXPECT_EQ("vendor", AS.GetTriple().getVendorName()); +  EXPECT_EQ("os", AS.GetTriple().getOSName()); + +  AS = ArchSpec(); +  EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("12-15-vendor.os-name", AS)); +  EXPECT_EQ(12, AS.GetMachOCPUType()); +  EXPECT_EQ(15, AS.GetMachOCPUSubType()); +  EXPECT_EQ("vendor.os", AS.GetTriple().getVendorName()); +  EXPECT_EQ("name", AS.GetTriple().getOSName()); + +  // These there should parse correctly, but the vendor / OS should be defaulted +  // since they are unrecognized. +  AS = ArchSpec(); +  EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("12-10-vendor", AS)); +  EXPECT_EQ(12, AS.GetMachOCPUType()); +  EXPECT_EQ(10, AS.GetMachOCPUSubType()); +  EXPECT_EQ("apple", AS.GetTriple().getVendorName()); +  EXPECT_EQ("", AS.GetTriple().getOSName()); + +  AS = ArchSpec(); +  EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("12.10.10", AS)); +  EXPECT_EQ(12, AS.GetMachOCPUType()); +  EXPECT_EQ(10, AS.GetMachOCPUSubType()); +  EXPECT_EQ("apple", AS.GetTriple().getVendorName()); +  EXPECT_EQ("", AS.GetTriple().getOSName()); + +  AS = ArchSpec(); +  EXPECT_TRUE(ParseMachCPUDashSubtypeTriple("12-10.10", AS)); +  EXPECT_EQ(12, AS.GetMachOCPUType()); +  EXPECT_EQ(10, AS.GetMachOCPUSubType()); +  EXPECT_EQ("apple", AS.GetTriple().getVendorName()); +  EXPECT_EQ("", AS.GetTriple().getOSName()); +} + diff --git a/lldb/unittests/Core/CMakeLists.txt b/lldb/unittests/Core/CMakeLists.txt index 17edbfe34ed..8ab43d666cf 100644 --- a/lldb/unittests/Core/CMakeLists.txt +++ b/lldb/unittests/Core/CMakeLists.txt @@ -1,4 +1,5 @@  add_lldb_unittest(LLDBCoreTests +  ArchSpecTest.cpp    BroadcasterTest.cpp    DataExtractorTest.cpp    ScalarTest.cpp  | 

