• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 #define LOG_TAG "vold_aidl_hal_test"
18 
19 #include <aidl/Gtest.h>
20 #include <aidl/Vintf.h>
21 #include <android/system/vold/BnVoldCheckpointListener.h>
22 #include <android/system/vold/CheckpointingState.h>
23 #include <android/system/vold/IVold.h>
24 #include <binder/IServiceManager.h>
25 #include <gtest/gtest.h>
26 #include <utils/String16.h>
27 
28 using ::android::defaultServiceManager;
29 using ::android::sp;
30 using ::android::String16;
31 using ::android::binder::Status;
32 using ::android::system::vold::BnVoldCheckpointListener;
33 using ::android::system::vold::CheckpointingState;
34 using ::android::system::vold::IVold;
35 
36 class VoldAidlTest : public ::testing::TestWithParam<std::string> {
37    public:
38     sp<IVold> vold_;
39 
SetUp()40     void SetUp() final {
41         auto manager = defaultServiceManager();
42         auto name = GetParam();
43         auto binder = manager->waitForService(String16(name.data(), name.size()));
44         vold_ = IVold::asInterface(binder);
45     }
46 
TearDown()47     void TearDown() final {}
48 };
49 
50 class TestListener : public BnVoldCheckpointListener {
51    public:
onCheckpointingComplete()52     Status onCheckpointingComplete() final {
53         ++called_;
54         return Status::ok();
55     }
56 
timesCalled()57     int timesCalled() { return called_; }
58 
59    private:
60     int called_ = 0;
61 };
62 
TEST_P(VoldAidlTest,PostBootAddListener)63 TEST_P(VoldAidlTest, PostBootAddListener) {
64     auto listener = sp<TestListener>::make();
65 
66     CheckpointingState state;
67     Status ret = vold_->registerCheckpointListener(listener, &state);
68     ASSERT_EQ(ret.isOk(), true);
69     EXPECT_EQ(state, CheckpointingState::CHECKPOINTING_COMPLETE);
70     EXPECT_EQ(listener->timesCalled(), 0);
71 }
72 
73 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VoldAidlTest);
74 INSTANTIATE_TEST_SUITE_P(PerInstance, VoldAidlTest,
75                          testing::ValuesIn(::android::getAidlHalInstanceNames(IVold::descriptor)),
76                          android::PrintInstanceNameToString);
77