From 98923fccad23da4e1dade15e016fbf3729cd485e Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sun, 14 Jan 2018 21:45:18 -0800 Subject: [PATCH] graphics: make mapper VTS utils more reusable Better include path (#include ), better library naming, and move GraphicsMapperHidlEnvironment to where tests are defined. Test: VTS Change-Id: I9fbf6515993ac11852b11ca6b8194a58afe5579a --- .../composer/2.1/vts/functional/Android.bp | 2 +- .../VtsHalGraphicsComposerV2_1TargetTest.cpp | 4 +- .../composer/2.2/vts/functional/Android.bp | 2 +- .../VtsHalGraphicsComposerV2_2TargetTest.cpp | 4 +- graphics/mapper/2.0/utils/vts/Android.bp | 6 +-- ...phicsMapperTestUtils.cpp => MapperVts.cpp} | 20 ++++----- .../mapper-vts/2.0/MapperVts.h} | 32 ++++---------- graphics/mapper/2.0/vts/functional/Android.bp | 8 +--- .../VtsHalGraphicsMapperV2_0TargetTest.cpp | 34 +++++++++++--- graphics/mapper/2.1/vts/functional/Android.bp | 6 +-- .../VtsHalGraphicsMapperV2_1TargetTest.cpp | 44 +++++++++++++------ 11 files changed, 87 insertions(+), 75 deletions(-) rename graphics/mapper/2.0/utils/vts/{VtsHalGraphicsMapperTestUtils.cpp => MapperVts.cpp} (95%) rename graphics/mapper/2.0/utils/vts/{VtsHalGraphicsMapperTestUtils.h => include/mapper-vts/2.0/MapperVts.h} (81%) diff --git a/graphics/composer/2.1/vts/functional/Android.bp b/graphics/composer/2.1/vts/functional/Android.bp index 40f18c0067..92b65a36a6 100644 --- a/graphics/composer/2.1/vts/functional/Android.bp +++ b/graphics/composer/2.1/vts/functional/Android.bp @@ -58,8 +58,8 @@ cc_test { "android.hardware.graphics.allocator@2.0", "android.hardware.graphics.composer@2.1", "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@2.0-vts", "libVtsHalGraphicsComposerTestUtils", - "libVtsHalGraphicsMapperTestUtils", "libnativehelper", ], header_libs: [ diff --git a/graphics/composer/2.1/vts/functional/VtsHalGraphicsComposerV2_1TargetTest.cpp b/graphics/composer/2.1/vts/functional/VtsHalGraphicsComposerV2_1TargetTest.cpp index 9a749d7837..376ee37985 100644 --- a/graphics/composer/2.1/vts/functional/VtsHalGraphicsComposerV2_1TargetTest.cpp +++ b/graphics/composer/2.1/vts/functional/VtsHalGraphicsComposerV2_1TargetTest.cpp @@ -17,10 +17,10 @@ #define LOG_TAG "graphics_composer_hidl_hal_test" #include +#include #include "GraphicsComposerCallback.h" #include "TestCommandReader.h" #include "VtsHalGraphicsComposerTestUtils.h" -#include "VtsHalGraphicsMapperTestUtils.h" #include #include @@ -48,7 +48,7 @@ using android::hardware::graphics::common::V1_0::Dataspace; using android::hardware::graphics::common::V1_0::PixelFormat; using android::hardware::graphics::common::V1_0::Transform; using android::hardware::graphics::mapper::V2_0::IMapper; -using android::hardware::graphics::mapper::V2_0::tests::Gralloc; +using android::hardware::graphics::mapper::V2_0::vts::Gralloc; using GrallocError = android::hardware::graphics::mapper::V2_0::Error; // Test environment for graphics.composer diff --git a/graphics/composer/2.2/vts/functional/Android.bp b/graphics/composer/2.2/vts/functional/Android.bp index 0325a6c57c..78322a1133 100644 --- a/graphics/composer/2.2/vts/functional/Android.bp +++ b/graphics/composer/2.2/vts/functional/Android.bp @@ -61,10 +61,10 @@ cc_test { "android.hardware.graphics.composer@2.2", "android.hardware.graphics.composer@2.1", "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@2.0-vts", "android.hardware.graphics.mapper@2.1", "libVtsHalGraphicsComposerTestUtils", "libVtsHalGraphicsComposerTestUtils@2.2", - "libVtsHalGraphicsMapperTestUtils", "libnativehelper", ], header_libs: [ diff --git a/graphics/composer/2.2/vts/functional/VtsHalGraphicsComposerV2_2TargetTest.cpp b/graphics/composer/2.2/vts/functional/VtsHalGraphicsComposerV2_2TargetTest.cpp index 8b44d617ae..6fbdd3c864 100644 --- a/graphics/composer/2.2/vts/functional/VtsHalGraphicsComposerV2_2TargetTest.cpp +++ b/graphics/composer/2.2/vts/functional/VtsHalGraphicsComposerV2_2TargetTest.cpp @@ -18,12 +18,12 @@ #include #include +#include #include #include "2.2/VtsHalGraphicsComposerTestUtils.h" #include "GraphicsComposerCallback.h" #include "TestCommandReader.h" #include "VtsHalGraphicsComposerTestUtils.h" -#include "VtsHalGraphicsMapperTestUtils.h" #include @@ -43,7 +43,7 @@ using android::hardware::graphics::common::V1_0::PixelFormat; using android::hardware::graphics::common::V1_0::Transform; using android::hardware::graphics::composer::V2_2::IComposerClient; using android::hardware::graphics::mapper::V2_0::IMapper; -using android::hardware::graphics::mapper::V2_0::tests::Gralloc; +using android::hardware::graphics::mapper::V2_0::vts::Gralloc; using GrallocError = android::hardware::graphics::mapper::V2_0::Error; // Test environment for graphics.composer diff --git a/graphics/mapper/2.0/utils/vts/Android.bp b/graphics/mapper/2.0/utils/vts/Android.bp index 8bca152afa..1aa31853b1 100644 --- a/graphics/mapper/2.0/utils/vts/Android.bp +++ b/graphics/mapper/2.0/utils/vts/Android.bp @@ -15,9 +15,9 @@ // cc_library_static { - name: "libVtsHalGraphicsMapperTestUtils", + name: "android.hardware.graphics.mapper@2.0-vts", defaults: ["hidl_defaults"], - srcs: ["VtsHalGraphicsMapperTestUtils.cpp"], + srcs: ["MapperVts.cpp"], cflags: [ "-O0", "-g", @@ -34,5 +34,5 @@ cc_library_static { "android.hardware.graphics.allocator@2.0", "android.hardware.graphics.mapper@2.0", ], - export_include_dirs: ["."], + export_include_dirs: ["include"], } diff --git a/graphics/mapper/2.0/utils/vts/VtsHalGraphicsMapperTestUtils.cpp b/graphics/mapper/2.0/utils/vts/MapperVts.cpp similarity index 95% rename from graphics/mapper/2.0/utils/vts/VtsHalGraphicsMapperTestUtils.cpp rename to graphics/mapper/2.0/utils/vts/MapperVts.cpp index e3229caf2d..d08ac56085 100644 --- a/graphics/mapper/2.0/utils/vts/VtsHalGraphicsMapperTestUtils.cpp +++ b/graphics/mapper/2.0/utils/vts/MapperVts.cpp @@ -14,28 +14,26 @@ * limitations under the License. */ -#include +#include -#include "VtsHalGraphicsMapperTestUtils.h" +#include namespace android { namespace hardware { namespace graphics { namespace mapper { namespace V2_0 { -namespace tests { +namespace vts { -Gralloc::Gralloc() { - init(); +Gralloc::Gralloc(const std::string& allocatorServiceName, const std::string& mapperServiceName) { + init(allocatorServiceName, mapperServiceName); } -void Gralloc::init() { - mAllocator = ::testing::VtsHalHidlTargetTestBase::getService( - GraphicsMapperHidlEnvironment::Instance()->getServiceName()); +void Gralloc::init(const std::string& allocatorServiceName, const std::string& mapperServiceName) { + mAllocator = ::testing::VtsHalHidlTargetTestBase::getService(allocatorServiceName); ASSERT_NE(nullptr, mAllocator.get()) << "failed to get allocator service"; - mMapper = ::testing::VtsHalHidlTargetTestBase::getService( - GraphicsMapperHidlEnvironment::Instance()->getServiceName()); + mMapper = ::testing::VtsHalHidlTargetTestBase::getService(mapperServiceName); ASSERT_NE(nullptr, mMapper.get()) << "failed to get mapper service"; ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode"; } @@ -240,7 +238,7 @@ int Gralloc::unlock(const native_handle_t* bufferHandle) { return releaseFence; } -} // namespace tests +} // namespace vts } // namespace V2_0 } // namespace mapper } // namespace graphics diff --git a/graphics/mapper/2.0/utils/vts/VtsHalGraphicsMapperTestUtils.h b/graphics/mapper/2.0/utils/vts/include/mapper-vts/2.0/MapperVts.h similarity index 81% rename from graphics/mapper/2.0/utils/vts/VtsHalGraphicsMapperTestUtils.h rename to graphics/mapper/2.0/utils/vts/include/mapper-vts/2.0/MapperVts.h index 1f7d88aefc..6c2c9a662c 100644 --- a/graphics/mapper/2.0/utils/vts/VtsHalGraphicsMapperTestUtils.h +++ b/graphics/mapper/2.0/utils/vts/include/mapper-vts/2.0/MapperVts.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef VTS_HAL_GRAPHICS_MAPPER_UTILS -#define VTS_HAL_GRAPHICS_MAPPER_UTILS +#pragma once +#include #include +#include -#include #include #include #include @@ -29,14 +29,15 @@ namespace hardware { namespace graphics { namespace mapper { namespace V2_0 { -namespace tests { +namespace vts { using android::hardware::graphics::allocator::V2_0::IAllocator; // A wrapper to IAllocator and IMapper. class Gralloc { public: - Gralloc(); + Gralloc(const std::string& allocatorServiceName = "default", + const std::string& mapperServiceName = "default"); ~Gralloc(); // IAllocator methods @@ -73,7 +74,7 @@ class Gralloc { int unlock(const native_handle_t* bufferHandle); private: - void init(); + void init(const std::string& allocatorServiceName, const std::string& mapperServiceName); const native_handle_t* cloneBuffer(const hidl_handle& rawHandle); sp mAllocator; @@ -85,26 +86,9 @@ class Gralloc { std::unordered_set mImportedBuffers; }; -// Test environment for graphics.mapper. -class GraphicsMapperHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { - public: - // get the test environment singleton - static GraphicsMapperHidlEnvironment* Instance() { - static GraphicsMapperHidlEnvironment* instance = new GraphicsMapperHidlEnvironment; - return instance; - } - - virtual void registerTestServices() override { - registerTestService(); - registerTestService(); - } -}; - -} // namespace tests +} // namespace vts } // namespace V2_0 } // namespace mapper } // namespace graphics } // namespace hardware } // namespace android - -#endif // VTS_HAL_GRAPHICS_MAPPER_UTILS diff --git a/graphics/mapper/2.0/vts/functional/Android.bp b/graphics/mapper/2.0/vts/functional/Android.bp index 8093b08676..969317a8f5 100644 --- a/graphics/mapper/2.0/vts/functional/Android.bp +++ b/graphics/mapper/2.0/vts/functional/Android.bp @@ -18,14 +18,10 @@ cc_test { name: "VtsHalGraphicsMapperV2_0TargetTest", defaults: ["VtsHalTargetTestDefaults"], srcs: ["VtsHalGraphicsMapperV2_0TargetTest.cpp"], - shared_libs: [ - "libsync", - ], static_libs: [ "android.hardware.graphics.allocator@2.0", - "android.hardware.graphics.mapper@2.0", "android.hardware.graphics.common@1.0", - "libVtsHalGraphicsMapperTestUtils", - "libnativehelper", + "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@2.0-vts", ], } diff --git a/graphics/mapper/2.0/vts/functional/VtsHalGraphicsMapperV2_0TargetTest.cpp b/graphics/mapper/2.0/vts/functional/VtsHalGraphicsMapperV2_0TargetTest.cpp index 21ea66d7cd..aa9beff735 100644 --- a/graphics/mapper/2.0/vts/functional/VtsHalGraphicsMapperV2_0TargetTest.cpp +++ b/graphics/mapper/2.0/vts/functional/VtsHalGraphicsMapperV2_0TargetTest.cpp @@ -18,24 +18,41 @@ #include #include -#include -#include "VtsHalGraphicsMapperTestUtils.h" +#include namespace android { namespace hardware { namespace graphics { namespace mapper { namespace V2_0 { -namespace tests { +namespace vts { namespace { using android::hardware::graphics::common::V1_0::BufferUsage; using android::hardware::graphics::common::V1_0::PixelFormat; +// Test environment for graphics.mapper. +class GraphicsMapperHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { + public: + // get the test environment singleton + static GraphicsMapperHidlEnvironment* Instance() { + static GraphicsMapperHidlEnvironment* instance = new GraphicsMapperHidlEnvironment; + return instance; + } + + virtual void registerTestServices() override { + registerTestService(); + registerTestService(); + } +}; + class GraphicsMapperHidlTest : public ::testing::VtsHalHidlTargetTestBase { protected: void SetUp() override { - ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique()); + ASSERT_NO_FATAL_FAILURE( + mGralloc = std::make_unique( + GraphicsMapperHidlEnvironment::Instance()->getServiceName(), + GraphicsMapperHidlEnvironment::Instance()->getServiceName())); mDummyDescriptorInfo.width = 64; mDummyDescriptorInfo.height = 64; @@ -167,7 +184,10 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferSingleton) { // free the imported handle with another mapper std::unique_ptr anotherGralloc; - ASSERT_NO_FATAL_FAILURE(anotherGralloc = std::make_unique()); + ASSERT_NO_FATAL_FAILURE( + anotherGralloc = std::make_unique( + GraphicsMapperHidlEnvironment::Instance()->getServiceName(), + GraphicsMapperHidlEnvironment::Instance()->getServiceName())); Error error = mGralloc->getMapper()->freeBuffer(importedHandle); ASSERT_EQ(Error::NONE, error); @@ -373,7 +393,7 @@ TEST_F(GraphicsMapperHidlTest, UnlockNegative) { } } // namespace -} // namespace tests +} // namespace vts } // namespace V2_0 } // namespace mapper } // namespace graphics @@ -381,7 +401,7 @@ TEST_F(GraphicsMapperHidlTest, UnlockNegative) { } // namespace android int main(int argc, char** argv) { - using android::hardware::graphics::mapper::V2_0::tests::GraphicsMapperHidlEnvironment; + using android::hardware::graphics::mapper::V2_0::vts::GraphicsMapperHidlEnvironment; ::testing::AddGlobalTestEnvironment(GraphicsMapperHidlEnvironment::Instance()); ::testing::InitGoogleTest(&argc, argv); GraphicsMapperHidlEnvironment::Instance()->init(&argc, argv); diff --git a/graphics/mapper/2.1/vts/functional/Android.bp b/graphics/mapper/2.1/vts/functional/Android.bp index 578d298a19..74d6fa8d1e 100644 --- a/graphics/mapper/2.1/vts/functional/Android.bp +++ b/graphics/mapper/2.1/vts/functional/Android.bp @@ -18,15 +18,11 @@ cc_test { name: "VtsHalGraphicsMapperV2_1TargetTest", defaults: ["VtsHalTargetTestDefaults"], srcs: ["VtsHalGraphicsMapperV2_1TargetTest.cpp"], - shared_libs: [ - "libsync", - ], static_libs: [ "android.hardware.graphics.allocator@2.0", "android.hardware.graphics.common@1.0", "android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@2.1", - "libVtsHalGraphicsMapperTestUtils", - "libnativehelper", + "android.hardware.graphics.mapper@2.0-vts", ], } diff --git a/graphics/mapper/2.1/vts/functional/VtsHalGraphicsMapperV2_1TargetTest.cpp b/graphics/mapper/2.1/vts/functional/VtsHalGraphicsMapperV2_1TargetTest.cpp index 88b96ae165..803c3265f2 100644 --- a/graphics/mapper/2.1/vts/functional/VtsHalGraphicsMapperV2_1TargetTest.cpp +++ b/graphics/mapper/2.1/vts/functional/VtsHalGraphicsMapperV2_1TargetTest.cpp @@ -19,22 +19,21 @@ #include #include #include -#include -#include "VtsHalGraphicsMapperTestUtils.h" +#include namespace android { namespace hardware { namespace graphics { namespace mapper { namespace V2_1 { -namespace tests { +namespace vts { namespace { -using android::hardware::graphics::mapper::V2_0::BufferDescriptor; -using android::hardware::graphics::mapper::V2_0::Error; - +using android::hardware::graphics::allocator::V2_0::IAllocator; using android::hardware::graphics::common::V1_1::BufferUsage; using android::hardware::graphics::common::V1_1::PixelFormat; +using V2_0::BufferDescriptor; +using V2_0::Error; // abuse VTS to check binary compatibility between BufferDescriptorInfos using OldBufferDescriptorInfo = @@ -52,9 +51,25 @@ static_assert(sizeof(OldBufferDescriptorInfo) == sizeof(IMapper::BufferDescripto offsetof(IMapper::BufferDescriptorInfo, usage), ""); -class Gralloc : public V2_0::tests::Gralloc { +// Test environment for graphics.mapper. +class GraphicsMapperHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { public: - Gralloc() : V2_0::tests::Gralloc() { + // get the test environment singleton + static GraphicsMapperHidlEnvironment* Instance() { + static GraphicsMapperHidlEnvironment* instance = new GraphicsMapperHidlEnvironment; + return instance; + } + + virtual void registerTestServices() override { + registerTestService(); + registerTestService(); + } +}; + +class Gralloc : public V2_0::vts::Gralloc { + public: + Gralloc(const std::string& allocatorServiceName, const std::string& mapperServiceName) + : V2_0::vts::Gralloc(allocatorServiceName, mapperServiceName) { if (::testing::Test::HasFatalFailure()) { return; } @@ -107,7 +122,7 @@ class Gralloc : public V2_0::tests::Gralloc { return nullptr; } - auto buffers = V2_0::tests::Gralloc::allocate(descriptor, 1, import, outStride); + auto buffers = V2_0::vts::Gralloc::allocate(descriptor, 1, import, outStride); if (::testing::Test::HasFatalFailure()) { return nullptr; } @@ -117,7 +132,7 @@ class Gralloc : public V2_0::tests::Gralloc { private: void init() { - mMapper = IMapper::castFrom(V2_0::tests::Gralloc::getMapper()); + mMapper = IMapper::castFrom(V2_0::vts::Gralloc::getMapper()); ASSERT_NE(nullptr, mMapper.get()) << "failed to find IMapper 2.1"; } @@ -127,7 +142,10 @@ class Gralloc : public V2_0::tests::Gralloc { class GraphicsMapperHidlTest : public ::testing::VtsHalHidlTargetTestBase { protected: void SetUp() override { - ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique()); + ASSERT_NO_FATAL_FAILURE( + mGralloc = std::make_unique( + GraphicsMapperHidlEnvironment::Instance()->getServiceName(), + GraphicsMapperHidlEnvironment::Instance()->getServiceName())); mDummyDescriptorInfo.width = 64; mDummyDescriptorInfo.height = 64; @@ -291,7 +309,7 @@ TEST_F(GraphicsMapperHidlTest, CreateDescriptor_2_1Negative) { } } // namespace -} // namespace tests +} // namespace vts } // namespace V2_1 } // namespace mapper } // namespace graphics @@ -299,7 +317,7 @@ TEST_F(GraphicsMapperHidlTest, CreateDescriptor_2_1Negative) { } // namespace android int main(int argc, char** argv) { - using android::hardware::graphics::mapper::V2_0::tests::GraphicsMapperHidlEnvironment; + using android::hardware::graphics::mapper::V2_1::vts::GraphicsMapperHidlEnvironment; ::testing::AddGlobalTestEnvironment(GraphicsMapperHidlEnvironment::Instance()); ::testing::InitGoogleTest(&argc, argv); GraphicsMapperHidlEnvironment::Instance()->init(&argc, argv);