8148244: Finalize and integrate GTest implementation

Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Stefan Sarne <stefan.sarne@oracle.com>
Co-authored-by: Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>
Co-authored-by: Erik Helin <erik.helin@oracle.com>
Co-authored-by: Alexandre Iline <alexandre.iline@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Reviewed-by: jwilhelm, erikj
This commit is contained in:
Igor Ignatyev 2016-05-09 14:15:40 +03:00
parent 66686b8152
commit dc12061bb6
10 changed files with 662 additions and 10 deletions

@ -0,0 +1,116 @@
#
# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
GTEST_TEST_SRC := $(HOTSPOT_TOPDIR)/test/native
GTEST_FRAMEWORK_SRC := $(SRC_ROOT)/test/fmw/gtest
# On Windows, there are no internal debug symbols so must set copying to true
# to get any at all.
ifeq ($(OPENJDK_TARGET_OS), windows)
GTEST_COPY_DEBUG_SYMBOLS := true
else
GTEST_COPY_DEBUG_SYMBOLS := false
endif
################################################################################
GTEST_TEST_SRC_FILES := $(shell $(FIND) $(HOTSPOT_TOPDIR)/test/native -name \
"test*.cpp" -type f)
ifeq ($(OPENJDK_TARGET_OS), windows)
GTEST_JVM_MAPFILE := $(JVM_MAPFILE)
else
GTEST_JVM_MAPFILE := $(JVM_OUTPUTDIR)/gtest/mapfile
$(JVM_OUTPUTDIR)/gtest/symbols: $(JVM_OUTPUTDIR)/symbols
$(call MakeDir, $(@D))
( $(CAT) $< ; echo "runUnitTests" ) > $@
$(GTEST_JVM_MAPFILE): $(JVM_OUTPUTDIR)/gtest/symbols
$(call create-mapfile)
endif
# Disabling switch warning for clang because of test source.
$(eval $(call SetupNativeCompilation, BUILD_GTEST_LIBJVM, \
TOOLCHAIN := $(JVM_TOOLCHAIN), \
LIBRARY := jvm, \
OUTPUT_DIR := $(JVM_OUTPUTDIR)/gtest, \
EXTRA_FILES := $(GTEST_TEST_SRC_FILES) \
$(GTEST_FRAMEWORK_SRC)/src/gtest-all.cc \
$(GTEST_TEST_SRC)/gtestMain.cpp, \
OBJECT_DIR := $(JVM_OUTPUTDIR)/gtest/objs, \
EXTRA_OBJECT_FILES := $(filter-out %/operator_new$(OBJ_SUFFIX), \
$(BUILD_LIBJVM_ALL_OBJS)), \
CFLAGS := $(JVM_CFLAGS) -I$(GTEST_FRAMEWORK_SRC) \
-I$(GTEST_FRAMEWORK_SRC)/include \
-I$(GTEST_TEST_SRC), \
CFLAGS_windows := /EHsc, \
CFLAGS_solaris := -DGTEST_HAS_EXCEPTIONS=0 -library=stlport4, \
CFLAGS_macosx := -DGTEST_OS_MAC=1, \
CFLAGS_DEBUG_SYMBOLS := $(JVM_CFLAGS_SYMBOLS), \
CXXFLAGS_DEBUG_SYMBOLS := $(JVM_CFLAGS_SYMBOLS), \
DISABLED_WARNINGS_gcc := undef, \
DISABLED_WARNINGS_clang := undef switch format-nonliteral \
tautological-undefined-compare, \
DISABLED_WARNINGS_solstudio := identexpected, \
LDFLAGS := $(JVM_LDFLAGS), \
LDFLAGS_solaris := -library=stlport4 $(call SET_SHARED_LIBRARY_ORIGIN), \
LIBS := $(JVM_LIBS), \
OPTIMIZATION := $(JVM_OPTIMIZATION), \
MAPFILE := $(GTEST_JVM_MAPFILE), \
USE_MAPFILE_FOR_SYMBOLS := true, \
COPY_DEBUG_SYMBOLS := $(GTEST_COPY_DEBUG_SYMBOLS), \
ZIP_EXTERNAL_DEBUG_SYMBOLS := false, \
))
TARGETS += $(BUILD_GTEST_LIBJVM)
################################################################################
$(eval $(call SetupNativeCompilation, BUILD_GTEST_LAUNCHER, \
TOOLCHAIN := $(JVM_TOOLCHAIN), \
PROGRAM := gtestLauncher, \
OUTPUT_DIR := $(JVM_OUTPUTDIR)/gtest, \
EXTRA_FILES := $(GTEST_TEST_SRC)/gtestLauncher.cpp, \
OBJECT_DIR := $(JVM_OUTPUTDIR)/gtest/launcher-objs, \
CFLAGS := $(JVM_CFLAGS) -I$(GTEST_FRAMEWORK_SRC) \
-I$(GTEST_FRAMEWORK_SRC)/include, \
CFLAGS_DEBUG_SYMBOLS := $(JVM_CFLAGS_SYMBOLS), \
CXXFLAGS_DEBUG_SYMBOLS := $(JVM_CFLAGS_SYMBOLS), \
LDFLAGS := $(LDFLAGS_TESTEXE), \
LDFLAGS_unix := -L$(JVM_OUTPUTDIR)/gtest $(call SET_SHARED_LIBRARY_ORIGIN), \
LDFLAGS_solaris := -library=stlport4, \
LIBS_unix := -ljvm, \
LIBS_windows := $(JVM_OUTPUTDIR)/gtest/objs/jvm.lib, \
COPY_DEBUG_SYMBOLS := $(GTEST_COPY_DEBUG_SYMBOLS), \
ZIP_EXTERNAL_DEBUG_SYMBOLS := false, \
))
$(BUILD_GTEST_LAUNCHER): $(BUILD_GTEST_LIBJVM)
TARGETS += $(BUILD_GTEST_LAUNCHER)
################################################################################

@ -37,6 +37,10 @@ include lib/CompileDtracePreJvm.gmk
include lib/CompileJvm.gmk
include lib/CompileDtracePostJvm.gmk
ifeq ($(BUILD_GTEST), true)
include lib/CompileGtest.gmk
endif
all: $(TARGETS)
.PHONY: all

@ -153,20 +153,33 @@ $(JVM_OUTPUTDIR)/symbols: $(SYMBOLS_SRC)
################################################################################
# Finally convert the symbol list into a platform-specific mapfile
$(JVM_MAPFILE): $(JVM_OUTPUTDIR)/symbols
$(call LogInfo, Creating mapfile)
$(RM) $@
ifeq ($(OPENJDK_TARGET_OS), macosx)
# On macosx, we need to add a leading underscore
ifeq ($(OPENJDK_TARGET_OS), macosx)
# On macosx, we need to add a leading underscore
define create-mapfile-work
$(AWK) '{ if ($$0 ~ ".") { print " _" $$0 } }' < $^ > $@.tmp
else ifeq ($(OPENJDK_TARGET_OS), windows)
# On windows, add an 'EXPORTS' header
endef
else ifeq ($(OPENJDK_TARGET_OS), windows)
# On windows, add an 'EXPORTS' header
define create-mapfile-work
$(ECHO) "EXPORTS" > $@.tmp
$(AWK) '{ if ($$0 ~ ".") { print " " $$0 } }' < $^ >> $@.tmp
else
# Assume standard linker script
endef
else
# Assume standard linker script
define create-mapfile-work
$(PRINTF) "SUNWprivate_1.1 { \n global: \n" > $@.tmp
$(AWK) '{ if ($$0 ~ ".") { print " " $$0 ";" } }' < $^ >> $@.tmp
$(PRINTF) " local: \n *; \n }; \n" >> $@.tmp
endif
endef
endif
define create-mapfile
$(call LogInfo, Creating mapfile)
$(call MakeDir, $(@D))
$(call create-mapfile-work)
$(RM) $@
$(MV) $@.tmp $@
endef
$(JVM_MAPFILE): $(JVM_OUTPUTDIR)/symbols
$(call create-mapfile)

@ -0,0 +1,67 @@
#
# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
default: all
include $(SPEC)
include MakeBase.gmk
$(foreach v, $(JVM_VARIANTS), \
$(eval $(call SetupCopyFiles, COPY_GTEST_$v, \
SRC := $(HOTSPOT_OUTPUTDIR)/variant-$v/libjvm/gtest, \
DEST := $(TEST_IMAGE_DIR)/hotspot/gtest/$v, \
FILES := $(call SHARED_LIBRARY,jvm) gtestLauncher$(EXE_SUFFIX), \
)) \
$(eval TARGETS += $$(COPY_GTEST_$v)) \
)
ifeq ($(OPENJDK_TARGET_OS), windows)
$(foreach v, $(JVM_VARIANTS), \
$(eval $(call SetupCopyFiles, COPY_GTEST_MSVCR_$v, \
DEST := $(TEST_IMAGE_DIR)/hotspot/gtest/$v, \
FILES := $(MSVCR_DLL) $(MSVCP_DLL), \
FLATTEN := true, \
)) \
$(eval TARGETS += $$(COPY_GTEST_MSVCR_$v)) \
$(eval $(call SetupCopyFiles, COPY_GTEST_PDB_$v, \
SRC := $(HOTSPOT_OUTPUTDIR)/variant-$v/libjvm/gtest, \
DEST := $(TEST_IMAGE_DIR)/hotspot/gtest/$v, \
FILES := jvm.pdb gtestLauncher.pdb, \
)) \
$(eval TARGETS += $$(COPY_GTEST_PDB_$v)) \
)
endif
ifeq ($(OPENJDK_TARGET_OS), solaris)
$(foreach v, $(JVM_VARIANTS), \
$(eval $(call SetupCopyFiles, COPY_GTEST_STLPORT_$v, \
DEST := $(TEST_IMAGE_DIR)/hotspot/gtest/$v, \
FILES := $(STLPORT_LIB), \
)) \
$(eval TARGETS += $$(COPY_GTEST_STLPORT_$v)) \
)
endif
all: $(TARGETS)

@ -52,6 +52,11 @@ UNIQ = uniq
WC = wc
ZIP = zip
define NEWLINE
endef
# Get OS name from uname (Cygwin inexplicably adds _NT-5.1)
UNAME_S := $(shell $(UNAME) -s | $(CUT) -f1 -d_)
ifeq ($(UNAME_S), SunOS)
@ -427,6 +432,20 @@ PHONY_LIST += hotspot_servertest servertest
################################################################
# Run the native gtest tests from the test image
hotspot_gtest:
$(foreach v, $(JVM_VARIANTS), \
$(MAKE) hotspot_gtest$v $(NEWLINE) )
hotspot_gtestserver hotspot_gtestclient hotspot_gtestminimal: hotspot_gtest%:
$(TESTNATIVE_DIR)/hotspot/gtest/$*/gtestLauncher \
-jdk $(shell $(GETMIXEDPATH) "$(PRODUCT_HOME)")
PHONY_LIST += hotspot_gtest hotspot_gtestserver hotspot_gtestclient \
hotspot_gtestminimal
################################################################
# Phony targets (e.g. these are not filenames)
.PHONY: all clean prep $(PHONY_LIST)

@ -0,0 +1,34 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "prims/jni.h"
extern "C" {
JNIIMPORT void JNICALL runUnitTests(int argv, char** argc);
}
int main(int argc, char** argv) {
runUnitTests(argc, argv);
return 0;
}

@ -0,0 +1,203 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef __APPLE__
# include <dlfcn.h>
#endif
#include "prims/jni.h"
#include "unittest.hpp"
extern "C" {
static int init_jvm(int argc, char **argv, bool is_executing_death_test) {
// don't care about the program name
argc--;
argv++;
int extra_jvm_args = is_executing_death_test ? 4 : 2;
int num_jvm_options = argc + extra_jvm_args;
JavaVMOption* options = new JavaVMOption[num_jvm_options];
options[0].optionString = (char*) "-Dsun.java.launcher.is_altjvm=true";
options[1].optionString = (char*) "-XX:+ExecutingUnitTests";
if (is_executing_death_test) {
// don't create core files or hs_err files when executing death tests
options[2].optionString = (char*) "-XX:+SuppressFatalErrorMessage";
options[3].optionString = (char*) "-XX:-CreateCoredumpOnCrash";
}
for (int i = 0; i < argc; i++) {
options[extra_jvm_args + i].optionString = argv[i];
}
JavaVMInitArgs args;
args.version = JNI_VERSION_1_8;
args.nOptions = num_jvm_options;
args.options = options;
JavaVM* jvm;
JNIEnv* env;
return JNI_CreateJavaVM(&jvm, (void**)&env, &args);
}
class JVMInitializerListener : public ::testing::EmptyTestEventListener {
private:
int _argc;
char** _argv;
bool _is_initialized;
void initialize_jvm() {
}
public:
JVMInitializerListener(int argc, char** argv) :
_argc(argc), _argv(argv), _is_initialized(false) {
}
virtual void OnTestStart(const ::testing::TestInfo& test_info) {
const char* name = test_info.name();
if (strstr(name, "_test_vm") != NULL && !_is_initialized) {
ASSERT_EQ(init_jvm(_argc, _argv, false), 0) << "Could not initialize the JVM";
_is_initialized = true;
}
}
};
static bool is_prefix(const char* prefix, const char* str) {
return strncmp(str, prefix, strlen(prefix)) == 0;
}
static char* get_java_home_arg(int argc, char** argv) {
for (int i = 0; i < argc; i++) {
if (strncmp(argv[i], "-jdk", strlen(argv[i])) == 0) {
return argv[i+1];
}
if (is_prefix("--jdk=", argv[i])) {
return argv[i] + strlen("--jdk=");
}
if (is_prefix("-jdk:", argv[i])) {
return argv[i] + strlen("-jdk:");
}
}
return NULL;
}
static int num_args_to_skip(char* arg) {
if (strcmp(arg, "-jdk") == 0) {
return 2; // skip the argument after -jdk as well
}
if (is_prefix("--jdk=", arg)) {
return 1;
}
if (is_prefix("-jdk:", arg)) {
return 1;
}
return 0;
}
static char** remove_test_runner_arguments(int* argcp, char **argv) {
int argc = *argcp;
char** new_argv = (char**) malloc(sizeof(char*) * argc);
int new_argc = 0;
int i = 0;
while (i < argc) {
int args_to_skip = num_args_to_skip(argv[i]);
if (args_to_skip == 0) {
new_argv[new_argc] = argv[i];
i++;
new_argc++;
} else {
i += num_args_to_skip(argv[i]);
}
}
*argcp = new_argc;
return new_argv;
}
JNIEXPORT void JNICALL runUnitTests(int argc, char** argv) {
// Must look at googletest options before initializing googletest, since
// InitGoogleTest removes googletest options from argv.
bool is_executing_death_test = true;
for (int i = 0; i < argc; i++) {
const char* death_test_flag = "--gtest_internal_run_death_test";
if (is_prefix(death_test_flag, argv[i])) {
is_executing_death_test = true;
}
}
::testing::InitGoogleTest(&argc, argv);
::testing::GTEST_FLAG(death_test_style) = "threadsafe";
// ::testing::GTEST_FLAG(death_test_output_prefix) = "Other VM";
char* java_home = get_java_home_arg(argc, argv);
if (java_home == NULL) {
fprintf(stderr, "ERROR: You must specify a JDK to use for running the unit tests.\n");
exit(1);
}
#ifndef _WIN32
int overwrite = 1; // overwrite an eventual existing value for JAVA_HOME
setenv("JAVA_HOME", java_home, overwrite);
// workaround for JDK-7131356
#ifdef __APPLE__
size_t len = strlen(java_home) + strlen("/lib/jli/libjli.dylib") + 1;
char* path = new char[len];
snprintf(path, len, "%s/lib/jli/libjli.dylib", java_home);
dlopen(path, RTLD_NOW | RTLD_GLOBAL);
#endif // __APPLE__
#else // _WIN32
char* java_home_var = "_ALT_JAVA_HOME_DIR";
size_t len = strlen(java_home) + strlen(java_home_var) + 2;
char * envString = new char[len];
sprintf_s(envString, len, "%s=%s", java_home_var, java_home);
_putenv(envString);
#endif // _WIN32
argv = remove_test_runner_arguments(&argc, argv);
if (is_executing_death_test) {
if (init_jvm(argc, argv, true) != 0) {
abort();
}
} else {
::testing::TestEventListeners& listeners = ::testing::UnitTest::GetInstance()->listeners();
listeners.Append(new JVMInitializerListener(argc, argv));
}
int result = RUN_ALL_TESTS();
if (result != 0) {
fprintf(stderr, "ERROR: RUN_ALL_TESTS() failed. Error %d\n", result);
exit(2);
}
}
} // extern "C"

@ -0,0 +1,45 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "runtime/os.hpp"
#include "unittest.hpp"
TEST_VM(os, page_size_for_region) {
size_t large_page_example = 4 * M;
size_t large_page = os::page_size_for_region_aligned(large_page_example, 1);
size_t small_page = os::vm_page_size();
if (large_page > small_page) {
size_t num_small_in_large = large_page / small_page;
size_t page = os::page_size_for_region_aligned(large_page, num_small_in_large);
ASSERT_EQ(page, small_page) << "Did not get a small page";
}
}
#ifdef ASSERT
TEST_VM_ASSERT_MSG(os, page_size_for_region_with_zero_min_pages, "sanity") {
size_t region_size = 16 * os::vm_page_size();
os::page_size_for_region_aligned(region_size, 0); // should assert
}
#endif

@ -0,0 +1,104 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include <stdlib.h>
#include <stdio.h>
#define GTEST_DONT_DEFINE_TEST 1
#include "gtest/gtest.h"
#ifdef assert
#undef assert
#endif
#define CONCAT(a, b) a ## b
#define TEST(category, name) GTEST_TEST(category, CONCAT(name, _test))
#define TEST_VM(category, name) GTEST_TEST(category, CONCAT(name, _test_vm))
#define TEST_VM_F(test_fixture, name) \
GTEST_TEST_(test_fixture, name ## _test_vm, test_fixture, \
::testing::internal::GetTypeId<test_fixture>())
#define TEST_OTHER_VM(category, name) \
static void test_ ## category ## _ ## name ## _(); \
\
static void child_ ## category ## _ ## name ## _() { \
::testing::GTEST_FLAG(throw_on_failure) = true; \
test_ ## category ## _ ## name ## _(); \
fprintf(stderr, "OKIDOKI"); \
exit(0); \
} \
\
TEST(category, CONCAT(name, _other_vm)) { \
ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \
::testing::ExitedWithCode(0), \
".*OKIDOKI.*"); \
} \
\
void test_ ## category ## _ ## name ## _()
#ifdef ASSERT
#define TEST_VM_ASSERT(category, name) \
static void test_ ## category ## _ ## name ## _(); \
\
static void child_ ## category ## _ ## name ## _() { \
::testing::GTEST_FLAG(throw_on_failure) = true; \
test_ ## category ## _ ## name ## _(); \
exit(0); \
} \
\
TEST(category, CONCAT(name, _vm_assert)) { \
ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \
::testing::ExitedWithCode(1), \
"assert failed"); \
} \
\
void test_ ## category ## _ ## name ## _()
#else
#define TEST_VM_ASSERT(...) \
TEST_VM_ASSERT is only available in debug builds
#endif
#ifdef ASSERT
#define TEST_VM_ASSERT_MSG(category, name, msg) \
static void test_ ## category ## _ ## name ## _(); \
\
static void child_ ## category ## _ ## name ## _() { \
::testing::GTEST_FLAG(throw_on_failure) = true; \
test_ ## category ## _ ## name ## _(); \
exit(0); \
} \
\
TEST(category, CONCAT(name, _vm_assert)) { \
ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \
::testing::ExitedWithCode(1), \
"assert failed: " msg); \
} \
\
void test_ ## category ## _ ## name ## _()
#else
#define TEST_VM_ASSERT_MSG(...) \
TEST_VM_ASSERT_MSG is only available in debug builds
#endif

@ -0,0 +1,47 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "prims/jvm.h"
#include "utilities/quickSort.hpp"
#include "unittest.hpp"
static int int_comparator(int a, int b) {
if (a == b) {
return 0;
} else if (a < b) {
return -1;
}
// a > b
return 1;
}
TEST(utilities, quicksort) {
int test_array[] = {3,2,1};
QuickSort::sort(test_array, 3, int_comparator, false);
ASSERT_EQ(1, test_array[0]);
ASSERT_EQ(2, test_array[1]);
ASSERT_EQ(3, test_array[2]);
}