diff --git a/src/hotspot/share/utilities/vmError.cpp b/src/hotspot/share/utilities/vmError.cpp index 8dd3c99db95..9e06614bc7e 100644 --- a/src/hotspot/share/utilities/vmError.cpp +++ b/src/hotspot/share/utilities/vmError.cpp @@ -1,7 +1,7 @@ /* * Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2024 SAP SE. All rights reserved. - * Copyright (c) 2023, Red Hat, Inc. and/or its affiliates. + * Copyright (c) 2023, 2025, Red Hat, Inc. and/or its affiliates. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1550,6 +1550,12 @@ void VMError::report_and_die(Thread* thread, const void* context, const char* fi void VMError::report_and_die(Thread* thread, unsigned int sig, address pc, const void* siginfo, const void* context) { + if (ExecutingUnitTests) { + // See TEST_VM_CRASH_SIGNAL gtest macro + char tmp[64]; + fprintf(stderr, "signaled: %s", os::exception_name(sig, tmp, sizeof(tmp))); + } + report_and_die(thread, sig, pc, siginfo, context, "%s", ""); } diff --git a/test/hotspot/gtest/unittest.hpp b/test/hotspot/gtest/unittest.hpp index e8f5817c4a6..c6ec593733c 100644 --- a/test/hotspot/gtest/unittest.hpp +++ b/test/hotspot/gtest/unittest.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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 @@ -159,4 +159,22 @@ extern void gtest_exit_from_child_vm(int num); \ void test_ ## category ## _ ## name ## _() +#define TEST_VM_CRASH_SIGNAL(category, name, signame) \ + static void test_ ## category ## _ ## name ## _(); \ + \ + static void child_ ## category ## _ ## name ## _() { \ + ::testing::GTEST_FLAG(throw_on_failure) = true; \ + test_ ## category ## _ ## name ## _(); \ + gtest_exit_from_child_vm(0); \ + } \ + \ + TEST(category, CONCAT(name, _vm_assert)) { \ + ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \ + ::testing::ExitedWithCode(1), \ + "signaled: " signame); \ + } \ + \ + void test_ ## category ## _ ## name ## _() + + #endif // UNITTEST_HPP