hotspot/test/native/unittest.hpp
author hseigel
Wed, 01 Mar 2017 08:00:02 -0500
changeset 46194 5596e6f63072
parent 41705 332239c052cc
permissions -rw-r--r--
8172307: Remove ununsed JVM API JVM_GetModuleByPackageName() Summary: Remove get_module_by_package_name() etc., and unneeded test. Reviewed-by: sspitsyn, gtriantafill
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     1
/*
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
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
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    31
#include "gtest/gtest.h"
39395
af07388255fc 8159365: assert is not defined for unit tests
ehelin
parents: 38255
diff changeset
    32
af07388255fc 8159365: assert is not defined for unit tests
ehelin
parents: 38255
diff changeset
    33
// 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
    34
// own standards incompatible assert macro that takes two parameters.
af07388255fc 8159365: assert is not defined for unit tests
ehelin
parents: 38255
diff changeset
    35
// 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
    36
// 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
    37
// 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
    38
#ifdef assert
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    39
  #undef assert
39395
af07388255fc 8159365: assert is not defined for unit tests
ehelin
parents: 38255
diff changeset
    40
  #ifdef vmassert
af07388255fc 8159365: assert is not defined for unit tests
ehelin
parents: 38255
diff changeset
    41
    #define assert(p, ...) vmassert(p, __VA_ARGS__)
af07388255fc 8159365: assert is not defined for unit tests
ehelin
parents: 38255
diff changeset
    42
  #endif
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    43
#endif
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    44
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    45
#define CONCAT(a, b) a ## b
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    46
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    47
#define TEST(category, name) GTEST_TEST(category, CONCAT(name, _test))
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    48
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    49
#define TEST_VM(category, name) GTEST_TEST(category, CONCAT(name, _test_vm))
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    50
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    51
#define TEST_VM_F(test_fixture, name)                               \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    52
  GTEST_TEST_(test_fixture, name ## _test_vm, test_fixture,         \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    53
              ::testing::internal::GetTypeId<test_fixture>())
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    54
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    55
#define TEST_OTHER_VM(category, name)                               \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    56
  static void test_  ## category ## _ ## name ## _();               \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    57
                                                                    \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    58
  static void child_ ## category ## _ ## name ## _() {              \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    59
    ::testing::GTEST_FLAG(throw_on_failure) = true;                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    60
    test_ ## category ## _ ## name ## _();                          \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    61
    fprintf(stderr, "OKIDOKI");                                     \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    62
    exit(0);                                                        \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    63
  }                                                                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    64
                                                                    \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    65
  TEST(category, CONCAT(name, _other_vm)) {                         \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    66
    ASSERT_EXIT(child_ ## category ## _ ## name ## _(),             \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    67
                ::testing::ExitedWithCode(0),                       \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    68
                ".*OKIDOKI.*");                                     \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    69
  }                                                                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    70
                                                                    \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    71
  void test_ ## category ## _ ## name ## _()
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    72
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    73
#ifdef ASSERT
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    74
#define TEST_VM_ASSERT(category, name)                              \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    75
  static void test_  ## category ## _ ## name ## _();               \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    76
                                                                    \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    77
  static void child_ ## category ## _ ## name ## _() {              \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    78
    ::testing::GTEST_FLAG(throw_on_failure) = true;                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    79
    test_ ## category ## _ ## name ## _();                          \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    80
    exit(0);                                                        \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    81
  }                                                                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    82
                                                                    \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    83
  TEST(category, CONCAT(name, _vm_assert)) {                        \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    84
    ASSERT_EXIT(child_ ## category ## _ ## name ## _(),             \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    85
                ::testing::ExitedWithCode(1),                       \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    86
                "assert failed");                                   \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    87
  }                                                                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    88
                                                                    \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    89
  void test_ ## category ## _ ## name ## _()
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    90
#else
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    91
#define TEST_VM_ASSERT(...)                                         \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    92
    TEST_VM_ASSERT is only available in debug builds
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    93
#endif
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    94
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    95
#ifdef ASSERT
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    96
#define TEST_VM_ASSERT_MSG(category, name, msg)                     \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    97
  static 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
  static void child_ ## category ## _ ## name ## _() {              \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   100
    ::testing::GTEST_FLAG(throw_on_failure) = true;                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   101
    test_ ## category ## _ ## name ## _();                          \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   102
    exit(0);                                                        \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   103
  }                                                                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   104
                                                                    \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   105
  TEST(category, CONCAT(name, _vm_assert)) {                        \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   106
    ASSERT_EXIT(child_ ## category ## _ ## name ## _(),             \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   107
                ::testing::ExitedWithCode(1),                       \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   108
                "assert failed: " msg);                             \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   109
  }                                                                 \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   110
                                                                    \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   111
  void test_ ## category ## _ ## name ## _()
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   112
#else
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   113
#define TEST_VM_ASSERT_MSG(...)                                     \
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   114
    TEST_VM_ASSERT_MSG is only available in debug builds
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   115
#endif
39396
84aae7f2f638 8159366: Header guards missing for unittest.hpp
ehelin
parents: 39395
diff changeset
   116
84aae7f2f638 8159366: Header guards missing for unittest.hpp
ehelin
parents: 39395
diff changeset
   117
#endif // UNITTEST_HPP