diff options
Diffstat (limited to 'unittests/Support/Host.cpp')
-rw-r--r-- | unittests/Support/Host.cpp | 92 |
1 files changed, 80 insertions, 12 deletions
diff --git a/unittests/Support/Host.cpp b/unittests/Support/Host.cpp index 934a604954272..fd53697793c7e 100644 --- a/unittests/Support/Host.cpp +++ b/unittests/Support/Host.cpp @@ -17,25 +17,17 @@ using namespace llvm; class HostTest : public testing::Test { Triple Host; - SmallVector<std::pair<Triple::ArchType, Triple::OSType>, 4> SupportedArchAndOSs; protected: bool isSupportedArchAndOS() { - if (is_contained(SupportedArchAndOSs, std::make_pair(Host.getArch(), Host.getOS()))) - return true; - - return false; - } - - HostTest() { - Host.setTriple(Triple::normalize(sys::getProcessTriple())); - // Initially this is only testing detection of the number of // physical cores, which is currently only supported/tested for // x86_64 Linux and Darwin. - SupportedArchAndOSs.push_back(std::make_pair(Triple::x86_64, Triple::Linux)); - SupportedArchAndOSs.push_back(std::make_pair(Triple::x86_64, Triple::Darwin)); + return (Host.getArch() == Triple::x86_64 && + (Host.isOSDarwin() || Host.getOS() == Triple::Linux)); } + + HostTest() : Host(Triple::normalize(sys::getProcessTriple())) {} }; TEST_F(HostTest, NumPhysicalCores) { @@ -46,3 +38,79 @@ TEST_F(HostTest, NumPhysicalCores) { else ASSERT_EQ(Num, -1); } + +TEST(getLinuxHostCPUName, ARM) { + StringRef CortexA9ProcCpuinfo = R"( +processor : 0 +model name : ARMv7 Processor rev 10 (v7l) +BogoMIPS : 1393.66 +Features : half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpd32 +CPU implementer : 0x41 +CPU architecture: 7 +CPU variant : 0x2 +CPU part : 0xc09 +CPU revision : 10 + +processor : 1 +model name : ARMv7 Processor rev 10 (v7l) +BogoMIPS : 1393.66 +Features : half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpd32 +CPU implementer : 0x41 +CPU architecture: 7 +CPU variant : 0x2 +CPU part : 0xc09 +CPU revision : 10 + +Hardware : Generic OMAP4 (Flattened Device Tree) +Revision : 0000 +Serial : 0000000000000000 +)"; + + EXPECT_EQ(sys::detail::getHostCPUNameForARM(CortexA9ProcCpuinfo), + "cortex-a9"); + EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x41\n" + "CPU part : 0xc0f"), + "cortex-a15"); + // Verify that both CPU implementer and CPU part are checked: + EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x40\n" + "CPU part : 0xc0f"), + "generic"); + EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x51\n" + "CPU part : 0x06f"), + "krait"); +} + +TEST(getLinuxHostCPUName, AArch64) { + EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x41\n" + "CPU part : 0xd03"), + "cortex-a53"); + // Verify that both CPU implementer and CPU part are checked: + EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x40\n" + "CPU part : 0xd03"), + "generic"); + EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x51\n" + "CPU part : 0x201"), + "kryo"); + + // MSM8992/4 weirdness + StringRef MSM8992ProcCpuInfo = R"( +Processor : AArch64 Processor rev 3 (aarch64) +processor : 0 +processor : 1 +processor : 2 +processor : 3 +processor : 4 +processor : 5 +Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 +CPU implementer : 0x41 +CPU architecture: 8 +CPU variant : 0x0 +CPU part : 0xd03 +CPU revision : 3 + +Hardware : Qualcomm Technologies, Inc MSM8992 +)"; + + EXPECT_EQ(sys::detail::getHostCPUNameForARM(MSM8992ProcCpuInfo), + "cortex-a53"); +} |