Hash :
338abb46
Author :
Date :
2018-01-30T18:16:30
Fix invalid heap exception in angle Running angle deqp test case, an invalid heap exception is thrown in angle on both linux and windows platforms. If build a nonsequential heap, and then erase any node of the heap, the heap is no longer valid. If using std::push_heap or std::pop_heap method next, this exception will be thrown out. So we should use std::make_heap after modifying the heap. TEST=angle_deqp_gles2_tests TEST=angle_deqp_gles3_tests TEST=HandleAllocatorTest.ReserveAfterReleaseBug BUG=angleproject:2326 Change-Id: I123fc81b3365c93081d0042c69b4e5114956fe0d Reviewed-on: https://chromium-review.googlesource.com/892961 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Unit tests for HandleAllocator.
//
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "libANGLE/HandleAllocator.h"
namespace
{
TEST(HandleAllocatorTest, ReservationsWithGaps)
{
gl::HandleAllocator allocator;
std::set<GLuint> allocationList;
for (GLuint id = 2; id < 50; id += 2)
{
allocationList.insert(id);
}
for (GLuint id : allocationList)
{
allocator.reserve(id);
}
std::set<GLuint> allocatedList;
for (size_t allocationNum = 0; allocationNum < allocationList.size() * 2; ++allocationNum)
{
GLuint handle = allocator.allocate();
EXPECT_EQ(0u, allocationList.count(handle));
EXPECT_EQ(0u, allocatedList.count(handle));
allocatedList.insert(handle);
}
}
TEST(HandleAllocatorTest, Random)
{
gl::HandleAllocator allocator;
std::set<GLuint> allocationList;
for (size_t iterationCount = 0; iterationCount < 40; ++iterationCount)
{
for (size_t randomCount = 0; randomCount < 40; ++randomCount)
{
GLuint randomHandle = (rand() % 1000) + 1;
if (allocationList.count(randomHandle) == 0)
{
allocator.reserve(randomHandle);
allocationList.insert(randomHandle);
}
}
for (size_t normalCount = 0; normalCount < 40; ++normalCount)
{
GLuint normalHandle = allocator.allocate();
EXPECT_EQ(0u, allocationList.count(normalHandle));
allocationList.insert(normalHandle);
}
}
}
TEST(HandleAllocatorTest, Reallocation)
{
// Note: no current test for overflow
gl::HandleAllocator limitedAllocator(10);
for (GLuint count = 1; count < 10; count++)
{
GLuint result = limitedAllocator.allocate();
EXPECT_EQ(count, result);
}
for (GLuint count = 1; count < 10; count++)
{
limitedAllocator.release(count);
}
for (GLuint count = 2; count < 10; count++)
{
limitedAllocator.reserve(count);
}
GLint finalResult = limitedAllocator.allocate();
EXPECT_EQ(finalResult, 1);
}
// The following test covers reserving a handle with max uint value. See http://anglebug.com/1052
TEST(HandleAllocatorTest, ReserveMaxUintHandle)
{
gl::HandleAllocator allocator;
GLuint maxUintHandle = std::numeric_limits<GLuint>::max();
allocator.reserve(maxUintHandle);
GLuint normalHandle = allocator.allocate();
EXPECT_EQ(1u, normalHandle);
}
// The following test covers reserving a handle with max uint value minus one then max uint value.
TEST(HandleAllocatorTest, ReserveMaxUintHandle2)
{
gl::HandleAllocator allocator;
GLuint maxUintHandle = std::numeric_limits<GLuint>::max();
allocator.reserve(maxUintHandle - 1);
allocator.reserve(maxUintHandle);
GLuint normalHandle = allocator.allocate();
EXPECT_EQ(1u, normalHandle);
}
// To test if the allocator keep the handle in a sorted order.
TEST(HandleAllocatorTest, SortedOrderHandle)
{
gl::HandleAllocator allocator;
allocator.reserve(3);
GLuint allocatedList[5];
for (GLuint count = 0; count < 5; count++)
{
allocatedList[count] = allocator.allocate();
}
EXPECT_EQ(1u, allocatedList[0]);
EXPECT_EQ(2u, allocatedList[1]);
EXPECT_EQ(4u, allocatedList[2]);
EXPECT_EQ(5u, allocatedList[3]);
EXPECT_EQ(6u, allocatedList[4]);
}
// Tests the reset method.
TEST(HandleAllocatorTest, Reset)
{
gl::HandleAllocator allocator;
for (int iteration = 0; iteration < 1; ++iteration)
{
allocator.reserve(3);
EXPECT_EQ(1u, allocator.allocate());
EXPECT_EQ(2u, allocator.allocate());
EXPECT_EQ(4u, allocator.allocate());
allocator.reset();
}
}
// Covers a particular bug with reserving and allocating sub ranges.
TEST(HandleAllocatorTest, ReserveAndAllocateIterated)
{
gl::HandleAllocator allocator;
for (int iteration = 0; iteration < 3; ++iteration)
{
allocator.reserve(5);
allocator.reserve(6);
GLuint a = allocator.allocate();
GLuint b = allocator.allocate();
GLuint c = allocator.allocate();
allocator.release(c);
allocator.release(a);
allocator.release(b);
allocator.release(5);
allocator.release(6);
}
}
// This test reproduces invalid heap bug when reserve resources after release.
TEST(HandleAllocatorTest, ReserveAfterReleaseBug)
{
gl::HandleAllocator allocator;
for (int iteration = 1; iteration <= 16; ++iteration)
{
allocator.allocate();
}
allocator.release(15);
allocator.release(16);
for (int iteration = 1; iteration <= 14; ++iteration)
{
allocator.release(iteration);
}
allocator.reserve(1);
allocator.allocate();
}
} // anonymous namespace