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> |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 18 | #include <unordered_set> |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 19 | #include <gtest/gtest.h> |
| 20 | #include <dlfcn.h> |
| 21 | #include <hardware/hardware.h> |
| 22 | |
| 23 | #define HWC2_INCLUDE_STRINGIFICATION |
| 24 | #define HWC2_USE_CPP11 |
| 25 | #include <hardware/hwcomposer2.h> |
| 26 | #undef HWC2_INCLUDE_STRINGIFICATION |
| 27 | #undef HWC2_USE_CPP11 |
| 28 | |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 29 | void hwc2TestHotplugCallback(hwc2_callback_data_t callbackData, |
| 30 | hwc2_display_t display, int32_t connected); |
| 31 | |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 32 | class Hwc2Test : public testing::Test { |
| 33 | public: |
| 34 | |
| 35 | virtual void SetUp() |
| 36 | { |
| 37 | hw_module_t const* hwc2Module; |
| 38 | |
| 39 | int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &hwc2Module); |
| 40 | ASSERT_GE(err, 0) << "failed to get hwc hardware module: " |
| 41 | << strerror(-err); |
| 42 | |
| 43 | /* The following method will fail if you have not run |
| 44 | * "adb shell stop" */ |
| 45 | err = hwc2_open(hwc2Module, &mHwc2Device); |
| 46 | ASSERT_GE(err, 0) << "failed to open hwc hardware module: " |
| 47 | << strerror(-err); |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 48 | |
| 49 | populateDisplays(); |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | virtual void TearDown() |
| 53 | { |
Marissa Wall | 1db2e37 | 2016-12-15 12:19:39 -0800 | [diff] [blame] | 54 | |
| 55 | for (auto itr = mLayers.begin(); itr != mLayers.end();) { |
| 56 | hwc2_display_t display = itr->first; |
| 57 | hwc2_layer_t layer = itr->second; |
| 58 | itr++; |
| 59 | /* Destroys and removes the layer from mLayers */ |
| 60 | destroyLayer(display, layer); |
| 61 | } |
| 62 | |
Marissa Wall | 03c9173 | 2016-12-15 12:23:16 -0800 | [diff] [blame^] | 63 | for (auto itr = mActiveDisplays.begin(); itr != mActiveDisplays.end();) { |
| 64 | hwc2_display_t display = *itr; |
| 65 | itr++; |
| 66 | /* Sets power mode to off and removes the display from |
| 67 | * mActiveDisplays */ |
| 68 | setPowerMode(display, HWC2_POWER_MODE_OFF); |
| 69 | } |
| 70 | |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 71 | if (mHwc2Device) |
| 72 | hwc2_close(mHwc2Device); |
| 73 | } |
| 74 | |
Marissa Wall | a4b0148 | 2017-02-17 20:52:03 -0800 | [diff] [blame] | 75 | void registerCallback(hwc2_callback_descriptor_t descriptor, |
| 76 | hwc2_callback_data_t callbackData, hwc2_function_pointer_t pointer, |
| 77 | hwc2_error_t* outErr = nullptr) |
| 78 | { |
| 79 | auto pfn = reinterpret_cast<HWC2_PFN_REGISTER_CALLBACK>( |
| 80 | getFunction(HWC2_FUNCTION_REGISTER_CALLBACK)); |
| 81 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 82 | |
| 83 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, descriptor, |
| 84 | callbackData, pointer)); |
| 85 | if (outErr) { |
| 86 | *outErr = err; |
| 87 | } else { |
| 88 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to register callback"; |
| 89 | } |
| 90 | } |
| 91 | |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 92 | void getDisplayType(hwc2_display_t display, hwc2_display_type_t* outType, |
| 93 | hwc2_error_t* outErr = nullptr) |
| 94 | { |
| 95 | auto pfn = reinterpret_cast<HWC2_PFN_GET_DISPLAY_TYPE>( |
| 96 | getFunction(HWC2_FUNCTION_GET_DISPLAY_TYPE)); |
| 97 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 98 | |
| 99 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, |
| 100 | reinterpret_cast<int32_t*>(outType))); |
| 101 | if (outErr) { |
| 102 | *outErr = err; |
| 103 | } else { |
| 104 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to get display type"; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /* If the populateDisplays function is still receiving displays and the |
| 109 | * display is connected, the display handle is stored in mDisplays. */ |
| 110 | void hotplugCallback(hwc2_display_t display, int32_t connected) |
| 111 | { |
| 112 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 113 | |
| 114 | if (mHotplugStatus != Hwc2TestHotplugStatus::Receiving) |
| 115 | return; |
| 116 | |
| 117 | if (connected == HWC2_CONNECTION_CONNECTED) |
| 118 | mDisplays.insert(display); |
| 119 | |
| 120 | mHotplugCv.notify_all(); |
| 121 | } |
| 122 | |
Marissa Wall | 1db2e37 | 2016-12-15 12:19:39 -0800 | [diff] [blame] | 123 | void createLayer(hwc2_display_t display, hwc2_layer_t* outLayer, |
| 124 | hwc2_error_t* outErr = nullptr) |
| 125 | { |
| 126 | auto pfn = reinterpret_cast<HWC2_PFN_CREATE_LAYER>( |
| 127 | getFunction(HWC2_FUNCTION_CREATE_LAYER)); |
| 128 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 129 | |
| 130 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, |
| 131 | outLayer)); |
| 132 | |
| 133 | if (err == HWC2_ERROR_NONE) |
| 134 | mLayers.insert(std::make_pair(display, *outLayer)); |
| 135 | |
| 136 | if (outErr) { |
| 137 | *outErr = err; |
| 138 | } else { |
| 139 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to create layer"; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | void destroyLayer(hwc2_display_t display, hwc2_layer_t layer, |
| 144 | hwc2_error_t* outErr = nullptr) |
| 145 | { |
| 146 | auto pfn = reinterpret_cast<HWC2_PFN_DESTROY_LAYER>( |
| 147 | getFunction(HWC2_FUNCTION_DESTROY_LAYER)); |
| 148 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 149 | |
| 150 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, layer)); |
| 151 | |
| 152 | if (err == HWC2_ERROR_NONE) |
| 153 | mLayers.erase(std::make_pair(display, layer)); |
| 154 | |
| 155 | if (outErr) { |
| 156 | *outErr = err; |
| 157 | } else { |
| 158 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to destroy layer " |
| 159 | << layer; |
| 160 | } |
| 161 | } |
| 162 | |
Marissa Wall | cf935cb | 2016-12-15 12:20:47 -0800 | [diff] [blame] | 163 | void getDisplayAttribute(hwc2_display_t display, hwc2_config_t config, |
| 164 | hwc2_attribute_t attribute, int32_t* outValue, |
| 165 | hwc2_error_t* outErr = nullptr) |
| 166 | { |
| 167 | auto pfn = reinterpret_cast<HWC2_PFN_GET_DISPLAY_ATTRIBUTE>( |
| 168 | getFunction(HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE)); |
| 169 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 170 | |
| 171 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, config, |
| 172 | attribute, outValue)); |
| 173 | |
| 174 | if (outErr) { |
| 175 | *outErr = err; |
| 176 | } else { |
| 177 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to get display attribute " |
| 178 | << getAttributeName(attribute) << " for config " << config; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | void getDisplayConfigs(hwc2_display_t display, |
| 183 | std::vector<hwc2_config_t>* outConfigs, |
| 184 | hwc2_error_t* outErr = nullptr) |
| 185 | { |
| 186 | auto pfn = reinterpret_cast<HWC2_PFN_GET_DISPLAY_CONFIGS>( |
| 187 | getFunction(HWC2_FUNCTION_GET_DISPLAY_CONFIGS)); |
| 188 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 189 | |
| 190 | uint32_t numConfigs = 0; |
| 191 | |
| 192 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, |
| 193 | &numConfigs, nullptr)); |
| 194 | |
| 195 | if (err == HWC2_ERROR_NONE) { |
| 196 | outConfigs->resize(numConfigs); |
| 197 | |
| 198 | err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, |
| 199 | &numConfigs, outConfigs->data())); |
| 200 | } |
| 201 | |
| 202 | if (outErr) { |
| 203 | *outErr = err; |
| 204 | } else { |
| 205 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to get configs for" |
| 206 | " display " << display; |
| 207 | } |
| 208 | } |
| 209 | |
Marissa Wall | 93dc04f | 2016-12-15 12:21:46 -0800 | [diff] [blame] | 210 | void getActiveConfig(hwc2_display_t display, hwc2_config_t* outConfig, |
| 211 | hwc2_error_t* outErr = nullptr) |
| 212 | { |
| 213 | auto pfn = reinterpret_cast<HWC2_PFN_GET_ACTIVE_CONFIG>( |
| 214 | getFunction(HWC2_FUNCTION_GET_ACTIVE_CONFIG)); |
| 215 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 216 | |
| 217 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, |
| 218 | outConfig)); |
| 219 | if (outErr) { |
| 220 | *outErr = err; |
| 221 | } else { |
| 222 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to get active config on" |
| 223 | " display " << display; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | void setActiveConfig(hwc2_display_t display, hwc2_config_t config, |
| 228 | hwc2_error_t* outErr = nullptr) |
| 229 | { |
| 230 | auto pfn = reinterpret_cast<HWC2_PFN_SET_ACTIVE_CONFIG>( |
| 231 | getFunction(HWC2_FUNCTION_SET_ACTIVE_CONFIG)); |
| 232 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 233 | |
| 234 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, config)); |
| 235 | if (outErr) { |
| 236 | *outErr = err; |
| 237 | } else { |
| 238 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to set active config " |
| 239 | << config; |
| 240 | } |
| 241 | } |
| 242 | |
Marissa Wall | 03c9173 | 2016-12-15 12:23:16 -0800 | [diff] [blame^] | 243 | void getDozeSupport(hwc2_display_t display, int32_t* outSupport, |
| 244 | hwc2_error_t* outErr = nullptr) |
| 245 | { |
| 246 | auto pfn = reinterpret_cast<HWC2_PFN_GET_DOZE_SUPPORT>( |
| 247 | getFunction(HWC2_FUNCTION_GET_DOZE_SUPPORT)); |
| 248 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 249 | |
| 250 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, |
| 251 | outSupport)); |
| 252 | if (outErr) { |
| 253 | *outErr = err; |
| 254 | } else { |
| 255 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to get doze support on" |
| 256 | " display " << display; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | void setPowerMode(hwc2_display_t display, hwc2_power_mode_t mode, |
| 261 | hwc2_error_t* outErr = nullptr) |
| 262 | { |
| 263 | auto pfn = reinterpret_cast<HWC2_PFN_SET_POWER_MODE>( |
| 264 | getFunction(HWC2_FUNCTION_SET_POWER_MODE)); |
| 265 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 266 | |
| 267 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, |
| 268 | mode)); |
| 269 | if (outErr) { |
| 270 | *outErr = err; |
| 271 | if (err != HWC2_ERROR_NONE) |
| 272 | return; |
| 273 | } else { |
| 274 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to set power mode " |
| 275 | << getPowerModeName(mode) << " on display " << display; |
| 276 | } |
| 277 | |
| 278 | if (mode == HWC2_POWER_MODE_OFF) { |
| 279 | mActiveDisplays.erase(display); |
| 280 | } else { |
| 281 | mActiveDisplays.insert(display); |
| 282 | } |
| 283 | } |
| 284 | |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 285 | protected: |
| 286 | hwc2_function_pointer_t getFunction(hwc2_function_descriptor_t descriptor) |
| 287 | { |
| 288 | return mHwc2Device->getFunction(mHwc2Device, descriptor); |
| 289 | } |
| 290 | |
| 291 | void getCapabilities(std::vector<hwc2_capability_t>* outCapabilities) |
| 292 | { |
| 293 | uint32_t num = 0; |
| 294 | |
| 295 | mHwc2Device->getCapabilities(mHwc2Device, &num, nullptr); |
| 296 | |
| 297 | outCapabilities->resize(num); |
| 298 | |
| 299 | mHwc2Device->getCapabilities(mHwc2Device, &num, |
| 300 | reinterpret_cast<int32_t*>(outCapabilities->data())); |
| 301 | } |
| 302 | |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 303 | /* Registers a hotplug callback and waits for hotplug callbacks. This |
| 304 | * function will have no effect if called more than once. */ |
| 305 | void populateDisplays() |
| 306 | { |
| 307 | /* Sets the hotplug status to receiving */ |
| 308 | { |
| 309 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 310 | |
| 311 | if (mHotplugStatus != Hwc2TestHotplugStatus::Init) |
| 312 | return; |
| 313 | mHotplugStatus = Hwc2TestHotplugStatus::Receiving; |
| 314 | } |
| 315 | |
| 316 | /* Registers the callback. This function call cannot be locked because |
| 317 | * a callback could happen on the same thread */ |
| 318 | ASSERT_NO_FATAL_FAILURE(registerCallback(HWC2_CALLBACK_HOTPLUG, this, |
| 319 | reinterpret_cast<hwc2_function_pointer_t>( |
| 320 | hwc2TestHotplugCallback))); |
| 321 | |
| 322 | /* Waits for hotplug events. If a hotplug event has not come within 1 |
| 323 | * second, stop waiting. */ |
| 324 | std::unique_lock<std::mutex> lock(mHotplugMutex); |
| 325 | |
| 326 | while (mHotplugCv.wait_for(lock, std::chrono::seconds(1)) != |
| 327 | std::cv_status::timeout) { } |
| 328 | |
| 329 | /* Sets the hotplug status to done. Future calls will have no effect */ |
| 330 | mHotplugStatus = Hwc2TestHotplugStatus::Done; |
| 331 | } |
| 332 | |
| 333 | void getBadDisplay(hwc2_display_t* outDisplay) |
| 334 | { |
| 335 | for (hwc2_display_t display = 0; display < UINT64_MAX; display++) { |
| 336 | if (mDisplays.count(display) == 0) { |
| 337 | *outDisplay = display; |
| 338 | return; |
| 339 | } |
| 340 | } |
| 341 | ASSERT_TRUE(false) << "Unable to find bad display. UINT64_MAX displays" |
| 342 | " are registered. This should never happen."; |
| 343 | } |
| 344 | |
Marissa Wall | 1db2e37 | 2016-12-15 12:19:39 -0800 | [diff] [blame] | 345 | /* NOTE: will create min(newlayerCnt, max supported layers) layers */ |
| 346 | void createLayers(hwc2_display_t display, |
| 347 | std::vector<hwc2_layer_t>* outLayers, size_t newLayerCnt) |
| 348 | { |
| 349 | std::vector<hwc2_layer_t> newLayers; |
| 350 | hwc2_layer_t layer; |
| 351 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 352 | |
| 353 | for (size_t i = 0; i < newLayerCnt; i++) { |
| 354 | |
| 355 | EXPECT_NO_FATAL_FAILURE(createLayer(display, &layer, &err)); |
| 356 | if (err == HWC2_ERROR_NO_RESOURCES) |
| 357 | break; |
| 358 | if (err != HWC2_ERROR_NONE) { |
| 359 | newLayers.clear(); |
| 360 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to create layer"; |
| 361 | } |
| 362 | newLayers.push_back(layer); |
| 363 | } |
| 364 | |
| 365 | *outLayers = std::move(newLayers); |
| 366 | } |
| 367 | |
| 368 | void destroyLayers(hwc2_display_t display, |
| 369 | std::vector<hwc2_layer_t>&& layers) |
| 370 | { |
| 371 | for (hwc2_layer_t layer : layers) { |
| 372 | EXPECT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 373 | } |
| 374 | } |
| 375 | |
Marissa Wall | cf935cb | 2016-12-15 12:20:47 -0800 | [diff] [blame] | 376 | void getInvalidConfig(hwc2_display_t display, hwc2_config_t* outConfig) |
| 377 | { |
| 378 | std::vector<hwc2_config_t> configs; |
| 379 | |
| 380 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 381 | |
| 382 | hwc2_config_t CONFIG_MAX = UINT32_MAX; |
| 383 | |
| 384 | ASSERT_LE(configs.size() - 1, CONFIG_MAX) << "every config value" |
| 385 | " (2^32 values) has been taken which shouldn't happen"; |
| 386 | |
| 387 | hwc2_config_t config; |
| 388 | for (config = 0; config < CONFIG_MAX; config++) { |
| 389 | if (std::count(configs.begin(), configs.end(), config) == 0) |
| 390 | break; |
| 391 | } |
| 392 | |
| 393 | *outConfig = config; |
| 394 | } |
| 395 | |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 396 | hwc2_device_t* mHwc2Device = nullptr; |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 397 | |
| 398 | enum class Hwc2TestHotplugStatus { |
| 399 | Init = 1, |
| 400 | Receiving, |
| 401 | Done, |
| 402 | }; |
| 403 | |
| 404 | std::mutex mHotplugMutex; |
| 405 | std::condition_variable mHotplugCv; |
| 406 | Hwc2TestHotplugStatus mHotplugStatus = Hwc2TestHotplugStatus::Init; |
| 407 | std::unordered_set<hwc2_display_t> mDisplays; |
Marissa Wall | 1db2e37 | 2016-12-15 12:19:39 -0800 | [diff] [blame] | 408 | |
| 409 | /* Store all created layers that have not been destroyed. If an ASSERT_* |
| 410 | * fails, then destroy the layers on exit */ |
| 411 | std::set<std::pair<hwc2_display_t, hwc2_layer_t>> mLayers; |
Marissa Wall | 03c9173 | 2016-12-15 12:23:16 -0800 | [diff] [blame^] | 412 | |
| 413 | /* Store the power mode state. If it is not HWC2_POWER_MODE_OFF when |
| 414 | * tearing down the test cases, change it to HWC2_POWER_MODE_OFF */ |
| 415 | std::set<hwc2_display_t> mActiveDisplays; |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 416 | }; |
| 417 | |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 418 | void hwc2TestHotplugCallback(hwc2_callback_data_t callbackData, |
| 419 | hwc2_display_t display, int32_t connection) |
| 420 | { |
| 421 | if (callbackData) |
| 422 | static_cast<Hwc2Test*>(callbackData)->hotplugCallback(display, |
| 423 | connection); |
| 424 | } |
| 425 | |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 426 | |
| 427 | static const std::array<hwc2_function_descriptor_t, 42> requiredFunctions = {{ |
| 428 | HWC2_FUNCTION_ACCEPT_DISPLAY_CHANGES, |
| 429 | HWC2_FUNCTION_CREATE_LAYER, |
| 430 | HWC2_FUNCTION_CREATE_VIRTUAL_DISPLAY, |
| 431 | HWC2_FUNCTION_DESTROY_LAYER, |
| 432 | HWC2_FUNCTION_DESTROY_VIRTUAL_DISPLAY, |
| 433 | HWC2_FUNCTION_DUMP, |
| 434 | HWC2_FUNCTION_GET_ACTIVE_CONFIG, |
| 435 | HWC2_FUNCTION_GET_CHANGED_COMPOSITION_TYPES, |
| 436 | HWC2_FUNCTION_GET_CLIENT_TARGET_SUPPORT, |
| 437 | HWC2_FUNCTION_GET_COLOR_MODES, |
| 438 | HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE, |
| 439 | HWC2_FUNCTION_GET_DISPLAY_CONFIGS, |
| 440 | HWC2_FUNCTION_GET_DISPLAY_NAME, |
| 441 | HWC2_FUNCTION_GET_DISPLAY_REQUESTS, |
| 442 | HWC2_FUNCTION_GET_DISPLAY_TYPE, |
| 443 | HWC2_FUNCTION_GET_DOZE_SUPPORT, |
| 444 | HWC2_FUNCTION_GET_HDR_CAPABILITIES, |
| 445 | HWC2_FUNCTION_GET_MAX_VIRTUAL_DISPLAY_COUNT, |
| 446 | HWC2_FUNCTION_GET_RELEASE_FENCES, |
| 447 | HWC2_FUNCTION_PRESENT_DISPLAY, |
| 448 | HWC2_FUNCTION_REGISTER_CALLBACK, |
| 449 | HWC2_FUNCTION_SET_ACTIVE_CONFIG, |
| 450 | HWC2_FUNCTION_SET_CLIENT_TARGET, |
| 451 | HWC2_FUNCTION_SET_COLOR_MODE, |
| 452 | HWC2_FUNCTION_SET_COLOR_TRANSFORM, |
| 453 | HWC2_FUNCTION_SET_CURSOR_POSITION, |
| 454 | HWC2_FUNCTION_SET_LAYER_BLEND_MODE, |
| 455 | HWC2_FUNCTION_SET_LAYER_BUFFER, |
| 456 | HWC2_FUNCTION_SET_LAYER_COLOR, |
| 457 | HWC2_FUNCTION_SET_LAYER_COMPOSITION_TYPE, |
| 458 | HWC2_FUNCTION_SET_LAYER_DATASPACE, |
| 459 | HWC2_FUNCTION_SET_LAYER_DISPLAY_FRAME, |
| 460 | HWC2_FUNCTION_SET_LAYER_PLANE_ALPHA, |
| 461 | HWC2_FUNCTION_SET_LAYER_SOURCE_CROP, |
| 462 | HWC2_FUNCTION_SET_LAYER_SURFACE_DAMAGE, |
| 463 | HWC2_FUNCTION_SET_LAYER_TRANSFORM, |
| 464 | HWC2_FUNCTION_SET_LAYER_VISIBLE_REGION, |
| 465 | HWC2_FUNCTION_SET_LAYER_Z_ORDER, |
| 466 | HWC2_FUNCTION_SET_OUTPUT_BUFFER, |
| 467 | HWC2_FUNCTION_SET_POWER_MODE, |
| 468 | HWC2_FUNCTION_SET_VSYNC_ENABLED, |
| 469 | HWC2_FUNCTION_VALIDATE_DISPLAY, |
| 470 | }}; |
| 471 | |
| 472 | /* TESTCASE: Tests that the HWC2 supports all required functions. */ |
| 473 | TEST_F(Hwc2Test, GET_FUNCTION) |
| 474 | { |
| 475 | for (hwc2_function_descriptor_t descriptor : requiredFunctions) { |
| 476 | hwc2_function_pointer_t pfn = getFunction(descriptor); |
| 477 | EXPECT_TRUE(pfn) << "failed to get function " |
| 478 | << getFunctionDescriptorName(descriptor); |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | /* TESTCASE: Tests that the HWC2 fails to retrieve and invalid function. */ |
| 483 | TEST_F(Hwc2Test, GET_FUNCTION_invalid_function) |
| 484 | { |
| 485 | hwc2_function_pointer_t pfn = getFunction(HWC2_FUNCTION_INVALID); |
| 486 | EXPECT_FALSE(pfn) << "failed to get invalid function"; |
| 487 | } |
| 488 | |
| 489 | /* TESTCASE: Tests that the HWC2 does not return an invalid capability. */ |
| 490 | TEST_F(Hwc2Test, GET_CAPABILITIES) |
| 491 | { |
| 492 | std::vector<hwc2_capability_t> capabilities; |
| 493 | |
| 494 | getCapabilities(&capabilities); |
| 495 | |
| 496 | EXPECT_EQ(std::count(capabilities.begin(), capabilities.end(), |
| 497 | HWC2_CAPABILITY_INVALID), 0); |
| 498 | } |
Marissa Wall | a4b0148 | 2017-02-17 20:52:03 -0800 | [diff] [blame] | 499 | |
| 500 | static const std::array<hwc2_callback_descriptor_t, 3> callbackDescriptors = {{ |
| 501 | HWC2_CALLBACK_HOTPLUG, |
| 502 | HWC2_CALLBACK_REFRESH, |
| 503 | HWC2_CALLBACK_VSYNC, |
| 504 | }}; |
| 505 | |
| 506 | /* TESTCASE: Tests that the HWC2 can successfully register all required |
| 507 | * callback functions. */ |
| 508 | TEST_F(Hwc2Test, REGISTER_CALLBACK) |
| 509 | { |
| 510 | hwc2_callback_data_t data = reinterpret_cast<hwc2_callback_data_t>( |
| 511 | const_cast<char*>("data")); |
| 512 | |
| 513 | for (auto descriptor : callbackDescriptors) { |
| 514 | ASSERT_NO_FATAL_FAILURE(registerCallback(descriptor, data, |
| 515 | []() { return; })); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | /* TESTCASE: Test that the HWC2 fails to register invalid callbacks. */ |
| 520 | TEST_F(Hwc2Test, REGISTER_CALLBACK_bad_parameter) |
| 521 | { |
| 522 | hwc2_callback_data_t data = reinterpret_cast<hwc2_callback_data_t>( |
| 523 | const_cast<char*>("data")); |
| 524 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 525 | |
| 526 | ASSERT_NO_FATAL_FAILURE(registerCallback(HWC2_CALLBACK_INVALID, data, |
| 527 | []() { return; }, &err)); |
| 528 | EXPECT_EQ(err, HWC2_ERROR_BAD_PARAMETER) << "returned wrong error code"; |
| 529 | } |
| 530 | |
| 531 | /* TESTCASE: Tests that the HWC2 can register a callback with null data. */ |
| 532 | TEST_F(Hwc2Test, REGISTER_CALLBACK_null_data) |
| 533 | { |
| 534 | hwc2_callback_data_t data = nullptr; |
| 535 | |
| 536 | for (auto descriptor : callbackDescriptors) { |
| 537 | ASSERT_NO_FATAL_FAILURE(registerCallback(descriptor, data, |
| 538 | []() { return; })); |
| 539 | } |
| 540 | } |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 541 | |
| 542 | /* TESTCASE: Tests that the HWC2 returns the correct display type for each |
| 543 | * physical display. */ |
| 544 | TEST_F(Hwc2Test, GET_DISPLAY_TYPE) |
| 545 | { |
| 546 | for (auto display : mDisplays) { |
| 547 | hwc2_display_type_t type; |
| 548 | |
| 549 | ASSERT_NO_FATAL_FAILURE(getDisplayType(display, &type)); |
| 550 | EXPECT_EQ(type, HWC2_DISPLAY_TYPE_PHYSICAL) << "failed to return" |
| 551 | " correct display type"; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | /* TESTCASE: Tests that the HWC2 returns an error when the display type of a bad |
| 556 | * display is requested. */ |
| 557 | TEST_F(Hwc2Test, GET_DISPLAY_TYPE_bad_display) |
| 558 | { |
| 559 | hwc2_display_t display; |
| 560 | hwc2_display_type_t type; |
| 561 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 562 | |
| 563 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 564 | |
| 565 | ASSERT_NO_FATAL_FAILURE(getDisplayType(display, &type, &err)); |
| 566 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 567 | } |
Marissa Wall | 1db2e37 | 2016-12-15 12:19:39 -0800 | [diff] [blame] | 568 | |
| 569 | /* TESTCASE: Tests that the HWC2 can create and destroy layers. */ |
| 570 | TEST_F(Hwc2Test, CREATE_DESTROY_LAYER) |
| 571 | { |
| 572 | for (auto display : mDisplays) { |
| 573 | hwc2_layer_t layer; |
| 574 | |
| 575 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer)); |
| 576 | |
| 577 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | /* TESTCASE: Tests that the HWC2 cannot create a layer for a bad display */ |
| 582 | TEST_F(Hwc2Test, CREATE_LAYER_bad_display) |
| 583 | { |
| 584 | hwc2_display_t display; |
| 585 | hwc2_layer_t layer; |
| 586 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 587 | |
| 588 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 589 | |
| 590 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer, &err)); |
| 591 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 592 | } |
| 593 | |
| 594 | /* TESTCASE: Tests that the HWC2 will either support a large number of resources |
| 595 | * or will return no resources. */ |
| 596 | TEST_F(Hwc2Test, CREATE_LAYER_no_resources) |
| 597 | { |
| 598 | const size_t layerCnt = 1000; |
| 599 | |
| 600 | for (auto display : mDisplays) { |
| 601 | std::vector<hwc2_layer_t> layers; |
| 602 | |
| 603 | ASSERT_NO_FATAL_FAILURE(createLayers(display, &layers, layerCnt)); |
| 604 | |
| 605 | ASSERT_NO_FATAL_FAILURE(destroyLayers(display, std::move(layers))); |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | /* TESTCASE: Tests that the HWC2 cannot destroy a layer for a bad display */ |
| 610 | TEST_F(Hwc2Test, DESTROY_LAYER_bad_display) |
| 611 | { |
| 612 | hwc2_display_t badDisplay; |
| 613 | |
| 614 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&badDisplay)); |
| 615 | |
| 616 | for (auto display : mDisplays) { |
| 617 | hwc2_layer_t layer = 0; |
| 618 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 619 | |
| 620 | ASSERT_NO_FATAL_FAILURE(destroyLayer(badDisplay, layer, &err)); |
| 621 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 622 | |
| 623 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer)); |
| 624 | |
| 625 | ASSERT_NO_FATAL_FAILURE(destroyLayer(badDisplay, layer, &err)); |
| 626 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 627 | |
| 628 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | /* TESTCASE: Tests that the HWC2 cannot destory a bad layer */ |
| 633 | TEST_F(Hwc2Test, DESTROY_LAYER_bad_layer) |
| 634 | { |
| 635 | for (auto display : mDisplays) { |
| 636 | hwc2_layer_t layer; |
| 637 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 638 | |
| 639 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, UINT64_MAX / 2, &err)); |
| 640 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 641 | |
| 642 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, 0, &err)); |
| 643 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 644 | |
| 645 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, UINT64_MAX - 1, &err)); |
| 646 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 647 | |
| 648 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, 1, &err)); |
| 649 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 650 | |
| 651 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, UINT64_MAX, &err)); |
| 652 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 653 | |
| 654 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer)); |
| 655 | |
| 656 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer + 1, &err)); |
| 657 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 658 | |
| 659 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 660 | |
| 661 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer, &err)); |
| 662 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 663 | } |
| 664 | } |
Marissa Wall | cf935cb | 2016-12-15 12:20:47 -0800 | [diff] [blame] | 665 | |
| 666 | static const std::array<hwc2_attribute_t, 2> requiredAttributes = {{ |
| 667 | HWC2_ATTRIBUTE_WIDTH, |
| 668 | HWC2_ATTRIBUTE_HEIGHT, |
| 669 | }}; |
| 670 | |
| 671 | static const std::array<hwc2_attribute_t, 3> optionalAttributes = {{ |
| 672 | HWC2_ATTRIBUTE_VSYNC_PERIOD, |
| 673 | HWC2_ATTRIBUTE_DPI_X, |
| 674 | HWC2_ATTRIBUTE_DPI_Y, |
| 675 | }}; |
| 676 | |
| 677 | /* TESTCASE: Tests that the HWC2 can return display attributes for a valid |
| 678 | * config. */ |
| 679 | TEST_F(Hwc2Test, GET_DISPLAY_ATTRIBUTE) |
| 680 | { |
| 681 | for (auto display : mDisplays) { |
| 682 | std::vector<hwc2_config_t> configs; |
| 683 | |
| 684 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 685 | |
| 686 | for (auto config : configs) { |
| 687 | int32_t value; |
| 688 | |
| 689 | for (auto attribute : requiredAttributes) { |
| 690 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, |
| 691 | attribute, &value)); |
| 692 | EXPECT_GE(value, 0) << "missing required attribute " |
| 693 | << getAttributeName(attribute) << " for config " |
| 694 | << config; |
| 695 | } |
| 696 | for (auto attribute : optionalAttributes) { |
| 697 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, |
| 698 | attribute, &value)); |
| 699 | } |
| 700 | } |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | /* TESTCASE: Tests that the HWC2 will return a value of -1 for an invalid |
| 705 | * attribute */ |
| 706 | TEST_F(Hwc2Test, GET_DISPLAY_ATTRIBUTE_invalid_attribute) |
| 707 | { |
| 708 | const hwc2_attribute_t attribute = HWC2_ATTRIBUTE_INVALID; |
| 709 | |
| 710 | for (auto display : mDisplays) { |
| 711 | std::vector<hwc2_config_t> configs; |
| 712 | |
| 713 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 714 | |
| 715 | for (auto config : configs) { |
| 716 | int32_t value; |
| 717 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 718 | |
| 719 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, |
| 720 | attribute, &value, &err)); |
| 721 | EXPECT_EQ(value, -1) << "failed to return -1 for an invalid" |
| 722 | " attribute for config " << config; |
| 723 | } |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | /* TESTCASE: Tests that the HWC2 will fail to get attributes for a bad display */ |
| 728 | TEST_F(Hwc2Test, GET_DISPLAY_ATTRIBUTE_bad_display) |
| 729 | { |
| 730 | hwc2_display_t display; |
| 731 | const hwc2_config_t config = 0; |
| 732 | int32_t value; |
| 733 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 734 | |
| 735 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 736 | |
| 737 | for (auto attribute : requiredAttributes) { |
| 738 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, attribute, |
| 739 | &value, &err)); |
| 740 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 741 | } |
| 742 | |
| 743 | for (auto attribute : optionalAttributes) { |
| 744 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, attribute, |
| 745 | &value, &err)); |
| 746 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | /* TESTCASE: Tests that the HWC2 will fail to get attributes for a bad config */ |
| 751 | TEST_F(Hwc2Test, GET_DISPLAY_ATTRIBUTE_bad_config) |
| 752 | { |
| 753 | for (auto display : mDisplays) { |
| 754 | hwc2_config_t config; |
| 755 | int32_t value; |
| 756 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 757 | |
| 758 | ASSERT_NO_FATAL_FAILURE(getInvalidConfig(display, &config)); |
| 759 | |
| 760 | for (auto attribute : requiredAttributes) { |
| 761 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, |
| 762 | attribute, &value, &err)); |
| 763 | EXPECT_EQ(err, HWC2_ERROR_BAD_CONFIG) << "returned wrong error code"; |
| 764 | } |
| 765 | |
| 766 | for (auto attribute : optionalAttributes) { |
| 767 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, |
| 768 | attribute, &value, &err)); |
| 769 | EXPECT_EQ(err, HWC2_ERROR_BAD_CONFIG) << "returned wrong error code"; |
| 770 | } |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | /* TESTCASE: Tests that the HWC2 will get display configs for active displays */ |
| 775 | TEST_F(Hwc2Test, GET_DISPLAY_CONFIGS) |
| 776 | { |
| 777 | for (auto display : mDisplays) { |
| 778 | std::vector<hwc2_config_t> configs; |
| 779 | |
| 780 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | /* TESTCASE: Tests that the HWC2 will not get display configs for bad displays */ |
| 785 | TEST_F(Hwc2Test, GET_DISPLAY_CONFIGS_bad_display) |
| 786 | { |
| 787 | hwc2_display_t display; |
| 788 | std::vector<hwc2_config_t> configs; |
| 789 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 790 | |
| 791 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 792 | |
| 793 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs, &err)); |
| 794 | |
| 795 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 796 | EXPECT_TRUE(configs.empty()) << "returned configs for bad display"; |
| 797 | } |
| 798 | |
| 799 | /* TESTCASE: Tests that the HWC2 will return the same config list multiple |
| 800 | * times in a row. */ |
| 801 | TEST_F(Hwc2Test, GET_DISPLAY_CONFIGS_same) |
| 802 | { |
| 803 | for (auto display : mDisplays) { |
| 804 | std::vector<hwc2_config_t> configs1, configs2; |
| 805 | |
| 806 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs1)); |
| 807 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs2)); |
| 808 | |
| 809 | EXPECT_TRUE(std::is_permutation(configs1.begin(), configs1.end(), |
| 810 | configs2.begin())) << "returned two different config sets"; |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | /* TESTCASE: Tests that the HWC2 does not return duplicate display configs */ |
| 815 | TEST_F(Hwc2Test, GET_DISPLAY_CONFIGS_duplicate) |
| 816 | { |
| 817 | for (auto display : mDisplays) { |
| 818 | std::vector<hwc2_config_t> configs; |
| 819 | |
| 820 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 821 | |
| 822 | std::unordered_set<hwc2_config_t> configsSet(configs.begin(), |
| 823 | configs.end()); |
| 824 | EXPECT_EQ(configs.size(), configsSet.size()) << "returned duplicate" |
| 825 | " configs"; |
| 826 | } |
| 827 | } |
Marissa Wall | 93dc04f | 2016-12-15 12:21:46 -0800 | [diff] [blame] | 828 | |
| 829 | /* TESTCASE: Tests that the HWC2 returns the active config for a display */ |
| 830 | TEST_F(Hwc2Test, GET_ACTIVE_CONFIG) |
| 831 | { |
| 832 | for (auto display : mDisplays) { |
| 833 | std::vector<hwc2_config_t> configs; |
| 834 | |
| 835 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 836 | |
| 837 | for (auto config : configs) { |
| 838 | hwc2_config_t activeConfig; |
| 839 | |
| 840 | ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config)); |
| 841 | ASSERT_NO_FATAL_FAILURE(getActiveConfig(display, &activeConfig)); |
| 842 | |
| 843 | EXPECT_EQ(activeConfig, config) << "failed to get active config"; |
| 844 | } |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | /* TESTCASE: Tests that the HWC2 does not return an active config for a bad |
| 849 | * display. */ |
| 850 | TEST_F(Hwc2Test, GET_ACTIVE_CONFIG_bad_display) |
| 851 | { |
| 852 | hwc2_display_t display; |
| 853 | hwc2_config_t activeConfig; |
| 854 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 855 | |
| 856 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 857 | |
| 858 | ASSERT_NO_FATAL_FAILURE(getActiveConfig(display, &activeConfig, &err)); |
| 859 | |
| 860 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 861 | } |
| 862 | |
| 863 | /* TESTCASE: Tests that the HWC2 either begins with a valid active config |
| 864 | * or returns an error when getActiveConfig is called. */ |
| 865 | TEST_F(Hwc2Test, GET_ACTIVE_CONFIG_bad_config) |
| 866 | { |
| 867 | for (auto display : mDisplays) { |
| 868 | std::vector<hwc2_config_t> configs; |
| 869 | hwc2_config_t activeConfig; |
| 870 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 871 | |
| 872 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 873 | |
| 874 | if (configs.empty()) |
| 875 | return; |
| 876 | |
| 877 | ASSERT_NO_FATAL_FAILURE(getActiveConfig(display, &activeConfig, &err)); |
| 878 | if (err == HWC2_ERROR_NONE) { |
| 879 | EXPECT_NE(std::count(configs.begin(), configs.end(), |
| 880 | activeConfig), 0) << "active config is not found in " |
| 881 | " configs for display"; |
| 882 | } else { |
| 883 | EXPECT_EQ(err, HWC2_ERROR_BAD_CONFIG) << "returned wrong error code"; |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | /* TESTCASE: Tests that the HWC2 can set every display config as an active |
| 889 | * config */ |
| 890 | TEST_F(Hwc2Test, SET_ACTIVE_CONFIG) |
| 891 | { |
| 892 | for (auto display : mDisplays) { |
| 893 | std::vector<hwc2_config_t> configs; |
| 894 | |
| 895 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 896 | |
| 897 | for (auto config : configs) { |
| 898 | EXPECT_NO_FATAL_FAILURE(setActiveConfig(display, config)); |
| 899 | } |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | /* TESTCASE: Tests that the HWC2 cannot set an active config for a bad display */ |
| 904 | TEST_F(Hwc2Test, SET_ACTIVE_CONFIG_bad_display) |
| 905 | { |
| 906 | hwc2_display_t display; |
| 907 | const hwc2_config_t config = 0; |
| 908 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 909 | |
| 910 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 911 | |
| 912 | ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config, &err)); |
| 913 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 914 | } |
| 915 | |
| 916 | /* TESTCASE: Tests that the HWC2 cannot set an invalid active config */ |
| 917 | TEST_F(Hwc2Test, SET_ACTIVE_CONFIG_bad_config) |
| 918 | { |
| 919 | for (auto display : mDisplays) { |
| 920 | hwc2_config_t config; |
| 921 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 922 | |
| 923 | ASSERT_NO_FATAL_FAILURE(getInvalidConfig(display, &config)); |
| 924 | |
| 925 | ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config, &err)); |
| 926 | EXPECT_EQ(err, HWC2_ERROR_BAD_CONFIG) << "returned wrong error code"; |
| 927 | } |
| 928 | } |
Marissa Wall | 03c9173 | 2016-12-15 12:23:16 -0800 | [diff] [blame^] | 929 | |
| 930 | /* TESTCASE: Tests that the HWC2 returns a valid value for getDozeSupport. */ |
| 931 | TEST_F(Hwc2Test, GET_DOZE_SUPPORT) |
| 932 | { |
| 933 | for (auto display : mDisplays) { |
| 934 | int32_t support = -1; |
| 935 | |
| 936 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support)); |
| 937 | |
| 938 | EXPECT_TRUE(support == 0 || support == 1) << "invalid doze support value"; |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | /* TESTCASE: Tests that the HWC2 cannot get doze support for a bad display. */ |
| 943 | TEST_F(Hwc2Test, GET_DOZE_SUPPORT_bad_display) |
| 944 | { |
| 945 | hwc2_display_t display; |
| 946 | int32_t support = -1; |
| 947 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 948 | |
| 949 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 950 | |
| 951 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support, &err)); |
| 952 | |
| 953 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 954 | } |
| 955 | |
| 956 | /* TESTCASE: Tests that the HWC2 can set all supported power modes */ |
| 957 | TEST_F(Hwc2Test, SET_POWER_MODE) |
| 958 | { |
| 959 | for (auto display : mDisplays) { |
| 960 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 961 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 962 | |
| 963 | int32_t support = -1; |
| 964 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support)); |
| 965 | if (support != 1) |
| 966 | return; |
| 967 | |
| 968 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE)); |
| 969 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, |
| 970 | HWC2_POWER_MODE_DOZE_SUSPEND)); |
| 971 | |
| 972 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | /* TESTCASE: Tests that the HWC2 cannot set a power mode for a bad display. */ |
| 977 | TEST_F(Hwc2Test, SET_POWER_MODE_bad_display) |
| 978 | { |
| 979 | hwc2_display_t display; |
| 980 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 981 | |
| 982 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 983 | |
| 984 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON, &err)); |
| 985 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 986 | |
| 987 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF, &err)); |
| 988 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 989 | |
| 990 | int32_t support = -1; |
| 991 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support, &err)); |
| 992 | if (support != 1) |
| 993 | return; |
| 994 | |
| 995 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE, &err)); |
| 996 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 997 | |
| 998 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE_SUSPEND, |
| 999 | &err)); |
| 1000 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1001 | } |
| 1002 | |
| 1003 | /* TESTCASE: Tests that the HWC2 cannot set an invalid power mode value. */ |
| 1004 | TEST_F(Hwc2Test, SET_POWER_MODE_bad_parameter) |
| 1005 | { |
| 1006 | for (auto display : mDisplays) { |
| 1007 | hwc2_power_mode_t mode = static_cast<hwc2_power_mode_t>( |
| 1008 | HWC2_POWER_MODE_DOZE_SUSPEND + 1); |
| 1009 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1010 | |
| 1011 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, mode, &err)); |
| 1012 | EXPECT_EQ(err, HWC2_ERROR_BAD_PARAMETER) << "returned wrong error code " |
| 1013 | << mode; |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | /* TESTCASE: Tests that the HWC2 will return unsupported if it does not support |
| 1018 | * an optional power mode. */ |
| 1019 | TEST_F(Hwc2Test, SET_POWER_MODE_unsupported) |
| 1020 | { |
| 1021 | for (auto display : mDisplays) { |
| 1022 | int32_t support = -1; |
| 1023 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1024 | |
| 1025 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support, &err)); |
| 1026 | if (support == 1) |
| 1027 | return; |
| 1028 | |
| 1029 | ASSERT_EQ(support, 0) << "invalid doze support value"; |
| 1030 | |
| 1031 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE, |
| 1032 | &err)); |
| 1033 | EXPECT_EQ(err, HWC2_ERROR_UNSUPPORTED) << "returned wrong error code"; |
| 1034 | |
| 1035 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, |
| 1036 | HWC2_POWER_MODE_DOZE_SUSPEND, &err)); |
| 1037 | EXPECT_EQ(err, HWC2_ERROR_UNSUPPORTED) << "returned wrong error code"; |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | /* TESTCASE: Tests that the HWC2 can set the same power mode multiple times. */ |
| 1042 | TEST_F(Hwc2Test, SET_POWER_MODE_stress) |
| 1043 | { |
| 1044 | for (auto display : mDisplays) { |
| 1045 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1046 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1047 | |
| 1048 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1049 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1050 | |
| 1051 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1052 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1053 | |
| 1054 | int32_t support = -1; |
| 1055 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support)); |
| 1056 | if (support != 1) |
| 1057 | return; |
| 1058 | |
| 1059 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE)); |
| 1060 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE)); |
| 1061 | |
| 1062 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, |
| 1063 | HWC2_POWER_MODE_DOZE_SUSPEND)); |
| 1064 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, |
| 1065 | HWC2_POWER_MODE_DOZE_SUSPEND)); |
| 1066 | |
| 1067 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1068 | } |
| 1069 | } |