Use typed integers for the ExecutionSerial

This will prevent mixing it up with other serial types in the future.

Bug: dawn:442
Change-Id: I74e964708acc62eb0f33127cc48f1b9a7b171d11
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/28923
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez
2020-09-28 19:35:14 +00:00
committed by Commit Bot service account
parent ad4a66ec8f
commit 62139fcca7
59 changed files with 204 additions and 217 deletions

View File

@@ -31,14 +31,15 @@ TEST(RingBufferAllocatorTests, BasicTest) {
ASSERT_EQ(allocator.GetSize(), sizeInBytes);
// Ensure failure upon sub-allocating an oversized request.
ASSERT_EQ(allocator.Allocate(sizeInBytes + 1, 0), RingBufferAllocator::kInvalidOffset);
ASSERT_EQ(allocator.Allocate(sizeInBytes + 1, ExecutionSerial(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);
ASSERT_EQ(allocator.Allocate(sizeInBytes / 2, ExecutionSerial(1)), 0u);
ASSERT_EQ(allocator.Allocate(sizeInBytes / 2, ExecutionSerial(2)), 32000u);
// Ensure the buffer is full.
ASSERT_EQ(allocator.Allocate(1, 3), RingBufferAllocator::kInvalidOffset);
ASSERT_EQ(allocator.Allocate(1, ExecutionSerial(3)), RingBufferAllocator::kInvalidOffset);
}
// Tests that several ringbuffer allocations do not fail.
@@ -49,9 +50,9 @@ TEST(RingBufferAllocatorTests, RingBufferManyAlloc) {
RingBufferAllocator allocator(maxNumOfFrames * frameSizeInBytes);
size_t offset = 0;
for (size_t i = 0; i < maxNumOfFrames; ++i) {
for (ExecutionSerial i(0); i < ExecutionSerial(maxNumOfFrames); ++i) {
offset = allocator.Allocate(frameSizeInBytes, i);
ASSERT_EQ(offset, i * frameSizeInBytes);
ASSERT_EQ(offset, uint64_t(i) * frameSizeInBytes);
}
}
@@ -64,22 +65,22 @@ TEST(RingBufferAllocatorTests, AllocInSameFrame) {
// F1
// [xxxx|--------]
size_t offset = allocator.Allocate(frameSizeInBytes, 1);
size_t offset = allocator.Allocate(frameSizeInBytes, ExecutionSerial(1));
// F1 F2
// [xxxx|xxxx|----]
offset = allocator.Allocate(frameSizeInBytes, 2);
offset = allocator.Allocate(frameSizeInBytes, ExecutionSerial(2));
// F1 F2
// [xxxx|xxxxxxxx]
offset = allocator.Allocate(frameSizeInBytes, 2);
offset = allocator.Allocate(frameSizeInBytes, ExecutionSerial(2));
ASSERT_EQ(offset, 8u);
ASSERT_EQ(allocator.GetUsedSize(), frameSizeInBytes * 3);
allocator.Deallocate(2);
allocator.Deallocate(ExecutionSerial(2));
ASSERT_EQ(allocator.GetUsedSize(), 0u);
EXPECT_TRUE(allocator.Empty());
@@ -93,10 +94,10 @@ TEST(RingBufferAllocatorTests, RingBufferSubAlloc) {
RingBufferAllocator allocator(maxNumOfFrames * frameSizeInBytes);
// Sub-alloc the first eight frames.
Serial serial = 1;
for (size_t i = 0; i < 8; ++i) {
ExecutionSerial serial(0);
while (serial < ExecutionSerial(8)) {
allocator.Allocate(frameSizeInBytes, serial);
serial += 1;
serial++;
}
// Each frame corrresponds to the serial number (for simplicity).
@@ -106,12 +107,12 @@ TEST(RingBufferAllocatorTests, RingBufferSubAlloc) {
//
// Ensure an oversized allocation fails (only 8 bytes left)
ASSERT_EQ(allocator.Allocate(frameSizeInBytes * 3, serial + 1),
ASSERT_EQ(allocator.Allocate(frameSizeInBytes * 3, serial),
RingBufferAllocator::kInvalidOffset);
ASSERT_EQ(allocator.GetUsedSize(), frameSizeInBytes * 8);
// Reclaim the first 3 frames.
allocator.Deallocate(3);
allocator.Deallocate(ExecutionSerial(2));
// F4 F5 F6 F7 F8
// [------------|xxxx|xxxx|xxxx|xxxx|xxxx|--------]
@@ -119,7 +120,7 @@ TEST(RingBufferAllocatorTests, RingBufferSubAlloc) {
ASSERT_EQ(allocator.GetUsedSize(), frameSizeInBytes * 5);
// Re-try the over-sized allocation.
size_t offset = allocator.Allocate(frameSizeInBytes * 3, serial);
size_t offset = allocator.Allocate(frameSizeInBytes * 3, ExecutionSerial(serial));
// F9 F4 F5 F6 F7 F8
// [xxxxxxxxxxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxxxxxx]
@@ -133,11 +134,10 @@ TEST(RingBufferAllocatorTests, RingBufferSubAlloc) {
ASSERT_EQ(allocator.GetUsedSize(), frameSizeInBytes * maxNumOfFrames);
// Ensure we are full.
ASSERT_EQ(allocator.Allocate(frameSizeInBytes, serial + 1),
RingBufferAllocator::kInvalidOffset);
ASSERT_EQ(allocator.Allocate(frameSizeInBytes, serial), RingBufferAllocator::kInvalidOffset);
// Reclaim the next two frames.
allocator.Deallocate(5);
allocator.Deallocate(ExecutionSerial(4));
// F9 F4 F5 F6 F7 F8
// [xxxxxxxxxxxx|----|----|xxxx|xxxx|xxxx|xxxxxxxx]
@@ -145,7 +145,7 @@ TEST(RingBufferAllocatorTests, RingBufferSubAlloc) {
ASSERT_EQ(allocator.GetUsedSize(), frameSizeInBytes * 8);
// Sub-alloc the chunk in the middle.
serial += 1;
serial++;
offset = allocator.Allocate(frameSizeInBytes * 2, serial);
ASSERT_EQ(offset, frameSizeInBytes * 3);
@@ -156,22 +156,19 @@ TEST(RingBufferAllocatorTests, RingBufferSubAlloc) {
//
// Ensure we are full.
ASSERT_EQ(allocator.Allocate(frameSizeInBytes, serial + 1),
RingBufferAllocator::kInvalidOffset);
ASSERT_EQ(allocator.Allocate(frameSizeInBytes, serial), RingBufferAllocator::kInvalidOffset);
// Reclaim all.
allocator.Deallocate(maxNumOfFrames);
allocator.Deallocate(kMaxExecutionSerial);
EXPECT_TRUE(allocator.Empty());
}
// Checks if ringbuffer sub-allocation does not overflow.
TEST(RingBufferAllocatorTests, RingBufferOverflow) {
Serial serial = 1;
RingBufferAllocator allocator(std::numeric_limits<uint64_t>::max());
ASSERT_EQ(allocator.Allocate(1, serial), 0u);
ASSERT_EQ(allocator.Allocate(std::numeric_limits<uint64_t>::max(), serial + 1),
ASSERT_EQ(allocator.Allocate(1, ExecutionSerial(1)), 0u);
ASSERT_EQ(allocator.Allocate(std::numeric_limits<uint64_t>::max(), ExecutionSerial(1)),
RingBufferAllocator::kInvalidOffset);
}