Teresa Johnson | 7943fec | 2016-10-13 17:43:20 +0000 | [diff] [blame] | 1 | //========- unittests/Support/Host.cpp - Host.cpp tests --------------========// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/Support/Host.h" |
| 11 | #include "llvm/ADT/SmallVector.h" |
| 12 | #include "llvm/ADT/Triple.h" |
| 13 | |
| 14 | #include "gtest/gtest.h" |
| 15 | |
| 16 | using namespace llvm; |
| 17 | |
| 18 | class HostTest : public testing::Test { |
| 19 | Triple Host; |
Teresa Johnson | 7943fec | 2016-10-13 17:43:20 +0000 | [diff] [blame] | 20 | |
| 21 | protected: |
| 22 | bool isSupportedArchAndOS() { |
Teresa Johnson | 7943fec | 2016-10-13 17:43:20 +0000 | [diff] [blame] | 23 | // Initially this is only testing detection of the number of |
Mehdi Amini | db46b7d | 2016-10-19 22:36:07 +0000 | [diff] [blame] | 24 | // physical cores, which is currently only supported/tested for |
| 25 | // x86_64 Linux and Darwin. |
Ahmed Bougacha | f0fe1a8 | 2017-02-04 00:46:59 +0000 | [diff] [blame] | 26 | return (Host.getArch() == Triple::x86_64 && |
| 27 | (Host.isOSDarwin() || Host.getOS() == Triple::Linux)); |
Teresa Johnson | 7943fec | 2016-10-13 17:43:20 +0000 | [diff] [blame] | 28 | } |
Ahmed Bougacha | f0fe1a8 | 2017-02-04 00:46:59 +0000 | [diff] [blame] | 29 | |
| 30 | HostTest() : Host(Triple::normalize(sys::getProcessTriple())) {} |
Teresa Johnson | 7943fec | 2016-10-13 17:43:20 +0000 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | TEST_F(HostTest, NumPhysicalCores) { |
| 34 | int Num = sys::getHostNumPhysicalCores(); |
| 35 | |
| 36 | if (isSupportedArchAndOS()) |
| 37 | ASSERT_GT(Num, 0); |
| 38 | else |
| 39 | ASSERT_EQ(Num, -1); |
| 40 | } |
Kristof Beyls | 9e46396 | 2017-03-30 07:24:49 +0000 | [diff] [blame] | 41 | |
| 42 | TEST(getLinuxHostCPUName, ARM) { |
| 43 | StringRef CortexA9ProcCpuinfo = R"( |
| 44 | processor : 0 |
| 45 | model name : ARMv7 Processor rev 10 (v7l) |
| 46 | BogoMIPS : 1393.66 |
| 47 | Features : half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpd32 |
| 48 | CPU implementer : 0x41 |
| 49 | CPU architecture: 7 |
| 50 | CPU variant : 0x2 |
| 51 | CPU part : 0xc09 |
| 52 | CPU revision : 10 |
| 53 | |
| 54 | processor : 1 |
| 55 | model name : ARMv7 Processor rev 10 (v7l) |
| 56 | BogoMIPS : 1393.66 |
| 57 | Features : half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpd32 |
| 58 | CPU implementer : 0x41 |
| 59 | CPU architecture: 7 |
| 60 | CPU variant : 0x2 |
| 61 | CPU part : 0xc09 |
| 62 | CPU revision : 10 |
| 63 | |
| 64 | Hardware : Generic OMAP4 (Flattened Device Tree) |
| 65 | Revision : 0000 |
| 66 | Serial : 0000000000000000 |
| 67 | )"; |
| 68 | |
Kristof Beyls | 77ce4f6 | 2017-03-31 13:06:40 +0000 | [diff] [blame^] | 69 | EXPECT_EQ(sys::detail::getHostCPUNameForARM(CortexA9ProcCpuinfo), |
Kristof Beyls | 9e46396 | 2017-03-30 07:24:49 +0000 | [diff] [blame] | 70 | "cortex-a9"); |
Kristof Beyls | 77ce4f6 | 2017-03-31 13:06:40 +0000 | [diff] [blame^] | 71 | EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x41\n" |
| 72 | "CPU part : 0xc0f"), |
| 73 | "cortex-a15"); |
Kristof Beyls | 9e46396 | 2017-03-30 07:24:49 +0000 | [diff] [blame] | 74 | // Verify that both CPU implementer and CPU part are checked: |
Kristof Beyls | 77ce4f6 | 2017-03-31 13:06:40 +0000 | [diff] [blame^] | 75 | EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x40\n" |
| 76 | "CPU part : 0xc0f"), |
| 77 | "generic"); |
| 78 | EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x51\n" |
| 79 | "CPU part : 0x06f"), |
| 80 | "krait"); |
Kristof Beyls | 9e46396 | 2017-03-30 07:24:49 +0000 | [diff] [blame] | 81 | } |