jdk

Форк
0
/
test_vmerror.cpp 
99 строк · 3.7 Кб
1
/*
2
 * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.
8
 *
9
 * This code is distributed in the hope that it will be useful, but WITHOUT
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
 * version 2 for more details (a copy is included in the LICENSE file that
13
 * accompanied this code).
14
 *
15
 * You should have received a copy of the GNU General Public License version
16
 * 2 along with this work; if not, write to the Free Software Foundation,
17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
 * or visit www.oracle.com if you need additional information or have any
21
 * questions.
22
 */
23

24
#include "precompiled.hpp"
25
#include "unittest.hpp"
26
#include "memory/allocation.hpp"
27
#include "memory/resourceArea.inline.hpp"
28
#include "runtime/thread.hpp"
29

30
#ifdef ASSERT
31

32
TEST_VM_ASSERT_MSG(vmErrorTest, resourceMark,
33
                  "fatal error: memory leak: allocating without ResourceMark") {
34

35
  // Check for assert when allocating from resource area without a
36
  // ResourceMark.  There must not be a ResourceMark on the
37
  // current stack when invoking this test case.
38
  ResourceArea* area = Thread::current()->resource_area();
39
  assert(area->nesting() == 0, "unexpected ResourceMark");
40
  area->allocate_bytes(100);
41
}
42

43
const char* const str = "hello";
44
const size_t      num = 500;
45

46
TEST_VM_ASSERT_MSG(vmErrorTest, assert1, "assert.str == nullptr. failed: expected null") {
47
  vmassert(str == nullptr, "expected null");
48
}
49

50
TEST_VM_ASSERT_MSG(vmErrorTest, assert2, "assert.num == 1023 && .str == 'X'. failed: num=500 str=\"hello\"") {
51
  vmassert(num == 1023 && *str == 'X',
52
           "num=" SIZE_FORMAT " str=\"%s\"", num, str);
53
}
54

55
TEST_VM_ASSERT_MSG(vmErrorTest, guarantee1, "guarantee.str == nullptr. failed: expected null") {
56
  guarantee(str == nullptr, "expected null");
57
}
58

59
TEST_VM_ASSERT_MSG(vmErrorTest, guarantee2, "guarantee.num == 1023 && .str == 'X'. failed: num=500 str=\"hello\"") {
60
  guarantee(num == 1023 && *str == 'X',
61
            "num=" SIZE_FORMAT " str=\"%s\"", num, str);
62
}
63

64
TEST_VM_ASSERT_MSG(vmErrorTest, fatal1, "fatal error: expected null") {
65
  fatal("expected null");
66
}
67

68
TEST_VM_ASSERT_MSG(vmErrorTest, fatal2, "fatal error: num=500 str=\"hello\"") {
69
  fatal("num=" SIZE_FORMAT " str=\"%s\"", num, str);
70
}
71

72
TEST_VM_ASSERT_MSG(vmErrorTest, fatal3, "fatal error: this message should be truncated during formatting") {
73
  const char* const eol = os::line_separator();
74
  const char* const msg = "this message should be truncated during formatting";
75
  fatal("%s%s#    %s%s#    %s%s#    %s%s#    %s%s#    "
76
        "%s%s#    %s%s#    %s%s#    %s%s#    %s%s#    "
77
        "%s%s#    %s%s#    %s%s#    %s%s#    %s",
78
        msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
79
        msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
80
        msg, eol, msg, eol, msg, eol, msg, eol, msg);
81
}
82

83
TEST_VM_ASSERT_MSG(vmErrorTest, out_of_memory1, "ChunkPool::allocate") {
84
  const size_t      num = (size_t)os::vm_page_size();
85
  vm_exit_out_of_memory(num, OOM_MALLOC_ERROR, "ChunkPool::allocate");
86
}
87

88
TEST_VM_ASSERT_MSG(vmErrorTest, shouldnotcallthis1, "Error: ShouldNotCall") {
89
  ShouldNotCallThis();
90
}
91

92
TEST_VM_ASSERT_MSG(vmErrorTest, shouldnotreachhere1, "Error: ShouldNotReachHere") {
93
  ShouldNotReachHere();
94
}
95

96
TEST_VM_ASSERT_MSG(vmErrorTest, unimplemented1, "Error: Unimplemented") {
97
  Unimplemented();
98
}
99
#endif // ASSERT
100

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.