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