2016-10-13 19:43:20 +02:00
|
|
|
//========- unittests/Support/Host.cpp - Host.cpp tests --------------========//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-10-13 19:43:20 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Support/Host.h"
|
2019-03-13 01:12:43 +01:00
|
|
|
#include "llvm/Config/llvm-config.h"
|
2016-10-13 19:43:20 +02:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/Triple.h"
|
2017-07-07 11:53:47 +02:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
#include "llvm/Support/Program.h"
|
2020-02-15 00:31:45 +01:00
|
|
|
#include "llvm/Support/Threading.h"
|
2016-10-13 19:43:20 +02:00
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2019-08-14 15:59:04 +02: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 { \
|
|
|
|
}
|
2017-07-07 11:53:47 +02:00
|
|
|
|
2016-10-13 19:43:20 +02: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 00:36:07 +02:00
|
|
|
// physical cores, which is currently only supported/tested for
|
|
|
|
// x86_64 Linux and Darwin.
|
2020-02-15 00:31:45 +01:00
|
|
|
return (Host.isOSWindows() && llvm_is_multithreaded()) ||
|
[Support] On Windows, ensure hardware_concurrency() extends to all CPU sockets and all NUMA groups
The goal of this patch is to maximize CPU utilization on multi-socket or high core count systems, so that parallel computations such as LLD/ThinLTO can use all hardware threads in the system. Before this patch, on Windows, a maximum of 64 hardware threads could be used at most, in some cases dispatched only on one CPU socket.
== Background ==
Windows doesn't have a flat cpu_set_t like Linux. Instead, it projects hardware CPUs (or NUMA nodes) to applications through a concept of "processor groups". A "processor" is the smallest unit of execution on a CPU, that is, an hyper-thread if SMT is active; a core otherwise. There's a limit of 32-bit processors on older 32-bit versions of Windows, which later was raised to 64-processors with 64-bit versions of Windows. This limit comes from the affinity mask, which historically is represented by the sizeof(void*). Consequently, the concept of "processor groups" was introduced for dealing with systems with more than 64 hyper-threads.
By default, the Windows OS assigns only one "processor group" to each starting application, in a round-robin manner. If the application wants to use more processors, it needs to programmatically enable it, by assigning threads to other "processor groups". This also means that affinity cannot cross "processor group" boundaries; one can only specify a "preferred" group on start-up, but the application is free to allocate more groups if it wants to.
This creates a peculiar situation, where newer CPUs like the AMD EPYC 7702P (64-cores, 128-hyperthreads) are projected by the OS as two (2) "processor groups". This means that by default, an application can only use half of the cores. This situation could only get worse in the years to come, as dies with more cores will appear on the market.
== The problem ==
The heavyweight_hardware_concurrency() API was introduced so that only *one hardware thread per core* was used. Once that API returns, that original intention is lost, only the number of threads is retained. Consider a situation, on Windows, where the system has 2 CPU sockets, 18 cores each, each core having 2 hyper-threads, for a total of 72 hyper-threads. Both heavyweight_hardware_concurrency() and hardware_concurrency() currently return 36, because on Windows they are simply wrappers over std::thread::hardware_concurrency() -- which can only return processors from the current "processor group".
== The changes in this patch ==
To solve this situation, we capture (and retain) the initial intention until the point of usage, through a new ThreadPoolStrategy class. The number of threads to use is deferred as late as possible, until the moment where the std::threads are created (ThreadPool in the case of ThinLTO).
When using hardware_concurrency(), setting ThreadCount to 0 now means to use all the possible hardware CPU (SMT) threads. Providing a ThreadCount above to the maximum number of threads will have no effect, the maximum will be used instead.
The heavyweight_hardware_concurrency() is similar to hardware_concurrency(), except that only one thread per hardware *core* will be used.
When LLVM_ENABLE_THREADS is OFF, the threading APIs will always return 1, to ensure any caller loops will be exercised at least once.
Differential Revision: https://reviews.llvm.org/D71775
2020-02-14 04:49:57 +01:00
|
|
|
(Host.getArch() == Triple::x86_64 &&
|
2017-02-04 01:46:59 +01:00
|
|
|
(Host.isOSDarwin() || Host.getOS() == Triple::Linux));
|
2016-10-13 19:43:20 +02:00
|
|
|
}
|
2017-02-04 01:46:59 +01:00
|
|
|
|
|
|
|
HostTest() : Host(Triple::normalize(sys::getProcessTriple())) {}
|
2016-10-13 19:43:20 +02: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 09:24:49 +02: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 15:06:40 +02: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 09:24:49 +02:00
|
|
|
"cortex-a9");
|
2017-03-31 15:06:40 +02: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 09:24:49 +02:00
|
|
|
// Verify that both CPU implementer and CPU part are checked:
|
2017-03-31 15:06:40 +02: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 09:24:49 +02:00
|
|
|
}
|
2017-04-04 21:06:04 +02: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-13 23:48:00 +02: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-22 19:46:36 +02:00
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x51\n"
|
|
|
|
"CPU part : 0xc00"),
|
|
|
|
"falkor");
|
2017-09-25 16:05:00 +02:00
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x51\n"
|
|
|
|
"CPU part : 0xc01"),
|
|
|
|
"saphira");
|
2017-04-04 21:06:04 +02: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-08 22:09:59 +01: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
|
2019-10-02 23:26:40 +02:00
|
|
|
CPU part : 0xd05
|
2017-12-08 22:09:59 +01:00
|
|
|
|
|
|
|
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"),
|
2019-10-02 23:26:40 +02:00
|
|
|
"exynos-m3");
|
|
|
|
// Verify Exynos M3.
|
2017-12-08 22:09:59 +01:00
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(ExynosProcCpuInfo +
|
|
|
|
"CPU variant : 0x1\n"
|
2019-10-02 23:26:40 +02:00
|
|
|
"CPU part : 0x002"),
|
|
|
|
"exynos-m3");
|
|
|
|
// Verify Exynos M4.
|
2017-12-08 22:09:59 +01:00
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(ExynosProcCpuInfo +
|
2019-10-02 23:26:40 +02:00
|
|
|
"CPU variant : 0x1\n"
|
|
|
|
"CPU part : 0x003"),
|
|
|
|
"exynos-m4");
|
2018-10-06 00:23:21 +02:00
|
|
|
|
|
|
|
const std::string ThunderX2T99ProcCpuInfo = R"(
|
|
|
|
processor : 0
|
|
|
|
BogoMIPS : 400.00
|
|
|
|
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics
|
|
|
|
CPU implementer : 0x43
|
|
|
|
CPU architecture: 8
|
|
|
|
CPU variant : 0x1
|
|
|
|
CPU part : 0x0af
|
|
|
|
)";
|
|
|
|
|
|
|
|
// Verify different versions of ThunderX2T99.
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(ThunderX2T99ProcCpuInfo +
|
|
|
|
"CPU implementer : 0x42\n"
|
|
|
|
"CPU part : 0x516"),
|
|
|
|
"thunderx2t99");
|
|
|
|
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(ThunderX2T99ProcCpuInfo +
|
|
|
|
"CPU implementer : 0x42\n"
|
|
|
|
"CPU part : 0x0516"),
|
|
|
|
"thunderx2t99");
|
|
|
|
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(ThunderX2T99ProcCpuInfo +
|
|
|
|
"CPU implementer : 0x43\n"
|
|
|
|
"CPU part : 0x516"),
|
|
|
|
"thunderx2t99");
|
|
|
|
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(ThunderX2T99ProcCpuInfo +
|
|
|
|
"CPU implementer : 0x43\n"
|
|
|
|
"CPU part : 0x0516"),
|
|
|
|
"thunderx2t99");
|
|
|
|
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(ThunderX2T99ProcCpuInfo +
|
|
|
|
"CPU implementer : 0x42\n"
|
|
|
|
"CPU part : 0xaf"),
|
|
|
|
"thunderx2t99");
|
|
|
|
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(ThunderX2T99ProcCpuInfo +
|
|
|
|
"CPU implementer : 0x42\n"
|
|
|
|
"CPU part : 0x0af"),
|
|
|
|
"thunderx2t99");
|
|
|
|
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(ThunderX2T99ProcCpuInfo +
|
|
|
|
"CPU implementer : 0x43\n"
|
|
|
|
"CPU part : 0xaf"),
|
|
|
|
"thunderx2t99");
|
|
|
|
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(ThunderX2T99ProcCpuInfo +
|
|
|
|
"CPU implementer : 0x43\n"
|
|
|
|
"CPU part : 0x0af"),
|
|
|
|
"thunderx2t99");
|
|
|
|
|
|
|
|
// Verify ThunderXT88.
|
|
|
|
const std::string ThunderXT88ProcCpuInfo = R"(
|
|
|
|
processor : 0
|
|
|
|
BogoMIPS : 200.00
|
|
|
|
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
|
|
|
|
CPU implementer : 0x43
|
|
|
|
CPU architecture: 8
|
|
|
|
CPU variant : 0x1
|
|
|
|
CPU part : 0x0a1
|
|
|
|
)";
|
|
|
|
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(ThunderXT88ProcCpuInfo +
|
|
|
|
"CPU implementer : 0x43\n"
|
|
|
|
"CPU part : 0x0a1"),
|
|
|
|
"thunderxt88");
|
|
|
|
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(ThunderXT88ProcCpuInfo +
|
|
|
|
"CPU implementer : 0x43\n"
|
|
|
|
"CPU part : 0xa1"),
|
|
|
|
"thunderxt88");
|
2018-11-09 20:32:08 +01:00
|
|
|
|
|
|
|
// Verify HiSilicon processors.
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x48\n"
|
|
|
|
"CPU part : 0xd01"),
|
|
|
|
"tsv110");
|
2017-04-04 21:06:04 +02:00
|
|
|
}
|
2017-07-07 11:53:47 +02:00
|
|
|
|
2019-03-13 12:51:13 +01:00
|
|
|
#if defined(__APPLE__) || defined(_AIX)
|
2019-03-13 01:12:43 +01:00
|
|
|
static bool runAndGetCommandOutput(
|
|
|
|
const char *ExePath, ArrayRef<llvm::StringRef> argv,
|
|
|
|
std::unique_ptr<char[]> &Buffer, off_t &Size) {
|
|
|
|
bool Success = false;
|
|
|
|
[ExePath, argv, &Buffer, &Size, &Success] {
|
|
|
|
using namespace llvm::sys;
|
|
|
|
SmallString<128> TestDirectory;
|
|
|
|
ASSERT_NO_ERROR(fs::createUniqueDirectory("host_test", TestDirectory));
|
|
|
|
|
|
|
|
SmallString<128> OutputFile(TestDirectory);
|
|
|
|
path::append(OutputFile, "out");
|
|
|
|
StringRef OutputPath = OutputFile.str();
|
|
|
|
|
|
|
|
const Optional<StringRef> Redirects[] = {
|
|
|
|
/*STDIN=*/None, /*STDOUT=*/OutputPath, /*STDERR=*/None};
|
|
|
|
int RetCode = ExecuteAndWait(ExePath, argv, /*env=*/llvm::None, Redirects);
|
|
|
|
ASSERT_EQ(0, RetCode);
|
|
|
|
|
|
|
|
int FD = 0;
|
|
|
|
ASSERT_NO_ERROR(fs::openFileForRead(OutputPath, FD));
|
|
|
|
Size = ::lseek(FD, 0, SEEK_END);
|
|
|
|
ASSERT_NE(-1, Size);
|
|
|
|
::lseek(FD, 0, SEEK_SET);
|
2019-08-15 17:54:37 +02:00
|
|
|
Buffer = std::make_unique<char[]>(Size);
|
2019-03-13 01:12:43 +01:00
|
|
|
ASSERT_EQ(::read(FD, Buffer.get(), Size), Size);
|
|
|
|
::close(FD);
|
|
|
|
|
|
|
|
ASSERT_NO_ERROR(fs::remove(OutputPath));
|
|
|
|
ASSERT_NO_ERROR(fs::remove(TestDirectory.str()));
|
|
|
|
Success = true;
|
|
|
|
}();
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(HostTest, DummyRunAndGetCommandOutputUse) {
|
|
|
|
// Suppress defined-but-not-used warnings when the tests using the helper are
|
|
|
|
// disabled.
|
|
|
|
(void) runAndGetCommandOutput;
|
|
|
|
}
|
2019-03-13 12:51:13 +01:00
|
|
|
#endif
|
2019-03-13 01:12:43 +01:00
|
|
|
|
2017-07-07 11:53:47 +02:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
TEST_F(HostTest, getMacOSHostVersion) {
|
|
|
|
using namespace llvm::sys;
|
|
|
|
llvm::Triple HostTriple(getProcessTriple());
|
|
|
|
if (!HostTriple.isMacOSX())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const char *SwVersPath = "/usr/bin/sw_vers";
|
2018-06-12 19:43:52 +02:00
|
|
|
StringRef argv[] = {SwVersPath, "-productVersion"};
|
2019-03-13 01:12:43 +01:00
|
|
|
std::unique_ptr<char[]> Buffer;
|
|
|
|
off_t Size;
|
|
|
|
ASSERT_EQ(runAndGetCommandOutput(SwVersPath, argv, Buffer, Size), true);
|
|
|
|
StringRef SystemVersion(Buffer.get(), Size);
|
2017-07-07 11:53:47 +02:00
|
|
|
|
|
|
|
// Ensure that the two versions match.
|
|
|
|
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));
|
2019-03-13 01:12:43 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_AIX)
|
|
|
|
TEST_F(HostTest, AIXVersionDetect) {
|
|
|
|
using namespace llvm::sys;
|
|
|
|
|
|
|
|
llvm::Triple HostTriple(getProcessTriple());
|
|
|
|
ASSERT_EQ(HostTriple.getOS(), Triple::AIX);
|
|
|
|
|
|
|
|
llvm::Triple ConfiguredHostTriple(LLVM_HOST_TRIPLE);
|
|
|
|
ASSERT_EQ(ConfiguredHostTriple.getOS(), Triple::AIX);
|
|
|
|
|
|
|
|
const char *ExePath = "/usr/bin/oslevel";
|
|
|
|
StringRef argv[] = {ExePath};
|
|
|
|
std::unique_ptr<char[]> Buffer;
|
|
|
|
off_t Size;
|
|
|
|
ASSERT_EQ(runAndGetCommandOutput(ExePath, argv, Buffer, Size), true);
|
|
|
|
StringRef SystemVersion(Buffer.get(), Size);
|
|
|
|
|
|
|
|
unsigned SystemMajor, SystemMinor, SystemMicro;
|
|
|
|
llvm::Triple((Twine("powerpc-ibm-aix") + SystemVersion))
|
|
|
|
.getOSVersion(SystemMajor, SystemMinor, SystemMicro);
|
|
|
|
|
|
|
|
// Ensure that the host triple version (major) and release (minor) numbers,
|
|
|
|
// unless explicitly configured, match with those of the current system.
|
|
|
|
if (!ConfiguredHostTriple.getOSMajorVersion()) {
|
|
|
|
unsigned HostMajor, HostMinor, HostMicro;
|
|
|
|
HostTriple.getOSVersion(HostMajor, HostMinor, HostMicro);
|
|
|
|
ASSERT_EQ(std::tie(SystemMajor, SystemMinor),
|
|
|
|
std::tie(HostMajor, HostMinor));
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Triple TargetTriple(getDefaultTargetTriple());
|
|
|
|
if (TargetTriple.getOS() != Triple::AIX)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Ensure that the target triple version (major) and release (minor) numbers
|
|
|
|
// match with those of the current system.
|
|
|
|
llvm::Triple ConfiguredTargetTriple(LLVM_DEFAULT_TARGET_TRIPLE);
|
|
|
|
if (ConfiguredTargetTriple.getOSMajorVersion())
|
|
|
|
return; // The version was configured explicitly; skip.
|
2017-07-07 11:53:47 +02:00
|
|
|
|
2019-03-13 01:12:43 +01:00
|
|
|
unsigned TargetMajor, TargetMinor, TargetMicro;
|
|
|
|
TargetTriple.getOSVersion(TargetMajor, TargetMinor, TargetMicro);
|
|
|
|
ASSERT_EQ(std::tie(SystemMajor, SystemMinor),
|
|
|
|
std::tie(TargetMajor, TargetMinor));
|
2017-07-07 11:53:47 +02:00
|
|
|
}
|
|
|
|
#endif
|