blob: 48f021e54275cd85a0a4582efeb47ba05038c560 [file] [log] [blame]
Teresa Johnson7943fec2016-10-13 17:43:20 +00001//========- 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
16using namespace llvm;
17
18class HostTest : public testing::Test {
19 Triple Host;
Teresa Johnson7943fec2016-10-13 17:43:20 +000020
21protected:
22 bool isSupportedArchAndOS() {
Teresa Johnson7943fec2016-10-13 17:43:20 +000023 // Initially this is only testing detection of the number of
Mehdi Aminidb46b7d2016-10-19 22:36:07 +000024 // physical cores, which is currently only supported/tested for
25 // x86_64 Linux and Darwin.
Ahmed Bougachaf0fe1a82017-02-04 00:46:59 +000026 return (Host.getArch() == Triple::x86_64 &&
27 (Host.isOSDarwin() || Host.getOS() == Triple::Linux));
Teresa Johnson7943fec2016-10-13 17:43:20 +000028 }
Ahmed Bougachaf0fe1a82017-02-04 00:46:59 +000029
30 HostTest() : Host(Triple::normalize(sys::getProcessTriple())) {}
Teresa Johnson7943fec2016-10-13 17:43:20 +000031};
32
33TEST_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 Beyls9e463962017-03-30 07:24:49 +000041
42TEST(getLinuxHostCPUName, ARM) {
43 StringRef CortexA9ProcCpuinfo = R"(
44processor : 0
45model name : ARMv7 Processor rev 10 (v7l)
46BogoMIPS : 1393.66
47Features : half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpd32
48CPU implementer : 0x41
49CPU architecture: 7
50CPU variant : 0x2
51CPU part : 0xc09
52CPU revision : 10
53
54processor : 1
55model name : ARMv7 Processor rev 10 (v7l)
56BogoMIPS : 1393.66
57Features : half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpd32
58CPU implementer : 0x41
59CPU architecture: 7
60CPU variant : 0x2
61CPU part : 0xc09
62CPU revision : 10
63
64Hardware : Generic OMAP4 (Flattened Device Tree)
65Revision : 0000
66Serial : 0000000000000000
67)";
68
Kristof Beyls77ce4f62017-03-31 13:06:40 +000069 EXPECT_EQ(sys::detail::getHostCPUNameForARM(CortexA9ProcCpuinfo),
Kristof Beyls9e463962017-03-30 07:24:49 +000070 "cortex-a9");
Kristof Beyls77ce4f62017-03-31 13:06:40 +000071 EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x41\n"
72 "CPU part : 0xc0f"),
73 "cortex-a15");
Kristof Beyls9e463962017-03-30 07:24:49 +000074 // Verify that both CPU implementer and CPU part are checked:
Kristof Beyls77ce4f62017-03-31 13:06:40 +000075 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 Beyls9e463962017-03-30 07:24:49 +000081}