Edit

kc3-lang/angle/src/libANGLE/HandleAllocator_unittest.cpp

Branch :

  • Show log

    Commit

  • Author : Jamie Madill
    Date : 2015-03-20 15:29:42
    Hash : bdd419f9
    Message : Fix ResourceManager create-on-bind reallocations. *re-land with build fix for Clang* We had a funny bug where the Handle Allocator would re-allocate reserved handles after the app layer creates one with Bind rather than using Gen. This affects Textures, Buffers and Renderbuffers. Fix this by using a different allocation scheme. It should still be fast on the "good" case (using Gen) and use tree lookups on the bind case. Also add some unit tests. BUG=angleproject:942 Change-Id: I63ce608fcd6a11f92e2b5421f090551934e729ed Reviewed-on: https://chromium-review.googlesource.com/261591 Tested-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>

  • src/libANGLE/HandleAllocator_unittest.cpp
  • //
    // 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);
    }
    
    }