summaryrefslogtreecommitdiffstats
path: root/graphics/mapper
diff options
context:
space:
mode:
authorChia-I Wu <olv@google.com>2018-08-01 10:01:02 -0700
committerChia-I Wu <olv@google.com>2018-08-01 10:01:38 -0700
commit2209bcb1868fad1b1b62233bd750a814674651c7 (patch)
tree69f960a1e1231c8c3024d250d61d675f549c8c80 /graphics/mapper
parentf6fa2f0f44d1b33c809c14cd66722b56277b4a7a (diff)
downloadplatform_hardware_interfaces-2209bcb1868fad1b1b62233bd750a814674651c7.tar.gz
platform_hardware_interfaces-2209bcb1868fad1b1b62233bd750a814674651c7.tar.bz2
platform_hardware_interfaces-2209bcb1868fad1b1b62233bd750a814674651c7.zip
graphics: test buffer allocation for thread safety
Bug: 111604912 Test: VTS Change-Id: I1b6cacc8d6ff5e1c145425ff6f32001090b07b06
Diffstat (limited to 'graphics/mapper')
-rw-r--r--graphics/mapper/2.0/vts/functional/VtsHalGraphicsMapperV2_0TargetTest.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/graphics/mapper/2.0/vts/functional/VtsHalGraphicsMapperV2_0TargetTest.cpp b/graphics/mapper/2.0/vts/functional/VtsHalGraphicsMapperV2_0TargetTest.cpp
index aa9beff735..5ec0af2cda 100644
--- a/graphics/mapper/2.0/vts/functional/VtsHalGraphicsMapperV2_0TargetTest.cpp
+++ b/graphics/mapper/2.0/vts/functional/VtsHalGraphicsMapperV2_0TargetTest.cpp
@@ -16,6 +16,10 @@
#define LOG_TAG "VtsHalGraphicsMapperV2_0TargetTest"
+#include <chrono>
+#include <thread>
+#include <vector>
+
#include <VtsHalHidlTargetTestBase.h>
#include <android-base/logging.h>
#include <mapper-vts/2.0/MapperVts.h>
@@ -125,6 +129,36 @@ TEST_F(GraphicsMapperHidlTest, AllocatorAllocateNoLeak) {
}
/**
+ * Test that IAllocator::allocate is thread-safe.
+ */
+TEST_F(GraphicsMapperHidlTest, AllocatorAllocateThreaded) {
+ BufferDescriptor descriptor;
+ ASSERT_NO_FATAL_FAILURE(descriptor = mGralloc->createDescriptor(mDummyDescriptorInfo));
+
+ std::atomic<bool> timeUp(false);
+ std::atomic<uint64_t> allocationCount(0);
+ auto threadLoop = [&]() {
+ while (!timeUp) {
+ mGralloc->getAllocator()->allocate(
+ descriptor, 1, [&](const auto&, const auto&, const auto&) { allocationCount++; });
+ }
+ };
+
+ std::vector<std::thread> threads;
+ for (int i = 0; i < 8; i++) {
+ threads.push_back(std::thread(threadLoop));
+ }
+
+ std::this_thread::sleep_for(std::chrono::seconds(3));
+ timeUp = true;
+ LOG(VERBOSE) << "Made " << allocationCount << " threaded allocations";
+
+ for (auto& thread : threads) {
+ thread.join();
+ }
+}
+
+/**
* Test IMapper::createDescriptor with valid descriptor info.
*/
TEST_F(GraphicsMapperHidlTest, CreateDescriptorBasic) {