diff options
author | Giacomo Travaglini <giacomo.travaglini@arm.com> | 2019-03-08 16:01:20 +0000 |
---|---|---|
committer | Giacomo Travaglini <giacomo.travaglini@arm.com> | 2019-03-22 10:01:10 +0000 |
commit | bbcbde7a924ca1ca58df997cfe9f750c285e5564 (patch) | |
tree | b185621387765b3749fc939bbc4112e7b7a9852a /src/base/circular_queue.test.cc | |
parent | 487ea069be405844e1fcf4aa1ed274b74f601c39 (diff) | |
download | gem5-bbcbde7a924ca1ca58df997cfe9f750c285e5564.tar.xz |
base: Fix CircularQueue when diffing iterators
This patch is fixing CircularQueue iterators' subtraction, in particular
the behaviour when head and tail round multiple times.
Change-Id: Ie79ac8accd30a10cf039cf4def87675b01375d6b
Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-by: Gabor Dozsa <gabor.dozsa@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/17188
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Diffstat (limited to 'src/base/circular_queue.test.cc')
-rw-r--r-- | src/base/circular_queue.test.cc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/base/circular_queue.test.cc b/src/base/circular_queue.test.cc index db59c3049..cce6cb0b6 100644 --- a/src/base/circular_queue.test.cc +++ b/src/base/circular_queue.test.cc @@ -212,6 +212,7 @@ TEST(CircularQueueTest, IteratorsOp) ASSERT_EQ(it_1 + 1, it_2); ASSERT_EQ(it_1, it_2 - 1); ASSERT_EQ(it_2 - it_1, 1); + ASSERT_EQ(it_1 - it_2, -1); auto temp_it = it_1; ASSERT_EQ(++temp_it, it_2); @@ -241,3 +242,27 @@ TEST(CircularQueueTest, FullLoop) ASSERT_EQ(starting_it._idx, ending_it._idx); ASSERT_TRUE(starting_it != ending_it); } + +/** + * Testing correct behaviour when rounding multiple times: + * - Round indexes in sync + * - Difference between begin() and end() iterator is still + * equal to the CircularQueue size. + */ +TEST(CircularQueueTest, MultipleRound) +{ + const auto cq_size = 8; + CircularQueue<uint32_t> cq(cq_size); + + // Filling the queue making it round multiple times + auto items_added = cq_size * 3; + for (auto idx = 0; idx < items_added; idx++) { + cq.push_back(0); + } + + auto starting_it = cq.begin(); + auto ending_it = cq.end(); + + ASSERT_EQ(starting_it._round + 1, ending_it._round); + ASSERT_EQ(ending_it - starting_it, cq_size); +} |