• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 #include <VtsCoreUtil.h>
18 #include <aidl/Gtest.h>
19 #include <aidl/Vintf.h>
20 #include <aidl/android/hardware/wifi/supplicant/BnSupplicant.h>
21 #include <android/binder_manager.h>
22 #include <android/binder_status.h>
23 #include <binder/IServiceManager.h>
24 #include <binder/ProcessState.h>
25 #include <cutils/properties.h>
26 
27 #include "supplicant_test_utils.h"
28 #include "wifi_aidl_test_utils.h"
29 
30 using aidl::android::hardware::wifi::supplicant::DebugLevel;
31 using aidl::android::hardware::wifi::supplicant::IfaceInfo;
32 using aidl::android::hardware::wifi::supplicant::IfaceType;
33 using android::ProcessState;
34 
35 class SupplicantAidlTest : public testing::TestWithParam<std::string> {
36   public:
SetUp()37     void SetUp() override {
38         initializeService();
39         supplicant_ = getSupplicant(GetParam().c_str());
40         ASSERT_NE(supplicant_, nullptr);
41         ASSERT_TRUE(supplicant_->setDebugParams(DebugLevel::EXCESSIVE, true, true).isOk());
42     }
43 
TearDown()44     void TearDown() override {
45         stopSupplicantService();
46         startWifiFramework();
47     }
48 
49   protected:
50     std::shared_ptr<ISupplicant> supplicant_;
51 };
52 
53 /*
54  * GetDebugLevel
55  */
TEST_P(SupplicantAidlTest,GetDebugLevel)56 TEST_P(SupplicantAidlTest, GetDebugLevel) {
57     DebugLevel retrievedLevel;
58     DebugLevel expectedLevel = DebugLevel::WARNING;
59     ASSERT_TRUE(supplicant_->setDebugParams(expectedLevel, true, true).isOk());
60     ASSERT_TRUE(supplicant_->getDebugLevel(&retrievedLevel).isOk());
61     ASSERT_EQ(retrievedLevel, expectedLevel);
62 }
63 
64 /*
65  * ListAndRemoveInterface
66  */
TEST_P(SupplicantAidlTest,ListAndRemoveInterface)67 TEST_P(SupplicantAidlTest, ListAndRemoveInterface) {
68     // Ensure that the STA interface exists
69     std::shared_ptr<ISupplicantStaIface> sta_iface;
70     EXPECT_TRUE(supplicant_->getStaInterface(getStaIfaceName(), &sta_iface).isOk());
71     ASSERT_NE(sta_iface, nullptr);
72 
73     // Interface list should contain at least 1 interface
74     std::vector<IfaceInfo> ifaces;
75     EXPECT_TRUE(supplicant_->listInterfaces(&ifaces).isOk());
76     ASSERT_FALSE(ifaces.empty());
77     int prevNumIfaces = ifaces.size();
78 
79     // Remove an interface and verify that it is removed from the list
80     EXPECT_TRUE(supplicant_->removeInterface(ifaces[0]).isOk());
81     EXPECT_TRUE(supplicant_->listInterfaces(&ifaces).isOk());
82     ASSERT_NE(ifaces.size(), prevNumIfaces);
83 }
84 
85 /*
86  * SetConcurrencyPriority
87  */
TEST_P(SupplicantAidlTest,SetConcurrencyPriority)88 TEST_P(SupplicantAidlTest, SetConcurrencyPriority) {
89     // Valid values
90     ASSERT_TRUE(supplicant_->setConcurrencyPriority(IfaceType::STA).isOk());
91     ASSERT_TRUE(supplicant_->setConcurrencyPriority(IfaceType::P2P).isOk());
92 
93     // Invalid value
94     ASSERT_FALSE(supplicant_->setConcurrencyPriority(static_cast<IfaceType>(2)).isOk());
95 }
96 
97 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SupplicantAidlTest);
98 INSTANTIATE_TEST_SUITE_P(
99         Supplicant, SupplicantAidlTest,
100         testing::ValuesIn(android::getAidlHalInstanceNames(ISupplicant::descriptor)),
101         android::PrintInstanceNameToString);
102 
main(int argc,char ** argv)103 int main(int argc, char** argv) {
104     ::testing::InitGoogleTest(&argc, argv);
105     ProcessState::self()->setThreadPoolMaxThreadCount(1);
106     ProcessState::self()->startThreadPool();
107     return RUN_ALL_TESTS();
108 }
109