[llvm] ce5588f - [RGT] Refactor environment-specific checks to use GTEST_SKIP()
Paul Robinson via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 11 10:47:37 PST 2022
Author: Paul Robinson
Date: 2022-02-11T10:47:07-08:00
New Revision: ce5588fdf478b6af724977c11a405685cebc3d26
URL: https://github.com/llvm/llvm-project/commit/ce5588fdf478b6af724977c11a405685cebc3d26
DIFF: https://github.com/llvm/llvm-project/commit/ce5588fdf478b6af724977c11a405685cebc3d26.diff
LOG: [RGT] Refactor environment-specific checks to use GTEST_SKIP()
This allows using GTEST_SKIP() to identify un-executed tests.
Found by the Rotten Green Tests project.
Added:
Modified:
llvm/unittests/Support/Host.cpp
Removed:
################################################################################
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 @@ class HostTest : public testing::Test {
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";
More information about the llvm-commits
mailing list