summaryrefslogtreecommitdiff
path: root/test_lazy.cpp
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2019-02-01 20:17:25 -0800
committerSteven Moreland <smoreland@google.com>2019-02-05 13:51:24 -0800
commite7cf1424b902e14548642d4dcbc9ce7bd957fa7a (patch)
tree980fcdbf530b972e67c6ebd0f2e0bac52729208a /test_lazy.cpp
parent2fa0f5509bde0d6922ad605b35566358a78a1151 (diff)
downloadhwservicemanager-e7cf1424b902e14548642d4dcbc9ce7bd957fa7a.tar.gz
Only access lazy HAL feature when clients do
This was causing some excess kernel logs. Fixes: 123769263 Test: hwservicemanager_test HidlServiceLazyTest ClientWithoutLazy (now passes) Test: internal 'lazy_hidl_test' fuzzing health storage HAL, for sanity Change-Id: Ie47c9e085c6f251a9fe1806d7f7f70865e6f5f12
Diffstat (limited to 'test_lazy.cpp')
-rw-r--r--test_lazy.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/test_lazy.cpp b/test_lazy.cpp
index df42329..21108ba 100644
--- a/test_lazy.cpp
+++ b/test_lazy.cpp
@@ -51,21 +51,32 @@ public:
// Note that this should include one count for hwservicemanager. A count of
// 1 indicates that hwservicemanager is the only process holding the service.
void setReportedClientCount(ssize_t count) {
- mInjectedReportCount = count;
+ mState.mInjectedReportCount = count;
+ }
+
+ // Essentially, the number of times the kernel API would be called
+ size_t getNumTimesReported() {
+ return mState.mInjectedTimes;
}
std::unique_ptr<HidlService> makeService() {
auto service = std::make_unique<NiceMock<MockHidlService>>();
- ON_CALL(*service, getNodeStrongRefCount()).WillByDefault(Invoke([&]() { return mInjectedReportCount; }));
+ ON_CALL(*service, getNodeStrongRefCount()).WillByDefault(Invoke([&]() {
+ mState.mInjectedTimes++;
+ return mState.mInjectedReportCount;
+ }));
return service;
}
protected:
void SetUp() override {
- mInjectedReportCount = -1;
+ mState = TestState();
}
- ssize_t mInjectedReportCount = -1;
+ struct TestState {
+ ssize_t mInjectedReportCount = -1;
+ size_t mInjectedTimes = 0;
+ } mState;
};
TEST_F(HidlServiceLazyTest, NoChange) {
@@ -197,3 +208,13 @@ TEST_F(HidlServiceLazyTest, NotificationSentForNewClientCallback) {
ASSERT_THAT(cb->stream, ElementsAre(true, false)); // reported only after two intervals
ASSERT_THAT(laterCb->stream, ElementsAre(true, false)); // reported only after two intervals
}
+
+TEST_F(HidlServiceLazyTest, ClientWithoutLazy) {
+ std::unique_ptr<HidlService> service = makeService();
+
+ setReportedClientCount(2);
+ service->handleClientCallbacks(false /*onInterval*/);
+
+ // kernel API should not be called
+ EXPECT_EQ(0u, getNumTimesReported());
+}