diff --git a/graphics/mapper/2.0/utils/vts/MapperVts.cpp b/graphics/mapper/2.0/utils/vts/MapperVts.cpp index d08ac56085..d4e4dde4fa 100644 --- a/graphics/mapper/2.0/utils/vts/MapperVts.cpp +++ b/graphics/mapper/2.0/utils/vts/MapperVts.cpp @@ -16,8 +16,6 @@ #include -#include - namespace android { namespace hardware { namespace graphics { @@ -30,10 +28,10 @@ Gralloc::Gralloc(const std::string& allocatorServiceName, const std::string& map } void Gralloc::init(const std::string& allocatorServiceName, const std::string& mapperServiceName) { - mAllocator = ::testing::VtsHalHidlTargetTestBase::getService(allocatorServiceName); + mAllocator = IAllocator::getService(allocatorServiceName); ASSERT_NE(nullptr, mAllocator.get()) << "failed to get allocator service"; - mMapper = ::testing::VtsHalHidlTargetTestBase::getService(mapperServiceName); + mMapper = IMapper::getService(mapperServiceName); ASSERT_NE(nullptr, mMapper.get()) << "failed to get mapper service"; ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode"; } diff --git a/graphics/mapper/2.0/utils/vts/include/mapper-vts/2.0/MapperVts.h b/graphics/mapper/2.0/utils/vts/include/mapper-vts/2.0/MapperVts.h index 6c2c9a662c..fc8a1028e5 100644 --- a/graphics/mapper/2.0/utils/vts/include/mapper-vts/2.0/MapperVts.h +++ b/graphics/mapper/2.0/utils/vts/include/mapper-vts/2.0/MapperVts.h @@ -22,6 +22,7 @@ #include #include +#include #include namespace android { diff --git a/graphics/mapper/2.0/vts/functional/Android.bp b/graphics/mapper/2.0/vts/functional/Android.bp index 853c2a3b0e..a055b61b60 100644 --- a/graphics/mapper/2.0/vts/functional/Android.bp +++ b/graphics/mapper/2.0/vts/functional/Android.bp @@ -24,5 +24,5 @@ cc_test { "android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@2.0-vts", ], - test_suites: ["general-tests"], + test_suites: ["general-tests", "vts-core"], } diff --git a/graphics/mapper/2.0/vts/functional/VtsHalGraphicsMapperV2_0TargetTest.cpp b/graphics/mapper/2.0/vts/functional/VtsHalGraphicsMapperV2_0TargetTest.cpp index 5ec0af2cda..b079a4b689 100644 --- a/graphics/mapper/2.0/vts/functional/VtsHalGraphicsMapperV2_0TargetTest.cpp +++ b/graphics/mapper/2.0/vts/functional/VtsHalGraphicsMapperV2_0TargetTest.cpp @@ -20,8 +20,10 @@ #include #include -#include #include +#include +#include +#include #include namespace android { @@ -35,28 +37,12 @@ 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: +class GraphicsMapperHidlTest + : public ::testing::TestWithParam> { + protected: void SetUp() override { - ASSERT_NO_FATAL_FAILURE( - mGralloc = std::make_unique( - GraphicsMapperHidlEnvironment::Instance()->getServiceName(), - GraphicsMapperHidlEnvironment::Instance()->getServiceName())); + ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique(std::get<0>(GetParam()), + std::get<1>(GetParam()))); mDummyDescriptorInfo.width = 64; mDummyDescriptorInfo.height = 64; @@ -75,14 +61,14 @@ class GraphicsMapperHidlTest : public ::testing::VtsHalHidlTargetTestBase { /** * Test IAllocator::dumpDebugInfo by calling it. */ -TEST_F(GraphicsMapperHidlTest, AllocatorDumpDebugInfo) { +TEST_P(GraphicsMapperHidlTest, AllocatorDumpDebugInfo) { mGralloc->dumpDebugInfo(); } /** * Test IAllocator::allocate with valid buffer descriptors. */ -TEST_F(GraphicsMapperHidlTest, AllocatorAllocate) { +TEST_P(GraphicsMapperHidlTest, AllocatorAllocate) { BufferDescriptor descriptor; ASSERT_NO_FATAL_FAILURE(descriptor = mGralloc->createDescriptor(mDummyDescriptorInfo)); @@ -105,7 +91,7 @@ TEST_F(GraphicsMapperHidlTest, AllocatorAllocate) { /** * Test IAllocator::allocate with invalid buffer descriptors. */ -TEST_F(GraphicsMapperHidlTest, AllocatorAllocateNegative) { +TEST_P(GraphicsMapperHidlTest, AllocatorAllocateNegative) { // this assumes any valid descriptor is non-empty BufferDescriptor descriptor; mGralloc->getAllocator()->allocate(descriptor, 1, @@ -117,7 +103,7 @@ TEST_F(GraphicsMapperHidlTest, AllocatorAllocateNegative) { /** * Test IAllocator::allocate does not leak. */ -TEST_F(GraphicsMapperHidlTest, AllocatorAllocateNoLeak) { +TEST_P(GraphicsMapperHidlTest, AllocatorAllocateNoLeak) { auto info = mDummyDescriptorInfo; info.width = 1024; info.height = 1024; @@ -131,7 +117,7 @@ TEST_F(GraphicsMapperHidlTest, AllocatorAllocateNoLeak) { /** * Test that IAllocator::allocate is thread-safe. */ -TEST_F(GraphicsMapperHidlTest, AllocatorAllocateThreaded) { +TEST_P(GraphicsMapperHidlTest, AllocatorAllocateThreaded) { BufferDescriptor descriptor; ASSERT_NO_FATAL_FAILURE(descriptor = mGralloc->createDescriptor(mDummyDescriptorInfo)); @@ -161,14 +147,14 @@ TEST_F(GraphicsMapperHidlTest, AllocatorAllocateThreaded) { /** * Test IMapper::createDescriptor with valid descriptor info. */ -TEST_F(GraphicsMapperHidlTest, CreateDescriptorBasic) { +TEST_P(GraphicsMapperHidlTest, CreateDescriptorBasic) { ASSERT_NO_FATAL_FAILURE(mGralloc->createDescriptor(mDummyDescriptorInfo)); } /** * Test IMapper::createDescriptor with invalid descriptor info. */ -TEST_F(GraphicsMapperHidlTest, CreateDescriptorNegative) { +TEST_P(GraphicsMapperHidlTest, CreateDescriptorNegative) { auto info = mDummyDescriptorInfo; info.width = 0; mGralloc->getMapper()->createDescriptor(info, [&](const auto& tmpError, const auto&) { @@ -179,7 +165,7 @@ TEST_F(GraphicsMapperHidlTest, CreateDescriptorNegative) { /** * Test IMapper::importBuffer and IMapper::freeBuffer with allocated buffers. */ -TEST_F(GraphicsMapperHidlTest, ImportFreeBufferBasic) { +TEST_P(GraphicsMapperHidlTest, ImportFreeBufferBasic) { const native_handle_t* bufferHandle; ASSERT_NO_FATAL_FAILURE(bufferHandle = mGralloc->allocate(mDummyDescriptorInfo, true)); ASSERT_NO_FATAL_FAILURE(mGralloc->freeBuffer(bufferHandle)); @@ -188,7 +174,7 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferBasic) { /** * Test IMapper::importBuffer and IMapper::freeBuffer with cloned buffers. */ -TEST_F(GraphicsMapperHidlTest, ImportFreeBufferClone) { +TEST_P(GraphicsMapperHidlTest, ImportFreeBufferClone) { const native_handle_t* clonedBufferHandle; ASSERT_NO_FATAL_FAILURE(clonedBufferHandle = mGralloc->allocate(mDummyDescriptorInfo, false)); @@ -206,7 +192,7 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferClone) { /** * Test IMapper::importBuffer and IMapper::freeBuffer cross mapper instances. */ -TEST_F(GraphicsMapperHidlTest, ImportFreeBufferSingleton) { +TEST_P(GraphicsMapperHidlTest, ImportFreeBufferSingleton) { const native_handle_t* rawHandle; ASSERT_NO_FATAL_FAILURE(rawHandle = mGralloc->allocate(mDummyDescriptorInfo, false)); @@ -218,10 +204,8 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferSingleton) { // free the imported handle with another mapper std::unique_ptr anotherGralloc; - ASSERT_NO_FATAL_FAILURE( - anotherGralloc = std::make_unique( - GraphicsMapperHidlEnvironment::Instance()->getServiceName(), - GraphicsMapperHidlEnvironment::Instance()->getServiceName())); + ASSERT_NO_FATAL_FAILURE(anotherGralloc = std::make_unique(std::get<0>(GetParam()), + std::get<1>(GetParam()))); Error error = mGralloc->getMapper()->freeBuffer(importedHandle); ASSERT_EQ(Error::NONE, error); @@ -231,7 +215,7 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferSingleton) { /** * Test IMapper::importBuffer and IMapper::freeBuffer do not leak. */ -TEST_F(GraphicsMapperHidlTest, ImportFreeBufferNoLeak) { +TEST_P(GraphicsMapperHidlTest, ImportFreeBufferNoLeak) { auto info = mDummyDescriptorInfo; info.width = 1024; info.height = 1024; @@ -245,7 +229,7 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferNoLeak) { /** * Test IMapper::importBuffer with invalid buffers. */ -TEST_F(GraphicsMapperHidlTest, ImportBufferNegative) { +TEST_P(GraphicsMapperHidlTest, ImportBufferNegative) { native_handle_t* invalidHandle = nullptr; mGralloc->getMapper()->importBuffer(invalidHandle, [&](const auto& tmpError, const auto&) { EXPECT_EQ(Error::BAD_BUFFER, tmpError) @@ -263,7 +247,7 @@ TEST_F(GraphicsMapperHidlTest, ImportBufferNegative) { /** * Test IMapper::freeBuffer with invalid buffers. */ -TEST_F(GraphicsMapperHidlTest, FreeBufferNegative) { +TEST_P(GraphicsMapperHidlTest, FreeBufferNegative) { native_handle_t* invalidHandle = nullptr; Error error = mGralloc->getMapper()->freeBuffer(invalidHandle); EXPECT_EQ(Error::BAD_BUFFER, error) << "freeBuffer with nullptr did not fail with BAD_BUFFER"; @@ -286,7 +270,7 @@ TEST_F(GraphicsMapperHidlTest, FreeBufferNegative) { /** * Test IMapper::lock and IMapper::unlock. */ -TEST_F(GraphicsMapperHidlTest, LockUnlockBasic) { +TEST_P(GraphicsMapperHidlTest, LockUnlockBasic) { const auto& info = mDummyDescriptorInfo; const native_handle_t* bufferHandle; @@ -332,7 +316,7 @@ TEST_F(GraphicsMapperHidlTest, LockUnlockBasic) { * Test IMapper::lockYCbCr. This locks a YV12 buffer, and makes sure we can * write to and read from it. */ -TEST_F(GraphicsMapperHidlTest, LockYCbCrBasic) { +TEST_P(GraphicsMapperHidlTest, LockYCbCrBasic) { auto info = mDummyDescriptorInfo; info.format = PixelFormat::YV12; @@ -391,7 +375,7 @@ TEST_F(GraphicsMapperHidlTest, LockYCbCrBasic) { /** * Test IMapper::unlock with invalid buffers. */ -TEST_F(GraphicsMapperHidlTest, UnlockNegative) { +TEST_P(GraphicsMapperHidlTest, UnlockNegative) { native_handle_t* invalidHandle = nullptr; mGralloc->getMapper()->unlock(invalidHandle, [&](const auto& tmpError, const auto&) { EXPECT_EQ(Error::BAD_BUFFER, tmpError) @@ -426,6 +410,14 @@ TEST_F(GraphicsMapperHidlTest, UnlockNegative) { #endif } +INSTANTIATE_TEST_CASE_P( + PerInstance, GraphicsMapperHidlTest, + testing::Combine( + testing::ValuesIn( + android::hardware::getAllHalInstanceNames(IAllocator::descriptor)), + testing::ValuesIn(android::hardware::getAllHalInstanceNames(IMapper::descriptor))), + android::hardware::PrintInstanceTupleNameToString<>); + } // namespace } // namespace vts } // namespace V2_0 @@ -433,13 +425,3 @@ TEST_F(GraphicsMapperHidlTest, UnlockNegative) { } // namespace graphics } // namespace hardware } // namespace android - -int main(int argc, char** argv) { - using android::hardware::graphics::mapper::V2_0::vts::GraphicsMapperHidlEnvironment; - ::testing::AddGlobalTestEnvironment(GraphicsMapperHidlEnvironment::Instance()); - ::testing::InitGoogleTest(&argc, argv); - GraphicsMapperHidlEnvironment::Instance()->init(&argc, argv); - int status = RUN_ALL_TESTS(); - LOG(INFO) << "Test result = " << status; - return status; -} diff --git a/graphics/mapper/2.1/utils/vts/Android.bp b/graphics/mapper/2.1/utils/vts/Android.bp index ca02aadfca..abbe50a64c 100644 --- a/graphics/mapper/2.1/utils/vts/Android.bp +++ b/graphics/mapper/2.1/utils/vts/Android.bp @@ -16,14 +16,13 @@ cc_library_static { name: "android.hardware.graphics.mapper@2.1-vts", - defaults: ["hidl_defaults"], + defaults: ["hidl_defaults", "VtsHalTargetTestDefaults"], srcs: ["MapperVts.cpp"], cflags: [ "-O0", "-g", ], static_libs: [ - "VtsHalHidlTargetTestBase", "android.hardware.graphics.allocator@2.0", "android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@2.0-vts", diff --git a/graphics/mapper/2.1/utils/vts/MapperVts.cpp b/graphics/mapper/2.1/utils/vts/MapperVts.cpp index 36f9cbbeb2..239de740cb 100644 --- a/graphics/mapper/2.1/utils/vts/MapperVts.cpp +++ b/graphics/mapper/2.1/utils/vts/MapperVts.cpp @@ -16,8 +16,6 @@ #include -#include - namespace android { namespace hardware { namespace graphics { diff --git a/graphics/mapper/2.1/vts/functional/Android.bp b/graphics/mapper/2.1/vts/functional/Android.bp index afd8e7f9d3..bb76c7452a 100644 --- a/graphics/mapper/2.1/vts/functional/Android.bp +++ b/graphics/mapper/2.1/vts/functional/Android.bp @@ -26,5 +26,5 @@ cc_test { "android.hardware.graphics.mapper@2.0-vts", "android.hardware.graphics.mapper@2.1-vts", ], - test_suites: ["general-tests"], + test_suites: ["general-tests", "vts-core"], } diff --git a/graphics/mapper/2.1/vts/functional/VtsHalGraphicsMapperV2_1TargetTest.cpp b/graphics/mapper/2.1/vts/functional/VtsHalGraphicsMapperV2_1TargetTest.cpp index 5e7cf93b49..1185945775 100644 --- a/graphics/mapper/2.1/vts/functional/VtsHalGraphicsMapperV2_1TargetTest.cpp +++ b/graphics/mapper/2.1/vts/functional/VtsHalGraphicsMapperV2_1TargetTest.cpp @@ -16,9 +16,11 @@ #define LOG_TAG "VtsHalGraphicsMapperV2_1TargetTest" -#include #include #include +#include +#include +#include #include namespace android { @@ -34,28 +36,12 @@ using android::hardware::graphics::common::V1_1::BufferUsage; using android::hardware::graphics::common::V1_1::PixelFormat; using V2_0::Error; -// 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: +class GraphicsMapperHidlTest + : public ::testing::TestWithParam> { + protected: void SetUp() override { - ASSERT_NO_FATAL_FAILURE( - mGralloc = std::make_unique( - GraphicsMapperHidlEnvironment::Instance()->getServiceName(), - GraphicsMapperHidlEnvironment::Instance()->getServiceName())); + ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique(std::get<0>(GetParam()), + std::get<1>(GetParam()))); mDummyDescriptorInfo.width = 64; mDummyDescriptorInfo.height = 64; @@ -74,7 +60,7 @@ class GraphicsMapperHidlTest : public ::testing::VtsHalHidlTargetTestBase { /** * Test that IMapper::validateBufferSize works. */ -TEST_F(GraphicsMapperHidlTest, ValidateBufferSizeBasic) { +TEST_P(GraphicsMapperHidlTest, ValidateBufferSizeBasic) { const native_handle_t* bufferHandle; uint32_t stride; ASSERT_NO_FATAL_FAILURE(bufferHandle = mGralloc->allocate(mDummyDescriptorInfo, true, &stride)); @@ -87,7 +73,7 @@ TEST_F(GraphicsMapperHidlTest, ValidateBufferSizeBasic) { /** * Test IMapper::validateBufferSize with invalid buffers. */ -TEST_F(GraphicsMapperHidlTest, ValidateBufferSizeBadBuffer) { +TEST_P(GraphicsMapperHidlTest, ValidateBufferSizeBadBuffer) { native_handle_t* invalidHandle = nullptr; Error ret = mGralloc->getMapper()->validateBufferSize(invalidHandle, mDummyDescriptorInfo, mDummyDescriptorInfo.width); @@ -114,7 +100,7 @@ TEST_F(GraphicsMapperHidlTest, ValidateBufferSizeBadBuffer) { /** * Test IMapper::validateBufferSize with invalid descriptor and/or stride. */ -TEST_F(GraphicsMapperHidlTest, ValidateBufferSizeBadValue) { +TEST_P(GraphicsMapperHidlTest, ValidateBufferSizeBadValue) { auto info = mDummyDescriptorInfo; info.width = 1024; info.height = 1024; @@ -161,7 +147,7 @@ TEST_F(GraphicsMapperHidlTest, ValidateBufferSizeBadValue) { /** * Test IMapper::getTransportSize. */ -TEST_F(GraphicsMapperHidlTest, GetTransportSizeBasic) { +TEST_P(GraphicsMapperHidlTest, GetTransportSizeBasic) { const native_handle_t* bufferHandle; uint32_t numFds; uint32_t numInts; @@ -173,7 +159,7 @@ TEST_F(GraphicsMapperHidlTest, GetTransportSizeBasic) { /** * Test IMapper::getTransportSize with invalid buffers. */ -TEST_F(GraphicsMapperHidlTest, GetTransportSizeBadBuffer) { +TEST_P(GraphicsMapperHidlTest, GetTransportSizeBadBuffer) { native_handle_t* invalidHandle = nullptr; mGralloc->getMapper()->getTransportSize( invalidHandle, [&](const auto& tmpError, const auto&, const auto&) { @@ -203,14 +189,14 @@ TEST_F(GraphicsMapperHidlTest, GetTransportSizeBadBuffer) { /** * Test IMapper::createDescriptor with valid descriptor info. */ -TEST_F(GraphicsMapperHidlTest, CreateDescriptor_2_1Basic) { +TEST_P(GraphicsMapperHidlTest, CreateDescriptor_2_1Basic) { ASSERT_NO_FATAL_FAILURE(mGralloc->createDescriptor(mDummyDescriptorInfo)); } /** * Test IMapper::createDescriptor with invalid descriptor info. */ -TEST_F(GraphicsMapperHidlTest, CreateDescriptor_2_1Negative) { +TEST_P(GraphicsMapperHidlTest, CreateDescriptor_2_1Negative) { auto info = mDummyDescriptorInfo; info.width = 0; mGralloc->getMapper()->createDescriptor_2_1(info, [&](const auto& tmpError, const auto&) { @@ -218,22 +204,18 @@ TEST_F(GraphicsMapperHidlTest, CreateDescriptor_2_1Negative) { }); } +INSTANTIATE_TEST_CASE_P( + PerInstance, GraphicsMapperHidlTest, + testing::Combine( + testing::ValuesIn( + android::hardware::getAllHalInstanceNames(IAllocator::descriptor)), + testing::ValuesIn(android::hardware::getAllHalInstanceNames(IMapper::descriptor))), + android::hardware::PrintInstanceTupleNameToString<>); + } // namespace } // namespace vts } // namespace V2_1 } // namespace mapper } // namespace graphics } // namespace hardware -} // namespace android - -int main(int argc, char** argv) { - using android::hardware::graphics::mapper::V2_1::vts::GraphicsMapperHidlEnvironment; - ::testing::AddGlobalTestEnvironment(GraphicsMapperHidlEnvironment::Instance()); - ::testing::InitGoogleTest(&argc, argv); - GraphicsMapperHidlEnvironment::Instance()->init(&argc, argv); - - int status = RUN_ALL_TESTS(); - LOG(INFO) << "Test result = " << status; - - return status; -} +} // namespace android \ No newline at end of file diff --git a/graphics/mapper/3.0/utils/vts/MapperVts.cpp b/graphics/mapper/3.0/utils/vts/MapperVts.cpp index c94e8db065..de886a9c70 100644 --- a/graphics/mapper/3.0/utils/vts/MapperVts.cpp +++ b/graphics/mapper/3.0/utils/vts/MapperVts.cpp @@ -16,8 +16,6 @@ #include -#include - namespace android { namespace hardware { namespace graphics { @@ -35,19 +33,19 @@ Gralloc::Gralloc(const std::string& allocatorServiceName, const std::string& map } void Gralloc::init(const std::string& allocatorServiceName, const std::string& mapperServiceName) { - mAllocator = ::testing::VtsHalHidlTargetTestBase::getService(allocatorServiceName); + mAllocator = IAllocator::getService(allocatorServiceName); ASSERT_NE(nullptr, mAllocator.get()) << "failed to get allocator service"; - mMapper = ::testing::VtsHalHidlTargetTestBase::getService(mapperServiceName); + mMapper = IMapper::getService(mapperServiceName); ASSERT_NE(nullptr, mMapper.get()) << "failed to get mapper service"; ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode"; } void Gralloc::initNoErr(const std::string& allocatorServiceName, const std::string& mapperServiceName) { - mAllocator = ::testing::VtsHalHidlTargetTestBase::getService(allocatorServiceName); + mAllocator = IAllocator::getService(allocatorServiceName); - mMapper = ::testing::VtsHalHidlTargetTestBase::getService(mapperServiceName); + mMapper = IMapper::getService(mapperServiceName); if (mMapper.get()) { ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode"; } diff --git a/graphics/mapper/3.0/utils/vts/include/mapper-vts/3.0/MapperVts.h b/graphics/mapper/3.0/utils/vts/include/mapper-vts/3.0/MapperVts.h index 1141a881e0..b2fbebb12f 100644 --- a/graphics/mapper/3.0/utils/vts/include/mapper-vts/3.0/MapperVts.h +++ b/graphics/mapper/3.0/utils/vts/include/mapper-vts/3.0/MapperVts.h @@ -22,6 +22,7 @@ #include #include +#include #include namespace android { diff --git a/graphics/mapper/3.0/vts/functional/Android.bp b/graphics/mapper/3.0/vts/functional/Android.bp index 77075a5a88..f01670e299 100644 --- a/graphics/mapper/3.0/vts/functional/Android.bp +++ b/graphics/mapper/3.0/vts/functional/Android.bp @@ -26,5 +26,5 @@ cc_test { "android.hardware.graphics.mapper@3.0", "android.hardware.graphics.mapper@3.0-vts", ], - test_suites: ["general-tests"], + test_suites: ["general-tests", "vts-core"], } diff --git a/graphics/mapper/3.0/vts/functional/VtsHalGraphicsMapperV3_0TargetTest.cpp b/graphics/mapper/3.0/vts/functional/VtsHalGraphicsMapperV3_0TargetTest.cpp index ff73ecf769..92b5994eed 100644 --- a/graphics/mapper/3.0/vts/functional/VtsHalGraphicsMapperV3_0TargetTest.cpp +++ b/graphics/mapper/3.0/vts/functional/VtsHalGraphicsMapperV3_0TargetTest.cpp @@ -20,8 +20,10 @@ #include #include -#include #include +#include +#include +#include #include namespace android { @@ -35,28 +37,12 @@ namespace { using android::hardware::graphics::common::V1_2::BufferUsage; using android::hardware::graphics::common::V1_2::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: +class GraphicsMapperHidlTest + : public ::testing::TestWithParam> { + protected: void SetUp() override { - ASSERT_NO_FATAL_FAILURE( - mGralloc = std::make_unique( - GraphicsMapperHidlEnvironment::Instance()->getServiceName(), - GraphicsMapperHidlEnvironment::Instance()->getServiceName())); + ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique(std::get<0>(GetParam()), + std::get<1>(GetParam()))); mDummyDescriptorInfo.width = 64; mDummyDescriptorInfo.height = 64; @@ -75,14 +61,14 @@ class GraphicsMapperHidlTest : public ::testing::VtsHalHidlTargetTestBase { /** * Test IAllocator::dumpDebugInfo by calling it. */ -TEST_F(GraphicsMapperHidlTest, AllocatorDumpDebugInfo) { +TEST_P(GraphicsMapperHidlTest, AllocatorDumpDebugInfo) { mGralloc->dumpDebugInfo(); } /** * Test IAllocator::allocate with valid buffer descriptors. */ -TEST_F(GraphicsMapperHidlTest, AllocatorAllocate) { +TEST_P(GraphicsMapperHidlTest, AllocatorAllocate) { BufferDescriptor descriptor; ASSERT_NO_FATAL_FAILURE(descriptor = mGralloc->createDescriptor(mDummyDescriptorInfo)); @@ -105,7 +91,7 @@ TEST_F(GraphicsMapperHidlTest, AllocatorAllocate) { /** * Test IAllocator::allocate with invalid buffer descriptors. */ -TEST_F(GraphicsMapperHidlTest, AllocatorAllocateNegative) { +TEST_P(GraphicsMapperHidlTest, AllocatorAllocateNegative) { // this assumes any valid descriptor is non-empty BufferDescriptor descriptor; mGralloc->getAllocator()->allocate(descriptor, 1, @@ -117,7 +103,7 @@ TEST_F(GraphicsMapperHidlTest, AllocatorAllocateNegative) { /** * Test IAllocator::allocate does not leak. */ -TEST_F(GraphicsMapperHidlTest, AllocatorAllocateNoLeak) { +TEST_P(GraphicsMapperHidlTest, AllocatorAllocateNoLeak) { auto info = mDummyDescriptorInfo; info.width = 1024; info.height = 1024; @@ -131,7 +117,7 @@ TEST_F(GraphicsMapperHidlTest, AllocatorAllocateNoLeak) { /** * Test that IAllocator::allocate is thread-safe. */ -TEST_F(GraphicsMapperHidlTest, AllocatorAllocateThreaded) { +TEST_P(GraphicsMapperHidlTest, AllocatorAllocateThreaded) { BufferDescriptor descriptor; ASSERT_NO_FATAL_FAILURE(descriptor = mGralloc->createDescriptor(mDummyDescriptorInfo)); @@ -161,14 +147,14 @@ TEST_F(GraphicsMapperHidlTest, AllocatorAllocateThreaded) { /** * Test IMapper::createDescriptor with valid descriptor info. */ -TEST_F(GraphicsMapperHidlTest, CreateDescriptorBasic) { +TEST_P(GraphicsMapperHidlTest, CreateDescriptorBasic) { ASSERT_NO_FATAL_FAILURE(mGralloc->createDescriptor(mDummyDescriptorInfo)); } /** * Test IMapper::createDescriptor with invalid descriptor info. */ -TEST_F(GraphicsMapperHidlTest, CreateDescriptorNegative) { +TEST_P(GraphicsMapperHidlTest, CreateDescriptorNegative) { auto info = mDummyDescriptorInfo; info.width = 0; mGralloc->getMapper()->createDescriptor(info, [&](const auto& tmpError, const auto&) { @@ -179,7 +165,7 @@ TEST_F(GraphicsMapperHidlTest, CreateDescriptorNegative) { /** * Test IMapper::importBuffer and IMapper::freeBuffer with allocated buffers. */ -TEST_F(GraphicsMapperHidlTest, ImportFreeBufferBasic) { +TEST_P(GraphicsMapperHidlTest, ImportFreeBufferBasic) { const native_handle_t* bufferHandle; ASSERT_NO_FATAL_FAILURE(bufferHandle = mGralloc->allocate(mDummyDescriptorInfo, true)); ASSERT_NO_FATAL_FAILURE(mGralloc->freeBuffer(bufferHandle)); @@ -188,7 +174,7 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferBasic) { /** * Test IMapper::importBuffer and IMapper::freeBuffer with cloned buffers. */ -TEST_F(GraphicsMapperHidlTest, ImportFreeBufferClone) { +TEST_P(GraphicsMapperHidlTest, ImportFreeBufferClone) { const native_handle_t* clonedBufferHandle; ASSERT_NO_FATAL_FAILURE(clonedBufferHandle = mGralloc->allocate(mDummyDescriptorInfo, false)); @@ -206,7 +192,7 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferClone) { /** * Test IMapper::importBuffer and IMapper::freeBuffer cross mapper instances. */ -TEST_F(GraphicsMapperHidlTest, ImportFreeBufferSingleton) { +TEST_P(GraphicsMapperHidlTest, ImportFreeBufferSingleton) { const native_handle_t* rawHandle; ASSERT_NO_FATAL_FAILURE(rawHandle = mGralloc->allocate(mDummyDescriptorInfo, false)); @@ -218,10 +204,8 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferSingleton) { // free the imported handle with another mapper std::unique_ptr anotherGralloc; - ASSERT_NO_FATAL_FAILURE( - anotherGralloc = std::make_unique( - GraphicsMapperHidlEnvironment::Instance()->getServiceName(), - GraphicsMapperHidlEnvironment::Instance()->getServiceName())); + ASSERT_NO_FATAL_FAILURE(anotherGralloc = std::make_unique(std::get<0>(GetParam()), + std::get<1>(GetParam()))); Error error = mGralloc->getMapper()->freeBuffer(importedHandle); ASSERT_EQ(Error::NONE, error); @@ -231,7 +215,7 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferSingleton) { /** * Test IMapper::importBuffer and IMapper::freeBuffer do not leak. */ -TEST_F(GraphicsMapperHidlTest, ImportFreeBufferNoLeak) { +TEST_P(GraphicsMapperHidlTest, ImportFreeBufferNoLeak) { auto info = mDummyDescriptorInfo; info.width = 1024; info.height = 1024; @@ -245,7 +229,7 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferNoLeak) { /** * Test IMapper::importBuffer with invalid buffers. */ -TEST_F(GraphicsMapperHidlTest, ImportBufferNegative) { +TEST_P(GraphicsMapperHidlTest, ImportBufferNegative) { native_handle_t* invalidHandle = nullptr; mGralloc->getMapper()->importBuffer(invalidHandle, [&](const auto& tmpError, const auto&) { EXPECT_EQ(Error::BAD_BUFFER, tmpError) @@ -263,7 +247,7 @@ TEST_F(GraphicsMapperHidlTest, ImportBufferNegative) { /** * Test IMapper::freeBuffer with invalid buffers. */ -TEST_F(GraphicsMapperHidlTest, FreeBufferNegative) { +TEST_P(GraphicsMapperHidlTest, FreeBufferNegative) { native_handle_t* invalidHandle = nullptr; Error error = mGralloc->getMapper()->freeBuffer(invalidHandle); EXPECT_EQ(Error::BAD_BUFFER, error) << "freeBuffer with nullptr did not fail with BAD_BUFFER"; @@ -286,7 +270,7 @@ TEST_F(GraphicsMapperHidlTest, FreeBufferNegative) { /** * Test IMapper::lock and IMapper::unlock. */ -TEST_F(GraphicsMapperHidlTest, LockUnlockBasic) { +TEST_P(GraphicsMapperHidlTest, LockUnlockBasic) { const auto& info = mDummyDescriptorInfo; const native_handle_t* bufferHandle; @@ -346,7 +330,7 @@ TEST_F(GraphicsMapperHidlTest, LockUnlockBasic) { * Test IMapper::lockYCbCr. This locks a YV12 buffer, and makes sure we can * write to and read from it. */ -TEST_F(GraphicsMapperHidlTest, LockYCbCrBasic) { +TEST_P(GraphicsMapperHidlTest, LockYCbCrBasic) { auto info = mDummyDescriptorInfo; info.format = PixelFormat::YV12; @@ -405,7 +389,7 @@ TEST_F(GraphicsMapperHidlTest, LockYCbCrBasic) { /** * Test IMapper::unlock with invalid buffers. */ -TEST_F(GraphicsMapperHidlTest, UnlockNegative) { +TEST_P(GraphicsMapperHidlTest, UnlockNegative) { native_handle_t* invalidHandle = nullptr; mGralloc->getMapper()->unlock(invalidHandle, [&](const auto& tmpError, const auto&) { EXPECT_EQ(Error::BAD_BUFFER, tmpError) @@ -443,7 +427,7 @@ TEST_F(GraphicsMapperHidlTest, UnlockNegative) { /** * Test IMapper::isSupported with required format RGBA_8888 */ -TEST_F(GraphicsMapperHidlTest, IsSupportedRGBA8888) { +TEST_P(GraphicsMapperHidlTest, IsSupportedRGBA8888) { const auto& info = mDummyDescriptorInfo; bool supported = false; @@ -454,7 +438,7 @@ TEST_F(GraphicsMapperHidlTest, IsSupportedRGBA8888) { /** * Test IMapper::isSupported with required format YV12 */ -TEST_F(GraphicsMapperHidlTest, IsSupportedYV12) { +TEST_P(GraphicsMapperHidlTest, IsSupportedYV12) { auto info = mDummyDescriptorInfo; info.format = PixelFormat::YV12; bool supported = false; @@ -466,7 +450,7 @@ TEST_F(GraphicsMapperHidlTest, IsSupportedYV12) { /** * Test IMapper::isSupported with optional format Y16 */ -TEST_F(GraphicsMapperHidlTest, IsSupportedY16) { +TEST_P(GraphicsMapperHidlTest, IsSupportedY16) { auto info = mDummyDescriptorInfo; info.format = PixelFormat::Y16; bool supported = false; @@ -474,6 +458,14 @@ TEST_F(GraphicsMapperHidlTest, IsSupportedY16) { ASSERT_NO_FATAL_FAILURE(supported = mGralloc->isSupported(info)); } +INSTANTIATE_TEST_CASE_P( + PerInstance, GraphicsMapperHidlTest, + testing::Combine( + testing::ValuesIn( + android::hardware::getAllHalInstanceNames(IAllocator::descriptor)), + testing::ValuesIn(android::hardware::getAllHalInstanceNames(IMapper::descriptor))), + android::hardware::PrintInstanceTupleNameToString<>); + } // namespace } // namespace vts } // namespace V3_0 @@ -481,13 +473,3 @@ TEST_F(GraphicsMapperHidlTest, IsSupportedY16) { } // namespace graphics } // namespace hardware } // namespace android - -int main(int argc, char** argv) { - using android::hardware::graphics::mapper::V3_0::vts::GraphicsMapperHidlEnvironment; - ::testing::AddGlobalTestEnvironment(GraphicsMapperHidlEnvironment::Instance()); - ::testing::InitGoogleTest(&argc, argv); - GraphicsMapperHidlEnvironment::Instance()->init(&argc, argv); - int status = RUN_ALL_TESTS(); - LOG(INFO) << "Test result = " << status; - return status; -}