Skip to content

Commit

Permalink
8348029: Make gtest death tests work with real crash signals
Browse files Browse the repository at this point in the history
Reviewed-by: mbaesken, szaldana
  • Loading branch information
tstuefe committed Jan 21, 2025
1 parent 4a9fba6 commit 48c7597
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/hotspot/share/utilities/vmError.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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", "");
}

Expand Down
20 changes: 19 additions & 1 deletion test/hotspot/gtest/unittest.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

1 comment on commit 48c7597

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.