Chromium Code Reviews| Index: test/unittests/heap/marking-unittest.cc |
| diff --git a/test/unittests/heap/marking-unittest.cc b/test/unittests/heap/marking-unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f316e151cd66b4e1df5c818c1fe2902640e0e5d9 |
| --- /dev/null |
| +++ b/test/unittests/heap/marking-unittest.cc |
| @@ -0,0 +1,100 @@ |
| +// Copyright 2016 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <stdlib.h> |
| + |
| +#include "src/globals.h" |
| +#include "src/heap/marking.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace v8 { |
| +namespace internal { |
| + |
| +TEST(Marking, MarkWhiteBlackWhite) { |
| + Bitmap* bitmap = reinterpret_cast<Bitmap*>(calloc(Bitmap::kSize, 0)); |
| + const int kLocationsSize = 3; |
| + int position[kLocationsSize] = { |
| + Bitmap::kBitsPerCell - 2, Bitmap::kBitsPerCell - 1, Bitmap::kBitsPerCell}; |
| + for (int i = 0; i < kLocationsSize; i++) { |
| + MarkBit mark_bit = bitmap->MarkBitFromIndex(position[i]); |
| + CHECK(Marking::IsWhite(mark_bit)); |
| + CHECK(!Marking::IsImpossible(mark_bit)); |
| + Marking::MarkBlack(mark_bit); |
| + CHECK(Marking::IsBlack(mark_bit)); |
| + CHECK(!Marking::IsImpossible(mark_bit)); |
| + Marking::MarkWhite(mark_bit); |
| + CHECK(Marking::IsWhite(mark_bit)); |
| + CHECK(!Marking::IsImpossible(mark_bit)); |
| + } |
|
Michael Lippautz
2016/07/12 14:22:31
free(bitmap) or you will get mail from leak saniti
Hannes Payer (out of office)
2016/07/12 14:44:26
Done.
|
| +} |
| + |
| +TEST(Marking, TransitionWhiteBlackWhite) { |
| + Bitmap* bitmap = reinterpret_cast<Bitmap*>(calloc(Bitmap::kSize, 0)); |
| + const int kLocationsSize = 3; |
| + int position[kLocationsSize] = { |
| + Bitmap::kBitsPerCell - 2, Bitmap::kBitsPerCell - 1, Bitmap::kBitsPerCell}; |
| + for (int i = 0; i < kLocationsSize; i++) { |
| + MarkBit mark_bit = bitmap->MarkBitFromIndex(position[i]); |
| + CHECK(Marking::IsWhite(mark_bit)); |
| + CHECK(!Marking::IsImpossible(mark_bit)); |
| + Marking::WhiteToBlack(mark_bit); |
| + CHECK(Marking::IsBlack(mark_bit)); |
| + CHECK(!Marking::IsImpossible(mark_bit)); |
| + Marking::BlackToWhite(mark_bit); |
| + CHECK(Marking::IsWhite(mark_bit)); |
| + CHECK(!Marking::IsImpossible(mark_bit)); |
| + } |
| +} |
| + |
| +TEST(Marking, TransitionAnyToGrey) { |
| + Bitmap* bitmap = reinterpret_cast<Bitmap*>(calloc(Bitmap::kSize, 0)); |
| + const int kLocationsSize = 3; |
| + int position[kLocationsSize] = { |
| + Bitmap::kBitsPerCell - 2, Bitmap::kBitsPerCell - 1, Bitmap::kBitsPerCell}; |
| + for (int i = 0; i < kLocationsSize; i++) { |
| + MarkBit mark_bit = bitmap->MarkBitFromIndex(position[i]); |
| + CHECK(Marking::IsWhite(mark_bit)); |
| + CHECK(!Marking::IsImpossible(mark_bit)); |
| + Marking::AnyToGrey(mark_bit); |
| + CHECK(Marking::IsGrey(mark_bit)); |
| + CHECK(Marking::IsBlackOrGrey(mark_bit)); |
| + CHECK(!Marking::IsImpossible(mark_bit)); |
| + Marking::MarkBlack(mark_bit); |
| + CHECK(Marking::IsBlack(mark_bit)); |
| + CHECK(Marking::IsBlackOrGrey(mark_bit)); |
| + CHECK(!Marking::IsImpossible(mark_bit)); |
| + Marking::AnyToGrey(mark_bit); |
| + CHECK(Marking::IsGrey(mark_bit)); |
| + CHECK(Marking::IsBlackOrGrey(mark_bit)); |
| + CHECK(!Marking::IsImpossible(mark_bit)); |
| + } |
| +} |
| + |
| +TEST(Marking, TransitionWhiteGreyBlackGrey) { |
| + Bitmap* bitmap = reinterpret_cast<Bitmap*>(calloc(Bitmap::kSize, 0)); |
| + const int kLocationsSize = 3; |
| + int position[kLocationsSize] = { |
| + Bitmap::kBitsPerCell - 2, Bitmap::kBitsPerCell - 1, Bitmap::kBitsPerCell}; |
| + for (int i = 0; i < kLocationsSize; i++) { |
| + MarkBit mark_bit = bitmap->MarkBitFromIndex(position[i]); |
| + CHECK(Marking::IsWhite(mark_bit)); |
| + CHECK(!Marking::IsBlackOrGrey(mark_bit)); |
| + CHECK(!Marking::IsImpossible(mark_bit)); |
| + Marking::WhiteToGrey(mark_bit); |
| + CHECK(Marking::IsGrey(mark_bit)); |
| + CHECK(Marking::IsBlackOrGrey(mark_bit)); |
| + CHECK(!Marking::IsImpossible(mark_bit)); |
| + Marking::GreyToBlack(mark_bit); |
| + CHECK(Marking::IsBlack(mark_bit)); |
| + CHECK(Marking::IsBlackOrGrey(mark_bit)); |
| + CHECK(!Marking::IsImpossible(mark_bit)); |
| + Marking::BlackToGrey(mark_bit); |
| + CHECK(Marking::IsGrey(mark_bit)); |
| + CHECK(Marking::IsBlackOrGrey(mark_bit)); |
| + CHECK(!Marking::IsImpossible(mark_bit)); |
| + } |
| +} |
| + |
| +} // namespace internal |
| +} // namespace v8 |