Skip to content

Commit ce5588f

Browse files
committed
[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.
1 parent a0ac6a9 commit ce5588f

File tree

1 file changed

+42
-21
lines changed

1 file changed

+42
-21
lines changed

llvm/unittests/Support/Host.cpp

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,18 @@ class HostTest : public testing::Test {
4747
HostTest() : Host(Triple::normalize(sys::getProcessTriple())) {}
4848
};
4949

50-
TEST_F(HostTest, NumPhysicalCores) {
50+
TEST_F(HostTest, NumPhysicalCoresSupported) {
51+
if (!isSupportedArchAndOS())
52+
GTEST_SKIP();
5153
int Num = sys::getHostNumPhysicalCores();
54+
ASSERT_GT(Num, 0);
55+
}
5256

57+
TEST_F(HostTest, NumPhysicalCoresUnsupported) {
5358
if (isSupportedArchAndOS())
54-
ASSERT_GT(Num, 0);
55-
else
56-
ASSERT_EQ(Num, -1);
59+
GTEST_SKIP();
60+
int Num = sys::getHostNumPhysicalCores();
61+
ASSERT_EQ(Num, -1);
5762
}
5863

5964
TEST(getLinuxHostCPUName, ARM) {
@@ -412,7 +417,7 @@ TEST_F(HostTest, DummyRunAndGetCommandOutputUse) {
412417
TEST_F(HostTest, getMacOSHostVersion) {
413418
llvm::Triple HostTriple(llvm::sys::getProcessTriple());
414419
if (!HostTriple.isMacOSX())
415-
return;
420+
GTEST_SKIP();
416421

417422
const char *SwVersPath = "/usr/bin/sw_vers";
418423
StringRef argv[] = {SwVersPath, "-productVersion"};
@@ -441,43 +446,59 @@ TEST_F(HostTest, getMacOSHostVersion) {
441446
}
442447
}
443448

444-
TEST_F(HostTest, AIXVersionDetect) {
445-
llvm::Triple HostTriple(llvm::sys::getProcessTriple());
446-
if (HostTriple.getOS() != Triple::AIX)
447-
return;
448-
449-
llvm::Triple ConfiguredHostTriple(LLVM_HOST_TRIPLE);
450-
ASSERT_EQ(ConfiguredHostTriple.getOS(), Triple::AIX);
451-
449+
// Helper to return AIX system version. Must return void to use ASSERT_*.
450+
static void getAIXSystemVersion(VersionTuple &SystemVersion) {
452451
const char *ExePath = "/usr/bin/oslevel";
453452
StringRef argv[] = {ExePath};
454453
std::unique_ptr<char[]> Buffer;
455454
off_t Size;
456455
ASSERT_EQ(runAndGetCommandOutput(ExePath, argv, Buffer, Size), true);
457456
StringRef SystemVersionStr = StringRef(Buffer.get(), Size).rtrim();
458457

459-
VersionTuple SystemVersion =
458+
SystemVersion =
460459
llvm::Triple((Twine("powerpc-ibm-aix") + SystemVersionStr))
461460
.getOSVersion();
461+
}
462+
463+
TEST_F(HostTest, AIXHostVersionDetect) {
464+
llvm::Triple HostTriple(llvm::sys::getProcessTriple());
465+
if (HostTriple.getOS() != Triple::AIX)
466+
GTEST_SKIP();
467+
468+
llvm::Triple ConfiguredHostTriple(LLVM_HOST_TRIPLE);
469+
ASSERT_EQ(ConfiguredHostTriple.getOS(), Triple::AIX);
470+
471+
VersionTuple SystemVersion;
472+
getAIXSystemVersion(SystemVersion);
462473

463474
// Ensure that the host triple version (major) and release (minor) numbers,
464475
// unless explicitly configured, match with those of the current system.
465-
if (!ConfiguredHostTriple.getOSMajorVersion()) {
466-
VersionTuple HostVersion = HostTriple.getOSVersion();
467-
ASSERT_EQ(SystemVersion.getMajor(), HostVersion.getMajor());
468-
ASSERT_EQ(SystemVersion.getMinor(), HostVersion.getMinor());
476+
auto SysMajor = SystemVersion.getMajor();
477+
auto SysMinor = SystemVersion.getMinor();
478+
VersionTuple HostVersion = HostTriple.getOSVersion();
479+
if (ConfiguredHostTriple.getOSMajorVersion()) {
480+
// Explicitly configured, force a match. We do it this way so the
481+
// asserts are always executed.
482+
SysMajor = HostVersion.getMajor();
483+
SysMinor = HostVersion.getMinor();
469484
}
485+
ASSERT_EQ(SysMajor, HostVersion.getMajor());
486+
ASSERT_EQ(SysMinor, HostVersion.getMinor());
487+
}
470488

489+
TEST_F(HostTest, AIXTargetVersionDetect) {
471490
llvm::Triple TargetTriple(llvm::sys::getDefaultTargetTriple());
472491
if (TargetTriple.getOS() != Triple::AIX)
473-
return;
492+
GTEST_SKIP();
474493

475494
// Ensure that the target triple version (major) and release (minor) numbers
476495
// match with those of the current system.
477496
llvm::Triple ConfiguredTargetTriple(LLVM_DEFAULT_TARGET_TRIPLE);
478497
if (ConfiguredTargetTriple.getOSMajorVersion())
479-
return; // The version was configured explicitly; skip.
498+
GTEST_SKIP(); // The version was configured explicitly; skip.
480499

500+
VersionTuple SystemVersion;
501+
getAIXSystemVersion(SystemVersion);
481502
VersionTuple TargetVersion = TargetTriple.getOSVersion();
482503
ASSERT_EQ(SystemVersion.getMajor(), TargetVersion.getMajor());
483504
ASSERT_EQ(SystemVersion.getMinor(), TargetVersion.getMinor());
@@ -486,7 +507,7 @@ TEST_F(HostTest, AIXVersionDetect) {
486507
TEST_F(HostTest, AIXHostCPUDetect) {
487508
llvm::Triple HostTriple(llvm::sys::getProcessTriple());
488509
if (HostTriple.getOS() != Triple::AIX)
489-
return;
510+
GTEST_SKIP();
490511

491512
// Return a value based on the current processor implementation mode.
492513
const char *ExePath = "/usr/sbin/getsystype";

0 commit comments

Comments
 (0)