diff options
| author | 2023-10-10 20:00:25 +0000 | |
|---|---|---|
| committer | 2023-10-11 19:53:38 +0000 | |
| commit | db002509f1d9fdc34ba8fb1ba8eb15793b9c5330 (patch) | |
| tree | 49d1308bdfffa5469a28cf9b247a2b73f28f7608 | |
| parent | 64edb6c4b8e5491de46bf7b58643c0d91ee4e652 (diff) | |
Make the boot config tests more hermetic
Use a test harness to try to reset boot configs to its original state on
completion. Otherwise we would be polluting the state of other tests.
Ideally these tests hit a fake HWC instead and leave hitting a real HWC
instance for xTS. Alas, we don't have a convenient fake set up, and the
alternative is deleting these tests which is worse.
Bug: 304555116
Test: SurfaceFlinger_test, followed by inputflinger_tests
Change-Id: Id70d11713aca69c9da9f404060f377b2b0d2629e
| -rw-r--r-- | services/surfaceflinger/tests/BootDisplayMode_test.cpp | 108 |
1 files changed, 85 insertions, 23 deletions
diff --git a/services/surfaceflinger/tests/BootDisplayMode_test.cpp b/services/surfaceflinger/tests/BootDisplayMode_test.cpp index f2874ae0e1..4f41a81011 100644 --- a/services/surfaceflinger/tests/BootDisplayMode_test.cpp +++ b/services/surfaceflinger/tests/BootDisplayMode_test.cpp @@ -28,33 +28,95 @@ namespace android { using gui::aidl_utils::statusTFromBinderStatus; -TEST(BootDisplayModeTest, setBootDisplayMode) { - sp<gui::ISurfaceComposer> sf(ComposerServiceAIDL::getComposerService()); - - const auto ids = SurfaceComposerClient::getPhysicalDisplayIds(); - ASSERT_FALSE(ids.empty()); - auto displayToken = SurfaceComposerClient::getPhysicalDisplayToken(ids.front()); - bool bootModeSupport = false; - binder::Status status = sf->getBootDisplayModeSupport(&bootModeSupport); - ASSERT_NO_FATAL_FAILURE(statusTFromBinderStatus(status)); - if (bootModeSupport) { - status = sf->setBootDisplayMode(displayToken, 0); +struct BootDisplayModeTest : public ::testing::Test { +protected: + void SetUp() override { + mSf = ComposerServiceAIDL::getComposerService(); + + const auto ids = SurfaceComposerClient::getPhysicalDisplayIds(); + ASSERT_FALSE(ids.empty()); + mDisplayToken = SurfaceComposerClient::getPhysicalDisplayToken(ids.front()); + bool bootModeSupport = false; + binder::Status status = mSf->getBootDisplayModeSupport(&bootModeSupport); + ASSERT_NO_FATAL_FAILURE(statusTFromBinderStatus(status)); + + if (!bootModeSupport) { + GTEST_SKIP() << "Boot mode not supported"; + } + + gui::DynamicDisplayInfo info; + status = mSf->getDynamicDisplayInfoFromToken(mDisplayToken, &info); ASSERT_EQ(NO_ERROR, statusTFromBinderStatus(status)); + mOldMode = info.preferredBootDisplayMode; + const auto newMode = [&]() -> std::optional<ui::DisplayModeId> { + for (const auto& mode : info.supportedDisplayModes) { + if (mode.id != mOldMode) { + return std::optional(mode.id); + } + } + return std::nullopt; + }(); + + if (!newMode) { + GTEST_SKIP() << "Only a single mode is supported"; + } + + mNewMode = *newMode; } -} -TEST(BootDisplayModeTest, clearBootDisplayMode) { - sp<gui::ISurfaceComposer> sf(ComposerServiceAIDL::getComposerService()); - const auto ids = SurfaceComposerClient::getPhysicalDisplayIds(); - ASSERT_FALSE(ids.empty()); - auto displayToken = SurfaceComposerClient::getPhysicalDisplayToken(ids.front()); - bool bootModeSupport = false; - binder::Status status = sf->getBootDisplayModeSupport(&bootModeSupport); - ASSERT_NO_FATAL_FAILURE(statusTFromBinderStatus(status)); - if (bootModeSupport) { - status = sf->clearBootDisplayMode(displayToken); - ASSERT_EQ(NO_ERROR, statusTFromBinderStatus(status)); + void TearDown() override { + binder::Status status = mSf->setBootDisplayMode(mDisplayToken, mOldMode); + EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status)); + + gui::DynamicDisplayInfo info; + status = mSf->getDynamicDisplayInfoFromToken(mDisplayToken, &info); + EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status)); + EXPECT_EQ(mOldMode, info.preferredBootDisplayMode); } + + ui::DisplayModeId mOldMode; + ui::DisplayModeId mNewMode; + sp<gui::ISurfaceComposer> mSf; + sp<IBinder> mDisplayToken; +}; + +TEST_F(BootDisplayModeTest, setBootDisplayMode) { + // Set a new mode and check that it got applied + binder::Status status = mSf->setBootDisplayMode(mDisplayToken, mNewMode); + EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status)); + + gui::DynamicDisplayInfo info; + status = mSf->getDynamicDisplayInfoFromToken(mDisplayToken, &info); + EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status)); + EXPECT_EQ(mNewMode, info.preferredBootDisplayMode); +} + +TEST_F(BootDisplayModeTest, clearBootDisplayMode) { + // Clear once to figure out what the system default is + binder::Status status = mSf->clearBootDisplayMode(mDisplayToken); + EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status)); + + gui::DynamicDisplayInfo info; + status = mSf->getDynamicDisplayInfoFromToken(mDisplayToken, &info); + EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status)); + + const ui::DisplayModeId systemMode = info.preferredBootDisplayMode; + const ui::DisplayModeId newMode = systemMode == mOldMode ? mNewMode : mOldMode; + + // Now set a new mode and clear the boot mode again to figure out if the api worked. + status = mSf->setBootDisplayMode(mDisplayToken, newMode); + EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status)); + + status = mSf->getDynamicDisplayInfoFromToken(mDisplayToken, &info); + EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status)); + EXPECT_EQ(newMode, info.preferredBootDisplayMode); + + status = mSf->clearBootDisplayMode(mDisplayToken); + EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status)); + + status = mSf->getDynamicDisplayInfoFromToken(mDisplayToken, &info); + EXPECT_EQ(NO_ERROR, statusTFromBinderStatus(status)); + EXPECT_EQ(systemMode, info.preferredBootDisplayMode); } } // namespace android |