test/hotspot/gtest/unittest.hpp
author dfuchs
Fri, 06 Sep 2019 14:04:44 +0100
changeset 58031 5aaf53d4fe63
parent 55091 c58772f2dbce
permissions -rw-r--r--
8230694: http.keepAlive system property is inconsistently/incorrectly documented Summary: trivially fixed the net-properties.html file Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     1
/*
55049
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents: 53757
diff changeset
     2
 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     4
 *
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     8
 *
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    14
 *
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    18
 *
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    21
 * questions.
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    22
 */
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    23
39396
84aae7f2f638 8159366: Header guards missing for unittest.hpp
ehelin
parents: 39395
diff changeset
    24
#ifndef UNITTEST_HPP
84aae7f2f638 8159366: Header guards missing for unittest.hpp
ehelin
parents: 39395
diff changeset
    25
#define UNITTEST_HPP
84aae7f2f638 8159366: Header guards missing for unittest.hpp
ehelin
parents: 39395
diff changeset
    26
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    27
#include <stdlib.h>
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    28
#include <stdio.h>
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    29
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    30
#define GTEST_DONT_DEFINE_TEST 1
55049
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents: 53757
diff changeset
    31
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents: 53757
diff changeset
    32
// googlemock has ::testing::internal::Log function, so we need to temporary
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents: 53757
diff changeset
    33
// undefine 'Log' from logging/log.hpp and define it back after gmock header
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents: 53757
diff changeset
    34
// file is included. As SS compiler doesn't have push_/pop_macro pragmas and
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents: 53757
diff changeset
    35
// log.hpp might have been already included, we have to copy-paste macro definition.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents: 53757
diff changeset
    36
#ifdef Log
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents: 53757
diff changeset
    37
  #define UNDEFINED_Log
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents: 53757
diff changeset
    38
  #undef Log
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents: 53757
diff changeset
    39
#endif
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents: 53757
diff changeset
    40
55091
c58772f2dbce 8224945: googlemock update breaks the build of arm32 and ppc
iignatyev
parents: 55049
diff changeset
    41
// R macro is defined by src/hotspot/cpu/arm/register_arm.hpp, F$n are defined
c58772f2dbce 8224945: googlemock update breaks the build of arm32 and ppc
iignatyev
parents: 55049
diff changeset
    42
// in ppc/register_ppc.hpp, these macros conflict with typenames used in
c58772f2dbce 8224945: googlemock update breaks the build of arm32 and ppc
iignatyev
parents: 55049
diff changeset
    43
// internal googlemock templates. As the macros are not expected to be used by
c58772f2dbce 8224945: googlemock update breaks the build of arm32 and ppc
iignatyev
parents: 55049
diff changeset
    44
// any of tests directly, and this header file is supposed to be the last
c58772f2dbce 8224945: googlemock update breaks the build of arm32 and ppc
iignatyev
parents: 55049
diff changeset
    45
// include, we just undefine it; if/when it changes, we will need to re-define
c58772f2dbce 8224945: googlemock update breaks the build of arm32 and ppc
iignatyev
parents: 55049
diff changeset
    46
// the macros after the following includes.
c58772f2dbce 8224945: googlemock update breaks the build of arm32 and ppc
iignatyev
parents: 55049
diff changeset
    47
#undef R
c58772f2dbce 8224945: googlemock update breaks the build of arm32 and ppc
iignatyev
parents: 55049
diff changeset
    48
#undef F1
c58772f2dbce 8224945: googlemock update breaks the build of arm32 and ppc
iignatyev
parents: 55049
diff changeset
    49
#undef F2
c58772f2dbce 8224945: googlemock update breaks the build of arm32 and ppc
iignatyev
parents: 55049
diff changeset
    50
55049
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents: 53757
diff changeset
    51
#include "gmock/gmock.h"
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    52
#include "gtest/gtest.h"
39395
af07388255fc 8159365: assert is not defined for unit tests
ehelin
parents: 38255
diff changeset
    53
55049
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents: 53757
diff changeset
    54
#ifdef UNDEFINED_Log
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents: 53757
diff changeset
    55
  #define Log(...)  LogImpl<LOG_TAGS(__VA_ARGS__)> // copied from logging/log.hpp
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents: 53757
diff changeset
    56
  #undef UNDEFINED_Log
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents: 53757
diff changeset
    57
#endif
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents: 53757
diff changeset
    58
39395
af07388255fc 8159365: assert is not defined for unit tests
ehelin
parents: 38255
diff changeset
    59
// gtest/gtest.h includes assert.h which will define the assert macro, but hotspot has its
af07388255fc 8159365: assert is not defined for unit tests
ehelin
parents: 38255
diff changeset
    60
// own standards incompatible assert macro that takes two parameters.
af07388255fc 8159365: assert is not defined for unit tests
ehelin
parents: 38255
diff changeset
    61
// The workaround is to undef assert and then re-define it. The re-definition
af07388255fc 8159365: assert is not defined for unit tests
ehelin
parents: 38255
diff changeset
    62
// must unfortunately be copied since debug.hpp might already have been
af07388255fc 8159365: assert is not defined for unit tests
ehelin
parents: 38255
diff changeset
    63
// included and a second include wouldn't work due to the header guards in debug.hpp.
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    64
#ifdef assert
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    65
  #undef assert
39395
af07388255fc 8159365: assert is not defined for unit tests
ehelin
parents: 38255
diff changeset
    66
  #ifdef vmassert
af07388255fc 8159365: assert is not defined for unit tests
ehelin
parents: 38255
diff changeset
    67
    #define assert(p, ...) vmassert(p, __VA_ARGS__)
af07388255fc 8159365: assert is not defined for unit tests
ehelin
parents: 38255
diff changeset
    68
  #endif
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    69
#endif
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    70
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    71
#define CONCAT(a, b) a ## b
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    72
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    73
#define TEST(category, name) GTEST_TEST(category, CONCAT(name, _test))
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    74
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    75
#define TEST_VM(category, name) GTEST_TEST(category, CONCAT(name, _test_vm))
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    76
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    77
#define TEST_VM_F(test_fixture, name)                               \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    78
  GTEST_TEST_(test_fixture, name ## _test_vm, test_fixture,         \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    79
              ::testing::internal::GetTypeId<test_fixture>())
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    80
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    81
#define TEST_OTHER_VM(category, name)                               \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    82
  static void test_  ## category ## _ ## name ## _();               \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    83
                                                                    \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    84
  static void child_ ## category ## _ ## name ## _() {              \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    85
    ::testing::GTEST_FLAG(throw_on_failure) = true;                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    86
    test_ ## category ## _ ## name ## _();                          \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    87
    fprintf(stderr, "OKIDOKI");                                     \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    88
    exit(0);                                                        \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    89
  }                                                                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    90
                                                                    \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    91
  TEST(category, CONCAT(name, _other_vm)) {                         \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    92
    ASSERT_EXIT(child_ ## category ## _ ## name ## _(),             \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    93
                ::testing::ExitedWithCode(0),                       \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    94
                ".*OKIDOKI.*");                                     \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    95
  }                                                                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    96
                                                                    \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    97
  void test_ ## category ## _ ## name ## _()
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    98
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    99
#ifdef ASSERT
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   100
#define TEST_VM_ASSERT(category, name)                              \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   101
  static void test_  ## category ## _ ## name ## _();               \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   102
                                                                    \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   103
  static void child_ ## category ## _ ## name ## _() {              \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   104
    ::testing::GTEST_FLAG(throw_on_failure) = true;                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   105
    test_ ## category ## _ ## name ## _();                          \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   106
    exit(0);                                                        \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   107
  }                                                                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   108
                                                                    \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   109
  TEST(category, CONCAT(name, _vm_assert)) {                        \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   110
    ASSERT_EXIT(child_ ## category ## _ ## name ## _(),             \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   111
                ::testing::ExitedWithCode(1),                       \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   112
                "assert failed");                                   \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   113
  }                                                                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   114
                                                                    \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   115
  void test_ ## category ## _ ## name ## _()
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   116
#else
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   117
#define TEST_VM_ASSERT(...)                                         \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   118
    TEST_VM_ASSERT is only available in debug builds
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   119
#endif
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   120
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   121
#ifdef ASSERT
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   122
#define TEST_VM_ASSERT_MSG(category, name, msg)                     \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   123
  static void test_  ## category ## _ ## name ## _();               \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   124
                                                                    \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   125
  static void child_ ## category ## _ ## name ## _() {              \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   126
    ::testing::GTEST_FLAG(throw_on_failure) = true;                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   127
    test_ ## category ## _ ## name ## _();                          \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   128
    exit(0);                                                        \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   129
  }                                                                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   130
                                                                    \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   131
  TEST(category, CONCAT(name, _vm_assert)) {                        \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   132
    ASSERT_EXIT(child_ ## category ## _ ## name ## _(),             \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   133
                ::testing::ExitedWithCode(1),                       \
53757
e31f39e088b7 8183004: Remove code related to gtest death tests from assert macro
stuefe
parents: 47216
diff changeset
   134
                "^assert failed: " msg);                             \
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   135
  }                                                                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   136
                                                                    \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   137
  void test_ ## category ## _ ## name ## _()
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   138
#else
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   139
#define TEST_VM_ASSERT_MSG(...)                                     \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   140
    TEST_VM_ASSERT_MSG is only available in debug builds
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   141
#endif
39396
84aae7f2f638 8159366: Header guards missing for unittest.hpp
ehelin
parents: 39395
diff changeset
   142
84aae7f2f638 8159366: Header guards missing for unittest.hpp
ehelin
parents: 39395
diff changeset
   143
#endif // UNITTEST_HPP