diff options
author | Kalesh Singh <kaleshsingh@google.com> | 2022-09-06 10:02:38 -0700 |
---|---|---|
committer | Kalesh Singh <kaleshsingh@google.com> | 2023-01-26 16:14:41 +0000 |
commit | a628880b6542a1d3a2b3d3c8a402716667db7eca (patch) | |
tree | 67ca3c43c812896b427ae816dd0c57c26d2812f5 | |
parent | 6e976b27ecd7fe3f969df0bf1190d605959183b2 (diff) | |
download | interfaces-android13-qpr3-c-s2-release.tar.gz |
suspend: De-flake suspend testsandroid-13.0.0_r82android-13.0.0_r81android-13.0.0_r80android-13.0.0_r74android-13.0.0_r73android-13.0.0_r72android-13.0.0_r66android-13.0.0_r65android-13.0.0_r64android-13.0.0_r60android-13.0.0_r59android-13.0.0_r58android13-qpr3-c-s8-releaseandroid13-qpr3-c-s7-releaseandroid13-qpr3-c-s6-releaseandroid13-qpr3-c-s5-releaseandroid13-qpr3-c-s4-releaseandroid13-qpr3-c-s3-releaseandroid13-qpr3-c-s2-releaseandroid13-qpr3-c-s12-releaseandroid13-qpr3-c-s11-releaseandroid13-qpr3-c-s10-releaseandroid13-qpr3-c-s1-release
The events that happen on the sock stream can race with the isBlocked() checks because the autosuspend loop is a separate thread from the test thread. Add some buffer time to avoid flakiness in these tests.
Test: Treehugger
Bug: 255898234
Bug: 265513788
Bug: 266077359
Change-Id: Ie03b343e46dc4035c09cb0a5399b4a5da569f7d4
Merged-In: Ie03b343e46dc4035c09cb0a5399b4a5da569f7d4
-rw-r--r-- | suspend/1.0/default/SystemSuspendUnitTest.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/suspend/1.0/default/SystemSuspendUnitTest.cpp b/suspend/1.0/default/SystemSuspendUnitTest.cpp index f92e416..a4d58b5 100644 --- a/suspend/1.0/default/SystemSuspendUnitTest.cpp +++ b/suspend/1.0/default/SystemSuspendUnitTest.cpp @@ -198,8 +198,12 @@ class SystemSuspendTest : public ::testing::Test { } virtual void TearDown() override { + // Allow some time for the autosuspend loop to happen, if unblocked + std::this_thread::sleep_for(100ms); + if (!isReadBlocked(wakeupCountFd)) readFd(wakeupCountFd); - if (!isReadBlocked(stateFd)) readFd(stateFd).empty(); + if (!isReadBlocked(stateFd)) readFd(stateFd); + ASSERT_TRUE(isReadBlocked(wakeupCountFd)); ASSERT_TRUE(isReadBlocked(stateFd)); } @@ -209,7 +213,12 @@ class SystemSuspendTest : public ::testing::Test { ASSERT_TRUE(WriteStringToFd(wakeupCount, wakeupCountFd)); } - bool isSystemSuspendBlocked(int timeout_ms = 20) { return isReadBlocked(stateFd, timeout_ms); } + bool isSystemSuspendBlocked(int timeout_ms = 20) { + // Allow some time for the autosuspend loop to happen, if unblocked + std::this_thread::sleep_for(100ms); + + return isReadBlocked(stateFd, timeout_ms); + } std::shared_ptr<IWakeLock> acquireWakeLock(const std::string& name = "TestLock") { std::shared_ptr<IWakeLock> wl = nullptr; @@ -305,15 +314,22 @@ TEST_F(SystemSuspendTest, OnlyOneEnableAutosuspend) { // Tests that autosuspend thread can only enabled again after its been disabled. TEST_F(SystemSuspendTest, EnableAutosuspendAfterDisableAutosuspend) { bool enabled = false; - unblockSystemSuspendFromWakeupCount(); + + checkLoop(1); + controlServiceInternal->enableAutosuspend(new BBinder(), &enabled); + ASSERT_FALSE(enabled); + systemSuspend->disableAutosuspend(); + unblockSystemSuspendFromWakeupCount(); + controlServiceInternal->enableAutosuspend(new BBinder(), &enabled); - ASSERT_EQ(enabled, true); + ASSERT_TRUE(enabled); } TEST_F(SystemSuspendTest, DisableAutosuspendBlocksSuspend) { checkLoop(1); systemSuspend->disableAutosuspend(); + unblockSystemSuspendFromWakeupCount(); ASSERT_TRUE(isSystemSuspendBlocked()); // Re-enable autosuspend @@ -425,10 +441,10 @@ TEST_F(SystemSuspendTest, MultipleWakeLocks) { std::shared_ptr<IWakeLock> wl1 = acquireWakeLock(); ASSERT_NE(wl1, nullptr); ASSERT_TRUE(isSystemSuspendBlocked()); - unblockSystemSuspendFromWakeupCount(); { std::shared_ptr<IWakeLock> wl2 = acquireWakeLock(); ASSERT_NE(wl2, nullptr); + unblockSystemSuspendFromWakeupCount(); ASSERT_TRUE(isSystemSuspendBlocked()); } ASSERT_TRUE(isSystemSuspendBlocked()); |