2016-10-14 01:43:20 +08:00
|
|
|
//========- unittests/Support/Host.cpp - Host.cpp tests --------------========//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Support/Host.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/Triple.h"
|
2017-07-07 17:53:47 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
#include "llvm/Support/Program.h"
|
2016-10-14 01:43:20 +08:00
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2017-07-07 17:53:47 +08:00
|
|
|
#define ASSERT_NO_ERROR(x) \
|
|
|
|
if (std::error_code ASSERT_NO_ERROR_ec = x) { \
|
|
|
|
SmallString<128> MessageStorage; \
|
|
|
|
raw_svector_ostream Message(MessageStorage); \
|
|
|
|
Message << #x ": did not return errc::success.\n" \
|
|
|
|
<< "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
|
|
|
|
<< "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
|
|
|
|
GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
|
|
|
|
} else { \
|
|
|
|
}
|
|
|
|
|
2016-10-14 01:43:20 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
class HostTest : public testing::Test {
|
|
|
|
Triple Host;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool isSupportedArchAndOS() {
|
|
|
|
// Initially this is only testing detection of the number of
|
2016-10-20 06:36:07 +08:00
|
|
|
// physical cores, which is currently only supported/tested for
|
|
|
|
// x86_64 Linux and Darwin.
|
2017-02-04 08:46:59 +08:00
|
|
|
return (Host.getArch() == Triple::x86_64 &&
|
|
|
|
(Host.isOSDarwin() || Host.getOS() == Triple::Linux));
|
2016-10-14 01:43:20 +08:00
|
|
|
}
|
2017-02-04 08:46:59 +08:00
|
|
|
|
|
|
|
HostTest() : Host(Triple::normalize(sys::getProcessTriple())) {}
|
2016-10-14 01:43:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(HostTest, NumPhysicalCores) {
|
|
|
|
int Num = sys::getHostNumPhysicalCores();
|
|
|
|
|
|
|
|
if (isSupportedArchAndOS())
|
|
|
|
ASSERT_GT(Num, 0);
|
|
|
|
else
|
|
|
|
ASSERT_EQ(Num, -1);
|
|
|
|
}
|
Refactor getHostCPUName to allow testing on non-native hardware.
This refactors getHostCPUName so that for the architectures that get the
host cpu info on linux from /proc/cpuinfo, the /proc/cpuinfo parsing
logic is present in the build, even if it wasn't built on a linux system
for that architecture.
Since the code is present in the build, we can then test that code also
on other systems, i.e. we don't need to have buildbots setup for all
architectures on linux to be able to test this. Instead, developers will
test this as part of the regression test run.
As an example, a few unit tests are added to test getHostCPUName for ARM
running linux. A unit test is preferred over a lit-based test, since the
expectation is that in the future, the functionality here will grow over
what can be tested with "llc -mcpu=native".
This is a preparation step to enable implementing the range of
improvements discussed on PR30516, such as adding AArch64 support,
support for big.LITTLE systems, reducing code duplication.
Differential Revision: https://reviews.llvm.org/D31236
llvm-svn: 299060
2017-03-30 15:24:49 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
)";
|
|
|
|
|
2017-03-31 21:06:40 +08:00
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(CortexA9ProcCpuinfo),
|
Refactor getHostCPUName to allow testing on non-native hardware.
This refactors getHostCPUName so that for the architectures that get the
host cpu info on linux from /proc/cpuinfo, the /proc/cpuinfo parsing
logic is present in the build, even if it wasn't built on a linux system
for that architecture.
Since the code is present in the build, we can then test that code also
on other systems, i.e. we don't need to have buildbots setup for all
architectures on linux to be able to test this. Instead, developers will
test this as part of the regression test run.
As an example, a few unit tests are added to test getHostCPUName for ARM
running linux. A unit test is preferred over a lit-based test, since the
expectation is that in the future, the functionality here will grow over
what can be tested with "llc -mcpu=native".
This is a preparation step to enable implementing the range of
improvements discussed on PR30516, such as adding AArch64 support,
support for big.LITTLE systems, reducing code duplication.
Differential Revision: https://reviews.llvm.org/D31236
llvm-svn: 299060
2017-03-30 15:24:49 +08:00
|
|
|
"cortex-a9");
|
2017-03-31 21:06:40 +08:00
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x41\n"
|
|
|
|
"CPU part : 0xc0f"),
|
|
|
|
"cortex-a15");
|
Refactor getHostCPUName to allow testing on non-native hardware.
This refactors getHostCPUName so that for the architectures that get the
host cpu info on linux from /proc/cpuinfo, the /proc/cpuinfo parsing
logic is present in the build, even if it wasn't built on a linux system
for that architecture.
Since the code is present in the build, we can then test that code also
on other systems, i.e. we don't need to have buildbots setup for all
architectures on linux to be able to test this. Instead, developers will
test this as part of the regression test run.
As an example, a few unit tests are added to test getHostCPUName for ARM
running linux. A unit test is preferred over a lit-based test, since the
expectation is that in the future, the functionality here will grow over
what can be tested with "llc -mcpu=native".
This is a preparation step to enable implementing the range of
improvements discussed on PR30516, such as adding AArch64 support,
support for big.LITTLE systems, reducing code duplication.
Differential Revision: https://reviews.llvm.org/D31236
llvm-svn: 299060
2017-03-30 15:24:49 +08:00
|
|
|
// Verify that both CPU implementer and CPU part are checked:
|
2017-03-31 21:06:40 +08:00
|
|
|
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");
|
Refactor getHostCPUName to allow testing on non-native hardware.
This refactors getHostCPUName so that for the architectures that get the
host cpu info on linux from /proc/cpuinfo, the /proc/cpuinfo parsing
logic is present in the build, even if it wasn't built on a linux system
for that architecture.
Since the code is present in the build, we can then test that code also
on other systems, i.e. we don't need to have buildbots setup for all
architectures on linux to be able to test this. Instead, developers will
test this as part of the regression test run.
As an example, a few unit tests are added to test getHostCPUName for ARM
running linux. A unit test is preferred over a lit-based test, since the
expectation is that in the future, the functionality here will grow over
what can be tested with "llc -mcpu=native".
This is a preparation step to enable implementing the range of
improvements discussed on PR30516, such as adding AArch64 support,
support for big.LITTLE systems, reducing code duplication.
Differential Revision: https://reviews.llvm.org/D31236
llvm-svn: 299060
2017-03-30 15:24:49 +08:00
|
|
|
}
|
2017-04-05 03:06:04 +08:00
|
|
|
|
|
|
|
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");
|
2017-09-14 05:48:00 +08:00
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x51\n"
|
|
|
|
"CPU part : 0x800"),
|
|
|
|
"cortex-a73");
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x51\n"
|
|
|
|
"CPU part : 0x801"),
|
|
|
|
"cortex-a73");
|
2017-09-23 01:46:36 +08:00
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x51\n"
|
|
|
|
"CPU part : 0xc00"),
|
|
|
|
"falkor");
|
2017-09-25 22:05:00 +08:00
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x51\n"
|
|
|
|
"CPU part : 0xc01"),
|
|
|
|
"saphira");
|
2017-04-05 03:06:04 +08:00
|
|
|
|
|
|
|
// 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");
|
2017-12-09 05:09:59 +08:00
|
|
|
|
|
|
|
// Exynos big.LITTLE weirdness
|
|
|
|
const std::string ExynosProcCpuInfo = R"(
|
|
|
|
processor : 0
|
|
|
|
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
|
|
|
|
CPU implementer : 0x41
|
|
|
|
CPU architecture: 8
|
|
|
|
CPU variant : 0x0
|
|
|
|
CPU part : 0xd03
|
|
|
|
|
|
|
|
processor : 1
|
|
|
|
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
|
|
|
|
CPU implementer : 0x53
|
|
|
|
CPU architecture: 8
|
|
|
|
)";
|
|
|
|
|
|
|
|
// Verify default for Exynos.
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(ExynosProcCpuInfo +
|
|
|
|
"CPU variant : 0xc\n"
|
|
|
|
"CPU part : 0xafe"),
|
|
|
|
"exynos-m1");
|
|
|
|
// Verify Exynos M1.
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(ExynosProcCpuInfo +
|
|
|
|
"CPU variant : 0x1\n"
|
|
|
|
"CPU part : 0x001"),
|
|
|
|
"exynos-m1");
|
|
|
|
// Verify Exynos M2.
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(ExynosProcCpuInfo +
|
|
|
|
"CPU variant : 0x4\n"
|
|
|
|
"CPU part : 0x001"),
|
|
|
|
"exynos-m2");
|
2017-04-05 03:06:04 +08:00
|
|
|
}
|
2017-07-07 17:53:47 +08:00
|
|
|
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
TEST_F(HostTest, getMacOSHostVersion) {
|
|
|
|
using namespace llvm::sys;
|
|
|
|
llvm::Triple HostTriple(getProcessTriple());
|
|
|
|
if (!HostTriple.isMacOSX())
|
|
|
|
return;
|
|
|
|
|
|
|
|
SmallString<128> TestDirectory;
|
|
|
|
ASSERT_NO_ERROR(fs::createUniqueDirectory("host_test", TestDirectory));
|
|
|
|
SmallString<128> OutputFile(TestDirectory);
|
|
|
|
path::append(OutputFile, "out");
|
|
|
|
|
|
|
|
const char *SwVersPath = "/usr/bin/sw_vers";
|
2018-06-13 01:43:52 +08:00
|
|
|
StringRef argv[] = {SwVersPath, "-productVersion"};
|
2017-07-07 17:53:47 +08:00
|
|
|
StringRef OutputPath = OutputFile.str();
|
2017-09-14 02:00:22 +08:00
|
|
|
const Optional<StringRef> Redirects[] = {/*STDIN=*/None,
|
|
|
|
/*STDOUT=*/OutputPath,
|
|
|
|
/*STDERR=*/None};
|
2018-06-13 01:43:52 +08:00
|
|
|
int RetCode = ExecuteAndWait(SwVersPath, argv, /*env=*/llvm::None, Redirects);
|
2017-07-07 17:53:47 +08:00
|
|
|
ASSERT_EQ(0, RetCode);
|
|
|
|
|
|
|
|
int FD = 0;
|
|
|
|
ASSERT_NO_ERROR(fs::openFileForRead(OutputPath, FD));
|
|
|
|
off_t Size = ::lseek(FD, 0, SEEK_END);
|
|
|
|
ASSERT_NE(-1, Size);
|
|
|
|
::lseek(FD, 0, SEEK_SET);
|
|
|
|
std::unique_ptr<char[]> Buffer = llvm::make_unique<char[]>(Size);
|
|
|
|
ASSERT_EQ(::read(FD, Buffer.get(), Size), Size);
|
|
|
|
::close(FD);
|
|
|
|
|
|
|
|
// Ensure that the two versions match.
|
|
|
|
StringRef SystemVersion(Buffer.get(), Size);
|
|
|
|
unsigned SystemMajor, SystemMinor, SystemMicro;
|
|
|
|
ASSERT_EQ(llvm::Triple((Twine("x86_64-apple-macos") + SystemVersion))
|
|
|
|
.getMacOSXVersion(SystemMajor, SystemMinor, SystemMicro),
|
|
|
|
true);
|
|
|
|
unsigned HostMajor, HostMinor, HostMicro;
|
|
|
|
ASSERT_EQ(HostTriple.getMacOSXVersion(HostMajor, HostMinor, HostMicro), true);
|
|
|
|
|
|
|
|
// Don't compare the 'Micro' version, as it's always '0' for the 'Darwin'
|
|
|
|
// triples.
|
|
|
|
ASSERT_EQ(std::tie(SystemMajor, SystemMinor), std::tie(HostMajor, HostMinor));
|
|
|
|
|
|
|
|
ASSERT_NO_ERROR(fs::remove(OutputPath));
|
|
|
|
ASSERT_NO_ERROR(fs::remove(TestDirectory.str()));
|
|
|
|
}
|
|
|
|
#endif
|