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