graphics: make mapper VTS utils more reusable

Better include path (#include <mapper-vts/2.0/MapperVts.h>), better
library naming, and move GraphicsMapperHidlEnvironment to where
tests are defined.

Test: VTS
Change-Id: I9fbf6515993ac11852b11ca6b8194a58afe5579a
This commit is contained in:
Chia-I Wu
2018-01-14 21:45:18 -08:00
parent 7d510c91f0
commit 98923fccad
11 changed files with 87 additions and 75 deletions

View File

@@ -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: [

View File

@@ -17,10 +17,10 @@
#define LOG_TAG "graphics_composer_hidl_hal_test"
#include <android-base/logging.h>
#include <mapper-vts/2.0/MapperVts.h>
#include "GraphicsComposerCallback.h"
#include "TestCommandReader.h"
#include "VtsHalGraphicsComposerTestUtils.h"
#include "VtsHalGraphicsMapperTestUtils.h"
#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
@@ -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

View File

@@ -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: [

View File

@@ -18,12 +18,12 @@
#include <android-base/logging.h>
#include <android/hardware/graphics/mapper/2.1/IMapper.h>
#include <mapper-vts/2.0/MapperVts.h>
#include <sync/sync.h>
#include "2.2/VtsHalGraphicsComposerTestUtils.h"
#include "GraphicsComposerCallback.h"
#include "TestCommandReader.h"
#include "VtsHalGraphicsComposerTestUtils.h"
#include "VtsHalGraphicsMapperTestUtils.h"
#include <VtsHalHidlTargetTestBase.h>
@@ -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

View File

@@ -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"],
}

View File

@@ -14,28 +14,26 @@
* limitations under the License.
*/
#include <VtsHalHidlTargetTestBase.h>
#include <mapper-vts/2.0/MapperVts.h>
#include "VtsHalGraphicsMapperTestUtils.h"
#include <VtsHalHidlTargetTestBase.h>
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<IAllocator>(
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IAllocator>());
void Gralloc::init(const std::string& allocatorServiceName, const std::string& mapperServiceName) {
mAllocator = ::testing::VtsHalHidlTargetTestBase::getService<IAllocator>(allocatorServiceName);
ASSERT_NE(nullptr, mAllocator.get()) << "failed to get allocator service";
mMapper = ::testing::VtsHalHidlTargetTestBase::getService<IMapper>(
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IMapper>());
mMapper = ::testing::VtsHalHidlTargetTestBase::getService<IMapper>(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

View File

@@ -14,12 +14,12 @@
* limitations under the License.
*/
#ifndef VTS_HAL_GRAPHICS_MAPPER_UTILS
#define VTS_HAL_GRAPHICS_MAPPER_UTILS
#pragma once
#include <string>
#include <unordered_set>
#include <vector>
#include <VtsHalHidlTargetTestEnvBase.h>
#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
#include <android/hardware/graphics/mapper/2.0/IMapper.h>
#include <utils/StrongPointer.h>
@@ -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<IAllocator> mAllocator;
@@ -85,26 +86,9 @@ class Gralloc {
std::unordered_set<const native_handle_t*> 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<IAllocator>();
registerTestService<IMapper>();
}
};
} // namespace tests
} // namespace vts
} // namespace V2_0
} // namespace mapper
} // namespace graphics
} // namespace hardware
} // namespace android
#endif // VTS_HAL_GRAPHICS_MAPPER_UTILS

View File

@@ -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",
],
}

View File

@@ -18,24 +18,41 @@
#include <VtsHalHidlTargetTestBase.h>
#include <android-base/logging.h>
#include <sync/sync.h>
#include "VtsHalGraphicsMapperTestUtils.h"
#include <mapper-vts/2.0/MapperVts.h>
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<IAllocator>();
registerTestService<IMapper>();
}
};
class GraphicsMapperHidlTest : public ::testing::VtsHalHidlTargetTestBase {
protected:
void SetUp() override {
ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique<Gralloc>());
ASSERT_NO_FATAL_FAILURE(
mGralloc = std::make_unique<Gralloc>(
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IAllocator>(),
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IMapper>()));
mDummyDescriptorInfo.width = 64;
mDummyDescriptorInfo.height = 64;
@@ -167,7 +184,10 @@ TEST_F(GraphicsMapperHidlTest, ImportFreeBufferSingleton) {
// free the imported handle with another mapper
std::unique_ptr<Gralloc> anotherGralloc;
ASSERT_NO_FATAL_FAILURE(anotherGralloc = std::make_unique<Gralloc>());
ASSERT_NO_FATAL_FAILURE(
anotherGralloc = std::make_unique<Gralloc>(
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IAllocator>(),
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IMapper>()));
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);

View File

@@ -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",
],
}

View File

@@ -19,22 +19,21 @@
#include <VtsHalHidlTargetTestBase.h>
#include <android-base/logging.h>
#include <android/hardware/graphics/mapper/2.1/IMapper.h>
#include <sync/sync.h>
#include "VtsHalGraphicsMapperTestUtils.h"
#include <mapper-vts/2.0/MapperVts.h>
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<IAllocator>();
registerTestService<IMapper>();
}
};
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<Gralloc>());
ASSERT_NO_FATAL_FAILURE(
mGralloc = std::make_unique<Gralloc>(
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IAllocator>(),
GraphicsMapperHidlEnvironment::Instance()->getServiceName<IMapper>()));
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);