Path: blob/master/test/hotspot/gtest/unittest.hpp
41140 views
/*1* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#ifndef UNITTEST_HPP24#define UNITTEST_HPP2526#include <stdlib.h>27#include <stdio.h>2829#define GTEST_DONT_DEFINE_TEST 13031// googlemock has ::testing::internal::Log function, so we need to temporary32// undefine 'Log' from logging/log.hpp and define it back after gmock header33// file is included. As SS compiler doesn't have push_/pop_macro pragmas and34// log.hpp might have been already included, we have to copy-paste macro definition.35#ifdef Log36#define UNDEFINED_Log37#undef Log38#endif3940// R macro is defined by src/hotspot/cpu/arm/register_arm.hpp, F$n are defined41// in ppc/register_ppc.hpp, these macros conflict with typenames used in42// internal googlemock templates. As the macros are not expected to be used by43// any of tests directly, and this header file is supposed to be the last44// include, we just undefine it; if/when it changes, we will need to re-define45// the macros after the following includes.46#undef R47#undef F148#undef F24950// A work around for GCC math header bug leaving isfinite() undefined,51// see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=1460852#include "utilities/globalDefinitions.hpp"5354#include "gmock/gmock.h"55#include "gtest/gtest.h"5657#ifdef UNDEFINED_Log58#define Log(...) LogImpl<LOG_TAGS(__VA_ARGS__)> // copied from logging/log.hpp59#undef UNDEFINED_Log60#endif6162// gtest/gtest.h includes assert.h which will define the assert macro, but hotspot has its63// own standards incompatible assert macro that takes two parameters.64// The workaround is to undef assert and then re-define it. The re-definition65// must unfortunately be copied since debug.hpp might already have been66// included and a second include wouldn't work due to the header guards in debug.hpp.67#ifdef assert68#undef assert69#ifdef vmassert70#define assert(p, ...) vmassert(p, __VA_ARGS__)71#endif72#endif7374#define CONCAT(a, b) a ## b7576#define TEST(category, name) GTEST_TEST(category, name)7778#define TEST_VM(category, name) GTEST_TEST(category, CONCAT(name, _vm))7980#define TEST_VM_F(test_fixture, name) \81GTEST_TEST_(test_fixture, name ## _vm, test_fixture, \82::testing::internal::GetTypeId<test_fixture>())8384#define TEST_OTHER_VM(category, name) \85static void test_ ## category ## _ ## name ## _(); \86\87static void child_ ## category ## _ ## name ## _() { \88::testing::GTEST_FLAG(throw_on_failure) = true; \89test_ ## category ## _ ## name ## _(); \90fprintf(stderr, "OKIDOKI"); \91exit(0); \92} \93\94TEST(category, CONCAT(name, _other_vm)) { \95ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \96::testing::ExitedWithCode(0), \97".*OKIDOKI.*"); \98} \99\100void test_ ## category ## _ ## name ## _()101102#ifdef ASSERT103#define TEST_VM_ASSERT(category, name) \104static void test_ ## category ## _ ## name ## _(); \105\106static void child_ ## category ## _ ## name ## _() { \107::testing::GTEST_FLAG(throw_on_failure) = true; \108test_ ## category ## _ ## name ## _(); \109exit(0); \110} \111\112TEST(category, CONCAT(name, _vm_assert)) { \113ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \114::testing::ExitedWithCode(1), \115"assert failed"); \116} \117\118void test_ ## category ## _ ## name ## _()119#else120#define TEST_VM_ASSERT(...) \121TEST_VM_ASSERT is only available in debug builds122#endif123124#ifdef ASSERT125#define TEST_VM_ASSERT_MSG(category, name, msg) \126static void test_ ## category ## _ ## name ## _(); \127\128static void child_ ## category ## _ ## name ## _() { \129::testing::GTEST_FLAG(throw_on_failure) = true; \130test_ ## category ## _ ## name ## _(); \131exit(0); \132} \133\134TEST(category, CONCAT(name, _vm_assert)) { \135ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \136::testing::ExitedWithCode(1), \137"assert failed: " msg); \138} \139\140void test_ ## category ## _ ## name ## _()141#else142#define TEST_VM_ASSERT_MSG(...) \143TEST_VM_ASSERT_MSG is only available in debug builds144#endif145146#endif // UNITTEST_HPP147148149