8348029: Make gtest death tests work with real crash signals

Reviewed-by: mbaesken, szaldana
This commit is contained in:
Thomas Stuefe 2025-01-21 14:46:25 +00:00
parent 4a9fba615d
commit 48c75976b1
2 changed files with 26 additions and 2 deletions

View File

@ -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", "");
}

View File

@ -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