From f6820b2b44e9fcc025f8d98790a01484a5ab8faa Mon Sep 17 00:00:00 2001 From: Ady Abraham Date: Fri, 7 Feb 2020 17:39:56 -0800 Subject: [PATCH] composer: add TestCommandReader to 2.4 Add a TestCommandReader to composer 2.4 VTS to parse correctly the new commands introduced in 2.4. Test: adb shell /data/nativetest64/VtsHalGraphicsComposerV2_4TargetTest/VtsHalGraphicsComposerV2_4TargetTest Bug: 149124892 Change-Id: Ide4f98fa3bfc771e4095cc672f59b87e1aa03427 --- .../2.1/utils/vts/TestCommandReader.cpp | 103 +++++++++--------- .../composer-vts/2.1/TestCommandReader.h | 14 ++- graphics/composer/2.4/utils/vts/Android.bp | 2 + .../composer/2.4/utils/vts/ComposerVts.cpp | 32 ++++++ .../2.4/utils/vts/TestCommandReader.cpp | 38 +++++++ .../include/composer-vts/2.4/ComposerVts.h | 3 + .../composer-vts/2.4/TestCommandReader.h | 32 ++++++ .../VtsHalGraphicsComposerV2_4TargetTest.cpp | 10 +- 8 files changed, 175 insertions(+), 59 deletions(-) create mode 100644 graphics/composer/2.4/utils/vts/TestCommandReader.cpp create mode 100644 graphics/composer/2.4/utils/vts/include/composer-vts/2.4/TestCommandReader.h diff --git a/graphics/composer/2.1/utils/vts/TestCommandReader.cpp b/graphics/composer/2.1/utils/vts/TestCommandReader.cpp index 454a89ccdc..0506f3ad88 100644 --- a/graphics/composer/2.1/utils/vts/TestCommandReader.cpp +++ b/graphics/composer/2.1/utils/vts/TestCommandReader.cpp @@ -29,63 +29,68 @@ void TestCommandReader::parse() { mErrors.clear(); mCompositionChanges.clear(); while (!isEmpty()) { - IComposerClient::Command command; + int32_t command; uint16_t length; ASSERT_TRUE(beginCommand(&command, &length)); - switch (command) { - case IComposerClient::Command::SELECT_DISPLAY: - ASSERT_EQ(2, length); - read64(); // display - break; - case IComposerClient::Command::SET_ERROR: { - ASSERT_EQ(2, length); - auto loc = read(); - auto err = readSigned(); - std::pair error(loc, err); - mErrors.push_back(error); - } break; - case IComposerClient::Command::SET_CHANGED_COMPOSITION_TYPES: - ASSERT_EQ(0, length % 3); - for (uint16_t count = 0; count < length / 3; ++count) { - uint64_t layerId = read64(); - uint32_t composition = read(); - - std::pair compositionChange(layerId, composition); - mCompositionChanges.push_back(compositionChange); - } - break; - case IComposerClient::Command::SET_DISPLAY_REQUESTS: - ASSERT_EQ(1, length % 3); - read(); // displayRequests, ignored for now - for (uint16_t count = 0; count < (length - 1) / 3; ++count) { - read64(); // layer - // silently eat requests to clear the client target, since we won't be testing - // client composition anyway - ASSERT_EQ(1u, read()); - } - break; - case IComposerClient::Command::SET_PRESENT_FENCE: - ASSERT_EQ(1, length); - close(readFence()); - break; - case IComposerClient::Command::SET_RELEASE_FENCES: - ASSERT_EQ(0, length % 3); - for (uint16_t count = 0; count < length / 3; ++count) { - read64(); - close(readFence()); - } - break; - default: - GTEST_FAIL() << "unexpected return command " << std::hex - << static_cast(command); - break; - } + parseSingleCommand(command, length); endCommand(); } } +void TestCommandReader::parseSingleCommand(int32_t commandRaw, uint16_t length) { + IComposerClient::Command command = static_cast(commandRaw); + + switch (command) { + case IComposerClient::Command::SELECT_DISPLAY: + ASSERT_EQ(2, length); + read64(); // display + break; + case IComposerClient::Command::SET_ERROR: { + ASSERT_EQ(2, length); + auto loc = read(); + auto err = readSigned(); + std::pair error(loc, err); + mErrors.push_back(error); + } break; + case IComposerClient::Command::SET_CHANGED_COMPOSITION_TYPES: + ASSERT_EQ(0, length % 3); + for (uint16_t count = 0; count < length / 3; ++count) { + uint64_t layerId = read64(); + uint32_t composition = read(); + + std::pair compositionChange(layerId, composition); + mCompositionChanges.push_back(compositionChange); + } + break; + case IComposerClient::Command::SET_DISPLAY_REQUESTS: + ASSERT_EQ(1, length % 3); + read(); // displayRequests, ignored for now + for (uint16_t count = 0; count < (length - 1) / 3; ++count) { + read64(); // layer + // silently eat requests to clear the client target, since we won't be testing + // client composition anyway + ASSERT_EQ(1u, read()); + } + break; + case IComposerClient::Command::SET_PRESENT_FENCE: + ASSERT_EQ(1, length); + close(readFence()); + break; + case IComposerClient::Command::SET_RELEASE_FENCES: + ASSERT_EQ(0, length % 3); + for (uint16_t count = 0; count < length / 3; ++count) { + read64(); + close(readFence()); + } + break; + default: + GTEST_FAIL() << "unexpected return command " << std::hex << static_cast(command); + break; + } +} + } // namespace vts } // namespace V2_1 } // namespace composer diff --git a/graphics/composer/2.1/utils/vts/include/composer-vts/2.1/TestCommandReader.h b/graphics/composer/2.1/utils/vts/include/composer-vts/2.1/TestCommandReader.h index c12debe066..40d347afc3 100644 --- a/graphics/composer/2.1/utils/vts/include/composer-vts/2.1/TestCommandReader.h +++ b/graphics/composer/2.1/utils/vts/include/composer-vts/2.1/TestCommandReader.h @@ -29,12 +29,16 @@ namespace vts { // returned. class TestCommandReader : public CommandReaderBase { public: - // Parse all commands in the return command queue. Call GTEST_FAIL() for - // unexpected errors or commands. - void parse(); + virtual ~TestCommandReader() = default; + // Parse all commands in the return command queue. Call GTEST_FAIL() for + // unexpected errors or commands. + void parse(); - std::vector> mErrors; - std::vector> mCompositionChanges; + std::vector> mErrors; + std::vector> mCompositionChanges; + + protected: + virtual void parseSingleCommand(int32_t commandRaw, uint16_t length); }; } // namespace vts diff --git a/graphics/composer/2.4/utils/vts/Android.bp b/graphics/composer/2.4/utils/vts/Android.bp index e42223d6eb..fc13c2a79c 100644 --- a/graphics/composer/2.4/utils/vts/Android.bp +++ b/graphics/composer/2.4/utils/vts/Android.bp @@ -20,6 +20,7 @@ cc_library_static { srcs: [ "ComposerVts.cpp", "GraphicsComposerCallback.cpp", + "TestCommandReader.cpp", ], static_libs: [ "android.hardware.graphics.composer@2.1", @@ -33,6 +34,7 @@ cc_library_static { "android.hardware.graphics.composer@2.1-command-buffer", "android.hardware.graphics.composer@2.2-command-buffer", "android.hardware.graphics.composer@2.3-command-buffer", + "android.hardware.graphics.composer@2.4-command-buffer", ], cflags: [ "-O0", diff --git a/graphics/composer/2.4/utils/vts/ComposerVts.cpp b/graphics/composer/2.4/utils/vts/ComposerVts.cpp index c5f3b5ed2f..b3f3374dae 100644 --- a/graphics/composer/2.4/utils/vts/ComposerVts.cpp +++ b/graphics/composer/2.4/utils/vts/ComposerVts.cpp @@ -132,6 +132,38 @@ Error ComposerClient::getLayerGenericMetadataKeys( return error; } +void ComposerClient::execute(TestCommandReader* reader, CommandWriterBase* writer) { + bool queueChanged = false; + uint32_t commandLength = 0; + hidl_vec commandHandles; + ASSERT_TRUE(writer->writeQueue(&queueChanged, &commandLength, &commandHandles)); + + if (queueChanged) { + auto ret = mClient->setInputCommandQueue(*writer->getMQDescriptor()); + ASSERT_EQ(V2_1::Error::NONE, ret); + } + + mClient->executeCommands_2_3( + commandLength, commandHandles, + [&](const auto& tmpError, const auto& tmpOutQueueChanged, const auto& tmpOutLength, + const auto& tmpOutHandles) { + ASSERT_EQ(V2_1::Error::NONE, tmpError); + + if (tmpOutQueueChanged) { + mClient->getOutputCommandQueue( + [&](const auto& tmpError, const auto& tmpDescriptor) { + ASSERT_EQ(V2_3::Error::NONE, tmpError); + reader->setMQDescriptor(tmpDescriptor); + }); + } + + ASSERT_TRUE(reader->readQueue(tmpOutLength, tmpOutHandles)); + reader->parse(); + }); + reader->reset(); + writer->reset(); +} + } // namespace vts } // namespace V2_4 } // namespace composer diff --git a/graphics/composer/2.4/utils/vts/TestCommandReader.cpp b/graphics/composer/2.4/utils/vts/TestCommandReader.cpp new file mode 100644 index 0000000000..a1ca62878a --- /dev/null +++ b/graphics/composer/2.4/utils/vts/TestCommandReader.cpp @@ -0,0 +1,38 @@ +/* + * Copyright 2020 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::hardware::graphics::composer::V2_4::vts { + +void TestCommandReader::parseSingleCommand(int32_t commandRaw, uint16_t length) { + IComposerClient::Command command = static_cast(commandRaw); + + switch (command) { + case IComposerClient::Command::SET_CLIENT_TARGET_PROPERTY: + ASSERT_EQ(2, length); + read(); + close(readFence()); + break; + default: + return android::hardware::graphics::composer::V2_1::vts::TestCommandReader:: + parseSingleCommand(commandRaw, length); + } +} + +} // namespace android::hardware::graphics::composer::V2_4::vts diff --git a/graphics/composer/2.4/utils/vts/include/composer-vts/2.4/ComposerVts.h b/graphics/composer/2.4/utils/vts/include/composer-vts/2.4/ComposerVts.h index fd59eb93cd..28e17b410d 100644 --- a/graphics/composer/2.4/utils/vts/include/composer-vts/2.4/ComposerVts.h +++ b/graphics/composer/2.4/utils/vts/include/composer-vts/2.4/ComposerVts.h @@ -22,6 +22,7 @@ #include #include #include +#include #include namespace android { @@ -92,6 +93,8 @@ class ComposerClient : public V2_3::vts::ComposerClient { Error setContentType(Display display, IComposerClient::ContentType contentType); + void execute(TestCommandReader* reader, CommandWriterBase* writer); + Error getLayerGenericMetadataKeys( std::vector* outKeys); diff --git a/graphics/composer/2.4/utils/vts/include/composer-vts/2.4/TestCommandReader.h b/graphics/composer/2.4/utils/vts/include/composer-vts/2.4/TestCommandReader.h new file mode 100644 index 0000000000..5736fa675a --- /dev/null +++ b/graphics/composer/2.4/utils/vts/include/composer-vts/2.4/TestCommandReader.h @@ -0,0 +1,32 @@ +/* + * Copyright 2020 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::hardware::graphics::composer::V2_4::vts { + +// A command parser that checks that no error nor unexpected commands are +// returned. +class TestCommandReader + : public android::hardware::graphics::composer::V2_1::vts::TestCommandReader { + protected: + void parseSingleCommand(int32_t commandRaw, uint16_t length) override; +}; + +} // namespace android::hardware::graphics::composer::V2_4::vts diff --git a/graphics/composer/2.4/vts/functional/VtsHalGraphicsComposerV2_4TargetTest.cpp b/graphics/composer/2.4/vts/functional/VtsHalGraphicsComposerV2_4TargetTest.cpp index a7c3fd7b0c..b6343d335a 100644 --- a/graphics/composer/2.4/vts/functional/VtsHalGraphicsComposerV2_4TargetTest.cpp +++ b/graphics/composer/2.4/vts/functional/VtsHalGraphicsComposerV2_4TargetTest.cpp @@ -23,9 +23,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -77,7 +77,7 @@ class GraphicsComposerHidlTest : public ::testing::TestWithParam { mComposerCallback->setVsyncAllowed(false); mWriter = std::make_unique(1024); - mReader = std::make_unique(); + mReader = std::make_unique(); } void TearDown() override { @@ -153,7 +153,7 @@ class GraphicsComposerHidlTest : public ::testing::TestWithParam { Display mPrimaryDisplay; Display mInvalidDisplayId; std::unique_ptr mWriter; - std::unique_ptr mReader; + std::unique_ptr mReader; private: Display waitForFirstDisplay() { @@ -184,7 +184,7 @@ class GraphicsComposerHidlCommandTest : public GraphicsComposerHidlTest { mPrimaryDisplay, activeConfig, IComposerClient::Attribute::HEIGHT); mWriter = std::make_unique(1024); - mReader = std::make_unique(); + mReader = std::make_unique(); } void TearDown() override { @@ -211,7 +211,7 @@ class GraphicsComposerHidlCommandTest : public GraphicsComposerHidlTest { int64_t newPeriodNanos); std::unique_ptr mWriter; - std::unique_ptr mReader; + std::unique_ptr mReader; int32_t mDisplayWidth; int32_t mDisplayHeight;