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 | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 29 | #include "Hwc2TestLayer.h" |
| 30 | |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 31 | void hwc2TestHotplugCallback(hwc2_callback_data_t callbackData, |
| 32 | hwc2_display_t display, int32_t connected); |
Marissa Wall | 572a1ee | 2016-12-15 12:24:13 -0800 | [diff] [blame] | 33 | void hwc2TestVsyncCallback(hwc2_callback_data_t callbackData, |
| 34 | hwc2_display_t display, int64_t timestamp); |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 35 | |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 36 | class Hwc2Test : public testing::Test { |
| 37 | public: |
| 38 | |
| 39 | virtual void SetUp() |
| 40 | { |
| 41 | hw_module_t const* hwc2Module; |
| 42 | |
| 43 | int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &hwc2Module); |
| 44 | ASSERT_GE(err, 0) << "failed to get hwc hardware module: " |
| 45 | << strerror(-err); |
| 46 | |
| 47 | /* The following method will fail if you have not run |
| 48 | * "adb shell stop" */ |
| 49 | err = hwc2_open(hwc2Module, &mHwc2Device); |
| 50 | ASSERT_GE(err, 0) << "failed to open hwc hardware module: " |
| 51 | << strerror(-err); |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 52 | |
| 53 | populateDisplays(); |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | virtual void TearDown() |
| 57 | { |
Marissa Wall | 1db2e37 | 2016-12-15 12:19:39 -0800 | [diff] [blame] | 58 | |
| 59 | for (auto itr = mLayers.begin(); itr != mLayers.end();) { |
| 60 | hwc2_display_t display = itr->first; |
| 61 | hwc2_layer_t layer = itr->second; |
| 62 | itr++; |
| 63 | /* Destroys and removes the layer from mLayers */ |
| 64 | destroyLayer(display, layer); |
| 65 | } |
| 66 | |
Marissa Wall | 03c9173 | 2016-12-15 12:23:16 -0800 | [diff] [blame] | 67 | for (auto itr = mActiveDisplays.begin(); itr != mActiveDisplays.end();) { |
| 68 | hwc2_display_t display = *itr; |
| 69 | itr++; |
| 70 | /* Sets power mode to off and removes the display from |
| 71 | * mActiveDisplays */ |
| 72 | setPowerMode(display, HWC2_POWER_MODE_OFF); |
| 73 | } |
| 74 | |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 75 | if (mHwc2Device) |
| 76 | hwc2_close(mHwc2Device); |
| 77 | } |
| 78 | |
Marissa Wall | a4b0148 | 2017-02-17 20:52:03 -0800 | [diff] [blame] | 79 | void registerCallback(hwc2_callback_descriptor_t descriptor, |
| 80 | hwc2_callback_data_t callbackData, hwc2_function_pointer_t pointer, |
| 81 | hwc2_error_t* outErr = nullptr) |
| 82 | { |
| 83 | auto pfn = reinterpret_cast<HWC2_PFN_REGISTER_CALLBACK>( |
| 84 | getFunction(HWC2_FUNCTION_REGISTER_CALLBACK)); |
| 85 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 86 | |
| 87 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, descriptor, |
| 88 | callbackData, pointer)); |
| 89 | if (outErr) { |
| 90 | *outErr = err; |
| 91 | } else { |
| 92 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to register callback"; |
| 93 | } |
| 94 | } |
| 95 | |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 96 | void getDisplayType(hwc2_display_t display, hwc2_display_type_t* outType, |
| 97 | hwc2_error_t* outErr = nullptr) |
| 98 | { |
| 99 | auto pfn = reinterpret_cast<HWC2_PFN_GET_DISPLAY_TYPE>( |
| 100 | getFunction(HWC2_FUNCTION_GET_DISPLAY_TYPE)); |
| 101 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 102 | |
| 103 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, |
| 104 | reinterpret_cast<int32_t*>(outType))); |
| 105 | if (outErr) { |
| 106 | *outErr = err; |
| 107 | } else { |
| 108 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to get display type"; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /* If the populateDisplays function is still receiving displays and the |
| 113 | * display is connected, the display handle is stored in mDisplays. */ |
| 114 | void hotplugCallback(hwc2_display_t display, int32_t connected) |
| 115 | { |
| 116 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 117 | |
| 118 | if (mHotplugStatus != Hwc2TestHotplugStatus::Receiving) |
| 119 | return; |
| 120 | |
| 121 | if (connected == HWC2_CONNECTION_CONNECTED) |
| 122 | mDisplays.insert(display); |
| 123 | |
| 124 | mHotplugCv.notify_all(); |
| 125 | } |
| 126 | |
Marissa Wall | 1db2e37 | 2016-12-15 12:19:39 -0800 | [diff] [blame] | 127 | void createLayer(hwc2_display_t display, hwc2_layer_t* outLayer, |
| 128 | hwc2_error_t* outErr = nullptr) |
| 129 | { |
| 130 | auto pfn = reinterpret_cast<HWC2_PFN_CREATE_LAYER>( |
| 131 | getFunction(HWC2_FUNCTION_CREATE_LAYER)); |
| 132 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 133 | |
| 134 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, |
| 135 | outLayer)); |
| 136 | |
| 137 | if (err == HWC2_ERROR_NONE) |
| 138 | mLayers.insert(std::make_pair(display, *outLayer)); |
| 139 | |
| 140 | if (outErr) { |
| 141 | *outErr = err; |
| 142 | } else { |
| 143 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to create layer"; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | void destroyLayer(hwc2_display_t display, hwc2_layer_t layer, |
| 148 | hwc2_error_t* outErr = nullptr) |
| 149 | { |
| 150 | auto pfn = reinterpret_cast<HWC2_PFN_DESTROY_LAYER>( |
| 151 | getFunction(HWC2_FUNCTION_DESTROY_LAYER)); |
| 152 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 153 | |
| 154 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, layer)); |
| 155 | |
| 156 | if (err == HWC2_ERROR_NONE) |
| 157 | mLayers.erase(std::make_pair(display, layer)); |
| 158 | |
| 159 | if (outErr) { |
| 160 | *outErr = err; |
| 161 | } else { |
| 162 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to destroy layer " |
| 163 | << layer; |
| 164 | } |
| 165 | } |
| 166 | |
Marissa Wall | cf935cb | 2016-12-15 12:20:47 -0800 | [diff] [blame] | 167 | void getDisplayAttribute(hwc2_display_t display, hwc2_config_t config, |
| 168 | hwc2_attribute_t attribute, int32_t* outValue, |
| 169 | hwc2_error_t* outErr = nullptr) |
| 170 | { |
| 171 | auto pfn = reinterpret_cast<HWC2_PFN_GET_DISPLAY_ATTRIBUTE>( |
| 172 | getFunction(HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE)); |
| 173 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 174 | |
| 175 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, config, |
| 176 | attribute, outValue)); |
| 177 | |
| 178 | if (outErr) { |
| 179 | *outErr = err; |
| 180 | } else { |
| 181 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to get display attribute " |
| 182 | << getAttributeName(attribute) << " for config " << config; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | void getDisplayConfigs(hwc2_display_t display, |
| 187 | std::vector<hwc2_config_t>* outConfigs, |
| 188 | hwc2_error_t* outErr = nullptr) |
| 189 | { |
| 190 | auto pfn = reinterpret_cast<HWC2_PFN_GET_DISPLAY_CONFIGS>( |
| 191 | getFunction(HWC2_FUNCTION_GET_DISPLAY_CONFIGS)); |
| 192 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 193 | |
| 194 | uint32_t numConfigs = 0; |
| 195 | |
| 196 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, |
| 197 | &numConfigs, nullptr)); |
| 198 | |
| 199 | if (err == HWC2_ERROR_NONE) { |
| 200 | outConfigs->resize(numConfigs); |
| 201 | |
| 202 | err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, |
| 203 | &numConfigs, outConfigs->data())); |
| 204 | } |
| 205 | |
| 206 | if (outErr) { |
| 207 | *outErr = err; |
| 208 | } else { |
| 209 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to get configs for" |
| 210 | " display " << display; |
| 211 | } |
| 212 | } |
| 213 | |
Marissa Wall | 93dc04f | 2016-12-15 12:21:46 -0800 | [diff] [blame] | 214 | void getActiveConfig(hwc2_display_t display, hwc2_config_t* outConfig, |
| 215 | hwc2_error_t* outErr = nullptr) |
| 216 | { |
| 217 | auto pfn = reinterpret_cast<HWC2_PFN_GET_ACTIVE_CONFIG>( |
| 218 | getFunction(HWC2_FUNCTION_GET_ACTIVE_CONFIG)); |
| 219 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 220 | |
| 221 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, |
| 222 | outConfig)); |
| 223 | if (outErr) { |
| 224 | *outErr = err; |
| 225 | } else { |
| 226 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to get active config on" |
| 227 | " display " << display; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | void setActiveConfig(hwc2_display_t display, hwc2_config_t config, |
| 232 | hwc2_error_t* outErr = nullptr) |
| 233 | { |
| 234 | auto pfn = reinterpret_cast<HWC2_PFN_SET_ACTIVE_CONFIG>( |
| 235 | getFunction(HWC2_FUNCTION_SET_ACTIVE_CONFIG)); |
| 236 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 237 | |
| 238 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, config)); |
| 239 | if (outErr) { |
| 240 | *outErr = err; |
| 241 | } else { |
| 242 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to set active config " |
| 243 | << config; |
| 244 | } |
| 245 | } |
| 246 | |
Marissa Wall | 03c9173 | 2016-12-15 12:23:16 -0800 | [diff] [blame] | 247 | void getDozeSupport(hwc2_display_t display, int32_t* outSupport, |
| 248 | hwc2_error_t* outErr = nullptr) |
| 249 | { |
| 250 | auto pfn = reinterpret_cast<HWC2_PFN_GET_DOZE_SUPPORT>( |
| 251 | getFunction(HWC2_FUNCTION_GET_DOZE_SUPPORT)); |
| 252 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 253 | |
| 254 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, |
| 255 | outSupport)); |
| 256 | if (outErr) { |
| 257 | *outErr = err; |
| 258 | } else { |
| 259 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to get doze support on" |
| 260 | " display " << display; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | void setPowerMode(hwc2_display_t display, hwc2_power_mode_t mode, |
| 265 | hwc2_error_t* outErr = nullptr) |
| 266 | { |
| 267 | auto pfn = reinterpret_cast<HWC2_PFN_SET_POWER_MODE>( |
| 268 | getFunction(HWC2_FUNCTION_SET_POWER_MODE)); |
| 269 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 270 | |
| 271 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, |
| 272 | mode)); |
| 273 | if (outErr) { |
| 274 | *outErr = err; |
| 275 | if (err != HWC2_ERROR_NONE) |
| 276 | return; |
| 277 | } else { |
| 278 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to set power mode " |
| 279 | << getPowerModeName(mode) << " on display " << display; |
| 280 | } |
| 281 | |
| 282 | if (mode == HWC2_POWER_MODE_OFF) { |
| 283 | mActiveDisplays.erase(display); |
| 284 | } else { |
| 285 | mActiveDisplays.insert(display); |
| 286 | } |
| 287 | } |
| 288 | |
Marissa Wall | 572a1ee | 2016-12-15 12:24:13 -0800 | [diff] [blame] | 289 | void setVsyncEnabled(hwc2_display_t display, hwc2_vsync_t enabled, |
| 290 | hwc2_error_t* outErr = nullptr) |
| 291 | { |
| 292 | auto pfn = reinterpret_cast<HWC2_PFN_SET_VSYNC_ENABLED>( |
| 293 | getFunction(HWC2_FUNCTION_SET_VSYNC_ENABLED)); |
| 294 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 295 | |
| 296 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, |
| 297 | enabled)); |
| 298 | if (outErr) { |
| 299 | *outErr = err; |
| 300 | } else { |
| 301 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to set vsync enabled " |
| 302 | << getVsyncName(enabled); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | void vsyncCallback(hwc2_display_t display, int64_t timestamp) |
| 307 | { |
| 308 | std::lock_guard<std::mutex> lock(mVsyncMutex); |
| 309 | mVsyncDisplay = display; |
| 310 | mVsyncTimestamp = timestamp; |
| 311 | mVsyncCv.notify_all(); |
| 312 | } |
| 313 | |
Marissa Wall | dd4087f | 2016-12-15 12:24:52 -0800 | [diff] [blame] | 314 | void getDisplayName(hwc2_display_t display, std::string* outName, |
| 315 | hwc2_error_t* outErr = nullptr) |
| 316 | { |
| 317 | auto pfn = reinterpret_cast<HWC2_PFN_GET_DISPLAY_NAME>( |
| 318 | getFunction(HWC2_FUNCTION_GET_DISPLAY_NAME)); |
| 319 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 320 | |
| 321 | uint32_t size = 0; |
| 322 | |
| 323 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, &size, |
| 324 | nullptr)); |
| 325 | |
| 326 | if (err == HWC2_ERROR_NONE) { |
| 327 | std::vector<char> name(size); |
| 328 | |
| 329 | err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, &size, |
| 330 | name.data())); |
| 331 | |
| 332 | outName->assign(name.data()); |
| 333 | } |
| 334 | |
| 335 | if (outErr) { |
| 336 | *outErr = err; |
| 337 | } else { |
| 338 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to get display name for " |
| 339 | << display; |
| 340 | } |
| 341 | } |
| 342 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 343 | void setLayerCompositionType(hwc2_display_t display, hwc2_layer_t layer, |
| 344 | hwc2_composition_t composition, hwc2_error_t* outErr = nullptr) |
| 345 | { |
| 346 | auto pfn = reinterpret_cast<HWC2_PFN_SET_LAYER_COMPOSITION_TYPE>( |
| 347 | getFunction(HWC2_FUNCTION_SET_LAYER_COMPOSITION_TYPE)); |
| 348 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 349 | |
| 350 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, layer, |
| 351 | composition)); |
| 352 | if (outErr) { |
| 353 | *outErr = err; |
| 354 | } else { |
| 355 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to set layer composition" |
| 356 | " type " << getCompositionName(composition); |
| 357 | } |
| 358 | } |
| 359 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame^] | 360 | void setLayerBlendMode(hwc2_display_t display, hwc2_layer_t layer, |
| 361 | hwc2_blend_mode_t mode, hwc2_error_t* outErr = nullptr) |
| 362 | { |
| 363 | auto pfn = reinterpret_cast<HWC2_PFN_SET_LAYER_BLEND_MODE>( |
| 364 | getFunction(HWC2_FUNCTION_SET_LAYER_BLEND_MODE)); |
| 365 | ASSERT_TRUE(pfn) << "failed to get function"; |
| 366 | |
| 367 | auto err = static_cast<hwc2_error_t>(pfn(mHwc2Device, display, layer, |
| 368 | mode)); |
| 369 | if (outErr) { |
| 370 | *outErr = err; |
| 371 | } else { |
| 372 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to set layer blend mode " |
| 373 | << getBlendModeName(mode); |
| 374 | } |
| 375 | } |
| 376 | |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 377 | protected: |
| 378 | hwc2_function_pointer_t getFunction(hwc2_function_descriptor_t descriptor) |
| 379 | { |
| 380 | return mHwc2Device->getFunction(mHwc2Device, descriptor); |
| 381 | } |
| 382 | |
| 383 | void getCapabilities(std::vector<hwc2_capability_t>* outCapabilities) |
| 384 | { |
| 385 | uint32_t num = 0; |
| 386 | |
| 387 | mHwc2Device->getCapabilities(mHwc2Device, &num, nullptr); |
| 388 | |
| 389 | outCapabilities->resize(num); |
| 390 | |
| 391 | mHwc2Device->getCapabilities(mHwc2Device, &num, |
| 392 | reinterpret_cast<int32_t*>(outCapabilities->data())); |
| 393 | } |
| 394 | |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 395 | /* Registers a hotplug callback and waits for hotplug callbacks. This |
| 396 | * function will have no effect if called more than once. */ |
| 397 | void populateDisplays() |
| 398 | { |
| 399 | /* Sets the hotplug status to receiving */ |
| 400 | { |
| 401 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 402 | |
| 403 | if (mHotplugStatus != Hwc2TestHotplugStatus::Init) |
| 404 | return; |
| 405 | mHotplugStatus = Hwc2TestHotplugStatus::Receiving; |
| 406 | } |
| 407 | |
| 408 | /* Registers the callback. This function call cannot be locked because |
| 409 | * a callback could happen on the same thread */ |
| 410 | ASSERT_NO_FATAL_FAILURE(registerCallback(HWC2_CALLBACK_HOTPLUG, this, |
| 411 | reinterpret_cast<hwc2_function_pointer_t>( |
| 412 | hwc2TestHotplugCallback))); |
| 413 | |
| 414 | /* Waits for hotplug events. If a hotplug event has not come within 1 |
| 415 | * second, stop waiting. */ |
| 416 | std::unique_lock<std::mutex> lock(mHotplugMutex); |
| 417 | |
| 418 | while (mHotplugCv.wait_for(lock, std::chrono::seconds(1)) != |
| 419 | std::cv_status::timeout) { } |
| 420 | |
| 421 | /* Sets the hotplug status to done. Future calls will have no effect */ |
| 422 | mHotplugStatus = Hwc2TestHotplugStatus::Done; |
| 423 | } |
| 424 | |
| 425 | void getBadDisplay(hwc2_display_t* outDisplay) |
| 426 | { |
| 427 | for (hwc2_display_t display = 0; display < UINT64_MAX; display++) { |
| 428 | if (mDisplays.count(display) == 0) { |
| 429 | *outDisplay = display; |
| 430 | return; |
| 431 | } |
| 432 | } |
| 433 | ASSERT_TRUE(false) << "Unable to find bad display. UINT64_MAX displays" |
| 434 | " are registered. This should never happen."; |
| 435 | } |
| 436 | |
Marissa Wall | 1db2e37 | 2016-12-15 12:19:39 -0800 | [diff] [blame] | 437 | /* NOTE: will create min(newlayerCnt, max supported layers) layers */ |
| 438 | void createLayers(hwc2_display_t display, |
| 439 | std::vector<hwc2_layer_t>* outLayers, size_t newLayerCnt) |
| 440 | { |
| 441 | std::vector<hwc2_layer_t> newLayers; |
| 442 | hwc2_layer_t layer; |
| 443 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 444 | |
| 445 | for (size_t i = 0; i < newLayerCnt; i++) { |
| 446 | |
| 447 | EXPECT_NO_FATAL_FAILURE(createLayer(display, &layer, &err)); |
| 448 | if (err == HWC2_ERROR_NO_RESOURCES) |
| 449 | break; |
| 450 | if (err != HWC2_ERROR_NONE) { |
| 451 | newLayers.clear(); |
| 452 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to create layer"; |
| 453 | } |
| 454 | newLayers.push_back(layer); |
| 455 | } |
| 456 | |
| 457 | *outLayers = std::move(newLayers); |
| 458 | } |
| 459 | |
| 460 | void destroyLayers(hwc2_display_t display, |
| 461 | std::vector<hwc2_layer_t>&& layers) |
| 462 | { |
| 463 | for (hwc2_layer_t layer : layers) { |
| 464 | EXPECT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 465 | } |
| 466 | } |
| 467 | |
Marissa Wall | cf935cb | 2016-12-15 12:20:47 -0800 | [diff] [blame] | 468 | void getInvalidConfig(hwc2_display_t display, hwc2_config_t* outConfig) |
| 469 | { |
| 470 | std::vector<hwc2_config_t> configs; |
| 471 | |
| 472 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 473 | |
| 474 | hwc2_config_t CONFIG_MAX = UINT32_MAX; |
| 475 | |
| 476 | ASSERT_LE(configs.size() - 1, CONFIG_MAX) << "every config value" |
| 477 | " (2^32 values) has been taken which shouldn't happen"; |
| 478 | |
| 479 | hwc2_config_t config; |
| 480 | for (config = 0; config < CONFIG_MAX; config++) { |
| 481 | if (std::count(configs.begin(), configs.end(), config) == 0) |
| 482 | break; |
| 483 | } |
| 484 | |
| 485 | *outConfig = config; |
| 486 | } |
| 487 | |
Marissa Wall | 572a1ee | 2016-12-15 12:24:13 -0800 | [diff] [blame] | 488 | void enableVsync(hwc2_display_t display) |
| 489 | { |
| 490 | ASSERT_NO_FATAL_FAILURE(registerCallback(HWC2_CALLBACK_VSYNC, this, |
| 491 | reinterpret_cast<hwc2_function_pointer_t>( |
| 492 | hwc2TestVsyncCallback))); |
| 493 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_ENABLE)); |
| 494 | } |
| 495 | |
| 496 | void disableVsync(hwc2_display_t display) |
| 497 | { |
| 498 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_DISABLE)); |
| 499 | } |
| 500 | |
| 501 | void waitForVsync(hwc2_display_t* outDisplay = nullptr, |
| 502 | int64_t* outTimestamp = nullptr) |
| 503 | { |
| 504 | std::unique_lock<std::mutex> lock(mVsyncMutex); |
| 505 | ASSERT_EQ(mVsyncCv.wait_for(lock, std::chrono::seconds(3)), |
| 506 | std::cv_status::no_timeout) << "timed out attempting to get" |
| 507 | " vsync callback"; |
| 508 | if (outDisplay) |
| 509 | *outDisplay = mVsyncDisplay; |
| 510 | if (outTimestamp) |
| 511 | *outTimestamp = mVsyncTimestamp; |
| 512 | } |
| 513 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 514 | /* Calls a set property function from Hwc2Test to set a property value from |
| 515 | * Hwc2TestLayer to hwc2_layer_t on hwc2_display_t */ |
| 516 | using TestLayerPropertyFunction = void (*)(Hwc2Test* test, |
| 517 | hwc2_display_t display, hwc2_layer_t layer, |
| 518 | const Hwc2TestLayer& testLayer, hwc2_error_t* outErr); |
| 519 | |
| 520 | /* Calls a set property function from Hwc2Test to set a bad property value |
| 521 | * on hwc2_layer_t on hwc2_display_t */ |
| 522 | using TestLayerPropertyBadLayerFunction = void (*)(Hwc2Test* test, |
| 523 | hwc2_display_t display, hwc2_layer_t layer, |
| 524 | const Hwc2TestLayer& testLayer, hwc2_error_t* outErr); |
| 525 | |
| 526 | /* Calls a set property function from Hwc2Test to set a bad property value |
| 527 | * on hwc2_layer_t on hwc2_display_t */ |
| 528 | using TestLayerPropertyBadParameterFunction = void (*)(Hwc2Test* test, |
| 529 | hwc2_display_t display, hwc2_layer_t layer, hwc2_error_t* outErr); |
| 530 | |
| 531 | /* Advances a property of Hwc2TestLayer */ |
| 532 | using AdvanceProperty = bool (*)(Hwc2TestLayer* testLayer); |
| 533 | |
| 534 | /* For each active display it cycles through each display config and tests |
| 535 | * each property value. It creates a layer, sets the property and then |
| 536 | * destroys the layer */ |
| 537 | void setLayerProperty(Hwc2TestCoverage coverage, |
| 538 | TestLayerPropertyFunction function, AdvanceProperty advance) |
| 539 | { |
| 540 | for (auto display : mDisplays) { |
| 541 | std::vector<hwc2_config_t> configs; |
| 542 | |
| 543 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 544 | |
| 545 | for (auto config : configs) { |
| 546 | hwc2_layer_t layer; |
| 547 | |
| 548 | ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config)); |
| 549 | Hwc2TestLayer testLayer(coverage); |
| 550 | |
| 551 | do { |
| 552 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer)); |
| 553 | |
| 554 | ASSERT_NO_FATAL_FAILURE(function(this, display, layer, |
| 555 | testLayer, nullptr)); |
| 556 | |
| 557 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 558 | } while (advance(&testLayer)); |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | /* For each active display it cycles through each display config and tests |
| 564 | * each property value. It creates a layer, cycles through each property |
| 565 | * value and updates the layer property value and then destroys the layer */ |
| 566 | void setLayerPropertyUpdate(Hwc2TestCoverage coverage, |
| 567 | TestLayerPropertyFunction function, AdvanceProperty advance) |
| 568 | { |
| 569 | for (auto display : mDisplays) { |
| 570 | std::vector<hwc2_config_t> configs; |
| 571 | |
| 572 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 573 | |
| 574 | for (auto config : configs) { |
| 575 | hwc2_layer_t layer; |
| 576 | |
| 577 | ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config)); |
| 578 | Hwc2TestLayer testLayer(coverage); |
| 579 | |
| 580 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer)); |
| 581 | |
| 582 | do { |
| 583 | ASSERT_NO_FATAL_FAILURE(function(this, display, layer, |
| 584 | testLayer, nullptr)); |
| 585 | } while (advance(&testLayer)); |
| 586 | |
| 587 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 588 | } |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | /* For each active display it cycles through each display config. |
| 593 | * 1) It attempts to set a valid property value to bad layer handle. |
| 594 | * 2) It creates a layer x and attempts to set a valid property value to |
| 595 | * layer x + 1 |
| 596 | * 3) It destroys the layer x and attempts to set a valid property value to |
| 597 | * the destroyed layer x. |
| 598 | */ |
| 599 | void setLayerPropertyBadLayer(Hwc2TestCoverage coverage, |
| 600 | TestLayerPropertyBadLayerFunction function) |
| 601 | { |
| 602 | for (auto display : mDisplays) { |
| 603 | std::vector<hwc2_config_t> configs; |
| 604 | |
| 605 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 606 | |
| 607 | for (auto config : configs) { |
| 608 | hwc2_layer_t layer = 0; |
| 609 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 610 | |
| 611 | ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config)); |
| 612 | Hwc2TestLayer testLayer(coverage); |
| 613 | |
| 614 | ASSERT_NO_FATAL_FAILURE(function(this, display, layer, |
| 615 | testLayer, &err)); |
| 616 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 617 | |
| 618 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer)); |
| 619 | |
| 620 | ASSERT_NO_FATAL_FAILURE(function(this, display, layer + 1, |
| 621 | testLayer, &err)); |
| 622 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 623 | |
| 624 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 625 | |
| 626 | ASSERT_NO_FATAL_FAILURE(function(this, display, layer, |
| 627 | testLayer, &err)); |
| 628 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 629 | } |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | /* For each active display it cycles through each display config and tests |
| 634 | * each property value. It creates a layer, sets a bad property value and |
| 635 | * then destroys the layer */ |
| 636 | void setLayerPropertyBadParameter(TestLayerPropertyBadParameterFunction function) |
| 637 | { |
| 638 | for (auto display : mDisplays) { |
| 639 | std::vector<hwc2_config_t> configs; |
| 640 | |
| 641 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 642 | |
| 643 | for (auto config : configs) { |
| 644 | hwc2_layer_t layer; |
| 645 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 646 | |
| 647 | ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config)); |
| 648 | |
| 649 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer)); |
| 650 | |
| 651 | ASSERT_NO_FATAL_FAILURE(function(this, display, layer, &err)); |
| 652 | EXPECT_EQ(err, HWC2_ERROR_BAD_PARAMETER) << "returned wrong" |
| 653 | " error code"; |
| 654 | |
| 655 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 660 | hwc2_device_t* mHwc2Device = nullptr; |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 661 | |
| 662 | enum class Hwc2TestHotplugStatus { |
| 663 | Init = 1, |
| 664 | Receiving, |
| 665 | Done, |
| 666 | }; |
| 667 | |
| 668 | std::mutex mHotplugMutex; |
| 669 | std::condition_variable mHotplugCv; |
| 670 | Hwc2TestHotplugStatus mHotplugStatus = Hwc2TestHotplugStatus::Init; |
| 671 | std::unordered_set<hwc2_display_t> mDisplays; |
Marissa Wall | 1db2e37 | 2016-12-15 12:19:39 -0800 | [diff] [blame] | 672 | |
| 673 | /* Store all created layers that have not been destroyed. If an ASSERT_* |
| 674 | * fails, then destroy the layers on exit */ |
| 675 | std::set<std::pair<hwc2_display_t, hwc2_layer_t>> mLayers; |
Marissa Wall | 03c9173 | 2016-12-15 12:23:16 -0800 | [diff] [blame] | 676 | |
| 677 | /* Store the power mode state. If it is not HWC2_POWER_MODE_OFF when |
| 678 | * tearing down the test cases, change it to HWC2_POWER_MODE_OFF */ |
| 679 | std::set<hwc2_display_t> mActiveDisplays; |
Marissa Wall | 572a1ee | 2016-12-15 12:24:13 -0800 | [diff] [blame] | 680 | |
| 681 | std::mutex mVsyncMutex; |
| 682 | std::condition_variable mVsyncCv; |
| 683 | hwc2_display_t mVsyncDisplay; |
| 684 | int64_t mVsyncTimestamp = -1; |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 685 | }; |
| 686 | |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 687 | void hwc2TestHotplugCallback(hwc2_callback_data_t callbackData, |
| 688 | hwc2_display_t display, int32_t connection) |
| 689 | { |
| 690 | if (callbackData) |
| 691 | static_cast<Hwc2Test*>(callbackData)->hotplugCallback(display, |
| 692 | connection); |
| 693 | } |
| 694 | |
Marissa Wall | 572a1ee | 2016-12-15 12:24:13 -0800 | [diff] [blame] | 695 | void hwc2TestVsyncCallback(hwc2_callback_data_t callbackData, |
| 696 | hwc2_display_t display, int64_t timestamp) |
| 697 | { |
| 698 | if (callbackData) |
| 699 | static_cast<Hwc2Test*>(callbackData)->vsyncCallback(display, |
| 700 | timestamp); |
| 701 | } |
| 702 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame^] | 703 | void setBlendMode(Hwc2Test* test, hwc2_display_t display, hwc2_layer_t layer, |
| 704 | const Hwc2TestLayer& testLayer, hwc2_error_t* outErr) |
| 705 | { |
| 706 | EXPECT_NO_FATAL_FAILURE(test->setLayerBlendMode(display, layer, |
| 707 | testLayer.getBlendMode(), outErr)); |
| 708 | } |
| 709 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 710 | void setComposition(Hwc2Test* test, hwc2_display_t display, hwc2_layer_t layer, |
| 711 | const Hwc2TestLayer& testLayer, hwc2_error_t* outErr) |
| 712 | { |
| 713 | hwc2_composition_t composition = testLayer.getComposition(); |
| 714 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 715 | |
| 716 | ASSERT_NO_FATAL_FAILURE(test->setLayerCompositionType(display, layer, |
| 717 | composition, &err)); |
| 718 | if (outErr) { |
| 719 | *outErr = err; |
| 720 | return; |
| 721 | } |
| 722 | |
| 723 | if (composition != HWC2_COMPOSITION_SIDEBAND) { |
| 724 | EXPECT_EQ(err, HWC2_ERROR_NONE) << "returned wrong error code"; |
| 725 | } else { |
| 726 | EXPECT_TRUE(err == HWC2_ERROR_NONE || err == HWC2_ERROR_UNSUPPORTED) |
| 727 | << "returned wrong error code"; |
| 728 | } |
| 729 | } |
| 730 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame^] | 731 | bool advanceBlendMode(Hwc2TestLayer* testLayer) |
| 732 | { |
| 733 | return testLayer->advanceBlendMode(); |
| 734 | } |
| 735 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 736 | bool advanceComposition(Hwc2TestLayer* testLayer) |
| 737 | { |
| 738 | return testLayer->advanceComposition(); |
| 739 | } |
| 740 | |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 741 | |
| 742 | static const std::array<hwc2_function_descriptor_t, 42> requiredFunctions = {{ |
| 743 | HWC2_FUNCTION_ACCEPT_DISPLAY_CHANGES, |
| 744 | HWC2_FUNCTION_CREATE_LAYER, |
| 745 | HWC2_FUNCTION_CREATE_VIRTUAL_DISPLAY, |
| 746 | HWC2_FUNCTION_DESTROY_LAYER, |
| 747 | HWC2_FUNCTION_DESTROY_VIRTUAL_DISPLAY, |
| 748 | HWC2_FUNCTION_DUMP, |
| 749 | HWC2_FUNCTION_GET_ACTIVE_CONFIG, |
| 750 | HWC2_FUNCTION_GET_CHANGED_COMPOSITION_TYPES, |
| 751 | HWC2_FUNCTION_GET_CLIENT_TARGET_SUPPORT, |
| 752 | HWC2_FUNCTION_GET_COLOR_MODES, |
| 753 | HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE, |
| 754 | HWC2_FUNCTION_GET_DISPLAY_CONFIGS, |
| 755 | HWC2_FUNCTION_GET_DISPLAY_NAME, |
| 756 | HWC2_FUNCTION_GET_DISPLAY_REQUESTS, |
| 757 | HWC2_FUNCTION_GET_DISPLAY_TYPE, |
| 758 | HWC2_FUNCTION_GET_DOZE_SUPPORT, |
| 759 | HWC2_FUNCTION_GET_HDR_CAPABILITIES, |
| 760 | HWC2_FUNCTION_GET_MAX_VIRTUAL_DISPLAY_COUNT, |
| 761 | HWC2_FUNCTION_GET_RELEASE_FENCES, |
| 762 | HWC2_FUNCTION_PRESENT_DISPLAY, |
| 763 | HWC2_FUNCTION_REGISTER_CALLBACK, |
| 764 | HWC2_FUNCTION_SET_ACTIVE_CONFIG, |
| 765 | HWC2_FUNCTION_SET_CLIENT_TARGET, |
| 766 | HWC2_FUNCTION_SET_COLOR_MODE, |
| 767 | HWC2_FUNCTION_SET_COLOR_TRANSFORM, |
| 768 | HWC2_FUNCTION_SET_CURSOR_POSITION, |
| 769 | HWC2_FUNCTION_SET_LAYER_BLEND_MODE, |
| 770 | HWC2_FUNCTION_SET_LAYER_BUFFER, |
| 771 | HWC2_FUNCTION_SET_LAYER_COLOR, |
| 772 | HWC2_FUNCTION_SET_LAYER_COMPOSITION_TYPE, |
| 773 | HWC2_FUNCTION_SET_LAYER_DATASPACE, |
| 774 | HWC2_FUNCTION_SET_LAYER_DISPLAY_FRAME, |
| 775 | HWC2_FUNCTION_SET_LAYER_PLANE_ALPHA, |
| 776 | HWC2_FUNCTION_SET_LAYER_SOURCE_CROP, |
| 777 | HWC2_FUNCTION_SET_LAYER_SURFACE_DAMAGE, |
| 778 | HWC2_FUNCTION_SET_LAYER_TRANSFORM, |
| 779 | HWC2_FUNCTION_SET_LAYER_VISIBLE_REGION, |
| 780 | HWC2_FUNCTION_SET_LAYER_Z_ORDER, |
| 781 | HWC2_FUNCTION_SET_OUTPUT_BUFFER, |
| 782 | HWC2_FUNCTION_SET_POWER_MODE, |
| 783 | HWC2_FUNCTION_SET_VSYNC_ENABLED, |
| 784 | HWC2_FUNCTION_VALIDATE_DISPLAY, |
| 785 | }}; |
| 786 | |
| 787 | /* TESTCASE: Tests that the HWC2 supports all required functions. */ |
| 788 | TEST_F(Hwc2Test, GET_FUNCTION) |
| 789 | { |
| 790 | for (hwc2_function_descriptor_t descriptor : requiredFunctions) { |
| 791 | hwc2_function_pointer_t pfn = getFunction(descriptor); |
| 792 | EXPECT_TRUE(pfn) << "failed to get function " |
| 793 | << getFunctionDescriptorName(descriptor); |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | /* TESTCASE: Tests that the HWC2 fails to retrieve and invalid function. */ |
| 798 | TEST_F(Hwc2Test, GET_FUNCTION_invalid_function) |
| 799 | { |
| 800 | hwc2_function_pointer_t pfn = getFunction(HWC2_FUNCTION_INVALID); |
| 801 | EXPECT_FALSE(pfn) << "failed to get invalid function"; |
| 802 | } |
| 803 | |
| 804 | /* TESTCASE: Tests that the HWC2 does not return an invalid capability. */ |
| 805 | TEST_F(Hwc2Test, GET_CAPABILITIES) |
| 806 | { |
| 807 | std::vector<hwc2_capability_t> capabilities; |
| 808 | |
| 809 | getCapabilities(&capabilities); |
| 810 | |
| 811 | EXPECT_EQ(std::count(capabilities.begin(), capabilities.end(), |
| 812 | HWC2_CAPABILITY_INVALID), 0); |
| 813 | } |
Marissa Wall | a4b0148 | 2017-02-17 20:52:03 -0800 | [diff] [blame] | 814 | |
| 815 | static const std::array<hwc2_callback_descriptor_t, 3> callbackDescriptors = {{ |
| 816 | HWC2_CALLBACK_HOTPLUG, |
| 817 | HWC2_CALLBACK_REFRESH, |
| 818 | HWC2_CALLBACK_VSYNC, |
| 819 | }}; |
| 820 | |
| 821 | /* TESTCASE: Tests that the HWC2 can successfully register all required |
| 822 | * callback functions. */ |
| 823 | TEST_F(Hwc2Test, REGISTER_CALLBACK) |
| 824 | { |
| 825 | hwc2_callback_data_t data = reinterpret_cast<hwc2_callback_data_t>( |
| 826 | const_cast<char*>("data")); |
| 827 | |
| 828 | for (auto descriptor : callbackDescriptors) { |
| 829 | ASSERT_NO_FATAL_FAILURE(registerCallback(descriptor, data, |
| 830 | []() { return; })); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | /* TESTCASE: Test that the HWC2 fails to register invalid callbacks. */ |
| 835 | TEST_F(Hwc2Test, REGISTER_CALLBACK_bad_parameter) |
| 836 | { |
| 837 | hwc2_callback_data_t data = reinterpret_cast<hwc2_callback_data_t>( |
| 838 | const_cast<char*>("data")); |
| 839 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 840 | |
| 841 | ASSERT_NO_FATAL_FAILURE(registerCallback(HWC2_CALLBACK_INVALID, data, |
| 842 | []() { return; }, &err)); |
| 843 | EXPECT_EQ(err, HWC2_ERROR_BAD_PARAMETER) << "returned wrong error code"; |
| 844 | } |
| 845 | |
| 846 | /* TESTCASE: Tests that the HWC2 can register a callback with null data. */ |
| 847 | TEST_F(Hwc2Test, REGISTER_CALLBACK_null_data) |
| 848 | { |
| 849 | hwc2_callback_data_t data = nullptr; |
| 850 | |
| 851 | for (auto descriptor : callbackDescriptors) { |
| 852 | ASSERT_NO_FATAL_FAILURE(registerCallback(descriptor, data, |
| 853 | []() { return; })); |
| 854 | } |
| 855 | } |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 856 | |
| 857 | /* TESTCASE: Tests that the HWC2 returns the correct display type for each |
| 858 | * physical display. */ |
| 859 | TEST_F(Hwc2Test, GET_DISPLAY_TYPE) |
| 860 | { |
| 861 | for (auto display : mDisplays) { |
| 862 | hwc2_display_type_t type; |
| 863 | |
| 864 | ASSERT_NO_FATAL_FAILURE(getDisplayType(display, &type)); |
| 865 | EXPECT_EQ(type, HWC2_DISPLAY_TYPE_PHYSICAL) << "failed to return" |
| 866 | " correct display type"; |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | /* TESTCASE: Tests that the HWC2 returns an error when the display type of a bad |
| 871 | * display is requested. */ |
| 872 | TEST_F(Hwc2Test, GET_DISPLAY_TYPE_bad_display) |
| 873 | { |
| 874 | hwc2_display_t display; |
| 875 | hwc2_display_type_t type; |
| 876 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 877 | |
| 878 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 879 | |
| 880 | ASSERT_NO_FATAL_FAILURE(getDisplayType(display, &type, &err)); |
| 881 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 882 | } |
Marissa Wall | 1db2e37 | 2016-12-15 12:19:39 -0800 | [diff] [blame] | 883 | |
| 884 | /* TESTCASE: Tests that the HWC2 can create and destroy layers. */ |
| 885 | TEST_F(Hwc2Test, CREATE_DESTROY_LAYER) |
| 886 | { |
| 887 | for (auto display : mDisplays) { |
| 888 | hwc2_layer_t layer; |
| 889 | |
| 890 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer)); |
| 891 | |
| 892 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | /* TESTCASE: Tests that the HWC2 cannot create a layer for a bad display */ |
| 897 | TEST_F(Hwc2Test, CREATE_LAYER_bad_display) |
| 898 | { |
| 899 | hwc2_display_t display; |
| 900 | hwc2_layer_t layer; |
| 901 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 902 | |
| 903 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 904 | |
| 905 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer, &err)); |
| 906 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 907 | } |
| 908 | |
| 909 | /* TESTCASE: Tests that the HWC2 will either support a large number of resources |
| 910 | * or will return no resources. */ |
| 911 | TEST_F(Hwc2Test, CREATE_LAYER_no_resources) |
| 912 | { |
| 913 | const size_t layerCnt = 1000; |
| 914 | |
| 915 | for (auto display : mDisplays) { |
| 916 | std::vector<hwc2_layer_t> layers; |
| 917 | |
| 918 | ASSERT_NO_FATAL_FAILURE(createLayers(display, &layers, layerCnt)); |
| 919 | |
| 920 | ASSERT_NO_FATAL_FAILURE(destroyLayers(display, std::move(layers))); |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | /* TESTCASE: Tests that the HWC2 cannot destroy a layer for a bad display */ |
| 925 | TEST_F(Hwc2Test, DESTROY_LAYER_bad_display) |
| 926 | { |
| 927 | hwc2_display_t badDisplay; |
| 928 | |
| 929 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&badDisplay)); |
| 930 | |
| 931 | for (auto display : mDisplays) { |
| 932 | hwc2_layer_t layer = 0; |
| 933 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 934 | |
| 935 | ASSERT_NO_FATAL_FAILURE(destroyLayer(badDisplay, layer, &err)); |
| 936 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 937 | |
| 938 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer)); |
| 939 | |
| 940 | ASSERT_NO_FATAL_FAILURE(destroyLayer(badDisplay, layer, &err)); |
| 941 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 942 | |
| 943 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | /* TESTCASE: Tests that the HWC2 cannot destory a bad layer */ |
| 948 | TEST_F(Hwc2Test, DESTROY_LAYER_bad_layer) |
| 949 | { |
| 950 | for (auto display : mDisplays) { |
| 951 | hwc2_layer_t layer; |
| 952 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 953 | |
| 954 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, UINT64_MAX / 2, &err)); |
| 955 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 956 | |
| 957 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, 0, &err)); |
| 958 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 959 | |
| 960 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, UINT64_MAX - 1, &err)); |
| 961 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 962 | |
| 963 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, 1, &err)); |
| 964 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 965 | |
| 966 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, UINT64_MAX, &err)); |
| 967 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 968 | |
| 969 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer)); |
| 970 | |
| 971 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer + 1, &err)); |
| 972 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 973 | |
| 974 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 975 | |
| 976 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer, &err)); |
| 977 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 978 | } |
| 979 | } |
Marissa Wall | cf935cb | 2016-12-15 12:20:47 -0800 | [diff] [blame] | 980 | |
| 981 | static const std::array<hwc2_attribute_t, 2> requiredAttributes = {{ |
| 982 | HWC2_ATTRIBUTE_WIDTH, |
| 983 | HWC2_ATTRIBUTE_HEIGHT, |
| 984 | }}; |
| 985 | |
| 986 | static const std::array<hwc2_attribute_t, 3> optionalAttributes = {{ |
| 987 | HWC2_ATTRIBUTE_VSYNC_PERIOD, |
| 988 | HWC2_ATTRIBUTE_DPI_X, |
| 989 | HWC2_ATTRIBUTE_DPI_Y, |
| 990 | }}; |
| 991 | |
| 992 | /* TESTCASE: Tests that the HWC2 can return display attributes for a valid |
| 993 | * config. */ |
| 994 | TEST_F(Hwc2Test, GET_DISPLAY_ATTRIBUTE) |
| 995 | { |
| 996 | for (auto display : mDisplays) { |
| 997 | std::vector<hwc2_config_t> configs; |
| 998 | |
| 999 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 1000 | |
| 1001 | for (auto config : configs) { |
| 1002 | int32_t value; |
| 1003 | |
| 1004 | for (auto attribute : requiredAttributes) { |
| 1005 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, |
| 1006 | attribute, &value)); |
| 1007 | EXPECT_GE(value, 0) << "missing required attribute " |
| 1008 | << getAttributeName(attribute) << " for config " |
| 1009 | << config; |
| 1010 | } |
| 1011 | for (auto attribute : optionalAttributes) { |
| 1012 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, |
| 1013 | attribute, &value)); |
| 1014 | } |
| 1015 | } |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | /* TESTCASE: Tests that the HWC2 will return a value of -1 for an invalid |
| 1020 | * attribute */ |
| 1021 | TEST_F(Hwc2Test, GET_DISPLAY_ATTRIBUTE_invalid_attribute) |
| 1022 | { |
| 1023 | const hwc2_attribute_t attribute = HWC2_ATTRIBUTE_INVALID; |
| 1024 | |
| 1025 | for (auto display : mDisplays) { |
| 1026 | std::vector<hwc2_config_t> configs; |
| 1027 | |
| 1028 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 1029 | |
| 1030 | for (auto config : configs) { |
| 1031 | int32_t value; |
| 1032 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1033 | |
| 1034 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, |
| 1035 | attribute, &value, &err)); |
| 1036 | EXPECT_EQ(value, -1) << "failed to return -1 for an invalid" |
| 1037 | " attribute for config " << config; |
| 1038 | } |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | /* TESTCASE: Tests that the HWC2 will fail to get attributes for a bad display */ |
| 1043 | TEST_F(Hwc2Test, GET_DISPLAY_ATTRIBUTE_bad_display) |
| 1044 | { |
| 1045 | hwc2_display_t display; |
| 1046 | const hwc2_config_t config = 0; |
| 1047 | int32_t value; |
| 1048 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1049 | |
| 1050 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 1051 | |
| 1052 | for (auto attribute : requiredAttributes) { |
| 1053 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, attribute, |
| 1054 | &value, &err)); |
| 1055 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1056 | } |
| 1057 | |
| 1058 | for (auto attribute : optionalAttributes) { |
| 1059 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, attribute, |
| 1060 | &value, &err)); |
| 1061 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | /* TESTCASE: Tests that the HWC2 will fail to get attributes for a bad config */ |
| 1066 | TEST_F(Hwc2Test, GET_DISPLAY_ATTRIBUTE_bad_config) |
| 1067 | { |
| 1068 | for (auto display : mDisplays) { |
| 1069 | hwc2_config_t config; |
| 1070 | int32_t value; |
| 1071 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1072 | |
| 1073 | ASSERT_NO_FATAL_FAILURE(getInvalidConfig(display, &config)); |
| 1074 | |
| 1075 | for (auto attribute : requiredAttributes) { |
| 1076 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, |
| 1077 | attribute, &value, &err)); |
| 1078 | EXPECT_EQ(err, HWC2_ERROR_BAD_CONFIG) << "returned wrong error code"; |
| 1079 | } |
| 1080 | |
| 1081 | for (auto attribute : optionalAttributes) { |
| 1082 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, |
| 1083 | attribute, &value, &err)); |
| 1084 | EXPECT_EQ(err, HWC2_ERROR_BAD_CONFIG) << "returned wrong error code"; |
| 1085 | } |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | /* TESTCASE: Tests that the HWC2 will get display configs for active displays */ |
| 1090 | TEST_F(Hwc2Test, GET_DISPLAY_CONFIGS) |
| 1091 | { |
| 1092 | for (auto display : mDisplays) { |
| 1093 | std::vector<hwc2_config_t> configs; |
| 1094 | |
| 1095 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | /* TESTCASE: Tests that the HWC2 will not get display configs for bad displays */ |
| 1100 | TEST_F(Hwc2Test, GET_DISPLAY_CONFIGS_bad_display) |
| 1101 | { |
| 1102 | hwc2_display_t display; |
| 1103 | std::vector<hwc2_config_t> configs; |
| 1104 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1105 | |
| 1106 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 1107 | |
| 1108 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs, &err)); |
| 1109 | |
| 1110 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1111 | EXPECT_TRUE(configs.empty()) << "returned configs for bad display"; |
| 1112 | } |
| 1113 | |
| 1114 | /* TESTCASE: Tests that the HWC2 will return the same config list multiple |
| 1115 | * times in a row. */ |
| 1116 | TEST_F(Hwc2Test, GET_DISPLAY_CONFIGS_same) |
| 1117 | { |
| 1118 | for (auto display : mDisplays) { |
| 1119 | std::vector<hwc2_config_t> configs1, configs2; |
| 1120 | |
| 1121 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs1)); |
| 1122 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs2)); |
| 1123 | |
| 1124 | EXPECT_TRUE(std::is_permutation(configs1.begin(), configs1.end(), |
| 1125 | configs2.begin())) << "returned two different config sets"; |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | /* TESTCASE: Tests that the HWC2 does not return duplicate display configs */ |
| 1130 | TEST_F(Hwc2Test, GET_DISPLAY_CONFIGS_duplicate) |
| 1131 | { |
| 1132 | for (auto display : mDisplays) { |
| 1133 | std::vector<hwc2_config_t> configs; |
| 1134 | |
| 1135 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 1136 | |
| 1137 | std::unordered_set<hwc2_config_t> configsSet(configs.begin(), |
| 1138 | configs.end()); |
| 1139 | EXPECT_EQ(configs.size(), configsSet.size()) << "returned duplicate" |
| 1140 | " configs"; |
| 1141 | } |
| 1142 | } |
Marissa Wall | 93dc04f | 2016-12-15 12:21:46 -0800 | [diff] [blame] | 1143 | |
| 1144 | /* TESTCASE: Tests that the HWC2 returns the active config for a display */ |
| 1145 | TEST_F(Hwc2Test, GET_ACTIVE_CONFIG) |
| 1146 | { |
| 1147 | for (auto display : mDisplays) { |
| 1148 | std::vector<hwc2_config_t> configs; |
| 1149 | |
| 1150 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 1151 | |
| 1152 | for (auto config : configs) { |
| 1153 | hwc2_config_t activeConfig; |
| 1154 | |
| 1155 | ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config)); |
| 1156 | ASSERT_NO_FATAL_FAILURE(getActiveConfig(display, &activeConfig)); |
| 1157 | |
| 1158 | EXPECT_EQ(activeConfig, config) << "failed to get active config"; |
| 1159 | } |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | /* TESTCASE: Tests that the HWC2 does not return an active config for a bad |
| 1164 | * display. */ |
| 1165 | TEST_F(Hwc2Test, GET_ACTIVE_CONFIG_bad_display) |
| 1166 | { |
| 1167 | hwc2_display_t display; |
| 1168 | hwc2_config_t activeConfig; |
| 1169 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1170 | |
| 1171 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 1172 | |
| 1173 | ASSERT_NO_FATAL_FAILURE(getActiveConfig(display, &activeConfig, &err)); |
| 1174 | |
| 1175 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1176 | } |
| 1177 | |
| 1178 | /* TESTCASE: Tests that the HWC2 either begins with a valid active config |
| 1179 | * or returns an error when getActiveConfig is called. */ |
| 1180 | TEST_F(Hwc2Test, GET_ACTIVE_CONFIG_bad_config) |
| 1181 | { |
| 1182 | for (auto display : mDisplays) { |
| 1183 | std::vector<hwc2_config_t> configs; |
| 1184 | hwc2_config_t activeConfig; |
| 1185 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1186 | |
| 1187 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 1188 | |
| 1189 | if (configs.empty()) |
| 1190 | return; |
| 1191 | |
| 1192 | ASSERT_NO_FATAL_FAILURE(getActiveConfig(display, &activeConfig, &err)); |
| 1193 | if (err == HWC2_ERROR_NONE) { |
| 1194 | EXPECT_NE(std::count(configs.begin(), configs.end(), |
| 1195 | activeConfig), 0) << "active config is not found in " |
| 1196 | " configs for display"; |
| 1197 | } else { |
| 1198 | EXPECT_EQ(err, HWC2_ERROR_BAD_CONFIG) << "returned wrong error code"; |
| 1199 | } |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | /* TESTCASE: Tests that the HWC2 can set every display config as an active |
| 1204 | * config */ |
| 1205 | TEST_F(Hwc2Test, SET_ACTIVE_CONFIG) |
| 1206 | { |
| 1207 | for (auto display : mDisplays) { |
| 1208 | std::vector<hwc2_config_t> configs; |
| 1209 | |
| 1210 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 1211 | |
| 1212 | for (auto config : configs) { |
| 1213 | EXPECT_NO_FATAL_FAILURE(setActiveConfig(display, config)); |
| 1214 | } |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | /* TESTCASE: Tests that the HWC2 cannot set an active config for a bad display */ |
| 1219 | TEST_F(Hwc2Test, SET_ACTIVE_CONFIG_bad_display) |
| 1220 | { |
| 1221 | hwc2_display_t display; |
| 1222 | const hwc2_config_t config = 0; |
| 1223 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1224 | |
| 1225 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 1226 | |
| 1227 | ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config, &err)); |
| 1228 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1229 | } |
| 1230 | |
| 1231 | /* TESTCASE: Tests that the HWC2 cannot set an invalid active config */ |
| 1232 | TEST_F(Hwc2Test, SET_ACTIVE_CONFIG_bad_config) |
| 1233 | { |
| 1234 | for (auto display : mDisplays) { |
| 1235 | hwc2_config_t config; |
| 1236 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1237 | |
| 1238 | ASSERT_NO_FATAL_FAILURE(getInvalidConfig(display, &config)); |
| 1239 | |
| 1240 | ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config, &err)); |
| 1241 | EXPECT_EQ(err, HWC2_ERROR_BAD_CONFIG) << "returned wrong error code"; |
| 1242 | } |
| 1243 | } |
Marissa Wall | 03c9173 | 2016-12-15 12:23:16 -0800 | [diff] [blame] | 1244 | |
| 1245 | /* TESTCASE: Tests that the HWC2 returns a valid value for getDozeSupport. */ |
| 1246 | TEST_F(Hwc2Test, GET_DOZE_SUPPORT) |
| 1247 | { |
| 1248 | for (auto display : mDisplays) { |
| 1249 | int32_t support = -1; |
| 1250 | |
| 1251 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support)); |
| 1252 | |
| 1253 | EXPECT_TRUE(support == 0 || support == 1) << "invalid doze support value"; |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | /* TESTCASE: Tests that the HWC2 cannot get doze support for a bad display. */ |
| 1258 | TEST_F(Hwc2Test, GET_DOZE_SUPPORT_bad_display) |
| 1259 | { |
| 1260 | hwc2_display_t display; |
| 1261 | int32_t support = -1; |
| 1262 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1263 | |
| 1264 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 1265 | |
| 1266 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support, &err)); |
| 1267 | |
| 1268 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1269 | } |
| 1270 | |
| 1271 | /* TESTCASE: Tests that the HWC2 can set all supported power modes */ |
| 1272 | TEST_F(Hwc2Test, SET_POWER_MODE) |
| 1273 | { |
| 1274 | for (auto display : mDisplays) { |
| 1275 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1276 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1277 | |
| 1278 | int32_t support = -1; |
| 1279 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support)); |
| 1280 | if (support != 1) |
| 1281 | return; |
| 1282 | |
| 1283 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE)); |
| 1284 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, |
| 1285 | HWC2_POWER_MODE_DOZE_SUSPEND)); |
| 1286 | |
| 1287 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | /* TESTCASE: Tests that the HWC2 cannot set a power mode for a bad display. */ |
| 1292 | TEST_F(Hwc2Test, SET_POWER_MODE_bad_display) |
| 1293 | { |
| 1294 | hwc2_display_t display; |
| 1295 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1296 | |
| 1297 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 1298 | |
| 1299 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON, &err)); |
| 1300 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1301 | |
| 1302 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF, &err)); |
| 1303 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1304 | |
| 1305 | int32_t support = -1; |
| 1306 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support, &err)); |
| 1307 | if (support != 1) |
| 1308 | return; |
| 1309 | |
| 1310 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE, &err)); |
| 1311 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1312 | |
| 1313 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE_SUSPEND, |
| 1314 | &err)); |
| 1315 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1316 | } |
| 1317 | |
| 1318 | /* TESTCASE: Tests that the HWC2 cannot set an invalid power mode value. */ |
| 1319 | TEST_F(Hwc2Test, SET_POWER_MODE_bad_parameter) |
| 1320 | { |
| 1321 | for (auto display : mDisplays) { |
| 1322 | hwc2_power_mode_t mode = static_cast<hwc2_power_mode_t>( |
| 1323 | HWC2_POWER_MODE_DOZE_SUSPEND + 1); |
| 1324 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1325 | |
| 1326 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, mode, &err)); |
| 1327 | EXPECT_EQ(err, HWC2_ERROR_BAD_PARAMETER) << "returned wrong error code " |
| 1328 | << mode; |
| 1329 | } |
| 1330 | } |
| 1331 | |
| 1332 | /* TESTCASE: Tests that the HWC2 will return unsupported if it does not support |
| 1333 | * an optional power mode. */ |
| 1334 | TEST_F(Hwc2Test, SET_POWER_MODE_unsupported) |
| 1335 | { |
| 1336 | for (auto display : mDisplays) { |
| 1337 | int32_t support = -1; |
| 1338 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1339 | |
| 1340 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support, &err)); |
| 1341 | if (support == 1) |
| 1342 | return; |
| 1343 | |
| 1344 | ASSERT_EQ(support, 0) << "invalid doze support value"; |
| 1345 | |
| 1346 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE, |
| 1347 | &err)); |
| 1348 | EXPECT_EQ(err, HWC2_ERROR_UNSUPPORTED) << "returned wrong error code"; |
| 1349 | |
| 1350 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, |
| 1351 | HWC2_POWER_MODE_DOZE_SUSPEND, &err)); |
| 1352 | EXPECT_EQ(err, HWC2_ERROR_UNSUPPORTED) << "returned wrong error code"; |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | /* TESTCASE: Tests that the HWC2 can set the same power mode multiple times. */ |
| 1357 | TEST_F(Hwc2Test, SET_POWER_MODE_stress) |
| 1358 | { |
| 1359 | for (auto display : mDisplays) { |
| 1360 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1361 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1362 | |
| 1363 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1364 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1365 | |
| 1366 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1367 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1368 | |
| 1369 | int32_t support = -1; |
| 1370 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support)); |
| 1371 | if (support != 1) |
| 1372 | return; |
| 1373 | |
| 1374 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE)); |
| 1375 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE)); |
| 1376 | |
| 1377 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, |
| 1378 | HWC2_POWER_MODE_DOZE_SUSPEND)); |
| 1379 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, |
| 1380 | HWC2_POWER_MODE_DOZE_SUSPEND)); |
| 1381 | |
| 1382 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1383 | } |
| 1384 | } |
Marissa Wall | 572a1ee | 2016-12-15 12:24:13 -0800 | [diff] [blame] | 1385 | |
| 1386 | /* TESTCASE: Tests that the HWC2 can enable and disable vsync on active |
| 1387 | * displays */ |
| 1388 | TEST_F(Hwc2Test, SET_VSYNC_ENABLED) |
| 1389 | { |
| 1390 | for (auto display : mDisplays) { |
| 1391 | hwc2_callback_data_t data = reinterpret_cast<hwc2_callback_data_t>( |
| 1392 | const_cast<char*>("data")); |
| 1393 | |
| 1394 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1395 | |
| 1396 | ASSERT_NO_FATAL_FAILURE(registerCallback(HWC2_CALLBACK_VSYNC, data, |
| 1397 | []() { return; })); |
| 1398 | |
| 1399 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_ENABLE)); |
| 1400 | |
| 1401 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_DISABLE)); |
| 1402 | |
| 1403 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1404 | } |
| 1405 | } |
| 1406 | |
| 1407 | /* TESTCASE: Tests that the HWC2 issues a valid vsync callback. */ |
| 1408 | TEST_F(Hwc2Test, SET_VSYNC_ENABLED_callback) |
| 1409 | { |
| 1410 | for (auto display : mDisplays) { |
| 1411 | hwc2_display_t receivedDisplay; |
| 1412 | int64_t receivedTimestamp; |
| 1413 | |
| 1414 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1415 | |
| 1416 | ASSERT_NO_FATAL_FAILURE(enableVsync(display)); |
| 1417 | |
| 1418 | ASSERT_NO_FATAL_FAILURE(waitForVsync(&receivedDisplay, |
| 1419 | &receivedTimestamp)); |
| 1420 | |
| 1421 | EXPECT_EQ(receivedDisplay, display) << "failed to get correct display"; |
| 1422 | EXPECT_GE(receivedTimestamp, 0) << "failed to get valid timestamp"; |
| 1423 | |
| 1424 | ASSERT_NO_FATAL_FAILURE(disableVsync(display)); |
| 1425 | |
| 1426 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | /* TESTCASE: Tests that the HWC2 cannot enable a vsync for a bad display */ |
| 1431 | TEST_F(Hwc2Test, SET_VSYNC_ENABLED_bad_display) |
| 1432 | { |
| 1433 | hwc2_display_t display; |
| 1434 | hwc2_callback_data_t data = reinterpret_cast<hwc2_callback_data_t>( |
| 1435 | const_cast<char*>("data")); |
| 1436 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1437 | |
| 1438 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 1439 | |
| 1440 | ASSERT_NO_FATAL_FAILURE(registerCallback(HWC2_CALLBACK_VSYNC, data, |
| 1441 | []() { return; })); |
| 1442 | |
| 1443 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_ENABLE, &err)); |
| 1444 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1445 | |
| 1446 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_DISABLE, &err)); |
| 1447 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1448 | } |
| 1449 | |
| 1450 | /* TESTCASE: Tests that the HWC2 cannot enable an invalid vsync value */ |
| 1451 | TEST_F(Hwc2Test, SET_VSYNC_ENABLED_bad_parameter) |
| 1452 | { |
| 1453 | for (auto display : mDisplays) { |
| 1454 | hwc2_callback_data_t data = reinterpret_cast<hwc2_callback_data_t>( |
| 1455 | const_cast<char*>("data")); |
| 1456 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1457 | |
| 1458 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1459 | |
| 1460 | ASSERT_NO_FATAL_FAILURE(registerCallback(HWC2_CALLBACK_VSYNC, data, |
| 1461 | []() { return; })); |
| 1462 | |
| 1463 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_INVALID, |
| 1464 | &err)); |
| 1465 | EXPECT_EQ(err, HWC2_ERROR_BAD_PARAMETER) << "returned wrong error code"; |
| 1466 | |
| 1467 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | /* TESTCASE: Tests that the HWC2 can enable and disable a vsync value multiple |
| 1472 | * times. */ |
| 1473 | TEST_F(Hwc2Test, SET_VSYNC_ENABLED_stress) |
| 1474 | { |
| 1475 | for (auto display : mDisplays) { |
| 1476 | hwc2_callback_data_t data = reinterpret_cast<hwc2_callback_data_t>( |
| 1477 | const_cast<char*>("data")); |
| 1478 | |
| 1479 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1480 | |
| 1481 | ASSERT_NO_FATAL_FAILURE(registerCallback(HWC2_CALLBACK_VSYNC, data, |
| 1482 | []() { return; })); |
| 1483 | |
| 1484 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_DISABLE)); |
| 1485 | |
| 1486 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_ENABLE)); |
| 1487 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_ENABLE)); |
| 1488 | |
| 1489 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_DISABLE)); |
| 1490 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_DISABLE)); |
| 1491 | |
| 1492 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | /* TESTCASE: Tests that the HWC2 can set a vsync enable value when the display |
| 1497 | * is off and no callback is registered. */ |
| 1498 | TEST_F(Hwc2Test, SET_VSYNC_ENABLED_no_callback_no_power) |
| 1499 | { |
| 1500 | const uint secs = 1; |
| 1501 | |
| 1502 | for (auto display : mDisplays) { |
| 1503 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_ENABLE)); |
| 1504 | |
| 1505 | sleep(secs); |
| 1506 | |
| 1507 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_DISABLE)); |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | /* TESTCASE: Tests that the HWC2 can set a vsync enable value when no callback |
| 1512 | * is registered. */ |
| 1513 | TEST_F(Hwc2Test, SET_VSYNC_ENABLED_no_callback) |
| 1514 | { |
| 1515 | const uint secs = 1; |
| 1516 | |
| 1517 | for (auto display : mDisplays) { |
| 1518 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1519 | |
| 1520 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_ENABLE)); |
| 1521 | |
| 1522 | sleep(secs); |
| 1523 | |
| 1524 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_DISABLE)); |
| 1525 | |
| 1526 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1527 | } |
| 1528 | } |
Marissa Wall | dd4087f | 2016-12-15 12:24:52 -0800 | [diff] [blame] | 1529 | |
| 1530 | /* TESTCASE: Tests that the HWC2 returns a display name for each display */ |
| 1531 | TEST_F(Hwc2Test, GET_DISPLAY_NAME) |
| 1532 | { |
| 1533 | for (auto display : mDisplays) { |
| 1534 | std::string name; |
| 1535 | |
| 1536 | ASSERT_NO_FATAL_FAILURE(getDisplayName(display, &name)); |
| 1537 | } |
| 1538 | } |
| 1539 | |
| 1540 | /* TESTCASE: Tests that the HWC2 does not return a display name for a bad |
| 1541 | * display */ |
| 1542 | TEST_F(Hwc2Test, GET_DISPLAY_NAME_bad_display) |
| 1543 | { |
| 1544 | hwc2_display_t display; |
| 1545 | std::string name; |
| 1546 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1547 | |
| 1548 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 1549 | |
| 1550 | ASSERT_NO_FATAL_FAILURE(getDisplayName(display, &name, &err)); |
| 1551 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1552 | } |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 1553 | |
| 1554 | /* TESTCASE: Tests that the HWC2 can set basic composition types. */ |
| 1555 | TEST_F(Hwc2Test, SET_LAYER_COMPOSITION_TYPE) |
| 1556 | { |
| 1557 | ASSERT_NO_FATAL_FAILURE(setLayerProperty(Hwc2TestCoverage::Complete, |
| 1558 | setComposition, advanceComposition)); |
| 1559 | } |
| 1560 | |
| 1561 | /* TESTCASE: Tests that the HWC2 can update a basic composition type on a |
| 1562 | * layer. */ |
| 1563 | TEST_F(Hwc2Test, SET_LAYER_COMPOSITION_TYPE_update) |
| 1564 | { |
| 1565 | ASSERT_NO_FATAL_FAILURE(setLayerPropertyUpdate(Hwc2TestCoverage::Complete, |
| 1566 | setComposition, advanceComposition)); |
| 1567 | } |
| 1568 | |
| 1569 | /* TESTCASE: Tests that the HWC2 cannot set a composition type for a bad layer */ |
| 1570 | TEST_F(Hwc2Test, SET_LAYER_COMPOSITION_TYPE_bad_layer) |
| 1571 | { |
| 1572 | ASSERT_NO_FATAL_FAILURE(setLayerPropertyBadLayer(Hwc2TestCoverage::Default, |
| 1573 | setComposition)); |
| 1574 | } |
| 1575 | |
| 1576 | /* TESTCASE: Tests that the HWC2 cannot set a bad composition type */ |
| 1577 | TEST_F(Hwc2Test, SET_LAYER_COMPOSITION_TYPE_bad_parameter) |
| 1578 | { |
| 1579 | ASSERT_NO_FATAL_FAILURE(setLayerPropertyBadParameter( |
| 1580 | [] (Hwc2Test* test, hwc2_display_t display, hwc2_layer_t layer, |
| 1581 | hwc2_error_t* outErr) { |
| 1582 | |
| 1583 | ASSERT_NO_FATAL_FAILURE(test->setLayerCompositionType(display, |
| 1584 | layer, HWC2_COMPOSITION_INVALID, outErr)); |
| 1585 | } |
| 1586 | )); |
| 1587 | } |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame^] | 1588 | |
| 1589 | /* TESTCASE: Tests that the HWC2 can set a blend mode value of a layer. */ |
| 1590 | TEST_F(Hwc2Test, SET_LAYER_BLEND_MODE) |
| 1591 | { |
| 1592 | ASSERT_NO_FATAL_FAILURE(setLayerProperty(Hwc2TestCoverage::Complete, |
| 1593 | setBlendMode, advanceBlendMode)); |
| 1594 | } |
| 1595 | |
| 1596 | /* TESTCASE: Tests that the HWC2 can update a blend mode value of a layer. */ |
| 1597 | TEST_F(Hwc2Test, SET_LAYER_BLEND_MODE_update) |
| 1598 | { |
| 1599 | ASSERT_NO_FATAL_FAILURE(setLayerPropertyUpdate(Hwc2TestCoverage::Complete, |
| 1600 | setBlendMode, advanceBlendMode)); |
| 1601 | } |
| 1602 | |
| 1603 | /* TESTCASE: Tests that the HWC2 cannot set a blend mode for a bad layer. */ |
| 1604 | TEST_F(Hwc2Test, SET_LAYER_BLEND_MODE_bad_layer) |
| 1605 | { |
| 1606 | ASSERT_NO_FATAL_FAILURE(setLayerPropertyBadLayer(Hwc2TestCoverage::Default, |
| 1607 | setBlendMode)); |
| 1608 | } |
| 1609 | |
| 1610 | /* TESTCASE: Tests that the HWC2 cannot set an invalid blend mode. */ |
| 1611 | TEST_F(Hwc2Test, SET_LAYER_BLEND_MODE_bad_parameter) |
| 1612 | { |
| 1613 | ASSERT_NO_FATAL_FAILURE(setLayerPropertyBadParameter( |
| 1614 | [] (Hwc2Test* test, hwc2_display_t display, hwc2_layer_t layer, |
| 1615 | hwc2_error_t* outErr) { |
| 1616 | |
| 1617 | ASSERT_NO_FATAL_FAILURE(test->setLayerBlendMode(display, |
| 1618 | layer, HWC2_BLEND_MODE_INVALID, outErr)); |
| 1619 | } |
| 1620 | )); |
| 1621 | } |