1 /* 2 * Copyright (C) 2016 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 #ifndef SUPPLICANT_HIDL_TEST_UTILS_H 18 #define SUPPLICANT_HIDL_TEST_UTILS_H 19 20 #include <VtsCoreUtil.h> 21 #include <android-base/logging.h> 22 #include <android/hardware/wifi/supplicant/1.0/ISupplicant.h> 23 #include <android/hardware/wifi/supplicant/1.0/ISupplicantP2pIface.h> 24 #include <android/hardware/wifi/supplicant/1.0/ISupplicantStaIface.h> 25 #include <android/hardware/wifi/supplicant/1.0/ISupplicantStaNetwork.h> 26 #include <android/hardware/wifi/supplicant/1.1/ISupplicant.h> 27 28 #include <getopt.h> 29 30 #include "wifi_hidl_test_utils.h" 31 32 // Used to start the android wifi framework after every test. 33 bool startWifiFramework(); 34 35 // Used to stop the android wifi framework before every test. 36 bool stopWifiFramework(); 37 38 void stopSupplicant(const std::string& wifi_instance_name); 39 // Used to configure the chip, driver and start wpa_supplicant before every 40 // test. 41 void startSupplicantAndWaitForHidlService( 42 const std::string& wifi_instance_name, 43 const std::string& supplicant_instance_name); 44 45 // Helper functions to obtain references to the various HIDL interface objects. 46 // Note: We only have a single instance of each of these objects currently. 47 // These helper functions should be modified to return vectors if we support 48 // multiple instances. 49 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant> 50 getSupplicant(const std::string& supplicant_instance_name, bool isP2pOn); 51 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantStaIface> 52 getSupplicantStaIface( 53 const android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant>& 54 supplicant); 55 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantStaNetwork> 56 createSupplicantStaNetwork( 57 const android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant>& 58 supplicant); 59 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantP2pIface> 60 getSupplicantP2pIface( 61 const android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant>& 62 supplicant); 63 bool turnOnExcessiveLogging( 64 const android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant>& 65 supplicant); 66 67 bool turnOnExcessiveLogging(); 68 69 bool waitForFrameworkReady(); 70 71 class SupplicantHidlTestBase 72 : public ::testing::TestWithParam<std::tuple<std::string, std::string>> { 73 public: SetUp()74 virtual void SetUp() override { 75 // Stop Wi-Fi 76 ASSERT_TRUE(stopWifiFramework()); // stop & wait for wifi to shutdown. 77 78 // should always be v1.0 wifi 79 wifi_v1_0_instance_name_ = std::get<0>(GetParam()); 80 supplicant_instance_name_ = std::get<1>(GetParam()); 81 std::system("/system/bin/start"); 82 ASSERT_TRUE(waitForFrameworkReady()); 83 isP2pOn_ = 84 testing::deviceSupportsFeature("android.hardware.wifi.direct"); 85 stopSupplicant(wifi_v1_0_instance_name_); 86 startSupplicantAndWaitForHidlService(wifi_v1_0_instance_name_, 87 supplicant_instance_name_); 88 LOG(INFO) << "SupplicantHidlTestBase isP2pOn_: " << isP2pOn_; 89 } 90 TearDown()91 virtual void TearDown() override { 92 stopSupplicant(wifi_v1_0_instance_name_); 93 // Start Wi-Fi 94 startWifiFramework(); 95 } 96 97 protected: 98 bool isP2pOn_ = false; 99 std::string wifi_v1_0_instance_name_; 100 std::string supplicant_instance_name_; 101 }; 102 103 class SupplicantHidlTestBaseV1_0 : public SupplicantHidlTestBase { 104 public: SetUp()105 virtual void SetUp() override { 106 SupplicantHidlTestBase::SetUp(); 107 supplicant_ = getSupplicant(supplicant_instance_name_, isP2pOn_); 108 ASSERT_NE(supplicant_.get(), nullptr); 109 EXPECT_TRUE(turnOnExcessiveLogging(supplicant_)); 110 } 111 112 protected: 113 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant> 114 supplicant_; 115 }; 116 #endif /* SUPPLICANT_HIDL_TEST_UTILS_H */ 117