Move kInvalidOffset to RingBufferAllocator namespace.

BUG=dawn:27

Change-Id: I1c580d8e41c4f9bb10b638297b4c3a3fa61a0d93
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11680
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Bryan Bernhart
2019-09-27 21:26:13 +00:00
committed by Commit Bot service account
parent f622a44750
commit 52bd6b7da6
3 changed files with 15 additions and 10 deletions

View File

@@ -18,6 +18,8 @@
using namespace dawn_native;
constexpr size_t RingBufferAllocator::kInvalidOffset;
// Number of basic tests for Ringbuffer
TEST(RingBufferAllocatorTests, BasicTest) {
constexpr size_t sizeInBytes = 64000;
@@ -29,14 +31,14 @@ TEST(RingBufferAllocatorTests, BasicTest) {
ASSERT_EQ(allocator.GetSize(), sizeInBytes);
// Ensure failure upon sub-allocating an oversized request.
ASSERT_EQ(allocator.Allocate(sizeInBytes + 1, 0), kInvalidOffset);
ASSERT_EQ(allocator.Allocate(sizeInBytes + 1, 0), RingBufferAllocator::kInvalidOffset);
// Fill the entire buffer with two requests of equal size.
ASSERT_EQ(allocator.Allocate(sizeInBytes / 2, 1), 0u);
ASSERT_EQ(allocator.Allocate(sizeInBytes / 2, 2), 32000u);
// Ensure the buffer is full.
ASSERT_EQ(allocator.Allocate(1, 3), kInvalidOffset);
ASSERT_EQ(allocator.Allocate(1, 3), RingBufferAllocator::kInvalidOffset);
}
// Tests that several ringbuffer allocations do not fail.
@@ -104,7 +106,8 @@ TEST(RingBufferAllocatorTests, RingBufferSubAlloc) {
//
// Ensure an oversized allocation fails (only 8 bytes left)
ASSERT_EQ(allocator.Allocate(frameSizeInBytes * 3, serial + 1), kInvalidOffset);
ASSERT_EQ(allocator.Allocate(frameSizeInBytes * 3, serial + 1),
RingBufferAllocator::kInvalidOffset);
ASSERT_EQ(allocator.GetUsedSize(), frameSizeInBytes * 8);
// Reclaim the first 3 frames.
@@ -130,7 +133,8 @@ TEST(RingBufferAllocatorTests, RingBufferSubAlloc) {
ASSERT_EQ(allocator.GetUsedSize(), frameSizeInBytes * maxNumOfFrames);
// Ensure we are full.
ASSERT_EQ(allocator.Allocate(frameSizeInBytes, serial + 1), kInvalidOffset);
ASSERT_EQ(allocator.Allocate(frameSizeInBytes, serial + 1),
RingBufferAllocator::kInvalidOffset);
// Reclaim the next two frames.
allocator.Deallocate(5);
@@ -152,7 +156,8 @@ TEST(RingBufferAllocatorTests, RingBufferSubAlloc) {
//
// Ensure we are full.
ASSERT_EQ(allocator.Allocate(frameSizeInBytes, serial + 1), kInvalidOffset);
ASSERT_EQ(allocator.Allocate(frameSizeInBytes, serial + 1),
RingBufferAllocator::kInvalidOffset);
// Reclaim all.
allocator.Deallocate(maxNumOfFrames);