summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/Host.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/Support/Host.cpp')
-rw-r--r--llvm/unittests/Support/Host.cpp63
1 files changed, 42 insertions, 21 deletions
diff --git a/llvm/unittests/Support/Host.cpp b/llvm/unittests/Support/Host.cpp
index 888cfb2658e4..0a0adcebc43d 100644
--- a/llvm/unittests/Support/Host.cpp
+++ b/llvm/unittests/Support/Host.cpp
@@ -47,13 +47,18 @@ protected:
HostTest() : Host(Triple::normalize(sys::getProcessTriple())) {}
};
-TEST_F(HostTest, NumPhysicalCores) {
+TEST_F(HostTest, NumPhysicalCoresSupported) {
+ if (!isSupportedArchAndOS())
+ GTEST_SKIP();
int Num = sys::getHostNumPhysicalCores();
+ ASSERT_GT(Num, 0);
+}
+TEST_F(HostTest, NumPhysicalCoresUnsupported) {
if (isSupportedArchAndOS())
- ASSERT_GT(Num, 0);
- else
- ASSERT_EQ(Num, -1);
+ GTEST_SKIP();
+ int Num = sys::getHostNumPhysicalCores();
+ ASSERT_EQ(Num, -1);
}
TEST(getLinuxHostCPUName, ARM) {
@@ -412,7 +417,7 @@ TEST_F(HostTest, DummyRunAndGetCommandOutputUse) {
TEST_F(HostTest, getMacOSHostVersion) {
llvm::Triple HostTriple(llvm::sys::getProcessTriple());
if (!HostTriple.isMacOSX())
- return;
+ GTEST_SKIP();
const char *SwVersPath = "/usr/bin/sw_vers";
StringRef argv[] = {SwVersPath, "-productVersion"};
@@ -441,14 +446,8 @@ TEST_F(HostTest, getMacOSHostVersion) {
}
}
-TEST_F(HostTest, AIXVersionDetect) {
- llvm::Triple HostTriple(llvm::sys::getProcessTriple());
- if (HostTriple.getOS() != Triple::AIX)
- return;
-
- llvm::Triple ConfiguredHostTriple(LLVM_HOST_TRIPLE);
- ASSERT_EQ(ConfiguredHostTriple.getOS(), Triple::AIX);
-
+// Helper to return AIX system version. Must return void to use ASSERT_*.
+static void getAIXSystemVersion(VersionTuple &SystemVersion) {
const char *ExePath = "/usr/bin/oslevel";
StringRef argv[] = {ExePath};
std::unique_ptr<char[]> Buffer;
@@ -456,28 +455,50 @@ TEST_F(HostTest, AIXVersionDetect) {
ASSERT_EQ(runAndGetCommandOutput(ExePath, argv, Buffer, Size), true);
StringRef SystemVersionStr = StringRef(Buffer.get(), Size).rtrim();
- VersionTuple SystemVersion =
+ SystemVersion =
llvm::Triple((Twine("powerpc-ibm-aix") + SystemVersionStr))
.getOSVersion();
+}
+
+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);
// Ensure that the host triple version (major) and release (minor) numbers,
// unless explicitly configured, match with those of the current system.
- if (!ConfiguredHostTriple.getOSMajorVersion()) {
- VersionTuple HostVersion = HostTriple.getOSVersion();
- ASSERT_EQ(SystemVersion.getMajor(), HostVersion.getMajor());
- ASSERT_EQ(SystemVersion.getMinor(), HostVersion.getMinor());
+ 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();
}
+ ASSERT_EQ(SysMajor, HostVersion.getMajor());
+ ASSERT_EQ(SysMinor, HostVersion.getMinor());
+}
+TEST_F(HostTest, AIXTargetVersionDetect) {
llvm::Triple TargetTriple(llvm::sys::getDefaultTargetTriple());
if (TargetTriple.getOS() != Triple::AIX)
- return;
+ GTEST_SKIP();
// 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.
+ GTEST_SKIP(); // The version was configured explicitly; skip.
+ VersionTuple SystemVersion;
+ getAIXSystemVersion(SystemVersion);
VersionTuple TargetVersion = TargetTriple.getOSVersion();
ASSERT_EQ(SystemVersion.getMajor(), TargetVersion.getMajor());
ASSERT_EQ(SystemVersion.getMinor(), TargetVersion.getMinor());
@@ -486,7 +507,7 @@ TEST_F(HostTest, AIXVersionDetect) {
TEST_F(HostTest, AIXHostCPUDetect) {
llvm::Triple HostTriple(llvm::sys::getProcessTriple());
if (HostTriple.getOS() != Triple::AIX)
- return;
+ GTEST_SKIP();
// Return a value based on the current processor implementation mode.
const char *ExePath = "/usr/sbin/getsystype";