forked from OSchip/llvm-project
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
This commit is contained in:
parent
ab40f9d0ef
commit
a8b668432d
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
add_lldb_unittest(LLDBCoreTests
|
||||
ArchSpecTest.cpp
|
||||
BroadcasterTest.cpp
|
||||
DataExtractorTest.cpp
|
||||
ScalarTest.cpp
|
||||
|
|
Loading…
Reference in New Issue