38255
|
1 |
/*
|
|
2 |
* Copyright (c) 2016, 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 |
|
39396
|
24 |
#ifndef UNITTEST_HPP
|
|
25 |
#define UNITTEST_HPP
|
|
26 |
|
38255
|
27 |
#include <stdlib.h>
|
|
28 |
#include <stdio.h>
|
|
29 |
|
|
30 |
#define GTEST_DONT_DEFINE_TEST 1
|
|
31 |
#include "gtest/gtest.h"
|
39395
|
32 |
|
|
33 |
// gtest/gtest.h includes assert.h which will define the assert macro, but hotspot has its
|
|
34 |
// own standards incompatible assert macro that takes two parameters.
|
|
35 |
// The workaround is to undef assert and then re-define it. The re-definition
|
|
36 |
// must unfortunately be copied since debug.hpp might already have been
|
|
37 |
// included and a second include wouldn't work due to the header guards in debug.hpp.
|
38255
|
38 |
#ifdef assert
|
|
39 |
#undef assert
|
39395
|
40 |
#ifdef vmassert
|
|
41 |
#define assert(p, ...) vmassert(p, __VA_ARGS__)
|
|
42 |
#endif
|
38255
|
43 |
#endif
|
|
44 |
|
|
45 |
#define CONCAT(a, b) a ## b
|
|
46 |
|
|
47 |
#define TEST(category, name) GTEST_TEST(category, CONCAT(name, _test))
|
|
48 |
|
|
49 |
#define TEST_VM(category, name) GTEST_TEST(category, CONCAT(name, _test_vm))
|
|
50 |
|
|
51 |
#define TEST_VM_F(test_fixture, name) \
|
|
52 |
GTEST_TEST_(test_fixture, name ## _test_vm, test_fixture, \
|
|
53 |
::testing::internal::GetTypeId<test_fixture>())
|
|
54 |
|
|
55 |
#define TEST_OTHER_VM(category, name) \
|
|
56 |
static void test_ ## category ## _ ## name ## _(); \
|
|
57 |
\
|
|
58 |
static void child_ ## category ## _ ## name ## _() { \
|
|
59 |
::testing::GTEST_FLAG(throw_on_failure) = true; \
|
|
60 |
test_ ## category ## _ ## name ## _(); \
|
|
61 |
fprintf(stderr, "OKIDOKI"); \
|
|
62 |
exit(0); \
|
|
63 |
} \
|
|
64 |
\
|
|
65 |
TEST(category, CONCAT(name, _other_vm)) { \
|
|
66 |
ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \
|
|
67 |
::testing::ExitedWithCode(0), \
|
|
68 |
".*OKIDOKI.*"); \
|
|
69 |
} \
|
|
70 |
\
|
|
71 |
void test_ ## category ## _ ## name ## _()
|
|
72 |
|
|
73 |
#ifdef ASSERT
|
|
74 |
#define TEST_VM_ASSERT(category, name) \
|
|
75 |
static void test_ ## category ## _ ## name ## _(); \
|
|
76 |
\
|
|
77 |
static void child_ ## category ## _ ## name ## _() { \
|
|
78 |
::testing::GTEST_FLAG(throw_on_failure) = true; \
|
|
79 |
test_ ## category ## _ ## name ## _(); \
|
|
80 |
exit(0); \
|
|
81 |
} \
|
|
82 |
\
|
|
83 |
TEST(category, CONCAT(name, _vm_assert)) { \
|
|
84 |
ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \
|
|
85 |
::testing::ExitedWithCode(1), \
|
|
86 |
"assert failed"); \
|
|
87 |
} \
|
|
88 |
\
|
|
89 |
void test_ ## category ## _ ## name ## _()
|
|
90 |
#else
|
|
91 |
#define TEST_VM_ASSERT(...) \
|
|
92 |
TEST_VM_ASSERT is only available in debug builds
|
|
93 |
#endif
|
|
94 |
|
|
95 |
#ifdef ASSERT
|
|
96 |
#define TEST_VM_ASSERT_MSG(category, name, msg) \
|
|
97 |
static void test_ ## category ## _ ## name ## _(); \
|
|
98 |
\
|
|
99 |
static void child_ ## category ## _ ## name ## _() { \
|
|
100 |
::testing::GTEST_FLAG(throw_on_failure) = true; \
|
|
101 |
test_ ## category ## _ ## name ## _(); \
|
|
102 |
exit(0); \
|
|
103 |
} \
|
|
104 |
\
|
|
105 |
TEST(category, CONCAT(name, _vm_assert)) { \
|
|
106 |
ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \
|
|
107 |
::testing::ExitedWithCode(1), \
|
|
108 |
"assert failed: " msg); \
|
|
109 |
} \
|
|
110 |
\
|
|
111 |
void test_ ## category ## _ ## name ## _()
|
|
112 |
#else
|
|
113 |
#define TEST_VM_ASSERT_MSG(...) \
|
|
114 |
TEST_VM_ASSERT_MSG is only available in debug builds
|
|
115 |
#endif
|
39396
|
116 |
|
|
117 |
#endif // UNITTEST_HPP
|