diff --git a/graphics/mapper/2.1/utils/OWNERS b/graphics/mapper/2.1/utils/OWNERS new file mode 100644 index 0000000000..3aa5fa1ffd --- /dev/null +++ b/graphics/mapper/2.1/utils/OWNERS @@ -0,0 +1,4 @@ +# Graphics team +jessehall@google.com +olv@google.com +stoza@google.com diff --git a/graphics/mapper/2.1/utils/vts/Android.bp b/graphics/mapper/2.1/utils/vts/Android.bp new file mode 100644 index 0000000000..ca02aadfca --- /dev/null +++ b/graphics/mapper/2.1/utils/vts/Android.bp @@ -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"], +} diff --git a/graphics/mapper/2.1/utils/vts/MapperVts.cpp b/graphics/mapper/2.1/utils/vts/MapperVts.cpp new file mode 100644 index 0000000000..0aaa926018 --- /dev/null +++ b/graphics/mapper/2.1/utils/vts/MapperVts.cpp @@ -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 + +#include + +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 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(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(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 diff --git a/graphics/mapper/2.1/utils/vts/include/mapper-vts/2.1/MapperVts.h b/graphics/mapper/2.1/utils/vts/include/mapper-vts/2.1/MapperVts.h new file mode 100644 index 0000000000..b7fa751936 --- /dev/null +++ b/graphics/mapper/2.1/utils/vts/include/mapper-vts/2.1/MapperVts.h @@ -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 +#include + +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 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 mMapperV2_1; +}; + +} // namespace vts +} // namespace V2_1 +} // namespace mapper +} // namespace graphics +} // namespace hardware +} // namespace android diff --git a/graphics/mapper/2.1/vts/functional/Android.bp b/graphics/mapper/2.1/vts/functional/Android.bp index 74d6fa8d1e..ac67af8538 100644 --- a/graphics/mapper/2.1/vts/functional/Android.bp +++ b/graphics/mapper/2.1/vts/functional/Android.bp @@ -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", ], } diff --git a/graphics/mapper/2.1/vts/functional/VtsHalGraphicsMapperV2_1TargetTest.cpp b/graphics/mapper/2.1/vts/functional/VtsHalGraphicsMapperV2_1TargetTest.cpp index 803c3265f2..5e7cf93b49 100644 --- a/graphics/mapper/2.1/vts/functional/VtsHalGraphicsMapperV2_1TargetTest.cpp +++ b/graphics/mapper/2.1/vts/functional/VtsHalGraphicsMapperV2_1TargetTest.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include 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 getMapper() const { return mMapper; } - - bool validateBufferSize(const native_handle_t* bufferHandle, - const IMapper::BufferDescriptorInfo& descriptorInfo, uint32_t stride) { - auto buffer = const_cast(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(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 mMapper; -}; - class GraphicsMapperHidlTest : public ::testing::VtsHalHidlTargetTestBase { protected: void SetUp() override {