2016-10-14 01:43:20 +08:00
|
|
|
//========- unittests/Support/Host.cpp - Host.cpp tests --------------========//
|
|
|
|
//
|
2019-01-19 16:50:56 +08: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-14 01:43:20 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Support/Host.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/Triple.h"
|
2022-02-01 03:31:46 +08:00
|
|
|
#include "llvm/Config/config.h"
|
2017-07-07 17:53:47 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
#include "llvm/Support/Program.h"
|
2020-02-15 07:31:45 +08:00
|
|
|
#include "llvm/Support/Threading.h"
|
2016-10-14 01:43:20 +08:00
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2019-08-14 21:59:04 +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 { \
|
|
|
|
}
|
2017-07-07 17:53:47 +08:00
|
|
|
|
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
|
2020-07-28 16:33:50 +08:00
|
|
|
// physical cores, which is currently only supported/tested on
|
|
|
|
// some systems.
|
2020-02-15 07:31:45 +08:00
|
|
|
return (Host.isOSWindows() && llvm_is_multithreaded()) ||
|
2021-07-15 06:23:37 +08:00
|
|
|
Host.isOSDarwin() || (Host.isX86() && Host.isOSLinux()) ||
|
2022-08-14 01:27:34 +08:00
|
|
|
(Host.isOSLinux() && !Host.isAndroid()) ||
|
|
|
|
(Host.isSystemZ() && Host.isOSzOS());
|
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
|
|
|
};
|
|
|
|
|
2022-02-12 02:43:22 +08:00
|
|
|
TEST_F(HostTest, NumPhysicalCoresSupported) {
|
|
|
|
if (!isSupportedArchAndOS())
|
|
|
|
GTEST_SKIP();
|
2016-10-14 01:43:20 +08:00
|
|
|
int Num = sys::getHostNumPhysicalCores();
|
2022-02-12 02:43:22 +08:00
|
|
|
ASSERT_GT(Num, 0);
|
|
|
|
}
|
2016-10-14 01:43:20 +08:00
|
|
|
|
2022-02-12 02:43:22 +08:00
|
|
|
TEST_F(HostTest, NumPhysicalCoresUnsupported) {
|
2016-10-14 01:43:20 +08:00
|
|
|
if (isSupportedArchAndOS())
|
2022-02-12 02:43:22 +08:00
|
|
|
GTEST_SKIP();
|
|
|
|
int Num = sys::getHostNumPhysicalCores();
|
|
|
|
ASSERT_EQ(Num, -1);
|
2016-10-14 01:43:20 +08:00
|
|
|
}
|
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");
|
2020-05-29 02:49:12 +08:00
|
|
|
|
2022-01-13 19:19:44 +08:00
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x41\n"
|
|
|
|
"CPU part : 0xd40"),
|
|
|
|
"neoverse-v1");
|
2020-05-29 02:49:12 +08:00
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x41\n"
|
|
|
|
"CPU part : 0xd0c"),
|
|
|
|
"neoverse-n1");
|
2017-04-05 03:06:04 +08:00
|
|
|
// 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
|
|
|
|
2022-05-03 23:10:02 +08:00
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0xc0\n"
|
|
|
|
"CPU part : 0xac3"),
|
|
|
|
"ampere1");
|
|
|
|
|
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
|
2019-10-03 05:26:40 +08:00
|
|
|
CPU part : 0xd05
|
2017-12-09 05:09:59 +08: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-03 05:26:40 +08:00
|
|
|
"exynos-m3");
|
|
|
|
// Verify Exynos M3.
|
2017-12-09 05:09:59 +08:00
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(ExynosProcCpuInfo +
|
|
|
|
"CPU variant : 0x1\n"
|
2019-10-03 05:26:40 +08:00
|
|
|
"CPU part : 0x002"),
|
|
|
|
"exynos-m3");
|
|
|
|
// Verify Exynos M4.
|
2017-12-09 05:09:59 +08:00
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(ExynosProcCpuInfo +
|
2019-10-03 05:26:40 +08:00
|
|
|
"CPU variant : 0x1\n"
|
|
|
|
"CPU part : 0x003"),
|
|
|
|
"exynos-m4");
|
2018-10-06 06:23:21 +08: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-10 03:32:08 +08:00
|
|
|
|
|
|
|
// Verify HiSilicon processors.
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM("CPU implementer : 0x48\n"
|
|
|
|
"CPU part : 0xd01"),
|
|
|
|
"tsv110");
|
2020-03-03 20:52:27 +08:00
|
|
|
|
|
|
|
// Verify A64FX.
|
|
|
|
const std::string A64FXProcCpuInfo = R"(
|
|
|
|
processor : 0
|
|
|
|
BogoMIPS : 200.00
|
|
|
|
Features : fp asimd evtstrm sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm fcma dcpop sve
|
|
|
|
CPU implementer : 0x46
|
|
|
|
CPU architecture: 8
|
|
|
|
CPU variant : 0x1
|
|
|
|
CPU part : 0x001
|
|
|
|
)";
|
|
|
|
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(A64FXProcCpuInfo), "a64fx");
|
[AArch64] Add NVIDIA Carmel support
Summary:
NVIDIA's Carmel ARM64 cores are used in Tegra194 chips found in Jetson AGX Xavier, DRIVE AGX Xavier and DRIVE AGX Pegasus.
References:
* https://devblogs.nvidia.com/nvidia-jetson-agx-xavier-32-teraops-ai-robotics/#h.huq9xtg75a5e
* NVIDIA Xavier Series System-on-Chip Technical Reference Manual 1.3 (https://developer.nvidia.com/embedded/downloads#?search=Xavier%20Series%20SoC%20Technical%20Reference%20Manual)
Reviewers: sdesmalen, paquette
Reviewed By: sdesmalen
Subscribers: llvm-commits, ianshmean, kristof.beyls, hiraditya, jfb, danielkiss, cfe-commits, t.p.northover
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D77940
2020-05-04 18:45:35 +08:00
|
|
|
|
|
|
|
// Verify Nvidia Carmel.
|
|
|
|
const std::string CarmelProcCpuInfo = R"(
|
|
|
|
processor : 0
|
|
|
|
model name : ARMv8 Processor rev 0 (v8l)
|
|
|
|
BogoMIPS : 62.50
|
|
|
|
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm dcpop
|
|
|
|
CPU implementer : 0x4e
|
|
|
|
CPU architecture: 8
|
|
|
|
CPU variant : 0x0
|
|
|
|
CPU part : 0x004
|
|
|
|
CPU revision : 0
|
|
|
|
)";
|
|
|
|
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(CarmelProcCpuInfo), "carmel");
|
2021-01-21 06:23:43 +08:00
|
|
|
|
|
|
|
// Snapdragon mixed implementer quirk
|
|
|
|
const std::string Snapdragon865ProcCPUInfo = R"(
|
|
|
|
processor : 0
|
|
|
|
BogoMIPS : 38.40
|
|
|
|
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp
|
|
|
|
CPU implementer : 0x51
|
|
|
|
CPU architecture: 8
|
|
|
|
CPU variant : 0xd
|
|
|
|
CPU part : 0x805
|
|
|
|
CPU revision : 14
|
|
|
|
processor : 1
|
|
|
|
processor : 2
|
|
|
|
processor : 3
|
|
|
|
processor : 4
|
|
|
|
processor : 5
|
|
|
|
processor : 6
|
|
|
|
BogoMIPS : 38.40
|
|
|
|
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp
|
|
|
|
CPU implementer : 0x41
|
|
|
|
CPU architecture: 8
|
|
|
|
CPU variant : 0x1
|
|
|
|
CPU part : 0xd0d
|
|
|
|
CPU revision : 0
|
|
|
|
)";
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForARM(Snapdragon865ProcCPUInfo), "cortex-a77");
|
2017-04-05 03:06:04 +08:00
|
|
|
}
|
2017-07-07 17:53:47 +08:00
|
|
|
|
2021-05-25 23:10:40 +08:00
|
|
|
TEST(getLinuxHostCPUName, s390x) {
|
|
|
|
SmallVector<std::string> ModelIDs(
|
2021-07-21 00:14:38 +08:00
|
|
|
{"3931", "8561", "3906", "2964", "2827", "2817", "2097", "2064"});
|
2021-05-25 23:10:40 +08:00
|
|
|
SmallVector<std::string> VectorSupport({"", "vx"});
|
|
|
|
SmallVector<StringRef> ExpectedCPUs;
|
|
|
|
|
2021-07-21 00:14:38 +08:00
|
|
|
// Model Id: 3931
|
|
|
|
ExpectedCPUs.push_back("zEC12");
|
2022-04-22 01:55:58 +08:00
|
|
|
ExpectedCPUs.push_back("z16");
|
2021-07-21 00:14:38 +08:00
|
|
|
|
2021-05-25 23:10:40 +08:00
|
|
|
// Model Id: 8561
|
|
|
|
ExpectedCPUs.push_back("zEC12");
|
|
|
|
ExpectedCPUs.push_back("z15");
|
|
|
|
|
|
|
|
// Model Id: 3906
|
|
|
|
ExpectedCPUs.push_back("zEC12");
|
|
|
|
ExpectedCPUs.push_back("z14");
|
|
|
|
|
|
|
|
// Model Id: 2964
|
|
|
|
ExpectedCPUs.push_back("zEC12");
|
|
|
|
ExpectedCPUs.push_back("z13");
|
|
|
|
|
|
|
|
// Model Id: 2827
|
|
|
|
ExpectedCPUs.push_back("zEC12");
|
|
|
|
ExpectedCPUs.push_back("zEC12");
|
|
|
|
|
|
|
|
// Model Id: 2817
|
|
|
|
ExpectedCPUs.push_back("z196");
|
|
|
|
ExpectedCPUs.push_back("z196");
|
|
|
|
|
2021-07-20 19:36:33 +08:00
|
|
|
// Model Id: 2097
|
|
|
|
ExpectedCPUs.push_back("z10");
|
|
|
|
ExpectedCPUs.push_back("z10");
|
|
|
|
|
|
|
|
// Model Id: 2064
|
2021-05-25 23:10:40 +08:00
|
|
|
ExpectedCPUs.push_back("generic");
|
|
|
|
ExpectedCPUs.push_back("generic");
|
|
|
|
|
|
|
|
const std::string DummyBaseVectorInfo =
|
|
|
|
"features : esan3 zarch stfle msa ldisp eimm dfp edat etf3eh highgprs "
|
|
|
|
"te ";
|
|
|
|
const std::string DummyBaseMachineInfo =
|
|
|
|
"processor 0: version = FF, identification = 059C88, machine = ";
|
|
|
|
|
|
|
|
int CheckIndex = 0;
|
|
|
|
for (size_t I = 0; I < ModelIDs.size(); I++) {
|
|
|
|
for (size_t J = 0; J < VectorSupport.size(); J++) {
|
|
|
|
const std::string DummyCPUInfo = DummyBaseVectorInfo + VectorSupport[J] +
|
|
|
|
"\n" + DummyBaseMachineInfo +
|
|
|
|
ModelIDs[I];
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForS390x(DummyCPUInfo),
|
|
|
|
ExpectedCPUs[CheckIndex++]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-17 14:06:42 +08:00
|
|
|
TEST(getLinuxHostCPUName, RISCV) {
|
|
|
|
const StringRef SifiveU74MCProcCPUInfo = R"(
|
|
|
|
processor : 0
|
|
|
|
hart : 2
|
|
|
|
isa : rv64imafdc
|
|
|
|
mmu : sv39
|
|
|
|
uarch : sifive,u74-mc
|
|
|
|
)";
|
|
|
|
EXPECT_EQ(sys::detail::getHostCPUNameForRISCV(SifiveU74MCProcCPUInfo),
|
|
|
|
"sifive-u74");
|
|
|
|
EXPECT_EQ(
|
|
|
|
sys::detail::getHostCPUNameForRISCV("uarch : sifive,bullet0\n"),
|
|
|
|
"sifive-u74");
|
|
|
|
}
|
|
|
|
|
2019-03-13 08:12:43 +08: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 23:54:37 +08:00
|
|
|
Buffer = std::make_unique<char[]>(Size);
|
2019-03-13 08:12:43 +08: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.
|
2021-12-20 08:28:31 +08:00
|
|
|
(void)&runAndGetCommandOutput;
|
2019-03-13 08:12:43 +08:00
|
|
|
}
|
|
|
|
|
2017-07-07 17:53:47 +08:00
|
|
|
TEST_F(HostTest, getMacOSHostVersion) {
|
2021-12-07 01:41:26 +08:00
|
|
|
llvm::Triple HostTriple(llvm::sys::getProcessTriple());
|
2017-07-07 17:53:47 +08:00
|
|
|
if (!HostTriple.isMacOSX())
|
2022-02-12 02:43:22 +08:00
|
|
|
GTEST_SKIP();
|
2017-07-07 17:53:47 +08:00
|
|
|
|
|
|
|
const char *SwVersPath = "/usr/bin/sw_vers";
|
2018-06-13 01:43:52 +08:00
|
|
|
StringRef argv[] = {SwVersPath, "-productVersion"};
|
2019-03-13 08:12:43 +08:00
|
|
|
std::unique_ptr<char[]> Buffer;
|
|
|
|
off_t Size;
|
|
|
|
ASSERT_EQ(runAndGetCommandOutput(SwVersPath, argv, Buffer, Size), true);
|
2021-12-07 01:41:26 +08:00
|
|
|
StringRef SystemVersionStr = StringRef(Buffer.get(), Size).rtrim();
|
2017-07-07 17:53:47 +08:00
|
|
|
|
|
|
|
// Ensure that the two versions match.
|
2021-12-07 01:41:26 +08:00
|
|
|
VersionTuple SystemVersion;
|
|
|
|
ASSERT_EQ(llvm::Triple((Twine("x86_64-apple-macos") + SystemVersionStr))
|
|
|
|
.getMacOSXVersion(SystemVersion),
|
2017-07-07 17:53:47 +08:00
|
|
|
true);
|
2021-12-07 01:41:26 +08:00
|
|
|
VersionTuple HostVersion;
|
|
|
|
ASSERT_EQ(HostTriple.getMacOSXVersion(HostVersion), true);
|
2017-07-07 17:53:47 +08:00
|
|
|
|
2021-12-07 01:41:26 +08:00
|
|
|
if (SystemVersion.getMajor() > 10) {
|
2021-01-07 06:40:17 +08:00
|
|
|
// Don't compare the 'Minor' and 'Micro' versions, as they're always '0' for
|
|
|
|
// the 'Darwin' triples on 11.x.
|
2021-12-07 01:41:26 +08:00
|
|
|
ASSERT_EQ(SystemVersion.getMajor(), HostVersion.getMajor());
|
2021-01-07 06:40:17 +08:00
|
|
|
} else {
|
|
|
|
// Don't compare the 'Micro' version, as it's always '0' for the 'Darwin'
|
|
|
|
// triples.
|
2021-12-07 01:41:26 +08:00
|
|
|
ASSERT_EQ(SystemVersion.getMajor(), HostVersion.getMajor());
|
|
|
|
ASSERT_EQ(SystemVersion.getMinor(), HostVersion.getMinor());
|
2021-01-07 06:40:17 +08:00
|
|
|
}
|
2019-03-13 08:12:43 +08:00
|
|
|
}
|
|
|
|
|
2022-02-12 02:43:22 +08:00
|
|
|
// Helper to return AIX system version. Must return void to use ASSERT_*.
|
|
|
|
static void getAIXSystemVersion(VersionTuple &SystemVersion) {
|
2019-03-13 08:12:43 +08:00
|
|
|
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);
|
2021-12-07 01:41:26 +08:00
|
|
|
StringRef SystemVersionStr = StringRef(Buffer.get(), Size).rtrim();
|
2019-03-13 08:12:43 +08:00
|
|
|
|
2022-02-12 02:43:22 +08:00
|
|
|
SystemVersion =
|
2021-12-07 01:41:26 +08:00
|
|
|
llvm::Triple((Twine("powerpc-ibm-aix") + SystemVersionStr))
|
|
|
|
.getOSVersion();
|
2022-02-12 02:43:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(HostTest, AIXHostVersionDetect) {
|
|
|
|
llvm::Triple HostTriple(llvm::sys::getProcessTriple());
|
|
|
|
if (HostTriple.getOS() != Triple::AIX)
|
|
|
|
GTEST_SKIP();
|
|
|
|
|
|
|
|
llvm::Triple ConfiguredHostTriple(LLVM_HOST_TRIPLE);
|
|
|
|
ASSERT_EQ(ConfiguredHostTriple.getOS(), Triple::AIX);
|
|
|
|
|
|
|
|
VersionTuple SystemVersion;
|
|
|
|
getAIXSystemVersion(SystemVersion);
|
2019-03-13 08:12:43 +08:00
|
|
|
|
|
|
|
// Ensure that the host triple version (major) and release (minor) numbers,
|
|
|
|
// unless explicitly configured, match with those of the current system.
|
2022-02-12 02:43:22 +08:00
|
|
|
auto SysMajor = SystemVersion.getMajor();
|
|
|
|
auto SysMinor = SystemVersion.getMinor();
|
|
|
|
VersionTuple HostVersion = HostTriple.getOSVersion();
|
|
|
|
if (ConfiguredHostTriple.getOSMajorVersion()) {
|
|
|
|
// Explicitly configured, force a match. We do it this way so the
|
|
|
|
// asserts are always executed.
|
|
|
|
SysMajor = HostVersion.getMajor();
|
|
|
|
SysMinor = HostVersion.getMinor();
|
2019-03-13 08:12:43 +08:00
|
|
|
}
|
2022-02-12 02:43:22 +08:00
|
|
|
ASSERT_EQ(SysMajor, HostVersion.getMajor());
|
|
|
|
ASSERT_EQ(SysMinor, HostVersion.getMinor());
|
|
|
|
}
|
2019-03-13 08:12:43 +08:00
|
|
|
|
2022-02-12 02:43:22 +08:00
|
|
|
TEST_F(HostTest, AIXTargetVersionDetect) {
|
2021-12-07 01:41:26 +08:00
|
|
|
llvm::Triple TargetTriple(llvm::sys::getDefaultTargetTriple());
|
2019-03-13 08:12:43 +08:00
|
|
|
if (TargetTriple.getOS() != Triple::AIX)
|
2022-02-12 02:43:22 +08:00
|
|
|
GTEST_SKIP();
|
2019-03-13 08:12:43 +08:00
|
|
|
|
|
|
|
// 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())
|
2022-02-12 02:43:22 +08:00
|
|
|
GTEST_SKIP(); // The version was configured explicitly; skip.
|
2017-07-07 17:53:47 +08:00
|
|
|
|
2022-02-12 02:43:22 +08:00
|
|
|
VersionTuple SystemVersion;
|
|
|
|
getAIXSystemVersion(SystemVersion);
|
2021-12-07 01:41:26 +08:00
|
|
|
VersionTuple TargetVersion = TargetTriple.getOSVersion();
|
|
|
|
ASSERT_EQ(SystemVersion.getMajor(), TargetVersion.getMajor());
|
|
|
|
ASSERT_EQ(SystemVersion.getMinor(), TargetVersion.getMinor());
|
2017-07-07 17:53:47 +08:00
|
|
|
}
|
2021-02-10 04:56:47 +08:00
|
|
|
|
|
|
|
TEST_F(HostTest, AIXHostCPUDetect) {
|
2021-12-07 01:41:26 +08:00
|
|
|
llvm::Triple HostTriple(llvm::sys::getProcessTriple());
|
|
|
|
if (HostTriple.getOS() != Triple::AIX)
|
2022-02-12 02:43:22 +08:00
|
|
|
GTEST_SKIP();
|
2021-12-07 01:41:26 +08:00
|
|
|
|
2021-02-10 04:56:47 +08:00
|
|
|
// Return a value based on the current processor implementation mode.
|
|
|
|
const char *ExePath = "/usr/sbin/getsystype";
|
|
|
|
StringRef argv[] = {ExePath, "-i"};
|
|
|
|
std::unique_ptr<char[]> Buffer;
|
|
|
|
off_t Size;
|
|
|
|
ASSERT_EQ(runAndGetCommandOutput(ExePath, argv, Buffer, Size), true);
|
|
|
|
StringRef CPU(Buffer.get(), Size);
|
|
|
|
StringRef MCPU = StringSwitch<const char *>(CPU)
|
|
|
|
.Case("POWER 4\n", "pwr4")
|
|
|
|
.Case("POWER 5\n", "pwr5")
|
|
|
|
.Case("POWER 6\n", "pwr6")
|
|
|
|
.Case("POWER 7\n", "pwr7")
|
|
|
|
.Case("POWER 8\n", "pwr8")
|
|
|
|
.Case("POWER 9\n", "pwr9")
|
|
|
|
.Case("POWER 10\n", "pwr10")
|
|
|
|
.Default("unknown");
|
|
|
|
|
|
|
|
StringRef HostCPU = sys::getHostCPUName();
|
|
|
|
|
|
|
|
// Just do the comparison on the base implementation mode.
|
|
|
|
if (HostCPU == "970")
|
|
|
|
HostCPU = StringRef("pwr4");
|
|
|
|
else
|
|
|
|
HostCPU = HostCPU.rtrim('x');
|
|
|
|
|
|
|
|
EXPECT_EQ(HostCPU, MCPU);
|
|
|
|
}
|