8170490: Convert TestBufferingOopClosure_test to GTest
Reviewed-by: dfazunen, iignatyev
This commit is contained in:
parent
9c6128c943
commit
8d6d1e4cda
@ -42,7 +42,7 @@
|
||||
// buffered entries.
|
||||
|
||||
class BufferingOopClosure: public OopClosure {
|
||||
friend class TestBufferingOopClosure;
|
||||
friend class BufferingOopClosureTest;
|
||||
protected:
|
||||
static const size_t BufferLength = 1024;
|
||||
|
||||
|
@ -54,7 +54,6 @@ void InternalVMTests::run() {
|
||||
run_unit_test(VMStructs_test);
|
||||
#endif
|
||||
#if INCLUDE_ALL_GCS
|
||||
run_unit_test(TestBufferingOopClosure_test);
|
||||
run_unit_test(ParallelCompact_test);
|
||||
#endif
|
||||
tty->print_cr("All internal VM tests passed");
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 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
|
||||
@ -19,20 +19,15 @@
|
||||
* 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 "precompiled.hpp"
|
||||
#include "gc/g1/bufferingOopClosure.hpp"
|
||||
#include "memory/iterator.hpp"
|
||||
#include "utilities/debug.hpp"
|
||||
|
||||
/////////////// Unit tests ///////////////
|
||||
|
||||
#ifndef PRODUCT
|
||||
|
||||
class TestBufferingOopClosure {
|
||||
#include "unittest.hpp"
|
||||
|
||||
class BufferingOopClosureTest : public ::testing::Test {
|
||||
public:
|
||||
// Helper class to fake a set of oop*s and narrowOop*s.
|
||||
class FakeRoots {
|
||||
public:
|
||||
@ -121,14 +116,14 @@ class TestBufferingOopClosure {
|
||||
public:
|
||||
CountOopClosure() : _narrow_oop_count(0), _full_oop_count(0) {}
|
||||
void do_oop(narrowOop* p) {
|
||||
assert((uintptr_t(p) & FakeRoots::NarrowOopMarker) != 0,
|
||||
"The narrowOop was unexpectedly not marked with the NarrowOopMarker");
|
||||
EXPECT_NE(uintptr_t(0), (uintptr_t(p) & FakeRoots::NarrowOopMarker))
|
||||
<< "The narrowOop was unexpectedly not marked with the NarrowOopMarker";
|
||||
_narrow_oop_count++;
|
||||
}
|
||||
|
||||
void do_oop(oop* p){
|
||||
assert((uintptr_t(p) & FakeRoots::NarrowOopMarker) == 0,
|
||||
"The oop was unexpectedly marked with the NarrowOopMarker");
|
||||
EXPECT_EQ(uintptr_t(0), (uintptr_t(p) & FakeRoots::NarrowOopMarker))
|
||||
<< "The oop was unexpectedly marked with the NarrowOopMarker";
|
||||
_full_oop_count++;
|
||||
}
|
||||
|
||||
@ -153,33 +148,14 @@ class TestBufferingOopClosure {
|
||||
|
||||
boc.done();
|
||||
|
||||
#define assert_testCount(got, expected) \
|
||||
assert((got) == (expected), \
|
||||
"Expected: %d, got: %d, when running testCount(%d, %d, %d)", \
|
||||
(got), (expected), num_narrow, num_full, do_oop_order)
|
||||
EXPECT_EQ(num_narrow, coc.narrow_oop_count()) << "when running testCount("
|
||||
<< num_narrow << ", " << num_full << ", " << do_oop_order << ")";
|
||||
|
||||
assert_testCount(num_narrow, coc.narrow_oop_count());
|
||||
assert_testCount(num_full, coc.full_oop_count());
|
||||
assert_testCount(num_narrow + num_full, coc.all_oop_count());
|
||||
}
|
||||
EXPECT_EQ(num_full, coc.full_oop_count()) << "when running testCount("
|
||||
<< num_narrow << ", " << num_full << ", " << do_oop_order << ")";
|
||||
|
||||
static void testCount() {
|
||||
int buffer_length = BufferingOopClosure::BufferLength;
|
||||
|
||||
for (int order = 0; order < FakeRoots::MaxOrder; order++) {
|
||||
testCount(0, 0, order);
|
||||
testCount(10, 0, order);
|
||||
testCount(0, 10, order);
|
||||
testCount(10, 10, order);
|
||||
testCount(buffer_length, 10, order);
|
||||
testCount(10, buffer_length, order);
|
||||
testCount(buffer_length, buffer_length, order);
|
||||
testCount(buffer_length + 1, 10, order);
|
||||
testCount(10, buffer_length + 1, order);
|
||||
testCount(buffer_length + 1, buffer_length, order);
|
||||
testCount(buffer_length, buffer_length + 1, order);
|
||||
testCount(buffer_length + 1, buffer_length + 1, order);
|
||||
}
|
||||
EXPECT_EQ(num_narrow + num_full, coc.all_oop_count()) << "when running testCount("
|
||||
<< num_narrow << ", " << num_full << ", " << do_oop_order << ")";
|
||||
}
|
||||
|
||||
static void testIsBufferEmptyOrFull(int num_narrow, int num_full, bool expect_empty, bool expect_full) {
|
||||
@ -190,34 +166,15 @@ class TestBufferingOopClosure {
|
||||
|
||||
fr.oops_do(&boc, 0);
|
||||
|
||||
#define assert_testIsBufferEmptyOrFull(got, expected) \
|
||||
assert((got) == (expected), \
|
||||
"Expected: %d, got: %d. testIsBufferEmptyOrFull(%d, %d, %s, %s)", \
|
||||
(got), (expected), num_narrow, num_full, \
|
||||
BOOL_TO_STR(expect_empty), BOOL_TO_STR(expect_full))
|
||||
EXPECT_EQ(expect_empty, boc.is_buffer_empty())
|
||||
<< "when running testIsBufferEmptyOrFull("
|
||||
<< num_narrow << ", " << num_full << ", "
|
||||
<< expect_empty << ", " << expect_full << ")";
|
||||
|
||||
assert_testIsBufferEmptyOrFull(expect_empty, boc.is_buffer_empty());
|
||||
assert_testIsBufferEmptyOrFull(expect_full, boc.is_buffer_full());
|
||||
}
|
||||
|
||||
static void testIsBufferEmptyOrFull() {
|
||||
int bl = BufferingOopClosure::BufferLength;
|
||||
|
||||
testIsBufferEmptyOrFull(0, 0, true, false);
|
||||
testIsBufferEmptyOrFull(1, 0, false, false);
|
||||
testIsBufferEmptyOrFull(0, 1, false, false);
|
||||
testIsBufferEmptyOrFull(1, 1, false, false);
|
||||
testIsBufferEmptyOrFull(10, 0, false, false);
|
||||
testIsBufferEmptyOrFull(0, 10, false, false);
|
||||
testIsBufferEmptyOrFull(10, 10, false, false);
|
||||
testIsBufferEmptyOrFull(0, bl, false, true);
|
||||
testIsBufferEmptyOrFull(bl, 0, false, true);
|
||||
testIsBufferEmptyOrFull(bl/2, bl/2, false, true);
|
||||
testIsBufferEmptyOrFull(bl-1, 1, false, true);
|
||||
testIsBufferEmptyOrFull(1, bl-1, false, true);
|
||||
// Processed
|
||||
testIsBufferEmptyOrFull(bl+1, 0, false, false);
|
||||
testIsBufferEmptyOrFull(bl*2, 0, false, true);
|
||||
EXPECT_EQ(expect_full, boc.is_buffer_full())
|
||||
<< "when running testIsBufferEmptyOrFull("
|
||||
<< num_narrow << ", " << num_full << ", "
|
||||
<< expect_empty << ", " << expect_full << ")";
|
||||
}
|
||||
|
||||
static void testEmptyAfterDone(int num_narrow, int num_full) {
|
||||
@ -231,41 +188,70 @@ class TestBufferingOopClosure {
|
||||
// Make sure all get processed.
|
||||
boc.done();
|
||||
|
||||
assert(boc.is_buffer_empty(),
|
||||
"Should be empty after call to done(). testEmptyAfterDone(%d, %d)",
|
||||
num_narrow, num_full);
|
||||
EXPECT_TRUE(boc.is_buffer_empty()) << "Should be empty after call to done()."
|
||||
<< " testEmptyAfterDone(" << num_narrow << ", " << num_full << ")";
|
||||
}
|
||||
|
||||
static void testEmptyAfterDone() {
|
||||
int bl = BufferingOopClosure::BufferLength;
|
||||
|
||||
testEmptyAfterDone(0, 0);
|
||||
testEmptyAfterDone(1, 0);
|
||||
testEmptyAfterDone(0, 1);
|
||||
testEmptyAfterDone(1, 1);
|
||||
testEmptyAfterDone(10, 0);
|
||||
testEmptyAfterDone(0, 10);
|
||||
testEmptyAfterDone(10, 10);
|
||||
testEmptyAfterDone(0, bl);
|
||||
testEmptyAfterDone(bl, 0);
|
||||
testEmptyAfterDone(bl/2, bl/2);
|
||||
testEmptyAfterDone(bl-1, 1);
|
||||
testEmptyAfterDone(1, bl-1);
|
||||
// Processed
|
||||
testEmptyAfterDone(bl+1, 0);
|
||||
testEmptyAfterDone(bl*2, 0);
|
||||
}
|
||||
|
||||
public:
|
||||
static void test() {
|
||||
testCount();
|
||||
testIsBufferEmptyOrFull();
|
||||
testEmptyAfterDone();
|
||||
static int get_buffer_length() {
|
||||
return BufferingOopClosure::BufferLength;
|
||||
}
|
||||
};
|
||||
|
||||
void TestBufferingOopClosure_test() {
|
||||
TestBufferingOopClosure::test();
|
||||
TEST_VM_F(BufferingOopClosureTest, count_test) {
|
||||
int bl = BufferingOopClosureTest::get_buffer_length();
|
||||
|
||||
for (int order = 0; order < FakeRoots::MaxOrder; order++) {
|
||||
testCount(0, 0, order);
|
||||
testCount(10, 0, order);
|
||||
testCount(0, 10, order);
|
||||
testCount(10, 10, order);
|
||||
testCount(bl, 10, order);
|
||||
testCount(10, bl, order);
|
||||
testCount(bl, bl, order);
|
||||
testCount(bl + 1, 10, order);
|
||||
testCount(10, bl + 1, order);
|
||||
testCount(bl + 1, bl, order);
|
||||
testCount(bl, bl + 1, order);
|
||||
testCount(bl + 1, bl + 1, order);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
TEST_VM_F(BufferingOopClosureTest, buffer_empty_or_full) {
|
||||
int bl = BufferingOopClosureTest::get_buffer_length();
|
||||
|
||||
testIsBufferEmptyOrFull(0, 0, true, false);
|
||||
testIsBufferEmptyOrFull(1, 0, false, false);
|
||||
testIsBufferEmptyOrFull(0, 1, false, false);
|
||||
testIsBufferEmptyOrFull(1, 1, false, false);
|
||||
testIsBufferEmptyOrFull(10, 0, false, false);
|
||||
testIsBufferEmptyOrFull(0, 10, false, false);
|
||||
testIsBufferEmptyOrFull(10, 10, false, false);
|
||||
testIsBufferEmptyOrFull(0, bl, false, true);
|
||||
testIsBufferEmptyOrFull(bl, 0, false, true);
|
||||
testIsBufferEmptyOrFull(bl / 2, bl / 2, false, true);
|
||||
testIsBufferEmptyOrFull(bl - 1, 1, false, true);
|
||||
testIsBufferEmptyOrFull(1, bl - 1, false, true);
|
||||
// Processed
|
||||
testIsBufferEmptyOrFull(bl + 1, 0, false, false);
|
||||
testIsBufferEmptyOrFull(bl * 2, 0, false, true);
|
||||
}
|
||||
|
||||
TEST_VM_F(BufferingOopClosureTest, empty_after_done) {
|
||||
int bl = BufferingOopClosureTest::get_buffer_length();
|
||||
|
||||
testEmptyAfterDone(0, 0);
|
||||
testEmptyAfterDone(1, 0);
|
||||
testEmptyAfterDone(0, 1);
|
||||
testEmptyAfterDone(1, 1);
|
||||
testEmptyAfterDone(10, 0);
|
||||
testEmptyAfterDone(0, 10);
|
||||
testEmptyAfterDone(10, 10);
|
||||
testEmptyAfterDone(0, bl);
|
||||
testEmptyAfterDone(bl, 0);
|
||||
testEmptyAfterDone(bl / 2, bl / 2);
|
||||
testEmptyAfterDone(bl - 1, 1);
|
||||
testEmptyAfterDone(1, bl - 1);
|
||||
// Processed
|
||||
testEmptyAfterDone(bl + 1, 0);
|
||||
testEmptyAfterDone(bl * 2, 0);
|
||||
}
|
Loading…
Reference in New Issue
Block a user