Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a9780260 authored by ramindani's avatar ramindani
Browse files

Add two tests for Stable AIDL composer3 as a start of tests.

If service exists then we can proceed with test otherwise we skip tests

This should help us write all the tests until we have the service implementation.

Test: atest VtsHalGraphicsComposer3_TargetTest Tests don't just work yet, we don't have service implemented yet.
BUG: 202053621
Change-Id: Ia9506dada0f1b5da446d6e2086aa4534c60d5565
parent 9119a2b9
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -4,6 +4,3 @@
adyabr@google.com
alecmouri@google.com
ramindani@google.com

# VTS team
include platform/hardware/interfaces:/OWNERS
 No newline at end of file
+67 −3
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
#include <aidl/Vintf.h>
#include <aidl/android/hardware/graphics/composer3/IComposer.h>
#include <android-base/properties.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <binder/ProcessState.h>
#include <gtest/gtest.h>
#include <string>
@@ -11,15 +13,77 @@
#undef LOG_TAG
#define LOG_TAG "VtsHalGraphicsComposer3_TargetTest"

typedef uint64_t DisplayId;

namespace aidl::android::hardware::graphics::composer3::vts {
namespace {

class VtsDisplay {
  public:
    VtsDisplay(DisplayId displayId, int32_t displayWidth, int32_t displayHeight)
        : mDisplayId(displayId), mDisplayWidth(displayWidth), mDisplayHeight(displayHeight) {}

    DisplayId get() const { return mDisplayId; }

    void setDimensions(int32_t displayWidth, int32_t displayHeight) {
        mDisplayWidth = displayWidth;
        mDisplayHeight = displayHeight;
    }

  private:
    const DisplayId mDisplayId;
    int32_t mDisplayWidth;
    int32_t mDisplayHeight;
};

class GraphicsComposerAidlTest : public ::testing::TestWithParam<std::string> {
    // TODO(b/201796346) setup composer client and use it to send data and generate commands.
  protected:
    void SetUp() override {
        std::string name = GetParam();
        ndk::SpAIBinder binder(AServiceManager_waitForService(name.c_str()));
        ASSERT_NE(binder, nullptr);
        ASSERT_NO_FATAL_FAILURE(mComposer = IComposer::fromBinder(binder));
        ASSERT_NE(mComposer, nullptr);
        ASSERT_NO_FATAL_FAILURE(mComposer->createClient(&mComposerClient));
        mInvalidDisplayId = GetInvalidDisplayId();
    }

    // returns an invalid display id (one that has not been registered to a
    // display.  Currently assuming that a device will never have close to
    // std::numeric_limit<uint64_t>::max() displays registered while running tests
    DisplayId GetInvalidDisplayId() {
        uint64_t id = std::numeric_limits<uint64_t>::max();
        while (id > 0) {
            if (std::none_of(mDisplays.begin(), mDisplays.end(),
                             [&](const VtsDisplay& display) { return id == display.get(); })) {
                return id;
            }
            id--;
        }

        return 0;
    }

    std::shared_ptr<IComposer> mComposer;
    std::shared_ptr<IComposerClient> mComposerClient{};
    DisplayId mInvalidDisplayId;
    std::vector<VtsDisplay>
            mDisplays;  // TODO(b/202401906) populate all the displays available for test.
};

TEST_P(GraphicsComposerAidlTest, getDisplayCapabilitiesBadDisplay) {
    // TODO(b/201797681) update with actual test instead of a place holder
    std::vector<DisplayCapability> capabilities;
    const auto error = mComposerClient->getDisplayCapabilities(mInvalidDisplayId, &capabilities);
    EXPECT_EQ(IComposerClient::EX_BAD_DISPLAY, error.getServiceSpecificError());
}

TEST_P(GraphicsComposerAidlTest, getDisplayCapabilities) {
    for (const auto& display : mDisplays) {
        std::vector<DisplayCapability> capabilities;
        const auto error = mComposerClient->getDisplayCapabilities(display.get(), &capabilities);

        EXPECT_NE(IComposerClient::EX_BAD_DISPLAY, error.getServiceSpecificError());
    }
}

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsComposerAidlTest);