From df5b105bbb55d9cc923ac45ff99e702126626670 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Tue, 18 Nov 2025 11:57:58 +0000 Subject: [PATCH] 8371698: ZGC: Call GTEST_SKIP when OS is unsupported Reviewed-by: aboldtch, jsikstro, mdoerr --- test/hotspot/gtest/gc/z/test_zForwarding.cpp | 10 ---------- test/hotspot/gtest/gc/z/test_zMapper_windows.cpp | 10 ---------- test/hotspot/gtest/gc/z/test_zVirtualMemoryManager.cpp | 10 ---------- test/hotspot/gtest/gc/z/zunittest.hpp | 10 +++++++++- 4 files changed, 9 insertions(+), 31 deletions(-) diff --git a/test/hotspot/gtest/gc/z/test_zForwarding.cpp b/test/hotspot/gtest/gc/z/test_zForwarding.cpp index 3a69ff3cbb7..5275b78fb82 100644 --- a/test/hotspot/gtest/gc/z/test_zForwarding.cpp +++ b/test/hotspot/gtest/gc/z/test_zForwarding.cpp @@ -51,11 +51,6 @@ public: zoffset _page_offset; virtual void SetUp() { - // Only run test on supported Windows versions - if (!is_os_supported()) { - GTEST_SKIP() << "OS not supported"; - } - _old_heap = ZHeap::_heap; ZHeap::_heap = (ZHeap*)os::malloc(sizeof(ZHeap), mtTest); @@ -83,11 +78,6 @@ public: } virtual void TearDown() { - if (!is_os_supported()) { - // Test skipped, nothing to cleanup - return; - } - os::free(ZHeap::_heap); ZHeap::_heap = _old_heap; ZGeneration::_old = _old_old; diff --git a/test/hotspot/gtest/gc/z/test_zMapper_windows.cpp b/test/hotspot/gtest/gc/z/test_zMapper_windows.cpp index 1789d2e3b43..95e6317dfd8 100644 --- a/test/hotspot/gtest/gc/z/test_zMapper_windows.cpp +++ b/test/hotspot/gtest/gc/z/test_zMapper_windows.cpp @@ -42,11 +42,6 @@ private: public: virtual void SetUp() { - // Only run test on supported Windows versions - if (!is_os_supported()) { - GTEST_SKIP() << "OS not supported"; - } - _zaddress_reserver.SetUp(ReservationSize); _reserver = _zaddress_reserver.reserver(); _registry = _zaddress_reserver.registry(); @@ -58,11 +53,6 @@ public: } virtual void TearDown() { - if (!is_os_supported()) { - // Test skipped, nothing to cleanup - return; - } - // Best-effort cleanup _registry = nullptr; _reserver = nullptr; diff --git a/test/hotspot/gtest/gc/z/test_zVirtualMemoryManager.cpp b/test/hotspot/gtest/gc/z/test_zVirtualMemoryManager.cpp index 2b6fbc198ca..7c41dde04cb 100644 --- a/test/hotspot/gtest/gc/z/test_zVirtualMemoryManager.cpp +++ b/test/hotspot/gtest/gc/z/test_zVirtualMemoryManager.cpp @@ -62,11 +62,6 @@ private: public: virtual void SetUp() { - // Only run test on supported Windows versions - if (!is_os_supported()) { - GTEST_SKIP() << "OS not supported"; - } - _zaddress_reserver.SetUp(ReservationSize); _reserver = _zaddress_reserver.reserver(); _registry = _zaddress_reserver.registry(); @@ -78,11 +73,6 @@ public: } virtual void TearDown() { - if (!is_os_supported()) { - // Test skipped, nothing to cleanup - return; - } - _registry = nullptr; _reserver = nullptr; _zaddress_reserver.TearDown(); diff --git a/test/hotspot/gtest/gc/z/zunittest.hpp b/test/hotspot/gtest/gc/z/zunittest.hpp index a4586d51a0e..2464f821380 100644 --- a/test/hotspot/gtest/gc/z/zunittest.hpp +++ b/test/hotspot/gtest/gc/z/zunittest.hpp @@ -76,7 +76,6 @@ public: } void SetUp(size_t reservation_size) { - GTEST_EXPECT_TRUE(ZArguments::is_os_supported()) << "Should not use SetUp on unsupported systems"; GTEST_EXPECT_FALSE(_active) << "SetUp called twice without a TearDown"; _active = true; @@ -109,12 +108,21 @@ private: ZAddressOffsetMaxSetter _zaddress_offset_max_setter; unsigned int _rand_seed; + void skip_all_tests() { + // Skipping from the constructor currently works, but according to the + // documentation the GTEST_SKIP macro should be used from the test or + // from the SetUp function. If this start to fail down the road, then + // we'll have to explicitly call this for each inheriting gtest. + GTEST_SKIP() << "OS not supported"; + } + protected: ZTest() : _zaddress_offset_max_setter(ZAddressOffsetMax), _rand_seed(static_cast(::testing::UnitTest::GetInstance()->random_seed())) { if (!is_os_supported()) { // If the OS does not support ZGC do not run initialization, as it may crash the VM. + skip_all_tests(); return; }