Merge "Convert VtsHalGraphicsMapperV*TargetTest to be parameterized test"

This commit is contained in:
Dan Shi 2019-12-10 00:19:36 +00:00 committed by Gerrit Code Review
commit f78d7734d1
12 changed files with 107 additions and 166 deletions

View file

@ -16,8 +16,6 @@
#include <mapper-vts/2.0/MapperVts.h> #include <mapper-vts/2.0/MapperVts.h>
#include <VtsHalHidlTargetTestBase.h>
namespace android { namespace android {
namespace hardware { namespace hardware {
namespace graphics { 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) { void Gralloc::init(const std::string& allocatorServiceName, const std::string& mapperServiceName) {
mAllocator = ::testing::VtsHalHidlTargetTestBase::getService<IAllocator>(allocatorServiceName); mAllocator = IAllocator::getService(allocatorServiceName);
ASSERT_NE(nullptr, mAllocator.get()) << "failed to get allocator service"; ASSERT_NE(nullptr, mAllocator.get()) << "failed to get allocator service";
mMapper = ::testing::VtsHalHidlTargetTestBase::getService<IMapper>(mapperServiceName); mMapper = IMapper::getService(mapperServiceName);
ASSERT_NE(nullptr, mMapper.get()) << "failed to get mapper service"; ASSERT_NE(nullptr, mMapper.get()) << "failed to get mapper service";
ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode"; ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode";
} }

View file

@ -22,6 +22,7 @@
#include <android/hardware/graphics/allocator/2.0/IAllocator.h> #include <android/hardware/graphics/allocator/2.0/IAllocator.h>
#include <android/hardware/graphics/mapper/2.0/IMapper.h> #include <android/hardware/graphics/mapper/2.0/IMapper.h>
#include <gtest/gtest.h>
#include <utils/StrongPointer.h> #include <utils/StrongPointer.h>
namespace android { namespace android {

View file

@ -24,5 +24,5 @@ cc_test {
"android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@2.0",
"android.hardware.graphics.mapper@2.0-vts", "android.hardware.graphics.mapper@2.0-vts",
], ],
test_suites: ["general-tests"], test_suites: ["general-tests", "vts-core"],
} }

View file

@ -20,8 +20,10 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
#include <VtsHalHidlTargetTestBase.h>
#include <android-base/logging.h> #include <android-base/logging.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
#include <mapper-vts/2.0/MapperVts.h> #include <mapper-vts/2.0/MapperVts.h>
namespace android { namespace android {
@ -35,28 +37,12 @@ namespace {
using android::hardware::graphics::common::V1_0::BufferUsage; using android::hardware::graphics::common::V1_0::BufferUsage;
using android::hardware::graphics::common::V1_0::PixelFormat; using android::hardware::graphics::common::V1_0::PixelFormat;
// Test environment for graphics.mapper. class GraphicsMapperHidlTest
class GraphicsMapperHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { : public ::testing::TestWithParam<std::tuple<std::string, std::string>> {
public: protected:
// get the test environment singleton
static GraphicsMapperHidlEnvironment* Instance() {
static GraphicsMapperHidlEnvironment* instance = new GraphicsMapperHidlEnvironment;
return instance;
}
virtual void registerTestServices() override {
registerTestService<IAllocator>();
registerTestService<IMapper>();
}
};
class GraphicsMapperHidlTest : public ::testing::VtsHalHidlTargetTestBase {
protected:
void SetUp() override { void SetUp() override {
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique<Gralloc>(std::get<0>(GetParam()),
mGralloc = std::make_unique<Gralloc>( std::get<1>(GetParam())));
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IAllocator>(),
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IMapper>()));
mDummyDescriptorInfo.width = 64; mDummyDescriptorInfo.width = 64;
mDummyDescriptorInfo.height = 64; mDummyDescriptorInfo.height = 64;
@ -75,14 +61,14 @@ class GraphicsMapperHidlTest : public ::testing::VtsHalHidlTargetTestBase {
/** /**
* Test IAllocator::dumpDebugInfo by calling it. * Test IAllocator::dumpDebugInfo by calling it.
*/ */
TEST_F(GraphicsMapperHidlTest, AllocatorDumpDebugInfo) { TEST_P(GraphicsMapperHidlTest, AllocatorDumpDebugInfo) {
mGralloc->dumpDebugInfo(); mGralloc->dumpDebugInfo();
} }
/** /**
* Test IAllocator::allocate with valid buffer descriptors. * Test IAllocator::allocate with valid buffer descriptors.
*/ */
TEST_F(GraphicsMapperHidlTest, AllocatorAllocate) { TEST_P(GraphicsMapperHidlTest, AllocatorAllocate) {
BufferDescriptor descriptor; BufferDescriptor descriptor;
ASSERT_NO_FATAL_FAILURE(descriptor = mGralloc->createDescriptor(mDummyDescriptorInfo)); ASSERT_NO_FATAL_FAILURE(descriptor = mGralloc->createDescriptor(mDummyDescriptorInfo));
@ -105,7 +91,7 @@ TEST_F(GraphicsMapperHidlTest, AllocatorAllocate) {
/** /**
* Test IAllocator::allocate with invalid buffer descriptors. * Test IAllocator::allocate with invalid buffer descriptors.
*/ */
TEST_F(GraphicsMapperHidlTest, AllocatorAllocateNegative) { TEST_P(GraphicsMapperHidlTest, AllocatorAllocateNegative) {
// this assumes any valid descriptor is non-empty // this assumes any valid descriptor is non-empty
BufferDescriptor descriptor; BufferDescriptor descriptor;
mGralloc->getAllocator()->allocate(descriptor, 1, mGralloc->getAllocator()->allocate(descriptor, 1,
@ -117,7 +103,7 @@ TEST_F(GraphicsMapperHidlTest, AllocatorAllocateNegative) {
/** /**
* Test IAllocator::allocate does not leak. * Test IAllocator::allocate does not leak.
*/ */
TEST_F(GraphicsMapperHidlTest, AllocatorAllocateNoLeak) { TEST_P(GraphicsMapperHidlTest, AllocatorAllocateNoLeak) {
auto info = mDummyDescriptorInfo; auto info = mDummyDescriptorInfo;
info.width = 1024; info.width = 1024;
info.height = 1024; info.height = 1024;
@ -131,7 +117,7 @@ TEST_F(GraphicsMapperHidlTest, AllocatorAllocateNoLeak) {
/** /**
* Test that IAllocator::allocate is thread-safe. * Test that IAllocator::allocate is thread-safe.
*/ */
TEST_F(GraphicsMapperHidlTest, AllocatorAllocateThreaded) { TEST_P(GraphicsMapperHidlTest, AllocatorAllocateThreaded) {
BufferDescriptor descriptor; BufferDescriptor descriptor;
ASSERT_NO_FATAL_FAILURE(descriptor = mGralloc->createDescriptor(mDummyDescriptorInfo)); ASSERT_NO_FATAL_FAILURE(descriptor = mGralloc->createDescriptor(mDummyDescriptorInfo));
@ -161,14 +147,14 @@ TEST_F(GraphicsMapperHidlTest, AllocatorAllocateThreaded) {
/** /**
* Test IMapper::createDescriptor with valid descriptor info. * Test IMapper::createDescriptor with valid descriptor info.
*/ */
TEST_F(GraphicsMapperHidlTest, CreateDescriptorBasic) { TEST_P(GraphicsMapperHidlTest, CreateDescriptorBasic) {
ASSERT_NO_FATAL_FAILURE(mGralloc->createDescriptor(mDummyDescriptorInfo)); ASSERT_NO_FATAL_FAILURE(mGralloc->createDescriptor(mDummyDescriptorInfo));
} }
/** /**
* Test IMapper::createDescriptor with invalid descriptor info. * Test IMapper::createDescriptor with invalid descriptor info.
*/ */
TEST_F(GraphicsMapperHidlTest, CreateDescriptorNegative) { TEST_P(GraphicsMapperHidlTest, CreateDescriptorNegative) {
auto info = mDummyDescriptorInfo; auto info = mDummyDescriptorInfo;
info.width = 0; info.width = 0;
mGralloc->getMapper()->createDescriptor(info, [&](const auto& tmpError, const auto&) { 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 IMapper::importBuffer and IMapper::freeBuffer with allocated buffers.
*/ */
TEST_F(GraphicsMapperHidlTest, ImportFreeBufferBasic) { TEST_P(GraphicsMapperHidlTest, ImportFreeBufferBasic) {
const native_handle_t* bufferHandle; const native_handle_t* bufferHandle;
ASSERT_NO_FATAL_FAILURE(bufferHandle = mGralloc->allocate(mDummyDescriptorInfo, true)); ASSERT_NO_FATAL_FAILURE(bufferHandle = mGralloc->allocate(mDummyDescriptorInfo, true));
ASSERT_NO_FATAL_FAILURE(mGralloc->freeBuffer(bufferHandle)); 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 IMapper::importBuffer and IMapper::freeBuffer with cloned buffers.
*/ */
TEST_F(GraphicsMapperHidlTest, ImportFreeBufferClone) { TEST_P(GraphicsMapperHidlTest, ImportFreeBufferClone) {
const native_handle_t* clonedBufferHandle; const native_handle_t* clonedBufferHandle;
ASSERT_NO_FATAL_FAILURE(clonedBufferHandle = mGralloc->allocate(mDummyDescriptorInfo, false)); 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 IMapper::importBuffer and IMapper::freeBuffer cross mapper instances.
*/ */
TEST_F(GraphicsMapperHidlTest, ImportFreeBufferSingleton) { TEST_P(GraphicsMapperHidlTest, ImportFreeBufferSingleton) {
const native_handle_t* rawHandle; const native_handle_t* rawHandle;
ASSERT_NO_FATAL_FAILURE(rawHandle = mGralloc->allocate(mDummyDescriptorInfo, false)); ASSERT_NO_FATAL_FAILURE(rawHandle = mGralloc->allocate(mDummyDescriptorInfo, false));
@ -218,10 +204,8 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferSingleton) {
// free the imported handle with another mapper // free the imported handle with another mapper
std::unique_ptr<Gralloc> anotherGralloc; std::unique_ptr<Gralloc> anotherGralloc;
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(anotherGralloc = std::make_unique<Gralloc>(std::get<0>(GetParam()),
anotherGralloc = std::make_unique<Gralloc>( std::get<1>(GetParam())));
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IAllocator>(),
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IMapper>()));
Error error = mGralloc->getMapper()->freeBuffer(importedHandle); Error error = mGralloc->getMapper()->freeBuffer(importedHandle);
ASSERT_EQ(Error::NONE, error); ASSERT_EQ(Error::NONE, error);
@ -231,7 +215,7 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferSingleton) {
/** /**
* Test IMapper::importBuffer and IMapper::freeBuffer do not leak. * Test IMapper::importBuffer and IMapper::freeBuffer do not leak.
*/ */
TEST_F(GraphicsMapperHidlTest, ImportFreeBufferNoLeak) { TEST_P(GraphicsMapperHidlTest, ImportFreeBufferNoLeak) {
auto info = mDummyDescriptorInfo; auto info = mDummyDescriptorInfo;
info.width = 1024; info.width = 1024;
info.height = 1024; info.height = 1024;
@ -245,7 +229,7 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferNoLeak) {
/** /**
* Test IMapper::importBuffer with invalid buffers. * Test IMapper::importBuffer with invalid buffers.
*/ */
TEST_F(GraphicsMapperHidlTest, ImportBufferNegative) { TEST_P(GraphicsMapperHidlTest, ImportBufferNegative) {
native_handle_t* invalidHandle = nullptr; native_handle_t* invalidHandle = nullptr;
mGralloc->getMapper()->importBuffer(invalidHandle, [&](const auto& tmpError, const auto&) { mGralloc->getMapper()->importBuffer(invalidHandle, [&](const auto& tmpError, const auto&) {
EXPECT_EQ(Error::BAD_BUFFER, tmpError) EXPECT_EQ(Error::BAD_BUFFER, tmpError)
@ -263,7 +247,7 @@ TEST_F(GraphicsMapperHidlTest, ImportBufferNegative) {
/** /**
* Test IMapper::freeBuffer with invalid buffers. * Test IMapper::freeBuffer with invalid buffers.
*/ */
TEST_F(GraphicsMapperHidlTest, FreeBufferNegative) { TEST_P(GraphicsMapperHidlTest, FreeBufferNegative) {
native_handle_t* invalidHandle = nullptr; native_handle_t* invalidHandle = nullptr;
Error error = mGralloc->getMapper()->freeBuffer(invalidHandle); Error error = mGralloc->getMapper()->freeBuffer(invalidHandle);
EXPECT_EQ(Error::BAD_BUFFER, error) << "freeBuffer with nullptr did not fail with BAD_BUFFER"; 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 IMapper::lock and IMapper::unlock.
*/ */
TEST_F(GraphicsMapperHidlTest, LockUnlockBasic) { TEST_P(GraphicsMapperHidlTest, LockUnlockBasic) {
const auto& info = mDummyDescriptorInfo; const auto& info = mDummyDescriptorInfo;
const native_handle_t* bufferHandle; 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 * Test IMapper::lockYCbCr. This locks a YV12 buffer, and makes sure we can
* write to and read from it. * write to and read from it.
*/ */
TEST_F(GraphicsMapperHidlTest, LockYCbCrBasic) { TEST_P(GraphicsMapperHidlTest, LockYCbCrBasic) {
auto info = mDummyDescriptorInfo; auto info = mDummyDescriptorInfo;
info.format = PixelFormat::YV12; info.format = PixelFormat::YV12;
@ -391,7 +375,7 @@ TEST_F(GraphicsMapperHidlTest, LockYCbCrBasic) {
/** /**
* Test IMapper::unlock with invalid buffers. * Test IMapper::unlock with invalid buffers.
*/ */
TEST_F(GraphicsMapperHidlTest, UnlockNegative) { TEST_P(GraphicsMapperHidlTest, UnlockNegative) {
native_handle_t* invalidHandle = nullptr; native_handle_t* invalidHandle = nullptr;
mGralloc->getMapper()->unlock(invalidHandle, [&](const auto& tmpError, const auto&) { mGralloc->getMapper()->unlock(invalidHandle, [&](const auto& tmpError, const auto&) {
EXPECT_EQ(Error::BAD_BUFFER, tmpError) EXPECT_EQ(Error::BAD_BUFFER, tmpError)
@ -426,6 +410,14 @@ TEST_F(GraphicsMapperHidlTest, UnlockNegative) {
#endif #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
} // namespace vts } // namespace vts
} // namespace V2_0 } // namespace V2_0
@ -433,13 +425,3 @@ TEST_F(GraphicsMapperHidlTest, UnlockNegative) {
} // namespace graphics } // namespace graphics
} // namespace hardware } // namespace hardware
} // namespace android } // 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;
}

View file

@ -16,14 +16,13 @@
cc_library_static { cc_library_static {
name: "android.hardware.graphics.mapper@2.1-vts", name: "android.hardware.graphics.mapper@2.1-vts",
defaults: ["hidl_defaults"], defaults: ["hidl_defaults", "VtsHalTargetTestDefaults"],
srcs: ["MapperVts.cpp"], srcs: ["MapperVts.cpp"],
cflags: [ cflags: [
"-O0", "-O0",
"-g", "-g",
], ],
static_libs: [ static_libs: [
"VtsHalHidlTargetTestBase",
"android.hardware.graphics.allocator@2.0", "android.hardware.graphics.allocator@2.0",
"android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@2.0",
"android.hardware.graphics.mapper@2.0-vts", "android.hardware.graphics.mapper@2.0-vts",

View file

@ -16,8 +16,6 @@
#include <mapper-vts/2.1/MapperVts.h> #include <mapper-vts/2.1/MapperVts.h>
#include <VtsHalHidlTargetTestBase.h>
namespace android { namespace android {
namespace hardware { namespace hardware {
namespace graphics { namespace graphics {

View file

@ -26,5 +26,5 @@ cc_test {
"android.hardware.graphics.mapper@2.0-vts", "android.hardware.graphics.mapper@2.0-vts",
"android.hardware.graphics.mapper@2.1-vts", "android.hardware.graphics.mapper@2.1-vts",
], ],
test_suites: ["general-tests"], test_suites: ["general-tests", "vts-core"],
} }

View file

@ -16,9 +16,11 @@
#define LOG_TAG "VtsHalGraphicsMapperV2_1TargetTest" #define LOG_TAG "VtsHalGraphicsMapperV2_1TargetTest"
#include <VtsHalHidlTargetTestBase.h>
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android/hardware/graphics/mapper/2.1/IMapper.h> #include <android/hardware/graphics/mapper/2.1/IMapper.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
#include <mapper-vts/2.1/MapperVts.h> #include <mapper-vts/2.1/MapperVts.h>
namespace android { namespace android {
@ -34,28 +36,12 @@ using android::hardware::graphics::common::V1_1::BufferUsage;
using android::hardware::graphics::common::V1_1::PixelFormat; using android::hardware::graphics::common::V1_1::PixelFormat;
using V2_0::Error; using V2_0::Error;
// Test environment for graphics.mapper. class GraphicsMapperHidlTest
class GraphicsMapperHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { : public ::testing::TestWithParam<std::tuple<std::string, std::string>> {
public: protected:
// get the test environment singleton
static GraphicsMapperHidlEnvironment* Instance() {
static GraphicsMapperHidlEnvironment* instance = new GraphicsMapperHidlEnvironment;
return instance;
}
virtual void registerTestServices() override {
registerTestService<IAllocator>();
registerTestService<IMapper>();
}
};
class GraphicsMapperHidlTest : public ::testing::VtsHalHidlTargetTestBase {
protected:
void SetUp() override { void SetUp() override {
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique<Gralloc>(std::get<0>(GetParam()),
mGralloc = std::make_unique<Gralloc>( std::get<1>(GetParam())));
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IAllocator>(),
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IMapper>()));
mDummyDescriptorInfo.width = 64; mDummyDescriptorInfo.width = 64;
mDummyDescriptorInfo.height = 64; mDummyDescriptorInfo.height = 64;
@ -74,7 +60,7 @@ class GraphicsMapperHidlTest : public ::testing::VtsHalHidlTargetTestBase {
/** /**
* Test that IMapper::validateBufferSize works. * Test that IMapper::validateBufferSize works.
*/ */
TEST_F(GraphicsMapperHidlTest, ValidateBufferSizeBasic) { TEST_P(GraphicsMapperHidlTest, ValidateBufferSizeBasic) {
const native_handle_t* bufferHandle; const native_handle_t* bufferHandle;
uint32_t stride; uint32_t stride;
ASSERT_NO_FATAL_FAILURE(bufferHandle = mGralloc->allocate(mDummyDescriptorInfo, true, &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 IMapper::validateBufferSize with invalid buffers.
*/ */
TEST_F(GraphicsMapperHidlTest, ValidateBufferSizeBadBuffer) { TEST_P(GraphicsMapperHidlTest, ValidateBufferSizeBadBuffer) {
native_handle_t* invalidHandle = nullptr; native_handle_t* invalidHandle = nullptr;
Error ret = mGralloc->getMapper()->validateBufferSize(invalidHandle, mDummyDescriptorInfo, Error ret = mGralloc->getMapper()->validateBufferSize(invalidHandle, mDummyDescriptorInfo,
mDummyDescriptorInfo.width); mDummyDescriptorInfo.width);
@ -114,7 +100,7 @@ TEST_F(GraphicsMapperHidlTest, ValidateBufferSizeBadBuffer) {
/** /**
* Test IMapper::validateBufferSize with invalid descriptor and/or stride. * Test IMapper::validateBufferSize with invalid descriptor and/or stride.
*/ */
TEST_F(GraphicsMapperHidlTest, ValidateBufferSizeBadValue) { TEST_P(GraphicsMapperHidlTest, ValidateBufferSizeBadValue) {
auto info = mDummyDescriptorInfo; auto info = mDummyDescriptorInfo;
info.width = 1024; info.width = 1024;
info.height = 1024; info.height = 1024;
@ -161,7 +147,7 @@ TEST_F(GraphicsMapperHidlTest, ValidateBufferSizeBadValue) {
/** /**
* Test IMapper::getTransportSize. * Test IMapper::getTransportSize.
*/ */
TEST_F(GraphicsMapperHidlTest, GetTransportSizeBasic) { TEST_P(GraphicsMapperHidlTest, GetTransportSizeBasic) {
const native_handle_t* bufferHandle; const native_handle_t* bufferHandle;
uint32_t numFds; uint32_t numFds;
uint32_t numInts; uint32_t numInts;
@ -173,7 +159,7 @@ TEST_F(GraphicsMapperHidlTest, GetTransportSizeBasic) {
/** /**
* Test IMapper::getTransportSize with invalid buffers. * Test IMapper::getTransportSize with invalid buffers.
*/ */
TEST_F(GraphicsMapperHidlTest, GetTransportSizeBadBuffer) { TEST_P(GraphicsMapperHidlTest, GetTransportSizeBadBuffer) {
native_handle_t* invalidHandle = nullptr; native_handle_t* invalidHandle = nullptr;
mGralloc->getMapper()->getTransportSize( mGralloc->getMapper()->getTransportSize(
invalidHandle, [&](const auto& tmpError, const auto&, const auto&) { invalidHandle, [&](const auto& tmpError, const auto&, const auto&) {
@ -203,14 +189,14 @@ TEST_F(GraphicsMapperHidlTest, GetTransportSizeBadBuffer) {
/** /**
* Test IMapper::createDescriptor with valid descriptor info. * 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)); ASSERT_NO_FATAL_FAILURE(mGralloc->createDescriptor(mDummyDescriptorInfo));
} }
/** /**
* Test IMapper::createDescriptor with invalid descriptor info. * Test IMapper::createDescriptor with invalid descriptor info.
*/ */
TEST_F(GraphicsMapperHidlTest, CreateDescriptor_2_1Negative) { TEST_P(GraphicsMapperHidlTest, CreateDescriptor_2_1Negative) {
auto info = mDummyDescriptorInfo; auto info = mDummyDescriptorInfo;
info.width = 0; info.width = 0;
mGralloc->getMapper()->createDescriptor_2_1(info, [&](const auto& tmpError, const auto&) { 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
} // namespace vts } // namespace vts
} // namespace V2_1 } // namespace V2_1
} // namespace mapper } // namespace mapper
} // namespace graphics } // namespace graphics
} // namespace hardware } // namespace hardware
} // namespace android } // 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;
}

View file

@ -16,8 +16,6 @@
#include <mapper-vts/3.0/MapperVts.h> #include <mapper-vts/3.0/MapperVts.h>
#include <VtsHalHidlTargetTestBase.h>
namespace android { namespace android {
namespace hardware { namespace hardware {
namespace graphics { 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) { void Gralloc::init(const std::string& allocatorServiceName, const std::string& mapperServiceName) {
mAllocator = ::testing::VtsHalHidlTargetTestBase::getService<IAllocator>(allocatorServiceName); mAllocator = IAllocator::getService(allocatorServiceName);
ASSERT_NE(nullptr, mAllocator.get()) << "failed to get allocator service"; ASSERT_NE(nullptr, mAllocator.get()) << "failed to get allocator service";
mMapper = ::testing::VtsHalHidlTargetTestBase::getService<IMapper>(mapperServiceName); mMapper = IMapper::getService(mapperServiceName);
ASSERT_NE(nullptr, mMapper.get()) << "failed to get mapper service"; ASSERT_NE(nullptr, mMapper.get()) << "failed to get mapper service";
ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode"; ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode";
} }
void Gralloc::initNoErr(const std::string& allocatorServiceName, void Gralloc::initNoErr(const std::string& allocatorServiceName,
const std::string& mapperServiceName) { const std::string& mapperServiceName) {
mAllocator = ::testing::VtsHalHidlTargetTestBase::getService<IAllocator>(allocatorServiceName); mAllocator = IAllocator::getService(allocatorServiceName);
mMapper = ::testing::VtsHalHidlTargetTestBase::getService<IMapper>(mapperServiceName); mMapper = IMapper::getService(mapperServiceName);
if (mMapper.get()) { if (mMapper.get()) {
ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode"; ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode";
} }

View file

@ -22,6 +22,7 @@
#include <android/hardware/graphics/allocator/3.0/IAllocator.h> #include <android/hardware/graphics/allocator/3.0/IAllocator.h>
#include <android/hardware/graphics/mapper/3.0/IMapper.h> #include <android/hardware/graphics/mapper/3.0/IMapper.h>
#include <gtest/gtest.h>
#include <utils/StrongPointer.h> #include <utils/StrongPointer.h>
namespace android { namespace android {

View file

@ -26,5 +26,5 @@ cc_test {
"android.hardware.graphics.mapper@3.0", "android.hardware.graphics.mapper@3.0",
"android.hardware.graphics.mapper@3.0-vts", "android.hardware.graphics.mapper@3.0-vts",
], ],
test_suites: ["general-tests"], test_suites: ["general-tests", "vts-core"],
} }

View file

@ -20,8 +20,10 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
#include <VtsHalHidlTargetTestBase.h>
#include <android-base/logging.h> #include <android-base/logging.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
#include <mapper-vts/3.0/MapperVts.h> #include <mapper-vts/3.0/MapperVts.h>
namespace android { namespace android {
@ -35,28 +37,12 @@ namespace {
using android::hardware::graphics::common::V1_2::BufferUsage; using android::hardware::graphics::common::V1_2::BufferUsage;
using android::hardware::graphics::common::V1_2::PixelFormat; using android::hardware::graphics::common::V1_2::PixelFormat;
// Test environment for graphics.mapper. class GraphicsMapperHidlTest
class GraphicsMapperHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { : public ::testing::TestWithParam<std::tuple<std::string, std::string>> {
public: protected:
// get the test environment singleton
static GraphicsMapperHidlEnvironment* Instance() {
static GraphicsMapperHidlEnvironment* instance = new GraphicsMapperHidlEnvironment;
return instance;
}
virtual void registerTestServices() override {
registerTestService<IAllocator>();
registerTestService<IMapper>();
}
};
class GraphicsMapperHidlTest : public ::testing::VtsHalHidlTargetTestBase {
protected:
void SetUp() override { void SetUp() override {
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique<Gralloc>(std::get<0>(GetParam()),
mGralloc = std::make_unique<Gralloc>( std::get<1>(GetParam())));
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IAllocator>(),
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IMapper>()));
mDummyDescriptorInfo.width = 64; mDummyDescriptorInfo.width = 64;
mDummyDescriptorInfo.height = 64; mDummyDescriptorInfo.height = 64;
@ -75,14 +61,14 @@ class GraphicsMapperHidlTest : public ::testing::VtsHalHidlTargetTestBase {
/** /**
* Test IAllocator::dumpDebugInfo by calling it. * Test IAllocator::dumpDebugInfo by calling it.
*/ */
TEST_F(GraphicsMapperHidlTest, AllocatorDumpDebugInfo) { TEST_P(GraphicsMapperHidlTest, AllocatorDumpDebugInfo) {
mGralloc->dumpDebugInfo(); mGralloc->dumpDebugInfo();
} }
/** /**
* Test IAllocator::allocate with valid buffer descriptors. * Test IAllocator::allocate with valid buffer descriptors.
*/ */
TEST_F(GraphicsMapperHidlTest, AllocatorAllocate) { TEST_P(GraphicsMapperHidlTest, AllocatorAllocate) {
BufferDescriptor descriptor; BufferDescriptor descriptor;
ASSERT_NO_FATAL_FAILURE(descriptor = mGralloc->createDescriptor(mDummyDescriptorInfo)); ASSERT_NO_FATAL_FAILURE(descriptor = mGralloc->createDescriptor(mDummyDescriptorInfo));
@ -105,7 +91,7 @@ TEST_F(GraphicsMapperHidlTest, AllocatorAllocate) {
/** /**
* Test IAllocator::allocate with invalid buffer descriptors. * Test IAllocator::allocate with invalid buffer descriptors.
*/ */
TEST_F(GraphicsMapperHidlTest, AllocatorAllocateNegative) { TEST_P(GraphicsMapperHidlTest, AllocatorAllocateNegative) {
// this assumes any valid descriptor is non-empty // this assumes any valid descriptor is non-empty
BufferDescriptor descriptor; BufferDescriptor descriptor;
mGralloc->getAllocator()->allocate(descriptor, 1, mGralloc->getAllocator()->allocate(descriptor, 1,
@ -117,7 +103,7 @@ TEST_F(GraphicsMapperHidlTest, AllocatorAllocateNegative) {
/** /**
* Test IAllocator::allocate does not leak. * Test IAllocator::allocate does not leak.
*/ */
TEST_F(GraphicsMapperHidlTest, AllocatorAllocateNoLeak) { TEST_P(GraphicsMapperHidlTest, AllocatorAllocateNoLeak) {
auto info = mDummyDescriptorInfo; auto info = mDummyDescriptorInfo;
info.width = 1024; info.width = 1024;
info.height = 1024; info.height = 1024;
@ -131,7 +117,7 @@ TEST_F(GraphicsMapperHidlTest, AllocatorAllocateNoLeak) {
/** /**
* Test that IAllocator::allocate is thread-safe. * Test that IAllocator::allocate is thread-safe.
*/ */
TEST_F(GraphicsMapperHidlTest, AllocatorAllocateThreaded) { TEST_P(GraphicsMapperHidlTest, AllocatorAllocateThreaded) {
BufferDescriptor descriptor; BufferDescriptor descriptor;
ASSERT_NO_FATAL_FAILURE(descriptor = mGralloc->createDescriptor(mDummyDescriptorInfo)); ASSERT_NO_FATAL_FAILURE(descriptor = mGralloc->createDescriptor(mDummyDescriptorInfo));
@ -161,14 +147,14 @@ TEST_F(GraphicsMapperHidlTest, AllocatorAllocateThreaded) {
/** /**
* Test IMapper::createDescriptor with valid descriptor info. * Test IMapper::createDescriptor with valid descriptor info.
*/ */
TEST_F(GraphicsMapperHidlTest, CreateDescriptorBasic) { TEST_P(GraphicsMapperHidlTest, CreateDescriptorBasic) {
ASSERT_NO_FATAL_FAILURE(mGralloc->createDescriptor(mDummyDescriptorInfo)); ASSERT_NO_FATAL_FAILURE(mGralloc->createDescriptor(mDummyDescriptorInfo));
} }
/** /**
* Test IMapper::createDescriptor with invalid descriptor info. * Test IMapper::createDescriptor with invalid descriptor info.
*/ */
TEST_F(GraphicsMapperHidlTest, CreateDescriptorNegative) { TEST_P(GraphicsMapperHidlTest, CreateDescriptorNegative) {
auto info = mDummyDescriptorInfo; auto info = mDummyDescriptorInfo;
info.width = 0; info.width = 0;
mGralloc->getMapper()->createDescriptor(info, [&](const auto& tmpError, const auto&) { 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 IMapper::importBuffer and IMapper::freeBuffer with allocated buffers.
*/ */
TEST_F(GraphicsMapperHidlTest, ImportFreeBufferBasic) { TEST_P(GraphicsMapperHidlTest, ImportFreeBufferBasic) {
const native_handle_t* bufferHandle; const native_handle_t* bufferHandle;
ASSERT_NO_FATAL_FAILURE(bufferHandle = mGralloc->allocate(mDummyDescriptorInfo, true)); ASSERT_NO_FATAL_FAILURE(bufferHandle = mGralloc->allocate(mDummyDescriptorInfo, true));
ASSERT_NO_FATAL_FAILURE(mGralloc->freeBuffer(bufferHandle)); 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 IMapper::importBuffer and IMapper::freeBuffer with cloned buffers.
*/ */
TEST_F(GraphicsMapperHidlTest, ImportFreeBufferClone) { TEST_P(GraphicsMapperHidlTest, ImportFreeBufferClone) {
const native_handle_t* clonedBufferHandle; const native_handle_t* clonedBufferHandle;
ASSERT_NO_FATAL_FAILURE(clonedBufferHandle = mGralloc->allocate(mDummyDescriptorInfo, false)); 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 IMapper::importBuffer and IMapper::freeBuffer cross mapper instances.
*/ */
TEST_F(GraphicsMapperHidlTest, ImportFreeBufferSingleton) { TEST_P(GraphicsMapperHidlTest, ImportFreeBufferSingleton) {
const native_handle_t* rawHandle; const native_handle_t* rawHandle;
ASSERT_NO_FATAL_FAILURE(rawHandle = mGralloc->allocate(mDummyDescriptorInfo, false)); ASSERT_NO_FATAL_FAILURE(rawHandle = mGralloc->allocate(mDummyDescriptorInfo, false));
@ -218,10 +204,8 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferSingleton) {
// free the imported handle with another mapper // free the imported handle with another mapper
std::unique_ptr<Gralloc> anotherGralloc; std::unique_ptr<Gralloc> anotherGralloc;
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(anotherGralloc = std::make_unique<Gralloc>(std::get<0>(GetParam()),
anotherGralloc = std::make_unique<Gralloc>( std::get<1>(GetParam())));
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IAllocator>(),
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IMapper>()));
Error error = mGralloc->getMapper()->freeBuffer(importedHandle); Error error = mGralloc->getMapper()->freeBuffer(importedHandle);
ASSERT_EQ(Error::NONE, error); ASSERT_EQ(Error::NONE, error);
@ -231,7 +215,7 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferSingleton) {
/** /**
* Test IMapper::importBuffer and IMapper::freeBuffer do not leak. * Test IMapper::importBuffer and IMapper::freeBuffer do not leak.
*/ */
TEST_F(GraphicsMapperHidlTest, ImportFreeBufferNoLeak) { TEST_P(GraphicsMapperHidlTest, ImportFreeBufferNoLeak) {
auto info = mDummyDescriptorInfo; auto info = mDummyDescriptorInfo;
info.width = 1024; info.width = 1024;
info.height = 1024; info.height = 1024;
@ -245,7 +229,7 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferNoLeak) {
/** /**
* Test IMapper::importBuffer with invalid buffers. * Test IMapper::importBuffer with invalid buffers.
*/ */
TEST_F(GraphicsMapperHidlTest, ImportBufferNegative) { TEST_P(GraphicsMapperHidlTest, ImportBufferNegative) {
native_handle_t* invalidHandle = nullptr; native_handle_t* invalidHandle = nullptr;
mGralloc->getMapper()->importBuffer(invalidHandle, [&](const auto& tmpError, const auto&) { mGralloc->getMapper()->importBuffer(invalidHandle, [&](const auto& tmpError, const auto&) {
EXPECT_EQ(Error::BAD_BUFFER, tmpError) EXPECT_EQ(Error::BAD_BUFFER, tmpError)
@ -263,7 +247,7 @@ TEST_F(GraphicsMapperHidlTest, ImportBufferNegative) {
/** /**
* Test IMapper::freeBuffer with invalid buffers. * Test IMapper::freeBuffer with invalid buffers.
*/ */
TEST_F(GraphicsMapperHidlTest, FreeBufferNegative) { TEST_P(GraphicsMapperHidlTest, FreeBufferNegative) {
native_handle_t* invalidHandle = nullptr; native_handle_t* invalidHandle = nullptr;
Error error = mGralloc->getMapper()->freeBuffer(invalidHandle); Error error = mGralloc->getMapper()->freeBuffer(invalidHandle);
EXPECT_EQ(Error::BAD_BUFFER, error) << "freeBuffer with nullptr did not fail with BAD_BUFFER"; 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 IMapper::lock and IMapper::unlock.
*/ */
TEST_F(GraphicsMapperHidlTest, LockUnlockBasic) { TEST_P(GraphicsMapperHidlTest, LockUnlockBasic) {
const auto& info = mDummyDescriptorInfo; const auto& info = mDummyDescriptorInfo;
const native_handle_t* bufferHandle; 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 * Test IMapper::lockYCbCr. This locks a YV12 buffer, and makes sure we can
* write to and read from it. * write to and read from it.
*/ */
TEST_F(GraphicsMapperHidlTest, LockYCbCrBasic) { TEST_P(GraphicsMapperHidlTest, LockYCbCrBasic) {
auto info = mDummyDescriptorInfo; auto info = mDummyDescriptorInfo;
info.format = PixelFormat::YV12; info.format = PixelFormat::YV12;
@ -405,7 +389,7 @@ TEST_F(GraphicsMapperHidlTest, LockYCbCrBasic) {
/** /**
* Test IMapper::unlock with invalid buffers. * Test IMapper::unlock with invalid buffers.
*/ */
TEST_F(GraphicsMapperHidlTest, UnlockNegative) { TEST_P(GraphicsMapperHidlTest, UnlockNegative) {
native_handle_t* invalidHandle = nullptr; native_handle_t* invalidHandle = nullptr;
mGralloc->getMapper()->unlock(invalidHandle, [&](const auto& tmpError, const auto&) { mGralloc->getMapper()->unlock(invalidHandle, [&](const auto& tmpError, const auto&) {
EXPECT_EQ(Error::BAD_BUFFER, tmpError) EXPECT_EQ(Error::BAD_BUFFER, tmpError)
@ -443,7 +427,7 @@ TEST_F(GraphicsMapperHidlTest, UnlockNegative) {
/** /**
* Test IMapper::isSupported with required format RGBA_8888 * Test IMapper::isSupported with required format RGBA_8888
*/ */
TEST_F(GraphicsMapperHidlTest, IsSupportedRGBA8888) { TEST_P(GraphicsMapperHidlTest, IsSupportedRGBA8888) {
const auto& info = mDummyDescriptorInfo; const auto& info = mDummyDescriptorInfo;
bool supported = false; bool supported = false;
@ -454,7 +438,7 @@ TEST_F(GraphicsMapperHidlTest, IsSupportedRGBA8888) {
/** /**
* Test IMapper::isSupported with required format YV12 * Test IMapper::isSupported with required format YV12
*/ */
TEST_F(GraphicsMapperHidlTest, IsSupportedYV12) { TEST_P(GraphicsMapperHidlTest, IsSupportedYV12) {
auto info = mDummyDescriptorInfo; auto info = mDummyDescriptorInfo;
info.format = PixelFormat::YV12; info.format = PixelFormat::YV12;
bool supported = false; bool supported = false;
@ -466,7 +450,7 @@ TEST_F(GraphicsMapperHidlTest, IsSupportedYV12) {
/** /**
* Test IMapper::isSupported with optional format Y16 * Test IMapper::isSupported with optional format Y16
*/ */
TEST_F(GraphicsMapperHidlTest, IsSupportedY16) { TEST_P(GraphicsMapperHidlTest, IsSupportedY16) {
auto info = mDummyDescriptorInfo; auto info = mDummyDescriptorInfo;
info.format = PixelFormat::Y16; info.format = PixelFormat::Y16;
bool supported = false; bool supported = false;
@ -474,6 +458,14 @@ TEST_F(GraphicsMapperHidlTest, IsSupportedY16) {
ASSERT_NO_FATAL_FAILURE(supported = mGralloc->isSupported(info)); 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
} // namespace vts } // namespace vts
} // namespace V3_0 } // namespace V3_0
@ -481,13 +473,3 @@ TEST_F(GraphicsMapperHidlTest, IsSupportedY16) {
} // namespace graphics } // namespace graphics
} // namespace hardware } // namespace hardware
} // namespace android } // 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;
}