| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Tests of circular queues. | 3 // Tests of the circular queue. |
| 4 | 4 |
| 5 #include "v8.h" | 5 #include "v8.h" |
| 6 #include "circular-queue-inl.h" | 6 #include "circular-queue-inl.h" |
| 7 #include "cctest.h" | 7 #include "cctest.h" |
| 8 | 8 |
| 9 namespace i = v8::internal; | 9 namespace i = v8::internal; |
| 10 | 10 |
| 11 using i::CircularQueue; | |
| 12 using i::SamplingCircularQueue; | 11 using i::SamplingCircularQueue; |
| 13 | 12 |
| 14 | 13 |
| 15 TEST(SingleRecordCircularQueue) { | |
| 16 typedef int Record; | |
| 17 CircularQueue<Record> cq(sizeof(Record) * 2); | |
| 18 CHECK(cq.IsEmpty()); | |
| 19 cq.Enqueue(1); | |
| 20 CHECK(!cq.IsEmpty()); | |
| 21 Record rec = 0; | |
| 22 cq.Dequeue(&rec); | |
| 23 CHECK_EQ(1, rec); | |
| 24 CHECK(cq.IsEmpty()); | |
| 25 } | |
| 26 | |
| 27 | |
| 28 TEST(MultipleRecordsCircularQueue) { | |
| 29 typedef int Record; | |
| 30 const int kQueueSize = 10; | |
| 31 CircularQueue<Record> cq(sizeof(Record) * (kQueueSize + 1)); | |
| 32 CHECK(cq.IsEmpty()); | |
| 33 cq.Enqueue(1); | |
| 34 CHECK(!cq.IsEmpty()); | |
| 35 for (int i = 2; i <= 5; ++i) { | |
| 36 cq.Enqueue(i); | |
| 37 CHECK(!cq.IsEmpty()); | |
| 38 } | |
| 39 Record rec = 0; | |
| 40 for (int i = 1; i <= 4; ++i) { | |
| 41 CHECK(!cq.IsEmpty()); | |
| 42 cq.Dequeue(&rec); | |
| 43 CHECK_EQ(i, rec); | |
| 44 } | |
| 45 for (int i = 6; i <= 12; ++i) { | |
| 46 cq.Enqueue(i); | |
| 47 CHECK(!cq.IsEmpty()); | |
| 48 } | |
| 49 for (int i = 5; i <= 12; ++i) { | |
| 50 CHECK(!cq.IsEmpty()); | |
| 51 cq.Dequeue(&rec); | |
| 52 CHECK_EQ(i, rec); | |
| 53 } | |
| 54 CHECK(cq.IsEmpty()); | |
| 55 } | |
| 56 | |
| 57 | |
| 58 TEST(SamplingCircularQueue) { | 14 TEST(SamplingCircularQueue) { |
| 59 typedef SamplingCircularQueue::Cell Record; | 15 typedef SamplingCircularQueue::Cell Record; |
| 60 const int kRecordsPerChunk = 4; | 16 const int kRecordsPerChunk = 4; |
| 61 SamplingCircularQueue scq(sizeof(Record), | 17 SamplingCircularQueue scq(sizeof(Record), |
| 62 kRecordsPerChunk * sizeof(Record), | 18 kRecordsPerChunk * sizeof(Record), |
| 63 3); | 19 3); |
| 64 | 20 |
| 65 // Check that we are using non-reserved values. | 21 // Check that we are using non-reserved values. |
| 66 CHECK_NE(SamplingCircularQueue::kClear, 1); | 22 CHECK_NE(SamplingCircularQueue::kClear, 1); |
| 67 CHECK_NE(SamplingCircularQueue::kEnd, 1); | 23 CHECK_NE(SamplingCircularQueue::kEnd, 1); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec)); | 168 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(*rec)); |
| 213 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue())); | 169 CHECK_EQ(rec, reinterpret_cast<Record*>(scq.StartDequeue())); |
| 214 scq.FinishDequeue(); | 170 scq.FinishDequeue(); |
| 215 CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue())); | 171 CHECK_NE(rec, reinterpret_cast<Record*>(scq.StartDequeue())); |
| 216 } | 172 } |
| 217 | 173 |
| 218 CHECK_EQ(NULL, scq.StartDequeue()); | 174 CHECK_EQ(NULL, scq.StartDequeue()); |
| 219 | 175 |
| 220 delete semaphore; | 176 delete semaphore; |
| 221 } | 177 } |
| OLD | NEW |