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(const std::string& wifi_instance_name); 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 // Used to initialize/deinitialize the driver and firmware at the 46 // beginning and end of each test. 47 void initializeDriverAndFirmware(const std::string& wifi_instance_name); 48 void deInitializeDriverAndFirmware(const std::string& wifi_instance_name); 49 50 // Helper functions to obtain references to the various HIDL interface objects. 51 // Note: We only have a single instance of each of these objects currently. 52 // These helper functions should be modified to return vectors if we support 53 // multiple instances. 54 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant> 55 getSupplicant(const std::string& supplicant_instance_name, bool isP2pOn); 56 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantStaIface> 57 getSupplicantStaIface( 58 const android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant>& 59 supplicant); 60 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantStaNetwork> 61 createSupplicantStaNetwork( 62 const android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant>& 63 supplicant); 64 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicantP2pIface> 65 getSupplicantP2pIface( 66 const android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant>& 67 supplicant); 68 bool turnOnExcessiveLogging( 69 const android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant>& 70 supplicant); 71 72 bool turnOnExcessiveLogging(); 73 74 bool waitForFrameworkReady(); 75 76 class SupplicantHidlTestBase 77 : public ::testing::TestWithParam<std::tuple<std::string, std::string>> { 78 public: SetUp()79 virtual void SetUp() override { 80 wifi_v1_0_instance_name_ = 81 std::get<0>(GetParam()); // should always be v1.0 wifi 82 supplicant_instance_name_ = std::get<1>(GetParam()); 83 84 // Stop & wait for wifi to shutdown. 85 ASSERT_TRUE(stopWifiFramework(wifi_v1_0_instance_name_)); 86 87 std::system("/system/bin/start"); 88 ASSERT_TRUE(waitForFrameworkReady()); 89 isP2pOn_ = 90 testing::deviceSupportsFeature("android.hardware.wifi.direct"); 91 stopSupplicant(wifi_v1_0_instance_name_); 92 startSupplicantAndWaitForHidlService(wifi_v1_0_instance_name_, 93 supplicant_instance_name_); 94 LOG(INFO) << "SupplicantHidlTestBase isP2pOn_: " << isP2pOn_; 95 } 96 TearDown()97 virtual void TearDown() override { 98 stopSupplicant(wifi_v1_0_instance_name_); 99 // Start Wi-Fi 100 startWifiFramework(); 101 } 102 103 protected: 104 bool isP2pOn_ = false; 105 std::string wifi_v1_0_instance_name_; 106 std::string supplicant_instance_name_; 107 }; 108 109 class SupplicantHidlTestBaseV1_0 : public SupplicantHidlTestBase { 110 public: SetUp()111 virtual void SetUp() override { 112 SupplicantHidlTestBase::SetUp(); 113 supplicant_ = getSupplicant(supplicant_instance_name_, isP2pOn_); 114 ASSERT_NE(supplicant_.get(), nullptr); 115 EXPECT_TRUE(turnOnExcessiveLogging(supplicant_)); 116 } 117 118 protected: 119 android::sp<android::hardware::wifi::supplicant::V1_0::ISupplicant> 120 supplicant_; 121 }; 122 #endif /* SUPPLICANT_HIDL_TEST_UTILS_H */ 123