summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKalesh Singh <kaleshsingh@google.com>2022-09-06 10:02:38 -0700
committerKalesh Singh <kaleshsingh@google.com>2023-01-26 16:14:41 +0000
commita628880b6542a1d3a2b3d3c8a402716667db7eca (patch)
tree67ca3c43c812896b427ae816dd0c57c26d2812f5
parent6e976b27ecd7fe3f969df0bf1190d605959183b2 (diff)
downloadinterfaces-android13-qpr3-c-s2-release.tar.gz
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.cpp26
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());