Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1273)

Side by Side Diff: test/cctest/test-gc-tracer.cc

Issue 1830723004: Refactor the ring buffer in GCTracer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix cast Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/unittests/heap/gc-tracer-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #include <stdlib.h>
29 #include <utility>
30
31 #include "src/heap/gc-tracer.h"
32 #include "test/cctest/cctest.h"
33
34 using namespace v8::internal;
35
36 TEST(RingBufferPartialFill) {
37 const int max_size = 6;
38 typedef RingBuffer<int, max_size>::const_iterator Iter;
39 RingBuffer<int, max_size> ring_buffer;
40 CHECK(ring_buffer.empty());
41 CHECK_EQ(static_cast<int>(ring_buffer.size()), 0);
42 CHECK(ring_buffer.begin() == ring_buffer.end());
43
44 // Fill ring_buffer partially: [0, 1, 2]
45 for (int i = 0; i < max_size / 2; i++) ring_buffer.push_back(i);
46
47 CHECK(!ring_buffer.empty());
48 CHECK(static_cast<int>(ring_buffer.size()) == max_size / 2);
49 CHECK(ring_buffer.begin() != ring_buffer.end());
50
51 // Test forward itartion
52 int i = 0;
53 for (Iter iter = ring_buffer.begin(); iter != ring_buffer.end(); ++iter) {
54 CHECK(*iter == i);
55 ++i;
56 }
57 CHECK_EQ(i, 3); // one past last element.
58
59 // Test backward iteration
60 i = 2;
61 Iter iter = ring_buffer.back();
62 while (true) {
63 CHECK(*iter == i);
64 if (iter == ring_buffer.begin()) break;
65 --iter;
66 --i;
67 }
68 CHECK_EQ(i, 0);
69 }
70
71
72 TEST(RingBufferWrapAround) {
73 const int max_size = 6;
74 typedef RingBuffer<int, max_size>::const_iterator Iter;
75 RingBuffer<int, max_size> ring_buffer;
76
77 // Fill ring_buffer (wrap around): [9, 10, 11, 12, 13, 14]
78 for (int i = 0; i < 2 * max_size + 3; i++) ring_buffer.push_back(i);
79
80 CHECK(!ring_buffer.empty());
81 CHECK(static_cast<int>(ring_buffer.size()) == max_size);
82 CHECK(ring_buffer.begin() != ring_buffer.end());
83
84 // Test forward iteration
85 int i = 9;
86 for (Iter iter = ring_buffer.begin(); iter != ring_buffer.end(); ++iter) {
87 CHECK(*iter == i);
88 ++i;
89 }
90 CHECK_EQ(i, 15); // one past last element.
91
92 // Test backward iteration
93 i = 14;
94 Iter iter = ring_buffer.back();
95 while (true) {
96 CHECK(*iter == i);
97 if (iter == ring_buffer.begin()) break;
98 --iter;
99 --i;
100 }
101 CHECK_EQ(i, 9);
102 }
103
104
105 TEST(RingBufferPushFront) {
106 const int max_size = 6;
107 typedef RingBuffer<int, max_size>::const_iterator Iter;
108 RingBuffer<int, max_size> ring_buffer;
109
110 // Fill ring_buffer (wrap around): [14, 13, 12, 11, 10, 9]
111 for (int i = 0; i < 2 * max_size + 3; i++) ring_buffer.push_front(i);
112
113 CHECK(!ring_buffer.empty());
114 CHECK(static_cast<int>(ring_buffer.size()) == max_size);
115 CHECK(ring_buffer.begin() != ring_buffer.end());
116
117 // Test forward iteration
118 int i = 14;
119 for (Iter iter = ring_buffer.begin(); iter != ring_buffer.end(); ++iter) {
120 CHECK(*iter == i);
121 --i;
122 }
123 CHECK_EQ(i, 8); // one past last element.
124 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/unittests/heap/gc-tracer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698