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 | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 360 | protected: |
| 361 | hwc2_function_pointer_t getFunction(hwc2_function_descriptor_t descriptor) |
| 362 | { |
| 363 | return mHwc2Device->getFunction(mHwc2Device, descriptor); |
| 364 | } |
| 365 | |
| 366 | void getCapabilities(std::vector<hwc2_capability_t>* outCapabilities) |
| 367 | { |
| 368 | uint32_t num = 0; |
| 369 | |
| 370 | mHwc2Device->getCapabilities(mHwc2Device, &num, nullptr); |
| 371 | |
| 372 | outCapabilities->resize(num); |
| 373 | |
| 374 | mHwc2Device->getCapabilities(mHwc2Device, &num, |
| 375 | reinterpret_cast<int32_t*>(outCapabilities->data())); |
| 376 | } |
| 377 | |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 378 | /* Registers a hotplug callback and waits for hotplug callbacks. This |
| 379 | * function will have no effect if called more than once. */ |
| 380 | void populateDisplays() |
| 381 | { |
| 382 | /* Sets the hotplug status to receiving */ |
| 383 | { |
| 384 | std::lock_guard<std::mutex> lock(mHotplugMutex); |
| 385 | |
| 386 | if (mHotplugStatus != Hwc2TestHotplugStatus::Init) |
| 387 | return; |
| 388 | mHotplugStatus = Hwc2TestHotplugStatus::Receiving; |
| 389 | } |
| 390 | |
| 391 | /* Registers the callback. This function call cannot be locked because |
| 392 | * a callback could happen on the same thread */ |
| 393 | ASSERT_NO_FATAL_FAILURE(registerCallback(HWC2_CALLBACK_HOTPLUG, this, |
| 394 | reinterpret_cast<hwc2_function_pointer_t>( |
| 395 | hwc2TestHotplugCallback))); |
| 396 | |
| 397 | /* Waits for hotplug events. If a hotplug event has not come within 1 |
| 398 | * second, stop waiting. */ |
| 399 | std::unique_lock<std::mutex> lock(mHotplugMutex); |
| 400 | |
| 401 | while (mHotplugCv.wait_for(lock, std::chrono::seconds(1)) != |
| 402 | std::cv_status::timeout) { } |
| 403 | |
| 404 | /* Sets the hotplug status to done. Future calls will have no effect */ |
| 405 | mHotplugStatus = Hwc2TestHotplugStatus::Done; |
| 406 | } |
| 407 | |
| 408 | void getBadDisplay(hwc2_display_t* outDisplay) |
| 409 | { |
| 410 | for (hwc2_display_t display = 0; display < UINT64_MAX; display++) { |
| 411 | if (mDisplays.count(display) == 0) { |
| 412 | *outDisplay = display; |
| 413 | return; |
| 414 | } |
| 415 | } |
| 416 | ASSERT_TRUE(false) << "Unable to find bad display. UINT64_MAX displays" |
| 417 | " are registered. This should never happen."; |
| 418 | } |
| 419 | |
Marissa Wall | 1db2e37 | 2016-12-15 12:19:39 -0800 | [diff] [blame] | 420 | /* NOTE: will create min(newlayerCnt, max supported layers) layers */ |
| 421 | void createLayers(hwc2_display_t display, |
| 422 | std::vector<hwc2_layer_t>* outLayers, size_t newLayerCnt) |
| 423 | { |
| 424 | std::vector<hwc2_layer_t> newLayers; |
| 425 | hwc2_layer_t layer; |
| 426 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 427 | |
| 428 | for (size_t i = 0; i < newLayerCnt; i++) { |
| 429 | |
| 430 | EXPECT_NO_FATAL_FAILURE(createLayer(display, &layer, &err)); |
| 431 | if (err == HWC2_ERROR_NO_RESOURCES) |
| 432 | break; |
| 433 | if (err != HWC2_ERROR_NONE) { |
| 434 | newLayers.clear(); |
| 435 | ASSERT_EQ(err, HWC2_ERROR_NONE) << "failed to create layer"; |
| 436 | } |
| 437 | newLayers.push_back(layer); |
| 438 | } |
| 439 | |
| 440 | *outLayers = std::move(newLayers); |
| 441 | } |
| 442 | |
| 443 | void destroyLayers(hwc2_display_t display, |
| 444 | std::vector<hwc2_layer_t>&& layers) |
| 445 | { |
| 446 | for (hwc2_layer_t layer : layers) { |
| 447 | EXPECT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 448 | } |
| 449 | } |
| 450 | |
Marissa Wall | cf935cb | 2016-12-15 12:20:47 -0800 | [diff] [blame] | 451 | void getInvalidConfig(hwc2_display_t display, hwc2_config_t* outConfig) |
| 452 | { |
| 453 | std::vector<hwc2_config_t> configs; |
| 454 | |
| 455 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 456 | |
| 457 | hwc2_config_t CONFIG_MAX = UINT32_MAX; |
| 458 | |
| 459 | ASSERT_LE(configs.size() - 1, CONFIG_MAX) << "every config value" |
| 460 | " (2^32 values) has been taken which shouldn't happen"; |
| 461 | |
| 462 | hwc2_config_t config; |
| 463 | for (config = 0; config < CONFIG_MAX; config++) { |
| 464 | if (std::count(configs.begin(), configs.end(), config) == 0) |
| 465 | break; |
| 466 | } |
| 467 | |
| 468 | *outConfig = config; |
| 469 | } |
| 470 | |
Marissa Wall | 572a1ee | 2016-12-15 12:24:13 -0800 | [diff] [blame] | 471 | void enableVsync(hwc2_display_t display) |
| 472 | { |
| 473 | ASSERT_NO_FATAL_FAILURE(registerCallback(HWC2_CALLBACK_VSYNC, this, |
| 474 | reinterpret_cast<hwc2_function_pointer_t>( |
| 475 | hwc2TestVsyncCallback))); |
| 476 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_ENABLE)); |
| 477 | } |
| 478 | |
| 479 | void disableVsync(hwc2_display_t display) |
| 480 | { |
| 481 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_DISABLE)); |
| 482 | } |
| 483 | |
| 484 | void waitForVsync(hwc2_display_t* outDisplay = nullptr, |
| 485 | int64_t* outTimestamp = nullptr) |
| 486 | { |
| 487 | std::unique_lock<std::mutex> lock(mVsyncMutex); |
| 488 | ASSERT_EQ(mVsyncCv.wait_for(lock, std::chrono::seconds(3)), |
| 489 | std::cv_status::no_timeout) << "timed out attempting to get" |
| 490 | " vsync callback"; |
| 491 | if (outDisplay) |
| 492 | *outDisplay = mVsyncDisplay; |
| 493 | if (outTimestamp) |
| 494 | *outTimestamp = mVsyncTimestamp; |
| 495 | } |
| 496 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame^] | 497 | /* Calls a set property function from Hwc2Test to set a property value from |
| 498 | * Hwc2TestLayer to hwc2_layer_t on hwc2_display_t */ |
| 499 | using TestLayerPropertyFunction = void (*)(Hwc2Test* test, |
| 500 | hwc2_display_t display, hwc2_layer_t layer, |
| 501 | const Hwc2TestLayer& testLayer, hwc2_error_t* outErr); |
| 502 | |
| 503 | /* Calls a set property function from Hwc2Test to set a bad property value |
| 504 | * on hwc2_layer_t on hwc2_display_t */ |
| 505 | using TestLayerPropertyBadLayerFunction = void (*)(Hwc2Test* test, |
| 506 | hwc2_display_t display, hwc2_layer_t layer, |
| 507 | const Hwc2TestLayer& testLayer, hwc2_error_t* outErr); |
| 508 | |
| 509 | /* Calls a set property function from Hwc2Test to set a bad property value |
| 510 | * on hwc2_layer_t on hwc2_display_t */ |
| 511 | using TestLayerPropertyBadParameterFunction = void (*)(Hwc2Test* test, |
| 512 | hwc2_display_t display, hwc2_layer_t layer, hwc2_error_t* outErr); |
| 513 | |
| 514 | /* Advances a property of Hwc2TestLayer */ |
| 515 | using AdvanceProperty = bool (*)(Hwc2TestLayer* testLayer); |
| 516 | |
| 517 | /* For each active display it cycles through each display config and tests |
| 518 | * each property value. It creates a layer, sets the property and then |
| 519 | * destroys the layer */ |
| 520 | void setLayerProperty(Hwc2TestCoverage coverage, |
| 521 | TestLayerPropertyFunction function, AdvanceProperty advance) |
| 522 | { |
| 523 | for (auto display : mDisplays) { |
| 524 | std::vector<hwc2_config_t> configs; |
| 525 | |
| 526 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 527 | |
| 528 | for (auto config : configs) { |
| 529 | hwc2_layer_t layer; |
| 530 | |
| 531 | ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config)); |
| 532 | Hwc2TestLayer testLayer(coverage); |
| 533 | |
| 534 | do { |
| 535 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer)); |
| 536 | |
| 537 | ASSERT_NO_FATAL_FAILURE(function(this, display, layer, |
| 538 | testLayer, nullptr)); |
| 539 | |
| 540 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 541 | } while (advance(&testLayer)); |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | /* For each active display it cycles through each display config and tests |
| 547 | * each property value. It creates a layer, cycles through each property |
| 548 | * value and updates the layer property value and then destroys the layer */ |
| 549 | void setLayerPropertyUpdate(Hwc2TestCoverage coverage, |
| 550 | TestLayerPropertyFunction function, AdvanceProperty advance) |
| 551 | { |
| 552 | for (auto display : mDisplays) { |
| 553 | std::vector<hwc2_config_t> configs; |
| 554 | |
| 555 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 556 | |
| 557 | for (auto config : configs) { |
| 558 | hwc2_layer_t layer; |
| 559 | |
| 560 | ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config)); |
| 561 | Hwc2TestLayer testLayer(coverage); |
| 562 | |
| 563 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer)); |
| 564 | |
| 565 | do { |
| 566 | ASSERT_NO_FATAL_FAILURE(function(this, display, layer, |
| 567 | testLayer, nullptr)); |
| 568 | } while (advance(&testLayer)); |
| 569 | |
| 570 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | /* For each active display it cycles through each display config. |
| 576 | * 1) It attempts to set a valid property value to bad layer handle. |
| 577 | * 2) It creates a layer x and attempts to set a valid property value to |
| 578 | * layer x + 1 |
| 579 | * 3) It destroys the layer x and attempts to set a valid property value to |
| 580 | * the destroyed layer x. |
| 581 | */ |
| 582 | void setLayerPropertyBadLayer(Hwc2TestCoverage coverage, |
| 583 | TestLayerPropertyBadLayerFunction function) |
| 584 | { |
| 585 | for (auto display : mDisplays) { |
| 586 | std::vector<hwc2_config_t> configs; |
| 587 | |
| 588 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 589 | |
| 590 | for (auto config : configs) { |
| 591 | hwc2_layer_t layer = 0; |
| 592 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 593 | |
| 594 | ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config)); |
| 595 | Hwc2TestLayer testLayer(coverage); |
| 596 | |
| 597 | ASSERT_NO_FATAL_FAILURE(function(this, display, layer, |
| 598 | testLayer, &err)); |
| 599 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 600 | |
| 601 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer)); |
| 602 | |
| 603 | ASSERT_NO_FATAL_FAILURE(function(this, display, layer + 1, |
| 604 | testLayer, &err)); |
| 605 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 606 | |
| 607 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 608 | |
| 609 | ASSERT_NO_FATAL_FAILURE(function(this, display, layer, |
| 610 | testLayer, &err)); |
| 611 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 612 | } |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | /* For each active display it cycles through each display config and tests |
| 617 | * each property value. It creates a layer, sets a bad property value and |
| 618 | * then destroys the layer */ |
| 619 | void setLayerPropertyBadParameter(TestLayerPropertyBadParameterFunction function) |
| 620 | { |
| 621 | for (auto display : mDisplays) { |
| 622 | std::vector<hwc2_config_t> configs; |
| 623 | |
| 624 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 625 | |
| 626 | for (auto config : configs) { |
| 627 | hwc2_layer_t layer; |
| 628 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 629 | |
| 630 | ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config)); |
| 631 | |
| 632 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer)); |
| 633 | |
| 634 | ASSERT_NO_FATAL_FAILURE(function(this, display, layer, &err)); |
| 635 | EXPECT_EQ(err, HWC2_ERROR_BAD_PARAMETER) << "returned wrong" |
| 636 | " error code"; |
| 637 | |
| 638 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 639 | } |
| 640 | } |
| 641 | } |
| 642 | |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 643 | hwc2_device_t* mHwc2Device = nullptr; |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 644 | |
| 645 | enum class Hwc2TestHotplugStatus { |
| 646 | Init = 1, |
| 647 | Receiving, |
| 648 | Done, |
| 649 | }; |
| 650 | |
| 651 | std::mutex mHotplugMutex; |
| 652 | std::condition_variable mHotplugCv; |
| 653 | Hwc2TestHotplugStatus mHotplugStatus = Hwc2TestHotplugStatus::Init; |
| 654 | std::unordered_set<hwc2_display_t> mDisplays; |
Marissa Wall | 1db2e37 | 2016-12-15 12:19:39 -0800 | [diff] [blame] | 655 | |
| 656 | /* Store all created layers that have not been destroyed. If an ASSERT_* |
| 657 | * fails, then destroy the layers on exit */ |
| 658 | std::set<std::pair<hwc2_display_t, hwc2_layer_t>> mLayers; |
Marissa Wall | 03c9173 | 2016-12-15 12:23:16 -0800 | [diff] [blame] | 659 | |
| 660 | /* Store the power mode state. If it is not HWC2_POWER_MODE_OFF when |
| 661 | * tearing down the test cases, change it to HWC2_POWER_MODE_OFF */ |
| 662 | std::set<hwc2_display_t> mActiveDisplays; |
Marissa Wall | 572a1ee | 2016-12-15 12:24:13 -0800 | [diff] [blame] | 663 | |
| 664 | std::mutex mVsyncMutex; |
| 665 | std::condition_variable mVsyncCv; |
| 666 | hwc2_display_t mVsyncDisplay; |
| 667 | int64_t mVsyncTimestamp = -1; |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 668 | }; |
| 669 | |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 670 | void hwc2TestHotplugCallback(hwc2_callback_data_t callbackData, |
| 671 | hwc2_display_t display, int32_t connection) |
| 672 | { |
| 673 | if (callbackData) |
| 674 | static_cast<Hwc2Test*>(callbackData)->hotplugCallback(display, |
| 675 | connection); |
| 676 | } |
| 677 | |
Marissa Wall | 572a1ee | 2016-12-15 12:24:13 -0800 | [diff] [blame] | 678 | void hwc2TestVsyncCallback(hwc2_callback_data_t callbackData, |
| 679 | hwc2_display_t display, int64_t timestamp) |
| 680 | { |
| 681 | if (callbackData) |
| 682 | static_cast<Hwc2Test*>(callbackData)->vsyncCallback(display, |
| 683 | timestamp); |
| 684 | } |
| 685 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame^] | 686 | void setComposition(Hwc2Test* test, hwc2_display_t display, hwc2_layer_t layer, |
| 687 | const Hwc2TestLayer& testLayer, hwc2_error_t* outErr) |
| 688 | { |
| 689 | hwc2_composition_t composition = testLayer.getComposition(); |
| 690 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 691 | |
| 692 | ASSERT_NO_FATAL_FAILURE(test->setLayerCompositionType(display, layer, |
| 693 | composition, &err)); |
| 694 | if (outErr) { |
| 695 | *outErr = err; |
| 696 | return; |
| 697 | } |
| 698 | |
| 699 | if (composition != HWC2_COMPOSITION_SIDEBAND) { |
| 700 | EXPECT_EQ(err, HWC2_ERROR_NONE) << "returned wrong error code"; |
| 701 | } else { |
| 702 | EXPECT_TRUE(err == HWC2_ERROR_NONE || err == HWC2_ERROR_UNSUPPORTED) |
| 703 | << "returned wrong error code"; |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | bool advanceComposition(Hwc2TestLayer* testLayer) |
| 708 | { |
| 709 | return testLayer->advanceComposition(); |
| 710 | } |
| 711 | |
Marissa Wall | 4d60005 | 2016-12-15 12:16:01 -0800 | [diff] [blame] | 712 | |
| 713 | static const std::array<hwc2_function_descriptor_t, 42> requiredFunctions = {{ |
| 714 | HWC2_FUNCTION_ACCEPT_DISPLAY_CHANGES, |
| 715 | HWC2_FUNCTION_CREATE_LAYER, |
| 716 | HWC2_FUNCTION_CREATE_VIRTUAL_DISPLAY, |
| 717 | HWC2_FUNCTION_DESTROY_LAYER, |
| 718 | HWC2_FUNCTION_DESTROY_VIRTUAL_DISPLAY, |
| 719 | HWC2_FUNCTION_DUMP, |
| 720 | HWC2_FUNCTION_GET_ACTIVE_CONFIG, |
| 721 | HWC2_FUNCTION_GET_CHANGED_COMPOSITION_TYPES, |
| 722 | HWC2_FUNCTION_GET_CLIENT_TARGET_SUPPORT, |
| 723 | HWC2_FUNCTION_GET_COLOR_MODES, |
| 724 | HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE, |
| 725 | HWC2_FUNCTION_GET_DISPLAY_CONFIGS, |
| 726 | HWC2_FUNCTION_GET_DISPLAY_NAME, |
| 727 | HWC2_FUNCTION_GET_DISPLAY_REQUESTS, |
| 728 | HWC2_FUNCTION_GET_DISPLAY_TYPE, |
| 729 | HWC2_FUNCTION_GET_DOZE_SUPPORT, |
| 730 | HWC2_FUNCTION_GET_HDR_CAPABILITIES, |
| 731 | HWC2_FUNCTION_GET_MAX_VIRTUAL_DISPLAY_COUNT, |
| 732 | HWC2_FUNCTION_GET_RELEASE_FENCES, |
| 733 | HWC2_FUNCTION_PRESENT_DISPLAY, |
| 734 | HWC2_FUNCTION_REGISTER_CALLBACK, |
| 735 | HWC2_FUNCTION_SET_ACTIVE_CONFIG, |
| 736 | HWC2_FUNCTION_SET_CLIENT_TARGET, |
| 737 | HWC2_FUNCTION_SET_COLOR_MODE, |
| 738 | HWC2_FUNCTION_SET_COLOR_TRANSFORM, |
| 739 | HWC2_FUNCTION_SET_CURSOR_POSITION, |
| 740 | HWC2_FUNCTION_SET_LAYER_BLEND_MODE, |
| 741 | HWC2_FUNCTION_SET_LAYER_BUFFER, |
| 742 | HWC2_FUNCTION_SET_LAYER_COLOR, |
| 743 | HWC2_FUNCTION_SET_LAYER_COMPOSITION_TYPE, |
| 744 | HWC2_FUNCTION_SET_LAYER_DATASPACE, |
| 745 | HWC2_FUNCTION_SET_LAYER_DISPLAY_FRAME, |
| 746 | HWC2_FUNCTION_SET_LAYER_PLANE_ALPHA, |
| 747 | HWC2_FUNCTION_SET_LAYER_SOURCE_CROP, |
| 748 | HWC2_FUNCTION_SET_LAYER_SURFACE_DAMAGE, |
| 749 | HWC2_FUNCTION_SET_LAYER_TRANSFORM, |
| 750 | HWC2_FUNCTION_SET_LAYER_VISIBLE_REGION, |
| 751 | HWC2_FUNCTION_SET_LAYER_Z_ORDER, |
| 752 | HWC2_FUNCTION_SET_OUTPUT_BUFFER, |
| 753 | HWC2_FUNCTION_SET_POWER_MODE, |
| 754 | HWC2_FUNCTION_SET_VSYNC_ENABLED, |
| 755 | HWC2_FUNCTION_VALIDATE_DISPLAY, |
| 756 | }}; |
| 757 | |
| 758 | /* TESTCASE: Tests that the HWC2 supports all required functions. */ |
| 759 | TEST_F(Hwc2Test, GET_FUNCTION) |
| 760 | { |
| 761 | for (hwc2_function_descriptor_t descriptor : requiredFunctions) { |
| 762 | hwc2_function_pointer_t pfn = getFunction(descriptor); |
| 763 | EXPECT_TRUE(pfn) << "failed to get function " |
| 764 | << getFunctionDescriptorName(descriptor); |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | /* TESTCASE: Tests that the HWC2 fails to retrieve and invalid function. */ |
| 769 | TEST_F(Hwc2Test, GET_FUNCTION_invalid_function) |
| 770 | { |
| 771 | hwc2_function_pointer_t pfn = getFunction(HWC2_FUNCTION_INVALID); |
| 772 | EXPECT_FALSE(pfn) << "failed to get invalid function"; |
| 773 | } |
| 774 | |
| 775 | /* TESTCASE: Tests that the HWC2 does not return an invalid capability. */ |
| 776 | TEST_F(Hwc2Test, GET_CAPABILITIES) |
| 777 | { |
| 778 | std::vector<hwc2_capability_t> capabilities; |
| 779 | |
| 780 | getCapabilities(&capabilities); |
| 781 | |
| 782 | EXPECT_EQ(std::count(capabilities.begin(), capabilities.end(), |
| 783 | HWC2_CAPABILITY_INVALID), 0); |
| 784 | } |
Marissa Wall | a4b0148 | 2017-02-17 20:52:03 -0800 | [diff] [blame] | 785 | |
| 786 | static const std::array<hwc2_callback_descriptor_t, 3> callbackDescriptors = {{ |
| 787 | HWC2_CALLBACK_HOTPLUG, |
| 788 | HWC2_CALLBACK_REFRESH, |
| 789 | HWC2_CALLBACK_VSYNC, |
| 790 | }}; |
| 791 | |
| 792 | /* TESTCASE: Tests that the HWC2 can successfully register all required |
| 793 | * callback functions. */ |
| 794 | TEST_F(Hwc2Test, REGISTER_CALLBACK) |
| 795 | { |
| 796 | hwc2_callback_data_t data = reinterpret_cast<hwc2_callback_data_t>( |
| 797 | const_cast<char*>("data")); |
| 798 | |
| 799 | for (auto descriptor : callbackDescriptors) { |
| 800 | ASSERT_NO_FATAL_FAILURE(registerCallback(descriptor, data, |
| 801 | []() { return; })); |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | /* TESTCASE: Test that the HWC2 fails to register invalid callbacks. */ |
| 806 | TEST_F(Hwc2Test, REGISTER_CALLBACK_bad_parameter) |
| 807 | { |
| 808 | hwc2_callback_data_t data = reinterpret_cast<hwc2_callback_data_t>( |
| 809 | const_cast<char*>("data")); |
| 810 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 811 | |
| 812 | ASSERT_NO_FATAL_FAILURE(registerCallback(HWC2_CALLBACK_INVALID, data, |
| 813 | []() { return; }, &err)); |
| 814 | EXPECT_EQ(err, HWC2_ERROR_BAD_PARAMETER) << "returned wrong error code"; |
| 815 | } |
| 816 | |
| 817 | /* TESTCASE: Tests that the HWC2 can register a callback with null data. */ |
| 818 | TEST_F(Hwc2Test, REGISTER_CALLBACK_null_data) |
| 819 | { |
| 820 | hwc2_callback_data_t data = nullptr; |
| 821 | |
| 822 | for (auto descriptor : callbackDescriptors) { |
| 823 | ASSERT_NO_FATAL_FAILURE(registerCallback(descriptor, data, |
| 824 | []() { return; })); |
| 825 | } |
| 826 | } |
Marissa Wall | cfb9a07 | 2017-02-17 20:53:18 -0800 | [diff] [blame] | 827 | |
| 828 | /* TESTCASE: Tests that the HWC2 returns the correct display type for each |
| 829 | * physical display. */ |
| 830 | TEST_F(Hwc2Test, GET_DISPLAY_TYPE) |
| 831 | { |
| 832 | for (auto display : mDisplays) { |
| 833 | hwc2_display_type_t type; |
| 834 | |
| 835 | ASSERT_NO_FATAL_FAILURE(getDisplayType(display, &type)); |
| 836 | EXPECT_EQ(type, HWC2_DISPLAY_TYPE_PHYSICAL) << "failed to return" |
| 837 | " correct display type"; |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | /* TESTCASE: Tests that the HWC2 returns an error when the display type of a bad |
| 842 | * display is requested. */ |
| 843 | TEST_F(Hwc2Test, GET_DISPLAY_TYPE_bad_display) |
| 844 | { |
| 845 | hwc2_display_t display; |
| 846 | hwc2_display_type_t type; |
| 847 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 848 | |
| 849 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 850 | |
| 851 | ASSERT_NO_FATAL_FAILURE(getDisplayType(display, &type, &err)); |
| 852 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 853 | } |
Marissa Wall | 1db2e37 | 2016-12-15 12:19:39 -0800 | [diff] [blame] | 854 | |
| 855 | /* TESTCASE: Tests that the HWC2 can create and destroy layers. */ |
| 856 | TEST_F(Hwc2Test, CREATE_DESTROY_LAYER) |
| 857 | { |
| 858 | for (auto display : mDisplays) { |
| 859 | hwc2_layer_t layer; |
| 860 | |
| 861 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer)); |
| 862 | |
| 863 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | /* TESTCASE: Tests that the HWC2 cannot create a layer for a bad display */ |
| 868 | TEST_F(Hwc2Test, CREATE_LAYER_bad_display) |
| 869 | { |
| 870 | hwc2_display_t display; |
| 871 | hwc2_layer_t layer; |
| 872 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 873 | |
| 874 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 875 | |
| 876 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer, &err)); |
| 877 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 878 | } |
| 879 | |
| 880 | /* TESTCASE: Tests that the HWC2 will either support a large number of resources |
| 881 | * or will return no resources. */ |
| 882 | TEST_F(Hwc2Test, CREATE_LAYER_no_resources) |
| 883 | { |
| 884 | const size_t layerCnt = 1000; |
| 885 | |
| 886 | for (auto display : mDisplays) { |
| 887 | std::vector<hwc2_layer_t> layers; |
| 888 | |
| 889 | ASSERT_NO_FATAL_FAILURE(createLayers(display, &layers, layerCnt)); |
| 890 | |
| 891 | ASSERT_NO_FATAL_FAILURE(destroyLayers(display, std::move(layers))); |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | /* TESTCASE: Tests that the HWC2 cannot destroy a layer for a bad display */ |
| 896 | TEST_F(Hwc2Test, DESTROY_LAYER_bad_display) |
| 897 | { |
| 898 | hwc2_display_t badDisplay; |
| 899 | |
| 900 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&badDisplay)); |
| 901 | |
| 902 | for (auto display : mDisplays) { |
| 903 | hwc2_layer_t layer = 0; |
| 904 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 905 | |
| 906 | ASSERT_NO_FATAL_FAILURE(destroyLayer(badDisplay, layer, &err)); |
| 907 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 908 | |
| 909 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer)); |
| 910 | |
| 911 | ASSERT_NO_FATAL_FAILURE(destroyLayer(badDisplay, layer, &err)); |
| 912 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 913 | |
| 914 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | /* TESTCASE: Tests that the HWC2 cannot destory a bad layer */ |
| 919 | TEST_F(Hwc2Test, DESTROY_LAYER_bad_layer) |
| 920 | { |
| 921 | for (auto display : mDisplays) { |
| 922 | hwc2_layer_t layer; |
| 923 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 924 | |
| 925 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, UINT64_MAX / 2, &err)); |
| 926 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 927 | |
| 928 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, 0, &err)); |
| 929 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 930 | |
| 931 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, UINT64_MAX - 1, &err)); |
| 932 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 933 | |
| 934 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, 1, &err)); |
| 935 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 936 | |
| 937 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, UINT64_MAX, &err)); |
| 938 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 939 | |
| 940 | ASSERT_NO_FATAL_FAILURE(createLayer(display, &layer)); |
| 941 | |
| 942 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer + 1, &err)); |
| 943 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 944 | |
| 945 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer)); |
| 946 | |
| 947 | ASSERT_NO_FATAL_FAILURE(destroyLayer(display, layer, &err)); |
| 948 | EXPECT_EQ(err, HWC2_ERROR_BAD_LAYER) << "returned wrong error code"; |
| 949 | } |
| 950 | } |
Marissa Wall | cf935cb | 2016-12-15 12:20:47 -0800 | [diff] [blame] | 951 | |
| 952 | static const std::array<hwc2_attribute_t, 2> requiredAttributes = {{ |
| 953 | HWC2_ATTRIBUTE_WIDTH, |
| 954 | HWC2_ATTRIBUTE_HEIGHT, |
| 955 | }}; |
| 956 | |
| 957 | static const std::array<hwc2_attribute_t, 3> optionalAttributes = {{ |
| 958 | HWC2_ATTRIBUTE_VSYNC_PERIOD, |
| 959 | HWC2_ATTRIBUTE_DPI_X, |
| 960 | HWC2_ATTRIBUTE_DPI_Y, |
| 961 | }}; |
| 962 | |
| 963 | /* TESTCASE: Tests that the HWC2 can return display attributes for a valid |
| 964 | * config. */ |
| 965 | TEST_F(Hwc2Test, GET_DISPLAY_ATTRIBUTE) |
| 966 | { |
| 967 | for (auto display : mDisplays) { |
| 968 | std::vector<hwc2_config_t> configs; |
| 969 | |
| 970 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 971 | |
| 972 | for (auto config : configs) { |
| 973 | int32_t value; |
| 974 | |
| 975 | for (auto attribute : requiredAttributes) { |
| 976 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, |
| 977 | attribute, &value)); |
| 978 | EXPECT_GE(value, 0) << "missing required attribute " |
| 979 | << getAttributeName(attribute) << " for config " |
| 980 | << config; |
| 981 | } |
| 982 | for (auto attribute : optionalAttributes) { |
| 983 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, |
| 984 | attribute, &value)); |
| 985 | } |
| 986 | } |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | /* TESTCASE: Tests that the HWC2 will return a value of -1 for an invalid |
| 991 | * attribute */ |
| 992 | TEST_F(Hwc2Test, GET_DISPLAY_ATTRIBUTE_invalid_attribute) |
| 993 | { |
| 994 | const hwc2_attribute_t attribute = HWC2_ATTRIBUTE_INVALID; |
| 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 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1004 | |
| 1005 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, |
| 1006 | attribute, &value, &err)); |
| 1007 | EXPECT_EQ(value, -1) << "failed to return -1 for an invalid" |
| 1008 | " attribute for config " << config; |
| 1009 | } |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | /* TESTCASE: Tests that the HWC2 will fail to get attributes for a bad display */ |
| 1014 | TEST_F(Hwc2Test, GET_DISPLAY_ATTRIBUTE_bad_display) |
| 1015 | { |
| 1016 | hwc2_display_t display; |
| 1017 | const hwc2_config_t config = 0; |
| 1018 | int32_t value; |
| 1019 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1020 | |
| 1021 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 1022 | |
| 1023 | for (auto attribute : requiredAttributes) { |
| 1024 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, attribute, |
| 1025 | &value, &err)); |
| 1026 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1027 | } |
| 1028 | |
| 1029 | for (auto attribute : optionalAttributes) { |
| 1030 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, attribute, |
| 1031 | &value, &err)); |
| 1032 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | /* TESTCASE: Tests that the HWC2 will fail to get attributes for a bad config */ |
| 1037 | TEST_F(Hwc2Test, GET_DISPLAY_ATTRIBUTE_bad_config) |
| 1038 | { |
| 1039 | for (auto display : mDisplays) { |
| 1040 | hwc2_config_t config; |
| 1041 | int32_t value; |
| 1042 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1043 | |
| 1044 | ASSERT_NO_FATAL_FAILURE(getInvalidConfig(display, &config)); |
| 1045 | |
| 1046 | for (auto attribute : requiredAttributes) { |
| 1047 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, |
| 1048 | attribute, &value, &err)); |
| 1049 | EXPECT_EQ(err, HWC2_ERROR_BAD_CONFIG) << "returned wrong error code"; |
| 1050 | } |
| 1051 | |
| 1052 | for (auto attribute : optionalAttributes) { |
| 1053 | ASSERT_NO_FATAL_FAILURE(getDisplayAttribute(display, config, |
| 1054 | attribute, &value, &err)); |
| 1055 | EXPECT_EQ(err, HWC2_ERROR_BAD_CONFIG) << "returned wrong error code"; |
| 1056 | } |
| 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | /* TESTCASE: Tests that the HWC2 will get display configs for active displays */ |
| 1061 | TEST_F(Hwc2Test, GET_DISPLAY_CONFIGS) |
| 1062 | { |
| 1063 | for (auto display : mDisplays) { |
| 1064 | std::vector<hwc2_config_t> configs; |
| 1065 | |
| 1066 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | /* TESTCASE: Tests that the HWC2 will not get display configs for bad displays */ |
| 1071 | TEST_F(Hwc2Test, GET_DISPLAY_CONFIGS_bad_display) |
| 1072 | { |
| 1073 | hwc2_display_t display; |
| 1074 | std::vector<hwc2_config_t> configs; |
| 1075 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1076 | |
| 1077 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 1078 | |
| 1079 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs, &err)); |
| 1080 | |
| 1081 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1082 | EXPECT_TRUE(configs.empty()) << "returned configs for bad display"; |
| 1083 | } |
| 1084 | |
| 1085 | /* TESTCASE: Tests that the HWC2 will return the same config list multiple |
| 1086 | * times in a row. */ |
| 1087 | TEST_F(Hwc2Test, GET_DISPLAY_CONFIGS_same) |
| 1088 | { |
| 1089 | for (auto display : mDisplays) { |
| 1090 | std::vector<hwc2_config_t> configs1, configs2; |
| 1091 | |
| 1092 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs1)); |
| 1093 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs2)); |
| 1094 | |
| 1095 | EXPECT_TRUE(std::is_permutation(configs1.begin(), configs1.end(), |
| 1096 | configs2.begin())) << "returned two different config sets"; |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | /* TESTCASE: Tests that the HWC2 does not return duplicate display configs */ |
| 1101 | TEST_F(Hwc2Test, GET_DISPLAY_CONFIGS_duplicate) |
| 1102 | { |
| 1103 | for (auto display : mDisplays) { |
| 1104 | std::vector<hwc2_config_t> configs; |
| 1105 | |
| 1106 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 1107 | |
| 1108 | std::unordered_set<hwc2_config_t> configsSet(configs.begin(), |
| 1109 | configs.end()); |
| 1110 | EXPECT_EQ(configs.size(), configsSet.size()) << "returned duplicate" |
| 1111 | " configs"; |
| 1112 | } |
| 1113 | } |
Marissa Wall | 93dc04f | 2016-12-15 12:21:46 -0800 | [diff] [blame] | 1114 | |
| 1115 | /* TESTCASE: Tests that the HWC2 returns the active config for a display */ |
| 1116 | TEST_F(Hwc2Test, GET_ACTIVE_CONFIG) |
| 1117 | { |
| 1118 | for (auto display : mDisplays) { |
| 1119 | std::vector<hwc2_config_t> configs; |
| 1120 | |
| 1121 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 1122 | |
| 1123 | for (auto config : configs) { |
| 1124 | hwc2_config_t activeConfig; |
| 1125 | |
| 1126 | ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config)); |
| 1127 | ASSERT_NO_FATAL_FAILURE(getActiveConfig(display, &activeConfig)); |
| 1128 | |
| 1129 | EXPECT_EQ(activeConfig, config) << "failed to get active config"; |
| 1130 | } |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | /* TESTCASE: Tests that the HWC2 does not return an active config for a bad |
| 1135 | * display. */ |
| 1136 | TEST_F(Hwc2Test, GET_ACTIVE_CONFIG_bad_display) |
| 1137 | { |
| 1138 | hwc2_display_t display; |
| 1139 | hwc2_config_t activeConfig; |
| 1140 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1141 | |
| 1142 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 1143 | |
| 1144 | ASSERT_NO_FATAL_FAILURE(getActiveConfig(display, &activeConfig, &err)); |
| 1145 | |
| 1146 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1147 | } |
| 1148 | |
| 1149 | /* TESTCASE: Tests that the HWC2 either begins with a valid active config |
| 1150 | * or returns an error when getActiveConfig is called. */ |
| 1151 | TEST_F(Hwc2Test, GET_ACTIVE_CONFIG_bad_config) |
| 1152 | { |
| 1153 | for (auto display : mDisplays) { |
| 1154 | std::vector<hwc2_config_t> configs; |
| 1155 | hwc2_config_t activeConfig; |
| 1156 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1157 | |
| 1158 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 1159 | |
| 1160 | if (configs.empty()) |
| 1161 | return; |
| 1162 | |
| 1163 | ASSERT_NO_FATAL_FAILURE(getActiveConfig(display, &activeConfig, &err)); |
| 1164 | if (err == HWC2_ERROR_NONE) { |
| 1165 | EXPECT_NE(std::count(configs.begin(), configs.end(), |
| 1166 | activeConfig), 0) << "active config is not found in " |
| 1167 | " configs for display"; |
| 1168 | } else { |
| 1169 | EXPECT_EQ(err, HWC2_ERROR_BAD_CONFIG) << "returned wrong error code"; |
| 1170 | } |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | /* TESTCASE: Tests that the HWC2 can set every display config as an active |
| 1175 | * config */ |
| 1176 | TEST_F(Hwc2Test, SET_ACTIVE_CONFIG) |
| 1177 | { |
| 1178 | for (auto display : mDisplays) { |
| 1179 | std::vector<hwc2_config_t> configs; |
| 1180 | |
| 1181 | ASSERT_NO_FATAL_FAILURE(getDisplayConfigs(display, &configs)); |
| 1182 | |
| 1183 | for (auto config : configs) { |
| 1184 | EXPECT_NO_FATAL_FAILURE(setActiveConfig(display, config)); |
| 1185 | } |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | /* TESTCASE: Tests that the HWC2 cannot set an active config for a bad display */ |
| 1190 | TEST_F(Hwc2Test, SET_ACTIVE_CONFIG_bad_display) |
| 1191 | { |
| 1192 | hwc2_display_t display; |
| 1193 | const hwc2_config_t config = 0; |
| 1194 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1195 | |
| 1196 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 1197 | |
| 1198 | ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config, &err)); |
| 1199 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1200 | } |
| 1201 | |
| 1202 | /* TESTCASE: Tests that the HWC2 cannot set an invalid active config */ |
| 1203 | TEST_F(Hwc2Test, SET_ACTIVE_CONFIG_bad_config) |
| 1204 | { |
| 1205 | for (auto display : mDisplays) { |
| 1206 | hwc2_config_t config; |
| 1207 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1208 | |
| 1209 | ASSERT_NO_FATAL_FAILURE(getInvalidConfig(display, &config)); |
| 1210 | |
| 1211 | ASSERT_NO_FATAL_FAILURE(setActiveConfig(display, config, &err)); |
| 1212 | EXPECT_EQ(err, HWC2_ERROR_BAD_CONFIG) << "returned wrong error code"; |
| 1213 | } |
| 1214 | } |
Marissa Wall | 03c9173 | 2016-12-15 12:23:16 -0800 | [diff] [blame] | 1215 | |
| 1216 | /* TESTCASE: Tests that the HWC2 returns a valid value for getDozeSupport. */ |
| 1217 | TEST_F(Hwc2Test, GET_DOZE_SUPPORT) |
| 1218 | { |
| 1219 | for (auto display : mDisplays) { |
| 1220 | int32_t support = -1; |
| 1221 | |
| 1222 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support)); |
| 1223 | |
| 1224 | EXPECT_TRUE(support == 0 || support == 1) << "invalid doze support value"; |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | /* TESTCASE: Tests that the HWC2 cannot get doze support for a bad display. */ |
| 1229 | TEST_F(Hwc2Test, GET_DOZE_SUPPORT_bad_display) |
| 1230 | { |
| 1231 | hwc2_display_t display; |
| 1232 | int32_t support = -1; |
| 1233 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1234 | |
| 1235 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 1236 | |
| 1237 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support, &err)); |
| 1238 | |
| 1239 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1240 | } |
| 1241 | |
| 1242 | /* TESTCASE: Tests that the HWC2 can set all supported power modes */ |
| 1243 | TEST_F(Hwc2Test, SET_POWER_MODE) |
| 1244 | { |
| 1245 | for (auto display : mDisplays) { |
| 1246 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1247 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1248 | |
| 1249 | int32_t support = -1; |
| 1250 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support)); |
| 1251 | if (support != 1) |
| 1252 | return; |
| 1253 | |
| 1254 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE)); |
| 1255 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, |
| 1256 | HWC2_POWER_MODE_DOZE_SUSPEND)); |
| 1257 | |
| 1258 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | /* TESTCASE: Tests that the HWC2 cannot set a power mode for a bad display. */ |
| 1263 | TEST_F(Hwc2Test, SET_POWER_MODE_bad_display) |
| 1264 | { |
| 1265 | hwc2_display_t display; |
| 1266 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1267 | |
| 1268 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 1269 | |
| 1270 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON, &err)); |
| 1271 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1272 | |
| 1273 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF, &err)); |
| 1274 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1275 | |
| 1276 | int32_t support = -1; |
| 1277 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support, &err)); |
| 1278 | if (support != 1) |
| 1279 | return; |
| 1280 | |
| 1281 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE, &err)); |
| 1282 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1283 | |
| 1284 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE_SUSPEND, |
| 1285 | &err)); |
| 1286 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1287 | } |
| 1288 | |
| 1289 | /* TESTCASE: Tests that the HWC2 cannot set an invalid power mode value. */ |
| 1290 | TEST_F(Hwc2Test, SET_POWER_MODE_bad_parameter) |
| 1291 | { |
| 1292 | for (auto display : mDisplays) { |
| 1293 | hwc2_power_mode_t mode = static_cast<hwc2_power_mode_t>( |
| 1294 | HWC2_POWER_MODE_DOZE_SUSPEND + 1); |
| 1295 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1296 | |
| 1297 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, mode, &err)); |
| 1298 | EXPECT_EQ(err, HWC2_ERROR_BAD_PARAMETER) << "returned wrong error code " |
| 1299 | << mode; |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | /* TESTCASE: Tests that the HWC2 will return unsupported if it does not support |
| 1304 | * an optional power mode. */ |
| 1305 | TEST_F(Hwc2Test, SET_POWER_MODE_unsupported) |
| 1306 | { |
| 1307 | for (auto display : mDisplays) { |
| 1308 | int32_t support = -1; |
| 1309 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1310 | |
| 1311 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support, &err)); |
| 1312 | if (support == 1) |
| 1313 | return; |
| 1314 | |
| 1315 | ASSERT_EQ(support, 0) << "invalid doze support value"; |
| 1316 | |
| 1317 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE, |
| 1318 | &err)); |
| 1319 | EXPECT_EQ(err, HWC2_ERROR_UNSUPPORTED) << "returned wrong error code"; |
| 1320 | |
| 1321 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, |
| 1322 | HWC2_POWER_MODE_DOZE_SUSPEND, &err)); |
| 1323 | EXPECT_EQ(err, HWC2_ERROR_UNSUPPORTED) << "returned wrong error code"; |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | /* TESTCASE: Tests that the HWC2 can set the same power mode multiple times. */ |
| 1328 | TEST_F(Hwc2Test, SET_POWER_MODE_stress) |
| 1329 | { |
| 1330 | for (auto display : mDisplays) { |
| 1331 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1332 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1333 | |
| 1334 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1335 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1336 | |
| 1337 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1338 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1339 | |
| 1340 | int32_t support = -1; |
| 1341 | ASSERT_NO_FATAL_FAILURE(getDozeSupport(display, &support)); |
| 1342 | if (support != 1) |
| 1343 | return; |
| 1344 | |
| 1345 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE)); |
| 1346 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_DOZE)); |
| 1347 | |
| 1348 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, |
| 1349 | HWC2_POWER_MODE_DOZE_SUSPEND)); |
| 1350 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, |
| 1351 | HWC2_POWER_MODE_DOZE_SUSPEND)); |
| 1352 | |
| 1353 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1354 | } |
| 1355 | } |
Marissa Wall | 572a1ee | 2016-12-15 12:24:13 -0800 | [diff] [blame] | 1356 | |
| 1357 | /* TESTCASE: Tests that the HWC2 can enable and disable vsync on active |
| 1358 | * displays */ |
| 1359 | TEST_F(Hwc2Test, SET_VSYNC_ENABLED) |
| 1360 | { |
| 1361 | for (auto display : mDisplays) { |
| 1362 | hwc2_callback_data_t data = reinterpret_cast<hwc2_callback_data_t>( |
| 1363 | const_cast<char*>("data")); |
| 1364 | |
| 1365 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1366 | |
| 1367 | ASSERT_NO_FATAL_FAILURE(registerCallback(HWC2_CALLBACK_VSYNC, data, |
| 1368 | []() { return; })); |
| 1369 | |
| 1370 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_ENABLE)); |
| 1371 | |
| 1372 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_DISABLE)); |
| 1373 | |
| 1374 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1375 | } |
| 1376 | } |
| 1377 | |
| 1378 | /* TESTCASE: Tests that the HWC2 issues a valid vsync callback. */ |
| 1379 | TEST_F(Hwc2Test, SET_VSYNC_ENABLED_callback) |
| 1380 | { |
| 1381 | for (auto display : mDisplays) { |
| 1382 | hwc2_display_t receivedDisplay; |
| 1383 | int64_t receivedTimestamp; |
| 1384 | |
| 1385 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1386 | |
| 1387 | ASSERT_NO_FATAL_FAILURE(enableVsync(display)); |
| 1388 | |
| 1389 | ASSERT_NO_FATAL_FAILURE(waitForVsync(&receivedDisplay, |
| 1390 | &receivedTimestamp)); |
| 1391 | |
| 1392 | EXPECT_EQ(receivedDisplay, display) << "failed to get correct display"; |
| 1393 | EXPECT_GE(receivedTimestamp, 0) << "failed to get valid timestamp"; |
| 1394 | |
| 1395 | ASSERT_NO_FATAL_FAILURE(disableVsync(display)); |
| 1396 | |
| 1397 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | /* TESTCASE: Tests that the HWC2 cannot enable a vsync for a bad display */ |
| 1402 | TEST_F(Hwc2Test, SET_VSYNC_ENABLED_bad_display) |
| 1403 | { |
| 1404 | hwc2_display_t display; |
| 1405 | hwc2_callback_data_t data = reinterpret_cast<hwc2_callback_data_t>( |
| 1406 | const_cast<char*>("data")); |
| 1407 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1408 | |
| 1409 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 1410 | |
| 1411 | ASSERT_NO_FATAL_FAILURE(registerCallback(HWC2_CALLBACK_VSYNC, data, |
| 1412 | []() { return; })); |
| 1413 | |
| 1414 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_ENABLE, &err)); |
| 1415 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1416 | |
| 1417 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_DISABLE, &err)); |
| 1418 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1419 | } |
| 1420 | |
| 1421 | /* TESTCASE: Tests that the HWC2 cannot enable an invalid vsync value */ |
| 1422 | TEST_F(Hwc2Test, SET_VSYNC_ENABLED_bad_parameter) |
| 1423 | { |
| 1424 | for (auto display : mDisplays) { |
| 1425 | hwc2_callback_data_t data = reinterpret_cast<hwc2_callback_data_t>( |
| 1426 | const_cast<char*>("data")); |
| 1427 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1428 | |
| 1429 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1430 | |
| 1431 | ASSERT_NO_FATAL_FAILURE(registerCallback(HWC2_CALLBACK_VSYNC, data, |
| 1432 | []() { return; })); |
| 1433 | |
| 1434 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_INVALID, |
| 1435 | &err)); |
| 1436 | EXPECT_EQ(err, HWC2_ERROR_BAD_PARAMETER) << "returned wrong error code"; |
| 1437 | |
| 1438 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | /* TESTCASE: Tests that the HWC2 can enable and disable a vsync value multiple |
| 1443 | * times. */ |
| 1444 | TEST_F(Hwc2Test, SET_VSYNC_ENABLED_stress) |
| 1445 | { |
| 1446 | for (auto display : mDisplays) { |
| 1447 | hwc2_callback_data_t data = reinterpret_cast<hwc2_callback_data_t>( |
| 1448 | const_cast<char*>("data")); |
| 1449 | |
| 1450 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1451 | |
| 1452 | ASSERT_NO_FATAL_FAILURE(registerCallback(HWC2_CALLBACK_VSYNC, data, |
| 1453 | []() { return; })); |
| 1454 | |
| 1455 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_DISABLE)); |
| 1456 | |
| 1457 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_ENABLE)); |
| 1458 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_ENABLE)); |
| 1459 | |
| 1460 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_DISABLE)); |
| 1461 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_DISABLE)); |
| 1462 | |
| 1463 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1464 | } |
| 1465 | } |
| 1466 | |
| 1467 | /* TESTCASE: Tests that the HWC2 can set a vsync enable value when the display |
| 1468 | * is off and no callback is registered. */ |
| 1469 | TEST_F(Hwc2Test, SET_VSYNC_ENABLED_no_callback_no_power) |
| 1470 | { |
| 1471 | const uint secs = 1; |
| 1472 | |
| 1473 | for (auto display : mDisplays) { |
| 1474 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_ENABLE)); |
| 1475 | |
| 1476 | sleep(secs); |
| 1477 | |
| 1478 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_DISABLE)); |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | /* TESTCASE: Tests that the HWC2 can set a vsync enable value when no callback |
| 1483 | * is registered. */ |
| 1484 | TEST_F(Hwc2Test, SET_VSYNC_ENABLED_no_callback) |
| 1485 | { |
| 1486 | const uint secs = 1; |
| 1487 | |
| 1488 | for (auto display : mDisplays) { |
| 1489 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_ON)); |
| 1490 | |
| 1491 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_ENABLE)); |
| 1492 | |
| 1493 | sleep(secs); |
| 1494 | |
| 1495 | ASSERT_NO_FATAL_FAILURE(setVsyncEnabled(display, HWC2_VSYNC_DISABLE)); |
| 1496 | |
| 1497 | ASSERT_NO_FATAL_FAILURE(setPowerMode(display, HWC2_POWER_MODE_OFF)); |
| 1498 | } |
| 1499 | } |
Marissa Wall | dd4087f | 2016-12-15 12:24:52 -0800 | [diff] [blame] | 1500 | |
| 1501 | /* TESTCASE: Tests that the HWC2 returns a display name for each display */ |
| 1502 | TEST_F(Hwc2Test, GET_DISPLAY_NAME) |
| 1503 | { |
| 1504 | for (auto display : mDisplays) { |
| 1505 | std::string name; |
| 1506 | |
| 1507 | ASSERT_NO_FATAL_FAILURE(getDisplayName(display, &name)); |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | /* TESTCASE: Tests that the HWC2 does not return a display name for a bad |
| 1512 | * display */ |
| 1513 | TEST_F(Hwc2Test, GET_DISPLAY_NAME_bad_display) |
| 1514 | { |
| 1515 | hwc2_display_t display; |
| 1516 | std::string name; |
| 1517 | hwc2_error_t err = HWC2_ERROR_NONE; |
| 1518 | |
| 1519 | ASSERT_NO_FATAL_FAILURE(getBadDisplay(&display)); |
| 1520 | |
| 1521 | ASSERT_NO_FATAL_FAILURE(getDisplayName(display, &name, &err)); |
| 1522 | EXPECT_EQ(err, HWC2_ERROR_BAD_DISPLAY) << "returned wrong error code"; |
| 1523 | } |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame^] | 1524 | |
| 1525 | /* TESTCASE: Tests that the HWC2 can set basic composition types. */ |
| 1526 | TEST_F(Hwc2Test, SET_LAYER_COMPOSITION_TYPE) |
| 1527 | { |
| 1528 | ASSERT_NO_FATAL_FAILURE(setLayerProperty(Hwc2TestCoverage::Complete, |
| 1529 | setComposition, advanceComposition)); |
| 1530 | } |
| 1531 | |
| 1532 | /* TESTCASE: Tests that the HWC2 can update a basic composition type on a |
| 1533 | * layer. */ |
| 1534 | TEST_F(Hwc2Test, SET_LAYER_COMPOSITION_TYPE_update) |
| 1535 | { |
| 1536 | ASSERT_NO_FATAL_FAILURE(setLayerPropertyUpdate(Hwc2TestCoverage::Complete, |
| 1537 | setComposition, advanceComposition)); |
| 1538 | } |
| 1539 | |
| 1540 | /* TESTCASE: Tests that the HWC2 cannot set a composition type for a bad layer */ |
| 1541 | TEST_F(Hwc2Test, SET_LAYER_COMPOSITION_TYPE_bad_layer) |
| 1542 | { |
| 1543 | ASSERT_NO_FATAL_FAILURE(setLayerPropertyBadLayer(Hwc2TestCoverage::Default, |
| 1544 | setComposition)); |
| 1545 | } |
| 1546 | |
| 1547 | /* TESTCASE: Tests that the HWC2 cannot set a bad composition type */ |
| 1548 | TEST_F(Hwc2Test, SET_LAYER_COMPOSITION_TYPE_bad_parameter) |
| 1549 | { |
| 1550 | ASSERT_NO_FATAL_FAILURE(setLayerPropertyBadParameter( |
| 1551 | [] (Hwc2Test* test, hwc2_display_t display, hwc2_layer_t layer, |
| 1552 | hwc2_error_t* outErr) { |
| 1553 | |
| 1554 | ASSERT_NO_FATAL_FAILURE(test->setLayerCompositionType(display, |
| 1555 | layer, HWC2_COMPOSITION_INVALID, outErr)); |
| 1556 | } |
| 1557 | )); |
| 1558 | } |