8164039: Convert test_memset_with_concurrent_readers to GTest

Reviewed-by: iignatyev, kbarrett
This commit is contained in:
Kirill Zhaldybin 2016-09-01 20:46:40 +03:00
parent 584c5686be
commit 87d30c0c7d
2 changed files with 24 additions and 30 deletions

View file

@ -93,7 +93,6 @@ void InternalVMTests::run() {
run_unit_test(FreeRegionList_test); run_unit_test(FreeRegionList_test);
run_unit_test(IHOP_test); run_unit_test(IHOP_test);
} }
run_unit_test(test_memset_with_concurrent_readers);
run_unit_test(WorkerDataArray_test); run_unit_test(WorkerDataArray_test);
run_unit_test(ParallelCompact_test); run_unit_test(ParallelCompact_test);
#endif #endif

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -19,30 +19,22 @@
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 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 * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*
*/ */
#include "precompiled.hpp" #include "precompiled.hpp"
#include <string.h> #include <string.h>
#include "gc/shared/memset_with_concurrent_readers.hpp"
#include "utilities/debug.hpp"
#include "utilities/globalDefinitions.hpp" #include "utilities/globalDefinitions.hpp"
#include "utilities/macros.hpp" #include <sstream>
#include "utilities/ostream.hpp" #include "gc/shared/memset_with_concurrent_readers.hpp"
#include "unittest.hpp"
#if INCLUDE_ALL_GCS #if INCLUDE_ALL_GCS
// Unit test
#ifndef PRODUCT
static unsigned line_byte(const char* line, size_t i) { static unsigned line_byte(const char* line, size_t i) {
return unsigned(line[i]) & 0xFF; return unsigned(line[i]) & 0xFF;
} }
// Verify memset_with_concurrent_readers mimics memset. TEST(gc, memset_with_concurrent_readers) {
// We don't attempt to verify the concurrent reader case.
void test_memset_with_concurrent_readers() {
const size_t chunk_size = 8 * BytesPerWord; const size_t chunk_size = 8 * BytesPerWord;
const unsigned chunk_count = 4; const unsigned chunk_count = 4;
const size_t block_size = (chunk_count + 4) * chunk_size; const size_t block_size = (chunk_count + 4) * chunk_size;
@ -76,29 +68,32 @@ void test_memset_with_concurrent_readers() {
bool middle_set = !memcmp(set_block, block + set_start, set_size); bool middle_set = !memcmp(set_block, block + set_start, set_size);
bool tail_clear = !memcmp(clear_block, block + set_end, block_size - set_end); bool tail_clear = !memcmp(clear_block, block + set_end, block_size - set_end);
if (!(head_clear && middle_set && tail_clear)) { if (!(head_clear && middle_set && tail_clear)) {
tty->print_cr("*** memset_with_concurrent_readers failed: " std::ostringstream err_stream;
"set start " SIZE_FORMAT ", set end " SIZE_FORMAT, err_stream << "*** memset_with_concurrent_readers failed: set start "
set_start, set_end); << set_start << ", set end " << set_end << std::endl;
for (unsigned chunk = 0; chunk < (block_size / chunk_size); ++chunk) { for (unsigned chunk = 0; chunk < (block_size / chunk_size); ++chunk) {
for (unsigned line = 0; line < (chunk_size / BytesPerWord); ++line) { for (unsigned line = 0; line < (chunk_size / BytesPerWord); ++line) {
const char* lp = &block[chunk * chunk_size + line * BytesPerWord]; const char* lp = &block[chunk * chunk_size + line * BytesPerWord];
tty->print_cr("%d,%d: %2x %2x %2x %2x %2x %2x %2x %2x",
chunk, line, err_stream << std::dec << chunk << "," << line << ": " << std::hex
line_byte(lp, 0), line_byte(lp, 1), << std::setw(2) << line_byte(lp, 0) << " "
line_byte(lp, 2), line_byte(lp, 3), << std::setw(2) << line_byte(lp, 1) << " "
line_byte(lp, 4), line_byte(lp, 5), << std::setw(2) << line_byte(lp, 2) << " "
line_byte(lp, 6), line_byte(lp, 7)); << std::setw(2) << line_byte(lp, 3) << " "
<< std::setw(2) << line_byte(lp, 4) << " "
<< std::setw(2) << line_byte(lp, 5) << " "
<< std::setw(2) << line_byte(lp, 6) << " "
<< std::setw(2) << line_byte(lp, 7) << std::endl;
} }
} }
assert(head_clear, "leading byte not clear"); EXPECT_TRUE(head_clear) << "leading byte not clear";
assert(middle_set, "memset byte not set"); EXPECT_TRUE(middle_set) << "memset byte not set";
assert(tail_clear, "trailing bye not clear"); EXPECT_TRUE(tail_clear) << "trailing bye not clear";
ASSERT_TRUE(head_clear && middle_set && tail_clear) << err_stream.str();
} }
} }
} }
} }
} }
#endif
#endif // end unit test
#endif // INCLUDE_ALL_GCS