mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 11:36:00 +00:00
graphics: make mapper 2.1 VTS utils more reusable
Move V2_1::vts::Gralloc to android.hardware.graphics.mapper@2.1-vts. Test: VTS Change-Id: Iecb7fc3cb90b886ad2d9c23a5cab8aef2da6367f
This commit is contained in:
4
graphics/mapper/2.1/utils/OWNERS
Normal file
4
graphics/mapper/2.1/utils/OWNERS
Normal file
@@ -0,0 +1,4 @@
|
||||
# Graphics team
|
||||
jessehall@google.com
|
||||
olv@google.com
|
||||
stoza@google.com
|
||||
39
graphics/mapper/2.1/utils/vts/Android.bp
Normal file
39
graphics/mapper/2.1/utils/vts/Android.bp
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// Copyright (C) 2016 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
cc_library_static {
|
||||
name: "android.hardware.graphics.mapper@2.1-vts",
|
||||
defaults: ["hidl_defaults"],
|
||||
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",
|
||||
"android.hardware.graphics.mapper@2.1",
|
||||
],
|
||||
export_static_lib_headers: [
|
||||
"android.hardware.graphics.allocator@2.0",
|
||||
"android.hardware.graphics.mapper@2.0",
|
||||
"android.hardware.graphics.mapper@2.0-vts",
|
||||
"android.hardware.graphics.mapper@2.1",
|
||||
],
|
||||
export_include_dirs: ["include"],
|
||||
}
|
||||
120
graphics/mapper/2.1/utils/vts/MapperVts.cpp
Normal file
120
graphics/mapper/2.1/utils/vts/MapperVts.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <mapper-vts/2.1/MapperVts.h>
|
||||
|
||||
#include <VtsHalHidlTargetTestBase.h>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace graphics {
|
||||
namespace mapper {
|
||||
namespace V2_1 {
|
||||
namespace vts {
|
||||
|
||||
using V2_0::Error;
|
||||
|
||||
// abuse VTS to check binary compatibility between BufferDescriptorInfos
|
||||
using OldBufferDescriptorInfo =
|
||||
android::hardware::graphics::mapper::V2_0::IMapper::BufferDescriptorInfo;
|
||||
static_assert(sizeof(OldBufferDescriptorInfo) == sizeof(IMapper::BufferDescriptorInfo) &&
|
||||
offsetof(OldBufferDescriptorInfo, width) ==
|
||||
offsetof(IMapper::BufferDescriptorInfo, width) &&
|
||||
offsetof(OldBufferDescriptorInfo, height) ==
|
||||
offsetof(IMapper::BufferDescriptorInfo, height) &&
|
||||
offsetof(OldBufferDescriptorInfo, layerCount) ==
|
||||
offsetof(IMapper::BufferDescriptorInfo, layerCount) &&
|
||||
offsetof(OldBufferDescriptorInfo, format) ==
|
||||
offsetof(IMapper::BufferDescriptorInfo, format) &&
|
||||
offsetof(OldBufferDescriptorInfo, usage) ==
|
||||
offsetof(IMapper::BufferDescriptorInfo, usage),
|
||||
"");
|
||||
|
||||
Gralloc::Gralloc(const std::string& allocatorServiceName, const std::string& mapperServiceName)
|
||||
: V2_0::vts::Gralloc(allocatorServiceName, mapperServiceName) {
|
||||
if (::testing::Test::HasFatalFailure()) {
|
||||
return;
|
||||
}
|
||||
init();
|
||||
}
|
||||
|
||||
void Gralloc::init() {
|
||||
mMapperV2_1 = IMapper::castFrom(V2_0::vts::Gralloc::getMapper());
|
||||
ASSERT_NE(nullptr, mMapperV2_1.get()) << "failed to get mapper 2.1 service";
|
||||
}
|
||||
|
||||
sp<IMapper> Gralloc::getMapper() const {
|
||||
return mMapperV2_1;
|
||||
}
|
||||
|
||||
bool Gralloc::validateBufferSize(const native_handle_t* bufferHandle,
|
||||
const IMapper::BufferDescriptorInfo& descriptorInfo,
|
||||
uint32_t stride) {
|
||||
auto buffer = const_cast<native_handle_t*>(bufferHandle);
|
||||
|
||||
Error error = mMapperV2_1->validateBufferSize(buffer, descriptorInfo, stride);
|
||||
return error == Error::NONE;
|
||||
}
|
||||
|
||||
void Gralloc::getTransportSize(const native_handle_t* bufferHandle, uint32_t* outNumFds,
|
||||
uint32_t* outNumInts) {
|
||||
auto buffer = const_cast<native_handle_t*>(bufferHandle);
|
||||
|
||||
*outNumFds = 0;
|
||||
*outNumInts = 0;
|
||||
mMapperV2_1->getTransportSize(
|
||||
buffer, [&](const auto& tmpError, const auto& tmpNumFds, const auto& tmpNumInts) {
|
||||
ASSERT_EQ(Error::NONE, tmpError) << "failed to get transport size";
|
||||
ASSERT_GE(bufferHandle->numFds, int(tmpNumFds)) << "invalid numFds " << tmpNumFds;
|
||||
ASSERT_GE(bufferHandle->numInts, int(tmpNumInts)) << "invalid numInts " << tmpNumInts;
|
||||
|
||||
*outNumFds = tmpNumFds;
|
||||
*outNumInts = tmpNumInts;
|
||||
});
|
||||
}
|
||||
|
||||
BufferDescriptor Gralloc::createDescriptor(const IMapper::BufferDescriptorInfo& descriptorInfo) {
|
||||
BufferDescriptor descriptor;
|
||||
mMapperV2_1->createDescriptor_2_1(
|
||||
descriptorInfo, [&](const auto& tmpError, const auto& tmpDescriptor) {
|
||||
ASSERT_EQ(Error::NONE, tmpError) << "failed to create descriptor";
|
||||
descriptor = tmpDescriptor;
|
||||
});
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
const native_handle_t* Gralloc::allocate(const IMapper::BufferDescriptorInfo& descriptorInfo,
|
||||
bool import, uint32_t* outStride) {
|
||||
BufferDescriptor descriptor = createDescriptor(descriptorInfo);
|
||||
if (::testing::Test::HasFatalFailure()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto buffers = V2_0::vts::Gralloc::allocate(descriptor, 1, import, outStride);
|
||||
if (::testing::Test::HasFatalFailure()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return buffers[0];
|
||||
}
|
||||
|
||||
} // namespace vts
|
||||
} // namespace V2_1
|
||||
} // namespace mapper
|
||||
} // namespace graphics
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <android/hardware/graphics/mapper/2.1/IMapper.h>
|
||||
#include <mapper-vts/2.0/MapperVts.h>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace graphics {
|
||||
namespace mapper {
|
||||
namespace V2_1 {
|
||||
namespace vts {
|
||||
|
||||
using android::hardware::graphics::allocator::V2_0::IAllocator;
|
||||
using V2_0::BufferDescriptor;
|
||||
|
||||
// A wrapper to IAllocator and IMapper.
|
||||
class Gralloc : public V2_0::vts::Gralloc {
|
||||
public:
|
||||
Gralloc(const std::string& allocatorServiceName, const std::string& mapperServiceName);
|
||||
|
||||
sp<IMapper> getMapper() const;
|
||||
|
||||
bool validateBufferSize(const native_handle_t* bufferHandle,
|
||||
const IMapper::BufferDescriptorInfo& descriptorInfo, uint32_t stride);
|
||||
void getTransportSize(const native_handle_t* bufferHandle, uint32_t* outNumFds,
|
||||
uint32_t* outNumInts);
|
||||
|
||||
BufferDescriptor createDescriptor(const IMapper::BufferDescriptorInfo& descriptorInfo);
|
||||
|
||||
const native_handle_t* allocate(const IMapper::BufferDescriptorInfo& descriptorInfo,
|
||||
bool import = true, uint32_t* outStride = nullptr);
|
||||
|
||||
protected:
|
||||
void init();
|
||||
|
||||
sp<IMapper> mMapperV2_1;
|
||||
};
|
||||
|
||||
} // namespace vts
|
||||
} // namespace V2_1
|
||||
} // namespace mapper
|
||||
} // namespace graphics
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
@@ -24,5 +24,6 @@ cc_test {
|
||||
"android.hardware.graphics.mapper@2.0",
|
||||
"android.hardware.graphics.mapper@2.1",
|
||||
"android.hardware.graphics.mapper@2.0-vts",
|
||||
"android.hardware.graphics.mapper@2.1-vts",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <VtsHalHidlTargetTestBase.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <android/hardware/graphics/mapper/2.1/IMapper.h>
|
||||
#include <mapper-vts/2.0/MapperVts.h>
|
||||
#include <mapper-vts/2.1/MapperVts.h>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
@@ -32,25 +32,8 @@ namespace {
|
||||
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 =
|
||||
android::hardware::graphics::mapper::V2_0::IMapper::BufferDescriptorInfo;
|
||||
static_assert(sizeof(OldBufferDescriptorInfo) == sizeof(IMapper::BufferDescriptorInfo) &&
|
||||
offsetof(OldBufferDescriptorInfo, width) ==
|
||||
offsetof(IMapper::BufferDescriptorInfo, width) &&
|
||||
offsetof(OldBufferDescriptorInfo, height) ==
|
||||
offsetof(IMapper::BufferDescriptorInfo, height) &&
|
||||
offsetof(OldBufferDescriptorInfo, layerCount) ==
|
||||
offsetof(IMapper::BufferDescriptorInfo, layerCount) &&
|
||||
offsetof(OldBufferDescriptorInfo, format) ==
|
||||
offsetof(IMapper::BufferDescriptorInfo, format) &&
|
||||
offsetof(OldBufferDescriptorInfo, usage) ==
|
||||
offsetof(IMapper::BufferDescriptorInfo, usage),
|
||||
"");
|
||||
|
||||
// Test environment for graphics.mapper.
|
||||
class GraphicsMapperHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
|
||||
public:
|
||||
@@ -66,79 +49,6 @@ class GraphicsMapperHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvB
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
sp<IMapper> getMapper() const { return mMapper; }
|
||||
|
||||
bool validateBufferSize(const native_handle_t* bufferHandle,
|
||||
const IMapper::BufferDescriptorInfo& descriptorInfo, uint32_t stride) {
|
||||
auto buffer = const_cast<native_handle_t*>(bufferHandle);
|
||||
|
||||
Error error = mMapper->validateBufferSize(buffer, descriptorInfo, stride);
|
||||
return error == Error::NONE;
|
||||
}
|
||||
|
||||
void getTransportSize(const native_handle_t* bufferHandle, uint32_t* numFds,
|
||||
uint32_t* numInts) {
|
||||
auto buffer = const_cast<native_handle_t*>(bufferHandle);
|
||||
|
||||
*numFds = 0;
|
||||
*numInts = 0;
|
||||
mMapper->getTransportSize(buffer, [&](const auto& tmpError, const auto& tmpNumFds,
|
||||
const auto& tmpNumInts) {
|
||||
ASSERT_EQ(Error::NONE, tmpError) << "failed to get transport size";
|
||||
ASSERT_GE(bufferHandle->numFds, int(tmpNumFds)) << "invalid numFds " << tmpNumFds;
|
||||
ASSERT_GE(bufferHandle->numInts, int(tmpNumInts)) << "invalid numInts " << tmpNumInts;
|
||||
|
||||
*numFds = tmpNumFds;
|
||||
*numInts = tmpNumInts;
|
||||
});
|
||||
}
|
||||
|
||||
BufferDescriptor createDescriptor(const IMapper::BufferDescriptorInfo& descriptorInfo) {
|
||||
BufferDescriptor descriptor;
|
||||
mMapper->createDescriptor_2_1(
|
||||
descriptorInfo, [&](const auto& tmpError, const auto& tmpDescriptor) {
|
||||
ASSERT_EQ(Error::NONE, tmpError) << "failed to create descriptor";
|
||||
descriptor = tmpDescriptor;
|
||||
});
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
const native_handle_t* allocate(const IMapper::BufferDescriptorInfo& descriptorInfo,
|
||||
bool import, uint32_t* outStride = nullptr) {
|
||||
BufferDescriptor descriptor = createDescriptor(descriptorInfo);
|
||||
if (::testing::Test::HasFatalFailure()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto buffers = V2_0::vts::Gralloc::allocate(descriptor, 1, import, outStride);
|
||||
if (::testing::Test::HasFatalFailure()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return buffers[0];
|
||||
}
|
||||
|
||||
private:
|
||||
void init() {
|
||||
mMapper = IMapper::castFrom(V2_0::vts::Gralloc::getMapper());
|
||||
ASSERT_NE(nullptr, mMapper.get()) << "failed to find IMapper 2.1";
|
||||
}
|
||||
|
||||
sp<IMapper> mMapper;
|
||||
};
|
||||
|
||||
class GraphicsMapperHidlTest : public ::testing::VtsHalHidlTargetTestBase {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
|
||||
Reference in New Issue
Block a user