Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/gtest/unittest.hpp
64435 views
1
/*
2
* Copyright (c) 2016, 2021, 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
#ifndef UNITTEST_HPP
25
#define UNITTEST_HPP
26
27
#include <stdlib.h>
28
#include <stdio.h>
29
30
#define GTEST_DONT_DEFINE_TEST 1
31
32
// googlemock has ::testing::internal::Log function, so we need to temporary
33
// undefine 'Log' from logging/log.hpp and define it back after gmock header
34
// file is included. As SS compiler doesn't have push_/pop_macro pragmas and
35
// log.hpp might have been already included, we have to copy-paste macro definition.
36
#ifdef Log
37
#define UNDEFINED_Log
38
#undef Log
39
#endif
40
41
// R macro is defined by src/hotspot/cpu/arm/register_arm.hpp, F$n are defined
42
// in ppc/register_ppc.hpp, these macros conflict with typenames used in
43
// internal googlemock templates. As the macros are not expected to be used by
44
// any of tests directly, and this header file is supposed to be the last
45
// include, we just undefine it; if/when it changes, we will need to re-define
46
// the macros after the following includes.
47
#undef R
48
#undef F1
49
#undef F2
50
51
// A work around for GCC math header bug leaving isfinite() undefined,
52
// see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14608
53
#include "utilities/globalDefinitions.hpp"
54
55
#include "gmock/gmock.h"
56
#include "gtest/gtest.h"
57
58
#ifdef UNDEFINED_Log
59
#define Log(...) LogImpl<LOG_TAGS(__VA_ARGS__)> // copied from logging/log.hpp
60
#undef UNDEFINED_Log
61
#endif
62
63
// gtest/gtest.h includes assert.h which will define the assert macro, but hotspot has its
64
// own standards incompatible assert macro that takes two parameters.
65
// The workaround is to undef assert and then re-define it. The re-definition
66
// must unfortunately be copied since debug.hpp might already have been
67
// included and a second include wouldn't work due to the header guards in debug.hpp.
68
#ifdef assert
69
#undef assert
70
#ifdef vmassert
71
#define assert(p, ...) vmassert(p, __VA_ARGS__)
72
#endif
73
#endif
74
75
#define CONCAT(a, b) a ## b
76
77
#define TEST(category, name) GTEST_TEST(category, name)
78
79
#define TEST_VM(category, name) GTEST_TEST(category, CONCAT(name, _vm))
80
81
#define TEST_VM_F(test_fixture, name) \
82
GTEST_TEST_(test_fixture, name ## _vm, test_fixture, \
83
::testing::internal::GetTypeId<test_fixture>())
84
85
#define TEST_OTHER_VM(category, name) \
86
static void test_ ## category ## _ ## name ## _(); \
87
\
88
static void child_ ## category ## _ ## name ## _() { \
89
::testing::GTEST_FLAG(throw_on_failure) = true; \
90
test_ ## category ## _ ## name ## _(); \
91
JavaVM* jvm[1]; \
92
jsize nVMs = 0; \
93
JNI_GetCreatedJavaVMs(&jvm[0], 1, &nVMs); \
94
if (nVMs == 1) { \
95
int ret = jvm[0]->DestroyJavaVM(); \
96
if (ret != 0) { \
97
fprintf(stderr, "Warning: DestroyJavaVM error %d\n", ret); \
98
} \
99
} \
100
fprintf(stderr, "OKIDOKI"); \
101
exit(0); \
102
} \
103
\
104
TEST(category, CONCAT(name, _other_vm)) { \
105
ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \
106
::testing::ExitedWithCode(0), \
107
".*OKIDOKI.*"); \
108
} \
109
\
110
void test_ ## category ## _ ## name ## _()
111
112
#ifdef ASSERT
113
#define TEST_VM_ASSERT(category, name) \
114
static void test_ ## category ## _ ## name ## _(); \
115
\
116
static void child_ ## category ## _ ## name ## _() { \
117
::testing::GTEST_FLAG(throw_on_failure) = true; \
118
test_ ## category ## _ ## name ## _(); \
119
exit(0); \
120
} \
121
\
122
TEST(category, CONCAT(name, _vm_assert)) { \
123
ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \
124
::testing::ExitedWithCode(1), \
125
"assert failed"); \
126
} \
127
\
128
void test_ ## category ## _ ## name ## _()
129
#else
130
#define TEST_VM_ASSERT(...) \
131
TEST_VM_ASSERT is only available in debug builds
132
#endif
133
134
#ifdef ASSERT
135
#define TEST_VM_ASSERT_MSG(category, name, msg) \
136
static void test_ ## category ## _ ## name ## _(); \
137
\
138
static void child_ ## category ## _ ## name ## _() { \
139
::testing::GTEST_FLAG(throw_on_failure) = true; \
140
test_ ## category ## _ ## name ## _(); \
141
exit(0); \
142
} \
143
\
144
TEST(category, CONCAT(name, _vm_assert)) { \
145
ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \
146
::testing::ExitedWithCode(1), \
147
"assert failed: " msg); \
148
} \
149
\
150
void test_ ## category ## _ ## name ## _()
151
#else
152
#define TEST_VM_ASSERT_MSG(...) \
153
TEST_VM_ASSERT_MSG is only available in debug builds
154
#endif
155
156
#endif // UNITTEST_HPP
157
158