Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <array> |
| 18 | #include <gtest/gtest.h> |
| 19 | #include <dlfcn.h> |
| 20 | #include <hardware/hardware.h> |
| 21 | |
| 22 | #define HWC2_INCLUDE_STRINGIFICATION |
| 23 | #define HWC2_USE_CPP11 |
| 24 | #include <hardware/hwcomposer2.h> |
| 25 | #undef HWC2_INCLUDE_STRINGIFICATION |
| 26 | #undef HWC2_USE_CPP11 |
| 27 | |
| 28 | class Hwc2Test : public testing::Test { |
| 29 | public: |
| 30 | |
| 31 | virtual void SetUp() |
| 32 | { |
| 33 | hw_module_t const* hwc2Module; |
| 34 | |
| 35 | int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &hwc2Module); |
| 36 | ASSERT_GE(err, 0) << "failed to get hwc hardware module: " |
| 37 | << strerror(-err); |
| 38 | |
| 39 | /* The following method will fail if you have not run |
| 40 | * "adb shell stop" */ |
| 41 | err = hwc2_open(hwc2Module, &mHwc2Device); |
| 42 | ASSERT_GE(err, 0) << "failed to open hwc hardware module: " |
| 43 | << strerror(-err); |
| 44 | } |
| 45 | |
| 46 | virtual void TearDown() |
| 47 | { |
| 48 | if (mHwc2Device) |
| 49 | hwc2_close(mHwc2Device); |
| 50 | } |
| 51 | |
| 52 | protected: |
| 53 | hwc2_function_pointer_t getFunction(hwc2_function_descriptor_t descriptor) |
| 54 | { |
| 55 | return mHwc2Device->getFunction(mHwc2Device, descriptor); |
| 56 | } |
| 57 | |
| 58 | void getCapabilities(std::vector<hwc2_capability_t>* outCapabilities) |
| 59 | { |
| 60 | uint32_t num = 0; |
| 61 | |
| 62 | mHwc2Device->getCapabilities(mHwc2Device, &num, nullptr); |
| 63 | |
| 64 | outCapabilities->resize(num); |
| 65 | |
| 66 | mHwc2Device->getCapabilities(mHwc2Device, &num, |
| 67 | reinterpret_cast<int32_t*>(outCapabilities->data())); |
| 68 | } |
| 69 | |
| 70 | hwc2_device_t* mHwc2Device = nullptr; |
| 71 | }; |
| 72 | |
| 73 | |
| 74 | static const std::array<hwc2_function_descriptor_t, 42> requiredFunctions = {{ |
| 75 | HWC2_FUNCTION_ACCEPT_DISPLAY_CHANGES, |
| 76 | HWC2_FUNCTION_CREATE_LAYER, |
| 77 | HWC2_FUNCTION_CREATE_VIRTUAL_DISPLAY, |
| 78 | HWC2_FUNCTION_DESTROY_LAYER, |
| 79 | HWC2_FUNCTION_DESTROY_VIRTUAL_DISPLAY, |
| 80 | HWC2_FUNCTION_DUMP, |
| 81 | HWC2_FUNCTION_GET_ACTIVE_CONFIG, |
| 82 | HWC2_FUNCTION_GET_CHANGED_COMPOSITION_TYPES, |
| 83 | HWC2_FUNCTION_GET_CLIENT_TARGET_SUPPORT, |
| 84 | HWC2_FUNCTION_GET_COLOR_MODES, |
| 85 | HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE, |
| 86 | HWC2_FUNCTION_GET_DISPLAY_CONFIGS, |
| 87 | HWC2_FUNCTION_GET_DISPLAY_NAME, |
| 88 | HWC2_FUNCTION_GET_DISPLAY_REQUESTS, |
| 89 | HWC2_FUNCTION_GET_DISPLAY_TYPE, |
| 90 | HWC2_FUNCTION_GET_DOZE_SUPPORT, |
| 91 | HWC2_FUNCTION_GET_HDR_CAPABILITIES, |
| 92 | HWC2_FUNCTION_GET_MAX_VIRTUAL_DISPLAY_COUNT, |
| 93 | HWC2_FUNCTION_GET_RELEASE_FENCES, |
| 94 | HWC2_FUNCTION_PRESENT_DISPLAY, |
| 95 | HWC2_FUNCTION_REGISTER_CALLBACK, |
| 96 | HWC2_FUNCTION_SET_ACTIVE_CONFIG, |
| 97 | HWC2_FUNCTION_SET_CLIENT_TARGET, |
| 98 | HWC2_FUNCTION_SET_COLOR_MODE, |
| 99 | HWC2_FUNCTION_SET_COLOR_TRANSFORM, |
| 100 | HWC2_FUNCTION_SET_CURSOR_POSITION, |
| 101 | HWC2_FUNCTION_SET_LAYER_BLEND_MODE, |
| 102 | HWC2_FUNCTION_SET_LAYER_BUFFER, |
| 103 | HWC2_FUNCTION_SET_LAYER_COLOR, |
| 104 | HWC2_FUNCTION_SET_LAYER_COMPOSITION_TYPE, |
| 105 | HWC2_FUNCTION_SET_LAYER_DATASPACE, |
| 106 | HWC2_FUNCTION_SET_LAYER_DISPLAY_FRAME, |
| 107 | HWC2_FUNCTION_SET_LAYER_PLANE_ALPHA, |
| 108 | HWC2_FUNCTION_SET_LAYER_SOURCE_CROP, |
| 109 | HWC2_FUNCTION_SET_LAYER_SURFACE_DAMAGE, |
| 110 | HWC2_FUNCTION_SET_LAYER_TRANSFORM, |
| 111 | HWC2_FUNCTION_SET_LAYER_VISIBLE_REGION, |
| 112 | HWC2_FUNCTION_SET_LAYER_Z_ORDER, |
| 113 | HWC2_FUNCTION_SET_OUTPUT_BUFFER, |
| 114 | HWC2_FUNCTION_SET_POWER_MODE, |
| 115 | HWC2_FUNCTION_SET_VSYNC_ENABLED, |
| 116 | HWC2_FUNCTION_VALIDATE_DISPLAY, |
| 117 | }}; |
| 118 | |
| 119 | /* TESTCASE: Tests that the HWC2 supports all required functions. */ |
| 120 | TEST_F(Hwc2Test, GET_FUNCTION) |
| 121 | { |
| 122 | for (hwc2_function_descriptor_t descriptor : requiredFunctions) { |
| 123 | hwc2_function_pointer_t pfn = getFunction(descriptor); |
| 124 | EXPECT_TRUE(pfn) << "failed to get function " |
| 125 | << getFunctionDescriptorName(descriptor); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | /* TESTCASE: Tests that the HWC2 fails to retrieve and invalid function. */ |
| 130 | TEST_F(Hwc2Test, GET_FUNCTION_invalid_function) |
| 131 | { |
| 132 | hwc2_function_pointer_t pfn = getFunction(HWC2_FUNCTION_INVALID); |
| 133 | EXPECT_FALSE(pfn) << "failed to get invalid function"; |
| 134 | } |
| 135 | |
| 136 | /* TESTCASE: Tests that the HWC2 does not return an invalid capability. */ |
| 137 | TEST_F(Hwc2Test, GET_CAPABILITIES) |
| 138 | { |
| 139 | std::vector<hwc2_capability_t> capabilities; |
| 140 | |
| 141 | getCapabilities(&capabilities); |
| 142 | |
| 143 | EXPECT_EQ(std::count(capabilities.begin(), capabilities.end(), |
| 144 | HWC2_CAPABILITY_INVALID), 0); |
| 145 | } |