diff options
author | Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> | 2024-03-05 00:45:47 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2024-03-05 00:45:47 +0000 |
commit | 119c7cdf37eae6f5ce49ac4f94e1a7bca9f107d3 (patch) | |
tree | a684527e87031cf8f07f5a7d418d79ea14b0d567 | |
parent | 956e18153f2b8ab38f1fac4ed7f6f054ac91f5e7 (diff) | |
parent | 453652eec9136ee2f8462a9fe8d18935f9967458 (diff) | |
download | aemu-119c7cdf37eae6f5ce49ac4f94e1a7bca9f107d3.tar.gz |
Merge "Allow mixing add and addFixed in HybridEntityManager" into main am: 453652eec9
Original change: https://android-review.googlesource.com/c/platform/hardware/google/aemu/+/2987119
Change-Id: I6ba7346ff43f50d94ea50e4685dd89461fcd36b8
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | base/CMakeLists.txt | 3 | ||||
-rw-r--r-- | base/HybridEntityManager_unittest.cpp | 45 | ||||
-rw-r--r-- | base/include/aemu/base/containers/HybridEntityManager.h | 5 |
3 files changed, 48 insertions, 5 deletions
diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt index 1c97220..5af7d98 100644 --- a/base/CMakeLists.txt +++ b/base/CMakeLists.txt @@ -150,7 +150,8 @@ if (ENABLE_VKCEREAL_TESTS) StringFormat_unittest.cpp SubAllocator_unittest.cpp TypeTraits_unittest.cpp - WorkerThread_unittest.cpp) + WorkerThread_unittest.cpp + HybridEntityManager_unittest.cpp) endif() add_executable(aemu-base_unittests ${aemu-base-test-srcs}) target_link_libraries( diff --git a/base/HybridEntityManager_unittest.cpp b/base/HybridEntityManager_unittest.cpp new file mode 100644 index 0000000..afc5670 --- /dev/null +++ b/base/HybridEntityManager_unittest.cpp @@ -0,0 +1,45 @@ +// Copyright (C) 2024 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include "aemu/base/containers/HybridEntityManager.h" + +#include <gtest/gtest.h> + +namespace android { +namespace base { + +static constexpr uint32_t kTestMaxIndex = 16; +using TestHCM = HybridEntityManager<kTestMaxIndex, uint64_t, int>; + +TEST(HybridEntityManager, UpdateIndex) { + TestHCM m; + // Occupy all linear entries. + for (uint32_t i = 0; i < kTestMaxIndex + 1; i++) { + m.add(i, 1); + } + int indices[4]; + indices[0] = m.addFixed(kTestMaxIndex, 0, 1); + indices[1] = m.add(100, 1); + indices[2] = m.add(2, 1); + m.remove(indices[1]); + m.addFixed(indices[1], 1, 1); + // Verify it doesn't overwrite old entries. + indices[3] = m.add(3, 1); + EXPECT_EQ(0, *m.get_const(indices[0])); + EXPECT_EQ(1, *m.get_const(indices[1])); + EXPECT_EQ(2, *m.get_const(indices[2])); + EXPECT_EQ(3, *m.get_const(indices[3])); +} + +} +}
\ No newline at end of file diff --git a/base/include/aemu/base/containers/HybridEntityManager.h b/base/include/aemu/base/containers/HybridEntityManager.h index dab8914..68452d9 100644 --- a/base/include/aemu/base/containers/HybridEntityManager.h +++ b/base/include/aemu/base/containers/HybridEntityManager.h @@ -70,11 +70,8 @@ public: } else { AutoLock lock(mMapLock); // Fixed allocations require us to update mIndexForMap to catch up with it. - // We assume that addFixed/add for the map case do not interleave badly - // (addFixed at i, add at i+1, addFixed at i+1) - mIndexForMap = index_u64; + mIndexForMap = std::max(index_u64 + 1, mIndexForMap); mMap[index_u64] = data; - ++mIndexForMap; return index; } } |