Path: blob/master/test/hotspot/gtest/utilities/test_vmerror.cpp
41144 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "precompiled.hpp"24#include "unittest.hpp"25#include "memory/allocation.hpp"26#include "memory/resourceArea.inline.hpp"27#include "runtime/thread.hpp"2829#ifdef ASSERT3031TEST_VM_ASSERT_MSG(vmErrorTest, resourceMark,32"fatal error: memory leak: allocating without ResourceMark") {3334// Check for assert when allocating from resource area without a35// ResourceMark. There must not be a ResourceMark on the36// current stack when invoking this test case.37ResourceArea* area = Thread::current()->resource_area();38assert(area->nesting() == 0, "unexpected ResourceMark");39area->allocate_bytes(100);40}4142const char* const str = "hello";43const size_t num = 500;4445TEST_VM_ASSERT_MSG(vmErrorTest, assert1, "assert.str == NULL. failed: expected null") {46vmassert(str == NULL, "expected null");47}4849TEST_VM_ASSERT_MSG(vmErrorTest, assert2, "assert.num == 1023 && .str == 'X'. failed: num=500 str=\"hello\"") {50vmassert(num == 1023 && *str == 'X',51"num=" SIZE_FORMAT " str=\"%s\"", num, str);52}5354TEST_VM_ASSERT_MSG(vmErrorTest, guarantee1, "guarantee.str == NULL. failed: expected null") {55guarantee(str == NULL, "expected null");56}5758TEST_VM_ASSERT_MSG(vmErrorTest, guarantee2, "guarantee.num == 1023 && .str == 'X'. failed: num=500 str=\"hello\"") {59guarantee(num == 1023 && *str == 'X',60"num=" SIZE_FORMAT " str=\"%s\"", num, str);61}6263TEST_VM_ASSERT_MSG(vmErrorTest, fatal1, "fatal error: expected null") {64fatal("expected null");65}6667TEST_VM_ASSERT_MSG(vmErrorTest, fatal2, "fatal error: num=500 str=\"hello\"") {68fatal("num=" SIZE_FORMAT " str=\"%s\"", num, str);69}7071TEST_VM_ASSERT_MSG(vmErrorTest, fatal3, "fatal error: this message should be truncated during formatting") {72const char* const eol = os::line_separator();73const char* const msg = "this message should be truncated during formatting";74fatal("%s%s# %s%s# %s%s# %s%s# %s%s# "75"%s%s# %s%s# %s%s# %s%s# %s%s# "76"%s%s# %s%s# %s%s# %s%s# %s",77msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,78msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,79msg, eol, msg, eol, msg, eol, msg, eol, msg);80}8182TEST_VM_ASSERT_MSG(vmErrorTest, out_of_memory1, "ChunkPool::allocate") {83const size_t num = (size_t)os::vm_page_size();84vm_exit_out_of_memory(num, OOM_MALLOC_ERROR, "ChunkPool::allocate");85}8687TEST_VM_ASSERT_MSG(vmErrorTest, shouldnotcallthis1, "Error: ShouldNotCall") {88ShouldNotCallThis();89}9091TEST_VM_ASSERT_MSG(vmErrorTest, shouldnotreachhere1, "Error: ShouldNotReachHere") {92ShouldNotReachHere();93}9495TEST_VM_ASSERT_MSG(vmErrorTest, unimplemented1, "Error: Unimplemented") {96Unimplemented();97}98#endif // ASSERT99100101