From 4e297c01eb6c45084ec183cc159291ea659de196 Mon Sep 17 00:00:00 2001 From: Axel Boldt-Christmas Date: Wed, 19 Nov 2025 14:13:15 +0000 Subject: [PATCH] ZGC: ZForwardingTest.find_every_other is mistaken for a other VM gtest --- src/hotspot/share/logging/logAsyncWriter.hpp | 4 +-- src/hotspot/share/logging/logStream.hpp | 10 +++--- test/hotspot/gtest/gtestMain.cpp | 6 ++-- test/hotspot/gtest/unittest.hpp | 35 ++++++++++++++------ 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/hotspot/share/logging/logAsyncWriter.hpp b/src/hotspot/share/logging/logAsyncWriter.hpp index a93b1ca58f6..736a9426bfe 100644 --- a/src/hotspot/share/logging/logAsyncWriter.hpp +++ b/src/hotspot/share/logging/logAsyncWriter.hpp @@ -1,6 +1,6 @@ /* * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. - * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -59,7 +59,7 @@ class LogFileStreamOutput; // ConfigurationLock. In addition flush() is called during JVM termination, via LogConfiguration::finalize. class AsyncLogWriter : public NonJavaThread { friend class AsyncLogTest; - friend class AsyncLogTest_logBuffer_vm_Test; + friend class AsyncLogTest_logBuffer__vm_Test; class Locker; class ProducerLocker; class ConsumerLocker; diff --git a/src/hotspot/share/logging/logStream.hpp b/src/hotspot/share/logging/logStream.hpp index d02961cd8c8..ecf1440c48a 100644 --- a/src/hotspot/share/logging/logStream.hpp +++ b/src/hotspot/share/logging/logStream.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,8 +31,9 @@ #include "utilities/ostream.hpp" class LogStreamImplBase : public outputStream { - friend class LogStreamTest_TestLineBufferAllocation_vm_Test; - friend class LogStreamTest_TestLineBufferAllocationCap_vm_Test; + // see test/hotspot/gtest/logging/test_logStream.cpp + friend class LogStreamTest_TestLineBufferAllocation__vm_Test; + friend class LogStreamTest_TestLineBufferAllocationCap__vm_Test; // No heap allocation of LogStream. static void* operator new (size_t) = delete; @@ -85,9 +86,6 @@ public: }; class LogStream : public LogStreamImpl { - // see test/hotspot/gtest/logging/test_logStream.cpp - friend class LogStreamTest_TestLineBufferAllocation_vm_Test; - friend class LogStreamTest_TestLineBufferAllocationCap_vm_Test; NONCOPYABLE(LogStream); diff --git a/test/hotspot/gtest/gtestMain.cpp b/test/hotspot/gtest/gtestMain.cpp index a1869ab5499..9b48429e26c 100644 --- a/test/hotspot/gtest/gtestMain.cpp +++ b/test/hotspot/gtest/gtestMain.cpp @@ -103,7 +103,7 @@ static int init_jvm(int argc, char **argv, bool disable_error_handling, JavaVM** } static bool is_same_vm_test(const char* name) { - return is_suffix("_vm", name) && !is_suffix("_other_vm", name); + return is_suffix("__vm", name); } class JVMInitializerListener : public ::testing::EmptyTestEventListener { @@ -234,8 +234,8 @@ static void runUnitTestsInner(int argc, char** argv) { if (::testing::GTEST_FLAG(internal_run_death_test).length() > 0) { // when we execute death test, filter value equals to test name const char* test_name = ::testing::GTEST_FLAG(filter).c_str(); - const char* const othervm_suffix = "_other_vm"; // TEST_OTHER_VM - const char* const vmassert_suffix = "_vm_assert"; // TEST_VM_ASSERT(_MSG) + const char* const othervm_suffix = "__other_vm"; // TEST_OTHER_VM + const char* const vmassert_suffix = "__vm_assert"; // TEST_VM_ASSERT(_MSG) if (is_suffix(othervm_suffix, test_name)) { is_othervm_test = true; } else if (is_suffix(vmassert_suffix, test_name)) { diff --git a/test/hotspot/gtest/unittest.hpp b/test/hotspot/gtest/unittest.hpp index 6a2cd400cb6..56ed1cef621 100644 --- a/test/hotspot/gtest/unittest.hpp +++ b/test/hotspot/gtest/unittest.hpp @@ -30,6 +30,7 @@ #include #define GTEST_DONT_DEFINE_TEST 1 +#define GTEST_DONT_DEFINE_TEST_F 1 // googlemock has ::testing::internal::Log function, so we need to temporary // undefine 'Log' from logging/log.hpp and define it back after gmock header @@ -54,6 +55,8 @@ BEGIN_ALLOW_FORBIDDEN_FUNCTIONS #include "gmock/gmock.h" #include "gtest/gtest.h" + +#include END_ALLOW_FORBIDDEN_FUNCTIONS #include "utilities/vmassert_reinstall.hpp" @@ -65,15 +68,27 @@ END_ALLOW_FORBIDDEN_FUNCTIONS // Wrapper around os::exit so we don't need to include os.hpp here. extern void gtest_exit_from_child_vm(int num); +constexpr bool gtest_check_valid_test_name(std::string_view name) { + auto ends_with = [&](std::string_view other) { + return name.size() >= other.size() && + name.compare(name.size() - other.size(), std::string_view::npos, other) == 0; + }; + + // Test names are not allowed to end in `_`, `__vm`, `__other_vm` or `__vm_assert` + return !ends_with("_") && !ends_with("__vm") && !ends_with("__other_vm") && !ends_with("__vm_assert"); +} + #define CONCAT(a, b) a ## b -#define TEST(category, name) GTEST_TEST(category, name) +#define HS_GTEST_CHECK_NAME(name) static_assert(gtest_check_valid_test_name(#name)); -#define TEST_VM(category, name) GTEST_TEST(category, CONCAT(name, _vm)) +#define TEST(category, name) HS_GTEST_CHECK_NAME(name) GTEST_TEST(category, name) -#define TEST_VM_F(test_fixture, name) \ - GTEST_TEST_(test_fixture, name ## _vm, test_fixture, \ - ::testing::internal::GetTypeId()) +#define TEST_F(category, name) HS_GTEST_CHECK_NAME(name) GTEST_TEST_F(category, name) + +#define TEST_VM(category, name) HS_GTEST_CHECK_NAME(name) GTEST_TEST(category, CONCAT(name, __vm)) + +#define TEST_VM_F(test_fixture, name) HS_GTEST_CHECK_NAME(name) GTEST_TEST_F(test_fixture, CONCAT(name, __vm)) #define TEST_OTHER_VM(category, name) \ static void test_ ## category ## _ ## name ## _(); \ @@ -94,7 +109,7 @@ extern void gtest_exit_from_child_vm(int num); gtest_exit_from_child_vm(0); \ } \ \ - TEST(category, CONCAT(name, _other_vm)) { \ + GTEST_TEST(category, CONCAT(name, __other_vm)) { \ ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \ ::testing::ExitedWithCode(0), \ ".*OKIDOKI.*"); \ @@ -112,7 +127,7 @@ extern void gtest_exit_from_child_vm(int num); gtest_exit_from_child_vm(0); \ } \ \ - TEST(category, CONCAT(name, _vm_assert)) { \ + GTEST_TEST(category, CONCAT(name, __vm_assert)) { \ ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \ ::testing::ExitedWithCode(1), \ "assert failed"); \ @@ -134,7 +149,7 @@ extern void gtest_exit_from_child_vm(int num); gtest_exit_from_child_vm(0); \ } \ \ - TEST(category, CONCAT(name, _vm_assert)) { \ + GTEST_TEST(category, CONCAT(name, __vm_assert)) { \ ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \ ::testing::ExitedWithCode(1), \ "assert failed: " msg); \ @@ -155,7 +170,7 @@ extern void gtest_exit_from_child_vm(int num); gtest_exit_from_child_vm(0); \ } \ \ - TEST(category, CONCAT(name, _vm_assert)) { \ + GTEST_TEST(category, CONCAT(name, __vm_assert)) { \ ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \ ::testing::ExitedWithCode(1), \ msg); \ @@ -172,7 +187,7 @@ extern void gtest_exit_from_child_vm(int num); gtest_exit_from_child_vm(0); \ } \ \ - TEST(category, CONCAT(name, _vm_assert)) { \ + GTEST_TEST(category, CONCAT(name, __vm_assert)) { \ ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \ ::testing::ExitedWithCode(1), \ "signaled: " signame); \